diff options
author | Olivier Andrieu <oliv__a@users.sourceforge.net> | 2004-06-05 16:32:00 +0000 |
---|---|---|
committer | Olivier Andrieu <oliv__a@users.sourceforge.net> | 2004-06-05 16:32:00 +0000 |
commit | 96f6740f2fbc16c7ee220d3d5abdc94e22da78f3 (patch) | |
tree | 6f7bb5afb73db345ab173311f0c919df5695b346 /dbus | |
parent | 63de4681299428db8be68bab64b969e0c1229273 (diff) |
2004-06-05 Olivier Andrieu <oliv__a@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.
Diffstat (limited to 'dbus')
-rw-r--r-- | dbus/dbus-connection.c | 70 | ||||
-rw-r--r-- | dbus/dbus-connection.h | 10 | ||||
-rw-r--r-- | dbus/dbus-marshal.c | 67 | ||||
-rw-r--r-- | dbus/dbus-marshal.h | 4 |
4 files changed, 106 insertions, 45 deletions
diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c index 524cef6b..9b59338b 100644 --- a/dbus/dbus-connection.c +++ b/dbus/dbus-connection.c @@ -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 @@ dbus_connection_remove_filter (DBusConnection *connection, * * * @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 @@ dbus_connection_register_object_path (DBusConnection *connection, * 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 @@ dbus_connection_register_fallback (DBusConnection *connection, * 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_connection_unregister_object_path (DBusConnection *connection, */ 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; diff --git a/dbus/dbus-connection.h b/dbus/dbus-connection.h index 0fe4eba2..5dcbc8c0 100644 --- a/dbus/dbus-connection.h +++ b/dbus/dbus-connection.h @@ -232,18 +232,18 @@ struct DBusObjectPathVTable }; 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; diff --git a/dbus/dbus-marshal.c b/dbus/dbus-marshal.c index 9856930f..01bb6a17 100644 --- a/dbus/dbus-marshal.c +++ b/dbus/dbus-marshal.c @@ -1478,7 +1478,7 @@ _dbus_demarshal_basic_type_array (const DBusString *str, 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 @@ _dbus_demarshal_string_array (const DBusString *str, #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 @@ _dbus_demarshal_object_path (const DBusString *str, 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 @@ _dbus_marshal_test (void) 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 @@ _dbus_marshal_test (void) /* 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 */ diff --git a/dbus/dbus-marshal.h b/dbus/dbus-marshal.h index 1c34c531..bf205ba4 100644 --- a/dbus/dbus-marshal.h +++ b/dbus/dbus-marshal.h @@ -311,6 +311,10 @@ dbus_bool_t _dbus_demarshal_string_array (const DBusString *str, 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, |