D-Bus 1.10.18

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\n",
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.\n", 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
255 if (_dbus_message_loader_get_is_corrupted (loader))
256 {
257 _dbus_warn ("loader corrupted on message that was expected to be valid; invalid reason %d\n",
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)\n");
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\n");
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
304 if (!_dbus_message_loader_get_is_corrupted (loader))
305 {
306 _dbus_warn ("loader not corrupted on message that was expected to be invalid\n");
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\n",
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
335 if (_dbus_message_loader_get_is_corrupted (loader))
336 {
337 _dbus_warn ("loader corrupted on message that was expected to be valid (but incomplete), corruption reason %d\n",
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\n");
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 {
362 if (!_dbus_message_loader_queue_messages (loader))
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 */
375 if (_dbus_message_loader_get_is_corrupted (loader))
376 record_validity_seen (loader->corruption_reason);
377
378 return TRUE;
379 }
380 else
381 return check_invalid_message (loader, expected_validity);
382 }
383
391 dbus_bool_t
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\n",
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
425 dbus_bool_t
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\n");
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)
447 _dbus_verbose_bytes_of_string (&data, 0,
448 _dbus_string_get_length (&data));
449
450 _dbus_warn ("Failed message loader test on %s\n",
451 _dbus_string_get_const_data (filename));
452 }
453
454 _dbus_string_free (&data);
455
456 return retval;
457 }
458
467 dbus_bool_t
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
483 /* check some trivial loader functions */
484 _dbus_message_loader_ref (loader);
485 _dbus_message_loader_unref (loader);
486 _dbus_message_loader_get_max_message_size (loader);
487
488 len = _dbus_string_get_length (data);
489 for (i = 0; i < len; i++)
490 {
491 DBusString *buffer;
492
493 _dbus_message_loader_get_buffer (loader, &buffer);
494 _dbus_string_append_byte (buffer,
495 _dbus_string_get_byte (data, i));
496 _dbus_message_loader_return_buffer (loader, buffer);
497 }
498
499 if (!check_loader_results (loader, expected_validity))
500 goto failed;
501
502 _dbus_message_loader_unref (loader);
503 loader = NULL;
504
505 /* Write the data all at once */
506
507 loader = _dbus_message_loader_new ();
508
509 {
510 DBusString *buffer;
511
512 _dbus_message_loader_get_buffer (loader, &buffer);
513 _dbus_string_copy (data, 0, buffer,
514 _dbus_string_get_length (buffer));
515 _dbus_message_loader_return_buffer (loader, buffer);
516 }
517
518 if (!check_loader_results (loader, expected_validity))
519 goto failed;
520
521 _dbus_message_loader_unref (loader);
522 loader = NULL;
523
524 /* Write the data 2 bytes at a time */
525
526 loader = _dbus_message_loader_new ();
527
528 len = _dbus_string_get_length (data);
529 for (i = 0; i < len; i += 2)
530 {
531 DBusString *buffer;
532
533 _dbus_message_loader_get_buffer (loader, &buffer);
534 _dbus_string_append_byte (buffer,
535 _dbus_string_get_byte (data, i));
536 if ((i+1) < len)
537 _dbus_string_append_byte (buffer,
538 _dbus_string_get_byte (data, i+1));
539 _dbus_message_loader_return_buffer (loader, buffer);
540 }
541
542 if (!check_loader_results (loader, expected_validity))
543 goto failed;
544
545 _dbus_message_loader_unref (loader);
546 loader = NULL;
547
548 retval = TRUE;
549
550 failed:
551
552 if (loader)
553 _dbus_message_loader_unref (loader);
554
555 return retval;
556 }
557
558 static dbus_bool_t
559 process_test_subdir (const DBusString *test_base_dir,
560 const char *subdir,
561 DBusValidity expected_validity,
562 DBusForeachMessageFileFunc function,
563 void *user_data)
564 {
565 DBusString test_directory;
566 DBusString filename;
567 DBusDirIter *dir;
568 dbus_bool_t retval;
569 DBusError error = DBUS_ERROR_INIT;
570
571 retval = FALSE;
572 dir = NULL;
573
574 if (!_dbus_string_init (&test_directory))
575 _dbus_assert_not_reached ("didn't allocate test_directory\n");
576
577 _dbus_string_init_const (&filename, subdir);
578
579 if (!_dbus_string_copy (test_base_dir, 0,
580 &test_directory, 0))
581 _dbus_assert_not_reached ("couldn't copy test_base_dir to test_directory");
582
583 if (!_dbus_concat_dir_and_file (&test_directory, &filename))
584 _dbus_assert_not_reached ("couldn't allocate full path");
585
586 _dbus_string_free (&filename);
587 if (!_dbus_string_init (&filename))
588 _dbus_assert_not_reached ("didn't allocate filename string\n");
589
590 dir = _dbus_directory_open (&test_directory, &error);
591 if (dir == NULL)
592 {
593 _dbus_warn ("Could not open %s: %s\n",
594 _dbus_string_get_const_data (&test_directory),
595 error.message);
596 dbus_error_free (&error);
597 goto failed;
598 }
599
600 printf ("Testing %s:\n", subdir);
601
602 next:
603 while (_dbus_directory_get_next_file (dir, &filename, &error))
604 {
605 DBusString full_path;
606
607 if (!_dbus_string_init (&full_path))
608 _dbus_assert_not_reached ("couldn't init string");
609
610 if (!_dbus_string_copy (&test_directory, 0, &full_path, 0))
611 _dbus_assert_not_reached ("couldn't copy dir to full_path");
612
613 if (!_dbus_concat_dir_and_file (&full_path, &filename))
614 _dbus_assert_not_reached ("couldn't concat file to dir");
615
616 if (_dbus_string_ends_with_c_str (&filename, ".message-raw"))
617 ;
618 else
619 {
620 if (_dbus_string_ends_with_c_str (&filename, ".message"))
621 {
622 printf ("SKIP: Could not load %s, message builder language no longer supported\n",
623 _dbus_string_get_const_data (&filename));
624 }
625
626 _dbus_verbose ("Skipping non-.message file %s\n",
627 _dbus_string_get_const_data (&filename));
628 _dbus_string_free (&full_path);
629 goto next;
630 }
631
632 printf (" %s\n",
633 _dbus_string_get_const_data (&filename));
634
635 if (! (*function) (&full_path,
636 expected_validity, user_data))
637 {
638 _dbus_string_free (&full_path);
639 goto failed;
640 }
641 else
642 _dbus_string_free (&full_path);
643 }
644
645 if (dbus_error_is_set (&error))
646 {
647 _dbus_warn ("Could not get next file in %s: %s\n",
648 _dbus_string_get_const_data (&test_directory),
649 error.message);
650 dbus_error_free (&error);
651 goto failed;
652 }
653
654 retval = TRUE;
655
656 failed:
657
658 if (dir)
659 _dbus_directory_close (dir);
660 _dbus_string_free (&test_directory);
661 _dbus_string_free (&filename);
662
663 return retval;
664 }
665
675 dbus_bool_t
676 dbus_internal_do_not_use_foreach_message_file (const char *test_data_dir,
677 DBusForeachMessageFileFunc func,
678 void *user_data)
679 {
680 DBusString test_directory;
681 dbus_bool_t retval;
682
683 retval = FALSE;
684
685 _dbus_string_init_const (&test_directory, test_data_dir);
686
687 if (!process_test_subdir (&test_directory, "valid-messages",
688 DBUS_VALID, func, user_data))
689 goto failed;
690
691 check_memleaks ();
692
693 if (!process_test_subdir (&test_directory, "invalid-messages",
694 DBUS_INVALID_FOR_UNKNOWN_REASON, func, user_data))
695 goto failed;
696
697 check_memleaks ();
698
699 if (!process_test_subdir (&test_directory, "incomplete-messages",
700 DBUS_VALID_BUT_INCOMPLETE, func, user_data))
701 goto failed;
702
703 check_memleaks ();
704
705 retval = TRUE;
706
707 failed:
708
709 _dbus_string_free (&test_directory);
710
711 return retval;
712 }
713
714 #if 0
715 #define GET_AND_CHECK(iter, typename, literal) \
716 do { \
717 if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_##typename) \
718 _dbus_assert_not_reached ("got wrong argument type from message iter"); \
719 dbus_message_iter_get_basic (&iter, &v_##typename); \
720 if (v_##typename != literal) \
721 _dbus_assert_not_reached ("got wrong value from message iter"); \
722 } while (0)
723
724 #define GET_AND_CHECK_STRCMP(iter, typename, literal) \
725 do { \
726 if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_##typename) \
727 _dbus_assert_not_reached ("got wrong argument type from message iter"); \
728 dbus_message_iter_get_basic (&iter, &v_##typename); \
729 if (strcmp (v_##typename, literal) != 0) \
730 _dbus_assert_not_reached ("got wrong value from message iter"); \
731 } while (0)
732
733 #define GET_AND_CHECK_AND_NEXT(iter, typename, literal) \
734 do { \
735 GET_AND_CHECK(iter, typename, literal); \
736 if (!dbus_message_iter_next (&iter)) \
737 _dbus_assert_not_reached ("failed to move iter to next"); \
738 } while (0)
739
740 #define GET_AND_CHECK_STRCMP_AND_NEXT(iter, typename, literal) \
741 do { \
742 GET_AND_CHECK_STRCMP(iter, typename, literal); \
743 if (!dbus_message_iter_next (&iter)) \
744 _dbus_assert_not_reached ("failed to move iter to next"); \
745 } while (0)
746
747 static void
748 message_iter_test (DBusMessage *message)
749 {
750 DBusMessageIter iter, array, array2;
751 const char *v_STRING;
752 double v_DOUBLE;
753 dbus_int16_t v_INT16;
754 dbus_uint16_t v_UINT16;
755 dbus_int32_t v_INT32;
756 dbus_uint32_t v_UINT32;
757 dbus_int64_t v_INT64;
758 dbus_uint64_t v_UINT64;
759 unsigned char v_BYTE;
760 dbus_bool_t v_BOOLEAN;
761
762 const dbus_int32_t *our_int_array;
763 int len;
764
765 dbus_message_iter_init (message, &iter);
766
767 GET_AND_CHECK_STRCMP_AND_NEXT (iter, STRING, "Test string");
768 GET_AND_CHECK_AND_NEXT (iter, INT32, -0x12345678);
769 GET_AND_CHECK_AND_NEXT (iter, UINT32, 0xedd1e);
770 GET_AND_CHECK_AND_NEXT (iter, DOUBLE, 3.14159);
771
772 if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY)
773 _dbus_assert_not_reached ("Argument type not an array");
774
775 if (dbus_message_iter_get_element_type (&iter) != DBUS_TYPE_DOUBLE)
776 _dbus_assert_not_reached ("Array type not double");
777
778 dbus_message_iter_recurse (&iter, &array);
779
780 GET_AND_CHECK_AND_NEXT (array, DOUBLE, 1.5);
781 GET_AND_CHECK (array, DOUBLE, 2.5);
782
783 if (dbus_message_iter_next (&array))
784 _dbus_assert_not_reached ("Didn't reach end of array");
785
786 if (!dbus_message_iter_next (&iter))
787 _dbus_assert_not_reached ("Reached end of arguments");
788
789 GET_AND_CHECK_AND_NEXT (iter, BYTE, 0xF0);
790
791 if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY)
792 _dbus_assert_not_reached ("no array");
793
794 if (dbus_message_iter_get_element_type (&iter) != DBUS_TYPE_INT32)
795 _dbus_assert_not_reached ("Array type not int32");
796
797 /* Empty array */
798 dbus_message_iter_recurse (&iter, &array);
799
800 if (dbus_message_iter_next (&array))
801 _dbus_assert_not_reached ("Didn't reach end of array");
802
803 if (!dbus_message_iter_next (&iter))
804 _dbus_assert_not_reached ("Reached end of arguments");
805
806 GET_AND_CHECK (iter, BYTE, 0xF0);
807
808 if (dbus_message_iter_next (&iter))
809 _dbus_assert_not_reached ("Didn't reach end of arguments");
810 }
811 #endif
812
813 static void
814 verify_test_message (DBusMessage *message)
815 {
816 DBusMessageIter iter;
817 DBusError error = DBUS_ERROR_INIT;
818 dbus_int16_t our_int16;
819 dbus_uint16_t our_uint16;
820 dbus_int32_t our_int;
821 dbus_uint32_t our_uint;
822 const char *our_str;
823 double our_double;
824 double v_DOUBLE;
825 dbus_bool_t our_bool;
826 unsigned char our_byte_1, our_byte_2;
827 const dbus_uint32_t *our_uint32_array = (void*)0xdeadbeef;
828 int our_uint32_array_len;
829 dbus_int32_t *our_int32_array = (void*)0xdeadbeef;
830 int our_int32_array_len;
831 dbus_int64_t our_int64;
832 dbus_uint64_t our_uint64;
833 dbus_int64_t *our_uint64_array = (void*)0xdeadbeef;
834 int our_uint64_array_len;
835 const dbus_int64_t *our_int64_array = (void*)0xdeadbeef;
836 int our_int64_array_len;
837 const double *our_double_array = (void*)0xdeadbeef;
838 int our_double_array_len;
839 const unsigned char *our_byte_array = (void*)0xdeadbeef;
840 int our_byte_array_len;
841 const dbus_bool_t *our_boolean_array = (void*)0xdeadbeef;
842 int our_boolean_array_len;
843 char **our_string_array;
844 int our_string_array_len;
845
846 dbus_message_iter_init (message, &iter);
847
848 if (!dbus_message_iter_get_args (&iter, &error,
849 DBUS_TYPE_INT16, &our_int16,
850 DBUS_TYPE_UINT16, &our_uint16,
851 DBUS_TYPE_INT32, &our_int,
852 DBUS_TYPE_UINT32, &our_uint,
853 DBUS_TYPE_INT64, &our_int64,
854 DBUS_TYPE_UINT64, &our_uint64,
855 DBUS_TYPE_STRING, &our_str,
856 DBUS_TYPE_DOUBLE, &our_double,
857 DBUS_TYPE_BOOLEAN, &our_bool,
858 DBUS_TYPE_BYTE, &our_byte_1,
859 DBUS_TYPE_BYTE, &our_byte_2,
860 DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32,
861 &our_uint32_array, &our_uint32_array_len,
862 DBUS_TYPE_ARRAY, DBUS_TYPE_INT32,
863 &our_int32_array, &our_int32_array_len,
864 DBUS_TYPE_ARRAY, DBUS_TYPE_UINT64,
865 &our_uint64_array, &our_uint64_array_len,
866 DBUS_TYPE_ARRAY, DBUS_TYPE_INT64,
867 &our_int64_array, &our_int64_array_len,
868 DBUS_TYPE_ARRAY, DBUS_TYPE_DOUBLE,
869 &our_double_array, &our_double_array_len,
870 DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
871 &our_byte_array, &our_byte_array_len,
872 DBUS_TYPE_ARRAY, DBUS_TYPE_BOOLEAN,
873 &our_boolean_array, &our_boolean_array_len,
874 DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
875 &our_string_array, &our_string_array_len,
876 0))
877 {
878 _dbus_warn ("error: %s - %s\n", error.name,
879 (error.message != NULL) ? error.message : "no message");
880 _dbus_assert_not_reached ("Could not get arguments");
881 }
882
883 if (our_int16 != -0x123)
884 _dbus_assert_not_reached ("16-bit integers differ!");
885
886 if (our_uint16 != 0x123)
887 _dbus_assert_not_reached ("16-bit uints differ!");
888
889 if (our_int != -0x12345678)
890 _dbus_assert_not_reached ("integers differ!");
891
892 if (our_uint != 0x12300042)
893 _dbus_assert_not_reached ("uints differ!");
894
895 if (our_int64 != DBUS_INT64_CONSTANT (-0x123456789abcd))
896 _dbus_assert_not_reached ("64-bit integers differ!");
897 if (our_uint64 != DBUS_UINT64_CONSTANT (0x123456789abcd))
898 _dbus_assert_not_reached ("64-bit unsigned integers differ!");
899
900 v_DOUBLE = 3.14159;
901 if (! _DBUS_DOUBLES_BITWISE_EQUAL (our_double, v_DOUBLE))
902 _dbus_assert_not_reached ("doubles differ!");
903
904 if (strcmp (our_str, "Test string") != 0)
905 _dbus_assert_not_reached ("strings differ!");
906
907 if (!our_bool)
908 _dbus_assert_not_reached ("booleans differ");
909
910 if (our_byte_1 != 42)
911 _dbus_assert_not_reached ("bytes differ!");
912
913 if (our_byte_2 != 24)
914 _dbus_assert_not_reached ("bytes differ!");
915
916 if (our_uint32_array_len != 4 ||
917 our_uint32_array[0] != 0x12345678 ||
918 our_uint32_array[1] != 0x23456781 ||
919 our_uint32_array[2] != 0x34567812 ||
920 our_uint32_array[3] != 0x45678123)
921 _dbus_assert_not_reached ("uint array differs");
922
923 if (our_int32_array_len != 4 ||
924 our_int32_array[0] != 0x12345678 ||
925 our_int32_array[1] != -0x23456781 ||
926 our_int32_array[2] != 0x34567812 ||
927 our_int32_array[3] != -0x45678123)
928 _dbus_assert_not_reached ("int array differs");
929
930 if (our_uint64_array_len != 4 ||
931 our_uint64_array[0] != 0x12345678 ||
932 our_uint64_array[1] != 0x23456781 ||
933 our_uint64_array[2] != 0x34567812 ||
934 our_uint64_array[3] != 0x45678123)
935 _dbus_assert_not_reached ("uint64 array differs");
936
937 if (our_int64_array_len != 4 ||
938 our_int64_array[0] != 0x12345678 ||
939 our_int64_array[1] != -0x23456781 ||
940 our_int64_array[2] != 0x34567812 ||
941 our_int64_array[3] != -0x45678123)
942 _dbus_assert_not_reached ("int64 array differs");
943
944 if (our_double_array_len != 3)
945 _dbus_assert_not_reached ("double array had wrong length");
946
947 /* On all IEEE machines (i.e. everything sane) exact equality
948 * should be preserved over the wire
949 */
950 v_DOUBLE = 0.1234;
951 if (! _DBUS_DOUBLES_BITWISE_EQUAL (our_double_array[0], v_DOUBLE))
952 _dbus_assert_not_reached ("double array had wrong values");
953 v_DOUBLE = 9876.54321;
954 if (! _DBUS_DOUBLES_BITWISE_EQUAL (our_double_array[1], v_DOUBLE))
955 _dbus_assert_not_reached ("double array had wrong values");
956 v_DOUBLE = -300.0;
957 if (! _DBUS_DOUBLES_BITWISE_EQUAL (our_double_array[2], v_DOUBLE))
958 _dbus_assert_not_reached ("double array had wrong values");
959
960 if (our_byte_array_len != 4)
961 _dbus_assert_not_reached ("byte array had wrong length");
962
963 if (our_byte_array[0] != 'a' ||
964 our_byte_array[1] != 'b' ||
965 our_byte_array[2] != 'c' ||
966 our_byte_array[3] != 234)
967 _dbus_assert_not_reached ("byte array had wrong values");
968
969 if (our_boolean_array_len != 5)
970 _dbus_assert_not_reached ("bool array had wrong length");
971
972 if (our_boolean_array[0] != TRUE ||
973 our_boolean_array[1] != FALSE ||
974 our_boolean_array[2] != TRUE ||
975 our_boolean_array[3] != TRUE ||
976 our_boolean_array[4] != FALSE)
977 _dbus_assert_not_reached ("bool array had wrong values");
978
979 if (our_string_array_len != 4)
980 _dbus_assert_not_reached ("string array was wrong length");
981
982 if (strcmp (our_string_array[0], "Foo") != 0 ||
983 strcmp (our_string_array[1], "bar") != 0 ||
984 strcmp (our_string_array[2], "") != 0 ||
985 strcmp (our_string_array[3], "woo woo woo woo") != 0)
986 _dbus_assert_not_reached ("string array had wrong values");
987
988 dbus_free_string_array (our_string_array);
989
990 if (dbus_message_iter_next (&iter))
991 _dbus_assert_not_reached ("Didn't reach end of arguments");
992 }
993
994 static void
995 verify_test_message_args_ignored (DBusMessage *message)
996 {
997 DBusMessageIter iter;
998 DBusError error = DBUS_ERROR_INIT;
999 dbus_uint32_t our_uint;
1000 DBusInitialFDs *initial_fds;
1001
1002 initial_fds = _dbus_check_fdleaks_enter ();
1003
1004 /* parse with empty signature: "" */
1005 dbus_message_iter_init (message, &iter);
1006 if (!dbus_message_iter_get_args (&iter, &error,
1007 DBUS_TYPE_INVALID))
1008 {
1009 _dbus_warn ("error: %s - %s\n", error.name,
1010 (error.message != NULL) ? error.message : "no message");
1011 }
1012 else
1013 {
1014 _dbus_assert (!dbus_error_is_set (&error));
1015 _dbus_verbose ("arguments ignored.\n");
1016 }
1017
1018 /* parse with shorter signature: "u" */
1019 dbus_message_iter_init (message, &iter);
1020 if (!dbus_message_iter_get_args (&iter, &error,
1021 DBUS_TYPE_UINT32, &our_uint,
1022 DBUS_TYPE_INVALID))
1023 {
1024 _dbus_warn ("error: %s - %s\n", error.name,
1025 (error.message != NULL) ? error.message : "no message");
1026 }
1027 else
1028 {
1029 _dbus_assert (!dbus_error_is_set (&error));
1030 _dbus_verbose ("arguments ignored.\n");
1031 }
1032
1033 _dbus_check_fdleaks_leave (initial_fds);
1034 }
1035
1036 static void
1037 verify_test_message_memleak (DBusMessage *message)
1038 {
1039 DBusMessageIter iter;
1040 DBusError error = DBUS_ERROR_INIT;
1041 dbus_uint32_t our_uint1;
1042 dbus_uint32_t our_uint2;
1043 dbus_uint32_t our_uint3;
1044 char **our_string_array1;
1045 int our_string_array_len1;
1046 char **our_string_array2;
1047 int our_string_array_len2;
1048 #ifdef HAVE_UNIX_FD_PASSING
1049 int our_unix_fd1;
1050 int our_unix_fd2;
1051 #endif
1052 DBusInitialFDs *initial_fds;
1053
1054 initial_fds = _dbus_check_fdleaks_enter ();
1055
1056 /* parse with wrong signature: "uashuu" */
1057 dbus_error_free (&error);
1058 dbus_message_iter_init (message, &iter);
1059 if (!dbus_message_iter_get_args (&iter, &error,
1060 DBUS_TYPE_UINT32, &our_uint1,
1061 DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
1062 &our_string_array1, &our_string_array_len1,
1063 #ifdef HAVE_UNIX_FD_PASSING
1064 DBUS_TYPE_UNIX_FD, &our_unix_fd1,
1065 #endif
1066 DBUS_TYPE_UINT32, &our_uint2,
1067 DBUS_TYPE_UINT32, &our_uint3,
1068 DBUS_TYPE_INVALID))
1069 {
1070 _dbus_verbose ("expected error: %s - %s\n", error.name,
1071 (error.message != NULL) ? error.message : "no message");
1072 /* ensure array of string and unix fd not leaked */
1073 _dbus_assert (our_string_array1 == NULL);
1074 #ifdef HAVE_UNIX_FD_PASSING
1075 _dbus_assert (our_unix_fd1 == -1);
1076 #endif
1077 }
1078 else
1079 {
1080 _dbus_warn ("error: parse with wrong signature: 'uashuu'.\n");
1081 }
1082
1083 /* parse with wrong signature: "uashuashu" */
1084 dbus_message_iter_init (message, &iter);
1085 dbus_error_free (&error);
1086 if (!dbus_message_iter_get_args (&iter, &error,
1087 DBUS_TYPE_UINT32, &our_uint1,
1088 DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
1089 &our_string_array1, &our_string_array_len1,
1090 #ifdef HAVE_UNIX_FD_PASSING
1091 DBUS_TYPE_UNIX_FD, &our_unix_fd1,
1092 #endif
1093 DBUS_TYPE_UINT32, &our_uint2,
1094 DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
1095 &our_string_array2, &our_string_array_len2,
1096 #ifdef HAVE_UNIX_FD_PASSING
1097 DBUS_TYPE_UNIX_FD, &our_unix_fd2,
1098 #endif
1099 DBUS_TYPE_UINT32, &our_uint3,
1100 DBUS_TYPE_INVALID))
1101 {
1102 _dbus_verbose ("expected error: %s - %s\n", error.name,
1103 (error.message != NULL) ? error.message : "no message");
1104 /* ensure array of string and unix fd not leaked */
1105 _dbus_assert (our_string_array1 == NULL);
1106 _dbus_assert (our_string_array2 == NULL);
1107 #ifdef HAVE_UNIX_FD_PASSING
1108 _dbus_assert (our_unix_fd1 == -1);
1109 _dbus_assert (our_unix_fd2 == -1);
1110 #endif
1111 }
1112 else
1113 {
1114 _dbus_warn ("error: parse with wrong signature: 'uashuashu'.\n");
1115 }
1116
1117 /* parse with correct signature: "uashuash" */
1118 dbus_message_iter_init (message, &iter);
1119 dbus_error_free (&error);
1120 if (!dbus_message_iter_get_args (&iter, &error,
1121 DBUS_TYPE_UINT32, &our_uint1,
1122 DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
1123 &our_string_array1, &our_string_array_len1,
1124 #ifdef HAVE_UNIX_FD_PASSING
1125 DBUS_TYPE_UNIX_FD, &our_unix_fd1,
1126 #endif
1127 DBUS_TYPE_UINT32, &our_uint2,
1128 DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
1129 &our_string_array2, &our_string_array_len2,
1130 #ifdef HAVE_UNIX_FD_PASSING
1131 DBUS_TYPE_UNIX_FD, &our_unix_fd2,
1132 #endif
1133 DBUS_TYPE_INVALID))
1134 {
1135 _dbus_warn ("error: %s - %s\n", error.name,
1136 (error.message != NULL) ? error.message : "no message");
1137 _dbus_assert_not_reached ("Could not get arguments");
1138 }
1139 else
1140 {
1141 dbus_free_string_array (our_string_array1);
1142 dbus_free_string_array (our_string_array2);
1143 #ifdef HAVE_UNIX_FD_PASSING
1144 _dbus_close (our_unix_fd1, &error);
1145 _dbus_close (our_unix_fd2, &error);
1146 #endif
1147 }
1148 _dbus_check_fdleaks_leave (initial_fds);
1149 }
1150
1157 dbus_bool_t
1158 _dbus_message_test (const char *test_data_dir)
1159 {
1160 DBusMessage *message, *message_without_unix_fds;
1161 DBusMessageLoader *loader;
1162 int i;
1163 const char *data;
1164 DBusMessage *copy;
1165 const char *name1;
1166 const char *name2;
1167 const dbus_uint32_t our_uint32_array[] =
1168 { 0x12345678, 0x23456781, 0x34567812, 0x45678123 };
1169 const dbus_int32_t our_int32_array[] =
1170 { 0x12345678, -0x23456781, 0x34567812, -0x45678123 };
1171 const dbus_uint32_t *v_ARRAY_UINT32 = our_uint32_array;
1172 const dbus_int32_t *v_ARRAY_INT32 = our_int32_array;
1173 const dbus_uint64_t our_uint64_array[] =
1174 { 0x12345678, 0x23456781, 0x34567812, 0x45678123 };
1175 const dbus_int64_t our_int64_array[] =
1176 { 0x12345678, -0x23456781, 0x34567812, -0x45678123 };
1177 const dbus_uint64_t *v_ARRAY_UINT64 = our_uint64_array;
1178 const dbus_int64_t *v_ARRAY_INT64 = our_int64_array;
1179 const char *our_string_array[] = { "Foo", "bar", "", "woo woo woo woo" };
1180 const char *our_string_array1[] = { "foo", "Bar", "", "Woo woo Woo woo" };
1181 const char **v_ARRAY_STRING = our_string_array;
1182 const char **v1_ARRAY_STRING = our_string_array1;
1183 const double our_double_array[] = { 0.1234, 9876.54321, -300.0 };
1184 const double *v_ARRAY_DOUBLE = our_double_array;
1185 const unsigned char our_byte_array[] = { 'a', 'b', 'c', 234 };
1186 const unsigned char *v_ARRAY_BYTE = our_byte_array;
1187 const dbus_bool_t our_boolean_array[] = { TRUE, FALSE, TRUE, TRUE, FALSE };
1188 const dbus_bool_t *v_ARRAY_BOOLEAN = our_boolean_array;
1189 char sig[64];
1190 const char *s;
1191 const char *v_STRING;
1192 double v_DOUBLE;
1193 dbus_int16_t v_INT16;
1194 dbus_uint16_t v_UINT16;
1195 dbus_int32_t v_INT32;
1196 dbus_uint32_t v_UINT32;
1197 dbus_uint32_t v1_UINT32;
1198 dbus_int64_t v_INT64;
1199 dbus_uint64_t v_UINT64;
1200 unsigned char v_BYTE;
1201 unsigned char v2_BYTE;
1202 dbus_bool_t v_BOOLEAN;
1203 DBusMessageIter iter, array_iter, struct_iter;
1204 #ifdef HAVE_UNIX_FD_PASSING
1205 int v_UNIX_FD;
1206 int v1_UNIX_FD;
1207 #endif
1208 char **decomposed;
1209 DBusInitialFDs *initial_fds;
1210 dbus_bool_t ok;
1211 char basic_types[] = DBUS_TYPE_BYTE_AS_STRING \
1212 DBUS_TYPE_BOOLEAN_AS_STRING \
1213 DBUS_TYPE_INT16_AS_STRING \
1214 DBUS_TYPE_INT32_AS_STRING \
1215 DBUS_TYPE_INT64_AS_STRING \
1216 DBUS_TYPE_UINT16_AS_STRING \
1217 DBUS_TYPE_UINT32_AS_STRING \
1218 DBUS_TYPE_UINT64_AS_STRING \
1219 DBUS_TYPE_DOUBLE_AS_STRING \
1220 DBUS_TYPE_STRING_AS_STRING;
1221
1222 initial_fds = _dbus_check_fdleaks_enter ();
1223
1224 message = dbus_message_new_method_call ("org.freedesktop.DBus.TestService",
1225 "/org/freedesktop/TestPath",
1226 "Foo.TestInterface",
1227 "TestMethod");
1228 _dbus_assert (dbus_message_has_destination (message, "org.freedesktop.DBus.TestService"));
1229 _dbus_assert (dbus_message_is_method_call (message, "Foo.TestInterface",
1230 "TestMethod"));
1231 _dbus_assert (strcmp (dbus_message_get_path (message),
1232 "/org/freedesktop/TestPath") == 0);
1233 dbus_message_set_serial (message, 1234);
1234
1235 /* string length including nul byte not a multiple of 4 */
1236 if (!dbus_message_set_sender (message, "org.foo.bar1"))
1237 _dbus_assert_not_reached ("out of memory");
1238
1239 _dbus_assert (dbus_message_has_sender (message, "org.foo.bar1"));
1240 dbus_message_set_reply_serial (message, 5678);
1241
1242 _dbus_verbose_bytes_of_string (&message->header.data, 0,
1243 _dbus_string_get_length (&message->header.data));
1244 _dbus_verbose_bytes_of_string (&message->body, 0,
1245 _dbus_string_get_length (&message->body));
1246
1247 if (!dbus_message_set_sender (message, NULL))
1248 _dbus_assert_not_reached ("out of memory");
1249
1250
1251 _dbus_verbose_bytes_of_string (&message->header.data, 0,
1252 _dbus_string_get_length (&message->header.data));
1253 _dbus_verbose_bytes_of_string (&message->body, 0,
1254 _dbus_string_get_length (&message->body));
1255
1256
1257 _dbus_assert (!dbus_message_has_sender (message, "org.foo.bar1"));
1258 _dbus_assert (dbus_message_get_serial (message) == 1234);
1259 _dbus_assert (dbus_message_get_reply_serial (message) == 5678);
1260 _dbus_assert (dbus_message_has_destination (message, "org.freedesktop.DBus.TestService"));
1261
1262 _dbus_assert (dbus_message_get_no_reply (message) == FALSE);
1263 dbus_message_set_no_reply (message, TRUE);
1264 _dbus_assert (dbus_message_get_no_reply (message) == TRUE);
1265 dbus_message_set_no_reply (message, FALSE);
1266 _dbus_assert (dbus_message_get_no_reply (message) == FALSE);
1267
1268 /* Set/get some header fields */
1269
1270 if (!dbus_message_set_path (message, "/foo"))
1271 _dbus_assert_not_reached ("out of memory");
1272 _dbus_assert (strcmp (dbus_message_get_path (message),
1273 "/foo") == 0);
1274
1275 if (!dbus_message_set_interface (message, "org.Foo"))
1276 _dbus_assert_not_reached ("out of memory");
1277 _dbus_assert (strcmp (dbus_message_get_interface (message),
1278 "org.Foo") == 0);
1279
1280 if (!dbus_message_set_member (message, "Bar"))
1281 _dbus_assert_not_reached ("out of memory");
1282 _dbus_assert (strcmp (dbus_message_get_member (message),
1283 "Bar") == 0);
1284
1285 /* Set/get them with longer values */
1286 if (!dbus_message_set_path (message, "/foo/bar"))
1287 _dbus_assert_not_reached ("out of memory");
1288 _dbus_assert (strcmp (dbus_message_get_path (message),
1289 "/foo/bar") == 0);
1290
1291 if (!dbus_message_set_interface (message, "org.Foo.Bar"))
1292 _dbus_assert_not_reached ("out of memory");
1293 _dbus_assert (strcmp (dbus_message_get_interface (message),
1294 "org.Foo.Bar") == 0);
1295
1296 if (!dbus_message_set_member (message, "BarFoo"))
1297 _dbus_assert_not_reached ("out of memory");
1298 _dbus_assert (strcmp (dbus_message_get_member (message),
1299 "BarFoo") == 0);
1300
1301 /* Realloc shorter again */
1302
1303 if (!dbus_message_set_path (message, "/foo"))
1304 _dbus_assert_not_reached ("out of memory");
1305 _dbus_assert (strcmp (dbus_message_get_path (message),
1306 "/foo") == 0);
1307
1308 if (!dbus_message_set_interface (message, "org.Foo"))
1309 _dbus_assert_not_reached ("out of memory");
1310 _dbus_assert (strcmp (dbus_message_get_interface (message),
1311 "org.Foo") == 0);
1312
1313 if (!dbus_message_set_member (message, "Bar"))
1314 _dbus_assert_not_reached ("out of memory");
1315 _dbus_assert (strcmp (dbus_message_get_member (message),
1316 "Bar") == 0);
1317
1318 /* Path decomposing */
1319 dbus_message_set_path (message, NULL);
1320 dbus_message_get_path_decomposed (message, &decomposed);
1321 _dbus_assert (decomposed == NULL);
1322 dbus_free_string_array (decomposed);
1323
1324 dbus_message_set_path (message, "/");
1325 dbus_message_get_path_decomposed (message, &decomposed);
1326 _dbus_assert (decomposed != NULL);
1327 _dbus_assert (decomposed[0] == NULL);
1328 dbus_free_string_array (decomposed);
1329
1330 dbus_message_set_path (message, "/a/b");
1331 dbus_message_get_path_decomposed (message, &decomposed);
1332 _dbus_assert (decomposed != NULL);
1333 _dbus_assert (strcmp (decomposed[0], "a") == 0);
1334 _dbus_assert (strcmp (decomposed[1], "b") == 0);
1335 _dbus_assert (decomposed[2] == NULL);
1336 dbus_free_string_array (decomposed);
1337
1338 dbus_message_set_path (message, "/spam/eggs");
1339 dbus_message_get_path_decomposed (message, &decomposed);
1340 _dbus_assert (decomposed != NULL);
1341 _dbus_assert (strcmp (decomposed[0], "spam") == 0);
1342 _dbus_assert (strcmp (decomposed[1], "eggs") == 0);
1343 _dbus_assert (decomposed[2] == NULL);
1344 dbus_free_string_array (decomposed);
1345
1346 dbus_message_unref (message);
1347
1348 /* Test the vararg functions */
1349 message = dbus_message_new_method_call ("org.freedesktop.DBus.TestService",
1350 "/org/freedesktop/TestPath",
1351 "Foo.TestInterface",
1352 "TestMethod");
1353 dbus_message_set_serial (message, 1);
1354 dbus_message_set_reply_serial (message, 5678);
1355
1356 v_INT16 = -0x123;
1357 v_UINT16 = 0x123;
1358 v_INT32 = -0x12345678;
1359 v_UINT32 = 0x12300042;
1360 v_INT64 = DBUS_INT64_CONSTANT (-0x123456789abcd);
1361 v_UINT64 = DBUS_UINT64_CONSTANT (0x123456789abcd);
1362 v_STRING = "Test string";
1363 v_DOUBLE = 3.14159;
1364 v_BOOLEAN = TRUE;
1365 v_BYTE = 42;
1366 v2_BYTE = 24;
1367 #ifdef HAVE_UNIX_FD_PASSING
1368 v_UNIX_FD = 1;
1369 v1_UNIX_FD = 2;
1370 #endif
1371
1372 dbus_message_append_args (message,
1373 DBUS_TYPE_INT16, &v_INT16,
1374 DBUS_TYPE_UINT16, &v_UINT16,
1375 DBUS_TYPE_INT32, &v_INT32,
1376 DBUS_TYPE_UINT32, &v_UINT32,
1377 DBUS_TYPE_INT64, &v_INT64,
1378 DBUS_TYPE_UINT64, &v_UINT64,
1379 DBUS_TYPE_STRING, &v_STRING,
1380 DBUS_TYPE_DOUBLE, &v_DOUBLE,
1381 DBUS_TYPE_BOOLEAN, &v_BOOLEAN,
1382 DBUS_TYPE_BYTE, &v_BYTE,
1383 DBUS_TYPE_BYTE, &v2_BYTE,
1384 DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &v_ARRAY_UINT32,
1385 _DBUS_N_ELEMENTS (our_uint32_array),
1386 DBUS_TYPE_ARRAY, DBUS_TYPE_INT32, &v_ARRAY_INT32,
1387 _DBUS_N_ELEMENTS (our_int32_array),
1388 DBUS_TYPE_ARRAY, DBUS_TYPE_UINT64, &v_ARRAY_UINT64,
1389 _DBUS_N_ELEMENTS (our_uint64_array),
1390 DBUS_TYPE_ARRAY, DBUS_TYPE_INT64, &v_ARRAY_INT64,
1391 _DBUS_N_ELEMENTS (our_int64_array),
1392 DBUS_TYPE_ARRAY, DBUS_TYPE_DOUBLE, &v_ARRAY_DOUBLE,
1393 _DBUS_N_ELEMENTS (our_double_array),
1394 DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &v_ARRAY_BYTE,
1395 _DBUS_N_ELEMENTS (our_byte_array),
1396 DBUS_TYPE_ARRAY, DBUS_TYPE_BOOLEAN, &v_ARRAY_BOOLEAN,
1397 _DBUS_N_ELEMENTS (our_boolean_array),
1398 DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &v_ARRAY_STRING,
1399 _DBUS_N_ELEMENTS (our_string_array),
1400
1401 DBUS_TYPE_INVALID);
1402
1403 i = 0;
1404 sig[i++] = DBUS_TYPE_INT16;
1405 sig[i++] = DBUS_TYPE_UINT16;
1406 sig[i++] = DBUS_TYPE_INT32;
1407 sig[i++] = DBUS_TYPE_UINT32;
1408 sig[i++] = DBUS_TYPE_INT64;
1409 sig[i++] = DBUS_TYPE_UINT64;
1410 sig[i++] = DBUS_TYPE_STRING;
1411 sig[i++] = DBUS_TYPE_DOUBLE;
1412 sig[i++] = DBUS_TYPE_BOOLEAN;
1413 sig[i++] = DBUS_TYPE_BYTE;
1414 sig[i++] = DBUS_TYPE_BYTE;
1415 sig[i++] = DBUS_TYPE_ARRAY;
1416 sig[i++] = DBUS_TYPE_UINT32;
1417 sig[i++] = DBUS_TYPE_ARRAY;
1418 sig[i++] = DBUS_TYPE_INT32;
1419 sig[i++] = DBUS_TYPE_ARRAY;
1420 sig[i++] = DBUS_TYPE_UINT64;
1421 sig[i++] = DBUS_TYPE_ARRAY;
1422 sig[i++] = DBUS_TYPE_INT64;
1423 sig[i++] = DBUS_TYPE_ARRAY;
1424 sig[i++] = DBUS_TYPE_DOUBLE;
1425 sig[i++] = DBUS_TYPE_ARRAY;
1426 sig[i++] = DBUS_TYPE_BYTE;
1427 sig[i++] = DBUS_TYPE_ARRAY;
1428 sig[i++] = DBUS_TYPE_BOOLEAN;
1429 sig[i++] = DBUS_TYPE_ARRAY;
1430 sig[i++] = DBUS_TYPE_STRING;
1431
1432 message_without_unix_fds = dbus_message_copy(message);
1433 _dbus_assert(message_without_unix_fds);
1434 #ifdef HAVE_UNIX_FD_PASSING
1435 dbus_message_append_args (message,
1436 DBUS_TYPE_UNIX_FD, &v_UNIX_FD,
1437 DBUS_TYPE_INVALID);
1438 sig[i++] = DBUS_TYPE_UNIX_FD;
1439 #endif
1440 sig[i++] = DBUS_TYPE_INVALID;
1441
1442 _dbus_assert (i < (int) _DBUS_N_ELEMENTS (sig));
1443
1444 _dbus_verbose ("HEADER\n");
1445 _dbus_verbose_bytes_of_string (&message->header.data, 0,
1446 _dbus_string_get_length (&message->header.data));
1447 _dbus_verbose ("BODY\n");
1448 _dbus_verbose_bytes_of_string (&message->body, 0,
1449 _dbus_string_get_length (&message->body));
1450
1451 _dbus_verbose ("Signature expected \"%s\" actual \"%s\"\n",
1452 sig, dbus_message_get_signature (message));
1453
1454 s = dbus_message_get_signature (message);
1455
1456 _dbus_assert (dbus_message_has_signature (message, sig));
1457 _dbus_assert (strcmp (s, sig) == 0);
1458
1459 verify_test_message (message);
1460
1461 copy = dbus_message_copy (message);
1462
1463 _dbus_assert (dbus_message_get_reply_serial (message) ==
1464 dbus_message_get_reply_serial (copy));
1465 _dbus_assert (message->header.padding == copy->header.padding);
1466
1467 _dbus_assert (_dbus_string_get_length (&message->header.data) ==
1468 _dbus_string_get_length (&copy->header.data));
1469
1470 _dbus_assert (_dbus_string_get_length (&message->body) ==
1471 _dbus_string_get_length (&copy->body));
1472
1473 verify_test_message (copy);
1474
1475 name1 = dbus_message_get_interface (message);
1476 name2 = dbus_message_get_interface (copy);
1477
1478 _dbus_assert (strcmp (name1, name2) == 0);
1479
1480 name1 = dbus_message_get_member (message);
1481 name2 = dbus_message_get_member (copy);
1482
1483 _dbus_assert (strcmp (name1, name2) == 0);
1484
1485 dbus_message_unref (copy);
1486
1487 /* Message loader test */
1488 dbus_message_lock (message);
1489 loader = _dbus_message_loader_new ();
1490
1491 /* check ref/unref */
1492 _dbus_message_loader_ref (loader);
1493 _dbus_message_loader_unref (loader);
1494
1495 /* Write the header data one byte at a time */
1496 data = _dbus_string_get_const_data (&message->header.data);
1497 for (i = 0; i < _dbus_string_get_length (&message->header.data); i++)
1498 {
1499 DBusString *buffer;
1500
1501 _dbus_message_loader_get_buffer (loader, &buffer);
1502 _dbus_string_append_byte (buffer, data[i]);
1503 _dbus_message_loader_return_buffer (loader, buffer);
1504 }
1505
1506 /* Write the body data one byte at a time */
1507 data = _dbus_string_get_const_data (&message->body);
1508 for (i = 0; i < _dbus_string_get_length (&message->body); i++)
1509 {
1510 DBusString *buffer;
1511
1512 _dbus_message_loader_get_buffer (loader, &buffer);
1513 _dbus_string_append_byte (buffer, data[i]);
1514 _dbus_message_loader_return_buffer (loader, buffer);
1515 }
1516
1517 #ifdef HAVE_UNIX_FD_PASSING
1518 {
1519 int *unix_fds;
1520 unsigned n_unix_fds;
1521 /* Write unix fd */
1522 _dbus_message_loader_get_unix_fds(loader, &unix_fds, &n_unix_fds);
1523 _dbus_assert(n_unix_fds > 0);
1524 _dbus_assert(message->n_unix_fds == 1);
1525 unix_fds[0] = _dbus_dup(message->unix_fds[0], NULL);
1526 _dbus_assert(unix_fds[0] >= 0);
1527 _dbus_message_loader_return_unix_fds(loader, unix_fds, 1);
1528 }
1529 #endif
1530
1531 dbus_message_unref (message);
1532
1533 /* Now pop back the message */
1534 if (!_dbus_message_loader_queue_messages (loader))
1535 _dbus_assert_not_reached ("no memory to queue messages");
1536
1537 if (_dbus_message_loader_get_is_corrupted (loader))
1538 _dbus_assert_not_reached ("message loader corrupted");
1539
1540 message = _dbus_message_loader_pop_message (loader);
1541 if (!message)
1542 _dbus_assert_not_reached ("received a NULL message");
1543
1544 if (dbus_message_get_reply_serial (message) != 5678)
1545 _dbus_assert_not_reached ("reply serial fields differ");
1546
1547 dbus_message_unref (message);
1548
1549 /* ovveride the serial, since it was reset by dbus_message_copy() */
1550 dbus_message_set_serial(message_without_unix_fds, 8901);
1551
1552 dbus_message_lock (message_without_unix_fds);
1553
1554 verify_test_message (message_without_unix_fds);
1555
1556 {
1557 /* Marshal and demarshal the message. */
1558
1559 DBusMessage *message2;
1560 DBusError error = DBUS_ERROR_INIT;
1561 char *marshalled = NULL;
1562 int len = 0;
1563 char garbage_header[DBUS_MINIMUM_HEADER_SIZE] = "xxx";
1564
1565 if (!dbus_message_marshal (message_without_unix_fds, &marshalled, &len))
1566 _dbus_assert_not_reached ("failed to marshal message");
1567
1568 _dbus_assert (len != 0);
1569 _dbus_assert (marshalled != NULL);
1570
1571 _dbus_assert (dbus_message_demarshal_bytes_needed (marshalled, len) == len);
1572 message2 = dbus_message_demarshal (marshalled, len, &error);
1573
1574 _dbus_assert (message2 != NULL);
1575 _dbus_assert (!dbus_error_is_set (&error));
1576 verify_test_message (message2);
1577
1578 dbus_message_unref (message2);
1579 dbus_free (marshalled);
1580
1581 /* Demarshal invalid message. */
1582
1583 message2 = dbus_message_demarshal ("invalid", 7, &error);
1584 _dbus_assert (message2 == NULL);
1585 _dbus_assert (dbus_error_is_set (&error));
1586 dbus_error_free (&error);
1587
1588 /* Demarshal invalid (empty) message. */
1589
1590 message2 = dbus_message_demarshal ("", 0, &error);
1591 _dbus_assert (message2 == NULL);
1592 _dbus_assert (dbus_error_is_set (&error));
1593 dbus_error_free (&error);
1594
1595 /* Bytes needed to demarshal empty message: 0 (more) */
1596
1597 _dbus_assert (dbus_message_demarshal_bytes_needed ("", 0) == 0);
1598
1599 /* Bytes needed to demarshal invalid message: -1 (error). */
1600
1601 _dbus_assert (dbus_message_demarshal_bytes_needed (garbage_header, DBUS_MINIMUM_HEADER_SIZE) == -1);
1602 }
1603
1604 dbus_message_unref (message_without_unix_fds);
1605 _dbus_message_loader_unref (loader);
1606
1607 check_memleaks ();
1608 _dbus_check_fdleaks_leave (initial_fds);
1609 initial_fds = _dbus_check_fdleaks_enter ();
1610
1611 /* Test enumeration of array elements */
1612 for (i = strlen (basic_types) - 1; i > 0; i--)
1613 {
1614 DBusBasicValue val;
1615 int some;
1616 char* signature = _dbus_strdup ("?");
1617
1618 signature[0] = basic_types[i];
1619 s = "SomeThingToSay";
1620 memset (&val, '\0', sizeof (val));
1621
1622 message = dbus_message_new_method_call ("de.ende.test",
1623 "/de/ende/test", "de.ende.Test", "ArtistName");
1624 _dbus_assert (message != NULL);
1625 dbus_message_iter_init_append (message, &iter);
1626 dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY,
1627 signature, &array_iter);
1628 for (some = 0; some < 3; some++)
1629 {
1630 if (basic_types[i] == DBUS_TYPE_STRING)
1631 dbus_message_iter_append_basic (&array_iter, DBUS_TYPE_STRING, &s);
1632 else
1633 dbus_message_iter_append_basic (&array_iter, basic_types[i], &val);
1634 }
1635 dbus_message_iter_close_container (&iter, &array_iter);
1636 dbus_message_iter_init (message, &iter);
1637 _dbus_assert (dbus_message_iter_get_element_count (&iter) == some);
1638 dbus_message_unref (message);
1639 dbus_free (signature);
1640 }
1641 /* Array of structs */
1642 message = dbus_message_new_method_call ("de.ende.test",
1643 "/de/ende/test", "de.ende.Test", "ArtistName");
1644 _dbus_assert (message != NULL);
1645 dbus_message_iter_init_append (message, &iter);
1646 dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY,
1647 DBUS_STRUCT_BEGIN_CHAR_AS_STRING
1648 DBUS_TYPE_STRING_AS_STRING
1649 DBUS_STRUCT_END_CHAR_AS_STRING, &array_iter);
1650 dbus_message_iter_open_container (&array_iter, DBUS_TYPE_STRUCT,
1651 NULL, &struct_iter);
1652 s = "SpamAndEggs";
1653 dbus_message_iter_append_basic (&struct_iter, DBUS_TYPE_STRING, &s);
1654 dbus_message_iter_close_container (&array_iter, &struct_iter);
1655 dbus_message_iter_close_container (&iter, &array_iter);
1656 dbus_message_iter_init (message, &iter);
1657 _dbus_assert (dbus_message_iter_get_element_count (&iter) == 1);
1658 dbus_message_unref (message);
1659 check_memleaks ();
1660
1661 /* Check that we can abandon a container */
1662 message = dbus_message_new_method_call ("org.freedesktop.DBus.TestService",
1663 "/org/freedesktop/TestPath",
1664 "Foo.TestInterface",
1665 "Method");
1666
1667 dbus_message_iter_init_append (message, &iter);
1668
1669 ok = dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY,
1670 (DBUS_STRUCT_BEGIN_CHAR_AS_STRING
1671 DBUS_TYPE_STRING_AS_STRING
1672 DBUS_TYPE_STRING_AS_STRING
1673 DBUS_STRUCT_END_CHAR_AS_STRING),
1674 &array_iter);
1675 _dbus_assert (ok);
1676 ok = dbus_message_iter_open_container (&array_iter, DBUS_TYPE_STRUCT,
1677 NULL, &struct_iter);
1678 _dbus_assert (ok);
1679 s = "peaches";
1680 ok = dbus_message_iter_append_basic (&struct_iter, DBUS_TYPE_STRING, &s);
1681 _dbus_assert (ok);
1682
1683 /* uh-oh, error, try and unwind */
1684
1685 dbus_message_iter_abandon_container (&array_iter, &struct_iter);
1686 dbus_message_iter_abandon_container (&array_iter, &iter);
1687
1688 dbus_message_unref (message);
1689
1690 /* Check we should not leak array of string or unix fd, fd.o#21259 */
1691 message = dbus_message_new_method_call ("org.freedesktop.DBus.TestService",
1692 "/org/freedesktop/TestPath",
1693 "Foo.TestInterface",
1694 "Method");
1695
1696 /* signature "uashuash" */
1697 dbus_message_append_args (message,
1698 DBUS_TYPE_UINT32, &v_UINT32,
1699 DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &v_ARRAY_STRING,
1700 _DBUS_N_ELEMENTS (our_string_array),
1701 #ifdef HAVE_UNIX_FD_PASSING
1702 DBUS_TYPE_UNIX_FD, &v_UNIX_FD,
1703 #endif
1704 DBUS_TYPE_UINT32, &v1_UINT32,
1705 DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &v1_ARRAY_STRING,
1706 _DBUS_N_ELEMENTS (our_string_array1),
1707 #ifdef HAVE_UNIX_FD_PASSING
1708 DBUS_TYPE_UNIX_FD, &v1_UNIX_FD,
1709 #endif
1710
1711 DBUS_TYPE_INVALID);
1712
1713 i = 0;
1714 sig[i++] = DBUS_TYPE_UINT32;
1715 sig[i++] = DBUS_TYPE_ARRAY;
1716 sig[i++] = DBUS_TYPE_STRING;
1717 #ifdef HAVE_UNIX_FD_PASSING
1718 sig[i++] = DBUS_TYPE_UNIX_FD;
1719 #endif
1720 sig[i++] = DBUS_TYPE_UINT32;
1721 sig[i++] = DBUS_TYPE_ARRAY;
1722 sig[i++] = DBUS_TYPE_STRING;
1723 #ifdef HAVE_UNIX_FD_PASSING
1724 sig[i++] = DBUS_TYPE_UNIX_FD;
1725 #endif
1726 sig[i++] = DBUS_TYPE_INVALID;
1727
1728 _dbus_assert (i < (int) _DBUS_N_ELEMENTS (sig));
1729
1730 verify_test_message_args_ignored (message);
1731 verify_test_message_memleak (message);
1732
1733 dbus_message_unref (message);
1734
1735 /* Load all the sample messages from the message factory */
1736 {
1737 DBusMessageDataIter diter;
1738 DBusMessageData mdata;
1739 int count;
1740
1741 reset_validities_seen ();
1742
1743 count = 0;
1744 _dbus_message_data_iter_init (&diter);
1745
1746 while (_dbus_message_data_iter_get_and_next (&diter,
1747 &mdata))
1748 {
1749 if (!dbus_internal_do_not_use_try_message_data (&mdata.data,
1750 mdata.expected_validity))
1751 {
1752 _dbus_warn ("expected validity %d and did not get it\n",
1753 mdata.expected_validity);
1754 _dbus_assert_not_reached ("message data failed");
1755 }
1756
1757 _dbus_message_data_free (&mdata);
1758
1759 count += 1;
1760 }
1761
1762 printf ("%d sample messages tested\n", count);
1763
1764 print_validities_seen (FALSE);
1765 print_validities_seen (TRUE);
1766 }
1767
1768 check_memleaks ();
1769 _dbus_check_fdleaks_leave (initial_fds);
1770
1771 /* Now load every message in test_data_dir if we have one */
1772 if (test_data_dir == NULL)
1773 return TRUE;
1774
1775 initial_fds = _dbus_check_fdleaks_enter ();
1776
1777 if (!dbus_internal_do_not_use_foreach_message_file (test_data_dir,
1778 (DBusForeachMessageFileFunc)
1779 dbus_internal_do_not_use_try_message_file,
1780 NULL))
1781 _dbus_assert_not_reached ("foreach_message_file test failed");
1782
1783 _dbus_check_fdleaks_leave (initial_fds);
1784
1785 return TRUE;
1786 }
1787
1788 #endif /* DBUS_ENABLE_EMBEDDED_TESTS */
dbus_uint32_t
unsigned int dbus_uint32_t
A 32-bit unsigned integer on all platforms.
Definition: dbus-arch-deps.h:43
DBUS_TYPE_UINT16
#define DBUS_TYPE_UINT16
Type code marking a 16-bit unsigned integer.
Definition: dbus-protocol.h:78
dbus_message_lock
void dbus_message_lock(DBusMessage *message)
Locks a message.
Definition: dbus-message.c:407
DBusError::message
const char * message
public error message field
Definition: dbus-errors.h:51
NULL
#define NULL
A null pointer, defined appropriately for C or C++.
dbus_message_is_method_call
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.
Definition: dbus-message.c:3679
_dbus_message_loader_get_max_message_size
DBUS_PRIVATE_EXPORT long _dbus_message_loader_get_max_message_size(DBusMessageLoader *loader)
Gets the maximum allowed message size in bytes.
Definition: dbus-message.c:4549
dbus_message_set_no_reply
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.
Definition: dbus-message.c:3061
dbus_message_iter_get_arg_type
int dbus_message_iter_get_arg_type(DBusMessageIter *iter)
Returns the argument type of the argument that the message iterator points to.
Definition: dbus-message.c:2180
_dbus_message_loader_return_buffer
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...
Definition: dbus-message.c:4059
dbus_free
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
Definition: dbus-memory.c:701
_dbus_message_loader_return_unix_fds
DBUS_PRIVATE_EXPORT void _dbus_message_loader_return_unix_fds(DBusMessageLoader *loader, int *fds, unsigned n_fds)
Returns a buffer obtained from _dbus_message_loader_get_unix_fds().
Definition: dbus-message.c:4128
dbus_message_get_serial
dbus_uint32_t dbus_message_get_serial(DBusMessage *message)
Returns the serial of a message or 0 if none has been specified.
Definition: dbus-message.c:1150
DBUS_STRUCT_BEGIN_CHAR_AS_STRING
#define DBUS_STRUCT_BEGIN_CHAR_AS_STRING
DBUS_STRUCT_BEGIN_CHAR as a string literal instead of a int literal
Definition: dbus-protocol.h:158
dbus_message_iter_recurse
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...
Definition: dbus-message.c:2236
_dbus_message_loader_pop_message
DBUS_PRIVATE_EXPORT DBusMessage * _dbus_message_loader_pop_message(DBusMessageLoader *loader)
Pops a loaded message (passing ownership of the message to the caller).
Definition: dbus-message.c:4459
dbus_message_set_interface
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...
Definition: dbus-message.c:3275
dbus_message_iter_close_container
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...
Definition: dbus-message.c:2995
DBUS_TYPE_STRUCT
#define DBUS_TYPE_STRUCT
STRUCT and DICT_ENTRY are sort of special since their codes can&#39;t appear in a type string...
Definition: dbus-protocol.h:136
_dbus_directory_close
void _dbus_directory_close(DBusDirIter *iter)
Closes a directory iteration.
Definition: dbus-sysdeps-util-unix.c:850
DBusHeader::padding
dbus_uint32_t padding
bytes of alignment in header
Definition: dbus-marshal-header.h:58
_dbus_message_iter_get_args_valist
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
DBUS_TYPE_STRING
#define DBUS_TYPE_STRING
Type code marking a UTF-8 encoded, nul-terminated Unicode string.
Definition: dbus-protocol.h:102
DBusMessage::body
DBusString body
Body network data.
Definition: dbus-message-private.h:105
_dbus_assert
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
Definition: dbus-internals.h:148
_dbus_directory_get_next_file
dbus_bool_t _dbus_directory_get_next_file(DBusDirIter *iter, DBusString *filename, DBusError *error)
Get next file in the directory.
Definition: dbus-sysdeps-util-unix.c:802
DBUS_ERROR_INIT
#define DBUS_ERROR_INIT
Expands to a suitable initializer for a DBusError on the stack.
Definition: dbus-errors.h:62
dbus_message_get_signature
const char * dbus_message_get_signature(DBusMessage *message)
Gets the type signature of the message, i.e.
Definition: dbus-message.c:3620
dbus_message_iter_init_append
void dbus_message_iter_init_append(DBusMessage *message, DBusMessageIter *iter)
Initializes a DBusMessageIter for appending arguments to the end of a message.
Definition: dbus-message.c:2498
dbus_error_free
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
DBUS_TYPE_BYTE
#define DBUS_TYPE_BYTE
Type code marking an 8-bit unsigned integer.
Definition: dbus-protocol.h:66
_dbus_file_get_contents
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.
Definition: dbus-file-unix.c:55
_dbus_message_loader_unref
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...
Definition: dbus-message.c:4002
DBusHeader::data
DBusString data
Header network data, stored separately from body so we can independently realloc it.
Definition: dbus-marshal-header.h:49
_dbus_concat_dir_and_file
dbus_bool_t _dbus_concat_dir_and_file(DBusString *dir, const DBusString *next_component)
Appends the given filename to the given directory.
Definition: dbus-sysdeps-unix.c:3019
dbus_message_get_path
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...
Definition: dbus-message.c:3173
_dbus_directory_open
DBusDirIter * _dbus_directory_open(const DBusString *filename, DBusError *error)
Open a directory to iterate over.
Definition: dbus-sysdeps-util-unix.c:754
_dbus_string_init
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
Definition: dbus-string.c:175
_dbus_dup
int _dbus_dup(int fd, DBusError *error)
Duplicates a file descriptor.
Definition: dbus-sysdeps-unix.c:3241
_dbus_string_copy
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
DBusValidity
This is primarily used in unit testing, so we can verify that each invalid message is invalid for the...
Definition: dbus-marshal-validate.h:49
DBusMessageIter
DBusMessageIter struct; contains no public fields.
Definition: dbus-message.h:51
DBUS_TYPE_DOUBLE
#define DBUS_TYPE_DOUBLE
Type code marking an 8-byte double in IEEE 754 format.
Definition: dbus-protocol.h:98
dbus_message_iter_init
dbus_bool_t dbus_message_iter_init(DBusMessage *message, DBusMessageIter *iter)
Initializes a DBusMessageIter for reading the arguments of the message passed in. ...
Definition: dbus-message.c:2105
_dbus_string_ends_with_c_str
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.
Definition: dbus-string-util.c:46
DBUS_TYPE_ARRAY
#define DBUS_TYPE_ARRAY
Type code marking a D-Bus array type.
Definition: dbus-protocol.h:120
DBUS_TYPE_INT64
#define DBUS_TYPE_INT64
Type code marking a 64-bit signed integer.
Definition: dbus-protocol.h:90
DBusDirIter
Internals of directory iterator.
Definition: dbus-sysdeps-util-unix.c:740
dbus_message_get_member
const char * dbus_message_get_member(DBusMessage *message)
Gets the interface member being invoked (DBUS_MESSAGE_TYPE_METHOD_CALL) or emitted (DBUS_MESSAGE_TYPE...
Definition: dbus-message.c:3390
DBusMessage
Internals of DBusMessage.
Definition: dbus-message-private.h:99
DBusString
Definition: dbus-string.h:42
DBUS_MINIMUM_HEADER_SIZE
#define DBUS_MINIMUM_HEADER_SIZE
The smallest header size that can occur.
Definition: dbus-protocol.h:346
dbus_bool_t
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
Definition: dbus-types.h:35
_dbus_string_init_const
void _dbus_string_init_const(DBusString *str, const char *value)
Initializes a constant string.
Definition: dbus-string.c:190
DBusMessage::header
DBusHeader header
Header network data and associated cache.
Definition: dbus-message-private.h:103
dbus_message_set_sender
dbus_bool_t dbus_message_set_sender(DBusMessage *message, const char *sender)
Sets the message sender.
Definition: dbus-message.c:3556
DBusMessageLoader::data
DBusString data
Buffered data.
Definition: dbus-message-private.h:64
dbus_uint64_t
_DBUS_GNUC_EXTENSION typedef unsigned long long dbus_uint64_t
A 64-bit unsigned integer.
Definition: dbus-arch-deps.h:37
_dbus_message_loader_ref
DBUS_PRIVATE_EXPORT DBusMessageLoader * _dbus_message_loader_ref(DBusMessageLoader *loader)
Increments the reference count of the loader.
Definition: dbus-message.c:3988
dbus_message_get_path_decomposed
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...
Definition: dbus-message.c:3241
_dbus_warn
void _dbus_warn(const char *format,...)
Prints a warning message to stderr.
Definition: dbus-internals.c:230
dbus_message_set_path
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...
Definition: dbus-message.c:3144
DBUS_TYPE_INT32
#define DBUS_TYPE_INT32
Type code marking a 32-bit signed integer.
Definition: dbus-protocol.h:82
_dbus_message_loader_new
DBUS_PRIVATE_EXPORT DBusMessageLoader * _dbus_message_loader_new(void)
Creates a new message loader.
Definition: dbus-message.c:3940
DBusError
Object representing an exception.
Definition: dbus-errors.h:48
dbus_int64_t
_DBUS_GNUC_EXTENSION typedef long long dbus_int64_t
A 64-bit signed integer.
Definition: dbus-arch-deps.h:36
dbus_message_iter_get_element_count
int dbus_message_iter_get_element_count(DBusMessageIter *iter)
Returns the number of elements in the array-typed value pointed to by the iterator.
Definition: dbus-message.c:2379
dbus_message_append_args
dbus_bool_t dbus_message_append_args(DBusMessage *message, int first_arg_type,...)
Appends fields to a message given a variable argument list.
Definition: dbus-message.c:1819
DBUS_TYPE_UINT64
#define DBUS_TYPE_UINT64
Type code marking a 64-bit unsigned integer.
Definition: dbus-protocol.h:94
dbus_message_get_reply_serial
dbus_uint32_t dbus_message_get_reply_serial(DBusMessage *message)
Returns the serial that the message is a reply to or 0 if none.
Definition: dbus-message.c:1190
dbus_message_has_signature
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...
Definition: dbus-message.c:3831
_dbus_message_loader_get_is_corrupted
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_message_loader_get_is_corrupted(DBusMessageLoader *loader)
Checks whether the loader is confused due to bad data.
Definition: dbus-message.c:4501
_DBUS_N_ELEMENTS
#define _DBUS_N_ELEMENTS(array)
Computes the number of elements in a fixed-size array using sizeof().
Definition: dbus-internals.h:189
DBUS_TYPE_UINT32
#define DBUS_TYPE_UINT32
Type code marking a 32-bit unsigned integer.
Definition: dbus-protocol.h:86
DBUS_VALID
the data is valid
Definition: dbus-marshal-validate.h:56
dbus_message_new_method_call
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.
Definition: dbus-message.c:1360
dbus_message_has_destination
dbus_bool_t dbus_message_has_destination(DBusMessage *message, const char *name)
Checks whether the message was sent to the given name.
Definition: dbus-message.c:3767
dbus_int16_t
short dbus_int16_t
A 16-bit signed integer on all platforms.
Definition: dbus-arch-deps.h:45
_dbus_string_append_byte
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
_dbus_string_free
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init().
Definition: dbus-string.c:259
TRUE
#define TRUE
Expands to "1".
dbus_message_marshal
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.
Definition: dbus-message.c:4798
_dbus_assert_not_reached
#define _dbus_assert_not_reached(explanation)
Aborts with an error message if called.
Definition: dbus-internals.h:159
dbus_message_copy
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 ...
Definition: dbus-message.c:1614
dbus_message_iter_get_element_type
int dbus_message_iter_get_element_type(DBusMessageIter *iter)
Returns the element type of the array that the message iterator points to.
Definition: dbus-message.c:2199
DBusError::name
const char * name
public error name field
Definition: dbus-errors.h:50
dbus_message_demarshal
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.
Definition: dbus-message.c:4860
DBUS_TYPE_UNIX_FD
#define DBUS_TYPE_UNIX_FD
Type code marking a unix file descriptor.
Definition: dbus-protocol.h:114
dbus_message_get_interface
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...
Definition: dbus-message.c:3304
DBUS_TYPE_INVALID
#define DBUS_TYPE_INVALID
Type code that is never equal to a legitimate type code.
Definition: dbus-protocol.h:60
dbus_message_set_reply_serial
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).
Definition: dbus-message.c:1166
dbus_message_has_sender
dbus_bool_t dbus_message_has_sender(DBusMessage *message, const char *name)
Checks whether the message has the given unique name as its sender.
Definition: dbus-message.c:3802
dbus_message_iter_next
dbus_bool_t dbus_message_iter_next(DBusMessageIter *iter)
Moves the iterator to the next field, if any.
Definition: dbus-message.c:2155
DBUS_INT64_CONSTANT
#define DBUS_INT64_CONSTANT(val)
Declare a 64-bit signed integer constant.
dbus_message_get_no_reply
dbus_bool_t dbus_message_get_no_reply(DBusMessage *message)
Returns TRUE if the message does not expect a reply.
Definition: dbus-message.c:3080
DBUS_TYPE_INT16
#define DBUS_TYPE_INT16
Type code marking a 16-bit signed integer.
Definition: dbus-protocol.h:74
_dbus_message_loader_get_unix_fds
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_message_loader_get_unix_fds(DBusMessageLoader *loader, int **fds, unsigned *max_n_fds)
Gets the buffer to use for reading unix fds from the network.
Definition: dbus-message.c:4079
dbus_free_string_array
void dbus_free_string_array(char **str_array)
Frees a NULL-terminated array of strings.
Definition: dbus-memory.c:749
DBUS_TYPE_BOOLEAN
#define DBUS_TYPE_BOOLEAN
Type code marking a boolean.
Definition: dbus-protocol.h:70
_dbus_message_loader_get_buffer
DBUS_PRIVATE_EXPORT void _dbus_message_loader_get_buffer(DBusMessageLoader *loader, DBusString **buffer)
Gets the buffer to use for reading data from the network.
Definition: dbus-message.c:4039
DBUS_STRUCT_END_CHAR_AS_STRING
#define DBUS_STRUCT_END_CHAR_AS_STRING
DBUS_STRUCT_END_CHAR a string literal instead of a int literal
Definition: dbus-protocol.h:162
dbus_message_iter_open_container
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...
Definition: dbus-message.c:2926
DBusBasicValue
A simple value union that lets you access bytes as if they were various types; useful when dealing wi...
Definition: dbus-types.h:137
DBUS_TYPE_STRING_AS_STRING
#define DBUS_TYPE_STRING_AS_STRING
DBUS_TYPE_STRING as a string literal instead of a int literal
Definition: dbus-protocol.h:104
dbus_message_iter_append_basic
dbus_bool_t dbus_message_iter_append_basic(DBusMessageIter *iter, int type, const void *value)
Appends a basic-typed value to the message.
Definition: dbus-message.c:2733
_dbus_close
dbus_bool_t _dbus_close(int fd, DBusError *error)
Closes a file descriptor.
Definition: dbus-sysdeps-unix.c:3213
dbus_shutdown
void dbus_shutdown(void)
Frees all memory allocated internally by libdbus and reverses the effects of dbus_threads_init().
Definition: dbus-memory.c:897
FALSE
#define FALSE
Expands to "0".
dbus_message_demarshal_bytes_needed
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.
Definition: dbus-message.c:4921
dbus_message_iter_abandon_container
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...
Definition: dbus-message.c:3028
_dbus_verbose_bytes_of_string
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.
Definition: dbus-marshal-basic.c:1360
_dbus_message_loader_queue_messages
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_message_loader_queue_messages(DBusMessageLoader *loader)
Converts buffered data into messages, if we have enough data.
Definition: dbus-message.c:4379
dbus_int32_t
int dbus_int32_t
A 32-bit signed integer on all platforms.
Definition: dbus-arch-deps.h:42
_dbus_strdup
char * _dbus_strdup(const char *str)
Duplicates a string.
Definition: dbus-internals.c:537
DBUS_UINT64_CONSTANT
#define DBUS_UINT64_CONSTANT(val)
Declare a 64-bit unsigned integer constant.
DBusMessageLoader::corruption_reason
DBusValidity corruption_reason
why we were corrupted
Definition: dbus-message-private.h:71
dbus_message_set_member
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...
Definition: dbus-message.c:3363
dbus_message_unref
void dbus_message_unref(DBusMessage *message)
Decrements the reference count of a DBusMessage, freeing the message if the count reaches 0...
Definition: dbus-message.c:1717
DBusMessageLoader
Implementation details of DBusMessageLoader.
Definition: dbus-message-private.h:60
dbus_error_is_set
dbus_bool_t dbus_error_is_set(const DBusError *error)
Checks whether an error occurred (the error is set).
Definition: dbus-errors.c:329
_DBUS_DOUBLES_BITWISE_EQUAL
#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:592
dbus_message_set_serial
void dbus_message_set_serial(DBusMessage *message, dbus_uint32_t serial)
Sets the serial number of a message.
Definition: dbus-message.c:277
dbus_uint16_t
unsigned short dbus_uint16_t
A 16-bit unsigned integer on all platforms.
Definition: dbus-arch-deps.h:46