summaryrefslogtreecommitdiffstats
path: root/meta/packages/dbus/dbus/dbussend.patch
blob: 49a251bbb084938898a1d5c56f364b5c098d9593 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
Index: dbus-send.1
===================================================================
--- tools/dbus-send.1	(revision 691)
+++ tools/dbus-send.1	(working copy)
@@ -36,8 +36,8 @@
 specified. Following arguments, if any, are the message contents
 (message arguments).  These are given as a type name, a colon, and
 then the value of the argument. The possible type names are: string,
-int32, uint32, double, byte, boolean.  (D-BUS supports more types than
-these, but \fIdbus-send\fP currently does not.)
+int32, uint32, double, byte, boolean, array.  (D-BUS supports more types 
+than these, but \fIdbus-send\fP currently does not.)
 
 .PP
 Here is an example invocation:
@@ -46,7 +46,8 @@
   dbus-send \-\-dest='org.freedesktop.ExampleService'        \\
             /org/freedesktop/sample/object/name              \\
             org.freedesktop.ExampleInterface.ExampleMethod   \\
-            int32:47 string:'hello world' double:65.32
+            int32:47 string:'hello world' double:65.32       \\
+            array:byte[0,1,2]
 
 .fi
 
Index: dbus-print-message.c
===================================================================
--- tools/dbus-print-message.c	(revision 691)
+++ tools/dbus-print-message.c	(working copy)
@@ -39,6 +39,78 @@
     }
 }
 
+static void
+iterate (DBusMessageIter* iter, int entry_type)
+{
+    do
+    {
+      char *str;
+      dbus_uint32_t uint32;
+      dbus_int32_t int32;
+      double d;
+      unsigned char byte;
+      dbus_bool_t boolean;
+      int type = dbus_message_iter_get_arg_type (iter);
+	    
+      DBusMessageIter array_iter;
+      int array_type = DBUS_TYPE_INVALID;
+      
+      if (type == DBUS_TYPE_INVALID)
+       {
+       if (entry_type == DBUS_TYPE_INVALID)
+         break;
+       else 
+         type == entry_type;
+       }
+      
+      switch (type)
+	{
+	case DBUS_TYPE_STRING:
+	  str = dbus_message_iter_get_string (iter);
+	  printf ("string:%s\n", str);
+	  break;
+
+	case DBUS_TYPE_INT32:
+	  int32 = dbus_message_iter_get_int32 (iter);
+	  printf ("int32:%d\n", int32);
+	  break;
+
+	case DBUS_TYPE_UINT32:
+	  uint32 = dbus_message_iter_get_uint32 (iter);
+	  printf ("int32:%u\n", uint32);
+	  break;
+
+	case DBUS_TYPE_DOUBLE:
+	  d = dbus_message_iter_get_double (iter);
+	  printf ("double:%f\n", d);
+	  break;
+
+	case DBUS_TYPE_BYTE:
+	  byte = dbus_message_iter_get_byte (iter);
+	  printf ("byte:%d\n", byte);
+	  break;
+
+	case DBUS_TYPE_BOOLEAN:
+	  boolean = dbus_message_iter_get_boolean (iter);
+	  printf ("boolean:%s\n", boolean ? "true" : "false");
+	  break;
+	
+	case DBUS_TYPE_ARRAY:
+	  dbus_message_iter_init_array_iterator (iter, 
+						 &array_iter,
+						 &array_type);
+	  printf ("array[\n");
+	  iterate (&array_iter, array_type);
+	  printf ("]\n");
+	  break;
+	
+	default:
+	  printf ("(unknown arg type %d)\n", type);
+	  break;
+	}
+    } while (dbus_message_iter_next (iter));
+}
+
 void
 print_message (DBusMessage *message)
 {
@@ -81,55 +153,6 @@
       
   dbus_message_iter_init (message, &iter);
 
-  do
-    {
-      int type = dbus_message_iter_get_arg_type (&iter);
-      char *str;
-      dbus_uint32_t uint32;
-      dbus_int32_t int32;
-      double d;
-      unsigned char byte;
-      dbus_bool_t boolean;
-
-      if (type == DBUS_TYPE_INVALID)
-	break;
-
-      switch (type)
-	{
-	case DBUS_TYPE_STRING:
-	  str = dbus_message_iter_get_string (&iter);
-	  printf ("string:%s\n", str);
-	  break;
-
-	case DBUS_TYPE_INT32:
-	  int32 = dbus_message_iter_get_int32 (&iter);
-	  printf ("int32:%d\n", int32);
-	  break;
-
-	case DBUS_TYPE_UINT32:
-	  uint32 = dbus_message_iter_get_uint32 (&iter);
-	  printf ("int32:%u\n", uint32);
-	  break;
-
-	case DBUS_TYPE_DOUBLE:
-	  d = dbus_message_iter_get_double (&iter);
-	  printf ("double:%f\n", d);
-	  break;
-
-	case DBUS_TYPE_BYTE:
-	  byte = dbus_message_iter_get_byte (&iter);
-	  printf ("byte:%d\n", byte);
-	  break;
-
-	case DBUS_TYPE_BOOLEAN:
-	  boolean = dbus_message_iter_get_boolean (&iter);
-	  printf ("boolean:%s\n", boolean ? "true" : "false");
-	  break;
-
-	default:
-	  printf ("(unknown arg type %d)\n", type);
-	  break;
-	}
-    } while (dbus_message_iter_next (&iter));
+  iterate (&iter, DBUS_TYPE_INVALID);
 }
 
Index: dbus-send.c
===================================================================
--- tools/dbus-send.c	(revision 691)
+++ tools/dbus-send.c	(working copy)
@@ -34,6 +34,146 @@
   exit (ecode);
 }
 
+
+static int 
+get_type (char **argv, char *arg)
+{
+  int type;
+	
+  if (arg[0] == 0 || !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, "array"))
+	type = DBUS_TYPE_ARRAY;
+      else
+	{
+	  fprintf (stderr, "%s: Unknown type \"%s\"\n", argv[0], arg);
+	  exit (1);
+	}
+	
+  return type;
+}
+
+
+static void
+append (char **argv, char *arg, char *c, DBusMessageIter *iter)
+{
+  int type, atype = 0;
+  dbus_uint32_t uint32;
+  dbus_int32_t int32;
+  double d;
+  unsigned char byte;
+  DBusMessageIter array_iter;
+  int end_found = 0;
+  char *next;
+
+  /* FIXME - we are ignoring OOM returns on all these functions */
+	
+  type = get_type(argv, arg);
+  if (type == DBUS_TYPE_ARRAY)
+    {
+      arg = c;
+      c = strchr (c, '[');	      
+      if (c == NULL)
+      {
+        fprintf (stderr, "%s: Data item \"%s\" is badly formed\n", argv[0], arg);
+	exit (1);
+      }
+      
+      if (strchr(c, ']') == NULL)
+      {
+        fprintf (stderr, "%s: Data item \"%s\" is badly formed\n", argv[0], arg);
+        exit (1);
+      }
+	
+      *(c++) = 0;
+	
+      atype = get_type(argv, arg);
+    }
+      
+
+  switch (type)
+    {
+    case DBUS_TYPE_BYTE:
+      byte = strtoul (c, NULL, 0);
+      dbus_message_iter_append_byte (iter, byte);
+      break;
+
+    case DBUS_TYPE_DOUBLE:
+      d = strtod (c, NULL);
+      dbus_message_iter_append_double (iter, d);
+      break;
+
+    case DBUS_TYPE_INT32:
+      int32 = strtol (c, NULL, 0);
+      dbus_message_iter_append_int32 (iter, int32);
+      break;
+
+    case DBUS_TYPE_UINT32:
+      uint32 = strtoul (c, NULL, 0);
+      dbus_message_iter_append_uint32 (iter, uint32);
+      break;
+
+    case DBUS_TYPE_STRING:
+      dbus_message_iter_append_string (iter, c);
+      break;
+
+    case DBUS_TYPE_BOOLEAN:
+      if (strcmp(c, "true") == 0)
+        dbus_message_iter_append_boolean (iter, TRUE);
+      else if (strcmp(c, "false") == 0)
+        dbus_message_iter_append_boolean (iter, FALSE);
+      else
+        {
+          fprintf (stderr, "%s: Expected \"true\" or \"false\" instead of \"%s\"\n", argv[0], c);
+          exit (1);
+        }
+      break;
+	
+      case DBUS_TYPE_ARRAY:
+        /* Decompose parameters and put it as array */
+        dbus_message_iter_append_array(iter, &array_iter, atype);
+	
+        while(!end_found)
+	  {
+            next = strchr(c, ',');
+            if (next == NULL) 
+              {
+                next = strchr(c, ']');
+		
+                if (next != NULL)
+		  next[0] = 0;
+		else 
+		  break;
+		
+		end_found = 1;
+              } 
+	    else 
+	      {
+                next[0] = 0;
+                next++;
+              }
+	      
+              append (argv, arg, c, &array_iter);
+              c = next;
+	  }
+	break;
+	  
+      default:
+	fprintf (stderr, "%s: Unsupported data type\n", argv[0]);
+	exit (1);
+    }
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -174,12 +314,7 @@
     {
       char *arg;
       char *c;
-      int type;
-      dbus_uint32_t uint32;
-      dbus_int32_t int32;
-      double d;
-      unsigned char byte;
-
+      
       type = DBUS_TYPE_INVALID;
       arg = argv[i++];
       c = strchr (arg, ':');
@@ -192,67 +327,7 @@
 
       *(c++) = 0;
 
-      if (arg[0] == 0 || !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
-	{
-	  fprintf (stderr, "%s: Unknown type \"%s\"\n", argv[0], arg);
-	  exit (1);
-	}
-
-      /* FIXME - we are ignoring OOM returns on all these functions */
-      switch (type)
-	{
-	case DBUS_TYPE_BYTE:
-	  byte = strtoul (c, NULL, 0);
-	  dbus_message_iter_append_byte (&iter, byte);
-	  break;
-
-	case DBUS_TYPE_DOUBLE:
-	  d = strtod (c, NULL);
-	  dbus_message_iter_append_double (&iter, d);
-	  break;
-
-	case DBUS_TYPE_INT32:
-	  int32 = strtol (c, NULL, 0);
-	  dbus_message_iter_append_int32 (&iter, int32);
-	  break;
-
-	case DBUS_TYPE_UINT32:
-	  uint32 = strtoul (c, NULL, 0);
-	  dbus_message_iter_append_uint32 (&iter, uint32);
-	  break;
-
-	case DBUS_TYPE_STRING:
-	  dbus_message_iter_append_string (&iter, c);
-	  break;
-
-	case DBUS_TYPE_BOOLEAN:
-          if (strcmp(c, "true") == 0)
-            dbus_message_iter_append_boolean (&iter, TRUE);
-	  else if (strcmp(c, "false") == 0)
-            dbus_message_iter_append_boolean (&iter, FALSE);
-	  else
-	    {
-	      fprintf (stderr, "%s: Expected \"true\" or \"false\" instead of \"%s\"\n", argv[0], c);
-	      exit (1);
-	    }
-	  break;
-
-	default:
-	  fprintf (stderr, "%s: Unsupported data type\n", argv[0]);
-	  exit (1);
-	}
+      append (argv, arg, c, &iter);
     }
 
   if (print_reply)