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
153 *type_str_p = &_dbus_empty_signature_str;
172 if (byte_order == DBUS_COMPILER_BYTE_ORDER)
175 _dbus_verbose (
"Swapping message into compiler byte order\n");
177 get_const_signature (&message->
header, &type_str, &type_pos);
181 DBUS_COMPILER_BYTE_ORDER,
186 DBUS_COMPILER_BYTE_ORDER);
195 #define ensure_byte_order(message) _dbus_message_byteswap (message)
215 *body = &message->
body;
233 #ifdef HAVE_UNIX_FD_PASSING
234 *fds = message->unix_fds;
235 *n_fds = message->n_unix_fds;
257 _dbus_return_if_fail (message !=
NULL);
258 _dbus_return_if_fail (!message->
locked);
295 #ifdef HAVE_UNIX_FD_PASSING
296 message->unix_fd_counter_delta = message->n_unix_fds;
300 _dbus_verbose (
"message has size %ld\n",
309 #ifdef HAVE_UNIX_FD_PASSING
365 #ifdef HAVE_UNIX_FD_PASSING
441 const char *signature)
443 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
444 _dbus_return_val_if_fail (!message->
locked,
FALSE);
445 _dbus_return_val_if_fail (signature ==
NULL ||
446 _dbus_check_is_valid_signature (signature));
451 return set_or_delete_string_field (message,
505 #define MAX_MESSAGE_SIZE_TO_CACHE 10 * _DBUS_ONE_KILOBYTE
508 #define MAX_MESSAGE_CACHE_SIZE 5
512 static int message_cache_count = 0;
516 dbus_message_cache_shutdown (
void *data)
522 "before registering a shutdown function");
527 if (message_cache[i])
528 dbus_message_finalize (message_cache[i]);
533 message_cache_count = 0;
534 message_cache_shutdown_registered =
FALSE;
547 dbus_message_get_cached (
void)
563 if (message_cache_count == 0)
578 if (message_cache[i])
580 message = message_cache[i];
581 message_cache[i] =
NULL;
582 message_cache_count -= 1;
600 #ifdef HAVE_UNIX_FD_PASSING
602 close_unix_fds(
int *fds,
unsigned *n_fds)
612 for (i = 0; i < *n_fds; i++)
628 free_counter (
void *element,
635 #ifdef HAVE_UNIX_FD_PASSING
649 dbus_message_cache_or_finalize (
DBusMessage *message)
662 free_counter, message);
665 #ifdef HAVE_UNIX_FD_PASSING
666 close_unix_fds(message->unix_fds, &message->n_unix_fds);
676 "the first time we constructed a message");
679 if (!message_cache_shutdown_registered)
689 message_cache[i] =
NULL;
693 message_cache_shutdown_registered =
TRUE;
698 if (!_dbus_enable_message_cache ())
711 while (message_cache[i] !=
NULL)
717 message_cache[i] = message;
718 message_cache_count += 1;
720 #ifndef DBUS_DISABLE_CHECKS
730 dbus_message_finalize (message);
733 #if defined(DBUS_ENABLE_CHECKS) || defined(DBUS_ENABLE_ASSERT)
747 if (iter->
iter_type == DBUS_MESSAGE_ITER_TYPE_READER)
757 else if (iter->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER)
775 _dbus_warn_check_failed (
"dbus message iterator invalid because the message has been modified (or perhaps the iterator is just uninitialized)\n");
802 int spec_type, msg_type, i, j;
810 spec_type = first_arg_type;
816 DBUS_VA_COPY (copy_args, var_args);
822 if (msg_type != spec_type)
825 "Argument %d is specified to be of type \"%s\", but "
826 "is actually of type \"%s\"\n", i,
835 #ifdef HAVE_UNIX_FD_PASSING
839 pfd = va_arg (var_args,
int*);
847 "Message refers to file descriptor at index %i,"
848 "but has only %i descriptors attached.\n",
860 "Platform does not support file desciptor passing.\n");
878 int spec_element_type;
883 spec_element_type = va_arg (var_args,
int);
886 if (spec_element_type != element_type)
889 "Argument %d is specified to be an array of \"%s\", but "
890 "is actually an array of \"%s\"\n",
902 n_elements_p = va_arg (var_args,
int*);
910 (
void *) ptr, n_elements_p);
912 else if (_DBUS_TYPE_IS_STRINGLIKE (spec_element_type))
918 str_array_p = va_arg (var_args,
char***);
919 n_elements_p = va_arg (var_args,
int*);
934 str_array =
dbus_new0 (
char*, n_elements + 1);
935 if (str_array ==
NULL)
937 _DBUS_SET_OOM (error);
945 while (j < n_elements)
952 if (str_array[j] ==
NULL)
955 _DBUS_SET_OOM (error);
969 *str_array_p = str_array;
970 *n_elements_p = n_elements;
972 #ifndef DBUS_DISABLE_CHECKS
975 _dbus_warn (
"you can't read arrays of container types (struct, variant, array) with %s for now\n",
976 _DBUS_FUNCTION_NAME);
981 #ifndef DBUS_DISABLE_CHECKS
984 _dbus_warn (
"you can only read arrays and basic types with %s for now\n",
985 _DBUS_FUNCTION_NAME);
993 spec_type = va_arg (var_args,
int);
997 "Message has only %d arguments, but more were expected", i);
1011 spec_type = first_arg_type;
1018 #ifdef HAVE_UNIX_FD_PASSING
1021 pfd = va_arg (copy_args,
int *);
1037 int spec_element_type;
1039 spec_element_type = va_arg (copy_args,
int);
1044 va_arg (copy_args,
int *);
1046 else if (_DBUS_TYPE_IS_STRINGLIKE (spec_element_type))
1048 char ***str_array_p;
1050 str_array_p = va_arg (copy_args,
char ***);
1052 va_arg (copy_args,
int *);
1055 *str_array_p =
NULL;
1059 spec_type = va_arg (copy_args,
int);
1129 _dbus_return_val_if_fail (message !=
NULL, 0);
1146 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
1147 _dbus_return_val_if_fail (!message->
locked,
FALSE);
1148 _dbus_return_val_if_fail (reply_serial != 0,
FALSE);
1167 _dbus_return_val_if_fail (message !=
NULL, 0);
1187 free_counter, message);
1193 #ifdef HAVE_UNIX_FD_PASSING
1194 close_unix_fds(message->unix_fds, &message->n_unix_fds);
1204 dbus_message_new_empty_header (
void)
1209 message = dbus_message_get_cached ();
1211 if (message !=
NULL)
1219 if (message ==
NULL)
1221 #ifndef DBUS_DISABLE_CHECKS
1225 #ifdef HAVE_UNIX_FD_PASSING
1226 message->unix_fds =
NULL;
1227 message->n_unix_fds_allocated = 0;
1233 _dbus_message_trace_ref (message, 0, 1,
"new_empty_header");
1236 #ifndef DBUS_DISABLE_CHECKS
1243 #ifdef HAVE_UNIX_FD_PASSING
1244 message->n_unix_fds = 0;
1245 message->n_unix_fds_allocated = 0;
1246 message->unix_fd_counter_delta = 0;
1295 message = dbus_message_new_empty_header ();
1296 if (message ==
NULL)
1300 DBUS_COMPILER_BYTE_ORDER,
1340 _dbus_return_val_if_fail (path !=
NULL,
NULL);
1341 _dbus_return_val_if_fail (method !=
NULL,
NULL);
1342 _dbus_return_val_if_fail (destination ==
NULL ||
1343 _dbus_check_is_valid_bus_name (destination),
NULL);
1344 _dbus_return_val_if_fail (_dbus_check_is_valid_path (path),
NULL);
1345 _dbus_return_val_if_fail (iface ==
NULL ||
1346 _dbus_check_is_valid_interface (iface),
NULL);
1347 _dbus_return_val_if_fail (_dbus_check_is_valid_member (method),
NULL);
1349 message = dbus_message_new_empty_header ();
1350 if (message ==
NULL)
1354 DBUS_COMPILER_BYTE_ORDER,
1356 destination, path, iface, method,
NULL))
1378 _dbus_return_val_if_fail (method_call !=
NULL,
NULL);
1384 message = dbus_message_new_empty_header ();
1385 if (message ==
NULL)
1389 DBUS_COMPILER_BYTE_ORDER,
1430 _dbus_return_val_if_fail (path !=
NULL,
NULL);
1431 _dbus_return_val_if_fail (iface !=
NULL,
NULL);
1432 _dbus_return_val_if_fail (name !=
NULL,
NULL);
1433 _dbus_return_val_if_fail (_dbus_check_is_valid_path (path),
NULL);
1434 _dbus_return_val_if_fail (_dbus_check_is_valid_interface (iface),
NULL);
1435 _dbus_return_val_if_fail (_dbus_check_is_valid_member (name),
NULL);
1437 message = dbus_message_new_empty_header ();
1438 if (message ==
NULL)
1442 DBUS_COMPILER_BYTE_ORDER,
1471 const char *error_name,
1472 const char *error_message)
1478 _dbus_return_val_if_fail (reply_to !=
NULL,
NULL);
1479 _dbus_return_val_if_fail (error_name !=
NULL,
NULL);
1480 _dbus_return_val_if_fail (_dbus_check_is_valid_error_name (error_name),
NULL);
1488 message = dbus_message_new_empty_header ();
1489 if (message ==
NULL)
1493 DBUS_COMPILER_BYTE_ORDER,
1510 if (error_message !=
NULL)
1543 const char *error_name,
1544 const char *error_format,
1551 _dbus_return_val_if_fail (reply_to !=
NULL,
NULL);
1552 _dbus_return_val_if_fail (error_name !=
NULL,
NULL);
1553 _dbus_return_val_if_fail (_dbus_check_is_valid_error_name (error_name),
NULL);
1558 va_start (args, error_format);
1591 _dbus_return_val_if_fail (message !=
NULL,
NULL);
1600 #ifndef DBUS_DISABLE_CHECKS
1622 #ifdef HAVE_UNIX_FD_PASSING
1623 retval->unix_fds =
dbus_new(
int, message->n_unix_fds);
1624 if (retval->unix_fds ==
NULL && message->n_unix_fds > 0)
1627 retval->n_unix_fds_allocated = message->n_unix_fds;
1629 for (retval->n_unix_fds = 0;
1630 retval->n_unix_fds < message->n_unix_fds;
1631 retval->n_unix_fds++)
1633 retval->unix_fds[retval->n_unix_fds] =
_dbus_dup(message->unix_fds[retval->n_unix_fds],
NULL);
1635 if (retval->unix_fds[retval->n_unix_fds] < 0)
1641 _dbus_message_trace_ref (retval, 0, 1,
"copy");
1648 #ifdef HAVE_UNIX_FD_PASSING
1649 close_unix_fds(retval->unix_fds, &retval->n_unix_fds);
1671 _dbus_return_val_if_fail (message !=
NULL,
NULL);
1677 _dbus_message_trace_ref (message, old_refcount, old_refcount + 1,
"ref");
1694 _dbus_return_if_fail (message !=
NULL);
1696 _dbus_return_if_fail (!message->
in_cache);
1702 _dbus_message_trace_ref (message, old_refcount, old_refcount - 1,
"unref");
1704 if (old_refcount == 1)
1707 dbus_message_cache_or_finalize (message);
1799 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
1801 va_start (var_args, first_arg_type);
1831 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
1833 type = first_arg_type;
1855 element_type = va_arg (var_args,
int);
1857 buf[0] = element_type;
1872 n_elements = va_arg (var_args,
int);
1882 else if (_DBUS_TYPE_IS_STRINGLIKE (element_type))
1884 const char ***value_p;
1889 value_p = va_arg (var_args,
const char***);
1890 n_elements = va_arg (var_args,
int);
1895 while (i < n_elements)
1908 _dbus_warn (
"arrays of %s can't be appended with %s for now\n",
1910 _DBUS_FUNCTION_NAME);
1917 #ifndef DBUS_DISABLE_CHECKS
1920 _dbus_warn (
"type %s isn't supported yet in %s\n",
1926 type = va_arg (var_args,
int);
1988 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
1989 _dbus_return_val_if_error_is_set (error,
FALSE);
1991 va_start (var_args, first_arg_type);
2016 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
2017 _dbus_return_val_if_error_is_set (error,
FALSE);
2024 _dbus_message_iter_init_common (
DBusMessage *message,
2071 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
2072 _dbus_return_val_if_fail (iter !=
NULL,
FALSE);
2074 get_const_signature (&message->
header, &type_str, &type_pos);
2076 _dbus_message_iter_init_common (message, real,
2077 DBUS_MESSAGE_ITER_TYPE_READER);
2099 _dbus_return_val_if_fail (_dbus_message_iter_check (real),
FALSE);
2100 _dbus_return_val_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_READER,
FALSE);
2118 _dbus_return_val_if_fail (_dbus_message_iter_check (real),
FALSE);
2119 _dbus_return_val_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_READER,
FALSE);
2144 _dbus_return_val_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_READER,
FALSE);
2201 _dbus_return_if_fail (_dbus_message_iter_check (real));
2202 _dbus_return_if_fail (sub !=
NULL);
2228 _dbus_return_val_if_fail (_dbus_message_iter_check (real),
NULL);
2298 _dbus_return_if_fail (_dbus_message_iter_check (real));
2299 _dbus_return_if_fail (value !=
NULL);
2303 #ifdef HAVE_UNIX_FD_PASSING
2311 *((
int*) value) = -1;
2317 *((
int*) value) = -1;
2345 _dbus_return_val_if_fail (_dbus_message_iter_check (real), 0);
2355 n_elements = total_len / alignment;
2386 _dbus_return_val_if_fail (_dbus_message_iter_check (real), 0);
2432 #ifndef DBUS_DISABLE_CHECKS
2435 _dbus_return_if_fail (_dbus_message_iter_check (real));
2436 _dbus_return_if_fail (value !=
NULL);
2462 _dbus_return_if_fail (message !=
NULL);
2463 _dbus_return_if_fail (iter !=
NULL);
2465 _dbus_message_iter_init_common (message, real,
2466 DBUS_MESSAGE_ITER_TYPE_WRITER);
2491 int current_sig_pos;
2508 ¤t_sig, ¤t_sig_pos))
2516 current_sig_pos += 1;
2561 const char *v_STRING;
2621 #ifndef DBUS_DISABLE_CHECKS
2625 if (!_dbus_message_iter_check (iter))
2638 #ifdef HAVE_UNIX_FD_PASSING
2648 if (m->n_unix_fds + n > m->n_unix_fds_allocated)
2654 k = (m->n_unix_fds + n) * 2;
2665 m->n_unix_fds_allocated = k;
2668 return m->unix_fds + m->n_unix_fds;
2699 _dbus_return_val_if_fail (_dbus_message_iter_append_check (real),
FALSE);
2700 _dbus_return_val_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER,
FALSE);
2702 _dbus_return_val_if_fail (value !=
NULL,
FALSE);
2704 #ifndef DBUS_DISABLE_CHECKS
2707 const char *
const *string_p;
2712 _dbus_return_val_if_fail (_dbus_check_is_valid_utf8 (*string_p),
FALSE);
2717 _dbus_return_val_if_fail (_dbus_check_is_valid_path (*string_p),
FALSE);
2722 _dbus_return_val_if_fail (_dbus_check_is_valid_signature (*string_p),
FALSE);
2727 _dbus_return_val_if_fail (*bool_p == 0 || *bool_p == 1,
FALSE);
2737 if (!_dbus_message_iter_open_signature (real))
2742 #ifdef HAVE_UNIX_FD_PASSING
2747 if (!(fds = expand_fd_array(real->
message, 1)))
2754 u = real->
message->n_unix_fds;
2762 real->
message->n_unix_fds += 1;
2785 if (!_dbus_message_iter_close_signature (real))
2835 _dbus_return_val_if_fail (_dbus_message_iter_append_check (real),
FALSE);
2836 _dbus_return_val_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER,
FALSE);
2839 _dbus_return_val_if_fail (value !=
NULL,
FALSE);
2840 _dbus_return_val_if_fail (n_elements >= 0,
FALSE);
2841 _dbus_return_val_if_fail (n_elements <=
2845 #ifndef DBUS_DISABLE_CHECKS
2851 for (i = 0; i < n_elements; i++)
2853 _dbus_return_val_if_fail ((*bools)[i] == 0 || (*bools)[i] == 1,
FALSE);
2887 const char *contained_signature,
2894 _dbus_return_val_if_fail (_dbus_message_iter_append_check (real),
FALSE);
2895 _dbus_return_val_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER,
FALSE);
2897 _dbus_return_val_if_fail (sub !=
NULL,
FALSE);
2899 contained_signature ==
NULL) ||
2901 contained_signature ==
NULL) ||
2903 contained_signature !=
NULL) ||
2912 (contained_signature ==
NULL ||
2913 _dbus_check_is_valid_signature (contained_signature)),
2916 if (!_dbus_message_iter_open_signature (real))
2921 if (contained_signature !=
NULL)
2961 _dbus_return_val_if_fail (_dbus_message_iter_append_check (real),
FALSE);
2962 _dbus_return_val_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER,
FALSE);
2963 _dbus_return_val_if_fail (_dbus_message_iter_append_check (real_sub),
FALSE);
2964 _dbus_return_val_if_fail (real_sub->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER,
FALSE);
2969 if (!_dbus_message_iter_close_signature (real))
2991 #ifndef DBUS_DISABLE_CHECKS
2994 _dbus_return_if_fail (_dbus_message_iter_append_check (real));
2995 _dbus_return_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER);
2996 _dbus_return_if_fail (_dbus_message_iter_append_check (real_sub));
2997 _dbus_return_if_fail (real_sub->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER);
3000 _dbus_message_iter_abandon_signature (real);
3023 _dbus_return_if_fail (message !=
NULL);
3024 _dbus_return_if_fail (!message->
locked);
3041 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3065 _dbus_return_if_fail (message !=
NULL);
3066 _dbus_return_if_fail (!message->
locked);
3083 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3104 const char *object_path)
3106 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3107 _dbus_return_val_if_fail (!message->
locked,
FALSE);
3108 _dbus_return_val_if_fail (object_path ==
NULL ||
3109 _dbus_check_is_valid_path (object_path),
3112 return set_or_delete_string_field (message,
3136 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3159 const char *msg_path;
3162 if (msg_path ==
NULL)
3173 if (strcmp (msg_path, path) == 0)
3205 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3206 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
3237 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3238 _dbus_return_val_if_fail (!message->
locked,
FALSE);
3239 _dbus_return_val_if_fail (iface ==
NULL ||
3240 _dbus_check_is_valid_interface (iface),
3243 return set_or_delete_string_field (message,
3267 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3288 const char *msg_interface;
3291 if (msg_interface ==
NULL)
3302 if (strcmp (msg_interface, iface) == 0)
3325 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3326 _dbus_return_val_if_fail (!message->
locked,
FALSE);
3327 _dbus_return_val_if_fail (member ==
NULL ||
3328 _dbus_check_is_valid_member (member),
3331 return set_or_delete_string_field (message,
3353 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3374 const char *msg_member;
3377 if (msg_member ==
NULL)
3388 if (strcmp (msg_member, member) == 0)
3408 const char *error_name)
3410 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3411 _dbus_return_val_if_fail (!message->
locked,
FALSE);
3412 _dbus_return_val_if_fail (error_name ==
NULL ||
3413 _dbus_check_is_valid_error_name (error_name),
3416 return set_or_delete_string_field (message,
3437 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3462 const char *destination)
3464 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3465 _dbus_return_val_if_fail (!message->
locked,
FALSE);
3466 _dbus_return_val_if_fail (destination ==
NULL ||
3467 _dbus_check_is_valid_bus_name (destination),
3470 return set_or_delete_string_field (message,
3490 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3518 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3519 _dbus_return_val_if_fail (!message->
locked,
FALSE);
3520 _dbus_return_val_if_fail (sender ==
NULL ||
3521 _dbus_check_is_valid_bus_name (sender),
3524 return set_or_delete_string_field (message,
3550 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3584 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3586 get_const_signature (&message->
header, &type_str, &type_pos);
3592 _dbus_message_has_type_interface_member (
DBusMessage *message,
3612 if (n && strcmp (n, member) == 0)
3616 if (n ==
NULL || strcmp (n, iface) == 0)
3642 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3643 _dbus_return_val_if_fail (iface !=
NULL,
FALSE);
3644 _dbus_return_val_if_fail (method !=
NULL,
FALSE);
3649 return _dbus_message_has_type_interface_member (message,
3668 const char *signal_name)
3670 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3671 _dbus_return_val_if_fail (iface !=
NULL,
FALSE);
3672 _dbus_return_val_if_fail (signal_name !=
NULL,
FALSE);
3677 return _dbus_message_has_type_interface_member (message,
3679 iface, signal_name);
3694 const char *error_name)
3698 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3699 _dbus_return_val_if_fail (error_name !=
NULL,
FALSE);
3709 if (n && strcmp (n, error_name) == 0)
3731 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3732 _dbus_return_val_if_fail (name !=
NULL,
FALSE);
3739 if (s && strcmp (s, name) == 0)
3766 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3767 _dbus_return_val_if_fail (name !=
NULL,
FALSE);
3774 if (s && strcmp (s, name) == 0)
3791 const char *signature)
3795 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3796 _dbus_return_val_if_fail (signature !=
NULL,
FALSE);
3803 if (s && strcmp (s, signature) == 0)
3837 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3838 _dbus_return_val_if_error_is_set (error,
FALSE);
3849 str ?
"%s" :
NULL, str);
3863 #ifdef HAVE_UNIX_FD_PASSING
3866 return message->n_unix_fds > 0;
3890 #define INITIAL_LOADER_DATA_LEN 32
3931 #ifdef HAVE_UNIX_FD_PASSING
3932 loader->unix_fds =
NULL;
3933 loader->n_unix_fds = loader->n_unix_fds_allocated = 0;
3934 loader->unix_fds_outstanding =
FALSE;
3966 #ifdef HAVE_UNIX_FD_PASSING
3967 close_unix_fds(loader->unix_fds, &loader->n_unix_fds);
4003 *buffer = &loader->
data;
4040 unsigned *max_n_fds)
4042 #ifdef HAVE_UNIX_FD_PASSING
4061 loader->unix_fds = a;
4065 *fds = loader->unix_fds + loader->n_unix_fds;
4066 *max_n_fds = loader->n_unix_fds_allocated - loader->n_unix_fds;
4068 loader->unix_fds_outstanding =
TRUE;
4091 #ifdef HAVE_UNIX_FD_PASSING
4093 _dbus_assert(loader->unix_fds + loader->n_unix_fds == fds);
4094 _dbus_assert(loader->n_unix_fds + n_fds <= loader->n_unix_fds_allocated);
4096 loader->n_unix_fds += n_fds;
4097 loader->unix_fds_outstanding =
FALSE;
4099 if (n_fds && loader->unix_fds_change)
4100 loader->unix_fds_change (loader->unix_fds_change_data);
4136 int fields_array_len,
4147 mode = DBUS_VALIDATION_MODE_DATA_IS_UNTRUSTED;
4169 _dbus_verbose (
"Failed to load header for new message code %d\n", validity);
4188 if (mode != DBUS_VALIDATION_MODE_WE_TRUST_THIS_DATA_ABSOLUTELY)
4190 get_const_signature (&message->
header, &type_str, &type_pos);
4204 _dbus_verbose (
"Failed to validate message body code %d\n", validity);
4219 #ifdef HAVE_UNIX_FD_PASSING
4221 if (n_unix_fds > loader->n_unix_fds)
4223 _dbus_verbose(
"Message contains references to more unix fds than were sent %u != %u\n",
4224 n_unix_fds, loader->n_unix_fds);
4237 message->unix_fds =
_dbus_memdup(loader->unix_fds, n_unix_fds *
sizeof(message->unix_fds[0]));
4238 if (message->unix_fds ==
NULL)
4240 _dbus_verbose (
"Failed to allocate file descriptor array\n");
4245 message->n_unix_fds_allocated = message->n_unix_fds = n_unix_fds;
4246 loader->n_unix_fds -= n_unix_fds;
4247 memmove (loader->unix_fds, loader->unix_fds + n_unix_fds, loader->n_unix_fds * sizeof (loader->unix_fds[0]));
4249 if (loader->unix_fds_change)
4250 loader->unix_fds_change (loader->unix_fds_change_data);
4253 message->unix_fds =
NULL;
4259 _dbus_verbose (
"Hmm, message claims to come with file descriptors "
4260 "but that's not supported on our platform, disconnecting.\n");
4273 _dbus_verbose (
"Failed to append new message to loader queue\n");
4280 (header_len + body_len));
4284 _dbus_verbose (
"Failed to move body into new message\n");
4297 _dbus_verbose (
"Loaded message %p\n", message);
4344 int byte_order, fields_array_len, header_len, body_len;
4359 message = dbus_message_new_empty_header ();
4360 if (message ==
NULL)
4363 if (!load_message (loader, message,
4364 byte_order, fields_array_len,
4365 header_len, body_len))
4379 _dbus_verbose (
"Initial peek at header says we don't have a whole message yet, or data broken with invalid code %d\n",
4494 _dbus_verbose (
"clamping requested max message size %ld to %d\n",
4525 _dbus_verbose (
"clamping requested max message unix_fds %ld to %d\n",
4552 #ifdef HAVE_UNIX_FD_PASSING
4553 return loader->n_unix_fds;
4569 void (* callback) (
void *),
4572 #ifdef HAVE_UNIX_FD_PASSING
4573 loader->unix_fds_change = callback;
4574 loader->unix_fds_change_data = data;
4616 _dbus_return_if_fail (*slot_p >= 0);
4644 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
4645 _dbus_return_val_if_fail (slot >= 0,
FALSE);
4649 slot, data, free_data_func,
4650 &old_free_func, &old_data);
4656 (* old_free_func) (old_data);
4676 _dbus_return_val_if_fail (message !=
NULL,
NULL);
4701 if (strcmp (type_str,
"method_call") == 0)
4703 if (strcmp (type_str,
"method_return") == 0)
4705 else if (strcmp (type_str,
"signal") == 0)
4707 else if (strcmp (type_str,
"error") == 0)
4732 return "method_call";
4734 return "method_return";
4758 char **marshalled_data_p,
4764 _dbus_return_val_if_fail (msg !=
NULL,
FALSE);
4765 _dbus_return_val_if_fail (marshalled_data_p !=
NULL,
FALSE);
4766 _dbus_return_val_if_fail (len_p !=
NULL,
FALSE);
4772 was_locked = msg->
locked;
4827 _dbus_return_val_if_fail (str !=
NULL,
NULL);
4862 _DBUS_SET_OOM (error);
4884 int byte_order, fields_array_len, header_len, body_len;
4898 &validity, &byte_order,
4908 _dbus_assert (have_message || (header_len + body_len) > len);
4909 (void) have_message;
4910 return header_len + body_len;
4943 _dbus_return_if_fail (message !=
NULL);
4944 _dbus_return_if_fail (!message->
locked);
4960 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
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...
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_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_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.
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_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...
union DBusMessageRealIter::@6 u
the type writer or reader that does all the work
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.
unsigned char _dbus_string_get_byte(const DBusString *str, int start)
Gets the byte at the given position.
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_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).
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.
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...
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.
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)
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_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.
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_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...
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.
_DBUS_STRING_DEFINE_STATIC(_dbus_empty_signature_str,"")
An static string representing an empty signature.
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_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_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_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...
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_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.
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_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.
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...