From 54a2e9f7961b4b8afff94bb0c5b756f986965be6 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 24 Feb 2005 16:03:56 +0000 Subject: 2005-02-24 Colin Walters * dbus/dbus-signature.c: New file; implements various functions related to type signatures. Includes an interator for parsing, validation functions. (dbus_type_is_basic): Moved here from dbus-marshal-basic.c:_dbus_type_is_basic. (dbus_type_is_container): Moved here from dbus-marshal-basic.c:_dbus_type_is_container. All callers of _dbus_type_is_container and _dbus_type_is_basic updated, and include dbus-signature.h. * dbus/dbus-signature.h: New file; prototypes for the above. * dbus/Makefile.am (DBUS_LIB_SOURCES): Add dbus-signature.c, dbus-signature.h. * dbus/dbus-marshal-basic.c (map_type_char_to_type): New utility function factored out of _dbus_first_type_in_signature. (_dbus_first_type_in_signature_c_str): New function; returns first type code for a type signature character. * dbus/dbus-marshal-basic.h: Prototype _dbus_first_type_in_signature_c_str, handle function moves. * dbus/dbus-marshal-recursive.h: Export _dbus_type_signature_next. * dbus/dbus-marshal-recursive.c (_dbus_type_signature_next): New function; skips to next complete type in type signature. Implemented using previous skip_one_complete_type. Now skip_one_complete_type just delegates to _dbus_type_signature_next. * dbus/dbus-marshal-basic.c (_dbus_type_is_basic): Moved to dbus-signature.c (_dbus_type_is_container): Ditto. * doc/dbus-specification.xml: Update introspection sample to use real type signatures. * dbus/dbus-test.h: Prototype signature test. * dbus/dbus-test.c (dbus_internal_do_not_use_run_tests): Run signature tests. * dbus/dbus-protocol.h (DBUS_ERROR_INVALID_SIGNATURE): New error. --- dbus/dbus-marshal-basic.c | 100 ++++++++++++++++------------------------------ 1 file changed, 34 insertions(+), 66 deletions(-) (limited to 'dbus/dbus-marshal-basic.c') diff --git a/dbus/dbus-marshal-basic.c b/dbus/dbus-marshal-basic.c index a443ea35..fde58d51 100644 --- a/dbus/dbus-marshal-basic.c +++ b/dbus/dbus-marshal-basic.c @@ -24,6 +24,7 @@ #include "dbus-internals.h" #include "dbus-marshal-basic.h" +#include "dbus-signature.h" #include @@ -509,7 +510,7 @@ _dbus_marshal_read_basic (const DBusString *str, const char *str_data; DBusBasicValue *vp; - _dbus_assert (_dbus_type_is_basic (type)); + _dbus_assert (dbus_type_is_basic (type)); str_data = _dbus_string_get_const_data (str); vp = value; @@ -620,7 +621,7 @@ _dbus_marshal_read_fixed_multi (const DBusString *str, int alignment; _dbus_assert (_dbus_type_is_fixed (element_type)); - _dbus_assert (_dbus_type_is_basic (element_type)); + _dbus_assert (dbus_type_is_basic (element_type)); #if 0 _dbus_verbose ("reading %d elements of %s\n", @@ -849,7 +850,7 @@ _dbus_marshal_write_basic (DBusString *str, { const DBusBasicValue *vp; - _dbus_assert (_dbus_type_is_basic (type)); + _dbus_assert (dbus_type_is_basic (type)); vp = value; @@ -1297,56 +1298,6 @@ _dbus_type_is_valid (int typecode) } } -/** macro that checks whether a typecode is a container type */ -#define TYPE_IS_CONTAINER(typecode) \ - ((typecode) == DBUS_TYPE_STRUCT || \ - (typecode) == DBUS_TYPE_DICT_ENTRY || \ - (typecode) == DBUS_TYPE_VARIANT || \ - (typecode) == DBUS_TYPE_ARRAY) - -/** - * A "container type" can contain basic types, or nested - * container types. #DBUS_TYPE_INVALID is not a container type. - * This function will crash if passed a typecode that isn't - * in dbus-protocol.h - * - * @returns #TRUE if type is a container - */ -dbus_bool_t -_dbus_type_is_container (int typecode) -{ - /* only reasonable (non-line-noise) typecodes are allowed */ - _dbus_assert (_dbus_type_is_valid (typecode) || typecode == DBUS_TYPE_INVALID); - return TYPE_IS_CONTAINER (typecode); -} - -/** - * A "basic type" is a somewhat arbitrary concept, but the intent - * is to include those types that are fully-specified by a single - * typecode, with no additional type information or nested - * values. So all numbers and strings are basic types and - * structs, arrays, and variants are not basic types. - * #DBUS_TYPE_INVALID is not a basic type. - * - * This function is defined to return #TRUE for exactly those - * types that can be written with _dbus_marshal_basic_type() - * and read with _dbus_marshal_read_basic(). - * - * This function will crash if passed a typecode that isn't - * in dbus-protocol.h - * - * @returns #TRUE if type is basic - */ -dbus_bool_t -_dbus_type_is_basic (int typecode) -{ - /* only reasonable (non-line-noise) typecodes are allowed */ - _dbus_assert (_dbus_type_is_valid (typecode) || typecode == DBUS_TYPE_INVALID); - - /* everything that isn't invalid or a container */ - return !(typecode == DBUS_TYPE_INVALID || TYPE_IS_CONTAINER (typecode)); -} - /** * Tells you whether values of this type can change length if you set * them to some other value. For this purpose, you assume that the @@ -1552,6 +1503,21 @@ _dbus_verbose_bytes_of_string (const DBusString *str, _dbus_verbose_bytes (d, len, start); } +static int +map_type_char_to_type (int t) +{ + if (t == DBUS_STRUCT_BEGIN_CHAR) + return DBUS_TYPE_STRUCT; + else if (t == DBUS_DICT_ENTRY_BEGIN_CHAR) + return DBUS_TYPE_DICT_ENTRY; + else + { + _dbus_assert (t != DBUS_STRUCT_END_CHAR); + _dbus_assert (t != DBUS_DICT_ENTRY_END_CHAR); + return t; + } +} + /** * Get the first type in the signature. The difference between this * and just getting the first byte of the signature is that you won't @@ -1566,20 +1532,22 @@ int _dbus_first_type_in_signature (const DBusString *str, int pos) { - unsigned char t; - - t = _dbus_string_get_byte (str, pos); + return map_type_char_to_type (_dbus_string_get_byte (str, pos)); +} - if (t == DBUS_STRUCT_BEGIN_CHAR) - return DBUS_TYPE_STRUCT; - else if (t == DBUS_DICT_ENTRY_BEGIN_CHAR) - return DBUS_TYPE_DICT_ENTRY; - else - { - _dbus_assert (t != DBUS_STRUCT_END_CHAR); - _dbus_assert (t != DBUS_DICT_ENTRY_END_CHAR); - return t; - } +/** + * Similar to #_dbus_first_type_in_signature, but operates + * on a C string buffer. + * + * @param str a C string buffer + * @param pos where the signature starts + * @returns the first type in the signature + */ +int +_dbus_first_type_in_signature_c_str (const char *str, + int pos) +{ + return map_type_char_to_type (str[pos]); } /** @} */ -- cgit