Apply systemd-based dbus activation
[platform/upstream/at-spi2-core.git] / dbind / dbind-any.c
index 088a207..ae499d7 100644 (file)
@@ -1,9 +1,27 @@
+/*
+ * Copyright 2008-2011 Novell, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
 /* type driven marshalling */
 #include <stdio.h>
 #include <glib.h>
 
 #include "config.h"
-#include "dbind-config.h"
 #include "dbind-any.h"
 
 #undef DEBUG
@@ -60,30 +78,30 @@ dbind_find_c_alignment_r (const char **type)
 
         switch (t) {
     case DBUS_TYPE_BYTE:
-        return DBIND_ALIGNOF_CHAR;
+        return ALIGNOF_CHAR;
     case DBUS_TYPE_BOOLEAN:
-        return DBIND_ALIGNOF_DBUS_BOOL_T;
+        return ALIGNOF_DBUS_BOOL_T;
     case DBUS_TYPE_INT16:
     case DBUS_TYPE_UINT16:
-        return DBIND_ALIGNOF_DBUS_INT16_T;
+        return ALIGNOF_DBUS_INT16_T;
     case DBUS_TYPE_INT32:
     case DBUS_TYPE_UINT32:
-        return DBIND_ALIGNOF_DBUS_INT32_T;
+        return ALIGNOF_DBUS_INT32_T;
     case DBUS_TYPE_INT64:
     case DBUS_TYPE_UINT64:
-        return DBIND_ALIGNOF_DBUS_INT64_T;
+        return ALIGNOF_DBUS_INT64_T;
     case DBUS_TYPE_DOUBLE:
-        return DBIND_ALIGNOF_DOUBLE;
+        return ALIGNOF_DOUBLE;
     /* ptr types */
     case DBUS_TYPE_STRING:
     case DBUS_TYPE_OBJECT_PATH:
     case DBUS_TYPE_SIGNATURE:
     case DBUS_TYPE_ARRAY:
-        return DBIND_ALIGNOF_DBIND_POINTER;
+        return ALIGNOF_DBIND_POINTER;
     case DBUS_STRUCT_BEGIN_CHAR:
       /* TODO: I think this would break with a nested struct */
-#if DBIND_ALIGNOF_DBIND_STRUCT > 1
-                retval = MAX (retval, DBIND_ALIGNOF_DBIND_STRUCT);
+#if ALIGNOF_DBIND_STRUCT > 1
+                retval = MAX (retval, ALIGNOF_DBIND_STRUCT);
 #endif
         while (**type != DBUS_STRUCT_END_CHAR) {
             int elem_align = dbind_find_c_alignment_r (type);
@@ -92,8 +110,8 @@ dbind_find_c_alignment_r (const char **type)
         (*type)++;
         return retval;
     case DBUS_DICT_ENTRY_BEGIN_CHAR:
-#if DBIND_ALIGNOF_DBIND_STRUCT > 1
-                retval = MAX (retval, DBIND_ALIGNOF_DBIND_STRUCT);
+#if ALIGNOF_DBIND_STRUCT > 1
+                retval = MAX (retval, ALIGNOF_DBIND_STRUCT);
 #endif
         while (**type != DBUS_DICT_ENTRY_END_CHAR) {
             int elem_align = dbind_find_c_alignment_r (type);
@@ -104,7 +122,7 @@ dbind_find_c_alignment_r (const char **type)
     case DBUS_TYPE_STRUCT:
     case DBUS_TYPE_DICT_ENTRY:
         warn_braces ();
-        return DBIND_ALIGNOF_DBIND_POINTER;
+        return ALIGNOF_DBIND_POINTER;
     case '\0':
         g_assert_not_reached();
         break;
@@ -287,7 +305,7 @@ dbind_any_free_r (const char **type, void **data)
 
         offset = 0 ;
         while (**type != DBUS_DICT_ENTRY_END_CHAR) {
-            char *subt = *type;
+            const char *subt = *type;
                         offset = ALIGN_VALUE (offset, dbind_find_c_alignment (*type));
                         *data = PTR_PLUS (data0, offset);
             dbind_any_free_r (type, data);
@@ -405,7 +423,7 @@ dbind_any_marshal (DBusMessageIter *iter,
 
         offset = 0 ;
         while (**type != DBUS_DICT_ENTRY_END_CHAR) {
-            char *subt = *type;
+            const char *subt = *type;
                         offset = ALIGN_VALUE (offset, dbind_find_c_alignment (*type));
                         *data = PTR_PLUS (data0, offset);
             dbind_any_marshal (&sub, type, data);
@@ -607,7 +625,7 @@ dbind_any_demarshal (DBusMessageIter *iter,
         dbus_message_iter_recurse (iter, &child);
 
         while (**type != DBUS_DICT_ENTRY_END_CHAR) {
-            char *subt = *type;
+            const char *subt = *type;
                         offset = ALIGN_VALUE (offset, dbind_find_c_alignment (*type));
                         *data = PTR_PLUS (data0, offset);
             dbind_any_demarshal (&child, type, data);
@@ -621,6 +639,10 @@ dbind_any_demarshal (DBusMessageIter *iter,
         (*type)++;
 
         break;
+    case DBUS_TYPE_VARIANT:
+        /* skip; unimplemented for now */
+        (*type)++;
+        break;
     }
     case DBUS_TYPE_STRUCT:
     case DBUS_TYPE_DICT_ENTRY:
@@ -630,6 +652,41 @@ dbind_any_demarshal (DBusMessageIter *iter,
     dbus_message_iter_next (iter);
 }
 
+static const char *
+pass_complex_arg (const char *p, char begin, char end)
+{
+  int level = 1;
+
+  p++;
+  while (*p && level > 0)
+  {
+    if (*p == begin)
+      level++;
+    else if (*p == end)
+      level--;
+    p++;
+  }
+  if (*p == end)
+    p++;
+  return p;
+}
+
+static const char *
+pass_arg (const char *p)
+{
+  switch (*p)
+  {
+  case '(':
+    return pass_complex_arg (p, '(', ')');
+  case '{':
+    return pass_complex_arg (p, '{', '}');
+  case 'a':
+    return pass_arg (p+1);
+  default:
+    return p + 1;
+  }
+}
+
 /*---------------------------------------------------------------------------*/
 
 void
@@ -686,7 +743,7 @@ dbind_any_demarshal_va (DBusMessageIter *iter,
             fprintf (stderr, "Unknown / invalid arg type %c\n", *p);
             break;
         }
-      p++;
+      p = pass_arg (p);
     }
 
     if (p [0] == '=' && p[1] == '>')