From ae0b3b71f411be9daf9b623056925286da9ce550 Mon Sep 17 00:00:00 2001 From: Patrik Flykt Date: Tue, 19 Feb 2013 14:44:23 +0200 Subject: [PATCH] client: Return the number of added dict entries Check that both the dict entry name and data are non-NULL, the dict data does not start with '--' indicating a new option and that the length is not exhausted. Return the number of dict entries. --- client/services.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/client/services.c b/client/services.c index c8343dd..1dddbad 100644 --- a/client/services.c +++ b/client/services.c @@ -88,11 +88,11 @@ static int append_property_array(DBusMessageIter *iter, char *property, return i; } -static void append_property_dict(DBusMessageIter *iter, char *property, +static int append_property_dict(DBusMessageIter *iter, char *property, char **keys, char **data, int num_args) { DBusMessageIter value, dict, entry, dict_key; - int i; + int i = 0; unsigned char prefix; dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &property); @@ -102,7 +102,12 @@ static void append_property_dict(DBusMessageIter *iter, char *property, dbus_dict_open(&value, &dict); - for (i = 0; i < num_args; i++) { + while (keys[i] != NULL && data[i] != NULL + && strncmp(data[i], "--", 2) != 0) { + + if (num_args > 0 && i == num_args) + break; + dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry); dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, @@ -133,10 +138,14 @@ static void append_property_dict(DBusMessageIter *iter, char *property, } dbus_message_iter_close_container(&entry, &dict_key); dbus_message_iter_close_container(&dict, &entry); + + i++; } /* Close {sv}, then close a{sv} */ dbus_dict_close(&value, &dict); dbus_dict_close(iter, &value); + + return i; } void iterate_array(DBusMessageIter *iter) -- 2.7.4