dbus/dbus dbus-marshal-basic.c, 1.22, 1.23 dbus-marshal-byteswap.c,
1.2, 1.3 dbus-marshal-recursive-util.c, 1.6,
1.7 dbus-marshal-recursive.c, 1.46,
1.47 dbus-marshal-validate.c, 1.11,
1.12 dbus-marshal-validate.h, 1.7, 1.8 dbus-message.c, 1.157,
1.158 dbus-protocol.h, 1.36, 1.37
Havoc Pennington
hp@freedesktop.org
Thu Jan 27 21:30:55 PST 2005
Update of /cvs/dbus/dbus/dbus
In directory gabe:/tmp/cvs-serv14245/dbus
Modified Files:
dbus-marshal-basic.c dbus-marshal-byteswap.c
dbus-marshal-recursive-util.c dbus-marshal-recursive.c
dbus-marshal-validate.c dbus-marshal-validate.h dbus-message.c
dbus-protocol.h
Log Message:
2005-01-28 Havoc Pennington <hp@redhat.com>
* doc/dbus-specification.xml: update to describe 16-bit types and
dict entries
* dbus/dbus-marshal-basic.c (_dbus_unpack_uint16): fix broken
assertion
* dbus/dbus-protocol.h (DBUS_TYPE_DICT_ENTRY): add DICT_ENTRY as a
type
* dbus/dbus-marshal-recursive.c: implement
Index: dbus-marshal-basic.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-marshal-basic.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- dbus-marshal-basic.c 28 Jan 2005 03:06:55 -0000 1.22
+++ dbus-marshal-basic.c 28 Jan 2005 05:30:53 -0000 1.23
@@ -172,7 +172,7 @@
_dbus_unpack_uint16 (int byte_order,
const unsigned char *data)
{
- _dbus_assert (_DBUS_ALIGN_ADDRESS (data, 4) == data);
+ _dbus_assert (_DBUS_ALIGN_ADDRESS (data, 2) == data);
if (byte_order == DBUS_LITTLE_ENDIAN)
return DBUS_UINT16_FROM_LE (*(dbus_uint16_t*)data);
@@ -1245,8 +1245,10 @@
* and it's simpler to just always align structs to 8;
* we want the amount of padding in a struct of a given
* type to be predictable, not location-dependent.
+ * DICT_ENTRY is always the same as struct.
*/
case DBUS_TYPE_STRUCT:
+ case DBUS_TYPE_DICT_ENTRY:
return 8;
default:
@@ -1283,6 +1285,7 @@
case DBUS_TYPE_SIGNATURE:
case DBUS_TYPE_ARRAY:
case DBUS_TYPE_STRUCT:
+ case DBUS_TYPE_DICT_ENTRY:
case DBUS_TYPE_VARIANT:
return TRUE;
@@ -1294,6 +1297,7 @@
/** 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)
@@ -1403,6 +1407,8 @@
return "signature";
case DBUS_TYPE_STRUCT:
return "struct";
+ case DBUS_TYPE_DICT_ENTRY:
+ return "dict_entry";
case DBUS_TYPE_ARRAY:
return "array";
case DBUS_TYPE_VARIANT:
@@ -1411,6 +1417,10 @@
return "begin_struct";
case DBUS_STRUCT_END_CHAR:
return "end_struct";
+ case DBUS_DICT_ENTRY_BEGIN_CHAR:
+ return "begin_dict_entry";
+ case DBUS_DICT_ENTRY_END_CHAR:
+ return "end_dict_entry";
default:
return "unknown";
}
@@ -1559,8 +1569,14 @@
if (t == DBUS_STRUCT_BEGIN_CHAR)
return DBUS_TYPE_STRUCT;
+ else if (t == DBUS_DICT_ENTRY_BEGIN_CHAR)
+ return DBUS_TYPE_DICT_ENTRY;
else
- return t;
+ {
+ _dbus_assert (t != DBUS_STRUCT_END_CHAR);
+ _dbus_assert (t != DBUS_DICT_ENTRY_END_CHAR);
+ return t;
+ }
}
/** @} */
Index: dbus-marshal-byteswap.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-marshal-byteswap.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- dbus-marshal-byteswap.c 28 Jan 2005 03:06:55 -0000 1.2
+++ dbus-marshal-byteswap.c 28 Jan 2005 05:30:53 -0000 1.3
@@ -175,6 +175,7 @@
break;
case DBUS_TYPE_STRUCT:
+ case DBUS_TYPE_DICT_ENTRY:
{
DBusTypeReader sub;
Index: dbus-marshal-recursive-util.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-marshal-recursive-util.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- dbus-marshal-recursive-util.c 28 Jan 2005 03:06:55 -0000 1.6
+++ dbus-marshal-recursive-util.c 28 Jan 2005 05:30:53 -0000 1.7
@@ -526,6 +526,19 @@
int seed);
static dbus_bool_t struct_build_signature (TestTypeNode *node,
DBusString *str);
+static dbus_bool_t dict_write_value (TestTypeNode *node,
+ DataBlock *block,
+ DBusTypeWriter *writer,
+ int seed);
+static dbus_bool_t dict_read_value (TestTypeNode *node,
+ DBusTypeReader *reader,
+ int seed);
+static dbus_bool_t dict_set_value (TestTypeNode *node,
+ DBusTypeReader *reader,
+ DBusTypeReader *realign_root,
+ int seed);
+static dbus_bool_t dict_build_signature (TestTypeNode *node,
+ DBusString *str);
static dbus_bool_t array_write_value (TestTypeNode *node,
DataBlock *block,
DBusTypeWriter *writer,
@@ -553,6 +566,7 @@
static void container_destroy (TestTypeNode *node);
+
static const TestTypeNodeClass int16_class = {
DBUS_TYPE_INT16,
sizeof (TestTypeNode),
@@ -793,6 +807,20 @@
NULL
};
+static const TestTypeNodeClass dict_1_class = {
+ DBUS_TYPE_ARRAY, /* this is correct, a dict is an array of dict entry */
+ sizeof (TestTypeNodeContainer),
+ 1, /* number of entries */
+ NULL,
+ container_destroy,
+ dict_write_value,
+ dict_read_value,
+ dict_set_value,
+ dict_build_signature,
+ NULL,
+ NULL
+};
+
static dbus_bool_t arrays_write_fixed_in_blocks = FALSE;
static const TestTypeNodeClass array_0_class = {
@@ -892,7 +920,8 @@
&struct_2_class,
&array_0_class,
&array_2_class,
- &variant_class
+ &variant_class,
+ &dict_1_class /* last since we want struct and array before it */
/* array_9_class is omitted on purpose, it's too slow;
* we only use it in one hardcoded test below
*/
@@ -2157,8 +2186,8 @@
_dbus_assert (n_elements == count);
for (i = 0; i < count; i++)
- _dbus_assert (((int)_dbus_unpack_uint16 (reader->byte_order,
- (const unsigned char*)values + (i * 2))) ==
+ _dbus_assert (((dbus_int16_t)_dbus_unpack_uint16 (reader->byte_order,
+ (const unsigned char*)values + (i * 2))) ==
int16_from_seed (seed + i));
return TRUE;
@@ -3298,6 +3327,233 @@
return variant_read_or_set_value (node, reader, realign_root, seed);
}
+static dbus_bool_t
+dict_write_value (TestTypeNode *node,
+ DataBlock *block,
+ DBusTypeWriter *writer,
+ int seed)
+{
+ TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
+ DataBlockState saved;
+ DBusTypeWriter sub;
+ DBusString entry_value_signature;
+ DBusString dict_entry_signature;
+ int i;
+ int n_entries;
+ int entry_value_type;
+ TestTypeNode *child;
+
+ n_entries = node->klass->subclass_detail;
+
+ _dbus_assert (container->children != NULL);
+
+ data_block_save (block, &saved);
+
+ if (!_dbus_string_init (&entry_value_signature))
+ return FALSE;
+
+ if (!_dbus_string_init (&dict_entry_signature))
+ {
+ _dbus_string_free (&entry_value_signature);
+ return FALSE;
+ }
+
+ child = _dbus_list_get_first (&container->children);
+
+ if (!node_build_signature (child,
+ &entry_value_signature))
+ goto oom;
+
+ if (!_dbus_string_append (&dict_entry_signature,
+ DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+ DBUS_TYPE_INT32_AS_STRING))
+ goto oom;
+
+ if (!_dbus_string_copy (&entry_value_signature, 0,
+ &dict_entry_signature,
+ _dbus_string_get_length (&dict_entry_signature)))
+ goto oom;
+
+ if (!_dbus_string_append_byte (&dict_entry_signature,
+ DBUS_DICT_ENTRY_END_CHAR))
+ goto oom;
+
+ entry_value_type = _dbus_first_type_in_signature (&entry_value_signature, 0);
+
+ if (!_dbus_type_writer_recurse (writer, DBUS_TYPE_ARRAY,
+ &dict_entry_signature, 0,
+ &sub))
+ goto oom;
+
+ i = 0;
+ while (i < n_entries)
+ {
+ DBusTypeWriter entry_sub;
+ dbus_int32_t key;
+
+ if (!_dbus_type_writer_recurse (&sub, DBUS_TYPE_DICT_ENTRY,
+ NULL, 0,
+ &entry_sub))
+ goto oom;
+
+ key = int32_from_seed (seed + i);
+
+ if (!_dbus_type_writer_write_basic (&entry_sub,
+ DBUS_TYPE_INT32,
+ &key))
+ goto oom;
+
+ if (!node_write_value (child, block, &entry_sub, seed + i))
+ goto oom;
+
+ if (!_dbus_type_writer_unrecurse (&sub, &entry_sub))
+ goto oom;
+
+ ++i;
+ }
+
+ if (!_dbus_type_writer_unrecurse (writer, &sub))
+ goto oom;
+
+ _dbus_string_free (&entry_value_signature);
+ _dbus_string_free (&dict_entry_signature);
+ return TRUE;
+
+ oom:
+ data_block_restore (block, &saved);
+ _dbus_string_free (&entry_value_signature);
+ _dbus_string_free (&dict_entry_signature);
+ return FALSE;
+}
+
+static dbus_bool_t
+dict_read_or_set_value (TestTypeNode *node,
+ DBusTypeReader *reader,
+ DBusTypeReader *realign_root,
+ int seed)
+{
+ TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
+ DBusTypeReader sub;
+ int i;
+ int n_entries;
+ TestTypeNode *child;
+
+ n_entries = node->klass->subclass_detail;
+
+ check_expected_type (reader, DBUS_TYPE_ARRAY);
+
+ child = _dbus_list_get_first (&container->children);
+
+ if (n_entries > 0)
+ {
+ _dbus_type_reader_recurse (reader, &sub);
+
+ check_expected_type (&sub, DBUS_TYPE_DICT_ENTRY);
+
+ i = 0;
+ while (i < n_entries)
+ {
+ DBusTypeReader entry_sub;
+
+ check_expected_type (&sub, DBUS_TYPE_DICT_ENTRY);
+
+ _dbus_type_reader_recurse (&sub, &entry_sub);
+
+ if (realign_root == NULL)
+ {
+ dbus_int32_t v;
+
+ check_expected_type (&entry_sub, DBUS_TYPE_INT32);
+
+ _dbus_type_reader_read_basic (&entry_sub,
+ (dbus_int32_t*) &v);
+
+ _dbus_assert (v == int32_from_seed (seed + i));
+
+ NEXT_EXPECTING_TRUE (&entry_sub);
+
+ if (!node_read_value (child, &entry_sub, seed + i))
+ return FALSE;
+
+ NEXT_EXPECTING_FALSE (&entry_sub);
+ }
+ else
+ {
+ dbus_int32_t v;
+
+ v = int32_from_seed (seed + i);
+
+ if (!_dbus_type_reader_set_basic (&entry_sub,
+ &v,
+ realign_root))
+ return FALSE;
+
+ NEXT_EXPECTING_TRUE (&entry_sub);
+
+ if (!node_set_value (child, &entry_sub, realign_root, seed + i))
+ return FALSE;
+
+ NEXT_EXPECTING_FALSE (&entry_sub);
+ }
+
+ if (i == (n_entries - 1))
+ NEXT_EXPECTING_FALSE (&sub);
+ else
+ NEXT_EXPECTING_TRUE (&sub);
+
+ ++i;
+ }
+ }
+
+ return TRUE;
+}
+
+static dbus_bool_t
+dict_read_value (TestTypeNode *node,
+ DBusTypeReader *reader,
+ int seed)
+{
+ return dict_read_or_set_value (node, reader, NULL, seed);
+}
+
+static dbus_bool_t
+dict_set_value (TestTypeNode *node,
+ DBusTypeReader *reader,
+ DBusTypeReader *realign_root,
+ int seed)
+{
+ return dict_read_or_set_value (node, reader, realign_root, seed);
+}
+
+static dbus_bool_t
+dict_build_signature (TestTypeNode *node,
+ DBusString *str)
+{
+ TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
+ int orig_len;
+
+ orig_len = _dbus_string_get_length (str);
+
+ if (!_dbus_string_append_byte (str, DBUS_TYPE_ARRAY))
+ goto oom;
+
+ if (!_dbus_string_append (str, DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_INT32_AS_STRING))
+ goto oom;
+
+ if (!node_build_signature (_dbus_list_get_first (&container->children),
+ str))
+ goto oom;
+
+ if (!_dbus_string_append_byte (str, DBUS_DICT_ENTRY_END_CHAR))
+ goto oom;
+
+ return TRUE;
+
+ oom:
+ _dbus_string_set_length (str, orig_len);
+ return FALSE;
+}
+
static void
container_destroy (TestTypeNode *node)
{
Index: dbus-marshal-recursive.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-marshal-recursive.c,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- dbus-marshal-recursive.c 27 Jan 2005 01:50:01 -0000 1.46
+++ dbus-marshal-recursive.c 28 Jan 2005 05:30:53 -0000 1.47
@@ -159,24 +159,26 @@
}
static void
-struct_types_only_reader_recurse (DBusTypeReader *sub,
- DBusTypeReader *parent)
+struct_or_dict_entry_types_only_reader_recurse (DBusTypeReader *sub,
+ DBusTypeReader *parent)
{
base_reader_recurse (sub, parent);
-
+
_dbus_assert (_dbus_string_get_byte (sub->type_str,
- sub->type_pos) == DBUS_STRUCT_BEGIN_CHAR);
+ sub->type_pos) == DBUS_STRUCT_BEGIN_CHAR ||
+ _dbus_string_get_byte (sub->type_str,
+ sub->type_pos) == DBUS_DICT_ENTRY_BEGIN_CHAR);
sub->type_pos += 1;
}
static void
-struct_reader_recurse (DBusTypeReader *sub,
- DBusTypeReader *parent)
+struct_or_dict_entry_reader_recurse (DBusTypeReader *sub,
+ DBusTypeReader *parent)
{
- struct_types_only_reader_recurse (sub, parent);
+ struct_or_dict_entry_types_only_reader_recurse (sub, parent);
- /* struct has 8 byte alignment */
+ /* struct and dict entry have 8 byte alignment */
sub->value_pos = _DBUS_ALIGN_VALUE (sub->value_pos, 8);
}
@@ -321,11 +323,13 @@
p = start + *type_pos;
_dbus_assert (*p != DBUS_STRUCT_END_CHAR);
+ _dbus_assert (*p != DBUS_DICT_ENTRY_END_CHAR);
while (*p == DBUS_TYPE_ARRAY)
++p;
_dbus_assert (*p != DBUS_STRUCT_END_CHAR);
+ _dbus_assert (*p != DBUS_DICT_ENTRY_END_CHAR);
if (*p == DBUS_STRUCT_BEGIN_CHAR)
{
@@ -354,6 +358,33 @@
}
}
}
+ else if (*p == DBUS_DICT_ENTRY_BEGIN_CHAR)
+ {
+ int depth;
+
+ depth = 1;
+
+ while (TRUE)
+ {
+ _dbus_assert (*p != DBUS_TYPE_INVALID);
+
+ ++p;
+
+ _dbus_assert (*p != DBUS_TYPE_INVALID);
+
+ if (*p == DBUS_DICT_ENTRY_BEGIN_CHAR)
+ depth += 1;
+ else if (*p == DBUS_DICT_ENTRY_END_CHAR)
+ {
+ depth -= 1;
+ if (depth == 0)
+ {
+ ++p;
+ break;
+ }
+ }
+ }
+ }
else
{
++p;
@@ -381,6 +412,7 @@
{
switch (current_type)
{
+ case DBUS_TYPE_DICT_ENTRY:
case DBUS_TYPE_STRUCT:
case DBUS_TYPE_VARIANT:
/* Scan forward over the entire container contents */
@@ -461,6 +493,27 @@
}
static void
+dict_entry_reader_next (DBusTypeReader *reader,
+ int current_type)
+{
+ int t;
+
+ base_reader_next (reader, current_type);
+
+ /* for STRUCT containers we return FALSE at the end of the struct,
+ * for INVALID we return FALSE at the end of the signature.
+ * In both cases we arrange for get_current_type() to return INVALID
+ * which is defined to happen iff we're at the end (no more next())
+ */
+ t = _dbus_string_get_byte (reader->type_str, reader->type_pos);
+ if (t == DBUS_DICT_ENTRY_END_CHAR)
+ {
+ reader->type_pos += 1;
+ reader->finished = TRUE;
+ }
+}
+
+static void
array_types_only_reader_next (DBusTypeReader *reader,
int current_type)
{
@@ -495,6 +548,7 @@
switch (_dbus_first_type_in_signature (reader->type_str,
reader->type_pos))
{
+ case DBUS_TYPE_DICT_ENTRY:
case DBUS_TYPE_STRUCT:
case DBUS_TYPE_VARIANT:
{
@@ -582,7 +636,7 @@
static const DBusTypeReaderClass struct_reader_class = {
"struct", 2,
FALSE,
- struct_reader_recurse,
+ struct_or_dict_entry_reader_recurse,
NULL,
struct_reader_next,
NULL
@@ -591,14 +645,32 @@
static const DBusTypeReaderClass struct_types_only_reader_class = {
"struct types", 3,
TRUE,
- struct_types_only_reader_recurse,
+ struct_or_dict_entry_types_only_reader_recurse,
NULL,
struct_reader_next,
NULL
};
+static const DBusTypeReaderClass dict_entry_reader_class = {
+ "dict_entry", 4,
+ FALSE,
+ struct_or_dict_entry_reader_recurse,
+ NULL,
+ dict_entry_reader_next,
+ NULL
+};
+
+static const DBusTypeReaderClass dict_entry_types_only_reader_class = {
+ "dict_entry types", 5,
+ TRUE,
+ struct_or_dict_entry_types_only_reader_recurse,
+ NULL,
+ dict_entry_reader_next,
+ NULL
+};
+
static const DBusTypeReaderClass array_reader_class = {
- "array", 4,
+ "array", 6,
FALSE,
array_reader_recurse,
array_reader_check_finished,
@@ -607,7 +679,7 @@
};
static const DBusTypeReaderClass array_types_only_reader_class = {
- "array types", 5,
+ "array types", 7,
TRUE,
array_types_only_reader_recurse,
NULL,
@@ -616,7 +688,7 @@
};
static const DBusTypeReaderClass variant_reader_class = {
- "variant", 6,
+ "variant", 8,
FALSE,
variant_reader_recurse,
NULL,
@@ -630,6 +702,8 @@
&body_types_only_reader_class,
&struct_reader_class,
&struct_types_only_reader_class,
+ &dict_entry_reader_class,
+ &dict_entry_types_only_reader_class,
&array_reader_class,
&array_types_only_reader_class,
&variant_reader_class
@@ -798,11 +872,13 @@
t = DBUS_TYPE_INVALID;
else
t = _dbus_first_type_in_signature (reader->type_str,
- reader->type_pos);
+ reader->type_pos);
_dbus_assert (t != DBUS_STRUCT_END_CHAR);
_dbus_assert (t != DBUS_STRUCT_BEGIN_CHAR);
-
+ _dbus_assert (t != DBUS_DICT_ENTRY_END_CHAR);
+ _dbus_assert (t != DBUS_DICT_ENTRY_BEGIN_CHAR);
+
#if 0
_dbus_verbose (" type reader %p current type_pos = %d type = %s\n",
reader, reader->type_pos,
@@ -989,6 +1065,12 @@
else
sub->klass = &struct_reader_class;
break;
+ case DBUS_TYPE_DICT_ENTRY:
+ if (reader->klass->types_only)
+ sub->klass = &dict_entry_types_only_reader_class;
+ else
+ sub->klass = &dict_entry_reader_class;
+ break;
case DBUS_TYPE_ARRAY:
if (reader->klass->types_only)
sub->klass = &array_types_only_reader_class;
@@ -1734,11 +1816,12 @@
}
static dbus_bool_t
-writer_recurse_struct (DBusTypeWriter *writer,
- const DBusString *contained_type,
- int contained_type_start,
- int contained_type_len,
- DBusTypeWriter *sub)
+writer_recurse_struct_or_dict_entry (DBusTypeWriter *writer,
+ int begin_char,
+ const DBusString *contained_type,
+ int contained_type_start,
+ int contained_type_len,
+ DBusTypeWriter *sub)
{
/* FIXME right now contained_type is ignored; we could probably
* almost trivially fix the code so if it's present we
@@ -1752,7 +1835,7 @@
return FALSE;
}
- if (!write_or_verify_typecode (sub, DBUS_STRUCT_BEGIN_CHAR))
+ if (!write_or_verify_typecode (sub, begin_char))
_dbus_assert_not_reached ("failed to insert struct typecode after prealloc");
if (writer->enabled)
@@ -2027,9 +2110,18 @@
switch (container_type)
{
case DBUS_TYPE_STRUCT:
- return writer_recurse_struct (writer,
- contained_type, contained_type_start, contained_type_len,
- sub);
+ return writer_recurse_struct_or_dict_entry (writer,
+ DBUS_STRUCT_BEGIN_CHAR,
+ contained_type,
+ contained_type_start, contained_type_len,
+ sub);
+ break;
+ case DBUS_TYPE_DICT_ENTRY:
+ return writer_recurse_struct_or_dict_entry (writer,
+ DBUS_DICT_ENTRY_BEGIN_CHAR,
+ contained_type,
+ contained_type_start, contained_type_len,
+ sub);
break;
case DBUS_TYPE_ARRAY:
return writer_recurse_array (writer,
@@ -2151,6 +2243,11 @@
if (!write_or_verify_typecode (sub, DBUS_STRUCT_END_CHAR))
return FALSE;
}
+ else if (sub->container_type == DBUS_TYPE_DICT_ENTRY)
+ {
+ if (!write_or_verify_typecode (sub, DBUS_DICT_ENTRY_END_CHAR))
+ return FALSE;
+ }
else if (sub->container_type == DBUS_TYPE_ARRAY)
{
if (sub->u.array.len_pos >= 0) /* len_pos == -1 if we weren't enabled when we passed it */
@@ -2217,11 +2314,16 @@
* parent makes no difference since there's only one value
* and we just finished writing it and won't use type_pos again
* writer->type_pos should remain as-is
+ *
+ *
+ * For all these, DICT_ENTRY is the same as STRUCT
*/
if (writer->type_str != NULL)
{
- if (sub->container_type == DBUS_TYPE_STRUCT &&
+ if ((sub->container_type == DBUS_TYPE_STRUCT ||
+ sub->container_type == DBUS_TYPE_DICT_ENTRY) &&
(writer->container_type == DBUS_TYPE_STRUCT ||
+ writer->container_type == DBUS_TYPE_DICT_ENTRY ||
writer->container_type == DBUS_TYPE_INVALID))
{
/* Advance the parent to the next struct field */
Index: dbus-marshal-validate.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-marshal-validate.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- dbus-marshal-validate.c 28 Jan 2005 03:06:55 -0000 1.11
+++ dbus-marshal-validate.c 28 Jan 2005 05:30:53 -0000 1.12
@@ -40,6 +40,10 @@
* The range passed in should NOT include the terminating
* nul/DBUS_TYPE_INVALID.
*
+ * @todo verify that dict entries have exactly two fields
+ *
+ * @todo require that dict entries are in an array
+ *
* @param type_str the string
* @param type_pos where the typecodes start
* @param len length of typecodes
@@ -55,6 +59,7 @@
int last;
int struct_depth;
int array_depth;
+ int dict_entry_depth;
_dbus_assert (type_str != NULL);
_dbus_assert (type_pos < _DBUS_INT32_MAX - len);
@@ -68,6 +73,7 @@
end = _dbus_string_get_const_data_len (type_str, type_pos + len, 0);
struct_depth = 0;
array_depth = 0;
+ dict_entry_depth = 0;
last = DBUS_TYPE_INVALID;
while (p != end)
@@ -112,7 +118,28 @@
struct_depth -= 1;
break;
- case DBUS_TYPE_STRUCT: /* doesn't appear in signatures */
+ case DBUS_DICT_ENTRY_BEGIN_CHAR:
+ if (last != DBUS_TYPE_ARRAY)
+ return DBUS_INVALID_DICT_ENTRY_NOT_INSIDE_ARRAY;
+
+ dict_entry_depth += 1;
+
+ if (dict_entry_depth > DBUS_MAXIMUM_TYPE_RECURSION_DEPTH)
+ return DBUS_INVALID_EXCEEDED_MAXIMUM_DICT_ENTRY_RECURSION;
+ break;
+
+ case DBUS_DICT_ENTRY_END_CHAR:
+ if (dict_entry_depth == 0)
+ return DBUS_INVALID_DICT_ENTRY_ENDED_BUT_NOT_STARTED;
+
+ if (last == DBUS_DICT_ENTRY_BEGIN_CHAR)
+ return DBUS_INVALID_DICT_ENTRY_HAS_NO_FIELDS;
+
+ dict_entry_depth -= 1;
+ break;
+
+ case DBUS_TYPE_STRUCT: /* doesn't appear in signatures */
+ case DBUS_TYPE_DICT_ENTRY: /* ditto */
default:
return DBUS_INVALID_UNKNOWN_TYPECODE;
}
@@ -130,6 +157,9 @@
if (struct_depth > 0)
return DBUS_INVALID_STRUCT_STARTED_BUT_NOT_ENDED;
+ if (dict_entry_depth > 0)
+ return DBUS_INVALID_DICT_ENTRY_STARTED_BUT_NOT_ENDED;
+
return DBUS_VALID;
}
@@ -377,6 +407,7 @@
}
break;
+ case DBUS_TYPE_DICT_ENTRY:
case DBUS_TYPE_STRUCT:
{
DBusTypeReader sub;
Index: dbus-marshal-validate.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-marshal-validate.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- dbus-marshal-validate.h 27 Jan 2005 23:39:26 -0000 1.7
+++ dbus-marshal-validate.h 28 Jan 2005 05:30:53 -0000 1.8
@@ -100,7 +100,14 @@
DBUS_INVALID_VARIANT_SIGNATURE_SPECIFIES_MULTIPLE_VALUES = 46,
DBUS_INVALID_VARIANT_SIGNATURE_MISSING_NUL = 47,
DBUS_INVALID_STRING_MISSING_NUL = 48,
- DBUS_INVALID_SIGNATURE_MISSING_NUL = 49
+ DBUS_INVALID_SIGNATURE_MISSING_NUL = 49,
+ DBUS_INVALID_EXCEEDED_MAXIMUM_DICT_ENTRY_RECURSION = 50,
+ DBUS_INVALID_DICT_ENTRY_ENDED_BUT_NOT_STARTED = 51,
+ DBUS_INVALID_DICT_ENTRY_STARTED_BUT_NOT_ENDED = 52,
+ DBUS_INVALID_DICT_ENTRY_HAS_NO_FIELDS = 53,
+ DBUS_INVALID_DICT_ENTRY_HAS_ONLY_ONE_FIELD = 54,
+ DBUS_INVALID_DICT_ENTRY_HAS_TOO_MANY_FIELDS = 55,
+ DBUS_INVALID_DICT_ENTRY_NOT_INSIDE_ARRAY = 56
} DBusValidity;
DBusValidity _dbus_validate_signature_with_reason (const DBusString *type_str,
Index: dbus-message.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-message.c,v
retrieving revision 1.157
retrieving revision 1.158
diff -u -d -r1.157 -r1.158
--- dbus-message.c 27 Jan 2005 23:39:26 -0000 1.157
+++ dbus-message.c 28 Jan 2005 05:30:53 -0000 1.158
@@ -2112,10 +2112,10 @@
* dbus_message_iter_close_container(). Container types are for
* example struct, variant, and array. For variants, the
* contained_signature should be the type of the single value inside
- * the variant. For structs, contained_signature should be #NULL; it
- * will be set to whatever types you write into the struct. For
- * arrays, contained_signature should be the type of the array
- * elements.
+ * the variant. For structs and dict entries, contained_signature
+ * should be #NULL; it will be set to whatever types you write into
+ * the struct. For arrays, contained_signature should be the type of
+ * the array elements.
*
* @todo If this fails due to lack of memory, the message is hosed and
* you have to start over building the whole message.
@@ -2142,7 +2142,21 @@
_dbus_return_val_if_fail (sub != NULL, FALSE);
_dbus_return_val_if_fail ((type == DBUS_TYPE_STRUCT &&
contained_signature == NULL) ||
+ (type == DBUS_TYPE_DICT_ENTRY &&
+ contained_signature == NULL) ||
contained_signature != NULL, FALSE);
+ _dbus_return_val_if_fail (type != DBUS_TYPE_DICT_ENTRY ||
+ dbus_message_iter_get_arg_type (iter) == DBUS_TYPE_ARRAY,
+ FALSE);
+
+#if 0
+ /* FIXME this would fail if the contained_signature is a dict entry,
+ * since dict entries are invalid signatures standalone (they must be in
+ * an array)
+ */
+ _dbus_return_val_if_fail (contained_signature == NULL ||
+ _dbus_check_is_valid_signature (contained_signature));
+#endif
if (!_dbus_message_iter_open_signature (real))
return FALSE;
Index: dbus-protocol.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-protocol.h,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- dbus-protocol.h 28 Jan 2005 03:06:55 -0000 1.36
+++ dbus-protocol.h 28 Jan 2005 05:30:53 -0000 1.37
@@ -77,20 +77,27 @@
#define DBUS_TYPE_VARIANT ((int) 'v')
#define DBUS_TYPE_VARIANT_AS_STRING "v"
-/* STRUCT is sort of special since its code can't appear in a type string,
- * instead DBUS_STRUCT_BEGIN_CHAR has to appear
+/* STRUCT and DICT_ENTRY are sort of special since their codes can't
+ * appear in a type string, instead
+ * DBUS_STRUCT_BEGIN_CHAR/DBUS_DICT_ENTRY_BEGIN_CHAR have to appear
*/
#define DBUS_TYPE_STRUCT ((int) 'r')
#define DBUS_TYPE_STRUCT_AS_STRING "r"
+#define DBUS_TYPE_DICT_ENTRY ((int) 'e')
+#define DBUS_TYPE_DICT_ENTRY_AS_STRING "e"
/* Does not count INVALID */
-#define DBUS_NUMBER_OF_TYPES (15)
+#define DBUS_NUMBER_OF_TYPES (16)
/* characters other than typecodes that appear in type signatures */
#define DBUS_STRUCT_BEGIN_CHAR ((int) '(')
#define DBUS_STRUCT_BEGIN_CHAR_AS_STRING "("
#define DBUS_STRUCT_END_CHAR ((int) ')')
#define DBUS_STRUCT_END_CHAR_AS_STRING ")"
+#define DBUS_DICT_ENTRY_BEGIN_CHAR ((int) '{')
+#define DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING "{"
+#define DBUS_DICT_ENTRY_END_CHAR ((int) '}')
+#define DBUS_DICT_ENTRY_END_CHAR_AS_STRING "}"
/* Max length in bytes of a bus name, interface, or member (not object
* path, paths are unlimited). This is limited because lots of stuff
More information about the dbus-commit
mailing list