From 3f1ad214b5e5c63697ee208d459b304a4ef6e79b Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Mon, 7 Jul 2003 00:47:01 +0000 Subject: 2003-07-06 Havoc Pennington * dbus/dbus-marshal.c (_dbus_marshal_set_object_id): new function (_dbus_marshal_object_id): new (_dbus_demarshal_object_id): new (_dbus_marshal_get_arg_end_pos): support object ID type, and consolidate identical switch cases. Don't conditionalize handling of DBUS_TYPE_UINT64, need to handle the type always. (_dbus_marshal_validate_arg): consolidate identical cases, and handle DBUS_TYPE_OBJECT_ID * dbus/dbus-objectid.c: new file with DBusObjectID data type. * dbus/dbus-protocol.h: add DBUS_TYPE_OBJECT_ID --- dbus/dbus-marshal.c | 157 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 123 insertions(+), 34 deletions(-) (limited to 'dbus/dbus-marshal.c') diff --git a/dbus/dbus-marshal.c b/dbus/dbus-marshal.c index 5d7290e3..2399a282 100644 --- a/dbus/dbus-marshal.c +++ b/dbus/dbus-marshal.c @@ -80,6 +80,19 @@ typedef union dbus_uint64_t u; #endif double d; +#ifdef WORDS_BIGENDIAN + struct + { + dbus_uint32_t high; + dbus_uint32_t low; + } bits; +#else + struct + { + dbus_uint32_t low; + dbus_uint32_t high; + } bits; +#endif } DBusOctets8; static DBusOctets8 @@ -423,6 +436,35 @@ _dbus_marshal_set_string (DBusString *str, return TRUE; } +/** + * Sets the existing marshaled object ID at the given offset to a new + * value. The given offset must point to an existing object ID or this + * function doesn't make sense. + * + * @param str the string to write the marshalled string to + * @param offset the byte offset where string should be written + * @param byte_order the byte order to use + * @param value the new value + */ +void +_dbus_marshal_set_object_id (DBusString *str, + int byte_order, + int offset, + const DBusObjectID *value) +{ + DBusOctets8 r; +#ifdef DBUS_HAVE_INT64 + r.u = dbus_object_id_get_as_integer (value); +#else + r.bits.low = dbus_object_id_get_low_bits (value); + r.bits.high = dbus_object_id_get_high_bits (value); +#endif + _dbus_assert (r.bits.low == dbus_object_id_get_low_bits (value)); + _dbus_assert (r.bits.high == dbus_object_id_get_high_bits (value)); + + set_8_octets (str, byte_order, offset, r); +} + static dbus_bool_t marshal_4_octets (DBusString *str, int byte_order, @@ -844,6 +886,32 @@ _dbus_marshal_string_array (DBusString *str, return FALSE; } +/** + * Marshals an object ID value. + * + * @param str the string to append the marshalled value to + * @param byte_order the byte order to use + * @param value the value + * @returns #TRUE on success + */ +dbus_bool_t +_dbus_marshal_object_id (DBusString *str, + int byte_order, + const DBusObjectID *value) +{ + DBusOctets8 r; +#ifdef DBUS_HAVE_INT64 + r.u = dbus_object_id_get_as_integer (value); +#else + r.bits.low = dbus_object_id_get_low_bits (value); + r.bits.high = dbus_object_id_get_high_bits (value); +#endif + _dbus_assert (r.bits.low == dbus_object_id_get_low_bits (value)); + _dbus_assert (r.bits.high == dbus_object_id_get_high_bits (value)); + + return marshal_8_octets (str, byte_order, r); +} + static dbus_uint32_t demarshal_4_octets (const DBusString *str, int byte_order, @@ -1393,6 +1461,36 @@ _dbus_demarshal_string_array (const DBusString *str, return FALSE; } +/** + * Demarshals an object ID. + * + * @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 value address to store new object ID + */ +void +_dbus_demarshal_object_id (const DBusString *str, + int byte_order, + int pos, + int *new_pos, + DBusObjectID *value) +{ + DBusOctets8 r; + + r = demarshal_8_octets (str, byte_order, pos, new_pos); + +#ifdef DBUS_HAVE_INT64 + dbus_object_id_set_as_integer (value, r.u); +#else + dbus_object_id_set_low_bits (value, r.bits.low); + dbus_object_id_set_high_bits (value, r.bits.high); +#endif + _dbus_assert (dbus_object_id_get_low_bits (value) == r.bits.low); + _dbus_assert (dbus_object_id_get_high_bits (value) == r.bits.high); +} + /** * Returns the position right after the end of an argument. PERFORMS * NO VALIDATION WHATSOEVER. The message must have been previously @@ -1435,30 +1533,16 @@ _dbus_marshal_get_arg_end_pos (const DBusString *str, break; case DBUS_TYPE_INT32: - *end_pos = _DBUS_ALIGN_VALUE (pos, sizeof (dbus_int32_t)) + sizeof (dbus_int32_t); - - break; - case DBUS_TYPE_UINT32: - *end_pos = _DBUS_ALIGN_VALUE (pos, sizeof (dbus_uint32_t)) + sizeof (dbus_uint32_t); - + *end_pos = _DBUS_ALIGN_VALUE (pos, 4) + 4; break; -#ifdef DBUS_HAVE_INT64 case DBUS_TYPE_INT64: - *end_pos = _DBUS_ALIGN_VALUE (pos, sizeof (dbus_int64_t)) + sizeof (dbus_int64_t); - - break; - case DBUS_TYPE_UINT64: - *end_pos = _DBUS_ALIGN_VALUE (pos, sizeof (dbus_uint64_t)) + sizeof (dbus_uint64_t); - - break; -#endif /* DBUS_HAVE_INT64 */ - + case DBUS_TYPE_OBJECT_ID: case DBUS_TYPE_DOUBLE: - *end_pos = _DBUS_ALIGN_VALUE (pos, sizeof (double)) + sizeof (double); - + + *end_pos = _DBUS_ALIGN_VALUE (pos, 8) + 8; break; case DBUS_TYPE_STRING: @@ -1717,6 +1801,7 @@ validate_array_data (const DBusString *str, case DBUS_TYPE_INT64: case DBUS_TYPE_UINT64: case DBUS_TYPE_DOUBLE: + case DBUS_TYPE_OBJECT_ID: /* Call validate arg one time to check alignment padding * at start of array */ @@ -1842,22 +1927,9 @@ _dbus_marshal_validate_arg (const DBusString *str, break; case DBUS_TYPE_INT64: - case DBUS_TYPE_UINT64: - { - int align_8 = _DBUS_ALIGN_VALUE (pos, 8); - - if (!_dbus_string_validate_nul (str, pos, - align_8 - pos)) - { - _dbus_verbose ("int64/uint64 alignment padding not initialized to nul\n"); - return FALSE; - } - - *end_pos = align_8 + 8; - } - break; - + case DBUS_TYPE_UINT64: case DBUS_TYPE_DOUBLE: + case DBUS_TYPE_OBJECT_ID: { int align_8 = _DBUS_ALIGN_VALUE (pos, 8); @@ -1866,7 +1938,7 @@ _dbus_marshal_validate_arg (const DBusString *str, if (!_dbus_string_validate_nul (str, pos, align_8 - pos)) { - _dbus_verbose ("double alignment padding not initialized to nul\n"); + _dbus_verbose ("double/int64/uint64/objid alignment padding not initialized to nul\n"); return FALSE; } @@ -2177,6 +2249,7 @@ _dbus_marshal_test (void) #endif char *s; DBusString t; + DBusObjectID obj_id, obj_id2; if (!_dbus_string_init (&str)) _dbus_assert_not_reached ("failed to init string"); @@ -2237,6 +2310,22 @@ _dbus_marshal_test (void) if (!(_dbus_demarshal_uint64 (&str, DBUS_LITTLE_ENDIAN, pos, &pos) == DBUS_UINT64_CONSTANT (0x123456789abc7))) _dbus_assert_not_reached ("demarshal failed"); #endif /* DBUS_HAVE_INT64 */ + + /* Marshal object IDs */ + dbus_object_id_set_high_bits (&obj_id, 0xfffe); + dbus_object_id_set_low_bits (&obj_id, 0xaacc); + + if (!_dbus_marshal_object_id (&str, DBUS_BIG_ENDIAN, &obj_id)) + _dbus_assert_not_reached ("could not marshal object ID value"); + _dbus_demarshal_object_id (&str, DBUS_BIG_ENDIAN, pos, &pos, &obj_id2); + if (!dbus_object_id_equal (&obj_id, &obj_id2)) + _dbus_assert_not_reached ("demarshal failed"); + + if (!_dbus_marshal_object_id (&str, DBUS_LITTLE_ENDIAN, &obj_id)) + _dbus_assert_not_reached ("could not marshal object ID value"); + _dbus_demarshal_object_id (&str, DBUS_LITTLE_ENDIAN, pos, &pos, &obj_id2); + if (!dbus_object_id_equal (&obj_id, &obj_id2)) + _dbus_assert_not_reached ("demarshal failed"); /* Marshal strings */ tmp1 = "This is the dbus test string"; -- cgit From fe195a911d86d0a71349988360de65cfac1b3f86 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Sat, 2 Aug 2003 01:59:14 +0000 Subject: 2003-08-01 Havoc Pennington * dbus/dbus-protocol.h (DBUS_MESSAGE_TYPE_*): introduce a message type enum to distinguish kinds of message (DBUS_HEADER_FLAG_NO_REPLY_EXPECTED): flag for a message that need not be replied to 2003-08-01 Havoc Pennington * dbus/dbus-marshal.c: adapt to DBusObjectID changes (unpack_8_octets): fix no-64-bit-int bug * dbus/dbus-object-registry.c (validate_id): validate the connection ID bits, not just the instance ID. * dbus/dbus-connection.c (_dbus_connection_init_id): initialize the connection-global 33 bits of the object ID * dbus/dbus-object-registry.c (info_from_entry): fill in object ID in the new way * dbus/dbus-objectid.h: rather than high/low bits, specifically define server/client/instance bits. --- dbus/dbus-marshal.c | 55 +++++++++++++---------------------------------------- 1 file changed, 13 insertions(+), 42 deletions(-) (limited to 'dbus/dbus-marshal.c') diff --git a/dbus/dbus-marshal.c b/dbus/dbus-marshal.c index 2399a282..aaf97c7c 100644 --- a/dbus/dbus-marshal.c +++ b/dbus/dbus-marshal.c @@ -80,19 +80,7 @@ typedef union dbus_uint64_t u; #endif double d; -#ifdef WORDS_BIGENDIAN - struct - { - dbus_uint32_t high; - dbus_uint32_t low; - } bits; -#else - struct - { - dbus_uint32_t low; - dbus_uint32_t high; - } bits; -#endif + DBusObjectID object_id; } DBusOctets8; static DBusOctets8 @@ -111,7 +99,8 @@ unpack_8_octets (int byte_order, r.u = DBUS_UINT64_FROM_BE (*(dbus_uint64_t*)data); #else r.d = *(double*)data; - swap_bytes (&r, sizeof (r)); + if (byte_order != DBUS_COMPILER_BYTE_ORDER) + swap_bytes ((unsigned char*) &r, sizeof (r)); #endif return r; @@ -453,14 +442,8 @@ _dbus_marshal_set_object_id (DBusString *str, const DBusObjectID *value) { DBusOctets8 r; -#ifdef DBUS_HAVE_INT64 - r.u = dbus_object_id_get_as_integer (value); -#else - r.bits.low = dbus_object_id_get_low_bits (value); - r.bits.high = dbus_object_id_get_high_bits (value); -#endif - _dbus_assert (r.bits.low == dbus_object_id_get_low_bits (value)); - _dbus_assert (r.bits.high == dbus_object_id_get_high_bits (value)); + + r.object_id = *value; set_8_octets (str, byte_order, offset, r); } @@ -724,7 +707,7 @@ marshal_8_octets_array (DBusString *str, #ifdef DBUS_HAVE_INT64 *((dbus_uint64_t*)d) = DBUS_UINT64_SWAP_LE_BE (*((dbus_uint64_t*)d)); #else - swap_bytes (d, 8); + swap_bytes ((unsigned char*) d, 8); #endif d += 8; } @@ -900,14 +883,8 @@ _dbus_marshal_object_id (DBusString *str, const DBusObjectID *value) { DBusOctets8 r; -#ifdef DBUS_HAVE_INT64 - r.u = dbus_object_id_get_as_integer (value); -#else - r.bits.low = dbus_object_id_get_low_bits (value); - r.bits.high = dbus_object_id_get_high_bits (value); -#endif - _dbus_assert (r.bits.low == dbus_object_id_get_low_bits (value)); - _dbus_assert (r.bits.high == dbus_object_id_get_high_bits (value)); + + r.object_id = *value; return marshal_8_octets (str, byte_order, r); } @@ -1242,7 +1219,7 @@ demarshal_8_octets_array (const DBusString *str, #ifdef DBUS_HAVE_INT64 retval[i].u = DBUS_UINT64_SWAP_LE_BE (retval[i].u); #else - swap_bytes (&retval[i], 8); + swap_bytes ((unsigned char *) &retval[i], 8); #endif } } @@ -1481,14 +1458,7 @@ _dbus_demarshal_object_id (const DBusString *str, r = demarshal_8_octets (str, byte_order, pos, new_pos); -#ifdef DBUS_HAVE_INT64 - dbus_object_id_set_as_integer (value, r.u); -#else - dbus_object_id_set_low_bits (value, r.bits.low); - dbus_object_id_set_high_bits (value, r.bits.high); -#endif - _dbus_assert (dbus_object_id_get_low_bits (value) == r.bits.low); - _dbus_assert (dbus_object_id_get_high_bits (value) == r.bits.high); + *value = r.object_id; } /** @@ -2312,8 +2282,9 @@ _dbus_marshal_test (void) #endif /* DBUS_HAVE_INT64 */ /* Marshal object IDs */ - dbus_object_id_set_high_bits (&obj_id, 0xfffe); - dbus_object_id_set_low_bits (&obj_id, 0xaacc); + dbus_object_id_set_server_bits (&obj_id, 0xfffe); + dbus_object_id_set_client_bits (&obj_id, 0xaacc); + dbus_object_id_set_instance_bits (&obj_id, 0x70f00f0f); if (!_dbus_marshal_object_id (&str, DBUS_BIG_ENDIAN, &obj_id)) _dbus_assert_not_reached ("could not marshal object ID value"); -- cgit From 8d38a2e2c5dc95de992c4d856ec1b0c0948bca3e Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Fri, 29 Aug 2003 01:05:00 +0000 Subject: 2003-08-28 Havoc Pennington purge DBusObjectID * dbus/dbus-connection.c: port to no ObjectID, create a DBusObjectTree, rename ObjectTree to ObjectPath in public API * dbus/dbus-connection.h (struct DBusObjectTreeVTable): delete everything except UnregisterFunction and MessageFunction * dbus/dbus-marshal.c: port away from DBusObjectID, add DBUS_TYPE_OBJECT_PATH * dbus/dbus-object-registry.[hc], dbus/dbus-object.[hc], dbus/dbus-objectid.[hc]: remove these, we are moving to path-based object IDs --- dbus/dbus-marshal.c | 105 ++++++++++++++++++++++------------------------------ 1 file changed, 44 insertions(+), 61 deletions(-) (limited to 'dbus/dbus-marshal.c') diff --git a/dbus/dbus-marshal.c b/dbus/dbus-marshal.c index aaf97c7c..449dd33a 100644 --- a/dbus/dbus-marshal.c +++ b/dbus/dbus-marshal.c @@ -80,7 +80,6 @@ typedef union dbus_uint64_t u; #endif double d; - DBusObjectID object_id; } DBusOctets8; static DBusOctets8 @@ -426,26 +425,27 @@ _dbus_marshal_set_string (DBusString *str, } /** - * Sets the existing marshaled object ID at the given offset to a new - * value. The given offset must point to an existing object ID or this + * Sets the existing marshaled object path at the given offset to a new + * value. The given offset must point to an existing object path or this * function doesn't make sense. * - * @param str the string to write the marshalled string to - * @param offset the byte offset where string should be written + * @todo implement this function + * + * @param str the string to write the marshalled path to + * @param offset the byte offset where path should be written * @param byte_order the byte order to use - * @param value the new value + * @param path the new path + * @param path_len number of elements in the path */ void -_dbus_marshal_set_object_id (DBusString *str, - int byte_order, - int offset, - const DBusObjectID *value) +_dbus_marshal_set_object_path (DBusString *str, + int byte_order, + int offset, + const char **path, + int path_len) { - DBusOctets8 r; - - r.object_id = *value; - - set_8_octets (str, byte_order, offset, r); + + /* FIXME */ } static dbus_bool_t @@ -870,23 +870,23 @@ _dbus_marshal_string_array (DBusString *str, } /** - * Marshals an object ID value. + * Marshals an object path value. * + * @todo implement this function + * * @param str the string to append the marshalled value to * @param byte_order the byte order to use - * @param value the value + * @param path the path + * @param path_len length of the path * @returns #TRUE on success */ dbus_bool_t -_dbus_marshal_object_id (DBusString *str, - int byte_order, - const DBusObjectID *value) +_dbus_marshal_object_path (DBusString *str, + int byte_order, + const char **path, + int path_len) { - DBusOctets8 r; - - r.object_id = *value; - - return marshal_8_octets (str, byte_order, r); + return TRUE; } static dbus_uint32_t @@ -1439,26 +1439,26 @@ _dbus_demarshal_string_array (const DBusString *str, } /** - * Demarshals an object ID. + * Demarshals an object path. * + * @todo implement this function + * * @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 value address to store new object ID + * @param path address to store new object path + * @param path_len length of stored path */ -void -_dbus_demarshal_object_id (const DBusString *str, - int byte_order, - int pos, - int *new_pos, - DBusObjectID *value) +dbus_bool_t +_dbus_demarshal_object_path (const DBusString *str, + int byte_order, + int pos, + int *new_pos, + char ***path, + int *path_len) { - DBusOctets8 r; - - r = demarshal_8_octets (str, byte_order, pos, new_pos); - - *value = r.object_id; + } /** @@ -1509,7 +1509,6 @@ _dbus_marshal_get_arg_end_pos (const DBusString *str, case DBUS_TYPE_INT64: case DBUS_TYPE_UINT64: - case DBUS_TYPE_OBJECT_ID: case DBUS_TYPE_DOUBLE: *end_pos = _DBUS_ALIGN_VALUE (pos, 8) + 8; @@ -1541,7 +1540,8 @@ _dbus_marshal_get_arg_end_pos (const DBusString *str, *end_pos = pos + len; } break; - + + case DBUS_TYPE_OBJECT_PATH: case DBUS_TYPE_ARRAY: { int len; @@ -1718,6 +1718,7 @@ validate_array_data (const DBusString *str, case DBUS_TYPE_NIL: break; + case DBUS_TYPE_OBJECT_PATH: case DBUS_TYPE_STRING: case DBUS_TYPE_NAMED: case DBUS_TYPE_ARRAY: @@ -1771,7 +1772,6 @@ validate_array_data (const DBusString *str, case DBUS_TYPE_INT64: case DBUS_TYPE_UINT64: case DBUS_TYPE_DOUBLE: - case DBUS_TYPE_OBJECT_ID: /* Call validate arg one time to check alignment padding * at start of array */ @@ -1802,7 +1802,9 @@ validate_array_data (const DBusString *str, * * @todo For array types that can't be invalid, we should not * walk the whole array validating it. e.g. just skip all the - * int values in an int array. + * int values in an int array. (maybe this is already done now -hp) + * + * @todo support DBUS_TYPE_OBJECT_PATH * * @param str a string * @param byte_order the byte order to use @@ -1899,7 +1901,6 @@ _dbus_marshal_validate_arg (const DBusString *str, case DBUS_TYPE_INT64: case DBUS_TYPE_UINT64: case DBUS_TYPE_DOUBLE: - case DBUS_TYPE_OBJECT_ID: { int align_8 = _DBUS_ALIGN_VALUE (pos, 8); @@ -2219,7 +2220,6 @@ _dbus_marshal_test (void) #endif char *s; DBusString t; - DBusObjectID obj_id, obj_id2; if (!_dbus_string_init (&str)) _dbus_assert_not_reached ("failed to init string"); @@ -2280,23 +2280,6 @@ _dbus_marshal_test (void) if (!(_dbus_demarshal_uint64 (&str, DBUS_LITTLE_ENDIAN, pos, &pos) == DBUS_UINT64_CONSTANT (0x123456789abc7))) _dbus_assert_not_reached ("demarshal failed"); #endif /* DBUS_HAVE_INT64 */ - - /* Marshal object IDs */ - dbus_object_id_set_server_bits (&obj_id, 0xfffe); - dbus_object_id_set_client_bits (&obj_id, 0xaacc); - dbus_object_id_set_instance_bits (&obj_id, 0x70f00f0f); - - if (!_dbus_marshal_object_id (&str, DBUS_BIG_ENDIAN, &obj_id)) - _dbus_assert_not_reached ("could not marshal object ID value"); - _dbus_demarshal_object_id (&str, DBUS_BIG_ENDIAN, pos, &pos, &obj_id2); - if (!dbus_object_id_equal (&obj_id, &obj_id2)) - _dbus_assert_not_reached ("demarshal failed"); - - if (!_dbus_marshal_object_id (&str, DBUS_LITTLE_ENDIAN, &obj_id)) - _dbus_assert_not_reached ("could not marshal object ID value"); - _dbus_demarshal_object_id (&str, DBUS_LITTLE_ENDIAN, pos, &pos, &obj_id2); - if (!dbus_object_id_equal (&obj_id, &obj_id2)) - _dbus_assert_not_reached ("demarshal failed"); /* Marshal strings */ tmp1 = "This is the dbus test string"; -- cgit From 5fd1e389e1c1c12ad4a55c2af6abdc8e7a2f6d41 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Sun, 31 Aug 2003 01:51:44 +0000 Subject: 2003-08-30 Havoc Pennington * test/data/valid-config-files/system.d/test.conf: change to root for the user so warnings don't get printed * dbus/dbus-message.c: add dbus_message_get_path, dbus_message_set_path * dbus/dbus-object-tree.c (do_test_dispatch): add test of dispatching to a path * dbus/dbus-string.c (_dbus_string_validate_path): add * dbus/dbus-marshal.c (_dbus_demarshal_object_path): implement (_dbus_marshal_object_path): implement * dbus/dbus-protocol.h (DBUS_HEADER_FIELD_PATH): new header field to contain the path to the target object (DBUS_HEADER_FIELD_SENDER_SERVICE): rename DBUS_HEADER_FIELD_SENDER to explicitly say it's the sender service --- dbus/dbus-marshal.c | 127 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 120 insertions(+), 7 deletions(-) (limited to 'dbus/dbus-marshal.c') diff --git a/dbus/dbus-marshal.c b/dbus/dbus-marshal.c index 449dd33a..6343056e 100644 --- a/dbus/dbus-marshal.c +++ b/dbus/dbus-marshal.c @@ -871,8 +871,6 @@ _dbus_marshal_string_array (DBusString *str, /** * Marshals an object path value. - * - * @todo implement this function * * @param str the string to append the marshalled value to * @param byte_order the byte order to use @@ -886,7 +884,41 @@ _dbus_marshal_object_path (DBusString *str, const char **path, int path_len) { + int array_start, old_string_len; + int i; + + old_string_len = _dbus_string_get_length (str); + + /* Set the length to 0 temporarily */ + if (!_dbus_marshal_uint32 (str, byte_order, 0)) + goto nomem; + + array_start = _dbus_string_get_length (str); + + i = 0; + while (i < path_len) + { + if (!_dbus_string_append_byte (str, '/')) + goto nomem; + + if (!_dbus_string_append (str, path[0])) + goto nomem; + + ++i; + } + + /* Write the length now that we know it */ + _dbus_marshal_set_uint32 (str, byte_order, + _DBUS_ALIGN_VALUE (old_string_len, sizeof(dbus_uint32_t)), + _dbus_string_get_length (str) - array_start); + return TRUE; + + nomem: + /* Restore the previous length */ + _dbus_string_set_length (str, old_string_len); + + return FALSE; } static dbus_uint32_t @@ -1438,10 +1470,10 @@ _dbus_demarshal_string_array (const DBusString *str, return FALSE; } +#define VERBOSE_DECOMPOSE 0 + /** * Demarshals an object path. - * - * @todo implement this function * * @param str the string containing the data * @param byte_order the byte order @@ -1458,7 +1490,82 @@ _dbus_demarshal_object_path (const DBusString *str, 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 + _dbus_verbose ("Decomposing path \"%s\"\n", + data); +#endif + + n_components = 0; + i = 0; + while (i < len) + { + if (data[i] == '/') + n_components += 1; + ++i; + } + + retval = dbus_new0 (char*, n_components + 1); + + if (retval == NULL) + return FALSE; + + comp = 0; + i = 0; + while (i < len) + { + if (data[i] == '/') + ++i; + j = i; + + while (j < len && data[j] != '/') + ++j; + + /* Now [i, j) is the path component */ + _dbus_assert (i < j); + _dbus_assert (data[i] != '/'); + _dbus_assert (j == len || data[j] == '/'); + +#if VERBOSE_DECOMPOSE + _dbus_verbose (" (component in [%d,%d))\n", + i, j); +#endif + + retval[comp] = _dbus_memdup (&data[i], j - i + 1); + if (retval[comp] == NULL) + { + dbus_free_string_array (retval); + return FALSE; + } + retval[comp][j-i] = '\0'; +#if VERBOSE_DECOMPOSE + _dbus_verbose (" (component %d = \"%s\")\n", + comp, retval[comp]); +#endif + + ++comp; + i = j; + } + _dbus_assert (i == len); + _dbus_assert (retval[0] != NULL); + + *path = retval; + if (path_len) + *path_len = n_components; + if (new_pos) + *new_pos = pos + len + 1; + + return TRUE; } /** @@ -1514,6 +1621,7 @@ _dbus_marshal_get_arg_end_pos (const DBusString *str, *end_pos = _DBUS_ALIGN_VALUE (pos, 8) + 8; break; + case DBUS_TYPE_OBJECT_PATH: case DBUS_TYPE_STRING: { int len; @@ -1540,8 +1648,7 @@ _dbus_marshal_get_arg_end_pos (const DBusString *str, *end_pos = pos + len; } break; - - case DBUS_TYPE_OBJECT_PATH: + case DBUS_TYPE_ARRAY: { int len; @@ -1917,6 +2024,7 @@ _dbus_marshal_validate_arg (const DBusString *str, } break; + case DBUS_TYPE_OBJECT_PATH: case DBUS_TYPE_STRING: { int len; @@ -1930,6 +2038,12 @@ _dbus_marshal_validate_arg (const DBusString *str, if (!validate_string (str, pos, len, end_pos)) return FALSE; + + if (type == DBUS_TYPE_OBJECT_PATH) + { + if (!_dbus_string_validate_path (str, pos, len)) + return FALSE; + } } break; @@ -2521,7 +2635,6 @@ _dbus_marshal_test (void) s = _dbus_demarshal_string (&str, DBUS_BIG_ENDIAN, 0, NULL); _dbus_assert (strcmp (s, "Hello") == 0); dbus_free (s); - _dbus_string_free (&str); -- cgit From fdb114e5cce2790fd3c68cfa13113c7b59b83e4e Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Sun, 31 Aug 2003 17:26:22 +0000 Subject: 2003-08-31 Havoc Pennington * fix build with --disable-tests --- dbus/dbus-marshal.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'dbus/dbus-marshal.c') diff --git a/dbus/dbus-marshal.c b/dbus/dbus-marshal.c index 6343056e..5297cb67 100644 --- a/dbus/dbus-marshal.c +++ b/dbus/dbus-marshal.c @@ -1906,12 +1906,6 @@ validate_array_data (const DBusString *str, * returns #TRUE if a valid arg begins at "pos" * * @todo security: need to audit this function. - * - * @todo For array types that can't be invalid, we should not - * walk the whole array validating it. e.g. just skip all the - * int values in an int array. (maybe this is already done now -hp) - * - * @todo support DBUS_TYPE_OBJECT_PATH * * @param str a string * @param byte_order the byte order to use -- cgit From d021cfae6695f0f44102edf758abfc42e2f3c093 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Wed, 3 Sep 2003 02:08:25 +0000 Subject: 2003-09-01 Havoc Pennington * glib/dbus-gparser.c: implement * glib/dbus-gobject.c: start implementing skeletons support * configure.in: when disabling checks/assert, also define G_DISABLE_ASSERT and G_DISABLE_CHECKS --- dbus/dbus-marshal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'dbus/dbus-marshal.c') diff --git a/dbus/dbus-marshal.c b/dbus/dbus-marshal.c index 5297cb67..c542ee8b 100644 --- a/dbus/dbus-marshal.c +++ b/dbus/dbus-marshal.c @@ -1473,7 +1473,8 @@ _dbus_demarshal_string_array (const DBusString *str, #define VERBOSE_DECOMPOSE 0 /** - * Demarshals an object path. + * 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 @@ -1556,7 +1557,6 @@ _dbus_demarshal_object_path (const DBusString *str, i = j; } _dbus_assert (i == len); - _dbus_assert (retval[0] != NULL); *path = retval; if (path_len) -- cgit From 85ab0327d82e4945ad16630e583d8cc68df25a90 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Sun, 7 Sep 2003 23:04:54 +0000 Subject: 2003-09-07 Havoc Pennington * Make Doxygen contented. --- dbus/dbus-marshal.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'dbus/dbus-marshal.c') diff --git a/dbus/dbus-marshal.c b/dbus/dbus-marshal.c index c542ee8b..3d6184e9 100644 --- a/dbus/dbus-marshal.c +++ b/dbus/dbus-marshal.c @@ -73,13 +73,17 @@ swap_bytes (unsigned char *data, } #endif /* !DBUS_HAVE_INT64 */ +/** + * Union used to manipulate 8 bytes as if they + * were various types. + */ typedef union { #ifdef DBUS_HAVE_INT64 - dbus_int64_t s; - dbus_uint64_t u; + dbus_int64_t s; /**< 64-bit integer */ + dbus_uint64_t u; /**< 64-bit unsinged integer */ #endif - double d; + double d; /**< double */ } DBusOctets8; static DBusOctets8 @@ -1470,6 +1474,7 @@ _dbus_demarshal_string_array (const DBusString *str, return FALSE; } +/** Set to 1 to get a bunch of spew about disassembling the path string */ #define VERBOSE_DECOMPOSE 0 /** -- cgit From 46c072e1136ca101aefd5fdae35c457899d55bbb Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Thu, 25 Sep 2003 08:50:14 +0000 Subject: 2003-09-25 Mark McLoughlin * doc/dbus-specification.sgml: don't require header fields to be 4-byte aligned and specify that fields should be distinguished from padding by the fact that zero is not a valid field name. * doc/TODO: remove re-alignment item and add item to doc the OBJECT_PATH type. * dbus/dbus-message.c: (HeaderField): rename the original member to value_offset and introduce a name_offset member to keep track of where the field actually begins. (adjust_field_offsets): remove. (append_int_field), (append_uint_field), (append_string_field): don't align the start of the header field to a 4-byte boundary. (get_next_field): impl finding the next marhsalled field after a given field. (re_align_field_recurse): impl re-aligning a number of already marshalled fields. (delete_field): impl deleting a field of any type and re-aligning any following fields. (delete_int_or_uint_field), (delete_string_field): remove. (set_int_field), (set_uint_field): no need to re-check that we have the correct type for the field. (set_string_field): ditto and impl re-aligning any following fields. (decode_header_data): update to take into account that the fields aren't 4-byte aligned any more and the new way to distinguish padding from header fields. Also, don't exit when there is too much header padding. (process_test_subdir): print the directory. (_dbus_message_test): add test to make sure a following field is re-aligned correctly after field deletion. * dbus/dbus-string.[ch]: (_dbus_string_insert_bytes): rename from insert_byte and allow the insert of multiple bytes. (_dbus_string_test): test inserting multiple bytes. * dbus/dbus-marshal.c: (_dbus_marshal_set_string): add warning note to docs about having to re-align any marshalled values following the string. * dbus/dbus-message-builder.c: (append_string_field), (_dbus_message_data_load): don't align the header field. * dbus/dbus-auth.c: (process_test_subdir): print the directory. * test/break-loader.c: (randomly_add_one_byte): upd. for insert_byte change. * test/data/invalid-messages/bad-header-field-alignment.message: new test case. * test/data/valid-messages/unknown-header-field.message: shove a dict in the unknown field. --- dbus/dbus-marshal.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'dbus/dbus-marshal.c') diff --git a/dbus/dbus-marshal.c b/dbus/dbus-marshal.c index 3d6184e9..cb989891 100644 --- a/dbus/dbus-marshal.c +++ b/dbus/dbus-marshal.c @@ -395,6 +395,10 @@ _dbus_marshal_set_uint64 (DBusString *str, * an existing string or the wrong length will be deleted * and replaced with the new string. * + * Note: no attempt is made by this function to re-align + * any data which has been already marshalled after this + * string. Use with caution. + * * @param str the string to write the marshalled string to * @param offset the byte offset where string should be written * @param byte_order the byte order to use -- cgit