summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2005-02-10 23:17:27 +0000
committerHavoc Pennington <hp@redhat.com>2005-02-10 23:17:27 +0000
commit83dd8129a0429a2647c3a989ec73c712feb6060c (patch)
tree80c635e9364fe3de942c3b87df1522d286f533b1
parentfd146b370dd2e014838c08ce0bfc8854ca93928b (diff)
2005-02-10 Havoc Pennington <hp@redhat.com>
* dbus/dbus-message-util.c (verify_test_message): tests for string array * dbus/dbus-message.c (dbus_message_append_args_valist): add support for arrays of string/signature/path
-rw-r--r--ChangeLog8
-rw-r--r--dbus/dbus-message-util.c21
-rw-r--r--dbus/dbus-message.c73
3 files changed, 79 insertions, 23 deletions
diff --git a/ChangeLog b/ChangeLog
index 84a46bf7..993294a9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2005-02-10 Havoc Pennington <hp@redhat.com>
+
+ * dbus/dbus-message-util.c (verify_test_message): tests for string
+ array
+
+ * dbus/dbus-message.c (dbus_message_append_args_valist): add
+ support for arrays of string/signature/path
+
2005-02-10 Joe Shaw <joeshaw@novell.com>
* dbus/dbus-connection.c
diff --git a/dbus/dbus-message-util.c b/dbus/dbus-message-util.c
index 69db2019..e9540be4 100644
--- a/dbus/dbus-message-util.c
+++ b/dbus/dbus-message-util.c
@@ -733,6 +733,8 @@ verify_test_message (DBusMessage *message)
int our_byte_array_len;
const dbus_bool_t *our_boolean_array = (void*)0xdeadbeef;
int our_boolean_array_len;
+ char **our_string_array;
+ int our_string_array_len;
dbus_message_iter_init (message, &iter);
@@ -767,6 +769,8 @@ verify_test_message (DBusMessage *message)
&our_byte_array, &our_byte_array_len,
DBUS_TYPE_ARRAY, DBUS_TYPE_BOOLEAN,
&our_boolean_array, &our_boolean_array_len,
+ DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
+ &our_string_array, &our_string_array_len,
0))
{
_dbus_warn ("error: %s - %s\n", error.name,
@@ -874,6 +878,17 @@ verify_test_message (DBusMessage *message)
our_boolean_array[4] != FALSE)
_dbus_assert_not_reached ("bool array had wrong values");
+ if (our_string_array_len != 4)
+ _dbus_assert_not_reached ("string array was wrong length");
+
+ if (strcmp (our_string_array[0], "Foo") != 0 ||
+ strcmp (our_string_array[1], "bar") != 0 ||
+ strcmp (our_string_array[2], "") != 0 ||
+ strcmp (our_string_array[3], "woo woo woo woo") != 0)
+ _dbus_assert_not_reached ("string array had wrong values");
+
+ dbus_free_string_array (our_string_array);
+
if (dbus_message_iter_next (&iter))
_dbus_assert_not_reached ("Didn't reach end of arguments");
}
@@ -1080,6 +1095,8 @@ _dbus_message_test (const char *test_data_dir)
_DBUS_N_ELEMENTS (our_byte_array),
DBUS_TYPE_ARRAY, DBUS_TYPE_BOOLEAN, &v_ARRAY_BOOLEAN,
_DBUS_N_ELEMENTS (our_boolean_array),
+ DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &v_ARRAY_STRING,
+ _DBUS_N_ELEMENTS (our_string_array),
DBUS_TYPE_INVALID);
i = 0;
@@ -1112,7 +1129,9 @@ _dbus_message_test (const char *test_data_dir)
sig[i++] = DBUS_TYPE_BYTE;
sig[i++] = DBUS_TYPE_ARRAY;
sig[i++] = DBUS_TYPE_BOOLEAN;
- sig[i++] = DBUS_TYPE_INVALID;
+ sig[i++] = DBUS_TYPE_ARRAY;
+ sig[i++] = DBUS_TYPE_STRING;
+ sig[i++] = DBUS_TYPE_INVALID;
_dbus_assert (i < (int) _DBUS_N_ELEMENTS (sig));
diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c
index 537f857b..71861689 100644
--- a/dbus/dbus-message.c
+++ b/dbus/dbus-message.c
@@ -1180,6 +1180,9 @@ dbus_message_get_type (DBusMessage *message)
* The last argument to this function must be #DBUS_TYPE_INVALID,
* marking the end of the argument list.
*
+ * String/signature/path arrays should be passed in as "const char***
+ * address_of_array" and "int n_elements"
+ *
* @todo support DBUS_TYPE_STRUCT and DBUS_TYPE_VARIANT and complex arrays
*
* @todo If this fails due to lack of memory, the message is hosed and
@@ -1252,26 +1255,11 @@ dbus_message_append_args_valist (DBusMessage *message,
else if (type == DBUS_TYPE_ARRAY)
{
int element_type;
- const DBusBasicValue **value;
- int n_elements;
DBusMessageIter array;
char buf[2];
element_type = va_arg (var_args, int);
-
-#ifndef DBUS_DISABLE_CHECKS
- if (!_dbus_type_is_fixed (element_type))
- {
- _dbus_warn ("arrays of %s can't be appended with %s for now\n",
- _dbus_type_to_string (element_type),
- _DBUS_FUNCTION_NAME);
- goto failed;
- }
-#endif
-
- value = va_arg (var_args, const DBusBasicValue**);
- n_elements = va_arg (var_args, int);
-
+
buf[0] = element_type;
buf[1] = '\0';
if (!dbus_message_iter_open_container (&iter,
@@ -1279,12 +1267,52 @@ dbus_message_append_args_valist (DBusMessage *message,
buf,
&array))
goto failed;
+
+ if (_dbus_type_is_fixed (element_type))
+ {
+ const DBusBasicValue **value;
+ int n_elements;
- if (!dbus_message_iter_append_fixed_array (&array,
- element_type,
- value,
- n_elements))
- goto failed;
+ value = va_arg (var_args, const DBusBasicValue**);
+ n_elements = va_arg (var_args, int);
+
+ if (!dbus_message_iter_append_fixed_array (&array,
+ element_type,
+ value,
+ n_elements))
+ goto failed;
+ }
+ else if (element_type == DBUS_TYPE_STRING ||
+ element_type == DBUS_TYPE_SIGNATURE ||
+ element_type == DBUS_TYPE_OBJECT_PATH)
+ {
+ const char ***value_p;
+ const char **value;
+ int n_elements;
+ int i;
+
+ value_p = va_arg (var_args, const char***);
+ n_elements = va_arg (var_args, int);
+
+ value = *value_p;
+
+ i = 0;
+ while (i < n_elements)
+ {
+ if (!dbus_message_iter_append_basic (&array,
+ element_type,
+ &value[i]))
+ goto failed;
+ ++i;
+ }
+ }
+ else
+ {
+ _dbus_warn ("arrays of %s can't be appended with %s for now\n",
+ _dbus_type_to_string (element_type),
+ _DBUS_FUNCTION_NAME);
+ goto failed;
+ }
if (!dbus_message_iter_close_container (&iter, &array))
goto failed;
@@ -1318,7 +1346,8 @@ dbus_message_append_args_valist (DBusMessage *message,
* In addition to those types, arrays of string, object path, and
* signature are supported; but these are returned as allocated memory
* and must be freed with dbus_free_string_array(), while the other
- * types are returned as const references.
+ * types are returned as const references. To get a string array
+ * pass in "char ***array_location" and "int *n_elements"
*
* The variable argument list should contain the type of the argument
* followed by a pointer to where the value should be stored. The list