D-Bus  1.11.10
dbus-message-util.c
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* dbus-message-util.c Would be in dbus-message.c, but only used by bus/tests
3  *
4  * Copyright (C) 2002, 2003, 2004, 2005 Red Hat Inc.
5  * Copyright (C) 2002, 2003 CodeFactory AB
6  *
7  * Licensed under the Academic Free License version 2.1
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 #include <config.h>
26 #include "dbus-internals.h"
27 #include "dbus-test.h"
28 #include "dbus-message-private.h"
29 #include "dbus-marshal-recursive.h"
30 #include "dbus-string.h"
31 #ifdef HAVE_UNIX_FD_PASSING
32 #include "dbus-sysdeps-unix.h"
33 #endif
34 
35 #ifdef __linux__
36 /* Necessary for the Linux-specific fd leak checking code only */
37 #include <sys/types.h>
38 #include <dirent.h>
39 #include <stdlib.h>
40 #include <errno.h>
41 #endif
42 
48 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
49 
61 static dbus_bool_t
62 dbus_message_iter_get_args (DBusMessageIter *iter,
63  DBusError *error,
64  int first_arg_type,
65  ...)
66 {
67  dbus_bool_t retval;
68  va_list var_args;
69 
70  _dbus_return_val_if_fail (iter != NULL, FALSE);
71  _dbus_return_val_if_error_is_set (error, FALSE);
72 
73  va_start (var_args, first_arg_type);
74  retval = _dbus_message_iter_get_args_valist (iter, error, first_arg_type, var_args);
75  va_end (var_args);
76 
77  return retval;
78 }
79 #endif /* DBUS_ENABLE_EMBEDDED_TESTS */
80 
83 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
84 #include "dbus-test.h"
85 #include "dbus-message-factory.h"
86 #include <stdio.h>
87 #include <stdlib.h>
88 
89 static int validities_seen[DBUS_VALIDITY_LAST + _DBUS_NEGATIVE_VALIDITY_COUNT];
90 
91 static void
92 reset_validities_seen (void)
93 {
94  int i;
95  i = 0;
96  while (i < _DBUS_N_ELEMENTS (validities_seen))
97  {
98  validities_seen[i] = 0;
99  ++i;
100  }
101 }
102 
103 static void
104 record_validity_seen (DBusValidity validity)
105 {
106  validities_seen[validity + _DBUS_NEGATIVE_VALIDITY_COUNT] += 1;
107 }
108 
109 static void
110 print_validities_seen (dbus_bool_t not_seen)
111 {
112  int i;
113  i = 0;
114  while (i < _DBUS_N_ELEMENTS (validities_seen))
115  {
116  if ((i - _DBUS_NEGATIVE_VALIDITY_COUNT) == DBUS_VALIDITY_UNKNOWN ||
117  (i - _DBUS_NEGATIVE_VALIDITY_COUNT) == DBUS_INVALID_FOR_UNKNOWN_REASON)
118  ;
119  else if ((not_seen && validities_seen[i] == 0) ||
120  (!not_seen && validities_seen[i] > 0))
121  printf ("validity %3d seen %d times\n",
122  i - _DBUS_NEGATIVE_VALIDITY_COUNT,
123  validities_seen[i]);
124  ++i;
125  }
126 }
127 
128 static void
129 check_memleaks (void)
130 {
131  dbus_shutdown ();
132 
133  if (_dbus_get_malloc_blocks_outstanding () != 0)
134  {
135  _dbus_warn ("%d dbus_malloc blocks were not freed in %s",
136  _dbus_get_malloc_blocks_outstanding (), __FILE__);
137  _dbus_assert_not_reached ("memleaks");
138  }
139 }
140 
141 #ifdef __linux__
142 struct DBusInitialFDs {
143  fd_set set;
144 };
145 #endif
146 
147 DBusInitialFDs *
148 _dbus_check_fdleaks_enter (void)
149 {
150 #ifdef __linux__
151  DIR *d;
152  DBusInitialFDs *fds;
153 
154  /* this is plain malloc so it won't interfere with leak checking */
155  fds = malloc (sizeof (DBusInitialFDs));
156  _dbus_assert (fds != NULL);
157 
158  /* This works on Linux only */
159 
160  if ((d = opendir ("/proc/self/fd")))
161  {
162  struct dirent *de;
163 
164  while ((de = readdir(d)))
165  {
166  long l;
167  char *e = NULL;
168  int fd;
169 
170  if (de->d_name[0] == '.')
171  continue;
172 
173  errno = 0;
174  l = strtol (de->d_name, &e, 10);
175  _dbus_assert (errno == 0 && e && !*e);
176 
177  fd = (int) l;
178 
179  if (fd < 3)
180  continue;
181 
182  if (fd == dirfd (d))
183  continue;
184 
185  FD_SET (fd, &fds->set);
186  }
187 
188  closedir (d);
189  }
190 
191  return fds;
192 #else
193  return NULL;
194 #endif
195 }
196 
197 void
198 _dbus_check_fdleaks_leave (DBusInitialFDs *fds)
199 {
200 #ifdef __linux__
201  DIR *d;
202 
203  /* This works on Linux only */
204 
205  if ((d = opendir ("/proc/self/fd")))
206  {
207  struct dirent *de;
208 
209  while ((de = readdir(d)))
210  {
211  long l;
212  char *e = NULL;
213  int fd;
214 
215  if (de->d_name[0] == '.')
216  continue;
217 
218  errno = 0;
219  l = strtol (de->d_name, &e, 10);
220  _dbus_assert (errno == 0 && e && !*e);
221 
222  fd = (int) l;
223 
224  if (fd < 3)
225  continue;
226 
227  if (fd == dirfd (d))
228  continue;
229 
230  if (FD_ISSET (fd, &fds->set))
231  continue;
232 
233  _dbus_warn ("file descriptor %i leaked in %s.", fd, __FILE__);
234  _dbus_assert_not_reached ("fdleaks");
235  }
236 
237  closedir (d);
238  }
239 
240  free (fds);
241 #else
242  _dbus_assert (fds == NULL);
243 #endif
244 }
245 
246 static dbus_bool_t
247 check_have_valid_message (DBusMessageLoader *loader)
248 {
249  DBusMessage *message;
250  dbus_bool_t retval;
251 
252  message = NULL;
253  retval = FALSE;
254 
256  {
257  _dbus_warn ("loader corrupted on message that was expected to be valid; invalid reason %d",
258  loader->corruption_reason);
259  goto failed;
260  }
261 
262  message = _dbus_message_loader_pop_message (loader);
263  if (message == NULL)
264  {
265  _dbus_warn ("didn't load message that was expected to be valid (message not popped)");
266  goto failed;
267  }
268 
269  if (_dbus_string_get_length (&loader->data) > 0)
270  {
271  _dbus_warn ("had leftover bytes from expected-to-be-valid single message");
272  goto failed;
273  }
274 
275 #if 0
276  /* FIXME */
277  /* Verify that we're able to properly deal with the message.
278  * For example, this would detect improper handling of messages
279  * in nonstandard byte order.
280  */
281  if (!check_message_handling (message))
282  goto failed;
283 #endif
284 
285  record_validity_seen (DBUS_VALID);
286 
287  retval = TRUE;
288 
289  failed:
290  if (message)
291  dbus_message_unref (message);
292 
293  return retval;
294 }
295 
296 static dbus_bool_t
297 check_invalid_message (DBusMessageLoader *loader,
298  DBusValidity expected_validity)
299 {
300  dbus_bool_t retval;
301 
302  retval = FALSE;
303 
305  {
306  _dbus_warn ("loader not corrupted on message that was expected to be invalid");
307  goto failed;
308  }
309 
310  record_validity_seen (loader->corruption_reason);
311 
312  if (expected_validity != DBUS_INVALID_FOR_UNKNOWN_REASON &&
313  loader->corruption_reason != expected_validity)
314  {
315  _dbus_warn ("expected message to be corrupted for reason %d and was corrupted for %d instead",
316  expected_validity, loader->corruption_reason);
317  goto failed;
318  }
319 
320  retval = TRUE;
321 
322  failed:
323  return retval;
324 }
325 
326 static dbus_bool_t
327 check_incomplete_message (DBusMessageLoader *loader)
328 {
329  DBusMessage *message;
330  dbus_bool_t retval;
331 
332  message = NULL;
333  retval = FALSE;
334 
336  {
337  _dbus_warn ("loader corrupted on message that was expected to be valid (but incomplete), corruption reason %d",
338  loader->corruption_reason);
339  goto failed;
340  }
341 
342  message = _dbus_message_loader_pop_message (loader);
343  if (message != NULL)
344  {
345  _dbus_warn ("loaded message that was expected to be incomplete");
346  goto failed;
347  }
348 
349  record_validity_seen (DBUS_VALID_BUT_INCOMPLETE);
350  retval = TRUE;
351 
352  failed:
353  if (message)
354  dbus_message_unref (message);
355  return retval;
356 }
357 
358 static dbus_bool_t
359 check_loader_results (DBusMessageLoader *loader,
360  DBusValidity expected_validity)
361 {
363  _dbus_assert_not_reached ("no memory to queue messages");
364 
365  if (expected_validity == DBUS_VALID)
366  return check_have_valid_message (loader);
367  else if (expected_validity == DBUS_VALID_BUT_INCOMPLETE)
368  return check_incomplete_message (loader);
369  else if (expected_validity == DBUS_VALIDITY_UNKNOWN)
370  {
371  /* here we just know we didn't segfault and that was the
372  * only test. Also, we record that we got coverage
373  * for the validity reason.
374  */
376  record_validity_seen (loader->corruption_reason);
377 
378  return TRUE;
379  }
380  else
381  return check_invalid_message (loader, expected_validity);
382 }
383 
392 dbus_internal_do_not_use_load_message_file (const DBusString *filename,
393  DBusString *data)
394 {
395  dbus_bool_t retval;
396  DBusError error = DBUS_ERROR_INIT;
397 
398  retval = FALSE;
399 
400  _dbus_verbose ("Loading raw %s\n", _dbus_string_get_const_data (filename));
401  if (!_dbus_file_get_contents (data, filename, &error))
402  {
403  _dbus_warn ("Could not load message file %s: %s",
404  _dbus_string_get_const_data (filename),
405  error.message);
406  dbus_error_free (&error);
407  goto failed;
408  }
409 
410  retval = TRUE;
411 
412  failed:
413 
414  return retval;
415 }
416 
426 dbus_internal_do_not_use_try_message_file (const DBusString *filename,
427  DBusValidity expected_validity)
428 {
429  DBusString data;
430  dbus_bool_t retval;
431 
432  retval = FALSE;
433 
434  if (!_dbus_string_init (&data))
435  _dbus_assert_not_reached ("could not allocate string");
436 
437  if (!dbus_internal_do_not_use_load_message_file (filename, &data))
438  goto failed;
439 
440  retval = dbus_internal_do_not_use_try_message_data (&data, expected_validity);
441 
442  failed:
443 
444  if (!retval)
445  {
446  if (_dbus_string_get_length (&data) > 0)
448  _dbus_string_get_length (&data));
449 
450  _dbus_warn ("Failed message loader test on %s",
451  _dbus_string_get_const_data (filename));
452  }
453 
454  _dbus_string_free (&data);
455 
456  return retval;
457 }
458 
468 dbus_internal_do_not_use_try_message_data (const DBusString *data,
469  DBusValidity expected_validity)
470 {
471  DBusMessageLoader *loader;
472  dbus_bool_t retval;
473  int len;
474  int i;
475 
476  loader = NULL;
477  retval = FALSE;
478 
479  /* Write the data one byte at a time */
480 
481  loader = _dbus_message_loader_new ();
482  if (loader == NULL)
483  goto failed;
484 
485  /* check some trivial loader functions */
486  _dbus_message_loader_ref (loader);
488 
489  len = _dbus_string_get_length (data);
490  for (i = 0; i < len; i++)
491  {
492  DBusString *buffer;
493 
494  _dbus_message_loader_get_buffer (loader, &buffer, NULL, NULL);
495  if (!_dbus_string_append_byte (buffer,
496  _dbus_string_get_byte (data, i)))
497  goto failed;
498  _dbus_message_loader_return_buffer (loader, buffer);
499  }
500 
501  if (!check_loader_results (loader, expected_validity))
502  goto failed;
503 
505  loader = NULL;
506 
507  /* Write the data all at once */
508 
509  loader = _dbus_message_loader_new ();
510  if (loader == NULL)
511  goto failed;
512 
513  {
514  DBusString *buffer;
515 
516  _dbus_message_loader_get_buffer (loader, &buffer, NULL, NULL);
517  if (!_dbus_string_copy (data, 0, buffer,
518  _dbus_string_get_length (buffer)))
519  goto failed;
520  _dbus_message_loader_return_buffer (loader, buffer);
521  }
522 
523  if (!check_loader_results (loader, expected_validity))
524  goto failed;
525 
527  loader = NULL;
528 
529  /* Write the data 2 bytes at a time */
530 
531  loader = _dbus_message_loader_new ();
532  if (loader == NULL)
533  goto failed;
534 
535  len = _dbus_string_get_length (data);
536  for (i = 0; i < len; i += 2)
537  {
538  DBusString *buffer;
539 
540  _dbus_message_loader_get_buffer (loader, &buffer, NULL, NULL);
541  if (!_dbus_string_append_byte (buffer,
542  _dbus_string_get_byte (data, i)))
543  goto failed;
544 
545  if ((i+1) < len)
546  {
547  if (!_dbus_string_append_byte (buffer,
548  _dbus_string_get_byte (data, i+1)))
549  goto failed;
550  }
551 
552  _dbus_message_loader_return_buffer (loader, buffer);
553  }
554 
555  if (!check_loader_results (loader, expected_validity))
556  goto failed;
557 
559  loader = NULL;
560 
561  retval = TRUE;
562 
563  failed:
564 
565  if (loader)
567 
568  return retval;
569 }
570 
571 static dbus_bool_t
572 process_test_subdir (const DBusString *test_base_dir,
573  const char *subdir,
574  DBusValidity expected_validity,
575  DBusForeachMessageFileFunc function,
576  void *user_data)
577 {
578  DBusString test_directory;
579  DBusString filename;
580  DBusDirIter *dir;
581  dbus_bool_t retval;
582  DBusError error = DBUS_ERROR_INIT;
583 
584  retval = FALSE;
585  dir = NULL;
586 
587  if (!_dbus_string_init (&test_directory))
588  _dbus_assert_not_reached ("didn't allocate test_directory");
589 
590  _dbus_string_init_const (&filename, subdir);
591 
592  if (!_dbus_string_copy (test_base_dir, 0,
593  &test_directory, 0))
594  _dbus_assert_not_reached ("couldn't copy test_base_dir to test_directory");
595 
596  if (!_dbus_concat_dir_and_file (&test_directory, &filename))
597  _dbus_assert_not_reached ("couldn't allocate full path");
598 
599  _dbus_string_free (&filename);
600  if (!_dbus_string_init (&filename))
601  _dbus_assert_not_reached ("didn't allocate filename string");
602 
603  dir = _dbus_directory_open (&test_directory, &error);
604  if (dir == NULL)
605  {
606  _dbus_warn ("Could not open %s: %s",
607  _dbus_string_get_const_data (&test_directory),
608  error.message);
609  dbus_error_free (&error);
610  goto failed;
611  }
612 
613  printf ("Testing %s:\n", subdir);
614 
615  next:
616  while (_dbus_directory_get_next_file (dir, &filename, &error))
617  {
618  DBusString full_path;
619 
620  if (!_dbus_string_init (&full_path))
621  _dbus_assert_not_reached ("couldn't init string");
622 
623  if (!_dbus_string_copy (&test_directory, 0, &full_path, 0))
624  _dbus_assert_not_reached ("couldn't copy dir to full_path");
625 
626  if (!_dbus_concat_dir_and_file (&full_path, &filename))
627  _dbus_assert_not_reached ("couldn't concat file to dir");
628 
629  if (_dbus_string_ends_with_c_str (&filename, ".message-raw"))
630  ;
631  else
632  {
633  if (_dbus_string_ends_with_c_str (&filename, ".message"))
634  {
635  printf ("SKIP: Could not load %s, message builder language no longer supported\n",
636  _dbus_string_get_const_data (&filename));
637  }
638 
639  _dbus_verbose ("Skipping non-.message file %s\n",
640  _dbus_string_get_const_data (&filename));
641  _dbus_string_free (&full_path);
642  goto next;
643  }
644 
645  printf (" %s\n",
646  _dbus_string_get_const_data (&filename));
647 
648  if (! (*function) (&full_path,
649  expected_validity, user_data))
650  {
651  _dbus_string_free (&full_path);
652  goto failed;
653  }
654  else
655  _dbus_string_free (&full_path);
656  }
657 
658  if (dbus_error_is_set (&error))
659  {
660  _dbus_warn ("Could not get next file in %s: %s",
661  _dbus_string_get_const_data (&test_directory),
662  error.message);
663  dbus_error_free (&error);
664  goto failed;
665  }
666 
667  retval = TRUE;
668 
669  failed:
670 
671  if (dir)
672  _dbus_directory_close (dir);
673  _dbus_string_free (&test_directory);
674  _dbus_string_free (&filename);
675 
676  return retval;
677 }
678 
689 dbus_internal_do_not_use_foreach_message_file (const char *test_data_dir,
690  DBusForeachMessageFileFunc func,
691  void *user_data)
692 {
693  DBusString test_directory;
694  dbus_bool_t retval;
695 
696  retval = FALSE;
697 
698  _dbus_string_init_const (&test_directory, test_data_dir);
699 
700  if (!process_test_subdir (&test_directory, "valid-messages",
701  DBUS_VALID, func, user_data))
702  goto failed;
703 
704  check_memleaks ();
705 
706  if (!process_test_subdir (&test_directory, "invalid-messages",
707  DBUS_INVALID_FOR_UNKNOWN_REASON, func, user_data))
708  goto failed;
709 
710  check_memleaks ();
711 
712  if (!process_test_subdir (&test_directory, "incomplete-messages",
713  DBUS_VALID_BUT_INCOMPLETE, func, user_data))
714  goto failed;
715 
716  check_memleaks ();
717 
718  retval = TRUE;
719 
720  failed:
721 
722  _dbus_string_free (&test_directory);
723 
724  return retval;
725 }
726 
727 #if 0
728 #define GET_AND_CHECK(iter, typename, literal) \
729  do { \
730  if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_##typename) \
731  _dbus_assert_not_reached ("got wrong argument type from message iter"); \
732  dbus_message_iter_get_basic (&iter, &v_##typename); \
733  if (v_##typename != literal) \
734  _dbus_assert_not_reached ("got wrong value from message iter"); \
735  } while (0)
736 
737 #define GET_AND_CHECK_STRCMP(iter, typename, literal) \
738  do { \
739  if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_##typename) \
740  _dbus_assert_not_reached ("got wrong argument type from message iter"); \
741  dbus_message_iter_get_basic (&iter, &v_##typename); \
742  if (strcmp (v_##typename, literal) != 0) \
743  _dbus_assert_not_reached ("got wrong value from message iter"); \
744  } while (0)
745 
746 #define GET_AND_CHECK_AND_NEXT(iter, typename, literal) \
747  do { \
748  GET_AND_CHECK(iter, typename, literal); \
749  if (!dbus_message_iter_next (&iter)) \
750  _dbus_assert_not_reached ("failed to move iter to next"); \
751  } while (0)
752 
753 #define GET_AND_CHECK_STRCMP_AND_NEXT(iter, typename, literal) \
754  do { \
755  GET_AND_CHECK_STRCMP(iter, typename, literal); \
756  if (!dbus_message_iter_next (&iter)) \
757  _dbus_assert_not_reached ("failed to move iter to next"); \
758  } while (0)
759 
760 static void
761 message_iter_test (DBusMessage *message)
762 {
763  DBusMessageIter iter, array, array2;
764  const char *v_STRING;
765  double v_DOUBLE;
766  dbus_int16_t v_INT16;
767  dbus_uint16_t v_UINT16;
768  dbus_int32_t v_INT32;
769  dbus_uint32_t v_UINT32;
770  dbus_int64_t v_INT64;
771  dbus_uint64_t v_UINT64;
772  unsigned char v_BYTE;
773  dbus_bool_t v_BOOLEAN;
774 
775  const dbus_int32_t *our_int_array;
776  int len;
777 
778  dbus_message_iter_init (message, &iter);
779 
780  GET_AND_CHECK_STRCMP_AND_NEXT (iter, STRING, "Test string");
781  GET_AND_CHECK_AND_NEXT (iter, INT32, -0x12345678);
782  GET_AND_CHECK_AND_NEXT (iter, UINT32, 0xedd1e);
783  GET_AND_CHECK_AND_NEXT (iter, DOUBLE, 3.14159);
784 
786  _dbus_assert_not_reached ("Argument type not an array");
787 
789  _dbus_assert_not_reached ("Array type not double");
790 
791  dbus_message_iter_recurse (&iter, &array);
792 
793  GET_AND_CHECK_AND_NEXT (array, DOUBLE, 1.5);
794  GET_AND_CHECK (array, DOUBLE, 2.5);
795 
796  if (dbus_message_iter_next (&array))
797  _dbus_assert_not_reached ("Didn't reach end of array");
798 
799  if (!dbus_message_iter_next (&iter))
800  _dbus_assert_not_reached ("Reached end of arguments");
801 
802  GET_AND_CHECK_AND_NEXT (iter, BYTE, 0xF0);
803 
805  _dbus_assert_not_reached ("no array");
806 
808  _dbus_assert_not_reached ("Array type not int32");
809 
810  /* Empty array */
811  dbus_message_iter_recurse (&iter, &array);
812 
813  if (dbus_message_iter_next (&array))
814  _dbus_assert_not_reached ("Didn't reach end of array");
815 
816  if (!dbus_message_iter_next (&iter))
817  _dbus_assert_not_reached ("Reached end of arguments");
818 
819  GET_AND_CHECK (iter, BYTE, 0xF0);
820 
821  if (dbus_message_iter_next (&iter))
822  _dbus_assert_not_reached ("Didn't reach end of arguments");
823 }
824 #endif
825 
826 static void
827 verify_test_message (DBusMessage *message)
828 {
829  DBusMessageIter iter;
830  DBusError error = DBUS_ERROR_INIT;
831  dbus_int16_t our_int16;
832  dbus_uint16_t our_uint16;
833  dbus_int32_t our_int;
834  dbus_uint32_t our_uint;
835  const char *our_str;
836  double our_double;
837  double v_DOUBLE;
838  dbus_bool_t our_bool;
839  unsigned char our_byte_1, our_byte_2;
840  const dbus_uint32_t *our_uint32_array = (void*)0xdeadbeef;
841  int our_uint32_array_len;
842  dbus_int32_t *our_int32_array = (void*)0xdeadbeef;
843  int our_int32_array_len;
844  dbus_int64_t our_int64;
845  dbus_uint64_t our_uint64;
846  dbus_int64_t *our_uint64_array = (void*)0xdeadbeef;
847  int our_uint64_array_len;
848  const dbus_int64_t *our_int64_array = (void*)0xdeadbeef;
849  int our_int64_array_len;
850  const double *our_double_array = (void*)0xdeadbeef;
851  int our_double_array_len;
852  const unsigned char *our_byte_array = (void*)0xdeadbeef;
853  int our_byte_array_len;
854  const dbus_bool_t *our_boolean_array = (void*)0xdeadbeef;
855  int our_boolean_array_len;
856  char **our_string_array;
857  int our_string_array_len;
858 
859  dbus_message_iter_init (message, &iter);
860 
861  if (!dbus_message_iter_get_args (&iter, &error,
862  DBUS_TYPE_INT16, &our_int16,
863  DBUS_TYPE_UINT16, &our_uint16,
864  DBUS_TYPE_INT32, &our_int,
865  DBUS_TYPE_UINT32, &our_uint,
866  DBUS_TYPE_INT64, &our_int64,
867  DBUS_TYPE_UINT64, &our_uint64,
868  DBUS_TYPE_STRING, &our_str,
869  DBUS_TYPE_DOUBLE, &our_double,
870  DBUS_TYPE_BOOLEAN, &our_bool,
871  DBUS_TYPE_BYTE, &our_byte_1,
872  DBUS_TYPE_BYTE, &our_byte_2,
874  &our_uint32_array, &our_uint32_array_len,
876  &our_int32_array, &our_int32_array_len,
878  &our_uint64_array, &our_uint64_array_len,
880  &our_int64_array, &our_int64_array_len,
882  &our_double_array, &our_double_array_len,
884  &our_byte_array, &our_byte_array_len,
886  &our_boolean_array, &our_boolean_array_len,
888  &our_string_array, &our_string_array_len,
889  0))
890  {
891  _dbus_warn ("error: %s - %s", error.name,
892  (error.message != NULL) ? error.message : "no message");
893  _dbus_assert_not_reached ("Could not get arguments");
894  }
895 
896  if (our_int16 != -0x123)
897  _dbus_assert_not_reached ("16-bit integers differ!");
898 
899  if (our_uint16 != 0x123)
900  _dbus_assert_not_reached ("16-bit uints differ!");
901 
902  if (our_int != -0x12345678)
903  _dbus_assert_not_reached ("integers differ!");
904 
905  if (our_uint != 0x12300042)
906  _dbus_assert_not_reached ("uints differ!");
907 
908  if (our_int64 != DBUS_INT64_CONSTANT (-0x123456789abcd))
909  _dbus_assert_not_reached ("64-bit integers differ!");
910  if (our_uint64 != DBUS_UINT64_CONSTANT (0x123456789abcd))
911  _dbus_assert_not_reached ("64-bit unsigned integers differ!");
912 
913  v_DOUBLE = 3.14159;
914  if (! _DBUS_DOUBLES_BITWISE_EQUAL (our_double, v_DOUBLE))
915  _dbus_assert_not_reached ("doubles differ!");
916 
917  if (strcmp (our_str, "Test string") != 0)
918  _dbus_assert_not_reached ("strings differ!");
919 
920  if (!our_bool)
921  _dbus_assert_not_reached ("booleans differ");
922 
923  if (our_byte_1 != 42)
924  _dbus_assert_not_reached ("bytes differ!");
925 
926  if (our_byte_2 != 24)
927  _dbus_assert_not_reached ("bytes differ!");
928 
929  if (our_uint32_array_len != 4 ||
930  our_uint32_array[0] != 0x12345678 ||
931  our_uint32_array[1] != 0x23456781 ||
932  our_uint32_array[2] != 0x34567812 ||
933  our_uint32_array[3] != 0x45678123)
934  _dbus_assert_not_reached ("uint array differs");
935 
936  if (our_int32_array_len != 4 ||
937  our_int32_array[0] != 0x12345678 ||
938  our_int32_array[1] != -0x23456781 ||
939  our_int32_array[2] != 0x34567812 ||
940  our_int32_array[3] != -0x45678123)
941  _dbus_assert_not_reached ("int array differs");
942 
943  if (our_uint64_array_len != 4 ||
944  our_uint64_array[0] != 0x12345678 ||
945  our_uint64_array[1] != 0x23456781 ||
946  our_uint64_array[2] != 0x34567812 ||
947  our_uint64_array[3] != 0x45678123)
948  _dbus_assert_not_reached ("uint64 array differs");
949 
950  if (our_int64_array_len != 4 ||
951  our_int64_array[0] != 0x12345678 ||
952  our_int64_array[1] != -0x23456781 ||
953  our_int64_array[2] != 0x34567812 ||
954  our_int64_array[3] != -0x45678123)
955  _dbus_assert_not_reached ("int64 array differs");
956 
957  if (our_double_array_len != 3)
958  _dbus_assert_not_reached ("double array had wrong length");
959 
960  /* On all IEEE machines (i.e. everything sane) exact equality
961  * should be preserved over the wire
962  */
963  v_DOUBLE = 0.1234;
964  if (! _DBUS_DOUBLES_BITWISE_EQUAL (our_double_array[0], v_DOUBLE))
965  _dbus_assert_not_reached ("double array had wrong values");
966  v_DOUBLE = 9876.54321;
967  if (! _DBUS_DOUBLES_BITWISE_EQUAL (our_double_array[1], v_DOUBLE))
968  _dbus_assert_not_reached ("double array had wrong values");
969  v_DOUBLE = -300.0;
970  if (! _DBUS_DOUBLES_BITWISE_EQUAL (our_double_array[2], v_DOUBLE))
971  _dbus_assert_not_reached ("double array had wrong values");
972 
973  if (our_byte_array_len != 4)
974  _dbus_assert_not_reached ("byte array had wrong length");
975 
976  if (our_byte_array[0] != 'a' ||
977  our_byte_array[1] != 'b' ||
978  our_byte_array[2] != 'c' ||
979  our_byte_array[3] != 234)
980  _dbus_assert_not_reached ("byte array had wrong values");
981 
982  if (our_boolean_array_len != 5)
983  _dbus_assert_not_reached ("bool array had wrong length");
984 
985  if (our_boolean_array[0] != TRUE ||
986  our_boolean_array[1] != FALSE ||
987  our_boolean_array[2] != TRUE ||
988  our_boolean_array[3] != TRUE ||
989  our_boolean_array[4] != FALSE)
990  _dbus_assert_not_reached ("bool array had wrong values");
991 
992  if (our_string_array_len != 4)
993  _dbus_assert_not_reached ("string array was wrong length");
994 
995  if (strcmp (our_string_array[0], "Foo") != 0 ||
996  strcmp (our_string_array[1], "bar") != 0 ||
997  strcmp (our_string_array[2], "") != 0 ||
998  strcmp (our_string_array[3], "woo woo woo woo") != 0)
999  _dbus_assert_not_reached ("string array had wrong values");
1000 
1001  dbus_free_string_array (our_string_array);
1002 
1003  if (dbus_message_iter_next (&iter))
1004  _dbus_assert_not_reached ("Didn't reach end of arguments");
1005 }
1006 
1007 static void
1008 verify_test_message_args_ignored (DBusMessage *message)
1009 {
1010  DBusMessageIter iter;
1011  DBusError error = DBUS_ERROR_INIT;
1012  dbus_uint32_t our_uint;
1013  DBusInitialFDs *initial_fds;
1014 
1015  initial_fds = _dbus_check_fdleaks_enter ();
1016 
1017  /* parse with empty signature: "" */
1018  dbus_message_iter_init (message, &iter);
1019  if (!dbus_message_iter_get_args (&iter, &error,
1021  {
1022  _dbus_warn ("error: %s - %s", error.name,
1023  (error.message != NULL) ? error.message : "no message");
1024  }
1025  else
1026  {
1027  _dbus_assert (!dbus_error_is_set (&error));
1028  _dbus_verbose ("arguments ignored.\n");
1029  }
1030 
1031  /* parse with shorter signature: "u" */
1032  dbus_message_iter_init (message, &iter);
1033  if (!dbus_message_iter_get_args (&iter, &error,
1034  DBUS_TYPE_UINT32, &our_uint,
1036  {
1037  _dbus_warn ("error: %s - %s", error.name,
1038  (error.message != NULL) ? error.message : "no message");
1039  }
1040  else
1041  {
1042  _dbus_assert (!dbus_error_is_set (&error));
1043  _dbus_verbose ("arguments ignored.\n");
1044  }
1045 
1046  _dbus_check_fdleaks_leave (initial_fds);
1047 }
1048 
1049 static void
1050 verify_test_message_memleak (DBusMessage *message)
1051 {
1052  DBusMessageIter iter;
1053  DBusError error = DBUS_ERROR_INIT;
1054  dbus_uint32_t our_uint1;
1055  dbus_uint32_t our_uint2;
1056  dbus_uint32_t our_uint3;
1057  char **our_string_array1;
1058  int our_string_array_len1;
1059  char **our_string_array2;
1060  int our_string_array_len2;
1061 #ifdef HAVE_UNIX_FD_PASSING
1062  int our_unix_fd1;
1063  int our_unix_fd2;
1064 #endif
1065  DBusInitialFDs *initial_fds;
1066 
1067  initial_fds = _dbus_check_fdleaks_enter ();
1068 
1069  /* parse with wrong signature: "uashuu" */
1070  dbus_error_free (&error);
1071  dbus_message_iter_init (message, &iter);
1072  if (!dbus_message_iter_get_args (&iter, &error,
1073  DBUS_TYPE_UINT32, &our_uint1,
1075  &our_string_array1, &our_string_array_len1,
1076 #ifdef HAVE_UNIX_FD_PASSING
1077  DBUS_TYPE_UNIX_FD, &our_unix_fd1,
1078 #endif
1079  DBUS_TYPE_UINT32, &our_uint2,
1080  DBUS_TYPE_UINT32, &our_uint3,
1082  {
1083  _dbus_verbose ("expected error: %s - %s\n", error.name,
1084  (error.message != NULL) ? error.message : "no message");
1085  /* ensure array of string and unix fd not leaked */
1086  _dbus_assert (our_string_array1 == NULL);
1087 #ifdef HAVE_UNIX_FD_PASSING
1088  _dbus_assert (our_unix_fd1 == -1);
1089 #endif
1090  }
1091  else
1092  {
1093  _dbus_warn ("error: parse with wrong signature: 'uashuu'.");
1094  }
1095 
1096  /* parse with wrong signature: "uashuashu" */
1097  dbus_message_iter_init (message, &iter);
1098  dbus_error_free (&error);
1099  if (!dbus_message_iter_get_args (&iter, &error,
1100  DBUS_TYPE_UINT32, &our_uint1,
1102  &our_string_array1, &our_string_array_len1,
1103 #ifdef HAVE_UNIX_FD_PASSING
1104  DBUS_TYPE_UNIX_FD, &our_unix_fd1,
1105 #endif
1106  DBUS_TYPE_UINT32, &our_uint2,
1108  &our_string_array2, &our_string_array_len2,
1109 #ifdef HAVE_UNIX_FD_PASSING
1110  DBUS_TYPE_UNIX_FD, &our_unix_fd2,
1111 #endif
1112  DBUS_TYPE_UINT32, &our_uint3,
1114  {
1115  _dbus_verbose ("expected error: %s - %s\n", error.name,
1116  (error.message != NULL) ? error.message : "no message");
1117  /* ensure array of string and unix fd not leaked */
1118  _dbus_assert (our_string_array1 == NULL);
1119  _dbus_assert (our_string_array2 == NULL);
1120 #ifdef HAVE_UNIX_FD_PASSING
1121  _dbus_assert (our_unix_fd1 == -1);
1122  _dbus_assert (our_unix_fd2 == -1);
1123 #endif
1124  }
1125  else
1126  {
1127  _dbus_warn ("error: parse with wrong signature: 'uashuashu'.");
1128  }
1129 
1130  /* parse with correct signature: "uashuash" */
1131  dbus_message_iter_init (message, &iter);
1132  dbus_error_free (&error);
1133  if (!dbus_message_iter_get_args (&iter, &error,
1134  DBUS_TYPE_UINT32, &our_uint1,
1136  &our_string_array1, &our_string_array_len1,
1137 #ifdef HAVE_UNIX_FD_PASSING
1138  DBUS_TYPE_UNIX_FD, &our_unix_fd1,
1139 #endif
1140  DBUS_TYPE_UINT32, &our_uint2,
1142  &our_string_array2, &our_string_array_len2,
1143 #ifdef HAVE_UNIX_FD_PASSING
1144  DBUS_TYPE_UNIX_FD, &our_unix_fd2,
1145 #endif
1147  {
1148  _dbus_warn ("error: %s - %s", error.name,
1149  (error.message != NULL) ? error.message : "no message");
1150  _dbus_assert_not_reached ("Could not get arguments");
1151  }
1152  else
1153  {
1154  dbus_free_string_array (our_string_array1);
1155  dbus_free_string_array (our_string_array2);
1156 #ifdef HAVE_UNIX_FD_PASSING
1157  _dbus_close (our_unix_fd1, &error);
1158  _dbus_close (our_unix_fd2, &error);
1159 #endif
1160  }
1161  _dbus_check_fdleaks_leave (initial_fds);
1162 }
1163 
1171 _dbus_message_test (const char *test_data_dir)
1172 {
1173  DBusMessage *message, *message_without_unix_fds;
1174  DBusMessageLoader *loader;
1175  int i;
1176  const char *data;
1177  DBusMessage *copy;
1178  const char *name1;
1179  const char *name2;
1180  const dbus_uint32_t our_uint32_array[] =
1181  { 0x12345678, 0x23456781, 0x34567812, 0x45678123 };
1182  const dbus_int32_t our_int32_array[] =
1183  { 0x12345678, -0x23456781, 0x34567812, -0x45678123 };
1184  const dbus_uint32_t *v_ARRAY_UINT32 = our_uint32_array;
1185  const dbus_int32_t *v_ARRAY_INT32 = our_int32_array;
1186  const dbus_uint64_t our_uint64_array[] =
1187  { 0x12345678, 0x23456781, 0x34567812, 0x45678123 };
1188  const dbus_int64_t our_int64_array[] =
1189  { 0x12345678, -0x23456781, 0x34567812, -0x45678123 };
1190  const dbus_uint64_t *v_ARRAY_UINT64 = our_uint64_array;
1191  const dbus_int64_t *v_ARRAY_INT64 = our_int64_array;
1192  const char *our_string_array[] = { "Foo", "bar", "", "woo woo woo woo" };
1193  const char *our_string_array1[] = { "foo", "Bar", "", "Woo woo Woo woo" };
1194  const char **v_ARRAY_STRING = our_string_array;
1195  const char **v1_ARRAY_STRING = our_string_array1;
1196  const double our_double_array[] = { 0.1234, 9876.54321, -300.0 };
1197  const double *v_ARRAY_DOUBLE = our_double_array;
1198  const unsigned char our_byte_array[] = { 'a', 'b', 'c', 234 };
1199  const unsigned char *v_ARRAY_BYTE = our_byte_array;
1200  const dbus_bool_t our_boolean_array[] = { TRUE, FALSE, TRUE, TRUE, FALSE };
1201  const dbus_bool_t *v_ARRAY_BOOLEAN = our_boolean_array;
1202  char sig[64];
1203  const char *s;
1204  const char *v_STRING;
1205  double v_DOUBLE;
1206  dbus_int16_t v_INT16;
1207  dbus_uint16_t v_UINT16;
1208  dbus_int32_t v_INT32;
1209  dbus_uint32_t v_UINT32;
1210  dbus_uint32_t v1_UINT32;
1211  dbus_int64_t v_INT64;
1212  dbus_uint64_t v_UINT64;
1213  unsigned char v_BYTE;
1214  unsigned char v2_BYTE;
1215  dbus_bool_t v_BOOLEAN;
1216  DBusMessageIter iter, array_iter, struct_iter;
1217 #ifdef HAVE_UNIX_FD_PASSING
1218  int v_UNIX_FD;
1219  int v1_UNIX_FD;
1220 #endif
1221  char **decomposed;
1222  DBusInitialFDs *initial_fds;
1223  dbus_bool_t ok;
1224  char basic_types[] = DBUS_TYPE_BYTE_AS_STRING \
1234 
1235  initial_fds = _dbus_check_fdleaks_enter ();
1236 
1237  message = dbus_message_new_method_call ("org.freedesktop.DBus.TestService",
1238  "/org/freedesktop/TestPath",
1239  "Foo.TestInterface",
1240  "TestMethod");
1241  _dbus_assert (dbus_message_has_destination (message, "org.freedesktop.DBus.TestService"));
1242  _dbus_assert (dbus_message_is_method_call (message, "Foo.TestInterface",
1243  "TestMethod"));
1244  _dbus_assert (strcmp (dbus_message_get_path (message),
1245  "/org/freedesktop/TestPath") == 0);
1246  dbus_message_set_serial (message, 1234);
1247 
1248  /* string length including nul byte not a multiple of 4 */
1249  if (!dbus_message_set_sender (message, "org.foo.bar1"))
1250  _dbus_assert_not_reached ("out of memory");
1251 
1252  _dbus_assert (dbus_message_has_sender (message, "org.foo.bar1"));
1253  dbus_message_set_reply_serial (message, 5678);
1254 
1256  _dbus_string_get_length (&message->header.data));
1257  _dbus_verbose_bytes_of_string (&message->body, 0,
1258  _dbus_string_get_length (&message->body));
1259 
1260  if (!dbus_message_set_sender (message, NULL))
1261  _dbus_assert_not_reached ("out of memory");
1262 
1263 
1265  _dbus_string_get_length (&message->header.data));
1266  _dbus_verbose_bytes_of_string (&message->body, 0,
1267  _dbus_string_get_length (&message->body));
1268 
1269 
1270  _dbus_assert (!dbus_message_has_sender (message, "org.foo.bar1"));
1271  _dbus_assert (dbus_message_get_serial (message) == 1234);
1272  _dbus_assert (dbus_message_get_reply_serial (message) == 5678);
1273  _dbus_assert (dbus_message_has_destination (message, "org.freedesktop.DBus.TestService"));
1274 
1275  _dbus_assert (dbus_message_get_no_reply (message) == FALSE);
1276  dbus_message_set_no_reply (message, TRUE);
1278  dbus_message_set_no_reply (message, FALSE);
1279  _dbus_assert (dbus_message_get_no_reply (message) == FALSE);
1280 
1281  /* Set/get some header fields */
1282 
1283  if (!dbus_message_set_path (message, "/foo"))
1284  _dbus_assert_not_reached ("out of memory");
1285  _dbus_assert (strcmp (dbus_message_get_path (message),
1286  "/foo") == 0);
1287 
1288  if (!dbus_message_set_interface (message, "org.Foo"))
1289  _dbus_assert_not_reached ("out of memory");
1290  _dbus_assert (strcmp (dbus_message_get_interface (message),
1291  "org.Foo") == 0);
1292 
1293  if (!dbus_message_set_member (message, "Bar"))
1294  _dbus_assert_not_reached ("out of memory");
1295  _dbus_assert (strcmp (dbus_message_get_member (message),
1296  "Bar") == 0);
1297 
1298  /* Set/get them with longer values */
1299  if (!dbus_message_set_path (message, "/foo/bar"))
1300  _dbus_assert_not_reached ("out of memory");
1301  _dbus_assert (strcmp (dbus_message_get_path (message),
1302  "/foo/bar") == 0);
1303 
1304  if (!dbus_message_set_interface (message, "org.Foo.Bar"))
1305  _dbus_assert_not_reached ("out of memory");
1306  _dbus_assert (strcmp (dbus_message_get_interface (message),
1307  "org.Foo.Bar") == 0);
1308 
1309  if (!dbus_message_set_member (message, "BarFoo"))
1310  _dbus_assert_not_reached ("out of memory");
1311  _dbus_assert (strcmp (dbus_message_get_member (message),
1312  "BarFoo") == 0);
1313 
1314  /* Realloc shorter again */
1315 
1316  if (!dbus_message_set_path (message, "/foo"))
1317  _dbus_assert_not_reached ("out of memory");
1318  _dbus_assert (strcmp (dbus_message_get_path (message),
1319  "/foo") == 0);
1320 
1321  if (!dbus_message_set_interface (message, "org.Foo"))
1322  _dbus_assert_not_reached ("out of memory");
1323  _dbus_assert (strcmp (dbus_message_get_interface (message),
1324  "org.Foo") == 0);
1325 
1326  if (!dbus_message_set_member (message, "Bar"))
1327  _dbus_assert_not_reached ("out of memory");
1328  _dbus_assert (strcmp (dbus_message_get_member (message),
1329  "Bar") == 0);
1330 
1331  /* Path decomposing */
1332  dbus_message_set_path (message, NULL);
1333  dbus_message_get_path_decomposed (message, &decomposed);
1334  _dbus_assert (decomposed == NULL);
1335  dbus_free_string_array (decomposed);
1336 
1337  dbus_message_set_path (message, "/");
1338  dbus_message_get_path_decomposed (message, &decomposed);
1339  _dbus_assert (decomposed != NULL);
1340  _dbus_assert (decomposed[0] == NULL);
1341  dbus_free_string_array (decomposed);
1342 
1343  dbus_message_set_path (message, "/a/b");
1344  dbus_message_get_path_decomposed (message, &decomposed);
1345  _dbus_assert (decomposed != NULL);
1346  _dbus_assert (strcmp (decomposed[0], "a") == 0);
1347  _dbus_assert (strcmp (decomposed[1], "b") == 0);
1348  _dbus_assert (decomposed[2] == NULL);
1349  dbus_free_string_array (decomposed);
1350 
1351  dbus_message_set_path (message, "/spam/eggs");
1352  dbus_message_get_path_decomposed (message, &decomposed);
1353  _dbus_assert (decomposed != NULL);
1354  _dbus_assert (strcmp (decomposed[0], "spam") == 0);
1355  _dbus_assert (strcmp (decomposed[1], "eggs") == 0);
1356  _dbus_assert (decomposed[2] == NULL);
1357  dbus_free_string_array (decomposed);
1358 
1359  dbus_message_unref (message);
1360 
1361  /* Test the vararg functions */
1362  message = dbus_message_new_method_call ("org.freedesktop.DBus.TestService",
1363  "/org/freedesktop/TestPath",
1364  "Foo.TestInterface",
1365  "TestMethod");
1366  dbus_message_set_serial (message, 1);
1367  dbus_message_set_reply_serial (message, 5678);
1368 
1369  v_INT16 = -0x123;
1370  v_UINT16 = 0x123;
1371  v_INT32 = -0x12345678;
1372  v_UINT32 = 0x12300042;
1373  v_INT64 = DBUS_INT64_CONSTANT (-0x123456789abcd);
1374  v_UINT64 = DBUS_UINT64_CONSTANT (0x123456789abcd);
1375  v_STRING = "Test string";
1376  v_DOUBLE = 3.14159;
1377  v_BOOLEAN = TRUE;
1378  v_BYTE = 42;
1379  v2_BYTE = 24;
1380 #ifdef HAVE_UNIX_FD_PASSING
1381  v_UNIX_FD = 1;
1382  v1_UNIX_FD = 2;
1383 #endif
1384 
1385  dbus_message_append_args (message,
1386  DBUS_TYPE_INT16, &v_INT16,
1387  DBUS_TYPE_UINT16, &v_UINT16,
1388  DBUS_TYPE_INT32, &v_INT32,
1389  DBUS_TYPE_UINT32, &v_UINT32,
1390  DBUS_TYPE_INT64, &v_INT64,
1391  DBUS_TYPE_UINT64, &v_UINT64,
1392  DBUS_TYPE_STRING, &v_STRING,
1393  DBUS_TYPE_DOUBLE, &v_DOUBLE,
1394  DBUS_TYPE_BOOLEAN, &v_BOOLEAN,
1395  DBUS_TYPE_BYTE, &v_BYTE,
1396  DBUS_TYPE_BYTE, &v2_BYTE,
1397  DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &v_ARRAY_UINT32,
1398  _DBUS_N_ELEMENTS (our_uint32_array),
1399  DBUS_TYPE_ARRAY, DBUS_TYPE_INT32, &v_ARRAY_INT32,
1400  _DBUS_N_ELEMENTS (our_int32_array),
1401  DBUS_TYPE_ARRAY, DBUS_TYPE_UINT64, &v_ARRAY_UINT64,
1402  _DBUS_N_ELEMENTS (our_uint64_array),
1403  DBUS_TYPE_ARRAY, DBUS_TYPE_INT64, &v_ARRAY_INT64,
1404  _DBUS_N_ELEMENTS (our_int64_array),
1405  DBUS_TYPE_ARRAY, DBUS_TYPE_DOUBLE, &v_ARRAY_DOUBLE,
1406  _DBUS_N_ELEMENTS (our_double_array),
1407  DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &v_ARRAY_BYTE,
1408  _DBUS_N_ELEMENTS (our_byte_array),
1409  DBUS_TYPE_ARRAY, DBUS_TYPE_BOOLEAN, &v_ARRAY_BOOLEAN,
1410  _DBUS_N_ELEMENTS (our_boolean_array),
1411  DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &v_ARRAY_STRING,
1412  _DBUS_N_ELEMENTS (our_string_array),
1413 
1415 
1416  i = 0;
1417  sig[i++] = DBUS_TYPE_INT16;
1418  sig[i++] = DBUS_TYPE_UINT16;
1419  sig[i++] = DBUS_TYPE_INT32;
1420  sig[i++] = DBUS_TYPE_UINT32;
1421  sig[i++] = DBUS_TYPE_INT64;
1422  sig[i++] = DBUS_TYPE_UINT64;
1423  sig[i++] = DBUS_TYPE_STRING;
1424  sig[i++] = DBUS_TYPE_DOUBLE;
1425  sig[i++] = DBUS_TYPE_BOOLEAN;
1426  sig[i++] = DBUS_TYPE_BYTE;
1427  sig[i++] = DBUS_TYPE_BYTE;
1428  sig[i++] = DBUS_TYPE_ARRAY;
1429  sig[i++] = DBUS_TYPE_UINT32;
1430  sig[i++] = DBUS_TYPE_ARRAY;
1431  sig[i++] = DBUS_TYPE_INT32;
1432  sig[i++] = DBUS_TYPE_ARRAY;
1433  sig[i++] = DBUS_TYPE_UINT64;
1434  sig[i++] = DBUS_TYPE_ARRAY;
1435  sig[i++] = DBUS_TYPE_INT64;
1436  sig[i++] = DBUS_TYPE_ARRAY;
1437  sig[i++] = DBUS_TYPE_DOUBLE;
1438  sig[i++] = DBUS_TYPE_ARRAY;
1439  sig[i++] = DBUS_TYPE_BYTE;
1440  sig[i++] = DBUS_TYPE_ARRAY;
1441  sig[i++] = DBUS_TYPE_BOOLEAN;
1442  sig[i++] = DBUS_TYPE_ARRAY;
1443  sig[i++] = DBUS_TYPE_STRING;
1444 
1445  message_without_unix_fds = dbus_message_copy(message);
1446  _dbus_assert(message_without_unix_fds);
1447 #ifdef HAVE_UNIX_FD_PASSING
1448  dbus_message_append_args (message,
1449  DBUS_TYPE_UNIX_FD, &v_UNIX_FD,
1451  sig[i++] = DBUS_TYPE_UNIX_FD;
1452 #endif
1453  sig[i++] = DBUS_TYPE_INVALID;
1454 
1455  _dbus_assert (i < (int) _DBUS_N_ELEMENTS (sig));
1456 
1457  _dbus_verbose ("HEADER\n");
1459  _dbus_string_get_length (&message->header.data));
1460  _dbus_verbose ("BODY\n");
1461  _dbus_verbose_bytes_of_string (&message->body, 0,
1462  _dbus_string_get_length (&message->body));
1463 
1464  _dbus_verbose ("Signature expected \"%s\" actual \"%s\"\n",
1465  sig, dbus_message_get_signature (message));
1466 
1467  s = dbus_message_get_signature (message);
1468 
1469  _dbus_assert (dbus_message_has_signature (message, sig));
1470  _dbus_assert (strcmp (s, sig) == 0);
1471 
1472  verify_test_message (message);
1473 
1474  copy = dbus_message_copy (message);
1475 
1478  _dbus_assert (message->header.padding == copy->header.padding);
1479 
1480  _dbus_assert (_dbus_string_get_length (&message->header.data) ==
1481  _dbus_string_get_length (&copy->header.data));
1482 
1483  _dbus_assert (_dbus_string_get_length (&message->body) ==
1484  _dbus_string_get_length (&copy->body));
1485 
1486  verify_test_message (copy);
1487 
1488  name1 = dbus_message_get_interface (message);
1489  name2 = dbus_message_get_interface (copy);
1490 
1491  _dbus_assert (strcmp (name1, name2) == 0);
1492 
1493  name1 = dbus_message_get_member (message);
1494  name2 = dbus_message_get_member (copy);
1495 
1496  _dbus_assert (strcmp (name1, name2) == 0);
1497 
1498  dbus_message_unref (copy);
1499 
1500  /* Message loader test */
1501  dbus_message_lock (message);
1502  loader = _dbus_message_loader_new ();
1503 
1504  /* check ref/unref */
1505  _dbus_message_loader_ref (loader);
1506  _dbus_message_loader_unref (loader);
1507 
1508  /* Write the header data one byte at a time */
1509  data = _dbus_string_get_const_data (&message->header.data);
1510  for (i = 0; i < _dbus_string_get_length (&message->header.data); i++)
1511  {
1512  DBusString *buffer;
1513 
1514  _dbus_message_loader_get_buffer (loader, &buffer, NULL, NULL);
1515  _dbus_string_append_byte (buffer, data[i]);
1516  _dbus_message_loader_return_buffer (loader, buffer);
1517  }
1518 
1519  /* Write the body data one byte at a time */
1520  data = _dbus_string_get_const_data (&message->body);
1521  for (i = 0; i < _dbus_string_get_length (&message->body); i++)
1522  {
1523  DBusString *buffer;
1524 
1525  _dbus_message_loader_get_buffer (loader, &buffer, NULL, NULL);
1526  _dbus_string_append_byte (buffer, data[i]);
1527  _dbus_message_loader_return_buffer (loader, buffer);
1528  }
1529 
1530 #ifdef HAVE_UNIX_FD_PASSING
1531  {
1532  int *unix_fds;
1533  unsigned n_unix_fds;
1534  /* Write unix fd */
1535  _dbus_message_loader_get_unix_fds(loader, &unix_fds, &n_unix_fds);
1536  _dbus_assert(n_unix_fds > 0);
1537  _dbus_assert(message->n_unix_fds == 1);
1538  unix_fds[0] = _dbus_dup(message->unix_fds[0], NULL);
1539  _dbus_assert(unix_fds[0] >= 0);
1540  _dbus_message_loader_return_unix_fds(loader, unix_fds, 1);
1541  }
1542 #endif
1543 
1544  dbus_message_unref (message);
1545 
1546  /* Now pop back the message */
1548  _dbus_assert_not_reached ("no memory to queue messages");
1549 
1551  _dbus_assert_not_reached ("message loader corrupted");
1552 
1553  message = _dbus_message_loader_pop_message (loader);
1554  if (!message)
1555  _dbus_assert_not_reached ("received a NULL message");
1556 
1557  if (dbus_message_get_reply_serial (message) != 5678)
1558  _dbus_assert_not_reached ("reply serial fields differ");
1559 
1560  dbus_message_unref (message);
1561 
1562  /* ovveride the serial, since it was reset by dbus_message_copy() */
1563  dbus_message_set_serial(message_without_unix_fds, 8901);
1564 
1565  dbus_message_lock (message_without_unix_fds);
1566 
1567  verify_test_message (message_without_unix_fds);
1568 
1569  {
1570  /* Marshal and demarshal the message. */
1571 
1572  DBusMessage *message2;
1573  DBusError error = DBUS_ERROR_INIT;
1574  char *marshalled = NULL;
1575  int len = 0;
1576  char garbage_header[DBUS_MINIMUM_HEADER_SIZE] = "xxx";
1577 
1578  if (!dbus_message_marshal (message_without_unix_fds, &marshalled, &len))
1579  _dbus_assert_not_reached ("failed to marshal message");
1580 
1581  _dbus_assert (len != 0);
1582  _dbus_assert (marshalled != NULL);
1583 
1584  _dbus_assert (dbus_message_demarshal_bytes_needed (marshalled, len) == len);
1585  message2 = dbus_message_demarshal (marshalled, len, &error);
1586 
1587  _dbus_assert (message2 != NULL);
1588  _dbus_assert (!dbus_error_is_set (&error));
1589  verify_test_message (message2);
1590 
1591  dbus_message_unref (message2);
1592  dbus_free (marshalled);
1593 
1594  /* Demarshal invalid message. */
1595 
1596  message2 = dbus_message_demarshal ("invalid", 7, &error);
1597  _dbus_assert (message2 == NULL);
1598  _dbus_assert (dbus_error_is_set (&error));
1599  dbus_error_free (&error);
1600 
1601  /* Demarshal invalid (empty) message. */
1602 
1603  message2 = dbus_message_demarshal ("", 0, &error);
1604  _dbus_assert (message2 == NULL);
1605  _dbus_assert (dbus_error_is_set (&error));
1606  dbus_error_free (&error);
1607 
1608  /* Bytes needed to demarshal empty message: 0 (more) */
1609 
1611 
1612  /* Bytes needed to demarshal invalid message: -1 (error). */
1613 
1615  }
1616 
1617  dbus_message_unref (message_without_unix_fds);
1618  _dbus_message_loader_unref (loader);
1619 
1620  check_memleaks ();
1621  _dbus_check_fdleaks_leave (initial_fds);
1622  initial_fds = _dbus_check_fdleaks_enter ();
1623 
1624  /* Test enumeration of array elements */
1625  for (i = strlen (basic_types) - 1; i > 0; i--)
1626  {
1627  DBusBasicValue val;
1628  int some;
1629  char* signature = _dbus_strdup ("?");
1630 
1631  signature[0] = basic_types[i];
1632  s = "SomeThingToSay";
1633  memset (&val, '\0', sizeof (val));
1634 
1635  message = dbus_message_new_method_call ("de.ende.test",
1636  "/de/ende/test", "de.ende.Test", "ArtistName");
1637  _dbus_assert (message != NULL);
1638  dbus_message_iter_init_append (message, &iter);
1640  signature, &array_iter);
1641  for (some = 0; some < 3; some++)
1642  {
1643  if (basic_types[i] == DBUS_TYPE_STRING)
1645  else
1646  dbus_message_iter_append_basic (&array_iter, basic_types[i], &val);
1647  }
1648  dbus_message_iter_close_container (&iter, &array_iter);
1649  dbus_message_iter_init (message, &iter);
1651  dbus_message_unref (message);
1652  dbus_free (signature);
1653  }
1654  /* Array of structs */
1655  message = dbus_message_new_method_call ("de.ende.test",
1656  "/de/ende/test", "de.ende.Test", "ArtistName");
1657  _dbus_assert (message != NULL);
1658  dbus_message_iter_init_append (message, &iter);
1662  DBUS_STRUCT_END_CHAR_AS_STRING, &array_iter);
1664  NULL, &struct_iter);
1665  s = "SpamAndEggs";
1667  dbus_message_iter_close_container (&array_iter, &struct_iter);
1668  dbus_message_iter_close_container (&iter, &array_iter);
1669  dbus_message_iter_init (message, &iter);
1671  dbus_message_unref (message);
1672  check_memleaks ();
1673 
1674  /* Check that we can abandon a container */
1675  message = dbus_message_new_method_call ("org.freedesktop.DBus.TestService",
1676  "/org/freedesktop/TestPath",
1677  "Foo.TestInterface",
1678  "Method");
1679 
1680  dbus_message_iter_init_append (message, &iter);
1681 
1687  &array_iter);
1688  _dbus_assert (ok);
1690  NULL, &struct_iter);
1691  _dbus_assert (ok);
1692  s = "peaches";
1693  ok = dbus_message_iter_append_basic (&struct_iter, DBUS_TYPE_STRING, &s);
1694  _dbus_assert (ok);
1695 
1696  /* uh-oh, error, try and unwind */
1697 
1698  dbus_message_iter_abandon_container (&array_iter, &struct_iter);
1699  dbus_message_iter_abandon_container (&array_iter, &iter);
1700 
1701  dbus_message_unref (message);
1702 
1703  /* Check we should not leak array of string or unix fd, fd.o#21259 */
1704  message = dbus_message_new_method_call ("org.freedesktop.DBus.TestService",
1705  "/org/freedesktop/TestPath",
1706  "Foo.TestInterface",
1707  "Method");
1708 
1709  /* signature "uashuash" */
1710  dbus_message_append_args (message,
1711  DBUS_TYPE_UINT32, &v_UINT32,
1712  DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &v_ARRAY_STRING,
1713  _DBUS_N_ELEMENTS (our_string_array),
1714 #ifdef HAVE_UNIX_FD_PASSING
1715  DBUS_TYPE_UNIX_FD, &v_UNIX_FD,
1716 #endif
1717  DBUS_TYPE_UINT32, &v1_UINT32,
1718  DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &v1_ARRAY_STRING,
1719  _DBUS_N_ELEMENTS (our_string_array1),
1720 #ifdef HAVE_UNIX_FD_PASSING
1721  DBUS_TYPE_UNIX_FD, &v1_UNIX_FD,
1722 #endif
1723 
1725 
1726  i = 0;
1727  sig[i++] = DBUS_TYPE_UINT32;
1728  sig[i++] = DBUS_TYPE_ARRAY;
1729  sig[i++] = DBUS_TYPE_STRING;
1730 #ifdef HAVE_UNIX_FD_PASSING
1731  sig[i++] = DBUS_TYPE_UNIX_FD;
1732 #endif
1733  sig[i++] = DBUS_TYPE_UINT32;
1734  sig[i++] = DBUS_TYPE_ARRAY;
1735  sig[i++] = DBUS_TYPE_STRING;
1736 #ifdef HAVE_UNIX_FD_PASSING
1737  sig[i++] = DBUS_TYPE_UNIX_FD;
1738 #endif
1739  sig[i++] = DBUS_TYPE_INVALID;
1740 
1741  _dbus_assert (i < (int) _DBUS_N_ELEMENTS (sig));
1742 
1743  verify_test_message_args_ignored (message);
1744  verify_test_message_memleak (message);
1745 
1746  dbus_message_unref (message);
1747 
1748  /* Load all the sample messages from the message factory */
1749  {
1750  DBusMessageDataIter diter;
1751  DBusMessageData mdata;
1752  int count;
1753 
1754  reset_validities_seen ();
1755 
1756  count = 0;
1757  _dbus_message_data_iter_init (&diter);
1758 
1759  while (_dbus_message_data_iter_get_and_next (&diter,
1760  &mdata))
1761  {
1762  if (!dbus_internal_do_not_use_try_message_data (&mdata.data,
1763  mdata.expected_validity))
1764  {
1765  _dbus_warn ("expected validity %d and did not get it",
1766  mdata.expected_validity);
1767  _dbus_assert_not_reached ("message data failed");
1768  }
1769 
1770  _dbus_message_data_free (&mdata);
1771 
1772  count += 1;
1773  }
1774 
1775  printf ("%d sample messages tested\n", count);
1776 
1777  print_validities_seen (FALSE);
1778  print_validities_seen (TRUE);
1779  }
1780 
1781  check_memleaks ();
1782  _dbus_check_fdleaks_leave (initial_fds);
1783 
1784  /* Now load every message in test_data_dir if we have one */
1785  if (test_data_dir == NULL)
1786  return TRUE;
1787 
1788  initial_fds = _dbus_check_fdleaks_enter ();
1789 
1790  if (!dbus_internal_do_not_use_foreach_message_file (test_data_dir,
1791  (DBusForeachMessageFileFunc)
1792  dbus_internal_do_not_use_try_message_file,
1793  NULL))
1794  _dbus_assert_not_reached ("foreach_message_file test failed");
1795 
1796  _dbus_check_fdleaks_leave (initial_fds);
1797 
1798  return TRUE;
1799 }
1800 
1801 #endif /* DBUS_ENABLE_EMBEDDED_TESTS */
#define DBUS_TYPE_UINT16
Type code marking a 16-bit unsigned integer.
Definition: dbus-protocol.h:78
void dbus_message_lock(DBusMessage *message)
Locks a message.
Definition: dbus-message.c:407
const char * message
public error message field
Definition: dbus-errors.h:51
#define NULL
A null pointer, defined appropriately for C or C++.
dbus_bool_t dbus_message_is_method_call(DBusMessage *message, const char *iface, const char *method)
Checks whether the message is a method call with the given interface and member fields.
void dbus_message_set_no_reply(DBusMessage *message, dbus_bool_t no_reply)
Sets a flag indicating that the message does not want a reply; if this flag is set, the other end of the connection may (but is not required to) optimize by not sending method return or error replies.
int dbus_message_iter_get_arg_type(DBusMessageIter *iter)
Returns the argument type of the argument that the message iterator points to.
DBUS_PRIVATE_EXPORT void _dbus_message_loader_return_buffer(DBusMessageLoader *loader, DBusString *buffer)
Returns a buffer obtained from _dbus_message_loader_get_buffer(), indicating to the loader how many b...
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
Definition: dbus-memory.c:702
dbus_uint32_t dbus_message_get_serial(DBusMessage *message)
Returns the serial of a message or 0 if none has been specified.
#define DBUS_STRUCT_BEGIN_CHAR_AS_STRING
DBUS_STRUCT_BEGIN_CHAR as a string literal instead of a int literal
void dbus_message_iter_recurse(DBusMessageIter *iter, DBusMessageIter *sub)
Recurses into a container value when reading values from a message, initializing a sub-iterator to us...
DBUS_PRIVATE_EXPORT DBusMessage * _dbus_message_loader_pop_message(DBusMessageLoader *loader)
Pops a loaded message (passing ownership of the message to the caller).
dbus_bool_t dbus_message_set_interface(DBusMessage *message, const char *iface)
Sets the interface this message is being sent to (for DBUS_MESSAGE_TYPE_METHOD_CALL) or the interface...
dbus_bool_t dbus_message_iter_close_container(DBusMessageIter *iter, DBusMessageIter *sub)
Closes a container-typed value appended to the message; may write out more information to the message...
#define DBUS_TYPE_STRUCT
STRUCT and DICT_ENTRY are sort of special since their codes can&#39;t appear in a type string...
void _dbus_directory_close(DBusDirIter *iter)
Closes a directory iteration.
dbus_uint32_t padding
bytes of alignment in header
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_message_iter_get_args_valist(DBusMessageIter *iter, DBusError *error, int first_arg_type, va_list var_args)
Implementation of the varargs arg-getting functions.
Definition: dbus-message.c:819
#define DBUS_TYPE_STRING
Type code marking a UTF-8 encoded, nul-terminated Unicode string.
DBusString body
Body network data.
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
dbus_bool_t _dbus_directory_get_next_file(DBusDirIter *iter, DBusString *filename, DBusError *error)
Get next file in the directory.
#define DBUS_ERROR_INIT
Expands to a suitable initializer for a DBusError on the stack.
Definition: dbus-errors.h:62
const char * dbus_message_get_signature(DBusMessage *message)
Gets the type signature of the message, i.e.
void dbus_message_iter_init_append(DBusMessage *message, DBusMessageIter *iter)
Initializes a DBusMessageIter for appending arguments to the end of a message.
void dbus_error_free(DBusError *error)
Frees an error that&#39;s been set (or just initialized), then reinitializes the error as in dbus_error_i...
Definition: dbus-errors.c:211
#define DBUS_TYPE_BYTE
Type code marking an 8-bit unsigned integer.
Definition: dbus-protocol.h:66
dbus_bool_t _dbus_file_get_contents(DBusString *str, const DBusString *filename, DBusError *error)
Appends the contents of the given file to the string, returning error code.
DBUS_PRIVATE_EXPORT void _dbus_message_loader_unref(DBusMessageLoader *loader)
Decrements the reference count of the loader and finalizes the loader when the count reaches zero...
DBusString data
Header network data, stored separately from body so we can independently realloc it.
dbus_bool_t _dbus_concat_dir_and_file(DBusString *dir, const DBusString *next_component)
Appends the given filename to the given directory.
const char * dbus_message_get_path(DBusMessage *message)
Gets the object path this message is being sent to (for DBUS_MESSAGE_TYPE_METHOD_CALL) or being emitt...
DBusDirIter * _dbus_directory_open(const DBusString *filename, DBusError *error)
Open a directory to iterate over.
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
Definition: dbus-string.c:175
int _dbus_dup(int fd, DBusError *error)
Duplicates a file descriptor.
dbus_bool_t _dbus_string_copy(const DBusString *source, int start, DBusString *dest, int insert_at)
Like _dbus_string_move(), but does not delete the section of the source string that&#39;s copied to the d...
Definition: dbus-string.c:1283
DBusValidity
This is primarily used in unit testing, so we can verify that each invalid message is invalid for the...
DBusMessageIter struct; contains no public fields.
Definition: dbus-message.h:51
#define DBUS_TYPE_DOUBLE
Type code marking an 8-byte double in IEEE 754 format.
Definition: dbus-protocol.h:98
dbus_bool_t dbus_message_iter_init(DBusMessage *message, DBusMessageIter *iter)
Initializes a DBusMessageIter for reading the arguments of the message passed in. ...
dbus_bool_t _dbus_string_ends_with_c_str(const DBusString *a, const char *c_str)
Returns whether a string ends with the given suffix.
#define DBUS_TYPE_ARRAY
Type code marking a D-Bus array type.
#define DBUS_TYPE_INT64
Type code marking a 64-bit signed integer.
Definition: dbus-protocol.h:90
Internals of directory iterator.
const char * dbus_message_get_member(DBusMessage *message)
Gets the interface member being invoked (DBUS_MESSAGE_TYPE_METHOD_CALL) or emitted (DBUS_MESSAGE_TYPE...
Internals of DBusMessage.
#define DBUS_MINIMUM_HEADER_SIZE
The smallest header size that can occur.
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
Definition: dbus-types.h:35
void _dbus_string_init_const(DBusString *str, const char *value)
Initializes a constant string.
Definition: dbus-string.c:190
DBusHeader header
Header network data and associated cache.
dbus_bool_t dbus_message_set_sender(DBusMessage *message, const char *sender)
Sets the message sender.
DBusString data
Buffered data.
DBUS_PRIVATE_EXPORT DBusMessageLoader * _dbus_message_loader_ref(DBusMessageLoader *loader)
Increments the reference count of the loader.
dbus_bool_t dbus_message_get_path_decomposed(DBusMessage *message, char ***path)
Gets the object path this message is being sent to (for DBUS_MESSAGE_TYPE_METHOD_CALL) or being emitt...
void _dbus_warn(const char *format,...)
Prints a warning message to stderr.
dbus_bool_t dbus_message_set_path(DBusMessage *message, const char *object_path)
Sets the object path this message is being sent to (for DBUS_MESSAGE_TYPE_METHOD_CALL) or the one a s...
#define DBUS_TYPE_INT32
Type code marking a 32-bit signed integer.
Definition: dbus-protocol.h:82
DBUS_PRIVATE_EXPORT DBusMessageLoader * _dbus_message_loader_new(void)
Creates a new message loader.
Object representing an exception.
Definition: dbus-errors.h:48
int dbus_message_iter_get_element_count(DBusMessageIter *iter)
Returns the number of elements in the array-typed value pointed to by the iterator.
dbus_bool_t dbus_message_append_args(DBusMessage *message, int first_arg_type,...)
Appends fields to a message given a variable argument list.
#define DBUS_TYPE_UINT64
Type code marking a 64-bit unsigned integer.
Definition: dbus-protocol.h:94
dbus_uint32_t dbus_message_get_reply_serial(DBusMessage *message)
Returns the serial that the message is a reply to or 0 if none.
dbus_bool_t dbus_message_has_signature(DBusMessage *message, const char *signature)
Checks whether the message has the given signature; see dbus_message_get_signature() for more details...
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_message_loader_get_is_corrupted(DBusMessageLoader *loader)
Checks whether the loader is confused due to bad data.
#define _DBUS_N_ELEMENTS(array)
Computes the number of elements in a fixed-size array using sizeof().
#define DBUS_TYPE_UINT32
Type code marking a 32-bit unsigned integer.
Definition: dbus-protocol.h:86
the data is valid
DBusMessage * dbus_message_new_method_call(const char *destination, const char *path, const char *iface, const char *method)
Constructs a new message to invoke a method on a remote object.
dbus_bool_t dbus_message_has_destination(DBusMessage *message, const char *name)
Checks whether the message was sent to the given name.
dbus_bool_t _dbus_string_append_byte(DBusString *str, unsigned char byte)
Appends a single byte to the string, returning FALSE if not enough memory.
Definition: dbus-string.c:1157
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init().
Definition: dbus-string.c:259
#define TRUE
Expands to "1".
dbus_bool_t dbus_message_marshal(DBusMessage *msg, char **marshalled_data_p, int *len_p)
Turn a DBusMessage into the marshalled form as described in the D-Bus specification.
#define _dbus_assert_not_reached(explanation)
Aborts with an error message if called.
DBusMessage * dbus_message_copy(const DBusMessage *message)
Creates a new message that is an exact replica of the message specified, except that its refcount is ...
int dbus_message_iter_get_element_type(DBusMessageIter *iter)
Returns the element type of the array that the message iterator points to.
const char * name
public error name field
Definition: dbus-errors.h:50
DBusMessage * dbus_message_demarshal(const char *str, int len, DBusError *error)
Demarshal a D-Bus message from the format described in the D-Bus specification.
#define DBUS_TYPE_UNIX_FD
Type code marking a unix file descriptor.
const char * dbus_message_get_interface(DBusMessage *message)
Gets the interface this message is being sent to (for DBUS_MESSAGE_TYPE_METHOD_CALL) or being emitted...
#define DBUS_TYPE_INVALID
Type code that is never equal to a legitimate type code.
Definition: dbus-protocol.h:60
dbus_bool_t dbus_message_set_reply_serial(DBusMessage *message, dbus_uint32_t reply_serial)
Sets the reply serial of a message (the serial of the message this is a reply to).
dbus_bool_t dbus_message_has_sender(DBusMessage *message, const char *name)
Checks whether the message has the given unique name as its sender.
dbus_bool_t dbus_message_iter_next(DBusMessageIter *iter)
Moves the iterator to the next field, if any.
dbus_bool_t dbus_message_get_no_reply(DBusMessage *message)
Returns TRUE if the message does not expect a reply.
#define DBUS_TYPE_INT16
Type code marking a 16-bit signed integer.
Definition: dbus-protocol.h:74
void dbus_free_string_array(char **str_array)
Frees a NULL-terminated array of strings.
Definition: dbus-memory.c:750
#define DBUS_TYPE_BOOLEAN
Type code marking a boolean.
Definition: dbus-protocol.h:70
#define DBUS_STRUCT_END_CHAR_AS_STRING
DBUS_STRUCT_END_CHAR a string literal instead of a int literal
dbus_bool_t dbus_message_iter_open_container(DBusMessageIter *iter, int type, const char *contained_signature, DBusMessageIter *sub)
Appends a container-typed value to the message; you are required to append the contents of the contai...
A simple value union that lets you access bytes as if they were various types; useful when dealing wi...
Definition: dbus-types.h:137
#define DBUS_TYPE_STRING_AS_STRING
DBUS_TYPE_STRING as a string literal instead of a int literal
dbus_bool_t dbus_message_iter_append_basic(DBusMessageIter *iter, int type, const void *value)
Appends a basic-typed value to the message.
dbus_bool_t _dbus_close(int fd, DBusError *error)
Closes a file descriptor.
void dbus_shutdown(void)
Frees all memory allocated internally by libdbus and reverses the effects of dbus_threads_init().
Definition: dbus-memory.c:898
#define FALSE
Expands to "0".
DBUS_PRIVATE_EXPORT void _dbus_message_loader_get_buffer(DBusMessageLoader *loader, DBusString **buffer, int *max_to_read, dbus_bool_t *may_read_unix_fds)
Gets the buffer to use for reading data from the network.
int dbus_message_demarshal_bytes_needed(const char *buf, int len)
Returns the number of bytes required to be in the buffer to demarshal a D-Bus message.
void dbus_message_iter_abandon_container(DBusMessageIter *iter, DBusMessageIter *sub)
Abandons creation of a contained-typed value and frees resources created by dbus_message_iter_open_co...
DBUS_PRIVATE_EXPORT void _dbus_verbose_bytes_of_string(const DBusString *str, int start, int len)
Dump the given part of the string to verbose log.
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_message_loader_queue_messages(DBusMessageLoader *loader)
Converts buffered data into messages, if we have enough data.
char * _dbus_strdup(const char *str)
Duplicates a string.
DBusValidity corruption_reason
why we were corrupted
dbus_bool_t dbus_message_set_member(DBusMessage *message, const char *member)
Sets the interface member being invoked (DBUS_MESSAGE_TYPE_METHOD_CALL) or emitted (DBUS_MESSAGE_TYPE...
void dbus_message_unref(DBusMessage *message)
Decrements the reference count of a DBusMessage, freeing the message if the count reaches 0...
Implementation details of DBusMessageLoader.
dbus_bool_t dbus_error_is_set(const DBusError *error)
Checks whether an error occurred (the error is set).
Definition: dbus-errors.c:329
#define _DBUS_DOUBLES_BITWISE_EQUAL(a, b)
On x86 there is an 80-bit FPU, and if you do "a == b" it may have a or b in an 80-bit register...
Definition: dbus-sysdeps.h:601
void dbus_message_set_serial(DBusMessage *message, dbus_uint32_t serial)
Sets the serial number of a message.
Definition: dbus-message.c:277