D-Bus  1.13.7
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 #include <dbus/dbus-test-tap.h>
35 
36 #ifdef __linux__
37 /* Necessary for the Linux-specific fd leak checking code only */
38 #include <sys/types.h>
39 #include <dirent.h>
40 #include <stdlib.h>
41 #include <errno.h>
42 #endif
43 
55 unsigned int
57 {
58 #ifdef HAVE_UNIX_FD_PASSING
59  return message->n_unix_fds;
60 #else
61  return 0;
62 #endif
63 }
64 
65 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
66 
78 static dbus_bool_t
79 dbus_message_iter_get_args (DBusMessageIter *iter,
80  DBusError *error,
81  int first_arg_type,
82  ...)
83 {
84  dbus_bool_t retval;
85  va_list var_args;
86 
87  _dbus_return_val_if_fail (iter != NULL, FALSE);
88  _dbus_return_val_if_error_is_set (error, FALSE);
89 
90  va_start (var_args, first_arg_type);
91  retval = _dbus_message_iter_get_args_valist (iter, error, first_arg_type, var_args);
92  va_end (var_args);
93 
94  return retval;
95 }
96 #endif /* DBUS_ENABLE_EMBEDDED_TESTS */
97 
100 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
101 #include "dbus-test.h"
102 #include "dbus-message-factory.h"
103 #include <stdio.h>
104 #include <stdlib.h>
105 
106 /* returns FALSE on fatal failure */
107 typedef dbus_bool_t (* DBusForeachMessageFileFunc) (const DBusString *filename,
108  DBusValidity expected_validity,
109  void *data);
110 
111 static dbus_bool_t try_message_data (const DBusString *data,
112  DBusValidity expected_validity);
113 
114 static int validities_seen[DBUS_VALIDITY_LAST + _DBUS_NEGATIVE_VALIDITY_COUNT];
115 
116 static void
117 reset_validities_seen (void)
118 {
119  int i;
120  i = 0;
121  while (i < _DBUS_N_ELEMENTS (validities_seen))
122  {
123  validities_seen[i] = 0;
124  ++i;
125  }
126 }
127 
128 static void
129 record_validity_seen (DBusValidity validity)
130 {
131  validities_seen[validity + _DBUS_NEGATIVE_VALIDITY_COUNT] += 1;
132 }
133 
134 static void
135 print_validities_seen (dbus_bool_t not_seen)
136 {
137  int i;
138  i = 0;
139  while (i < _DBUS_N_ELEMENTS (validities_seen))
140  {
141  if ((i - _DBUS_NEGATIVE_VALIDITY_COUNT) == DBUS_VALIDITY_UNKNOWN ||
142  (i - _DBUS_NEGATIVE_VALIDITY_COUNT) == DBUS_INVALID_FOR_UNKNOWN_REASON)
143  ;
144  else if ((not_seen && validities_seen[i] == 0) ||
145  (!not_seen && validities_seen[i] > 0))
146  _dbus_test_diag ("validity %3d seen %d times",
147  i - _DBUS_NEGATIVE_VALIDITY_COUNT,
148  validities_seen[i]);
149  ++i;
150  }
151 }
152 
153 static void
154 check_memleaks (void)
155 {
156  dbus_shutdown ();
157 
158  if (_dbus_get_malloc_blocks_outstanding () != 0)
159  {
160  _dbus_test_fatal ("%d dbus_malloc blocks were not freed in %s",
161  _dbus_get_malloc_blocks_outstanding (), __FILE__);
162  }
163 }
164 
165 #ifdef __linux__
166 struct DBusInitialFDs {
167  fd_set set;
168 };
169 #endif
170 
171 DBusInitialFDs *
172 _dbus_check_fdleaks_enter (void)
173 {
174 #ifdef __linux__
175  DIR *d;
176  DBusInitialFDs *fds;
177 
178  /* this is plain malloc so it won't interfere with leak checking */
179  fds = malloc (sizeof (DBusInitialFDs));
180  _dbus_assert (fds != NULL);
181 
182  /* This works on Linux only */
183 
184  if ((d = opendir ("/proc/self/fd")))
185  {
186  struct dirent *de;
187 
188  while ((de = readdir(d)))
189  {
190  long l;
191  char *e = NULL;
192  int fd;
193 
194  if (de->d_name[0] == '.')
195  continue;
196 
197  errno = 0;
198  l = strtol (de->d_name, &e, 10);
199  _dbus_assert (errno == 0 && e && !*e);
200 
201  fd = (int) l;
202 
203  if (fd < 3)
204  continue;
205 
206  if (fd == dirfd (d))
207  continue;
208 
209  if (fd >= FD_SETSIZE)
210  {
211  _dbus_verbose ("FD %d unexpectedly large; cannot track whether "
212  "it is leaked\n", fd);
213  continue;
214  }
215 
216  FD_SET (fd, &fds->set);
217  }
218 
219  closedir (d);
220  }
221 
222  return fds;
223 #else
224  return NULL;
225 #endif
226 }
227 
228 void
229 _dbus_check_fdleaks_leave (DBusInitialFDs *fds)
230 {
231 #ifdef __linux__
232  DIR *d;
233 
234  /* This works on Linux only */
235 
236  if ((d = opendir ("/proc/self/fd")))
237  {
238  struct dirent *de;
239 
240  while ((de = readdir(d)))
241  {
242  long l;
243  char *e = NULL;
244  int fd;
245 
246  if (de->d_name[0] == '.')
247  continue;
248 
249  errno = 0;
250  l = strtol (de->d_name, &e, 10);
251  _dbus_assert (errno == 0 && e && !*e);
252 
253  fd = (int) l;
254 
255  if (fd < 3)
256  continue;
257 
258  if (fd == dirfd (d))
259  continue;
260 
261  if (fd >= FD_SETSIZE)
262  {
263  _dbus_verbose ("FD %d unexpectedly large; cannot track whether "
264  "it is leaked\n", fd);
265  continue;
266  }
267 
268  if (FD_ISSET (fd, &fds->set))
269  continue;
270 
271  _dbus_test_fatal ("file descriptor %i leaked in %s.", fd, __FILE__);
272  }
273 
274  closedir (d);
275  }
276 
277  free (fds);
278 #else
279  _dbus_assert (fds == NULL);
280 #endif
281 }
282 
283 static dbus_bool_t
284 check_have_valid_message (DBusMessageLoader *loader)
285 {
286  DBusMessage *message;
287  dbus_bool_t retval;
288 
289  message = NULL;
290  retval = FALSE;
291 
293  {
294  _dbus_warn ("loader corrupted on message that was expected to be valid; invalid reason %d",
295  loader->corruption_reason);
296  goto failed;
297  }
298 
299  message = _dbus_message_loader_pop_message (loader);
300  if (message == NULL)
301  {
302  _dbus_warn ("didn't load message that was expected to be valid (message not popped)");
303  goto failed;
304  }
305 
306  if (_dbus_string_get_length (&loader->data) > 0)
307  {
308  _dbus_warn ("had leftover bytes from expected-to-be-valid single message");
309  goto failed;
310  }
311 
312 #if 0
313  /* FIXME */
314  /* Verify that we're able to properly deal with the message.
315  * For example, this would detect improper handling of messages
316  * in nonstandard byte order.
317  */
318  if (!check_message_handling (message))
319  goto failed;
320 #endif
321 
322  record_validity_seen (DBUS_VALID);
323 
324  retval = TRUE;
325 
326  failed:
327  if (message)
328  dbus_message_unref (message);
329 
330  return retval;
331 }
332 
333 static dbus_bool_t
334 check_invalid_message (DBusMessageLoader *loader,
335  DBusValidity expected_validity)
336 {
337  dbus_bool_t retval;
338 
339  retval = FALSE;
340 
342  {
343  _dbus_warn ("loader not corrupted on message that was expected to be invalid");
344  goto failed;
345  }
346 
347  record_validity_seen (loader->corruption_reason);
348 
349  if (expected_validity != DBUS_INVALID_FOR_UNKNOWN_REASON &&
350  loader->corruption_reason != expected_validity)
351  {
352  _dbus_warn ("expected message to be corrupted for reason %d and was corrupted for %d instead",
353  expected_validity, loader->corruption_reason);
354  goto failed;
355  }
356 
357  retval = TRUE;
358 
359  failed:
360  return retval;
361 }
362 
363 static dbus_bool_t
364 check_incomplete_message (DBusMessageLoader *loader)
365 {
366  DBusMessage *message;
367  dbus_bool_t retval;
368 
369  message = NULL;
370  retval = FALSE;
371 
373  {
374  _dbus_warn ("loader corrupted on message that was expected to be valid (but incomplete), corruption reason %d",
375  loader->corruption_reason);
376  goto failed;
377  }
378 
379  message = _dbus_message_loader_pop_message (loader);
380  if (message != NULL)
381  {
382  _dbus_warn ("loaded message that was expected to be incomplete");
383  goto failed;
384  }
385 
386  record_validity_seen (DBUS_VALID_BUT_INCOMPLETE);
387  retval = TRUE;
388 
389  failed:
390  if (message)
391  dbus_message_unref (message);
392  return retval;
393 }
394 
395 static dbus_bool_t
396 check_loader_results (DBusMessageLoader *loader,
397  DBusValidity expected_validity)
398 {
400  _dbus_test_fatal ("no memory to queue messages");
401 
402  if (expected_validity == DBUS_VALID)
403  return check_have_valid_message (loader);
404  else if (expected_validity == DBUS_VALID_BUT_INCOMPLETE)
405  return check_incomplete_message (loader);
406  else if (expected_validity == DBUS_VALIDITY_UNKNOWN)
407  {
408  /* here we just know we didn't segfault and that was the
409  * only test. Also, we record that we got coverage
410  * for the validity reason.
411  */
413  record_validity_seen (loader->corruption_reason);
414 
415  return TRUE;
416  }
417  else
418  return check_invalid_message (loader, expected_validity);
419 }
420 
428 static dbus_bool_t
429 load_message_file (const DBusString *filename,
430  DBusString *data)
431 {
432  dbus_bool_t retval;
433  DBusError error = DBUS_ERROR_INIT;
434 
435  retval = FALSE;
436 
437  _dbus_verbose ("Loading raw %s\n", _dbus_string_get_const_data (filename));
438  if (!_dbus_file_get_contents (data, filename, &error))
439  {
440  _dbus_warn ("Could not load message file %s: %s",
441  _dbus_string_get_const_data (filename),
442  error.message);
443  dbus_error_free (&error);
444  goto failed;
445  }
446 
447  retval = TRUE;
448 
449  failed:
450 
451  return retval;
452 }
453 
463 static dbus_bool_t
464 try_message_file (const DBusString *filename,
465  DBusValidity expected_validity,
466  void *unused)
467 {
468  DBusString data;
469  dbus_bool_t retval;
470 
471  retval = FALSE;
472 
473  if (!_dbus_string_init (&data))
474  _dbus_test_fatal ("could not allocate string");
475 
476  if (!load_message_file (filename, &data))
477  goto failed;
478 
479  retval = try_message_data (&data, expected_validity);
480 
481  failed:
482 
483  if (!retval)
484  {
485  if (_dbus_string_get_length (&data) > 0)
487  _dbus_string_get_length (&data));
488 
489  _dbus_warn ("Failed message loader test on %s",
490  _dbus_string_get_const_data (filename));
491  }
492 
493  _dbus_string_free (&data);
494 
495  return retval;
496 }
497 
506 static dbus_bool_t
507 try_message_data (const DBusString *data,
508  DBusValidity expected_validity)
509 {
510  DBusMessageLoader *loader;
511  dbus_bool_t retval;
512  int len;
513  int i;
514 
515  loader = NULL;
516  retval = FALSE;
517 
518  /* Write the data one byte at a time */
519 
520  loader = _dbus_message_loader_new ();
521  if (loader == NULL)
522  goto failed;
523 
524  /* check some trivial loader functions */
525  _dbus_message_loader_ref (loader);
527 
528  len = _dbus_string_get_length (data);
529  for (i = 0; i < len; i++)
530  {
531  DBusString *buffer;
532 
533  _dbus_message_loader_get_buffer (loader, &buffer, NULL, NULL);
534  if (!_dbus_string_append_byte (buffer,
535  _dbus_string_get_byte (data, i)))
536  goto failed;
537  _dbus_message_loader_return_buffer (loader, buffer);
538  }
539 
540  if (!check_loader_results (loader, expected_validity))
541  goto failed;
542 
544  loader = NULL;
545 
546  /* Write the data all at once */
547 
548  loader = _dbus_message_loader_new ();
549  if (loader == NULL)
550  goto failed;
551 
552  {
553  DBusString *buffer;
554 
555  _dbus_message_loader_get_buffer (loader, &buffer, NULL, NULL);
556  if (!_dbus_string_copy (data, 0, buffer,
557  _dbus_string_get_length (buffer)))
558  goto failed;
559  _dbus_message_loader_return_buffer (loader, buffer);
560  }
561 
562  if (!check_loader_results (loader, expected_validity))
563  goto failed;
564 
566  loader = NULL;
567 
568  /* Write the data 2 bytes at a time */
569 
570  loader = _dbus_message_loader_new ();
571  if (loader == NULL)
572  goto failed;
573 
574  len = _dbus_string_get_length (data);
575  for (i = 0; i < len; i += 2)
576  {
577  DBusString *buffer;
578 
579  _dbus_message_loader_get_buffer (loader, &buffer, NULL, NULL);
580  if (!_dbus_string_append_byte (buffer,
581  _dbus_string_get_byte (data, i)))
582  goto failed;
583 
584  if ((i+1) < len)
585  {
586  if (!_dbus_string_append_byte (buffer,
587  _dbus_string_get_byte (data, i+1)))
588  goto failed;
589  }
590 
591  _dbus_message_loader_return_buffer (loader, buffer);
592  }
593 
594  if (!check_loader_results (loader, expected_validity))
595  goto failed;
596 
598  loader = NULL;
599 
600  retval = TRUE;
601 
602  failed:
603 
604  if (loader)
606 
607  return retval;
608 }
609 
610 static dbus_bool_t
611 process_test_subdir (const DBusString *test_base_dir,
612  const char *subdir,
613  DBusValidity expected_validity,
614  DBusForeachMessageFileFunc function,
615  void *user_data)
616 {
617  DBusString test_directory;
618  DBusString filename;
619  DBusDirIter *dir;
620  dbus_bool_t retval;
621  DBusError error = DBUS_ERROR_INIT;
622 
623  retval = FALSE;
624  dir = NULL;
625 
626  if (!_dbus_string_init (&test_directory))
627  _dbus_test_fatal ("didn't allocate test_directory");
628 
629  _dbus_string_init_const (&filename, subdir);
630 
631  if (!_dbus_string_copy (test_base_dir, 0,
632  &test_directory, 0))
633  _dbus_test_fatal ("couldn't copy test_base_dir to test_directory");
634 
635  if (!_dbus_concat_dir_and_file (&test_directory, &filename))
636  _dbus_test_fatal ("couldn't allocate full path");
637 
638  _dbus_string_free (&filename);
639  if (!_dbus_string_init (&filename))
640  _dbus_test_fatal ("didn't allocate filename string");
641 
642  dir = _dbus_directory_open (&test_directory, &error);
643  if (dir == NULL)
644  {
645  _dbus_warn ("Could not open %s: %s",
646  _dbus_string_get_const_data (&test_directory),
647  error.message);
648  dbus_error_free (&error);
649  goto failed;
650  }
651 
652  _dbus_test_diag ("Testing %s:", subdir);
653 
654  next:
655  while (_dbus_directory_get_next_file (dir, &filename, &error))
656  {
657  DBusString full_path;
658 
659  if (!_dbus_string_init (&full_path))
660  _dbus_test_fatal ("couldn't init string");
661 
662  if (!_dbus_string_copy (&test_directory, 0, &full_path, 0))
663  _dbus_test_fatal ("couldn't copy dir to full_path");
664 
665  if (!_dbus_concat_dir_and_file (&full_path, &filename))
666  _dbus_test_fatal ("couldn't concat file to dir");
667 
668  if (_dbus_string_ends_with_c_str (&filename, ".message-raw"))
669  ;
670  else
671  {
672  _dbus_verbose ("Skipping non-.message-raw file %s\n",
673  _dbus_string_get_const_data (&filename));
674  _dbus_string_free (&full_path);
675  goto next;
676  }
677 
678  _dbus_test_diag (" %s",
679  _dbus_string_get_const_data (&filename));
680 
681  if (! (*function) (&full_path,
682  expected_validity, user_data))
683  {
684  _dbus_string_free (&full_path);
685  goto failed;
686  }
687  else
688  _dbus_string_free (&full_path);
689  }
690 
691  if (dbus_error_is_set (&error))
692  {
693  _dbus_warn ("Could not get next file in %s: %s",
694  _dbus_string_get_const_data (&test_directory),
695  error.message);
696  dbus_error_free (&error);
697  goto failed;
698  }
699 
700  retval = TRUE;
701 
702  failed:
703 
704  if (dir)
705  _dbus_directory_close (dir);
706  _dbus_string_free (&test_directory);
707  _dbus_string_free (&filename);
708 
709  return retval;
710 }
711 
721 static dbus_bool_t
722 foreach_message_file (const char *test_data_dir,
723  DBusForeachMessageFileFunc func,
724  void *user_data)
725 {
726  DBusString test_directory;
727  dbus_bool_t retval;
728 
729  retval = FALSE;
730 
731  _dbus_string_init_const (&test_directory, test_data_dir);
732 
733  if (!process_test_subdir (&test_directory, "invalid-messages",
734  DBUS_INVALID_FOR_UNKNOWN_REASON, func, user_data))
735  goto failed;
736 
737  check_memleaks ();
738 
739  retval = TRUE;
740 
741  failed:
742 
743  _dbus_string_free (&test_directory);
744 
745  return retval;
746 }
747 
748 #if 0
749 #define GET_AND_CHECK(iter, typename, literal) \
750  do { \
751  if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_##typename) \
752  _dbus_test_fatal ("got wrong argument type from message iter"); \
753  dbus_message_iter_get_basic (&iter, &v_##typename); \
754  if (v_##typename != literal) \
755  _dbus_test_fatal ("got wrong value from message iter"); \
756  } while (0)
757 
758 #define GET_AND_CHECK_STRCMP(iter, typename, literal) \
759  do { \
760  if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_##typename) \
761  _dbus_test_fatal ("got wrong argument type from message iter"); \
762  dbus_message_iter_get_basic (&iter, &v_##typename); \
763  if (strcmp (v_##typename, literal) != 0) \
764  _dbus_test_fatal ("got wrong value from message iter"); \
765  } while (0)
766 
767 #define GET_AND_CHECK_AND_NEXT(iter, typename, literal) \
768  do { \
769  GET_AND_CHECK(iter, typename, literal); \
770  if (!dbus_message_iter_next (&iter)) \
771  _dbus_test_fatal ("failed to move iter to next"); \
772  } while (0)
773 
774 #define GET_AND_CHECK_STRCMP_AND_NEXT(iter, typename, literal) \
775  do { \
776  GET_AND_CHECK_STRCMP(iter, typename, literal); \
777  if (!dbus_message_iter_next (&iter)) \
778  _dbus_test_fatal ("failed to move iter to next"); \
779  } while (0)
780 
781 static void
782 message_iter_test (DBusMessage *message)
783 {
784  DBusMessageIter iter, array, array2;
785  const char *v_STRING;
786  double v_DOUBLE;
787  dbus_int16_t v_INT16;
788  dbus_uint16_t v_UINT16;
789  dbus_int32_t v_INT32;
790  dbus_uint32_t v_UINT32;
791  dbus_int64_t v_INT64;
792  dbus_uint64_t v_UINT64;
793  unsigned char v_BYTE;
794  dbus_bool_t v_BOOLEAN;
795 
796  const dbus_int32_t *our_int_array;
797  int len;
798 
799  dbus_message_iter_init (message, &iter);
800 
801  GET_AND_CHECK_STRCMP_AND_NEXT (iter, STRING, "Test string");
802  GET_AND_CHECK_AND_NEXT (iter, INT32, -0x12345678);
803  GET_AND_CHECK_AND_NEXT (iter, UINT32, 0xedd1e);
804  GET_AND_CHECK_AND_NEXT (iter, DOUBLE, 3.14159);
805 
807  _dbus_test_fatal ("Argument type not an array");
808 
810  _dbus_test_fatal ("Array type not double");
811 
812  dbus_message_iter_recurse (&iter, &array);
813 
814  GET_AND_CHECK_AND_NEXT (array, DOUBLE, 1.5);
815  GET_AND_CHECK (array, DOUBLE, 2.5);
816 
817  if (dbus_message_iter_next (&array))
818  _dbus_test_fatal ("Didn't reach end of array");
819 
820  if (!dbus_message_iter_next (&iter))
821  _dbus_test_fatal ("Reached end of arguments");
822 
823  GET_AND_CHECK_AND_NEXT (iter, BYTE, 0xF0);
824 
826  _dbus_test_fatal ("no array");
827 
829  _dbus_test_fatal ("Array type not int32");
830 
831  /* Empty array */
832  dbus_message_iter_recurse (&iter, &array);
833 
834  if (dbus_message_iter_next (&array))
835  _dbus_test_fatal ("Didn't reach end of array");
836 
837  if (!dbus_message_iter_next (&iter))
838  _dbus_test_fatal ("Reached end of arguments");
839 
840  GET_AND_CHECK (iter, BYTE, 0xF0);
841 
842  if (dbus_message_iter_next (&iter))
843  _dbus_test_fatal ("Didn't reach end of arguments");
844 }
845 #endif
846 
847 static void
848 verify_test_message (DBusMessage *message)
849 {
850  DBusMessageIter iter;
851  DBusError error = DBUS_ERROR_INIT;
852  dbus_int16_t our_int16;
853  dbus_uint16_t our_uint16;
854  dbus_int32_t our_int;
855  dbus_uint32_t our_uint;
856  const char *our_str;
857  double our_double;
858  double v_DOUBLE;
859  dbus_bool_t our_bool;
860  unsigned char our_byte_1, our_byte_2;
861  const dbus_uint32_t *our_uint32_array = (void*)0xdeadbeef;
862  int our_uint32_array_len;
863  dbus_int32_t *our_int32_array = (void*)0xdeadbeef;
864  int our_int32_array_len;
865  dbus_int64_t our_int64;
866  dbus_uint64_t our_uint64;
867  dbus_int64_t *our_uint64_array = (void*)0xdeadbeef;
868  int our_uint64_array_len;
869  const dbus_int64_t *our_int64_array = (void*)0xdeadbeef;
870  int our_int64_array_len;
871  const double *our_double_array = (void*)0xdeadbeef;
872  int our_double_array_len;
873  const unsigned char *our_byte_array = (void*)0xdeadbeef;
874  int our_byte_array_len;
875  const dbus_bool_t *our_boolean_array = (void*)0xdeadbeef;
876  int our_boolean_array_len;
877  char **our_string_array;
878  int our_string_array_len;
879 
880  dbus_message_iter_init (message, &iter);
881 
882  if (!dbus_message_iter_get_args (&iter, &error,
883  DBUS_TYPE_INT16, &our_int16,
884  DBUS_TYPE_UINT16, &our_uint16,
885  DBUS_TYPE_INT32, &our_int,
886  DBUS_TYPE_UINT32, &our_uint,
887  DBUS_TYPE_INT64, &our_int64,
888  DBUS_TYPE_UINT64, &our_uint64,
889  DBUS_TYPE_STRING, &our_str,
890  DBUS_TYPE_DOUBLE, &our_double,
891  DBUS_TYPE_BOOLEAN, &our_bool,
892  DBUS_TYPE_BYTE, &our_byte_1,
893  DBUS_TYPE_BYTE, &our_byte_2,
895  &our_uint32_array, &our_uint32_array_len,
897  &our_int32_array, &our_int32_array_len,
899  &our_uint64_array, &our_uint64_array_len,
901  &our_int64_array, &our_int64_array_len,
903  &our_double_array, &our_double_array_len,
905  &our_byte_array, &our_byte_array_len,
907  &our_boolean_array, &our_boolean_array_len,
909  &our_string_array, &our_string_array_len,
910  0))
911  {
912  _dbus_test_fatal ("Could not get arguments: %s - %s", error.name,
913  (error.message != NULL) ? error.message : "no message");
914  }
915 
916  if (our_int16 != -0x123)
917  _dbus_test_fatal ("16-bit integers differ!");
918 
919  if (our_uint16 != 0x123)
920  _dbus_test_fatal ("16-bit uints differ!");
921 
922  if (our_int != -0x12345678)
923  _dbus_test_fatal ("integers differ!");
924 
925  if (our_uint != 0x12300042)
926  _dbus_test_fatal ("uints differ!");
927 
928  if (our_int64 != DBUS_INT64_CONSTANT (-0x123456789abcd))
929  _dbus_test_fatal ("64-bit integers differ!");
930  if (our_uint64 != DBUS_UINT64_CONSTANT (0x123456789abcd))
931  _dbus_test_fatal ("64-bit unsigned integers differ!");
932 
933  v_DOUBLE = 3.14159;
934  if (! _DBUS_DOUBLES_BITWISE_EQUAL (our_double, v_DOUBLE))
935  _dbus_test_fatal ("doubles differ!");
936 
937  if (strcmp (our_str, "Test string") != 0)
938  _dbus_test_fatal ("strings differ!");
939 
940  if (!our_bool)
941  _dbus_test_fatal ("booleans differ");
942 
943  if (our_byte_1 != 42)
944  _dbus_test_fatal ("bytes differ!");
945 
946  if (our_byte_2 != 24)
947  _dbus_test_fatal ("bytes differ!");
948 
949  if (our_uint32_array_len != 4 ||
950  our_uint32_array[0] != 0x12345678 ||
951  our_uint32_array[1] != 0x23456781 ||
952  our_uint32_array[2] != 0x34567812 ||
953  our_uint32_array[3] != 0x45678123)
954  _dbus_test_fatal ("uint array differs");
955 
956  if (our_int32_array_len != 4 ||
957  our_int32_array[0] != 0x12345678 ||
958  our_int32_array[1] != -0x23456781 ||
959  our_int32_array[2] != 0x34567812 ||
960  our_int32_array[3] != -0x45678123)
961  _dbus_test_fatal ("int array differs");
962 
963  if (our_uint64_array_len != 4 ||
964  our_uint64_array[0] != 0x12345678 ||
965  our_uint64_array[1] != 0x23456781 ||
966  our_uint64_array[2] != 0x34567812 ||
967  our_uint64_array[3] != 0x45678123)
968  _dbus_test_fatal ("uint64 array differs");
969 
970  if (our_int64_array_len != 4 ||
971  our_int64_array[0] != 0x12345678 ||
972  our_int64_array[1] != -0x23456781 ||
973  our_int64_array[2] != 0x34567812 ||
974  our_int64_array[3] != -0x45678123)
975  _dbus_test_fatal ("int64 array differs");
976 
977  if (our_double_array_len != 3)
978  _dbus_test_fatal ("double array had wrong length");
979 
980  /* On all IEEE machines (i.e. everything sane) exact equality
981  * should be preserved over the wire
982  */
983  v_DOUBLE = 0.1234;
984  if (! _DBUS_DOUBLES_BITWISE_EQUAL (our_double_array[0], v_DOUBLE))
985  _dbus_test_fatal ("double array had wrong values");
986  v_DOUBLE = 9876.54321;
987  if (! _DBUS_DOUBLES_BITWISE_EQUAL (our_double_array[1], v_DOUBLE))
988  _dbus_test_fatal ("double array had wrong values");
989  v_DOUBLE = -300.0;
990  if (! _DBUS_DOUBLES_BITWISE_EQUAL (our_double_array[2], v_DOUBLE))
991  _dbus_test_fatal ("double array had wrong values");
992 
993  if (our_byte_array_len != 4)
994  _dbus_test_fatal ("byte array had wrong length");
995 
996  if (our_byte_array[0] != 'a' ||
997  our_byte_array[1] != 'b' ||
998  our_byte_array[2] != 'c' ||
999  our_byte_array[3] != 234)
1000  _dbus_test_fatal ("byte array had wrong values");
1001 
1002  if (our_boolean_array_len != 5)
1003  _dbus_test_fatal ("bool array had wrong length");
1004 
1005  if (our_boolean_array[0] != TRUE ||
1006  our_boolean_array[1] != FALSE ||
1007  our_boolean_array[2] != TRUE ||
1008  our_boolean_array[3] != TRUE ||
1009  our_boolean_array[4] != FALSE)
1010  _dbus_test_fatal ("bool array had wrong values");
1011 
1012  if (our_string_array_len != 4)
1013  _dbus_test_fatal ("string array was wrong length");
1014 
1015  if (strcmp (our_string_array[0], "Foo") != 0 ||
1016  strcmp (our_string_array[1], "bar") != 0 ||
1017  strcmp (our_string_array[2], "") != 0 ||
1018  strcmp (our_string_array[3], "woo woo woo woo") != 0)
1019  _dbus_test_fatal ("string array had wrong values");
1020 
1021  dbus_free_string_array (our_string_array);
1022 
1023  if (dbus_message_iter_next (&iter))
1024  _dbus_test_fatal ("Didn't reach end of arguments");
1025 }
1026 
1027 static void
1028 verify_test_message_args_ignored (DBusMessage *message)
1029 {
1030  DBusMessageIter iter;
1031  DBusError error = DBUS_ERROR_INIT;
1032  dbus_uint32_t our_uint;
1033  DBusInitialFDs *initial_fds;
1034 
1035  initial_fds = _dbus_check_fdleaks_enter ();
1036 
1037  /* parse with empty signature: "" */
1038  dbus_message_iter_init (message, &iter);
1039  if (!dbus_message_iter_get_args (&iter, &error,
1041  {
1042  _dbus_warn ("error: %s - %s", error.name,
1043  (error.message != NULL) ? error.message : "no message");
1044  }
1045  else
1046  {
1047  _dbus_assert (!dbus_error_is_set (&error));
1048  _dbus_verbose ("arguments ignored.\n");
1049  }
1050 
1051  /* parse with shorter signature: "u" */
1052  dbus_message_iter_init (message, &iter);
1053  if (!dbus_message_iter_get_args (&iter, &error,
1054  DBUS_TYPE_UINT32, &our_uint,
1056  {
1057  _dbus_warn ("error: %s - %s", error.name,
1058  (error.message != NULL) ? error.message : "no message");
1059  }
1060  else
1061  {
1062  _dbus_assert (!dbus_error_is_set (&error));
1063  _dbus_verbose ("arguments ignored.\n");
1064  }
1065 
1066  _dbus_check_fdleaks_leave (initial_fds);
1067 }
1068 
1069 static void
1070 verify_test_message_memleak (DBusMessage *message)
1071 {
1072  DBusMessageIter iter;
1073  DBusError error = DBUS_ERROR_INIT;
1074  dbus_uint32_t our_uint1;
1075  dbus_uint32_t our_uint2;
1076  dbus_uint32_t our_uint3;
1077  char **our_string_array1;
1078  int our_string_array_len1;
1079  char **our_string_array2;
1080  int our_string_array_len2;
1081 #ifdef HAVE_UNIX_FD_PASSING
1082  int our_unix_fd1;
1083  int our_unix_fd2;
1084 #endif
1085  DBusInitialFDs *initial_fds;
1086 
1087  initial_fds = _dbus_check_fdleaks_enter ();
1088 
1089  /* parse with wrong signature: "uashuu" */
1090  dbus_error_free (&error);
1091  dbus_message_iter_init (message, &iter);
1092  if (!dbus_message_iter_get_args (&iter, &error,
1093  DBUS_TYPE_UINT32, &our_uint1,
1095  &our_string_array1, &our_string_array_len1,
1096 #ifdef HAVE_UNIX_FD_PASSING
1097  DBUS_TYPE_UNIX_FD, &our_unix_fd1,
1098 #endif
1099  DBUS_TYPE_UINT32, &our_uint2,
1100  DBUS_TYPE_UINT32, &our_uint3,
1102  {
1103  _dbus_verbose ("expected error: %s - %s\n", error.name,
1104  (error.message != NULL) ? error.message : "no message");
1105  /* ensure array of string and unix fd not leaked */
1106  _dbus_assert (our_string_array1 == NULL);
1107 #ifdef HAVE_UNIX_FD_PASSING
1108  _dbus_assert (our_unix_fd1 == -1);
1109 #endif
1110  }
1111  else
1112  {
1113  _dbus_test_fatal ("error: parse with wrong signature: 'uashuu'.");
1114  }
1115 
1116  /* parse with wrong signature: "uashuashu" */
1117  dbus_message_iter_init (message, &iter);
1118  dbus_error_free (&error);
1119  if (!dbus_message_iter_get_args (&iter, &error,
1120  DBUS_TYPE_UINT32, &our_uint1,
1122  &our_string_array1, &our_string_array_len1,
1123 #ifdef HAVE_UNIX_FD_PASSING
1124  DBUS_TYPE_UNIX_FD, &our_unix_fd1,
1125 #endif
1126  DBUS_TYPE_UINT32, &our_uint2,
1128  &our_string_array2, &our_string_array_len2,
1129 #ifdef HAVE_UNIX_FD_PASSING
1130  DBUS_TYPE_UNIX_FD, &our_unix_fd2,
1131 #endif
1132  DBUS_TYPE_UINT32, &our_uint3,
1134  {
1135  _dbus_verbose ("expected error: %s - %s\n", error.name,
1136  (error.message != NULL) ? error.message : "no message");
1137  /* ensure array of string and unix fd not leaked */
1138  _dbus_assert (our_string_array1 == NULL);
1139  _dbus_assert (our_string_array2 == NULL);
1140 #ifdef HAVE_UNIX_FD_PASSING
1141  _dbus_assert (our_unix_fd1 == -1);
1142  _dbus_assert (our_unix_fd2 == -1);
1143 #endif
1144  }
1145  else
1146  {
1147  _dbus_test_fatal ("error: parse with wrong signature: 'uashuashu'.");
1148  }
1149 
1150  /* parse with correct signature: "uashuash" */
1151  dbus_message_iter_init (message, &iter);
1152  dbus_error_free (&error);
1153  if (!dbus_message_iter_get_args (&iter, &error,
1154  DBUS_TYPE_UINT32, &our_uint1,
1156  &our_string_array1, &our_string_array_len1,
1157 #ifdef HAVE_UNIX_FD_PASSING
1158  DBUS_TYPE_UNIX_FD, &our_unix_fd1,
1159 #endif
1160  DBUS_TYPE_UINT32, &our_uint2,
1162  &our_string_array2, &our_string_array_len2,
1163 #ifdef HAVE_UNIX_FD_PASSING
1164  DBUS_TYPE_UNIX_FD, &our_unix_fd2,
1165 #endif
1167  {
1168  _dbus_test_fatal ("Could not get arguments: %s - %s", error.name,
1169  (error.message != NULL) ? error.message : "no message");
1170  }
1171  else
1172  {
1173  dbus_free_string_array (our_string_array1);
1174  dbus_free_string_array (our_string_array2);
1175 #ifdef HAVE_UNIX_FD_PASSING
1176  _dbus_close (our_unix_fd1, &error);
1177  _dbus_close (our_unix_fd2, &error);
1178 #endif
1179  }
1180  _dbus_check_fdleaks_leave (initial_fds);
1181 }
1182 
1190 _dbus_message_test (const char *test_data_dir)
1191 {
1192  DBusMessage *message, *message_without_unix_fds;
1193  DBusMessageLoader *loader;
1194  int i;
1195  const char *data;
1196  DBusMessage *copy;
1197  const char *name1;
1198  const char *name2;
1199  const dbus_uint32_t our_uint32_array[] =
1200  { 0x12345678, 0x23456781, 0x34567812, 0x45678123 };
1201  const dbus_int32_t our_int32_array[] =
1202  { 0x12345678, -0x23456781, 0x34567812, -0x45678123 };
1203  const dbus_uint32_t *v_ARRAY_UINT32 = our_uint32_array;
1204  const dbus_int32_t *v_ARRAY_INT32 = our_int32_array;
1205  const dbus_uint64_t our_uint64_array[] =
1206  { 0x12345678, 0x23456781, 0x34567812, 0x45678123 };
1207  const dbus_int64_t our_int64_array[] =
1208  { 0x12345678, -0x23456781, 0x34567812, -0x45678123 };
1209  const dbus_uint64_t *v_ARRAY_UINT64 = our_uint64_array;
1210  const dbus_int64_t *v_ARRAY_INT64 = our_int64_array;
1211  const char *our_string_array[] = { "Foo", "bar", "", "woo woo woo woo" };
1212  const char *our_string_array1[] = { "foo", "Bar", "", "Woo woo Woo woo" };
1213  const char **v_ARRAY_STRING = our_string_array;
1214  const char **v1_ARRAY_STRING = our_string_array1;
1215  const double our_double_array[] = { 0.1234, 9876.54321, -300.0 };
1216  const double *v_ARRAY_DOUBLE = our_double_array;
1217  const unsigned char our_byte_array[] = { 'a', 'b', 'c', 234 };
1218  const unsigned char *v_ARRAY_BYTE = our_byte_array;
1219  const dbus_bool_t our_boolean_array[] = { TRUE, FALSE, TRUE, TRUE, FALSE };
1220  const dbus_bool_t *v_ARRAY_BOOLEAN = our_boolean_array;
1221  char sig[64];
1222  const char *s;
1223  const char *v_STRING;
1224  double v_DOUBLE;
1225  dbus_int16_t v_INT16;
1226  dbus_uint16_t v_UINT16;
1227  dbus_int32_t v_INT32;
1228  dbus_uint32_t v_UINT32;
1229  dbus_uint32_t v1_UINT32;
1230  dbus_int64_t v_INT64;
1231  dbus_uint64_t v_UINT64;
1232  unsigned char v_BYTE;
1233  unsigned char v2_BYTE;
1234  dbus_bool_t v_BOOLEAN;
1235  DBusMessageIter iter, array_iter, struct_iter;
1236 #ifdef HAVE_UNIX_FD_PASSING
1237  int v_UNIX_FD;
1238  int v1_UNIX_FD;
1239 #endif
1240  char **decomposed;
1241  DBusInitialFDs *initial_fds;
1242  dbus_bool_t ok;
1243  char basic_types[] = DBUS_TYPE_BYTE_AS_STRING \
1253 
1254  initial_fds = _dbus_check_fdleaks_enter ();
1255 
1256  message = dbus_message_new_method_call ("org.freedesktop.DBus.TestService",
1257  "/org/freedesktop/TestPath",
1258  "Foo.TestInterface",
1259  "TestMethod");
1260  _dbus_assert (dbus_message_has_destination (message, "org.freedesktop.DBus.TestService"));
1261  _dbus_assert (dbus_message_is_method_call (message, "Foo.TestInterface",
1262  "TestMethod"));
1263  _dbus_assert (strcmp (dbus_message_get_path (message),
1264  "/org/freedesktop/TestPath") == 0);
1265  dbus_message_set_serial (message, 1234);
1266 
1267  /* string length including nul byte not a multiple of 4 */
1268  if (!dbus_message_set_sender (message, "org.foo.bar1"))
1269  _dbus_test_fatal ("out of memory");
1270 
1271  _dbus_assert (dbus_message_has_sender (message, "org.foo.bar1"));
1272  dbus_message_set_reply_serial (message, 5678);
1273 
1275  _dbus_string_get_length (&message->header.data));
1276  _dbus_verbose_bytes_of_string (&message->body, 0,
1277  _dbus_string_get_length (&message->body));
1278 
1279  if (!dbus_message_set_sender (message, NULL))
1280  _dbus_test_fatal ("out of memory");
1281 
1282 
1284  _dbus_string_get_length (&message->header.data));
1285  _dbus_verbose_bytes_of_string (&message->body, 0,
1286  _dbus_string_get_length (&message->body));
1287 
1288 
1289  _dbus_assert (!dbus_message_has_sender (message, "org.foo.bar1"));
1290  _dbus_assert (dbus_message_get_serial (message) == 1234);
1291  _dbus_assert (dbus_message_get_reply_serial (message) == 5678);
1292  _dbus_assert (dbus_message_has_destination (message, "org.freedesktop.DBus.TestService"));
1293 
1294  _dbus_assert (dbus_message_get_no_reply (message) == FALSE);
1295  dbus_message_set_no_reply (message, TRUE);
1297  dbus_message_set_no_reply (message, FALSE);
1298  _dbus_assert (dbus_message_get_no_reply (message) == FALSE);
1299 
1300  /* Set/get some header fields */
1301 
1302  if (!dbus_message_set_path (message, "/foo"))
1303  _dbus_test_fatal ("out of memory");
1304  _dbus_assert (strcmp (dbus_message_get_path (message),
1305  "/foo") == 0);
1306 
1307  if (!dbus_message_set_container_instance (message, "/org/freedesktop/DBus/Containers1/c42"))
1308  _dbus_test_fatal ("out of memory");
1310  "/org/freedesktop/DBus/Containers1/c42") == 0);
1311 
1312  if (!dbus_message_set_interface (message, "org.Foo"))
1313  _dbus_test_fatal ("out of memory");
1314  _dbus_assert (strcmp (dbus_message_get_interface (message),
1315  "org.Foo") == 0);
1316 
1317  if (!dbus_message_set_member (message, "Bar"))
1318  _dbus_test_fatal ("out of memory");
1319  _dbus_assert (strcmp (dbus_message_get_member (message),
1320  "Bar") == 0);
1321 
1322  /* Set/get them with longer values */
1323  if (!dbus_message_set_path (message, "/foo/bar"))
1324  _dbus_test_fatal ("out of memory");
1325  _dbus_assert (strcmp (dbus_message_get_path (message),
1326  "/foo/bar") == 0);
1327 
1328  if (!dbus_message_set_interface (message, "org.Foo.Bar"))
1329  _dbus_test_fatal ("out of memory");
1330  _dbus_assert (strcmp (dbus_message_get_interface (message),
1331  "org.Foo.Bar") == 0);
1332 
1333  if (!dbus_message_set_member (message, "BarFoo"))
1334  _dbus_test_fatal ("out of memory");
1335  _dbus_assert (strcmp (dbus_message_get_member (message),
1336  "BarFoo") == 0);
1337 
1338  /* Realloc shorter again */
1339 
1340  if (!dbus_message_set_path (message, "/foo"))
1341  _dbus_test_fatal ("out of memory");
1342  _dbus_assert (strcmp (dbus_message_get_path (message),
1343  "/foo") == 0);
1344 
1345  if (!dbus_message_set_interface (message, "org.Foo"))
1346  _dbus_test_fatal ("out of memory");
1347  _dbus_assert (strcmp (dbus_message_get_interface (message),
1348  "org.Foo") == 0);
1349 
1350  if (!dbus_message_set_member (message, "Bar"))
1351  _dbus_test_fatal ("out of memory");
1352  _dbus_assert (strcmp (dbus_message_get_member (message),
1353  "Bar") == 0);
1354 
1355  /* Path decomposing */
1356  dbus_message_set_path (message, NULL);
1357  dbus_message_get_path_decomposed (message, &decomposed);
1358  _dbus_assert (decomposed == NULL);
1359  dbus_free_string_array (decomposed);
1360 
1361  dbus_message_set_path (message, "/");
1362  dbus_message_get_path_decomposed (message, &decomposed);
1363  _dbus_assert (decomposed != NULL);
1364  _dbus_assert (decomposed[0] == NULL);
1365  dbus_free_string_array (decomposed);
1366 
1367  dbus_message_set_path (message, "/a/b");
1368  dbus_message_get_path_decomposed (message, &decomposed);
1369  _dbus_assert (decomposed != NULL);
1370  _dbus_assert (strcmp (decomposed[0], "a") == 0);
1371  _dbus_assert (strcmp (decomposed[1], "b") == 0);
1372  _dbus_assert (decomposed[2] == NULL);
1373  dbus_free_string_array (decomposed);
1374 
1375  dbus_message_set_path (message, "/spam/eggs");
1376  dbus_message_get_path_decomposed (message, &decomposed);
1377  _dbus_assert (decomposed != NULL);
1378  _dbus_assert (strcmp (decomposed[0], "spam") == 0);
1379  _dbus_assert (strcmp (decomposed[1], "eggs") == 0);
1380  _dbus_assert (decomposed[2] == NULL);
1381  dbus_free_string_array (decomposed);
1382 
1383  dbus_message_unref (message);
1384 
1385  /* Test the vararg functions */
1386  message = dbus_message_new_method_call ("org.freedesktop.DBus.TestService",
1387  "/org/freedesktop/TestPath",
1388  "Foo.TestInterface",
1389  "TestMethod");
1390  dbus_message_set_serial (message, 1);
1391  dbus_message_set_reply_serial (message, 5678);
1392 
1393  v_INT16 = -0x123;
1394  v_UINT16 = 0x123;
1395  v_INT32 = -0x12345678;
1396  v_UINT32 = 0x12300042;
1397  v_INT64 = DBUS_INT64_CONSTANT (-0x123456789abcd);
1398  v_UINT64 = DBUS_UINT64_CONSTANT (0x123456789abcd);
1399  v_STRING = "Test string";
1400  v_DOUBLE = 3.14159;
1401  v_BOOLEAN = TRUE;
1402  v_BYTE = 42;
1403  v2_BYTE = 24;
1404 #ifdef HAVE_UNIX_FD_PASSING
1405  v_UNIX_FD = 1;
1406  v1_UNIX_FD = 2;
1407 #endif
1408 
1409  dbus_message_append_args (message,
1410  DBUS_TYPE_INT16, &v_INT16,
1411  DBUS_TYPE_UINT16, &v_UINT16,
1412  DBUS_TYPE_INT32, &v_INT32,
1413  DBUS_TYPE_UINT32, &v_UINT32,
1414  DBUS_TYPE_INT64, &v_INT64,
1415  DBUS_TYPE_UINT64, &v_UINT64,
1416  DBUS_TYPE_STRING, &v_STRING,
1417  DBUS_TYPE_DOUBLE, &v_DOUBLE,
1418  DBUS_TYPE_BOOLEAN, &v_BOOLEAN,
1419  DBUS_TYPE_BYTE, &v_BYTE,
1420  DBUS_TYPE_BYTE, &v2_BYTE,
1421  DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &v_ARRAY_UINT32,
1422  _DBUS_N_ELEMENTS (our_uint32_array),
1423  DBUS_TYPE_ARRAY, DBUS_TYPE_INT32, &v_ARRAY_INT32,
1424  _DBUS_N_ELEMENTS (our_int32_array),
1425  DBUS_TYPE_ARRAY, DBUS_TYPE_UINT64, &v_ARRAY_UINT64,
1426  _DBUS_N_ELEMENTS (our_uint64_array),
1427  DBUS_TYPE_ARRAY, DBUS_TYPE_INT64, &v_ARRAY_INT64,
1428  _DBUS_N_ELEMENTS (our_int64_array),
1429  DBUS_TYPE_ARRAY, DBUS_TYPE_DOUBLE, &v_ARRAY_DOUBLE,
1430  _DBUS_N_ELEMENTS (our_double_array),
1431  DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &v_ARRAY_BYTE,
1432  _DBUS_N_ELEMENTS (our_byte_array),
1433  DBUS_TYPE_ARRAY, DBUS_TYPE_BOOLEAN, &v_ARRAY_BOOLEAN,
1434  _DBUS_N_ELEMENTS (our_boolean_array),
1435  DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &v_ARRAY_STRING,
1436  _DBUS_N_ELEMENTS (our_string_array),
1437 
1439 
1440  i = 0;
1441  sig[i++] = DBUS_TYPE_INT16;
1442  sig[i++] = DBUS_TYPE_UINT16;
1443  sig[i++] = DBUS_TYPE_INT32;
1444  sig[i++] = DBUS_TYPE_UINT32;
1445  sig[i++] = DBUS_TYPE_INT64;
1446  sig[i++] = DBUS_TYPE_UINT64;
1447  sig[i++] = DBUS_TYPE_STRING;
1448  sig[i++] = DBUS_TYPE_DOUBLE;
1449  sig[i++] = DBUS_TYPE_BOOLEAN;
1450  sig[i++] = DBUS_TYPE_BYTE;
1451  sig[i++] = DBUS_TYPE_BYTE;
1452  sig[i++] = DBUS_TYPE_ARRAY;
1453  sig[i++] = DBUS_TYPE_UINT32;
1454  sig[i++] = DBUS_TYPE_ARRAY;
1455  sig[i++] = DBUS_TYPE_INT32;
1456  sig[i++] = DBUS_TYPE_ARRAY;
1457  sig[i++] = DBUS_TYPE_UINT64;
1458  sig[i++] = DBUS_TYPE_ARRAY;
1459  sig[i++] = DBUS_TYPE_INT64;
1460  sig[i++] = DBUS_TYPE_ARRAY;
1461  sig[i++] = DBUS_TYPE_DOUBLE;
1462  sig[i++] = DBUS_TYPE_ARRAY;
1463  sig[i++] = DBUS_TYPE_BYTE;
1464  sig[i++] = DBUS_TYPE_ARRAY;
1465  sig[i++] = DBUS_TYPE_BOOLEAN;
1466  sig[i++] = DBUS_TYPE_ARRAY;
1467  sig[i++] = DBUS_TYPE_STRING;
1468 
1469  message_without_unix_fds = dbus_message_copy(message);
1470  _dbus_assert(message_without_unix_fds);
1471 #ifdef HAVE_UNIX_FD_PASSING
1472  dbus_message_append_args (message,
1473  DBUS_TYPE_UNIX_FD, &v_UNIX_FD,
1475  sig[i++] = DBUS_TYPE_UNIX_FD;
1476 #endif
1477  sig[i++] = DBUS_TYPE_INVALID;
1478 
1479  _dbus_assert (i < (int) _DBUS_N_ELEMENTS (sig));
1480 
1481  _dbus_verbose ("HEADER\n");
1483  _dbus_string_get_length (&message->header.data));
1484  _dbus_verbose ("BODY\n");
1485  _dbus_verbose_bytes_of_string (&message->body, 0,
1486  _dbus_string_get_length (&message->body));
1487 
1488  _dbus_verbose ("Signature expected \"%s\" actual \"%s\"\n",
1489  sig, dbus_message_get_signature (message));
1490 
1491  s = dbus_message_get_signature (message);
1492 
1493  _dbus_assert (dbus_message_has_signature (message, sig));
1494  _dbus_assert (strcmp (s, sig) == 0);
1495 
1496  verify_test_message (message);
1497 
1498  copy = dbus_message_copy (message);
1499 
1502  _dbus_assert (message->header.padding == copy->header.padding);
1503 
1504  _dbus_assert (_dbus_string_get_length (&message->header.data) ==
1505  _dbus_string_get_length (&copy->header.data));
1506 
1507  _dbus_assert (_dbus_string_get_length (&message->body) ==
1508  _dbus_string_get_length (&copy->body));
1509 
1510  verify_test_message (copy);
1511 
1512  name1 = dbus_message_get_interface (message);
1513  name2 = dbus_message_get_interface (copy);
1514 
1515  _dbus_assert (strcmp (name1, name2) == 0);
1516 
1517  name1 = dbus_message_get_member (message);
1518  name2 = dbus_message_get_member (copy);
1519 
1520  _dbus_assert (strcmp (name1, name2) == 0);
1521 
1522  dbus_message_unref (copy);
1523 
1524  /* Message loader test */
1525  dbus_message_lock (message);
1526  loader = _dbus_message_loader_new ();
1527 
1528  /* check ref/unref */
1529  _dbus_message_loader_ref (loader);
1530  _dbus_message_loader_unref (loader);
1531 
1532  /* Write the header data one byte at a time */
1533  data = _dbus_string_get_const_data (&message->header.data);
1534  for (i = 0; i < _dbus_string_get_length (&message->header.data); i++)
1535  {
1536  DBusString *buffer;
1537 
1538  _dbus_message_loader_get_buffer (loader, &buffer, NULL, NULL);
1539  _dbus_string_append_byte (buffer, data[i]);
1540  _dbus_message_loader_return_buffer (loader, buffer);
1541  }
1542 
1543  /* Write the body data one byte at a time */
1544  data = _dbus_string_get_const_data (&message->body);
1545  for (i = 0; i < _dbus_string_get_length (&message->body); i++)
1546  {
1547  DBusString *buffer;
1548 
1549  _dbus_message_loader_get_buffer (loader, &buffer, NULL, NULL);
1550  _dbus_string_append_byte (buffer, data[i]);
1551  _dbus_message_loader_return_buffer (loader, buffer);
1552  }
1553 
1554 #ifdef HAVE_UNIX_FD_PASSING
1555  {
1556  int *unix_fds;
1557  unsigned n_unix_fds;
1558  /* Write unix fd */
1559  _dbus_message_loader_get_unix_fds(loader, &unix_fds, &n_unix_fds);
1560  _dbus_assert(n_unix_fds > 0);
1561  _dbus_assert(message->n_unix_fds == 1);
1562  unix_fds[0] = _dbus_dup(message->unix_fds[0], NULL);
1563  _dbus_assert(unix_fds[0] >= 0);
1564  _dbus_message_loader_return_unix_fds(loader, unix_fds, 1);
1565  }
1566 #endif
1567 
1568  dbus_message_unref (message);
1569 
1570  /* Now pop back the message */
1572  _dbus_test_fatal ("no memory to queue messages");
1573 
1575  _dbus_test_fatal ("message loader corrupted");
1576 
1577  message = _dbus_message_loader_pop_message (loader);
1578  if (!message)
1579  _dbus_test_fatal ("received a NULL message");
1580 
1581  if (dbus_message_get_reply_serial (message) != 5678)
1582  _dbus_test_fatal ("reply serial fields differ");
1583 
1584  dbus_message_unref (message);
1585 
1586  /* ovveride the serial, since it was reset by dbus_message_copy() */
1587  dbus_message_set_serial(message_without_unix_fds, 8901);
1588 
1589  dbus_message_lock (message_without_unix_fds);
1590 
1591  verify_test_message (message_without_unix_fds);
1592 
1593  {
1594  /* Marshal and demarshal the message. */
1595 
1596  DBusMessage *message2;
1597  DBusError error = DBUS_ERROR_INIT;
1598  char *marshalled = NULL;
1599  int len = 0;
1600  char garbage_header[DBUS_MINIMUM_HEADER_SIZE] = "xxx";
1601 
1602  if (!dbus_message_marshal (message_without_unix_fds, &marshalled, &len))
1603  _dbus_test_fatal ("failed to marshal message");
1604 
1605  _dbus_assert (len != 0);
1606  _dbus_assert (marshalled != NULL);
1607 
1608  _dbus_assert (dbus_message_demarshal_bytes_needed (marshalled, len) == len);
1609  message2 = dbus_message_demarshal (marshalled, len, &error);
1610 
1611  _dbus_assert (message2 != NULL);
1612  _dbus_assert (!dbus_error_is_set (&error));
1613  verify_test_message (message2);
1614 
1615  dbus_message_unref (message2);
1616  dbus_free (marshalled);
1617 
1618  /* Demarshal invalid message. */
1619 
1620  message2 = dbus_message_demarshal ("invalid", 7, &error);
1621  _dbus_assert (message2 == NULL);
1622  _dbus_assert (dbus_error_is_set (&error));
1623  dbus_error_free (&error);
1624 
1625  /* Demarshal invalid (empty) message. */
1626 
1627  message2 = dbus_message_demarshal ("", 0, &error);
1628  _dbus_assert (message2 == NULL);
1629  _dbus_assert (dbus_error_is_set (&error));
1630  dbus_error_free (&error);
1631 
1632  /* Bytes needed to demarshal empty message: 0 (more) */
1633 
1635 
1636  /* Bytes needed to demarshal invalid message: -1 (error). */
1637 
1639  }
1640 
1641  dbus_message_unref (message_without_unix_fds);
1642  _dbus_message_loader_unref (loader);
1643 
1644  check_memleaks ();
1645  _dbus_check_fdleaks_leave (initial_fds);
1646  initial_fds = _dbus_check_fdleaks_enter ();
1647 
1648  /* Test enumeration of array elements */
1649  for (i = strlen (basic_types) - 1; i > 0; i--)
1650  {
1651  DBusBasicValue val;
1652  int some;
1653  char* signature = _dbus_strdup ("?");
1654 
1655  signature[0] = basic_types[i];
1656  s = "SomeThingToSay";
1657  memset (&val, '\0', sizeof (val));
1658 
1659  message = dbus_message_new_method_call ("de.ende.test",
1660  "/de/ende/test", "de.ende.Test", "ArtistName");
1661  _dbus_assert (message != NULL);
1662  dbus_message_iter_init_append (message, &iter);
1664  signature, &array_iter);
1665  for (some = 0; some < 3; some++)
1666  {
1667  if (basic_types[i] == DBUS_TYPE_STRING)
1669  else
1670  dbus_message_iter_append_basic (&array_iter, basic_types[i], &val);
1671  }
1672  dbus_message_iter_close_container (&iter, &array_iter);
1673  dbus_message_iter_init (message, &iter);
1675  dbus_message_unref (message);
1676  dbus_free (signature);
1677  }
1678  /* Array of structs */
1679  message = dbus_message_new_method_call ("de.ende.test",
1680  "/de/ende/test", "de.ende.Test", "ArtistName");
1681  _dbus_assert (message != NULL);
1682  dbus_message_iter_init_append (message, &iter);
1686  DBUS_STRUCT_END_CHAR_AS_STRING, &array_iter);
1688  NULL, &struct_iter);
1689  s = "SpamAndEggs";
1691  dbus_message_iter_close_container (&array_iter, &struct_iter);
1692  dbus_message_iter_close_container (&iter, &array_iter);
1693  dbus_message_iter_init (message, &iter);
1695  dbus_message_unref (message);
1696  check_memleaks ();
1697 
1698  /* Check that we can abandon a container */
1699  message = dbus_message_new_method_call ("org.freedesktop.DBus.TestService",
1700  "/org/freedesktop/TestPath",
1701  "Foo.TestInterface",
1702  "Method");
1703 
1704  dbus_message_iter_init_append (message, &iter);
1705 
1710  DBUS_STRUCT_END_CHAR_AS_STRING),
1711  &array_iter);
1712  _dbus_assert (ok);
1714  NULL, &struct_iter);
1715  _dbus_assert (ok);
1716  s = "peaches";
1717  ok = dbus_message_iter_append_basic (&struct_iter, DBUS_TYPE_STRING, &s);
1718  _dbus_assert (ok);
1719 
1720  /* uh-oh, error, try and unwind */
1721 
1722  dbus_message_iter_abandon_container (&array_iter, &struct_iter);
1723  dbus_message_iter_abandon_container (&array_iter, &iter);
1724 
1725  dbus_message_unref (message);
1726 
1727  /* Check we should not leak array of string or unix fd, fd.o#21259 */
1728  message = dbus_message_new_method_call ("org.freedesktop.DBus.TestService",
1729  "/org/freedesktop/TestPath",
1730  "Foo.TestInterface",
1731  "Method");
1732 
1733  /* signature "uashuash" */
1734  dbus_message_append_args (message,
1735  DBUS_TYPE_UINT32, &v_UINT32,
1736  DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &v_ARRAY_STRING,
1737  _DBUS_N_ELEMENTS (our_string_array),
1738 #ifdef HAVE_UNIX_FD_PASSING
1739  DBUS_TYPE_UNIX_FD, &v_UNIX_FD,
1740 #endif
1741  DBUS_TYPE_UINT32, &v1_UINT32,
1742  DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &v1_ARRAY_STRING,
1743  _DBUS_N_ELEMENTS (our_string_array1),
1744 #ifdef HAVE_UNIX_FD_PASSING
1745  DBUS_TYPE_UNIX_FD, &v1_UNIX_FD,
1746 #endif
1747 
1749 
1750  i = 0;
1751  sig[i++] = DBUS_TYPE_UINT32;
1752  sig[i++] = DBUS_TYPE_ARRAY;
1753  sig[i++] = DBUS_TYPE_STRING;
1754 #ifdef HAVE_UNIX_FD_PASSING
1755  sig[i++] = DBUS_TYPE_UNIX_FD;
1756 #endif
1757  sig[i++] = DBUS_TYPE_UINT32;
1758  sig[i++] = DBUS_TYPE_ARRAY;
1759  sig[i++] = DBUS_TYPE_STRING;
1760 #ifdef HAVE_UNIX_FD_PASSING
1761  sig[i++] = DBUS_TYPE_UNIX_FD;
1762 #endif
1763  sig[i++] = DBUS_TYPE_INVALID;
1764 
1765  _dbus_assert (i < (int) _DBUS_N_ELEMENTS (sig));
1766 
1767  verify_test_message_args_ignored (message);
1768  verify_test_message_memleak (message);
1769 
1770  dbus_message_unref (message);
1771 
1772  /* Load all the sample messages from the message factory */
1773  {
1774  DBusMessageDataIter diter;
1775  DBusMessageData mdata;
1776  int count;
1777 
1778  reset_validities_seen ();
1779 
1780  count = 0;
1781  _dbus_message_data_iter_init (&diter);
1782 
1783  while (_dbus_message_data_iter_get_and_next (&diter,
1784  &mdata))
1785  {
1786  if (!try_message_data (&mdata.data, mdata.expected_validity))
1787  {
1788  _dbus_test_fatal ("expected validity %d and did not get it",
1789  mdata.expected_validity);
1790  }
1791 
1792  _dbus_message_data_free (&mdata);
1793 
1794  count += 1;
1795  }
1796 
1797  _dbus_test_diag ("%d sample messages tested", count);
1798 
1799  print_validities_seen (FALSE);
1800  print_validities_seen (TRUE);
1801  }
1802 
1803  check_memleaks ();
1804  _dbus_check_fdleaks_leave (initial_fds);
1805 
1806  /* Now load every message in test_data_dir if we have one */
1807  if (test_data_dir == NULL)
1808  return TRUE;
1809 
1810  initial_fds = _dbus_check_fdleaks_enter ();
1811 
1812  if (!foreach_message_file (test_data_dir, try_message_file, NULL))
1813  _dbus_test_fatal ("foreach_message_file test failed");
1814 
1815  _dbus_check_fdleaks_leave (initial_fds);
1816 
1817  return TRUE;
1818 }
1819 
1820 #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:419
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:703
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
0-7 bytes of alignment in header, the distance from [B] to [C]
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:826
#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:1300
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:61
#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.
const char * dbus_message_get_container_instance(DBusMessage *message)
Gets the container instance this message was sent from, or NULL if none.
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.
dbus_bool_t dbus_message_set_container_instance(DBusMessage *message, const char *object_path)
Sets the container instance this message was sent from.
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:1174
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init(), and fills it with the same contents as #_DBUS_STRING_I...
Definition: dbus-string.c:264
#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.
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.
unsigned int _dbus_message_get_n_unix_fds(DBusMessage *message)
Gets the number of unix fds attached to this message.
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:751
#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.
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:899
#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:628
void dbus_message_set_serial(DBusMessage *message, dbus_uint32_t serial)
Sets the serial number of a message.
Definition: dbus-message.c:289