dbus/dbus dbus-marshal.h, 1.21, 1.22 dbus-marshal.c, 1.50, 1.51 dbus-connection.h, 1.27, 1.28 dbus-connection.c, 1.79, 1.80

Olivier Andrieu oandrieu at pdx.freedesktop.org
Sat Jun 5 09:32:02 PDT 2004


Update of /cvs/dbus/dbus/dbus
In directory pdx:/tmp/cvs-serv10912/dbus

Modified Files:
	dbus-marshal.h dbus-marshal.c dbus-connection.h 
	dbus-connection.c 
Log Message:
2004-06-05  Olivier Andrieu  <oliv__a at users.sourceforge.net>

	* dbus/dbus-connection.h, dbus/dbus-connection.c: have object path
	registration functions take the path argument as char* instead of
	char**.

	* dbus/dbus-marshal.h, dbus/dbus-marshal.c (_dbus_decompose_path):
	split off the path decompostion part of
	_dbus_demarshal_object_path. Some misc. fixes to silence compiler
	warnings. 

	* glib/dbus-gobject.c, test/test-service.c: update accordingly.


Index: dbus-marshal.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-marshal.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- a/dbus-marshal.h	28 May 2004 13:10:35 -0000	1.21
+++ b/dbus-marshal.h	5 Jun 2004 16:32:00 -0000	1.22
@@ -311,6 +311,10 @@
 					    int                   *new_pos,
 					    char                ***array,
 					    int                   *array_len);
+dbus_bool_t   _dbus_decompose_path         (const char*            data,
+					    int                    len,
+					    char                ***path,
+					    int                   *path_len);
 dbus_bool_t   _dbus_demarshal_object_path  (const DBusString      *str,
 					    int                    byte_order,
 					    int                    pos,

Index: dbus-marshal.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-marshal.c,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -d -r1.50 -r1.51
--- a/dbus-marshal.c	28 May 2004 13:10:35 -0000	1.50
+++ b/dbus-marshal.c	5 Jun 2004 16:32:00 -0000	1.51
@@ -1478,7 +1478,7 @@
     case DBUS_TYPE_INT32:
     case DBUS_TYPE_UINT32:
       return demarshal_4_octets_array (str, byte_order, *pos, pos,
-				       (dbus_uint32_t *) array, array_len);
+				       (dbus_uint32_t **)array, array_len);
       break;
 #ifdef DBUS_HAVE_INT64
     case DBUS_TYPE_INT64:
@@ -1584,32 +1584,24 @@
 #define VERBOSE_DECOMPOSE 0
 
 /**
- * Demarshals an object path.  A path of just "/" is
+ * Decompose an object path.  A path of just "/" is
  * represented as an empty vector of strings.
  * 
- * @param str the string containing the data
- * @param byte_order the byte order
- * @param pos the position in the string
- * @param new_pos the new position of the string
+ * @param data the path data
+ * @param len  the length of the path string
  * @param path address to store new object path
  * @param path_len length of stored path
  */
 dbus_bool_t
-_dbus_demarshal_object_path (const DBusString *str,
-                             int               byte_order,
-                             int               pos,
-                             int              *new_pos,
-                             char           ***path,
-                             int              *path_len)
+_dbus_decompose_path (const char*     data,
+                      int             len,
+                      char         ***path,
+                      int            *path_len)
 {
-  int len;
   char **retval;
-  const char *data;
   int n_components;
   int i, j, comp;
-  
-  len = _dbus_demarshal_uint32 (str, byte_order, pos, &pos);
-  data = _dbus_string_get_const_data_len (str, pos, len + 1);
+
   _dbus_assert (data != NULL);
 
 #if VERBOSE_DECOMPOSE
@@ -1673,9 +1665,40 @@
   if (path_len)
     *path_len = n_components;
   
+  return TRUE;
+}
+
+/**
+ * Demarshals an object path.  A path of just "/" is
+ * represented as an empty vector of strings.
+ * 
+ * @param str the string containing the data
+ * @param byte_order the byte order
+ * @param pos the position in the string
+ * @param new_pos the new position of the string
+ * @param path address to store new object path
+ * @param path_len length of stored path
+ */
+dbus_bool_t
+_dbus_demarshal_object_path (const DBusString *str,
+                             int               byte_order,
+                             int               pos,
+                             int              *new_pos,
+                             char           ***path,
+                             int              *path_len)
+{
+  int len;
+  const char *data;
+  
+  len = _dbus_demarshal_uint32 (str, byte_order, pos, &pos);
+  data = _dbus_string_get_const_data_len (str, pos, len + 1);
+
+  if (!_dbus_decompose_path (data, len, path, path_len))
+    return FALSE;
+
   if (new_pos)
     *new_pos = pos + len + 1;
-  
+
   return TRUE;
 }
 
@@ -2562,7 +2585,9 @@
   int pos = 0, len;
   dbus_int32_t array1[3] = { 0x123, 0x456, 0x789 }, *array2;
 #ifdef DBUS_HAVE_INT64
-  dbus_int64_t array3[3] = { 0x123ffffffff, 0x456ffffffff, 0x789ffffffff }, *array4;
+  dbus_int64_t array3[3] = { DBUS_INT64_CONSTANT (0x123ffffffff), 
+                             DBUS_INT64_CONSTANT (0x456ffffffff), 
+                             DBUS_INT64_CONSTANT (0x789ffffffff) }, *array4;
 #endif
   char *s;
   DBusString t;
@@ -2607,12 +2632,12 @@
   /* Marshal signed integers */
   if (!_dbus_marshal_int64 (&str, DBUS_BIG_ENDIAN, DBUS_INT64_CONSTANT (-0x123456789abc7)))
     _dbus_assert_not_reached ("could not marshal signed integer value");
-  if (!_dbus_demarshal_int64 (&str, DBUS_BIG_ENDIAN, pos, &pos) == DBUS_INT64_CONSTANT (-0x123456789abc7))
+  if (_dbus_demarshal_int64 (&str, DBUS_BIG_ENDIAN, pos, &pos) != DBUS_INT64_CONSTANT (-0x123456789abc7))
     _dbus_assert_not_reached ("demarshal failed");
 
   if (!_dbus_marshal_int64 (&str, DBUS_LITTLE_ENDIAN, DBUS_INT64_CONSTANT (-0x123456789abc7)))
     _dbus_assert_not_reached ("could not marshal signed integer value");
-  if (!_dbus_demarshal_int64 (&str, DBUS_LITTLE_ENDIAN, pos, &pos) == DBUS_INT64_CONSTANT (-0x123456789abc7))
+  if (_dbus_demarshal_int64 (&str, DBUS_LITTLE_ENDIAN, pos, &pos) != DBUS_INT64_CONSTANT (-0x123456789abc7))
     _dbus_assert_not_reached ("demarshal failed");
   
   /* Marshal unsigned integers */

Index: dbus-connection.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-connection.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- a/dbus-connection.h	2 Dec 2003 10:44:21 -0000	1.27
+++ b/dbus-connection.h	5 Jun 2004 16:32:00 -0000	1.28
@@ -232,18 +232,18 @@
 };
 
 dbus_bool_t dbus_connection_register_object_path   (DBusConnection              *connection,
-                                                    const char                 **path,
+                                                    const char                  *path,
                                                     const DBusObjectPathVTable  *vtable,
                                                     void                        *user_data);
 dbus_bool_t dbus_connection_register_fallback      (DBusConnection              *connection,
-                                                    const char                 **path,
+                                                    const char                  *path,
                                                     const DBusObjectPathVTable  *vtable,
                                                     void                        *user_data);
-void        dbus_connection_unregister_object_path (DBusConnection              *connection,
-                                                    const char                 **path);
+dbus_bool_t dbus_connection_unregister_object_path (DBusConnection              *connection,
+                                                    const char                  *path);
 
 dbus_bool_t dbus_connection_list_registered        (DBusConnection              *connection,
-                                                    const char                 **parent_path,
+                                                    const char                  *parent_path,
                                                     char                      ***child_entries);
 
 DBUS_END_DECLS;

Index: dbus-connection.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-connection.c,v
retrieving revision 1.79
retrieving revision 1.80
diff -u -d -r1.79 -r1.80
--- a/dbus-connection.c	17 May 2004 09:43:24 -0000	1.79
+++ b/dbus-connection.c	5 Jun 2004 16:32:00 -0000	1.80
@@ -37,6 +37,7 @@
 #include "dbus-string.h"
 #include "dbus-pending-call.h"
 #include "dbus-object-tree.h"
+#include "dbus-marshal.h"
 
 #if 0
 #define CONNECTION_LOCK(connection)   do {                      \
@@ -3151,33 +3152,39 @@
  *
  *
  * @param connection the connection
- * @param path #NULL-terminated array of path elements
+ * @param path a '/' delimited string of path elements
  * @param vtable the virtual table
  * @param user_data data to pass to functions in the vtable
  * @returns #FALSE if not enough memory
  */
 dbus_bool_t
 dbus_connection_register_object_path (DBusConnection              *connection,
-                                      const char                 **path,
+                                      const char                  *path,
                                       const DBusObjectPathVTable  *vtable,
                                       void                        *user_data)
 {
+  char **decomposed_path;
   dbus_bool_t retval;
   
   _dbus_return_val_if_fail (connection != NULL, FALSE);
   _dbus_return_val_if_fail (path != NULL, FALSE);
-  _dbus_return_val_if_fail (path[0] != NULL, FALSE);
+  _dbus_return_val_if_fail (path[0] == '/', FALSE);
   _dbus_return_val_if_fail (vtable != NULL, FALSE);
 
+  if (!_dbus_decompose_path (path, strlen (path), &decomposed_path, NULL))
+    return FALSE;
+
   CONNECTION_LOCK (connection);
 
   retval = _dbus_object_tree_register (connection->objects,
                                        FALSE,
-                                       path, vtable,
+                                       (const char **) decomposed_path, vtable,
                                        user_data);
 
   CONNECTION_UNLOCK (connection);
 
+  dbus_free_string_array (decomposed_path);
+
   return retval;
 }
 
@@ -3188,33 +3195,39 @@
  * policy for a whole "subdirectory."
  *
  * @param connection the connection
- * @param path #NULL-terminated array of path elements
+ * @param path a '/' delimited string of path elements
  * @param vtable the virtual table
  * @param user_data data to pass to functions in the vtable
  * @returns #FALSE if not enough memory
  */
 dbus_bool_t
 dbus_connection_register_fallback (DBusConnection              *connection,
-                                   const char                 **path,
+                                   const char                  *path,
                                    const DBusObjectPathVTable  *vtable,
                                    void                        *user_data)
 {
+  char **decomposed_path;
   dbus_bool_t retval;
   
   _dbus_return_val_if_fail (connection != NULL, FALSE);
   _dbus_return_val_if_fail (path != NULL, FALSE);
-  _dbus_return_val_if_fail (path[0] != NULL, FALSE);
+  _dbus_return_val_if_fail (path[0] == '/', FALSE);
   _dbus_return_val_if_fail (vtable != NULL, FALSE);
 
+  if (!_dbus_decompose_path (path, strlen (path), &decomposed_path, NULL))
+    return FALSE;
+
   CONNECTION_LOCK (connection);
 
   retval = _dbus_object_tree_register (connection->objects,
                                        TRUE,
-                                       path, vtable,
+				       (const char **) decomposed_path, vtable,
                                        user_data);
 
   CONNECTION_UNLOCK (connection);
 
+  dbus_free_string_array (decomposed_path);
+
   return retval;
 }
 
@@ -3224,19 +3237,29 @@
  * Can unregister both fallback paths and object paths.
  *
  * @param connection the connection
- * @param path the #NULL-terminated array of path elements
+ * @param path a '/' delimited string of path elements
+ * @returns #FALSE if not enough memory
  */
-void
+dbus_bool_t
 dbus_connection_unregister_object_path (DBusConnection              *connection,
-                                        const char                 **path)
+                                        const char                  *path)
 {
-  _dbus_return_if_fail (connection != NULL);
-  _dbus_return_if_fail (path != NULL);
-  _dbus_return_if_fail (path[0] != NULL);
+  char **decomposed_path;
+
+  _dbus_return_val_if_fail (connection != NULL, FALSE);
+  _dbus_return_val_if_fail (path != NULL, FALSE);
+  _dbus_return_val_if_fail (path[0] == '/', FALSE);
+
+  if (!_dbus_decompose_path (path, strlen (path), &decomposed_path, NULL))
+      return FALSE;
 
   CONNECTION_LOCK (connection);
 
-  _dbus_object_tree_unregister_and_unlock (connection->objects, path);
+  _dbus_object_tree_unregister_and_unlock (connection->objects, (const char **) decomposed_path);
+
+  dbus_free_string_array (decomposed_path);
+
+  return TRUE;
 }
 
 /**
@@ -3251,18 +3274,27 @@
  */
 dbus_bool_t
 dbus_connection_list_registered (DBusConnection              *connection,
-                                 const char                 **parent_path,
+                                 const char                  *parent_path,
                                  char                      ***child_entries)
 {
+  char **decomposed_path;
+  dbus_bool_t retval;
   _dbus_return_val_if_fail (connection != NULL, FALSE);
   _dbus_return_val_if_fail (parent_path != NULL, FALSE);
+  _dbus_return_val_if_fail (parent_path[0] == '/', FALSE);
   _dbus_return_val_if_fail (child_entries != NULL, FALSE);
 
+  if (!_dbus_decompose_path (parent_path, strlen (parent_path), &decomposed_path, NULL))
+    return FALSE;
+
   CONNECTION_LOCK (connection);
 
-  return _dbus_object_tree_list_registered_and_unlock (connection->objects,
-                                                       parent_path,
-                                                       child_entries);
+  retval = _dbus_object_tree_list_registered_and_unlock (connection->objects,
+							 (const char **) decomposed_path,
+							 child_entries);
+  dbus_free_string_array (decomposed_path);
+
+  return retval;
 }
 
 static DBusDataSlotAllocator slot_allocator;




More information about the dbus-commit mailing list