26 #include "dbus-internals.h"
27 #include "dbus-marshal-recursive.h"
28 #include "dbus-marshal-validate.h"
29 #include "dbus-marshal-byteswap.h"
30 #include "dbus-marshal-header.h"
31 #include "dbus-signature.h"
32 #include "dbus-message-private.h"
33 #include "dbus-object-tree.h"
34 #include "dbus-memory.h"
35 #include "dbus-list.h"
36 #include "dbus-threads-internal.h"
37 #ifdef HAVE_UNIX_FD_PASSING
38 #include "dbus-sysdeps-unix.h"
43 #define _DBUS_TYPE_IS_STRINGLIKE(type) \
44 (type == DBUS_TYPE_STRING || type == DBUS_TYPE_SIGNATURE || \
45 type == DBUS_TYPE_OBJECT_PATH)
47 static void dbus_message_finalize (
DBusMessage *message);
59 #ifdef DBUS_BUILD_TESTS
61 _dbus_enable_message_cache (
void)
63 static int enabled = -1;
78 _dbus_warn (
"DBUS_MESSAGE_CACHE should be 0 or 1 if set, not '%s'",
87 # define _dbus_enable_message_cache() (TRUE)
90 #ifndef _dbus_message_trace_ref
97 static int enabled = -1;
99 _dbus_trace_ref (
"DBusMessage", message, old_refcount, new_refcount, why,
100 "DBUS_MESSAGE_TRACE", &enabled);
113 DBUS_MESSAGE_ITER_TYPE_READER = 3,
114 DBUS_MESSAGE_ITER_TYPE_WRITER = 7
152 *type_str_p = &_dbus_empty_signature_str;
171 if (byte_order == DBUS_COMPILER_BYTE_ORDER)
174 _dbus_verbose (
"Swapping message into compiler byte order\n");
176 get_const_signature (&message->
header, &type_str, &type_pos);
180 DBUS_COMPILER_BYTE_ORDER,
185 DBUS_COMPILER_BYTE_ORDER);
194 #define ensure_byte_order(message) _dbus_message_byteswap (message)
214 *body = &message->
body;
232 #ifdef HAVE_UNIX_FD_PASSING
233 *fds = message->unix_fds;
234 *n_fds = message->n_unix_fds;
256 _dbus_return_if_fail (message !=
NULL);
257 _dbus_return_if_fail (!message->
locked);
294 #ifdef HAVE_UNIX_FD_PASSING
295 message->unix_fd_counter_delta = message->n_unix_fds;
299 _dbus_verbose (
"message has size %ld\n",
308 #ifdef HAVE_UNIX_FD_PASSING
364 #ifdef HAVE_UNIX_FD_PASSING
440 const char *signature)
442 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
443 _dbus_return_val_if_fail (!message->
locked,
FALSE);
444 _dbus_return_val_if_fail (signature ==
NULL ||
445 _dbus_check_is_valid_signature (signature));
450 return set_or_delete_string_field (message,
504 #define MAX_MESSAGE_SIZE_TO_CACHE 10 * _DBUS_ONE_KILOBYTE
507 #define MAX_MESSAGE_CACHE_SIZE 5
511 static int message_cache_count = 0;
515 dbus_message_cache_shutdown (
void *data)
524 if (message_cache[i])
525 dbus_message_finalize (message_cache[i]);
530 message_cache_count = 0;
531 message_cache_shutdown_registered =
FALSE;
544 dbus_message_get_cached (
void)
555 if (message_cache_count == 0)
570 if (message_cache[i])
572 message = message_cache[i];
573 message_cache[i] =
NULL;
574 message_cache_count -= 1;
592 #ifdef HAVE_UNIX_FD_PASSING
594 close_unix_fds(
int *fds,
unsigned *n_fds)
604 for (i = 0; i < *n_fds; i++)
620 free_counter (
void *element,
627 #ifdef HAVE_UNIX_FD_PASSING
641 dbus_message_cache_or_finalize (
DBusMessage *message)
654 free_counter, message);
657 #ifdef HAVE_UNIX_FD_PASSING
658 close_unix_fds(message->unix_fds, &message->n_unix_fds);
665 if (!message_cache_shutdown_registered)
675 message_cache[i] =
NULL;
679 message_cache_shutdown_registered =
TRUE;
684 if (!_dbus_enable_message_cache ())
697 while (message_cache[i] !=
NULL)
703 message_cache[i] = message;
704 message_cache_count += 1;
706 #ifndef DBUS_DISABLE_CHECKS
716 dbus_message_finalize (message);
719 #ifndef DBUS_DISABLE_CHECKS
733 if (iter->
iter_type == DBUS_MESSAGE_ITER_TYPE_READER)
743 else if (iter->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER)
761 _dbus_warn_check_failed (
"dbus message iterator invalid because the message has been modified (or perhaps the iterator is just uninitialized)\n");
790 int spec_type, msg_type, i;
797 spec_type = first_arg_type;
804 if (msg_type != spec_type)
807 "Argument %d is specified to be of type \"%s\", but "
808 "is actually of type \"%s\"\n", i,
817 #ifdef HAVE_UNIX_FD_PASSING
821 pfd = va_arg (var_args,
int*);
829 "Message refers to file descriptor at index %i,"
830 "but has only %i descriptors attached.\n",
842 "Platform does not support file desciptor passing.\n");
860 int spec_element_type;
865 spec_element_type = va_arg (var_args,
int);
868 if (spec_element_type != element_type)
871 "Argument %d is specified to be an array of \"%s\", but "
872 "is actually an array of \"%s\"\n",
884 n_elements_p = va_arg (var_args,
int*);
892 (
void *) ptr, n_elements_p);
894 else if (_DBUS_TYPE_IS_STRINGLIKE (spec_element_type))
900 str_array_p = va_arg (var_args,
char***);
901 n_elements_p = va_arg (var_args,
int*);
916 str_array =
dbus_new0 (
char*, n_elements + 1);
917 if (str_array ==
NULL)
919 _DBUS_SET_OOM (error);
927 while (i < n_elements)
934 if (str_array[i] ==
NULL)
937 _DBUS_SET_OOM (error);
951 *str_array_p = str_array;
952 *n_elements_p = n_elements;
954 #ifndef DBUS_DISABLE_CHECKS
957 _dbus_warn (
"you can't read arrays of container types (struct, variant, array) with %s for now\n",
958 _DBUS_FUNCTION_NAME);
963 #ifndef DBUS_DISABLE_CHECKS
966 _dbus_warn (
"you can only read arrays and basic types with %s for now\n",
967 _DBUS_FUNCTION_NAME);
972 spec_type = va_arg (var_args,
int);
976 "Message has only %d arguments, but more were expected", i);
1051 _dbus_return_val_if_fail (message !=
NULL, 0);
1068 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
1069 _dbus_return_val_if_fail (!message->
locked,
FALSE);
1070 _dbus_return_val_if_fail (reply_serial != 0,
FALSE);
1089 _dbus_return_val_if_fail (message !=
NULL, 0);
1109 free_counter, message);
1115 #ifdef HAVE_UNIX_FD_PASSING
1116 close_unix_fds(message->unix_fds, &message->n_unix_fds);
1126 dbus_message_new_empty_header (
void)
1131 message = dbus_message_get_cached ();
1133 if (message !=
NULL)
1141 if (message ==
NULL)
1143 #ifndef DBUS_DISABLE_CHECKS
1147 #ifdef HAVE_UNIX_FD_PASSING
1148 message->unix_fds =
NULL;
1149 message->n_unix_fds_allocated = 0;
1155 _dbus_message_trace_ref (message, 0, 1,
"new_empty_header");
1158 #ifndef DBUS_DISABLE_CHECKS
1165 #ifdef HAVE_UNIX_FD_PASSING
1166 message->n_unix_fds = 0;
1167 message->n_unix_fds_allocated = 0;
1168 message->unix_fd_counter_delta = 0;
1217 message = dbus_message_new_empty_header ();
1218 if (message ==
NULL)
1222 DBUS_COMPILER_BYTE_ORDER,
1257 const char *interface,
1262 _dbus_return_val_if_fail (path !=
NULL,
NULL);
1263 _dbus_return_val_if_fail (method !=
NULL,
NULL);
1264 _dbus_return_val_if_fail (destination ==
NULL ||
1265 _dbus_check_is_valid_bus_name (destination),
NULL);
1266 _dbus_return_val_if_fail (_dbus_check_is_valid_path (path),
NULL);
1267 _dbus_return_val_if_fail (interface ==
NULL ||
1268 _dbus_check_is_valid_interface (interface),
NULL);
1269 _dbus_return_val_if_fail (_dbus_check_is_valid_member (method),
NULL);
1271 message = dbus_message_new_empty_header ();
1272 if (message ==
NULL)
1276 DBUS_COMPILER_BYTE_ORDER,
1278 destination, path, interface, method,
NULL))
1300 _dbus_return_val_if_fail (method_call !=
NULL,
NULL);
1306 message = dbus_message_new_empty_header ();
1307 if (message ==
NULL)
1311 DBUS_COMPILER_BYTE_ORDER,
1347 const char *interface,
1352 _dbus_return_val_if_fail (path !=
NULL,
NULL);
1353 _dbus_return_val_if_fail (interface !=
NULL,
NULL);
1354 _dbus_return_val_if_fail (name !=
NULL,
NULL);
1355 _dbus_return_val_if_fail (_dbus_check_is_valid_path (path),
NULL);
1356 _dbus_return_val_if_fail (_dbus_check_is_valid_interface (interface),
NULL);
1357 _dbus_return_val_if_fail (_dbus_check_is_valid_member (name),
NULL);
1359 message = dbus_message_new_empty_header ();
1360 if (message ==
NULL)
1364 DBUS_COMPILER_BYTE_ORDER,
1366 NULL, path, interface, name,
NULL))
1393 const char *error_name,
1394 const char *error_message)
1400 _dbus_return_val_if_fail (reply_to !=
NULL,
NULL);
1401 _dbus_return_val_if_fail (error_name !=
NULL,
NULL);
1402 _dbus_return_val_if_fail (_dbus_check_is_valid_error_name (error_name),
NULL);
1410 message = dbus_message_new_empty_header ();
1411 if (message ==
NULL)
1415 DBUS_COMPILER_BYTE_ORDER,
1432 if (error_message !=
NULL)
1465 const char *error_name,
1466 const char *error_format,
1473 _dbus_return_val_if_fail (reply_to !=
NULL,
NULL);
1474 _dbus_return_val_if_fail (error_name !=
NULL,
NULL);
1475 _dbus_return_val_if_fail (_dbus_check_is_valid_error_name (error_name),
NULL);
1480 va_start (args, error_format);
1513 _dbus_return_val_if_fail (message !=
NULL,
NULL);
1522 #ifndef DBUS_DISABLE_CHECKS
1544 #ifdef HAVE_UNIX_FD_PASSING
1545 retval->unix_fds =
dbus_new(
int, message->n_unix_fds);
1546 if (retval->unix_fds ==
NULL && message->n_unix_fds > 0)
1549 retval->n_unix_fds_allocated = message->n_unix_fds;
1551 for (retval->n_unix_fds = 0;
1552 retval->n_unix_fds < message->n_unix_fds;
1553 retval->n_unix_fds++)
1555 retval->unix_fds[retval->n_unix_fds] =
_dbus_dup(message->unix_fds[retval->n_unix_fds],
NULL);
1557 if (retval->unix_fds[retval->n_unix_fds] < 0)
1563 _dbus_message_trace_ref (retval, 0, 1,
"copy");
1570 #ifdef HAVE_UNIX_FD_PASSING
1571 close_unix_fds(retval->unix_fds, &retval->n_unix_fds);
1593 _dbus_return_val_if_fail (message !=
NULL,
NULL);
1599 _dbus_message_trace_ref (message, old_refcount, old_refcount + 1,
"ref");
1616 _dbus_return_if_fail (message !=
NULL);
1618 _dbus_return_if_fail (!message->
in_cache);
1624 _dbus_message_trace_ref (message, old_refcount, old_refcount - 1,
"unref");
1626 if (old_refcount == 1)
1629 dbus_message_cache_or_finalize (message);
1721 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
1723 va_start (var_args, first_arg_type);
1753 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
1755 type = first_arg_type;
1777 element_type = va_arg (var_args,
int);
1779 buf[0] = element_type;
1794 n_elements = va_arg (var_args,
int);
1804 else if (_DBUS_TYPE_IS_STRINGLIKE (element_type))
1806 const char ***value_p;
1811 value_p = va_arg (var_args,
const char***);
1812 n_elements = va_arg (var_args,
int);
1817 while (i < n_elements)
1830 _dbus_warn (
"arrays of %s can't be appended with %s for now\n",
1832 _DBUS_FUNCTION_NAME);
1839 #ifndef DBUS_DISABLE_CHECKS
1842 _dbus_warn (
"type %s isn't supported yet in %s\n",
1848 type = va_arg (var_args,
int);
1910 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
1911 _dbus_return_val_if_error_is_set (error,
FALSE);
1913 va_start (var_args, first_arg_type);
1938 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
1939 _dbus_return_val_if_error_is_set (error,
FALSE);
1946 _dbus_message_iter_init_common (
DBusMessage *message,
1993 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
1994 _dbus_return_val_if_fail (iter !=
NULL,
FALSE);
1996 get_const_signature (&message->
header, &type_str, &type_pos);
1998 _dbus_message_iter_init_common (message, real,
1999 DBUS_MESSAGE_ITER_TYPE_READER);
2021 _dbus_return_val_if_fail (_dbus_message_iter_check (real),
FALSE);
2022 _dbus_return_val_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_READER,
FALSE);
2040 _dbus_return_val_if_fail (_dbus_message_iter_check (real),
FALSE);
2041 _dbus_return_val_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_READER,
FALSE);
2066 _dbus_return_val_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_READER,
FALSE);
2123 _dbus_return_if_fail (_dbus_message_iter_check (real));
2124 _dbus_return_if_fail (sub !=
NULL);
2150 _dbus_return_val_if_fail (_dbus_message_iter_check (real),
NULL);
2220 _dbus_return_if_fail (_dbus_message_iter_check (real));
2221 _dbus_return_if_fail (value !=
NULL);
2225 #ifdef HAVE_UNIX_FD_PASSING
2233 *((
int*) value) = -1;
2239 *((
int*) value) = -1;
2272 _dbus_return_val_if_fail (_dbus_message_iter_check (real), 0);
2318 #ifndef DBUS_DISABLE_CHECKS
2321 _dbus_return_if_fail (_dbus_message_iter_check (real));
2322 _dbus_return_if_fail (value !=
NULL);
2348 _dbus_return_if_fail (message !=
NULL);
2349 _dbus_return_if_fail (iter !=
NULL);
2351 _dbus_message_iter_init_common (message, real,
2352 DBUS_MESSAGE_ITER_TYPE_WRITER);
2377 int current_sig_pos;
2394 ¤t_sig, ¤t_sig_pos))
2402 current_sig_pos += 1;
2447 const char *v_STRING;
2507 #ifndef DBUS_DISABLE_CHECKS
2511 if (!_dbus_message_iter_check (iter))
2524 #ifdef HAVE_UNIX_FD_PASSING
2534 if (m->n_unix_fds + n > m->n_unix_fds_allocated)
2540 k = (m->n_unix_fds + n) * 2;
2551 m->n_unix_fds_allocated = k;
2554 return m->unix_fds + m->n_unix_fds;
2585 _dbus_return_val_if_fail (_dbus_message_iter_append_check (real),
FALSE);
2586 _dbus_return_val_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER,
FALSE);
2588 _dbus_return_val_if_fail (value !=
NULL,
FALSE);
2590 #ifndef DBUS_DISABLE_CHECKS
2593 const char *
const *string_p;
2598 _dbus_return_val_if_fail (_dbus_check_is_valid_utf8 (*string_p),
FALSE);
2603 _dbus_return_val_if_fail (_dbus_check_is_valid_path (*string_p),
FALSE);
2608 _dbus_return_val_if_fail (_dbus_check_is_valid_signature (*string_p),
FALSE);
2613 _dbus_return_val_if_fail (*bool_p == 0 || *bool_p == 1,
FALSE);
2623 if (!_dbus_message_iter_open_signature (real))
2628 #ifdef HAVE_UNIX_FD_PASSING
2633 if (!(fds = expand_fd_array(real->
message, 1)))
2640 u = real->
message->n_unix_fds;
2648 real->
message->n_unix_fds += 1;
2671 if (!_dbus_message_iter_close_signature (real))
2721 _dbus_return_val_if_fail (_dbus_message_iter_append_check (real),
FALSE);
2722 _dbus_return_val_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER,
FALSE);
2725 _dbus_return_val_if_fail (value !=
NULL,
FALSE);
2726 _dbus_return_val_if_fail (n_elements >= 0,
FALSE);
2727 _dbus_return_val_if_fail (n_elements <=
2731 #ifndef DBUS_DISABLE_CHECKS
2737 for (i = 0; i < n_elements; i++)
2739 _dbus_return_val_if_fail ((*bools)[i] == 0 || (*bools)[i] == 1,
FALSE);
2773 const char *contained_signature,
2780 _dbus_return_val_if_fail (_dbus_message_iter_append_check (real),
FALSE);
2781 _dbus_return_val_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER,
FALSE);
2783 _dbus_return_val_if_fail (sub !=
NULL,
FALSE);
2785 contained_signature ==
NULL) ||
2787 contained_signature ==
NULL) ||
2789 contained_signature !=
NULL) ||
2798 (contained_signature ==
NULL ||
2799 _dbus_check_is_valid_signature (contained_signature)),
2802 if (!_dbus_message_iter_open_signature (real))
2807 if (contained_signature !=
NULL)
2847 _dbus_return_val_if_fail (_dbus_message_iter_append_check (real),
FALSE);
2848 _dbus_return_val_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER,
FALSE);
2849 _dbus_return_val_if_fail (_dbus_message_iter_append_check (real_sub),
FALSE);
2850 _dbus_return_val_if_fail (real_sub->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER,
FALSE);
2855 if (!_dbus_message_iter_close_signature (real))
2877 #ifndef DBUS_DISABLE_CHECKS
2880 _dbus_return_if_fail (_dbus_message_iter_append_check (real));
2881 _dbus_return_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER);
2882 _dbus_return_if_fail (_dbus_message_iter_append_check (real_sub));
2883 _dbus_return_if_fail (real_sub->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER);
2886 _dbus_message_iter_abandon_signature (real);
2909 _dbus_return_if_fail (message !=
NULL);
2910 _dbus_return_if_fail (!message->
locked);
2927 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
2951 _dbus_return_if_fail (message !=
NULL);
2952 _dbus_return_if_fail (!message->
locked);
2969 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
2990 const char *object_path)
2992 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
2993 _dbus_return_val_if_fail (!message->
locked,
FALSE);
2994 _dbus_return_val_if_fail (object_path ==
NULL ||
2995 _dbus_check_is_valid_path (object_path),
2998 return set_or_delete_string_field (message,
3022 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3045 const char *msg_path;
3048 if (msg_path ==
NULL)
3059 if (strcmp (msg_path, path) == 0)
3091 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3092 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
3121 const char *interface)
3123 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3124 _dbus_return_val_if_fail (!message->
locked,
FALSE);
3125 _dbus_return_val_if_fail (interface ==
NULL ||
3126 _dbus_check_is_valid_interface (interface),
3129 return set_or_delete_string_field (message,
3153 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3172 const char *interface)
3174 const char *msg_interface;
3177 if (msg_interface ==
NULL)
3179 if (interface ==
NULL)
3185 if (interface ==
NULL)
3188 if (strcmp (msg_interface, interface) == 0)
3211 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3212 _dbus_return_val_if_fail (!message->
locked,
FALSE);
3213 _dbus_return_val_if_fail (member ==
NULL ||
3214 _dbus_check_is_valid_member (member),
3217 return set_or_delete_string_field (message,
3239 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3260 const char *msg_member;
3263 if (msg_member ==
NULL)
3274 if (strcmp (msg_member, member) == 0)
3294 const char *error_name)
3296 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3297 _dbus_return_val_if_fail (!message->
locked,
FALSE);
3298 _dbus_return_val_if_fail (error_name ==
NULL ||
3299 _dbus_check_is_valid_error_name (error_name),
3302 return set_or_delete_string_field (message,
3323 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3348 const char *destination)
3350 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3351 _dbus_return_val_if_fail (!message->
locked,
FALSE);
3352 _dbus_return_val_if_fail (destination ==
NULL ||
3353 _dbus_check_is_valid_bus_name (destination),
3356 return set_or_delete_string_field (message,
3376 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3404 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3405 _dbus_return_val_if_fail (!message->
locked,
FALSE);
3406 _dbus_return_val_if_fail (sender ==
NULL ||
3407 _dbus_check_is_valid_bus_name (sender),
3410 return set_or_delete_string_field (message,
3436 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3470 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3472 get_const_signature (&message->
header, &type_str, &type_pos);
3478 _dbus_message_has_type_interface_member (
DBusMessage *message,
3480 const char *interface,
3498 if (n && strcmp (n, member) == 0)
3502 if (n ==
NULL || strcmp (n, interface) == 0)
3525 const char *interface,
3528 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3529 _dbus_return_val_if_fail (interface !=
NULL,
FALSE);
3530 _dbus_return_val_if_fail (method !=
NULL,
FALSE);
3535 return _dbus_message_has_type_interface_member (message,
3553 const char *interface,
3554 const char *signal_name)
3556 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3557 _dbus_return_val_if_fail (interface !=
NULL,
FALSE);
3558 _dbus_return_val_if_fail (signal_name !=
NULL,
FALSE);
3563 return _dbus_message_has_type_interface_member (message,
3565 interface, signal_name);
3580 const char *error_name)
3584 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3585 _dbus_return_val_if_fail (error_name !=
NULL,
FALSE);
3595 if (n && strcmp (n, error_name) == 0)
3617 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3618 _dbus_return_val_if_fail (name !=
NULL,
FALSE);
3625 if (s && strcmp (s, name) == 0)
3652 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3653 _dbus_return_val_if_fail (name !=
NULL,
FALSE);
3660 if (s && strcmp (s, name) == 0)
3677 const char *signature)
3681 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3682 _dbus_return_val_if_fail (signature !=
NULL,
FALSE);
3689 if (s && strcmp (s, signature) == 0)
3723 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3724 _dbus_return_val_if_error_is_set (error,
FALSE);
3735 str ?
"%s" :
NULL, str);
3749 #ifdef HAVE_UNIX_FD_PASSING
3752 return message->n_unix_fds > 0;
3776 #define INITIAL_LOADER_DATA_LEN 32
3817 #ifdef HAVE_UNIX_FD_PASSING
3818 loader->unix_fds =
NULL;
3819 loader->n_unix_fds = loader->n_unix_fds_allocated = 0;
3820 loader->unix_fds_outstanding =
FALSE;
3852 #ifdef HAVE_UNIX_FD_PASSING
3853 close_unix_fds(loader->unix_fds, &loader->n_unix_fds);
3889 *buffer = &loader->
data;
3928 unsigned *max_n_fds)
3930 #ifdef HAVE_UNIX_FD_PASSING
3949 loader->unix_fds = a;
3953 *fds = loader->unix_fds + loader->n_unix_fds;
3954 *max_n_fds = loader->n_unix_fds_allocated - loader->n_unix_fds;
3956 loader->unix_fds_outstanding =
TRUE;
3979 #ifdef HAVE_UNIX_FD_PASSING
3981 _dbus_assert(loader->unix_fds + loader->n_unix_fds == fds);
3982 _dbus_assert(loader->n_unix_fds + n_fds <= loader->n_unix_fds_allocated);
3984 loader->n_unix_fds += n_fds;
3985 loader->unix_fds_outstanding =
FALSE;
4021 int fields_array_len,
4032 mode = DBUS_VALIDATION_MODE_DATA_IS_UNTRUSTED;
4054 _dbus_verbose (
"Failed to load header for new message code %d\n", validity);
4073 if (mode != DBUS_VALIDATION_MODE_WE_TRUST_THIS_DATA_ABSOLUTELY)
4075 get_const_signature (&message->
header, &type_str, &type_pos);
4089 _dbus_verbose (
"Failed to validate message body code %d\n", validity);
4104 #ifdef HAVE_UNIX_FD_PASSING
4106 if (n_unix_fds > loader->n_unix_fds)
4108 _dbus_verbose(
"Message contains references to more unix fds than were sent %u != %u\n",
4109 n_unix_fds, loader->n_unix_fds);
4122 message->unix_fds =
_dbus_memdup(loader->unix_fds, n_unix_fds *
sizeof(message->unix_fds[0]));
4123 if (message->unix_fds ==
NULL)
4125 _dbus_verbose (
"Failed to allocate file descriptor array\n");
4130 message->n_unix_fds_allocated = message->n_unix_fds = n_unix_fds;
4131 loader->n_unix_fds -= n_unix_fds;
4132 memmove(loader->unix_fds + n_unix_fds, loader->unix_fds, loader->n_unix_fds);
4135 message->unix_fds =
NULL;
4141 _dbus_verbose (
"Hmm, message claims to come with file descriptors "
4142 "but that's not supported on our platform, disconnecting.\n");
4155 _dbus_verbose (
"Failed to append new message to loader queue\n");
4162 (header_len + body_len));
4166 _dbus_verbose (
"Failed to move body into new message\n");
4179 _dbus_verbose (
"Loaded message %p\n", message);
4226 int byte_order, fields_array_len, header_len, body_len;
4241 message = dbus_message_new_empty_header ();
4242 if (message ==
NULL)
4245 if (!load_message (loader, message,
4246 byte_order, fields_array_len,
4247 header_len, body_len))
4261 _dbus_verbose (
"Initial peek at header says we don't have a whole message yet, or data broken with invalid code %d\n",
4376 _dbus_verbose (
"clamping requested max message size %ld to %d\n",
4407 _dbus_verbose (
"clamping requested max message unix_fds %ld to %d\n",
4465 _dbus_return_if_fail (*slot_p >= 0);
4493 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
4494 _dbus_return_val_if_fail (slot >= 0,
FALSE);
4498 slot, data, free_data_func,
4499 &old_free_func, &old_data);
4505 (* old_free_func) (old_data);
4525 _dbus_return_val_if_fail (message !=
NULL,
NULL);
4550 if (strcmp (type_str,
"method_call") == 0)
4552 if (strcmp (type_str,
"method_return") == 0)
4554 else if (strcmp (type_str,
"signal") == 0)
4556 else if (strcmp (type_str,
"error") == 0)
4581 return "method_call";
4583 return "method_return";
4607 char **marshalled_data_p,
4613 _dbus_return_val_if_fail (msg !=
NULL,
FALSE);
4614 _dbus_return_val_if_fail (marshalled_data_p !=
NULL,
FALSE);
4615 _dbus_return_val_if_fail (len_p !=
NULL,
FALSE);
4621 was_locked = msg->
locked;
4676 _dbus_return_val_if_fail (str !=
NULL,
NULL);
4708 _DBUS_SET_OOM (error);
4731 int byte_order, fields_array_len, header_len, body_len;
4745 &validity, &byte_order,
4755 _dbus_assert (have_message || (header_len + body_len) > len);
4756 (void) have_message;
4757 return header_len + body_len;
dbus_bool_t dbus_type_is_fixed(int typecode)
Tells you whether values of this type can change length if you set them to some other value...
void _dbus_type_reader_read_fixed_multi(const DBusTypeReader *reader, void *value, int *n_elements)
Reads a block of fixed-length basic values, from the current point in an array to the end of the arra...
int dbus_message_type_from_string(const char *type_str)
Utility function to convert a machine-readable (not translated) string into a D-Bus message type...
unsigned int dbus_uint32_t
A 32-bit unsigned integer on all platforms.
DBusMessage * dbus_message_ref(DBusMessage *message)
Increments the reference count of a DBusMessage.
void dbus_message_lock(DBusMessage *message)
Locks a message.
const char * message
public error message field
dbus_bool_t dbus_message_has_path(DBusMessage *message, const char *path)
Checks if the message has a particular object path.
dbus_int32_t _dbus_atomic_get(DBusAtomic *atomic)
Atomically get the value of an integer.
dbus_uint32_t changed_stamp
Incremented when iterators are invalidated.
#define NULL
A null pointer, defined appropriately for C or C++.
dbus_bool_t _dbus_header_load(DBusHeader *header, DBusValidationMode mode, DBusValidity *validity, int byte_order, int fields_array_len, int header_len, int body_len, const DBusString *str, int start, int len)
Creates a message header from potentially-untrusted data.
void(* DBusFreeFunction)(void *memory)
The type of a function which frees a block of memory.
long _dbus_message_loader_get_max_message_size(DBusMessageLoader *loader)
Gets the maximum allowed message size in bytes.
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.
void _dbus_message_loader_putback_message_link(DBusMessageLoader *loader, DBusList *link)
Returns a popped message link, used to undo a pop.
dbus_bool_t _dbus_header_copy(const DBusHeader *header, DBusHeader *dest)
Initializes dest with a copy of the given header.
int dbus_message_iter_get_arg_type(DBusMessageIter *iter)
Returns the argument type of the argument that the message iterator points to.
dbus_uint32_t sig_refcount
depth of open_signature()
void _dbus_type_writer_remove_types(DBusTypeWriter *writer)
Removes type string from the writer.
void * dbus_realloc(void *memory, size_t bytes)
Resizes a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
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().
dbus_uint32_t dbus_message_get_serial(DBusMessage *message)
Returns the serial of a message or 0 if none has been specified.
DBusList * messages
Complete messages.
The type writer is an iterator for writing to a block of values.
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...
void _dbus_type_reader_recurse(DBusTypeReader *reader, DBusTypeReader *sub)
Initialize a new reader pointing to the first type and corresponding value that's a child of the curr...
DBusMessage * _dbus_message_loader_pop_message(DBusMessageLoader *loader)
Pops a loaded message (passing ownership of the message to the caller).
DBusList * _dbus_list_find_last(DBusList **list, void *data)
Finds a value in the list.
#define DBUS_ERROR_NOT_SUPPORTED
Requested operation isn't supported (like ENOSYS on UNIX).
#define dbus_new(type, count)
Safe macro for using dbus_malloc().
void dbus_message_free_data_slot(dbus_int32_t *slot_p)
Deallocates a global ID for message data slots.
#define DBUS_HEADER_FIELD_SIGNATURE
Header field code for the type signature of a message.
const char * dbus_message_get_error_name(DBusMessage *message)
Gets the error name (DBUS_MESSAGE_TYPE_ERROR only) or NULL if none.
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...
dbus_bool_t dbus_message_is_error(DBusMessage *message, const char *error_name)
Checks whether the message is an error reply with the given error name.
void _dbus_list_remove_link(DBusList **list, DBusList *link)
Removes a link from the list.
#define DBUS_TYPE_STRUCT
STRUCT and DICT_ENTRY are sort of special since their codes can't appear in a type string...
#define DBUS_TYPE_DICT_ENTRY
Type code used to represent a dict entry; however, this type code does not appear in type signatures...
const char * dbus_message_get_sender(DBusMessage *message)
Gets the unique name of the connection which originated this message, or NULL if unknown or inapplica...
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.
#define DBUS_TYPE_STRING
Type code marking a UTF-8 encoded, nul-terminated Unicode string.
DBusString body
Body network data.
dbus_uint32_t _dbus_header_get_serial(DBusHeader *header)
See dbus_message_get_serial()
dbus_bool_t _dbus_header_get_flag(DBusHeader *header, dbus_uint32_t flag)
Gets a message flag bit, returning TRUE if the bit is set.
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
#define DBUS_HEADER_FLAG_NO_REPLY_EXPECTED
If set, this flag means that the sender of a message does not care about getting a reply...
dbus_bool_t dbus_message_has_interface(DBusMessage *message, const char *interface)
Checks if the message has an interface.
void _dbus_list_append_link(DBusList **list, DBusList *link)
Appends a link to the list.
Internals of DBusCounter.
dbus_bool_t dbus_message_allocate_data_slot(dbus_int32_t *slot_p)
Allocates an integer ID to be used for storing application-specific data on any DBusMessage.
void * data
Data stored at this element.
#define MAX_MESSAGE_CACHE_SIZE
Avoid caching too many messages.
DBusMessage * dbus_message_new(int message_type)
Constructs a new message of the given message type.
#define DBUS_ERROR_INCONSISTENT_MESSAGE
The message meta data does not match the payload.
dbus_bool_t _dbus_header_init(DBusHeader *header)
Initializes a header, but doesn't prepare it for use; to make the header valid, you have to call _dbu...
void _dbus_warn_check_failed(const char *format,...)
Prints a "critical" warning to stderr when an assertion fails; differs from _dbus_warn primarily in t...
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's been set (or just initialized), then reinitializes the error as in dbus_error_i...
void dbus_message_set_auto_start(DBusMessage *message, dbus_bool_t auto_start)
Sets a flag indicating that an owner for the destination name will be automatically started before th...
union DBusMessageRealIter::@6 u
the type writer or reader that does all the work
void _dbus_message_loader_unref(DBusMessageLoader *loader)
Decrements the reference count of the loader and finalizes the loader when the count reaches zero...
DBusCounter * _dbus_counter_ref(DBusCounter *counter)
Increments refcount of the counter.
unsigned char _dbus_string_get_byte(const DBusString *str, int start)
Gets the byte at the given position.
int _dbus_dup(int fd, DBusError *error)
Duplicates a file descriptor.
DBusValidity _dbus_message_loader_get_corruption_reason(DBusMessageLoader *loader)
Checks what kind of bad data confused the loader.
dbus_bool_t _dbus_type_writer_write_basic(DBusTypeWriter *writer, int type, const void *value)
Writes out a basic type.
#define DBUS_MESSAGE_TYPE_ERROR
Message type of an error reply message, see dbus_message_get_type()
DBusList * _dbus_list_alloc_link(void *data)
Allocates a linked list node.
#define DBUS_MAXIMUM_MESSAGE_UNIX_FDS
The maximum total number of unix fds in a message.
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...
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
#define DBUS_MESSAGE_TYPE_METHOD_RETURN
Message type of a method return message, see dbus_message_get_type()
dbus_bool_t _dbus_string_append_printf_valist(DBusString *str, const char *format, va_list args)
Appends a printf-style formatted string to the DBusString.
DBusTypeReader reader
reader
DBusValidationMode
This is used rather than a bool for high visibility.
dbus_bool_t dbus_message_iter_has_next(DBusMessageIter *iter)
Checks if an iterator has any more fields.
DBusMessage * message
Message used.
dbus_bool_t _dbus_data_slot_allocator_alloc(DBusDataSlotAllocator *allocator, DBusRMutex **mutex_loc, dbus_int32_t *slot_id_p)
Allocates an integer ID to be used for storing data in a DBusDataSlotList.
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's copied to the d...
#define DBUS_HEADER_FIELD_INTERFACE
Header field code for the interface containing a member (method or signal).
#define DBUS_DICT_ENTRY_BEGIN_CHAR
Code marking the start of a dict entry type in a type signature.
DBusList * _dbus_list_pop_first_link(DBusList **list)
Removes the first link in the list and returns it.
dbus_bool_t dbus_message_has_member(DBusMessage *message, const char *member)
Checks if the message has an interface member.
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.
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_message_add_counter(DBusMessage *message, DBusCounter *counter)
Adds a counter to be incremented immediately with the size/unix fds of this message, and decremented by the size/unix fds of this message when this message if finalized.
const char * _dbus_getenv(const char *varname)
Wrapper for getenv().
const char * dbus_message_get_destination(DBusMessage *message)
Gets the destination of a message or NULL if there is none set.
void _dbus_message_add_counter_link(DBusMessage *message, DBusList *link)
Adds a counter to be incremented immediately with the size/unix fds of this message, and decremented by the size/unix fds of this message when this message if finalized.
#define DBUS_TYPE_ARRAY
Type code marking a D-Bus array type.
DBusString * type_str
where to write typecodes (or read type expectations)
dbus_bool_t dbus_message_iter_append_fixed_array(DBusMessageIter *iter, int element_type, const void *value, int n_elements)
Appends a block of fixed-length values to an array.
dbus_bool_t dbus_message_set_error_name(DBusMessage *message, const char *error_name)
Sets the name of the error (DBUS_MESSAGE_TYPE_ERROR).
dbus_int32_t _dbus_atomic_dec(DBusAtomic *atomic)
Atomically decrement an integer.
const char * dbus_message_get_member(DBusMessage *message)
Gets the interface member being invoked (DBUS_MESSAGE_TYPE_METHOD_CALL) or emitted (DBUS_MESSAGE_TYPE...
dbus_bool_t _dbus_list_remove_last(DBusList **list, void *data)
Removes a value from the list.
Internals of DBusMessage.
Internals of DBusMessageIter.
#define dbus_new0(type, count)
Safe macro for using dbus_malloc0().
dbus_uint32_t changed_stamp
stamp to detect invalid iters
void _dbus_type_writer_init_types_delayed(DBusTypeWriter *writer, int byte_order, DBusString *value_str, int value_pos)
Initialize a write iterator, with the signature to be provided later.
dbus_bool_t _dbus_string_compact(DBusString *str, int max_waste)
Compacts the string to avoid wasted memory.
int _dbus_header_get_message_type(DBusHeader *header)
Gets the type of the message.
#define DBUS_HEADER_FIELD_ERROR_NAME
Header field code for an error name (found in DBUS_MESSAGE_TYPE_ERROR messages).
#define DBUS_MINIMUM_HEADER_SIZE
The smallest header size that can occur.
dbus_bool_t _dbus_type_writer_unrecurse(DBusTypeWriter *writer, DBusTypeWriter *sub)
Closes a container created by _dbus_type_writer_recurse() and writes any additional information to th...
dbus_bool_t dbus_type_is_basic(int typecode)
A "basic type" is a somewhat arbitrary concept, but the intent is to include those types that are ful...
void _dbus_message_loader_set_max_message_size(DBusMessageLoader *loader, long size)
Sets the maximum size message we allow.
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
void _dbus_string_init_const(DBusString *str, const char *value)
Initializes a constant string.
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.
void _dbus_type_reader_read_basic(const DBusTypeReader *reader, void *value)
Reads a basic-typed value, as with _dbus_marshal_read_basic().
unsigned int locked
Message being sent, no modifications allowed.
#define ensure_byte_order(message)
byte-swap the message if it doesn't match our byte order.
DBusMessageLoader * _dbus_message_loader_ref(DBusMessageLoader *loader)
Increments the reference count of the loader.
dbus_bool_t _dbus_header_get_field_basic(DBusHeader *header, int field, int type, void *value)
Gets the value of a field with basic type.
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...
can't determine validity due to OOM
void _dbus_warn(const char *format,...)
Prints a warning message to stderr.
void _dbus_string_delete(DBusString *str, int start, int len)
Deletes a segment of a DBusString with length len starting at start.
dbus_bool_t _dbus_string_init_preallocated(DBusString *str, int allocate_size)
Initializes a string that can be up to the given allocation size before it has to realloc...
void _dbus_counter_unref(DBusCounter *counter)
Decrements refcount of the counter and possibly finalizes the counter.
dbus_bool_t dbus_message_set_interface(DBusMessage *message, const char *interface)
Sets the interface this message is being sent to (for DBUS_MESSAGE_TYPE_METHOD_CALL) or the interface...
void _dbus_message_remove_counter(DBusMessage *message, DBusCounter *counter)
Removes a counter tracking the size/unix fds of this message, and decrements the counter by the size/...
dbus_bool_t _dbus_list_append(DBusList **list, void *data)
Appends a value to the list.
dbus_bool_t _dbus_decompose_path(const char *data, int len, char ***path, int *path_len)
Decompose an object path.
void * _dbus_memdup(const void *mem, size_t n_bytes)
Duplicates a block of memory.
dbus_bool_t _dbus_data_slot_list_set(DBusDataSlotAllocator *allocator, DBusDataSlotList *list, int slot, void *data, DBusFreeFunction free_data_func, DBusFreeFunction *old_free_func, void **old_data)
Stores a pointer in the data slot list, along with an optional function to be used for freeing the da...
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...
void _dbus_list_foreach(DBusList **list, DBusForeachFunction function, void *data)
Calls the given function for each element in the list.
long max_message_size
Maximum size of a message.
void _dbus_counter_adjust_unix_fd(DBusCounter *counter, long delta)
Adjusts the value of the unix fd counter by the given delta which may be positive or negative...
int _dbus_string_get_length(const DBusString *str)
Gets the length of a string (not including nul termination).
dbus_bool_t _dbus_type_reader_next(DBusTypeReader *reader)
Skip to the next value on this "level".
DBusList * counters
0-N DBusCounter used to track message size/unix fds.
DBusMessageLoader * _dbus_message_loader_new(void)
Creates a new message loader.
long size_counter_delta
Size we incremented the size counters by.
#define CHANGED_STAMP_BITS
How many bits are in the changed_stamp used to validate iterators.
void _dbus_header_byteswap(DBusHeader *header, int new_order)
Swaps the header into the given order if required.
dbus_bool_t _dbus_header_have_message_untrusted(int max_message_length, DBusValidity *validity, int *byte_order, int *fields_array_len, int *header_len, int *body_len, const DBusString *str, int start, int len)
Given data long enough to contain the length of the message body and the fields array, check whether the data is long enough to contain the entire message (assuming the claimed lengths are accurate).
#define DBUS_MESSAGE_TYPE_METHOD_CALL
Message type of a method call message, see dbus_message_get_type()
#define DBUS_HEADER_FIELD_UNIX_FDS
Header field code for the number of unix file descriptors associated with this message.
int _dbus_current_generation
_dbus_current_generation is used to track each time that dbus_shutdown() is called, so we can reinit things after it's been called.
dbus_bool_t dbus_message_get_args(DBusMessage *message, DBusError *error, int first_arg_type,...)
Gets arguments from a message given a variable argument list.
Object representing an exception.
unsigned int in_cache
Has been "freed" since it's in the cache (this is a debug feature)
void * _dbus_list_pop_first(DBusList **list)
Removes the first value in the list and returns it.
#define DBUS_TYPE_SIGNATURE
Type code marking a D-Bus type signature.
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_MESSAGE_TYPE_SIGNAL
Message type of a signal message, see dbus_message_get_type()
void dbus_set_error(DBusError *error, const char *name, const char *format,...)
Assigns an error name and message to a DBusError.
dbus_uint32_t dbus_message_get_reply_serial(DBusMessage *message)
Returns the serial that the message is a reply to or 0 if none.
#define INITIAL_LOADER_DATA_LEN
The initial buffer size of the message loader.
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...
void _dbus_data_slot_list_clear(DBusDataSlotList *list)
Frees all data slots contained in the list, calling application-provided free functions if they exist...
dbus_int32_t _dbus_atomic_inc(DBusAtomic *atomic)
Atomically increments an integer.
dbus_bool_t _dbus_message_loader_get_is_corrupted(DBusMessageLoader *loader)
Checks whether the loader is confused due to bad data.
#define DBUS_TYPE_VARIANT
Type code marking a D-Bus variant type.
#define DBUS_TYPE_UINT32
Type code marking a 32-bit unsigned integer.
DBusValidity _dbus_validate_body_with_reason(const DBusString *expected_signature, int expected_signature_start, int byte_order, int *bytes_remaining, const DBusString *value_str, int value_pos, int len)
Verifies that the range of value_str from value_pos to value_end is a legitimate value of type expect...
void _dbus_header_reinit(DBusHeader *header)
Re-initializes a header that was previously initialized and never freed.
#define DBUS_HEADER_FIELD_DESTINATION
Header field code for the destination bus name of a message.
dbus_uint32_t byte_order
byte order of the block
dbus_bool_t _dbus_header_delete_field(DBusHeader *header, int field)
Deletes a field, if it exists.
dbus_bool_t _dbus_close(int fd, DBusError *error)
Closes a file descriptor.
dbus_bool_t dbus_message_has_destination(DBusMessage *message, const char *name)
Checks whether the message was sent to the given name.
#define DBUS_MESSAGE_TYPE_INVALID
This value is never a valid message type, see dbus_message_get_type()
dbus_bool_t dbus_message_get_auto_start(DBusMessage *message)
Returns TRUE if the message will cause an owner for destination name to be auto-started.
dbus_uint32_t byte_order
byte order to write values with
#define _DBUS_UNLOCK(name)
Unlocks a global lock.
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init().
The type reader is an iterator for reading values from a block of values.
void * _dbus_data_slot_list_get(DBusDataSlotAllocator *allocator, DBusDataSlotList *list, int slot)
Retrieves data previously set with _dbus_data_slot_list_set_data().
long _dbus_message_loader_get_max_message_unix_fds(DBusMessageLoader *loader)
Gets the maximum allowed number of unix fds per message.
#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.
dbus_bool_t _dbus_header_set_field_basic(DBusHeader *header, int field, int type, const void *value)
Sets the value of a field with basic type.
void _dbus_data_slot_list_init(DBusDataSlotList *list)
Initializes a slot list.
#define _dbus_assert_not_reached(explanation)
Aborts with an error message if called.
DBusMessage * dbus_message_copy(const DBusMessage *message)
Creates a new message that is an exact replica of the message specified, except that its refcount is ...
int dbus_message_iter_get_element_type(DBusMessageIter *iter)
Returns the element type of the array that the message iterator points to.
void _dbus_message_get_network_data(DBusMessage *message, const DBusString **header, const DBusString **body)
Gets the data to be sent over the network for this message.
dbus_bool_t dbus_message_is_method_call(DBusMessage *message, const char *interface, const char *method)
Checks whether the message is a method call with the given interface and member fields.
#define DBUS_HEADER_FIELD_MEMBER
Header field code for a member (method or signal).
long max_message_unix_fds
Maximum unix fds in a message.
unsigned int corrupted
We got broken data, and are no longer working.
dbus_bool_t dbus_message_get_args_valist(DBusMessage *message, DBusError *error, int first_arg_type, va_list var_args)
Like dbus_message_get_args but takes a va_list for use by language bindings.
#define DBUS_HEADER_FIELD_SENDER
Header field code for the sender of a message; usually initialized by the message bus...
void _dbus_type_writer_add_types(DBusTypeWriter *writer, DBusString *type_str, int type_pos)
Adds type string to the writer, if it had none.
#define DBUS_TYPE_OBJECT_PATH
Type code marking a D-Bus object path.
dbus_bool_t dbus_set_error_from_message(DBusError *error, DBusMessage *message)
Sets a DBusError based on the contents of the given message.
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.
void dbus_message_iter_get_fixed_array(DBusMessageIter *iter, void *value, int *n_elements)
Reads a block of fixed-length values from the message iterator.
#define DBUS_TYPE_UNIX_FD
Type code marking a unix file descriptor.
void _dbus_message_loader_return_buffer(DBusMessageLoader *loader, DBusString *buffer, int bytes_read)
Returns a buffer obtained from _dbus_message_loader_get_buffer(), indicating to the loader how many b...
dbus_bool_t _dbus_header_create(DBusHeader *header, int byte_order, int message_type, const char *destination, const char *path, const char *interface, const char *member, const char *error_name)
Fills in the primary fields of the header, so the header is ready for use.
DBusMessage * dbus_message_new_signal(const char *path, const char *interface, const char *name)
Constructs a new message representing a signal emission.
#define _DBUS_DEFINE_GLOBAL_LOCK(name)
Defines a global lock variable with the given name.
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...
An allocator that tracks a set of slot IDs.
#define DBUS_TYPE_INVALID
Type code that is never equal to a legitimate type code.
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).
void _dbus_counter_notify(DBusCounter *counter)
Calls the notify function from _dbus_counter_set_notify(), if that function has been specified and th...
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.
void dbus_message_iter_get_basic(DBusMessageIter *iter, void *value)
Reads a basic-typed value from the message iterator.
void * dbus_message_get_data(DBusMessage *message, dbus_int32_t slot)
Retrieves data previously set with dbus_message_set_data().
void _dbus_type_reader_init(DBusTypeReader *reader, int byte_order, const DBusString *type_str, int type_pos, const DBusString *value_str, int value_pos)
Initializes a type reader.
void _dbus_header_free(DBusHeader *header)
Frees a header.
DBusList * _dbus_message_loader_pop_message_link(DBusMessageLoader *loader)
Pops a loaded message inside a list link (passing ownership of the message and link to the caller)...
#define DBUS_MAXIMUM_ARRAY_LENGTH
Max length of a marshaled array in bytes (64M, 2^26) We use signed int for lengths so must be INT_MAX...
dbus_bool_t dbus_message_set_destination(DBusMessage *message, const char *destination)
Sets the message's destination.
void dbus_error_init(DBusError *error)
Initializes a DBusError structure.
DBusAtomic refcount
Reference count.
dbus_bool_t dbus_message_get_no_reply(DBusMessage *message)
Returns TRUE if the message does not expect a reply.
const char * _dbus_string_get_const_data_len(const DBusString *str, int start, int len)
const version of _dbus_string_get_data_len().
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.
void dbus_free_string_array(char **str_array)
Frees a NULL-terminated array of strings.
#define DBUS_TYPE_BOOLEAN
Type code marking a boolean.
void _dbus_message_loader_get_buffer(DBusMessageLoader *loader, DBusString **buffer)
Gets the buffer to use for reading data from the network.
dbus_bool_t _dbus_string_append_len(DBusString *str, const char *buffer, int len)
Appends block of bytes with the given length to a DBusString.
dbus_uint32_t iter_type
whether this is a reader or writer iter
void _dbus_header_set_serial(DBusHeader *header, dbus_uint32_t serial)
Sets the serial number of a header.
int _dbus_type_reader_get_element_type(const DBusTypeReader *reader)
Gets the type of an element of the array the reader is currently pointing to.
char _dbus_header_get_byte_order(const DBusHeader *header)
Returns the header's byte order.
_DBUS_STRING_DEFINE_STATIC(_dbus_header_signature_str, DBUS_HEADER_SIGNATURE)
Static DBusString containing the signature of a message header.
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...
dbus_bool_t dbus_message_is_signal(DBusMessage *message, const char *interface, const char *signal_name)
Checks whether the message is a signal with the given interface and member fields.
dbus_bool_t _dbus_type_reader_has_next(const DBusTypeReader *reader)
Check whether there's another value on this "level".
A simple value union that lets you access bytes as if they were various types; useful when dealing wi...
dbus_uint32_t container_type
what are we inside? (e.g.
int _dbus_type_reader_get_array_length(const DBusTypeReader *reader)
Returns the number of bytes in the array.
dbus_bool_t _dbus_header_get_field_raw(DBusHeader *header, int field, const DBusString **str, int *pos)
Gets the raw marshaled data for a field.
dbus_bool_t dbus_message_iter_append_basic(DBusMessageIter *iter, int type, const void *value)
Appends a basic-typed value to the message.
int dbus_message_iter_get_array_len(DBusMessageIter *iter)
Returns the number of bytes in the array as marshaled in the wire protocol.
void(* DBusForeachFunction)(void *element, void *data)
Used to iterate over each item in a collection, such as a DBusList.
int _dbus_type_reader_get_current_type(const DBusTypeReader *reader)
Gets the type of the value the reader is currently pointing to; or for a types-only reader gets the t...
#define FALSE
Expands to "0".
#define DBUS_HEADER_FIELD_PATH
Header field code for the path - the path is the object emitting a signal or the object receiving a m...
int dbus_message_get_type(DBusMessage *message)
Gets the type of a message.
#define DBUS_HEADER_FIELD_REPLY_SERIAL
Header field code for a reply serial, used to match a DBUS_MESSAGE_TYPE_METHOD_RETURN message with th...
unsigned int buffer_outstanding
Someone is using the buffer to read.
int generation
_dbus_current_generation when message was created
void _dbus_list_prepend_link(DBusList **list, DBusList *link)
Prepends a link to the list.
dbus_bool_t _dbus_string_set_length(DBusString *str, int length)
Sets the length of a string.
dbus_bool_t _dbus_register_shutdown_func(DBusShutdownFunction function, void *data)
Register a cleanup function to be called exactly once the next time dbus_shutdown() is called...
#define _DBUS_LOCK(name)
Locks a global lock.
#define _DBUS_LOCK_NAME(name)
Expands to name of a global lock variable.
const char * _dbus_type_to_string(int typecode)
Returns a string describing the given type.
DBusMessage * _dbus_message_loader_peek_message(DBusMessageLoader *loader)
Peeks at first loaded message, returns NULL if no messages have been queued.
dbus_bool_t _dbus_string_copy_len(const DBusString *source, int start, int len, DBusString *dest, int insert_at)
Like _dbus_string_copy(), but can copy a segment from the middle of the source string.
dbus_bool_t _dbus_string_steal_data(DBusString *str, char **data_return)
Like _dbus_string_get_data(), but removes the gotten data from the original string.
void _dbus_type_reader_get_signature(const DBusTypeReader *reader, const DBusString **str_p, int *start_p, int *len_p)
Gets the string and range of said string containing the signature of the current value.
dbus_bool_t dbus_message_append_args_valist(DBusMessage *message, int first_arg_type, va_list var_args)
Like dbus_message_append_args() but takes a va_list for use by language bindings. ...
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.
char * dbus_message_iter_get_signature(DBusMessageIter *iter)
Returns the current signature of a message iterator.
dbus_bool_t _dbus_type_writer_write_fixed_multi(DBusTypeWriter *writer, int element_type, const void *value, int n_elements)
Writes a block of fixed-length basic values, i.e.
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...
void _dbus_verbose_bytes_of_string(const DBusString *str, int start, int len)
Dump the given part of the string to verbose log.
dbus_bool_t dbus_message_contains_unix_fds(DBusMessage *message)
Checks whether a message contains unix fds.
#define DBUS_HEADER_FLAG_NO_AUTO_START
If set, this flag means that even if the message bus knows how to start an owner for the destination ...
dbus_bool_t _dbus_message_loader_queue_messages(DBusMessageLoader *loader)
Converts buffered data into messages, if we have enough data.
void _dbus_message_get_unix_fds(DBusMessage *message, const int **fds, unsigned *n_fds)
Gets the unix fds to be sent over the network for this message.
int refcount
Reference count.
int dbus_int32_t
A 32-bit signed integer on all platforms.
char * _dbus_strdup(const char *str)
Duplicates a string.
#define MAX_MESSAGE_SIZE_TO_CACHE
Avoid caching huge messages.
#define DBUS_ERROR_INVALID_ARGS
Invalid arguments passed to a method call.
void _dbus_data_slot_allocator_free(DBusDataSlotAllocator *allocator, dbus_int32_t *slot_id_p)
Deallocates an ID previously allocated with _dbus_data_slot_allocator_alloc().
int _dbus_type_get_alignment(int typecode)
Gets the alignment requirement for the given type; will be 1, 4, or 8.
DBusValidity corruption_reason
why we were corrupted
void _dbus_message_loader_set_max_message_unix_fds(DBusMessageLoader *loader, long n)
Sets the maximum unix fds per message we allow.
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...
const char * _dbus_string_get_const_data(const DBusString *str)
Gets the raw character buffer from a const string.
const char * dbus_message_type_to_string(int type)
Utility function to convert a D-Bus message type into a machine-readable string (not translated)...
void dbus_message_unref(DBusMessage *message)
Decrements the reference count of a DBusMessage, freeing the message if the count reaches 0...
void _dbus_string_init_const_len(DBusString *str, const char *value, int len)
Initializes a constant string with a length.
Implementation details of DBusMessageLoader.
DBusMessage * dbus_message_new_method_call(const char *destination, const char *path, const char *interface, const char *method)
Constructs a new message to invoke a method on a remote object.
dbus_bool_t _dbus_type_writer_recurse(DBusTypeWriter *writer, int container_type, const DBusString *contained_type, int contained_type_start, DBusTypeWriter *sub)
Opens a new container and writes out the initial information for that container.
dbus_uint32_t u32
as int32
DBusMessage * dbus_message_new_error_printf(DBusMessage *reply_to, const char *error_name, const char *error_format,...)
Creates a new message that is an error reply to another message, allowing you to use printf formattin...
dbus_bool_t dbus_message_set_data(DBusMessage *message, dbus_int32_t slot, void *data, DBusFreeFunction free_data_func)
Stores a pointer on a DBusMessage, along with an optional function to be used for freeing the data wh...
void dbus_message_set_serial(DBusMessage *message, dbus_uint32_t serial)
Sets the serial number of a message.
void _dbus_header_toggle_flag(DBusHeader *header, dbus_uint32_t flag, dbus_bool_t value)
Toggles a message flag bit, turning on the bit if value = TRUE and flipping it off if value = FALSE...
void _dbus_header_update_lengths(DBusHeader *header, int body_len)
Fills in the correct body length.
DBusMessage * dbus_message_new_method_return(DBusMessage *method_call)
Constructs a message that is a reply to a method call.
DBusTypeWriter writer
writer
void _dbus_data_slot_list_free(DBusDataSlotList *list)
Frees the data slot list and all data slots contained in it, calling application-provided free functi...
#define DBUS_MAXIMUM_MESSAGE_LENGTH
The maximum total message size including header and body; similar rationale to max array size...
DBusDataSlotList slot_list
Data stored by allocated integer ID.
void _dbus_list_clear(DBusList **list)
Frees all links in the list and sets the list head to NULL.
void _dbus_marshal_byteswap(const DBusString *signature, int signature_start, int old_byte_order, int new_byte_order, DBusString *value_str, int value_pos)
Byteswaps the marshaled data in the given value_str.
dbus_bool_t dbus_type_is_container(int typecode)
A "container type" can contain basic types, or nested container types.
DBusMessage * dbus_message_new_error(DBusMessage *reply_to, const char *error_name, const char *error_message)
Creates a new message that is an error reply to another message.
void _dbus_counter_adjust_size(DBusCounter *counter, long delta)
Adjusts the value of the size counter by the given delta which may be positive or negative...