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.h" 39 #include "dbus-sysdeps-unix.h" 44 #define _DBUS_TYPE_IS_STRINGLIKE(type) \ 45 (type == DBUS_TYPE_STRING || type == DBUS_TYPE_SIGNATURE || \ 46 type == DBUS_TYPE_OBJECT_PATH) 48 static void dbus_message_finalize (
DBusMessage *message);
60 #ifdef DBUS_ENABLE_EMBEDDED_TESTS 62 _dbus_enable_message_cache (
void)
64 static int enabled = -1;
79 _dbus_warn (
"DBUS_MESSAGE_CACHE should be 0 or 1 if set, not '%s'",
88 # define _dbus_enable_message_cache() (TRUE) 91 #ifndef _dbus_message_trace_ref 98 static int enabled = -1;
100 _dbus_trace_ref (
"DBusMessage", message, old_refcount, new_refcount, why,
101 "DBUS_MESSAGE_TRACE", &enabled);
114 DBUS_MESSAGE_ITER_TYPE_READER = 3,
115 DBUS_MESSAGE_ITER_TYPE_WRITER = 7
148 dbus_uint32_t dummy3;
176 *type_str_p = &_dbus_empty_signature_str;
195 if (byte_order == DBUS_COMPILER_BYTE_ORDER)
198 _dbus_verbose (
"Swapping message into compiler byte order\n");
200 get_const_signature (&message->
header, &type_str, &type_pos);
204 DBUS_COMPILER_BYTE_ORDER,
209 DBUS_COMPILER_BYTE_ORDER);
218 #define ensure_byte_order(message) _dbus_message_byteswap (message) 238 *body = &message->
body;
256 #ifdef HAVE_UNIX_FD_PASSING 257 *fds = message->unix_fds;
258 *n_fds = message->n_unix_fds;
278 dbus_uint32_t serial)
280 _dbus_return_if_fail (message !=
NULL);
281 _dbus_return_if_fail (!message->
locked);
315 _dbus_string_get_length (&message->
header.
data) +
316 _dbus_string_get_length (&message->
body);
318 #ifdef HAVE_UNIX_FD_PASSING 319 message->unix_fd_counter_delta = message->n_unix_fds;
323 _dbus_verbose (
"message has size %ld\n",
332 #ifdef HAVE_UNIX_FD_PASSING 388 #ifdef HAVE_UNIX_FD_PASSING 412 _dbus_string_get_length (&message->
body));
484 #define MAX_MESSAGE_SIZE_TO_CACHE 10 * _DBUS_ONE_KILOBYTE 487 #define MAX_MESSAGE_CACHE_SIZE 5 491 static int message_cache_count = 0;
495 dbus_message_cache_shutdown (
void *data)
501 "before registering a shutdown function");
506 if (message_cache[i])
507 dbus_message_finalize (message_cache[i]);
512 message_cache_count = 0;
513 message_cache_shutdown_registered =
FALSE;
526 dbus_message_get_cached (
void)
542 if (message_cache_count == 0)
557 if (message_cache[i])
559 message = message_cache[i];
560 message_cache[i] =
NULL;
561 message_cache_count -= 1;
579 #ifdef HAVE_UNIX_FD_PASSING 581 close_unix_fds(
int *fds,
unsigned *n_fds)
591 for (i = 0; i < *n_fds; i++)
607 free_counter (
void *element,
614 #ifdef HAVE_UNIX_FD_PASSING 628 dbus_message_cache_or_finalize (
DBusMessage *message)
641 free_counter, message);
644 #ifdef HAVE_UNIX_FD_PASSING 645 close_unix_fds(message->unix_fds, &message->n_unix_fds);
655 "the first time we constructed a message");
658 if (!message_cache_shutdown_registered)
668 message_cache[i] =
NULL;
672 message_cache_shutdown_registered =
TRUE;
677 if (!_dbus_enable_message_cache ())
680 if ((_dbus_string_get_length (&message->
header.
data) +
681 _dbus_string_get_length (&message->
body)) >
690 while (message_cache[i] !=
NULL)
697 message_cache_count += 1;
699 #ifndef DBUS_DISABLE_CHECKS 709 dbus_message_finalize (message);
733 _dbus_return_if_fail (iter !=
NULL);
744 #if defined(DBUS_ENABLE_CHECKS) || defined(DBUS_ENABLE_ASSERT) 759 "closed, or is uninitialized or corrupt");
765 if (iter->
iter_type == DBUS_MESSAGE_ITER_TYPE_READER)
775 else if (iter->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER)
793 _dbus_warn_check_failed (
"dbus message iterator invalid because the message has been modified (or perhaps the iterator is just uninitialized)");
820 int spec_type, msg_type, i, j;
828 spec_type = first_arg_type;
834 DBUS_VA_COPY (copy_args, var_args);
840 if (msg_type != spec_type)
843 "Argument %d is specified to be of type \"%s\", but " 844 "is actually of type \"%s\"\n", i,
853 #ifdef HAVE_UNIX_FD_PASSING 857 pfd = va_arg (var_args,
int*);
865 "Message refers to file descriptor at index %i," 866 "but has only %i descriptors attached.\n",
878 "Platform does not support file desciptor passing.\n");
896 int spec_element_type;
901 spec_element_type = va_arg (var_args,
int);
904 if (spec_element_type != element_type)
907 "Argument %d is specified to be an array of \"%s\", but " 908 "is actually an array of \"%s\"\n",
920 n_elements_p = va_arg (var_args,
int*);
928 (
void *) ptr, n_elements_p);
930 else if (_DBUS_TYPE_IS_STRINGLIKE (spec_element_type))
936 str_array_p = va_arg (var_args,
char***);
937 n_elements_p = va_arg (var_args,
int*);
952 str_array =
dbus_new0 (
char*, n_elements + 1);
953 if (str_array ==
NULL)
955 _DBUS_SET_OOM (error);
963 while (j < n_elements)
970 if (str_array[j] ==
NULL)
973 _DBUS_SET_OOM (error);
987 *str_array_p = str_array;
988 *n_elements_p = n_elements;
990 #ifndef DBUS_DISABLE_CHECKS 993 _dbus_warn (
"you can't read arrays of container types (struct, variant, array) with %s for now",
994 _DBUS_FUNCTION_NAME);
999 #ifndef DBUS_DISABLE_CHECKS 1002 _dbus_warn (
"you can only read arrays and basic types with %s for now",
1003 _DBUS_FUNCTION_NAME);
1011 spec_type = va_arg (var_args,
int);
1015 "Message has only %d arguments, but more were expected", i);
1029 spec_type = first_arg_type;
1036 #ifdef HAVE_UNIX_FD_PASSING 1039 pfd = va_arg (copy_args,
int *);
1055 int spec_element_type;
1057 spec_element_type = va_arg (copy_args,
int);
1062 va_arg (copy_args,
int *);
1064 else if (_DBUS_TYPE_IS_STRINGLIKE (spec_element_type))
1066 char ***str_array_p;
1068 str_array_p = va_arg (copy_args,
char ***);
1070 va_arg (copy_args,
int *);
1073 *str_array_p =
NULL;
1077 spec_type = va_arg (copy_args,
int);
1147 _dbus_return_val_if_fail (message !=
NULL, 0);
1162 dbus_uint32_t reply_serial)
1166 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
1167 _dbus_return_val_if_fail (!message->
locked,
FALSE);
1168 _dbus_return_val_if_fail (reply_serial != 0,
FALSE);
1170 value.
u32 = reply_serial;
1187 dbus_uint32_t v_UINT32;
1189 _dbus_return_val_if_fail (message !=
NULL, 0);
1209 free_counter, message);
1215 #ifdef HAVE_UNIX_FD_PASSING 1216 close_unix_fds(message->unix_fds, &message->n_unix_fds);
1226 dbus_message_new_empty_header (
void)
1231 message = dbus_message_get_cached ();
1233 if (message !=
NULL)
1241 if (message ==
NULL)
1243 #ifndef DBUS_DISABLE_CHECKS 1247 #ifdef HAVE_UNIX_FD_PASSING 1248 message->unix_fds =
NULL;
1249 message->n_unix_fds_allocated = 0;
1255 _dbus_message_trace_ref (message, 0, 1,
"new_empty_header");
1258 #ifndef DBUS_DISABLE_CHECKS 1265 #ifdef HAVE_UNIX_FD_PASSING 1266 message->n_unix_fds = 0;
1267 message->n_unix_fds_allocated = 0;
1268 message->unix_fd_counter_delta = 0;
1317 message = dbus_message_new_empty_header ();
1318 if (message ==
NULL)
1322 DBUS_COMPILER_BYTE_ORDER,
1362 _dbus_return_val_if_fail (path !=
NULL,
NULL);
1363 _dbus_return_val_if_fail (method !=
NULL,
NULL);
1364 _dbus_return_val_if_fail (destination ==
NULL ||
1365 _dbus_check_is_valid_bus_name (destination),
NULL);
1366 _dbus_return_val_if_fail (_dbus_check_is_valid_path (path),
NULL);
1367 _dbus_return_val_if_fail (iface ==
NULL ||
1368 _dbus_check_is_valid_interface (iface),
NULL);
1369 _dbus_return_val_if_fail (_dbus_check_is_valid_member (method),
NULL);
1371 message = dbus_message_new_empty_header ();
1372 if (message ==
NULL)
1376 DBUS_COMPILER_BYTE_ORDER,
1378 destination, path, iface, method,
NULL))
1400 _dbus_return_val_if_fail (method_call !=
NULL,
NULL);
1406 message = dbus_message_new_empty_header ();
1407 if (message ==
NULL)
1411 DBUS_COMPILER_BYTE_ORDER,
1452 _dbus_return_val_if_fail (path !=
NULL,
NULL);
1453 _dbus_return_val_if_fail (iface !=
NULL,
NULL);
1454 _dbus_return_val_if_fail (name !=
NULL,
NULL);
1455 _dbus_return_val_if_fail (_dbus_check_is_valid_path (path),
NULL);
1456 _dbus_return_val_if_fail (_dbus_check_is_valid_interface (iface),
NULL);
1457 _dbus_return_val_if_fail (_dbus_check_is_valid_member (name),
NULL);
1459 message = dbus_message_new_empty_header ();
1460 if (message ==
NULL)
1464 DBUS_COMPILER_BYTE_ORDER,
1493 const char *error_name,
1494 const char *error_message)
1500 _dbus_return_val_if_fail (reply_to !=
NULL,
NULL);
1501 _dbus_return_val_if_fail (error_name !=
NULL,
NULL);
1502 _dbus_return_val_if_fail (_dbus_check_is_valid_error_name (error_name),
NULL);
1510 message = dbus_message_new_empty_header ();
1511 if (message ==
NULL)
1515 DBUS_COMPILER_BYTE_ORDER,
1532 if (error_message !=
NULL)
1565 const char *error_name,
1566 const char *error_format,
1573 _dbus_return_val_if_fail (reply_to !=
NULL,
NULL);
1574 _dbus_return_val_if_fail (error_name !=
NULL,
NULL);
1575 _dbus_return_val_if_fail (_dbus_check_is_valid_error_name (error_name),
NULL);
1580 va_start (args, error_format);
1584 _dbus_string_get_const_data (&str));
1613 _dbus_return_val_if_fail (message !=
NULL,
NULL);
1622 #ifndef DBUS_DISABLE_CHECKS 1633 _dbus_string_get_length (&message->
body)))
1644 #ifdef HAVE_UNIX_FD_PASSING 1645 retval->unix_fds =
dbus_new(
int, message->n_unix_fds);
1646 if (retval->unix_fds ==
NULL && message->n_unix_fds > 0)
1649 retval->n_unix_fds_allocated = message->n_unix_fds;
1651 for (retval->n_unix_fds = 0;
1652 retval->n_unix_fds < message->n_unix_fds;
1653 retval->n_unix_fds++)
1655 retval->unix_fds[retval->n_unix_fds] =
_dbus_dup(message->unix_fds[retval->n_unix_fds],
NULL);
1657 if (retval->unix_fds[retval->n_unix_fds] < 0)
1663 _dbus_message_trace_ref (retval, 0, 1,
"copy");
1670 #ifdef HAVE_UNIX_FD_PASSING 1671 close_unix_fds(retval->unix_fds, &retval->n_unix_fds);
1691 dbus_int32_t old_refcount;
1693 _dbus_return_val_if_fail (message !=
NULL,
NULL);
1699 _dbus_message_trace_ref (message, old_refcount, old_refcount + 1,
"ref");
1714 dbus_int32_t old_refcount;
1716 _dbus_return_if_fail (message !=
NULL);
1718 _dbus_return_if_fail (!message->
in_cache);
1724 _dbus_message_trace_ref (message, old_refcount, old_refcount - 1,
"unref");
1726 if (old_refcount == 1)
1729 dbus_message_cache_or_finalize (message);
1827 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
1829 va_start (var_args, first_arg_type);
1859 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
1861 type = first_arg_type;
1883 element_type = va_arg (var_args,
int);
1885 buf[0] = element_type;
1900 n_elements = va_arg (var_args,
int);
1910 else if (_DBUS_TYPE_IS_STRINGLIKE (element_type))
1912 const char ***value_p;
1917 value_p = va_arg (var_args,
const char***);
1918 n_elements = va_arg (var_args,
int);
1923 while (i < n_elements)
1936 _dbus_warn (
"arrays of %s can't be appended with %s for now",
1938 _DBUS_FUNCTION_NAME);
1946 #ifndef DBUS_DISABLE_CHECKS 1949 _dbus_warn (
"type %s isn't supported yet in %s",
1955 type = va_arg (var_args,
int);
2017 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
2018 _dbus_return_val_if_error_is_set (error,
FALSE);
2020 va_start (var_args, first_arg_type);
2045 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
2046 _dbus_return_val_if_error_is_set (error,
FALSE);
2053 _dbus_message_iter_init_common (
DBusMessage *message,
2071 4 *
sizeof (
void *) +
sizeof (dbus_uint32_t) + 9 *
sizeof (
int));
2114 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
2115 _dbus_return_val_if_fail (iter !=
NULL,
FALSE);
2117 get_const_signature (&message->
header, &type_str, &type_pos);
2119 _dbus_message_iter_init_common (message, real,
2120 DBUS_MESSAGE_ITER_TYPE_READER);
2142 _dbus_return_val_if_fail (_dbus_message_iter_check (real),
FALSE);
2143 _dbus_return_val_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_READER,
FALSE);
2161 _dbus_return_val_if_fail (_dbus_message_iter_check (real),
FALSE);
2162 _dbus_return_val_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_READER,
FALSE);
2187 _dbus_return_val_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_READER,
FALSE);
2244 _dbus_return_if_fail (_dbus_message_iter_check (real));
2245 _dbus_return_if_fail (sub !=
NULL);
2271 _dbus_return_val_if_fail (_dbus_message_iter_check (real),
NULL);
2279 _dbus_string_get_const_data (sig) + start,
2341 _dbus_return_if_fail (_dbus_message_iter_check (real));
2342 _dbus_return_if_fail (value !=
NULL);
2346 #ifdef HAVE_UNIX_FD_PASSING 2354 *((
int*) value) = -1;
2360 *((
int*) value) = -1;
2388 _dbus_return_val_if_fail (_dbus_message_iter_check (real), 0);
2398 n_elements = total_len / alignment;
2429 _dbus_return_val_if_fail (_dbus_message_iter_check (real), 0);
2475 #ifndef DBUS_DISABLE_CHECKS 2478 _dbus_return_if_fail (_dbus_message_iter_check (real));
2479 _dbus_return_if_fail (value !=
NULL);
2505 _dbus_return_if_fail (message !=
NULL);
2506 _dbus_return_if_fail (iter !=
NULL);
2508 _dbus_message_iter_init_common (message, real,
2509 DBUS_MESSAGE_ITER_TYPE_WRITER);
2518 _dbus_string_get_length (&message->
body));
2534 int current_sig_pos;
2551 ¤t_sig, ¤t_sig_pos))
2558 current_len = _dbus_string_get_byte (current_sig, current_sig_pos);
2559 current_sig_pos += 1;
2590 str, _dbus_string_get_length (str));
2607 const char *v_STRING;
2624 v_STRING = _dbus_string_get_const_data (str);
2667 #ifndef DBUS_DISABLE_CHECKS 2671 if (!_dbus_message_iter_check (iter))
2684 #ifdef HAVE_UNIX_FD_PASSING 2694 if (m->n_unix_fds + n > m->n_unix_fds_allocated)
2700 k = (m->n_unix_fds + n) * 2;
2711 m->n_unix_fds_allocated = k;
2714 return m->unix_fds + m->n_unix_fds;
2745 _dbus_return_val_if_fail (_dbus_message_iter_append_check (real),
FALSE);
2746 _dbus_return_val_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER,
FALSE);
2748 _dbus_return_val_if_fail (value !=
NULL,
FALSE);
2750 #ifndef DBUS_DISABLE_CHECKS 2755 const char *
const *string_p;
2760 _dbus_return_val_if_fail (_dbus_check_is_valid_utf8 (*string_p),
FALSE);
2765 _dbus_return_val_if_fail (_dbus_check_is_valid_path (*string_p),
FALSE);
2773 _dbus_string_get_length (&str));
2783 _dbus_return_val_if_fail (*bool_p == 0 || *bool_p == 1,
FALSE);
2793 if (!_dbus_message_iter_open_signature (real))
2798 #ifdef HAVE_UNIX_FD_PASSING 2805 if (!(fds = expand_fd_array(real->
message, 1)))
2812 u = real->
message->n_unix_fds;
2820 real->
message->n_unix_fds += 1;
2847 if (!_dbus_message_iter_close_signature (real))
2897 _dbus_return_val_if_fail (_dbus_message_iter_append_check (real),
FALSE);
2898 _dbus_return_val_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER,
FALSE);
2901 _dbus_return_val_if_fail (value !=
NULL,
FALSE);
2902 _dbus_return_val_if_fail (n_elements >= 0,
FALSE);
2903 _dbus_return_val_if_fail (n_elements <=
2907 #ifndef DBUS_DISABLE_CHECKS 2913 for (i = 0; i < n_elements; i++)
2915 _dbus_return_val_if_fail ((*bools)[i] == 0 || (*bools)[i] == 1,
FALSE);
2955 const char *contained_signature,
2964 _dbus_return_val_if_fail (sub !=
NULL,
FALSE);
2967 _dbus_message_real_iter_zero (real_sub);
2969 _dbus_return_val_if_fail (_dbus_message_iter_append_check (real),
FALSE);
2970 _dbus_return_val_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER,
FALSE);
2973 contained_signature ==
NULL) ||
2975 contained_signature ==
NULL) ||
2977 contained_signature !=
NULL) ||
2985 if (contained_signature !=
NULL)
2990 _dbus_string_get_length (&contained_str));
2998 contained_signature_validity = DBUS_VALID_BUT_INCOMPLETE;
3002 contained_signature ==
NULL ||
3006 if (!_dbus_message_iter_open_signature (real))
3012 if (contained_signature !=
NULL)
3030 _dbus_message_iter_abandon_signature (real);
3063 _dbus_return_val_if_fail (_dbus_message_iter_append_check (real),
FALSE);
3064 _dbus_return_val_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER,
FALSE);
3065 _dbus_return_val_if_fail (_dbus_message_iter_append_check (real_sub),
FALSE);
3066 _dbus_return_val_if_fail (real_sub->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER,
FALSE);
3070 _dbus_message_real_iter_zero (real_sub);
3072 if (!_dbus_message_iter_close_signature (real))
3096 #ifndef DBUS_DISABLE_CHECKS 3097 _dbus_return_if_fail (_dbus_message_iter_append_check (real));
3098 _dbus_return_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER);
3099 _dbus_return_if_fail (_dbus_message_iter_append_check (real_sub));
3100 _dbus_return_if_fail (real_sub->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER);
3103 _dbus_message_iter_abandon_signature (real);
3104 _dbus_message_real_iter_zero (real_sub);
3161 if (_dbus_message_real_iter_is_zeroed (real) &&
3162 _dbus_message_real_iter_is_zeroed (real_sub))
3165 #ifndef DBUS_DISABLE_CHECKS 3170 _dbus_return_if_fail (_dbus_message_iter_append_check (real));
3171 _dbus_return_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER);
3181 if (_dbus_message_real_iter_is_zeroed (real_sub))
3184 #ifndef DBUS_DISABLE_CHECKS 3185 _dbus_return_if_fail (_dbus_message_iter_append_check (real_sub));
3186 _dbus_return_if_fail (real_sub->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER);
3193 _dbus_message_iter_abandon_signature (real);
3194 _dbus_message_real_iter_zero (real_sub);
3217 _dbus_return_if_fail (message !=
NULL);
3218 _dbus_return_if_fail (!message->
locked);
3235 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3259 _dbus_return_if_fail (message !=
NULL);
3260 _dbus_return_if_fail (!message->
locked);
3277 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3298 const char *object_path)
3300 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3301 _dbus_return_val_if_fail (!message->
locked,
FALSE);
3302 _dbus_return_val_if_fail (object_path ==
NULL ||
3303 _dbus_check_is_valid_path (object_path),
3306 return set_or_delete_string_field (message,
3330 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3353 const char *msg_path;
3356 if (msg_path ==
NULL)
3367 if (strcmp (msg_path, path) == 0)
3399 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3400 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
3431 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3432 _dbus_return_val_if_fail (!message->
locked,
FALSE);
3433 _dbus_return_val_if_fail (iface ==
NULL ||
3434 _dbus_check_is_valid_interface (iface),
3437 return set_or_delete_string_field (message,
3461 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3482 const char *msg_interface;
3485 if (msg_interface ==
NULL)
3496 if (strcmp (msg_interface, iface) == 0)
3519 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3520 _dbus_return_val_if_fail (!message->
locked,
FALSE);
3521 _dbus_return_val_if_fail (member ==
NULL ||
3522 _dbus_check_is_valid_member (member),
3525 return set_or_delete_string_field (message,
3547 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3568 const char *msg_member;
3571 if (msg_member ==
NULL)
3582 if (strcmp (msg_member, member) == 0)
3602 const char *error_name)
3604 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3605 _dbus_return_val_if_fail (!message->
locked,
FALSE);
3606 _dbus_return_val_if_fail (error_name ==
NULL ||
3607 _dbus_check_is_valid_error_name (error_name),
3610 return set_or_delete_string_field (message,
3631 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3656 const char *destination)
3658 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3659 _dbus_return_val_if_fail (!message->
locked,
FALSE);
3660 _dbus_return_val_if_fail (destination ==
NULL ||
3661 _dbus_check_is_valid_bus_name (destination),
3664 return set_or_delete_string_field (message,
3684 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3712 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3713 _dbus_return_val_if_fail (!message->
locked,
FALSE);
3714 _dbus_return_val_if_fail (sender ==
NULL ||
3715 _dbus_check_is_valid_bus_name (sender),
3718 return set_or_delete_string_field (message,
3744 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3778 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3780 get_const_signature (&message->
header, &type_str, &type_pos);
3782 return _dbus_string_get_const_data_len (type_str, type_pos, 0);
3786 _dbus_message_has_type_interface_member (
DBusMessage *message,
3806 if (n && strcmp (n, member) == 0)
3810 if (n ==
NULL || strcmp (n, iface) == 0)
3836 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3837 _dbus_return_val_if_fail (iface !=
NULL,
FALSE);
3838 _dbus_return_val_if_fail (method !=
NULL,
FALSE);
3843 return _dbus_message_has_type_interface_member (message,
3862 const char *signal_name)
3864 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3865 _dbus_return_val_if_fail (iface !=
NULL,
FALSE);
3866 _dbus_return_val_if_fail (signal_name !=
NULL,
FALSE);
3871 return _dbus_message_has_type_interface_member (message,
3873 iface, signal_name);
3888 const char *error_name)
3892 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3893 _dbus_return_val_if_fail (error_name !=
NULL,
FALSE);
3903 if (n && strcmp (n, error_name) == 0)
3925 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3926 _dbus_return_val_if_fail (name !=
NULL,
FALSE);
3933 if (s && strcmp (s, name) == 0)
3960 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3961 _dbus_return_val_if_fail (name !=
NULL,
FALSE);
3968 if (s && strcmp (s, name) == 0)
3985 const char *signature)
3989 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3990 _dbus_return_val_if_fail (signature !=
NULL,
FALSE);
3997 if (s && strcmp (s, signature) == 0)
4031 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
4032 _dbus_return_val_if_error_is_set (error,
FALSE);
4043 str ?
"%s" :
NULL, str);
4057 #ifdef HAVE_UNIX_FD_PASSING 4060 return message->n_unix_fds > 0;
4084 #define INITIAL_LOADER_DATA_LEN 32 4125 #ifdef HAVE_UNIX_FD_PASSING 4126 loader->unix_fds =
NULL;
4127 loader->n_unix_fds = loader->n_unix_fds_allocated = 0;
4128 loader->unix_fds_outstanding =
FALSE;
4160 #ifdef HAVE_UNIX_FD_PASSING 4161 close_unix_fds(loader->unix_fds, &loader->n_unix_fds);
4199 *buffer = &loader->
data;
4203 if (max_to_read !=
NULL)
4205 #ifdef HAVE_UNIX_FD_PASSING 4209 int fields_array_len;
4215 *may_read_fds =
TRUE;
4217 #ifdef HAVE_UNIX_FD_PASSING 4220 if (loader->n_unix_fds == 0)
4231 remain = _dbus_string_get_length (&loader->
data);
4245 *may_read_fds =
FALSE;
4269 needed = header_len + body_len;
4271 *max_to_read = needed - remain;
4272 *may_read_fds =
FALSE;
4278 needed = header_len + body_len;
4307 #ifdef HAVE_UNIX_FD_PASSING 4321 unsigned *max_n_fds)
4341 loader->unix_fds = a;
4345 *fds = loader->unix_fds + loader->n_unix_fds;
4346 *max_n_fds = loader->n_unix_fds_allocated - loader->n_unix_fds;
4348 loader->unix_fds_outstanding =
TRUE;
4368 _dbus_assert(loader->unix_fds + loader->n_unix_fds == fds);
4369 _dbus_assert(loader->n_unix_fds + n_fds <= loader->n_unix_fds_allocated);
4371 loader->n_unix_fds += n_fds;
4372 loader->unix_fds_outstanding =
FALSE;
4374 if (n_fds && loader->unix_fds_change)
4375 loader->unix_fds_change (loader->unix_fds_change_data);
4409 int fields_array_len,
4418 dbus_uint32_t n_unix_fds = 0;
4420 mode = DBUS_VALIDATION_MODE_DATA_IS_UNTRUSTED;
4430 _dbus_assert ((header_len + body_len) <= _dbus_string_get_length (&loader->
data));
4440 _dbus_string_get_length (&loader->
data)))
4442 _dbus_verbose (
"Failed to load header for new message code %d\n", validity);
4461 if (mode != DBUS_VALIDATION_MODE_WE_TRUST_THIS_DATA_ABSOLUTELY)
4463 get_const_signature (&message->
header, &type_str, &type_pos);
4477 _dbus_verbose (
"Failed to validate message body code %d\n", validity);
4492 #ifdef HAVE_UNIX_FD_PASSING 4494 if (n_unix_fds > loader->n_unix_fds)
4496 _dbus_verbose(
"Message contains references to more unix fds than were sent %u != %u\n",
4497 n_unix_fds, loader->n_unix_fds);
4510 message->unix_fds =
_dbus_memdup(loader->unix_fds, n_unix_fds *
sizeof(message->unix_fds[0]));
4511 if (message->unix_fds ==
NULL)
4513 _dbus_verbose (
"Failed to allocate file descriptor array\n");
4518 message->n_unix_fds_allocated = message->n_unix_fds = n_unix_fds;
4519 loader->n_unix_fds -= n_unix_fds;
4520 memmove (loader->unix_fds, loader->unix_fds + n_unix_fds, loader->n_unix_fds * sizeof (loader->unix_fds[0]));
4522 if (loader->unix_fds_change)
4523 loader->unix_fds_change (loader->unix_fds_change_data);
4526 message->unix_fds =
NULL;
4532 _dbus_verbose (
"Hmm, message claims to come with file descriptors " 4533 "but that's not supported on our platform, disconnecting.\n");
4546 _dbus_verbose (
"Failed to append new message to loader queue\n");
4553 (header_len + body_len));
4557 _dbus_verbose (
"Failed to move body into new message\n");
4570 _dbus_verbose (
"Loaded message %p\n", message);
4617 int byte_order, fields_array_len, header_len, body_len;
4626 _dbus_string_get_length (&loader->
data)))
4632 message = dbus_message_new_empty_header ();
4633 if (message ==
NULL)
4636 if (!load_message (loader, message,
4637 byte_order, fields_array_len,
4638 header_len, body_len))
4652 _dbus_verbose (
"Initial peek at header says we don't have a whole message yet, or data broken with invalid code %d\n",
4767 _dbus_verbose (
"clamping requested max message size %ld to %d\n",
4798 _dbus_verbose (
"clamping requested max message unix_fds %ld to %d\n",
4825 #ifdef HAVE_UNIX_FD_PASSING 4826 return loader->n_unix_fds;
4842 void (* callback) (
void *),
4845 #ifdef HAVE_UNIX_FD_PASSING 4846 loader->unix_fds_change = callback;
4847 loader->unix_fds_change_data = data;
4889 _dbus_return_if_fail (*slot_p >= 0);
4917 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
4918 _dbus_return_val_if_fail (slot >= 0,
FALSE);
4922 slot, data, free_data_func,
4923 &old_free_func, &old_data);
4929 (* old_free_func) (old_data);
4949 _dbus_return_val_if_fail (message !=
NULL,
NULL);
4974 if (strcmp (type_str,
"method_call") == 0)
4976 if (strcmp (type_str,
"method_return") == 0)
4978 else if (strcmp (type_str,
"signal") == 0)
4980 else if (strcmp (type_str,
"error") == 0)
5005 return "method_call";
5007 return "method_return";
5031 char **marshalled_data_p,
5037 _dbus_return_val_if_fail (msg !=
NULL,
FALSE);
5038 _dbus_return_val_if_fail (marshalled_data_p !=
NULL,
FALSE);
5039 _dbus_return_val_if_fail (len_p !=
NULL,
FALSE);
5045 was_locked = msg->
locked;
5053 *len_p = _dbus_string_get_length (&tmp);
5058 *len_p = _dbus_string_get_length (&tmp);
5100 _dbus_return_val_if_fail (str !=
NULL,
NULL);
5135 _DBUS_SET_OOM (error);
5160 int byte_order, fields_array_len, header_len, body_len;
5174 &validity, &byte_order,
5184 _dbus_assert (have_message || (header_len + body_len) > len);
5185 (void) have_message;
5186 return header_len + body_len;
5219 _dbus_return_if_fail (message !=
NULL);
5220 _dbus_return_if_fail (!message->
locked);
5236 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
5312 &variant_signature, 0, &self->data, 0);
5315 &contained_signature, 0, &variant_writer))
5331 &contained_signature, 1, &array_writer))
5335 &real_array_reader->
u.
reader))
5359 &real_inner_reader->
u.
reader))
5410 len = _dbus_string_get_byte (&self->data, 0);
5411 ret = _dbus_string_get_const_data_len (&self->data, 1, len);
5442 _dbus_assert (_dbus_message_iter_append_check (real_writer));
5447 &variant_signature, 0, &self->data, 0);
5450 if (!_dbus_message_iter_open_signature (real_writer))
5456 if (!_dbus_message_iter_close_signature (real_writer))
5466 return _dbus_string_get_length (&self->data);
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...
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...
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...
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_uint32_t changed_stamp
Incremented when iterators are invalidated.
#define NULL
A null pointer, defined appropriately for C or C++.
dbus_bool_t dbus_message_is_method_call(DBusMessage *message, const char *iface, const char *method)
Checks whether the message is a method call with the given interface and member fields.
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_message_loader_return_buffer(DBusMessageLoader *loader, DBusString *buffer)
Returns a buffer obtained from _dbus_message_loader_get_buffer(), indicating to the loader how many b...
void _dbus_type_writer_remove_types(DBusTypeWriter *writer)
Removes type string from the writer.
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
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.
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...
#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_variant_get_signature(DBusVariant *self)
Return the signature of the item stored in self.
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_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.
#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...
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...
An opaque data structure containing the serialized form of any single D-Bus message item...
union DBusMessageRealIter::@6 u
the type writer or reader that does all the work
Layout of a DBusMessageIter on the stack in dbus 1.10.0.
dbus_bool_t dbus_message_get_allow_interactive_authorization(DBusMessage *message)
Returns whether the flag controlled by dbus_message_set_allow_interactive_authorization() has been se...
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.
dbus_bool_t dbus_message_has_interface(DBusMessage *message, const char *iface)
Checks if the message has an interface.
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()
DBusMessage * dbus_message_new_signal(const char *path, const char *iface, const char *name)
Constructs a new message representing a signal emission.
_DBUS_STRING_DEFINE_STATIC(_dbus_empty_signature_str, "")
An static string representing an empty signature.
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.
int _dbus_dup(int fd, DBusError *error)
Duplicates a file descriptor.
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_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_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).
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.
void _dbus_type_writer_init_values_only(DBusTypeWriter *writer, int byte_order, const DBusString *type_str, int type_pos, DBusString *value_str, int value_pos)
Like _dbus_type_writer_init(), except the type string passed in should correspond to an existing sign...
#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.
dbus_bool_t dbus_message_is_signal(DBusMessage *message, const char *iface, const char *signal_name)
Checks whether the message is a signal with the given interface and member fields.
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...
#define DBUS_TYPE_VARIANT_AS_STRING
DBUS_TYPE_VARIANT as a string literal instead of a int literal
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_int32_t _dbus_atomic_inc(DBusAtomic *atomic)
Atomically increments an integer.
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...
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)
int dbus_message_iter_get_element_count(DBusMessageIter *iter)
Returns the number of elements in the array-typed value pointed to by the iterator.
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.
void _dbus_message_loader_set_pending_fds_function(DBusMessageLoader *loader, void(*callback)(void *), void *data)
Register a function to be called whenever the number of pending file descriptors in the loader change...
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_message_iter_init_closed(DBusMessageIter *iter)
Initialize iter as if with DBUS_MESSAGE_ITER_INIT_CLOSED.
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_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.
dbus_bool_t _dbus_variant_write(DBusVariant *self, DBusMessageIter *writer)
Copy the single D-Bus message item from self into writer.
#define DBUS_TYPE_UINT32
Type code marking a 32-bit unsigned integer.
void _dbus_header_reinit(DBusHeader *header)
Re-initializes a header that was previously initialized and never freed.
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.
#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_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()
#define DBUS_HEADER_FLAG_ALLOW_INTERACTIVE_AUTHORIZATION
If set on a method call, this flag means that the caller is prepared to wait for interactive authoriz...
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_message_iter_abandon_container_if_open(DBusMessageIter *iter, DBusMessageIter *sub)
Abandons creation of a contained-typed value and frees resources created by dbus_message_iter_open_co...
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.
#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.
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.
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...
dbus_bool_t _dbus_type_writer_write_reader(DBusTypeWriter *writer, DBusTypeReader *reader)
Iterate through all values in the given reader, writing a copy of each value to the writer...
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).
DBusVariant * _dbus_variant_read(DBusMessageIter *reader)
Copy a single D-Bus message item from reader into a newly-allocated DBusVariant.
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.
DBusValidity _dbus_validate_signature_with_reason(const DBusString *type_str, int type_pos, int len)
Verifies that the range of type_str from type_pos to type_end is a valid signature.
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.
dbus_int32_t _dbus_atomic_dec(DBusAtomic *atomic)
Atomically decrement an integer.
DBusAtomic refcount
Reference count.
dbus_bool_t dbus_message_get_no_reply(DBusMessage *message)
Returns TRUE if the message does not expect a reply.
void dbus_free_string_array(char **str_array)
Frees a NULL-terminated array of strings.
#define DBUS_TYPE_BOOLEAN
Type code marking a boolean.
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_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.
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.
dbus_bool_t _dbus_close(int fd, DBusError *error)
Closes a file descriptor.
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".
void dbus_message_set_allow_interactive_authorization(DBusMessage *message, dbus_bool_t allow)
Sets a flag indicating that the caller of the method is prepared to wait for interactive authorizatio...
#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_PRIVATE_EXPORT 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, initializing it first if necessary.
#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_message_loader_get_buffer(DBusMessageLoader *loader, DBusString **buffer, int *max_to_read, dbus_bool_t *may_read_fds)
Gets the buffer to use for reading data from the network.
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.
dbus_int32_t _dbus_atomic_get(DBusAtomic *atomic)
Atomically get the value of an integer.
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...
DBUS_PRIVATE_EXPORT void _dbus_verbose_bytes_of_string(const DBusString *str, int start, int len)
Dump the given part of the string to verbose log.
dbus_bool_t _dbus_data_slot_allocator_alloc(DBusDataSlotAllocator *allocator, dbus_int32_t *slot_id_p)
Allocates an integer ID to be used for storing data in a DBusDataSlotList.
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_realloc(void *memory, size_t bytes)
Resizes a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
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.
char * _dbus_strdup(const char *str)
Duplicates a string.
#define _DBUS_ZERO(object)
Sets all bits in an object to zero.
#define MAX_MESSAGE_SIZE_TO_CACHE
Avoid caching huge messages.
const char * _dbus_getenv(const char *varname)
Wrapper for getenv().
#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_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.
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.
int _dbus_message_loader_get_pending_fds_count(DBusMessageLoader *loader)
Return how many file descriptors are pending in the loader.
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...