From 61411a061c09def43687153e6c734ff27b7fd556 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 11 May 2005 18:07:22 +0000 Subject: 2005-05-11 Colin Walters * dbus/dbus-signature.c (dbus_signature_iter_get_signature): New function, returns signature string for signature iter. * dbus/dbus-signature.h: Prototype it. * dbus/dbus-message.c (dbus_message_iter_get_signature): New function, returns signature string for message iter. (dbus_message_iter_get_array_len): New function, returns length of array. (dbus_message_iter_get_fixed_array): Fix assertion; this function should be used when the iter is pointing to the contents of an array * dbus/dbus-message.h: Prototypes. * dbus/dbus-marshal-recursive.c (_dbus_type_reader_get_array_length): New function; returns length of an array. * dbus/dbus-marshal-recursive.h: Prototype it. --- dbus/dbus-message.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) (limited to 'dbus/dbus-message.c') diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c index 8a9014ca..d9a5234f 100644 --- a/dbus/dbus-message.c +++ b/dbus/dbus-message.c @@ -1612,6 +1612,41 @@ dbus_message_iter_recurse (DBusMessageIter *iter, _dbus_type_reader_recurse (&real->u.reader, &real_sub->u.reader); } +/** + * Returns the current signature of a message iterator. This + * is useful primarily for dealing with variants; one can + * recurse into a variant and determine the signature of + * the variant's value. + * + * @param iter the message iterator + * @returns the contained signature, or NULL if out of memory + */ +char * +dbus_message_iter_get_signature (DBusMessageIter *iter) +{ + const DBusString *sig; + DBusString retstr; + char *ret; + int start, len; + DBusMessageRealIter *real = (DBusMessageRealIter *)iter; + + _dbus_return_val_if_fail (_dbus_message_iter_check (real), NULL); + + if (!_dbus_string_init (&retstr)) + return NULL; + + _dbus_type_reader_get_signature (&real->u.reader, &sig, + &start, &len); + if (!_dbus_string_append_len (&retstr, + _dbus_string_get_const_data (sig) + start, + len)) + return NULL; + if (!_dbus_string_steal_data (&retstr, &ret)) + return NULL; + _dbus_string_free (&retstr); + return ret; +} + /** * Reads a basic-typed value from the message iterator. * Basic types are the non-containers such as integer and string. @@ -1660,6 +1695,22 @@ dbus_message_iter_get_basic (DBusMessageIter *iter, value); } +/** + * Returns the number of elements in the array; + * + * @param iter the iterator + * @returns the number of elements in the array + */ +int +dbus_message_iter_get_array_len (DBusMessageIter *iter) +{ + DBusMessageRealIter *real = (DBusMessageRealIter *)iter; + + _dbus_return_val_if_fail (_dbus_message_iter_check (real), 0); + + return _dbus_type_reader_get_array_length (&real->u.reader); +} + /** * Reads a block of fixed-length values from the message iterator. * Fixed-length values are those basic types that are not string-like, @@ -1686,7 +1737,7 @@ dbus_message_iter_get_fixed_array (DBusMessageIter *iter, _dbus_return_if_fail (_dbus_message_iter_check (real)); _dbus_return_if_fail (value != NULL); - _dbus_return_if_fail (dbus_type_is_fixed (_dbus_type_reader_get_element_type (&real->u.reader))); + _dbus_return_if_fail (dbus_type_is_fixed (_dbus_type_reader_get_current_type (&real->u.reader))); _dbus_type_reader_read_fixed_multi (&real->u.reader, value, n_elements); -- cgit