From c757d55ce00f11ceadb684a37d80ca7101038f8c Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Fri, 14 Jun 2013 12:39:07 +0300 Subject: [PATCH] tools/mpris-player: Fix append_iter to copy all fields This makes append_iter to work properly when copying another iter with more than one field. --- tools/mpris-player.c | 73 ++++++++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/tools/mpris-player.c b/tools/mpris-player.c index 918e364a1..099ae48f0 100644 --- a/tools/mpris-player.c +++ b/tools/mpris-player.c @@ -182,45 +182,56 @@ static void dict_append_array(DBusMessageIter *dict, const char *key, int type, dbus_message_iter_close_container(dict, &entry); } -static void append_iter(DBusMessageIter *base, DBusMessageIter *iter) +static void append_basic(DBusMessageIter *base, DBusMessageIter *iter, + int type) { - int type; + const void *value; + + dbus_message_iter_get_basic(iter, &value); + dbus_message_iter_append_basic(base, type, &value); +} - type = dbus_message_iter_get_arg_type(iter); +static void append_iter(DBusMessageIter *base, DBusMessageIter *iter); +static void append_container(DBusMessageIter *base, DBusMessageIter *iter, + int type) +{ + DBusMessageIter iter_sub, base_sub; + char *sig; - if (dbus_type_is_basic(type)) { - const void *value; + dbus_message_iter_recurse(iter, &iter_sub); - dbus_message_iter_get_basic(iter, &value); - dbus_message_iter_append_basic(base, type, &value); - } else if (dbus_type_is_container(type)) { - DBusMessageIter iter_sub, base_sub; - char *sig; + switch (type) { + case DBUS_TYPE_ARRAY: + case DBUS_TYPE_VARIANT: + sig = dbus_message_iter_get_signature(&iter_sub); + break; + default: + sig = NULL; + break; + } - dbus_message_iter_recurse(iter, &iter_sub); + dbus_message_iter_open_container(base, type, sig, &base_sub); - switch (type) { - case DBUS_TYPE_ARRAY: - case DBUS_TYPE_VARIANT: - sig = dbus_message_iter_get_signature(&iter_sub); - break; - default: - sig = NULL; - break; - } + if (sig != NULL) + dbus_free(sig); - dbus_message_iter_open_container(base, type, sig, &base_sub); + append_iter(&base_sub, &iter_sub); - if (sig != NULL) - dbus_free(sig); + dbus_message_iter_close_container(base, &base_sub); +} + +static void append_iter(DBusMessageIter *base, DBusMessageIter *iter) +{ + int type; - while (dbus_message_iter_get_arg_type(&iter_sub) != + while ((type = dbus_message_iter_get_arg_type(iter)) != DBUS_TYPE_INVALID) { - append_iter(&base_sub, &iter_sub); - dbus_message_iter_next(&iter_sub); - } + if (dbus_type_is_basic(type)) + append_basic(base, iter, type); + else if (dbus_type_is_container(type)) + append_container(base, iter, type); - dbus_message_iter_close_container(base, &base_sub); + dbus_message_iter_next(iter); } } @@ -536,7 +547,6 @@ static gboolean properties_changed(DBusConnection *conn, { DBusMessage *signal; DBusMessageIter iter, args; - const char *iface; char *path, *owner; dbus_message_iter_init(msg, &iter); @@ -558,12 +568,7 @@ static gboolean properties_changed(DBusConnection *conn, if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - dbus_message_iter_get_basic(&iter, &iface); - dbus_message_iter_init_append(signal, &args); - dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &iface); - - dbus_message_iter_next(&iter); append_iter(&args, &iter); -- 2.11.0