dbus/tools dbus-send.c,1.15,1.16 dbus-print-message.c,1.6,1.7
Colin Walters
walters at freedesktop.org
Wed Jun 15 21:48:12 PDT 2005
Update of /cvs/dbus/dbus/tools
In directory gabe:/tmp/cvs-serv30389/tools
Modified Files:
dbus-send.c dbus-print-message.c
Log Message:
2005-06-16 Colin Walters <walters at 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.
Index: dbus-send.c
===================================================================
RCS file: /cvs/dbus/dbus/tools/dbus-send.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- dbus-send.c 2 Jun 2005 18:22:04 -0000 1.15
+++ dbus-send.c 16 Jun 2005 04:48:10 -0000 1.16
@@ -103,14 +103,77 @@
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 @@
path,
name,
last_dot + 1);
+ dbus_message_set_auto_start (message, TRUE);
}
else if (message_type == DBUS_MESSAGE_TYPE_SIGNAL)
{
@@ -256,6 +320,7 @@
char *arg;
char *c;
int type;
+ int secondary_type;
int container_type;
DBusMessageIter *target_iter;
DBusMessageIter container_iter;
@@ -278,6 +343,8 @@
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 @@
*(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 @@
{
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);
Index: dbus-print-message.c
===================================================================
RCS file: /cvs/dbus/dbus/tools/dbus-print-message.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- dbus-print-message.c 11 May 2005 18:48:24 -0000 1.6
+++ dbus-print-message.c 16 Jun 2005 04:48:10 -0000 1.7
@@ -118,6 +118,19 @@
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);
More information about the dbus-commit
mailing list