diff --git a/tools/dbus-send.c b/tools/dbus-send.c index 0a6f79a..6c56306 100644 --- a/tools/dbus-send.c +++ b/tools/dbus-send.c @@ -164,6 +164,8 @@ append_array (DBusMessageIter *iter, int type, const char *value) free (dupval); } +static int type_from_name(const char *name); + static void append_dict (DBusMessageIter *iter, int keytype, int valtype, const char *value) { @@ -187,7 +189,30 @@ append_dict (DBusMessageIter *iter, int keytype, int valtype, const char *value) fprintf (stderr, "%s: Malformed dictionary\n", appname); exit (1); } - append_arg (&subiter, valtype, val); + if (valtype == DBUS_TYPE_VARIANT) + { + char sig[2]; + char *c = strchr(val, ':'); + if (!c) + { + fprintf (stderr, "Missing type in variant dict\n"); + exit (1); + } + *(c++) = '\0'; + sig[0] = type_from_name(val); + sig[1] = '\0'; + DBusMessageIter subsubiter; + dbus_message_iter_open_container (&subiter, + DBUS_TYPE_VARIANT, + sig, + &subsubiter); + append_arg(&subsubiter, sig[0], c); + dbus_message_iter_close_container (&subiter, &subsubiter); + } + else + { + append_arg (&subiter, valtype, val); + } dbus_message_iter_close_container (iter, &subiter); val = strtok (NULL, ","); @@ -473,7 +498,11 @@ main (int argc, char *argv[]) exit (1); } *(c++) = 0; - secondary_type = type_from_name (arg); + if (!strcmp(arg, "variant")) + /* Hack: support variant values for dictionaries. */ + secondary_type = DBUS_TYPE_VARIANT; + else + secondary_type = type_from_name (arg); sig[0] = DBUS_DICT_ENTRY_BEGIN_CHAR; sig[1] = type; sig[2] = secondary_type;