diff options
author | Colin Walters <walters@verbum.org> | 2005-06-16 04:48:10 +0000 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2005-06-16 04:48:10 +0000 |
commit | 70bd20a50e5d8d5dd5ddabf945812d881090d3f5 (patch) | |
tree | 4ea31ea7ce8cac1752e7571a6e2fd0228fc31deb | |
parent | 3220372584bf346507c00a9445374cc2f1dd6ad0 (diff) |
2005-06-16 Colin Walters <walters@verbum.org>
* tools/dbus-send.c (append_array): Use strtok.
(append_dict): New function.
(type_from_name): New function, extracted from main.
(main): Handle sending dicts.
* tools/dbus-print-message.c (print_iter): Print dict
entries.
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | tools/dbus-print-message.c | 13 | ||||
-rw-r--r-- | tools/dbus-send.c | 123 |
3 files changed, 124 insertions, 22 deletions
@@ -1,5 +1,15 @@ 2005-06-16 Colin Walters <walters@verbum.org> + * tools/dbus-send.c (append_array): Use strtok. + (append_dict): New function. + (type_from_name): New function, extracted from main. + (main): Handle sending dicts. + + * tools/dbus-print-message.c (print_iter): Print dict + entries. + +2005-06-16 Colin Walters <walters@verbum.org> + * glib/dbus-gvalue.c (marshal_basic): Marshal NULL string values as the empty string (#2948). diff --git a/tools/dbus-print-message.c b/tools/dbus-print-message.c index 7fcdec79..bd47666c 100644 --- a/tools/dbus-print-message.c +++ b/tools/dbus-print-message.c @@ -118,6 +118,19 @@ print_iter (DBusMessageIter *iter, int depth) printf("]"); break; } + case DBUS_TYPE_DICT_ENTRY: + { + DBusMessageIter subiter; + + dbus_message_iter_recurse (iter, &subiter); + + printf("{"); + print_iter (&subiter, depth); + dbus_message_iter_next (&subiter); + print_iter (&subiter, depth); + printf("}"); + break; + } default: printf (" (dbus-monitor too dumb to decipher arg type '%c')\n", type); diff --git a/tools/dbus-send.c b/tools/dbus-send.c index 5747fa97..4c7a3666 100644 --- a/tools/dbus-send.c +++ b/tools/dbus-send.c @@ -103,14 +103,77 @@ append_arg (DBusMessageIter *iter, int type, const char *value) static void append_array (DBusMessageIter *iter, int type, const char *value) { - const char *c; + const char *val; + char *dupval = strdup (value); - append_arg (iter, type, value); - c = value; - while ((c = strchr (c + 1, ',')) != NULL) + val = strtok (dupval, ","); + while (val != NULL) { - append_arg (iter, type, c); + append_arg (iter, type, val); + val = strtok (NULL, ","); } + free (dupval); +} + +static void +append_dict (DBusMessageIter *iter, int keytype, int valtype, const char *value) +{ + const char *val; + char *dupval = strdup (value); + + val = strtok (dupval, ","); + while (val != NULL) + { + DBusMessageIter subiter; + char sig[3]; + sig[0] = keytype; + sig[1] = valtype; + sig[2] = '\0'; + + dbus_message_iter_open_container (iter, + DBUS_TYPE_DICT_ENTRY, + sig, + &subiter); + + append_arg (&subiter, keytype, val); + val = strtok (NULL, ","); + if (val == NULL) + { + fprintf (stderr, "%s: Malformed dictionary\n", appname); + exit (1); + } + append_arg (&subiter, valtype, val); + + dbus_message_iter_close_container (iter, &subiter); + val = strtok (NULL, ","); + } + free (dupval); +} + +static int +type_from_name (const char *arg) +{ + int type; + if (!strcmp (arg, "string")) + type = DBUS_TYPE_STRING; + else if (!strcmp (arg, "int32")) + type = DBUS_TYPE_INT32; + else if (!strcmp (arg, "uint32")) + type = DBUS_TYPE_UINT32; + else if (!strcmp (arg, "double")) + type = DBUS_TYPE_DOUBLE; + else if (!strcmp (arg, "byte")) + type = DBUS_TYPE_BYTE; + else if (!strcmp (arg, "boolean")) + type = DBUS_TYPE_BOOLEAN; + else if (!strcmp (arg, "objpath")) + type = DBUS_TYPE_OBJECT_PATH; + else + { + fprintf (stderr, "%s: Unknown type \"%s\"\n", appname, arg); + exit (1); + } + return type; } int @@ -215,6 +278,7 @@ main (int argc, char *argv[]) path, name, last_dot + 1); + dbus_message_set_auto_start (message, TRUE); } else if (message_type == DBUS_MESSAGE_TYPE_SIGNAL) { @@ -256,6 +320,7 @@ main (int argc, char *argv[]) char *arg; char *c; int type; + int secondary_type; int container_type; DBusMessageIter *target_iter; DBusMessageIter container_iter; @@ -278,6 +343,8 @@ main (int argc, char *argv[]) container_type = DBUS_TYPE_VARIANT; else if (strcmp (arg, "array") == 0) container_type = DBUS_TYPE_ARRAY; + else if (strcmp (arg, "dict") == 0) + container_type = DBUS_TYPE_DICT_ENTRY; if (container_type != DBUS_TYPE_INVALID) { @@ -291,27 +358,35 @@ main (int argc, char *argv[]) *(c++) = 0; } - if (arg[0] == 0 || !strcmp (arg, "string")) + if (arg[0] == 0) type = DBUS_TYPE_STRING; - else if (!strcmp (arg, "int32")) - type = DBUS_TYPE_INT32; - else if (!strcmp (arg, "uint32")) - type = DBUS_TYPE_UINT32; - else if (!strcmp (arg, "double")) - type = DBUS_TYPE_DOUBLE; - else if (!strcmp (arg, "byte")) - type = DBUS_TYPE_BYTE; - else if (!strcmp (arg, "boolean")) - type = DBUS_TYPE_BOOLEAN; - else if (!strcmp (arg, "objpath")) - type = DBUS_TYPE_OBJECT_PATH; else + type = type_from_name (arg); + + if (container_type == DBUS_TYPE_DICT_ENTRY) { - fprintf (stderr, "%s: Unknown type \"%s\"\n", appname, arg); - exit (1); + arg = c; + c = strchr (c, ':'); + if (c == NULL) + { + fprintf (stderr, "%s: Data item \"%s\" is badly formed\n", argv[0], arg); + exit (1); + } + *(c++) = 0; + secondary_type = type_from_name (arg); + char sig[5]; + sig[0] = DBUS_DICT_ENTRY_BEGIN_CHAR; + sig[1] = type; + sig[2] = secondary_type; + sig[3] = DBUS_DICT_ENTRY_END_CHAR; + sig[4] = '\0'; + dbus_message_iter_open_container (&iter, + DBUS_TYPE_ARRAY, + sig, + &container_iter); + target_iter = &container_iter; } - - if (container_type != DBUS_TYPE_INVALID) + else if (container_type != DBUS_TYPE_INVALID) { char sig[2]; sig[0] = type; @@ -329,6 +404,10 @@ main (int argc, char *argv[]) { append_array (target_iter, type, c); } + else if (container_type == DBUS_TYPE_DICT_ENTRY) + { + append_dict (target_iter, type, secondary_type, c); + } else append_arg (target_iter, type, c); |