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"
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)
48static 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;
290 dbus_uint32_t serial)
292 _dbus_return_if_fail (message !=
NULL);
293 _dbus_return_if_fail (!message->
locked);
327 _dbus_string_get_length (&message->
header.
data) +
328 _dbus_string_get_length (&message->
body);
330#ifdef HAVE_UNIX_FD_PASSING
331 message->unix_fd_counter_delta = message->n_unix_fds;
335 _dbus_verbose (
"message has size %ld\n",
344#ifdef HAVE_UNIX_FD_PASSING
400#ifdef HAVE_UNIX_FD_PASSING
424 _dbus_string_get_length (&message->
body));
496#define MAX_MESSAGE_SIZE_TO_CACHE 10 * _DBUS_ONE_KILOBYTE
499#define MAX_MESSAGE_CACHE_SIZE 5
503static int message_cache_count = 0;
507dbus_message_cache_shutdown (
void *data)
513 "before registering a shutdown function");
518 if (message_cache[i])
519 dbus_message_finalize (message_cache[i]);
524 message_cache_count = 0;
525 message_cache_shutdown_registered =
FALSE;
538dbus_message_get_cached (
void)
554 if (message_cache_count == 0)
569 if (message_cache[i])
571 message = message_cache[i];
572 message_cache[i] =
NULL;
573 message_cache_count -= 1;
591#ifdef HAVE_UNIX_FD_PASSING
593close_unix_fds(
int *fds,
unsigned *n_fds)
603 for (i = 0; i < *n_fds; i++)
619free_counter (
void *element,
626#ifdef HAVE_UNIX_FD_PASSING
640dbus_message_cache_or_finalize (
DBusMessage *message)
653 free_counter, message);
656#ifdef HAVE_UNIX_FD_PASSING
657 close_unix_fds(message->unix_fds, &message->n_unix_fds);
667 "the first time we constructed a message");
670 if (!message_cache_shutdown_registered)
680 message_cache[i] =
NULL;
684 message_cache_shutdown_registered =
TRUE;
689 if (!_dbus_enable_message_cache ())
692 if ((_dbus_string_get_length (&message->
header.
data) +
693 _dbus_string_get_length (&message->
body)) >
702 while (message_cache[i] !=
NULL)
708 message_cache[i] = message;
709 message_cache_count += 1;
711#ifndef DBUS_DISABLE_CHECKS
721 dbus_message_finalize (message);
745 _dbus_return_if_fail (iter !=
NULL);
756#if defined(DBUS_ENABLE_CHECKS) || defined(DBUS_ENABLE_ASSERT)
771 "closed, or is uninitialized or corrupt");
777 if (iter->
iter_type == DBUS_MESSAGE_ITER_TYPE_READER)
787 else if (iter->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER)
805 _dbus_warn_check_failed (
"dbus message iterator invalid because the message has been modified (or perhaps the iterator is just uninitialized)");
832 int spec_type, msg_type, i, j;
840 spec_type = first_arg_type;
846 DBUS_VA_COPY (copy_args, var_args);
852 if (msg_type != spec_type)
855 "Argument %d is specified to be of type \"%s\", but "
856 "is actually of type \"%s\"\n", i,
865#ifdef HAVE_UNIX_FD_PASSING
869 pfd = va_arg (var_args,
int*);
877 "Message refers to file descriptor at index %i,"
878 "but has only %i descriptors attached.\n",
890 "Platform does not support file desciptor passing.\n");
898 ptr = va_arg (var_args,
void *);
908 int spec_element_type;
913 spec_element_type = va_arg (var_args,
int);
916 if (spec_element_type != element_type)
919 "Argument %d is specified to be an array of \"%s\", but "
920 "is actually an array of \"%s\"\n",
931 ptr = va_arg (var_args,
const void **);
932 n_elements_p = va_arg (var_args,
int*);
941 else if (_DBUS_TYPE_IS_STRINGLIKE (spec_element_type))
947 str_array_p = va_arg (var_args,
char***);
948 n_elements_p = va_arg (var_args,
int*);
963 str_array =
dbus_new0 (
char*, n_elements + 1);
964 if (str_array ==
NULL)
966 _DBUS_SET_OOM (error);
974 while (j < n_elements)
981 if (str_array[j] ==
NULL)
984 _DBUS_SET_OOM (error);
998 *str_array_p = str_array;
999 *n_elements_p = n_elements;
1001#ifndef DBUS_DISABLE_CHECKS
1004 _dbus_warn (
"you can't read arrays of container types (struct, variant, array) with %s for now",
1005 _DBUS_FUNCTION_NAME);
1010#ifndef DBUS_DISABLE_CHECKS
1013 _dbus_warn (
"you can only read arrays and basic types with %s for now",
1014 _DBUS_FUNCTION_NAME);
1022 spec_type = va_arg (var_args,
int);
1026 "Message has only %d arguments, but more were expected", i);
1040 spec_type = first_arg_type;
1047#ifdef HAVE_UNIX_FD_PASSING
1050 pfd = va_arg (copy_args,
int *);
1062 va_arg (copy_args,
const void *);
1066 int spec_element_type;
1068 spec_element_type = va_arg (copy_args,
int);
1072 va_arg (copy_args,
const void **);
1073 va_arg (copy_args,
int *);
1075 else if (_DBUS_TYPE_IS_STRINGLIKE (spec_element_type))
1077 char ***str_array_p;
1079 str_array_p = va_arg (copy_args,
char ***);
1081 va_arg (copy_args,
int *);
1084 *str_array_p =
NULL;
1088 spec_type = va_arg (copy_args,
int);
1158 _dbus_return_val_if_fail (message !=
NULL, 0);
1173 dbus_uint32_t reply_serial)
1177 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
1178 _dbus_return_val_if_fail (!message->
locked,
FALSE);
1179 _dbus_return_val_if_fail (reply_serial != 0,
FALSE);
1181 value.
u32 = reply_serial;
1198 dbus_uint32_t v_UINT32;
1200 _dbus_return_val_if_fail (message !=
NULL, 0);
1220 free_counter, message);
1226#ifdef HAVE_UNIX_FD_PASSING
1227 close_unix_fds(message->unix_fds, &message->n_unix_fds);
1237dbus_message_new_empty_header (
void)
1242 message = dbus_message_get_cached ();
1244 if (message !=
NULL)
1252 if (message ==
NULL)
1254#ifndef DBUS_DISABLE_CHECKS
1258#ifdef HAVE_UNIX_FD_PASSING
1259 message->unix_fds =
NULL;
1260 message->n_unix_fds_allocated = 0;
1266 _dbus_message_trace_ref (message, 0, 1,
"new_empty_header");
1269#ifndef DBUS_DISABLE_CHECKS
1276#ifdef HAVE_UNIX_FD_PASSING
1277 message->n_unix_fds = 0;
1278 message->n_unix_fds_allocated = 0;
1279 message->unix_fd_counter_delta = 0;
1328 message = dbus_message_new_empty_header ();
1329 if (message ==
NULL)
1333 DBUS_COMPILER_BYTE_ORDER,
1373 _dbus_return_val_if_fail (path !=
NULL,
NULL);
1374 _dbus_return_val_if_fail (method !=
NULL,
NULL);
1375 _dbus_return_val_if_fail (destination ==
NULL ||
1376 _dbus_check_is_valid_bus_name (destination),
NULL);
1377 _dbus_return_val_if_fail (_dbus_check_is_valid_path (path),
NULL);
1378 _dbus_return_val_if_fail (iface ==
NULL ||
1379 _dbus_check_is_valid_interface (iface),
NULL);
1380 _dbus_return_val_if_fail (_dbus_check_is_valid_member (method),
NULL);
1382 message = dbus_message_new_empty_header ();
1383 if (message ==
NULL)
1387 DBUS_COMPILER_BYTE_ORDER,
1389 destination, path, iface, method,
NULL))
1411 _dbus_return_val_if_fail (method_call !=
NULL,
NULL);
1417 message = dbus_message_new_empty_header ();
1418 if (message ==
NULL)
1422 DBUS_COMPILER_BYTE_ORDER,
1463 _dbus_return_val_if_fail (path !=
NULL,
NULL);
1464 _dbus_return_val_if_fail (iface !=
NULL,
NULL);
1465 _dbus_return_val_if_fail (name !=
NULL,
NULL);
1466 _dbus_return_val_if_fail (_dbus_check_is_valid_path (path),
NULL);
1467 _dbus_return_val_if_fail (_dbus_check_is_valid_interface (iface),
NULL);
1468 _dbus_return_val_if_fail (_dbus_check_is_valid_member (name),
NULL);
1470 message = dbus_message_new_empty_header ();
1471 if (message ==
NULL)
1475 DBUS_COMPILER_BYTE_ORDER,
1504 const char *error_name,
1505 const char *error_message)
1511 _dbus_return_val_if_fail (reply_to !=
NULL,
NULL);
1512 _dbus_return_val_if_fail (error_name !=
NULL,
NULL);
1513 _dbus_return_val_if_fail (_dbus_check_is_valid_error_name (error_name),
NULL);
1521 message = dbus_message_new_empty_header ();
1522 if (message ==
NULL)
1526 DBUS_COMPILER_BYTE_ORDER,
1543 if (error_message !=
NULL)
1576 const char *error_name,
1577 const char *error_format,
1584 _dbus_return_val_if_fail (reply_to !=
NULL,
NULL);
1585 _dbus_return_val_if_fail (error_name !=
NULL,
NULL);
1586 _dbus_return_val_if_fail (_dbus_check_is_valid_error_name (error_name),
NULL);
1591 va_start (args, error_format);
1595 _dbus_string_get_const_data (&str));
1624 _dbus_return_val_if_fail (message !=
NULL,
NULL);
1633#ifndef DBUS_DISABLE_CHECKS
1644 _dbus_string_get_length (&message->
body)))
1655#ifdef HAVE_UNIX_FD_PASSING
1656 retval->unix_fds =
dbus_new(
int, message->n_unix_fds);
1657 if (retval->unix_fds ==
NULL && message->n_unix_fds > 0)
1660 retval->n_unix_fds_allocated = message->n_unix_fds;
1662 for (retval->n_unix_fds = 0;
1663 retval->n_unix_fds < message->n_unix_fds;
1664 retval->n_unix_fds++)
1666 retval->unix_fds[retval->n_unix_fds] =
_dbus_dup(message->unix_fds[retval->n_unix_fds],
NULL);
1668 if (retval->unix_fds[retval->n_unix_fds] < 0)
1674 _dbus_message_trace_ref (retval, 0, 1,
"copy");
1681#ifdef HAVE_UNIX_FD_PASSING
1682 close_unix_fds(retval->unix_fds, &retval->n_unix_fds);
1702 dbus_int32_t old_refcount;
1704 _dbus_return_val_if_fail (message !=
NULL,
NULL);
1710 _dbus_message_trace_ref (message, old_refcount, old_refcount + 1,
"ref");
1725 dbus_int32_t old_refcount;
1727 _dbus_return_if_fail (message !=
NULL);
1729 _dbus_return_if_fail (!message->
in_cache);
1735 _dbus_message_trace_ref (message, old_refcount, old_refcount - 1,
"unref");
1737 if (old_refcount == 1)
1740 dbus_message_cache_or_finalize (message);
1838 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
1840 va_start (var_args, first_arg_type);
1870 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
1872 type = first_arg_type;
1881 value = va_arg (var_args,
const void *);
1894 element_type = va_arg (var_args,
int);
1896 buf[0] = element_type;
1910 value = va_arg (var_args,
const void **);
1911 n_elements = va_arg (var_args,
int);
1921 else if (_DBUS_TYPE_IS_STRINGLIKE (element_type))
1923 const char ***value_p;
1928 value_p = va_arg (var_args,
const char***);
1929 n_elements = va_arg (var_args,
int);
1934 while (i < n_elements)
1947 _dbus_warn (
"arrays of %s can't be appended with %s for now",
1949 _DBUS_FUNCTION_NAME);
1957#ifndef DBUS_DISABLE_CHECKS
1960 _dbus_warn (
"type %s isn't supported yet in %s",
1966 type = va_arg (var_args,
int);
2028 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
2029 _dbus_return_val_if_error_is_set (error,
FALSE);
2031 va_start (var_args, first_arg_type);
2056 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
2057 _dbus_return_val_if_error_is_set (error,
FALSE);
2064_dbus_message_iter_init_common (
DBusMessage *message,
2082 4 *
sizeof (
void *) +
sizeof (dbus_uint32_t) + 9 *
sizeof (
int));
2125 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
2126 _dbus_return_val_if_fail (iter !=
NULL,
FALSE);
2128 get_const_signature (&message->
header, &type_str, &type_pos);
2130 _dbus_message_iter_init_common (message, real,
2131 DBUS_MESSAGE_ITER_TYPE_READER);
2153 _dbus_return_val_if_fail (_dbus_message_iter_check (real),
FALSE);
2154 _dbus_return_val_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_READER,
FALSE);
2172 _dbus_return_val_if_fail (_dbus_message_iter_check (real),
FALSE);
2173 _dbus_return_val_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_READER,
FALSE);
2198 _dbus_return_val_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_READER,
FALSE);
2255 _dbus_return_if_fail (_dbus_message_iter_check (real));
2256 _dbus_return_if_fail (sub !=
NULL);
2282 _dbus_return_val_if_fail (_dbus_message_iter_check (real),
NULL);
2290 _dbus_string_get_const_data (sig) + start,
2356 _dbus_return_if_fail (_dbus_message_iter_check (real));
2357 _dbus_return_if_fail (value !=
NULL);
2361#ifdef HAVE_UNIX_FD_PASSING
2369 *((
int*) value) = -1;
2375 *((
int*) value) = -1;
2403 _dbus_return_val_if_fail (_dbus_message_iter_check (real), 0);
2413 n_elements = total_len / alignment;
2444 _dbus_return_val_if_fail (_dbus_message_iter_check (real), 0);
2490#ifndef DBUS_DISABLE_CHECKS
2493 _dbus_return_if_fail (_dbus_message_iter_check (real));
2494 _dbus_return_if_fail (value !=
NULL);
2520 _dbus_return_if_fail (message !=
NULL);
2521 _dbus_return_if_fail (iter !=
NULL);
2523 _dbus_message_iter_init_common (message, real,
2524 DBUS_MESSAGE_ITER_TYPE_WRITER);
2533 _dbus_string_get_length (&message->
body));
2549 int current_sig_pos;
2566 ¤t_sig, ¤t_sig_pos))
2573 current_len = _dbus_string_get_byte (current_sig, current_sig_pos);
2574 current_sig_pos += 1;
2605 str, _dbus_string_get_length (str));
2622 const char *v_STRING;
2639 v_STRING = _dbus_string_get_const_data (str);
2682#ifndef DBUS_DISABLE_CHECKS
2686 if (!_dbus_message_iter_check (iter))
2699#ifdef HAVE_UNIX_FD_PASSING
2709 if (m->n_unix_fds + n > m->n_unix_fds_allocated)
2715 k = (m->n_unix_fds + n) * 2;
2726 m->n_unix_fds_allocated = k;
2729 return m->unix_fds + m->n_unix_fds;
2760 _dbus_return_val_if_fail (_dbus_message_iter_append_check (real),
FALSE);
2761 _dbus_return_val_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER,
FALSE);
2763 _dbus_return_val_if_fail (value !=
NULL,
FALSE);
2765#ifndef DBUS_DISABLE_CHECKS
2770 const char *
const *string_p;
2775 _dbus_return_val_if_fail (_dbus_check_is_valid_utf8 (*string_p),
FALSE);
2780 _dbus_return_val_if_fail (_dbus_check_is_valid_path (*string_p),
FALSE);
2788 _dbus_string_get_length (&str));
2798 _dbus_return_val_if_fail (*bool_p == 0 || *bool_p == 1,
FALSE);
2808 if (!_dbus_message_iter_open_signature (real))
2813#ifdef HAVE_UNIX_FD_PASSING
2820 if (!(fds = expand_fd_array(real->
message, 1)))
2827 u = real->
message->n_unix_fds;
2835 real->
message->n_unix_fds += 1;
2862 if (!_dbus_message_iter_close_signature (real))
2912 _dbus_return_val_if_fail (_dbus_message_iter_append_check (real),
FALSE);
2913 _dbus_return_val_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER,
FALSE);
2916 _dbus_return_val_if_fail (value !=
NULL,
FALSE);
2917 _dbus_return_val_if_fail (n_elements >= 0,
FALSE);
2918 _dbus_return_val_if_fail (n_elements <=
2922#ifndef DBUS_DISABLE_CHECKS
2928 for (i = 0; i < n_elements; i++)
2930 _dbus_return_val_if_fail ((*bools)[i] == 0 || (*bools)[i] == 1,
FALSE);
2970 const char *contained_signature,
2979 _dbus_return_val_if_fail (sub !=
NULL,
FALSE);
2982 _dbus_message_real_iter_zero (real_sub);
2984 _dbus_return_val_if_fail (_dbus_message_iter_append_check (real),
FALSE);
2985 _dbus_return_val_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER,
FALSE);
2988 contained_signature ==
NULL) ||
2990 contained_signature ==
NULL) ||
2992 contained_signature !=
NULL) ||
3000 if (contained_signature !=
NULL)
3005 _dbus_string_get_length (&contained_str));
3013 contained_signature_validity = DBUS_VALID_BUT_INCOMPLETE;
3017 contained_signature ==
NULL ||
3021 if (!_dbus_message_iter_open_signature (real))
3027 if (contained_signature !=
NULL)
3045 _dbus_message_iter_abandon_signature (real);
3078 _dbus_return_val_if_fail (_dbus_message_iter_append_check (real),
FALSE);
3079 _dbus_return_val_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER,
FALSE);
3080 _dbus_return_val_if_fail (_dbus_message_iter_append_check (real_sub),
FALSE);
3081 _dbus_return_val_if_fail (real_sub->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER,
FALSE);
3085 _dbus_message_real_iter_zero (real_sub);
3087 if (!_dbus_message_iter_close_signature (real))
3111#ifndef DBUS_DISABLE_CHECKS
3112 _dbus_return_if_fail (_dbus_message_iter_append_check (real));
3113 _dbus_return_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER);
3114 _dbus_return_if_fail (_dbus_message_iter_append_check (real_sub));
3115 _dbus_return_if_fail (real_sub->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER);
3118 _dbus_message_iter_abandon_signature (real);
3119 _dbus_message_real_iter_zero (real_sub);
3176 if (_dbus_message_real_iter_is_zeroed (real) &&
3177 _dbus_message_real_iter_is_zeroed (real_sub))
3180#ifndef DBUS_DISABLE_CHECKS
3185 _dbus_return_if_fail (_dbus_message_iter_append_check (real));
3186 _dbus_return_if_fail (real->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER);
3196 if (_dbus_message_real_iter_is_zeroed (real_sub))
3199#ifndef DBUS_DISABLE_CHECKS
3200 _dbus_return_if_fail (_dbus_message_iter_append_check (real_sub));
3201 _dbus_return_if_fail (real_sub->
iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER);
3208 _dbus_message_iter_abandon_signature (real);
3209 _dbus_message_real_iter_zero (real_sub);
3232 _dbus_return_if_fail (message !=
NULL);
3233 _dbus_return_if_fail (!message->
locked);
3250 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3274 _dbus_return_if_fail (message !=
NULL);
3275 _dbus_return_if_fail (!message->
locked);
3292 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3313 const char *object_path)
3315 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3316 _dbus_return_val_if_fail (!message->
locked,
FALSE);
3317 _dbus_return_val_if_fail (object_path ==
NULL ||
3318 _dbus_check_is_valid_path (object_path),
3321 return set_or_delete_string_field (message,
3345 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3368 const char *msg_path;
3371 if (msg_path ==
NULL)
3382 if (strcmp (msg_path, path) == 0)
3414 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3415 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
3446 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3447 _dbus_return_val_if_fail (!message->
locked,
FALSE);
3448 _dbus_return_val_if_fail (iface ==
NULL ||
3449 _dbus_check_is_valid_interface (iface),
3452 return set_or_delete_string_field (message,
3476 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3497 const char *msg_interface;
3500 if (msg_interface ==
NULL)
3511 if (strcmp (msg_interface, iface) == 0)
3534 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3535 _dbus_return_val_if_fail (!message->
locked,
FALSE);
3536 _dbus_return_val_if_fail (member ==
NULL ||
3537 _dbus_check_is_valid_member (member),
3540 return set_or_delete_string_field (message,
3562 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3583 const char *msg_member;
3586 if (msg_member ==
NULL)
3597 if (strcmp (msg_member, member) == 0)
3617 const char *error_name)
3619 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3620 _dbus_return_val_if_fail (!message->
locked,
FALSE);
3621 _dbus_return_val_if_fail (error_name ==
NULL ||
3622 _dbus_check_is_valid_error_name (error_name),
3625 return set_or_delete_string_field (message,
3646 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3671 const char *destination)
3673 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3674 _dbus_return_val_if_fail (!message->
locked,
FALSE);
3675 _dbus_return_val_if_fail (destination ==
NULL ||
3676 _dbus_check_is_valid_bus_name (destination),
3679 return set_or_delete_string_field (message,
3699 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3727 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3728 _dbus_return_val_if_fail (!message->
locked,
FALSE);
3729 _dbus_return_val_if_fail (sender ==
NULL ||
3730 _dbus_check_is_valid_bus_name (sender),
3733 return set_or_delete_string_field (message,
3759 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3793 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3795 get_const_signature (&message->
header, &type_str, &type_pos);
3797 return _dbus_string_get_const_data_len (type_str, type_pos, 0);
3801_dbus_message_has_type_interface_member (
DBusMessage *message,
3821 if (n && strcmp (n, member) == 0)
3825 if (n ==
NULL || strcmp (n, iface) == 0)
3851 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3852 _dbus_return_val_if_fail (iface !=
NULL,
FALSE);
3853 _dbus_return_val_if_fail (method !=
NULL,
FALSE);
3858 return _dbus_message_has_type_interface_member (message,
3877 const char *signal_name)
3879 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3880 _dbus_return_val_if_fail (iface !=
NULL,
FALSE);
3881 _dbus_return_val_if_fail (signal_name !=
NULL,
FALSE);
3886 return _dbus_message_has_type_interface_member (message,
3888 iface, signal_name);
3903 const char *error_name)
3907 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3908 _dbus_return_val_if_fail (error_name !=
NULL,
FALSE);
3918 if (n && strcmp (n, error_name) == 0)
3940 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3941 _dbus_return_val_if_fail (name !=
NULL,
FALSE);
3948 if (s && strcmp (s, name) == 0)
3975 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3976 _dbus_return_val_if_fail (name !=
NULL,
FALSE);
3983 if (s && strcmp (s, name) == 0)
4000 const char *signature)
4004 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
4005 _dbus_return_val_if_fail (signature !=
NULL,
FALSE);
4012 if (s && strcmp (s, signature) == 0)
4046 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
4047 _dbus_return_val_if_error_is_set (error,
FALSE);
4058 str ?
"%s" :
NULL, str);
4072#ifdef HAVE_UNIX_FD_PASSING
4075 return message->n_unix_fds > 0;
4093 const char *object_path)
4095 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
4096 _dbus_return_val_if_fail (!message->
locked,
FALSE);
4097 _dbus_return_val_if_fail (object_path ==
NULL ||
4098 _dbus_check_is_valid_path (object_path),
4101 return set_or_delete_string_field (message,
4122 _dbus_return_val_if_fail (message !=
NULL,
NULL);
4150#define INITIAL_LOADER_DATA_LEN 32
4191#ifdef HAVE_UNIX_FD_PASSING
4192 loader->unix_fds =
NULL;
4193 loader->n_unix_fds = loader->n_unix_fds_allocated = 0;
4194 loader->unix_fds_outstanding =
FALSE;
4226#ifdef HAVE_UNIX_FD_PASSING
4227 close_unix_fds(loader->unix_fds, &loader->n_unix_fds);
4263 *buffer = &loader->
data;
4267 if (max_to_read !=
NULL)
4269#ifdef HAVE_UNIX_FD_PASSING
4273 int fields_array_len;
4279 *may_read_fds =
TRUE;
4281#ifdef HAVE_UNIX_FD_PASSING
4284 if (loader->n_unix_fds == 0)
4295 remain = _dbus_string_get_length (&loader->
data);
4309 *may_read_fds =
FALSE;
4333 needed = header_len + body_len;
4335 *max_to_read = needed - remain;
4336 *may_read_fds =
FALSE;
4342 needed = header_len + body_len;
4371#ifdef HAVE_UNIX_FD_PASSING
4385 unsigned *max_n_fds)
4405 loader->unix_fds = a;
4409 *fds = loader->unix_fds + loader->n_unix_fds;
4410 *max_n_fds = loader->n_unix_fds_allocated - loader->n_unix_fds;
4412 loader->unix_fds_outstanding =
TRUE;
4432 _dbus_assert(loader->unix_fds + loader->n_unix_fds == fds);
4433 _dbus_assert(loader->n_unix_fds + n_fds <= loader->n_unix_fds_allocated);
4435 loader->n_unix_fds += n_fds;
4436 loader->unix_fds_outstanding =
FALSE;
4438 if (n_fds && loader->unix_fds_change)
4439 loader->unix_fds_change (loader->unix_fds_change_data);
4473 int fields_array_len,
4482 dbus_uint32_t n_unix_fds = 0;
4484 mode = DBUS_VALIDATION_MODE_DATA_IS_UNTRUSTED;
4494 _dbus_assert ((header_len + body_len) <= _dbus_string_get_length (&loader->
data));
4505 _dbus_verbose (
"Failed to load header for new message code %d\n", validity);
4524 if (mode != DBUS_VALIDATION_MODE_WE_TRUST_THIS_DATA_ABSOLUTELY)
4526 get_const_signature (&message->
header, &type_str, &type_pos);
4540 _dbus_verbose (
"Failed to validate message body code %d\n", validity);
4555#ifdef HAVE_UNIX_FD_PASSING
4557 if (n_unix_fds > loader->n_unix_fds)
4559 _dbus_verbose(
"Message contains references to more unix fds than were sent %u != %u\n",
4560 n_unix_fds, loader->n_unix_fds);
4573 message->unix_fds =
_dbus_memdup(loader->unix_fds, n_unix_fds *
sizeof(message->unix_fds[0]));
4574 if (message->unix_fds ==
NULL)
4576 _dbus_verbose (
"Failed to allocate file descriptor array\n");
4581 message->n_unix_fds_allocated = message->n_unix_fds = n_unix_fds;
4582 loader->n_unix_fds -= n_unix_fds;
4583 memmove (loader->unix_fds, loader->unix_fds + n_unix_fds, loader->n_unix_fds * sizeof (loader->unix_fds[0]));
4585 if (loader->unix_fds_change)
4586 loader->unix_fds_change (loader->unix_fds_change_data);
4589 message->unix_fds =
NULL;
4595 _dbus_verbose (
"Hmm, message claims to come with file descriptors "
4596 "but that's not supported on our platform, disconnecting.\n");
4609 _dbus_verbose (
"Failed to append new message to loader queue\n");
4616 (header_len + body_len));
4620 _dbus_verbose (
"Failed to move body into new message\n");
4633 _dbus_verbose (
"Loaded message %p\n", message);
4680 int byte_order, fields_array_len, header_len, body_len;
4689 _dbus_string_get_length (&loader->
data)))
4695 message = dbus_message_new_empty_header ();
4696 if (message ==
NULL)
4699 if (!load_message (loader, message,
4700 byte_order, fields_array_len,
4701 header_len, body_len))
4715 _dbus_verbose (
"Initial peek at header says we don't have a whole message yet, or data broken with invalid code %d\n",
4830 _dbus_verbose (
"clamping requested max message size %ld to %d\n",
4861 _dbus_verbose (
"clamping requested max message unix_fds %ld to %d\n",
4888#ifdef HAVE_UNIX_FD_PASSING
4889 return loader->n_unix_fds;
4905 void (* callback) (
void *),
4908#ifdef HAVE_UNIX_FD_PASSING
4909 loader->unix_fds_change = callback;
4910 loader->unix_fds_change_data = data;
4952 _dbus_return_if_fail (*slot_p >= 0);
4980 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
4981 _dbus_return_val_if_fail (slot >= 0,
FALSE);
4985 slot, data, free_data_func,
4986 &old_free_func, &old_data);
4992 (* old_free_func) (old_data);
5012 _dbus_return_val_if_fail (message !=
NULL,
NULL);
5037 if (strcmp (type_str,
"method_call") == 0)
5039 if (strcmp (type_str,
"method_return") == 0)
5041 else if (strcmp (type_str,
"signal") == 0)
5043 else if (strcmp (type_str,
"error") == 0)
5068 return "method_call";
5070 return "method_return";
5094 char **marshalled_data_p,
5100 _dbus_return_val_if_fail (msg !=
NULL,
FALSE);
5101 _dbus_return_val_if_fail (marshalled_data_p !=
NULL,
FALSE);
5102 _dbus_return_val_if_fail (len_p !=
NULL,
FALSE);
5108 was_locked = msg->
locked;
5116 *len_p = _dbus_string_get_length (&tmp);
5121 *len_p = _dbus_string_get_length (&tmp);
5163 _dbus_return_val_if_fail (str !=
NULL,
NULL);
5201 _DBUS_SET_OOM (error);
5226 int byte_order, fields_array_len, header_len, body_len;
5240 &validity, &byte_order,
5250 _dbus_assert (have_message || (header_len + body_len) > len);
5251 (void) have_message;
5252 return header_len + body_len;
5285 _dbus_return_if_fail (message !=
NULL);
5286 _dbus_return_if_fail (!message->
locked);
5302 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
5378 &variant_signature, 0, &self->data, 0);
5381 &contained_signature, 0, &variant_writer))
5397 &contained_signature, 1, &array_writer))
5401 &real_array_reader->
u.
reader))
5425 &real_inner_reader->
u.
reader))
5476 len = _dbus_string_get_byte (&self->data, 0);
5477 ret = _dbus_string_get_const_data_len (&self->data, 1, len);
5508 _dbus_assert (_dbus_message_iter_append_check (real_writer));
5513 &variant_signature, 0, &self->data, 0);
5516 if (!_dbus_message_iter_open_signature (real_writer))
5522 if (!_dbus_message_iter_close_signature (real_writer))
5532 return _dbus_string_get_length (&self->data);
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().
void _dbus_data_slot_list_clear(DBusDataSlotList *list)
Frees all data slots contained in the list, calling application-provided free functions if they exist...
void _dbus_data_slot_list_init(DBusDataSlotList *list)
Initializes a slot list.
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...
void * _dbus_data_slot_list_get(DBusDataSlotAllocator *allocator, DBusDataSlotList *list, int slot)
Retrieves data previously set with _dbus_data_slot_list_set_data().
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_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.
void dbus_error_init(DBusError *error)
Initializes a DBusError structure.
void dbus_set_error(DBusError *error, const char *name, const char *format,...)
Assigns an error name and message to a DBusError.
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...
#define _dbus_assert_not_reached(explanation)
Aborts with an error message if called.
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
#define _DBUS_UNLOCK(name)
Unlocks a global lock.
#define _DBUS_LOCK(name)
Locks a global lock, initializing it first if necessary.
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...
char * _dbus_strdup(const char *str)
Duplicates a string.
void _dbus_warn(const char *format,...)
Prints a warning message to stderr.
#define _DBUS_LOCK_NAME(name)
Expands to name of a global lock variable.
#define _DBUS_ZERO(object)
Sets all bits in an object to zero.
void * _dbus_memdup(const void *mem, size_t n_bytes)
Duplicates a block of memory.
DBusList * _dbus_list_pop_first_link(DBusList **list)
Removes the first link in the list and returns it.
void _dbus_list_append_link(DBusList **list, DBusList *link)
Appends a link to the list.
void _dbus_list_clear_full(DBusList **list, DBusFreeFunction function)
Free every link and every element in the list.
void _dbus_list_remove_link(DBusList **list, DBusList *link)
Removes a link from the list.
DBusList * _dbus_list_find_last(DBusList **list, void *data)
Finds a value in the list.
void * _dbus_list_pop_first(DBusList **list)
Removes the first value in the list and returns it.
void _dbus_list_foreach(DBusList **list, DBusForeachFunction function, void *data)
Calls the given function for each element in the list.
void _dbus_list_clear(DBusList **list)
Frees all links in the list and sets the list head to NULL.
void _dbus_list_prepend_link(DBusList **list, DBusList *link)
Prepends a link to the list.
DBusList * _dbus_list_alloc_link(void *data)
Allocates a linked list node.
dbus_bool_t _dbus_list_remove_last(DBusList **list, void *data)
Removes a value from the list.
dbus_bool_t _dbus_list_append(DBusList **list, void *data)
Appends a value to the list.
#define NULL
A null pointer, defined appropriately for C or C++.
#define TRUE
Expands to "1".
#define FALSE
Expands to "0".
dbus_bool_t _dbus_type_writer_write_basic(DBusTypeWriter *writer, int type, const void *value)
Writes out a basic type.
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...
DBusValidity
This is primarily used in unit testing, so we can verify that each invalid message is invalid for the...
void _dbus_header_update_lengths(DBusHeader *header, int body_len)
Fills in the correct body length.
dbus_bool_t _dbus_header_copy(const DBusHeader *header, DBusHeader *dest)
Initializes dest with a copy of the given header.
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.
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...
int _dbus_type_get_alignment(int typecode)
Gets the alignment requirement for the given type; will be 1, 4, or 8.
void _dbus_type_writer_remove_types(DBusTypeWriter *writer)
Removes type string from the writer.
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.
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_header_set_field_basic(DBusHeader *header, int field, int type, const void *value)
Sets the value of a field with basic type.
int _dbus_header_get_message_type(DBusHeader *header)
Gets the type of the message.
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_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.
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_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_bool_t _dbus_header_get_flag(DBusHeader *header, dbus_uint32_t flag)
Gets a message flag bit, returning TRUE if the bit is set.
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.
void _dbus_type_reader_read_fixed_multi(const DBusTypeReader *reader, const 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...
char _dbus_header_get_byte_order(const DBusHeader *header)
Returns the header's byte order.
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,...
void _dbus_header_reinit(DBusHeader *header)
Re-initializes a header that was previously initialized and never freed.
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.
dbus_bool_t _dbus_type_reader_next(DBusTypeReader *reader)
Skip to the next value on this "level".
dbus_bool_t _dbus_header_delete_field(DBusHeader *header, int field)
Deletes a field, if it exists.
int _dbus_type_reader_get_array_length(const DBusTypeReader *reader)
Returns the number of bytes in the array.
dbus_bool_t _dbus_header_remove_unknown_fields(DBusHeader *header)
Remove every header field not known to this version of dbus.
dbus_uint32_t _dbus_header_get_serial(DBusHeader *header)
See dbus_message_get_serial()
void _dbus_type_writer_add_types(DBusTypeWriter *writer, DBusString *type_str, int type_pos)
Adds type string to the writer, if it had none.
dbus_bool_t _dbus_type_reader_has_next(const DBusTypeReader *reader)
Check whether there's another value on this "level".
void _dbus_type_reader_read_basic(const DBusTypeReader *reader, void *value)
Reads a basic-typed value, as with _dbus_marshal_read_basic().
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.
const char * _dbus_type_to_string(int typecode)
Returns a string describing the given type.
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_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...
void _dbus_header_free(DBusHeader *header)
Frees a header.
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...
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.
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_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_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_set_serial(DBusHeader *header, dbus_uint32_t serial)
Sets the serial number of a header.
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)
Creates a message header from potentially-untrusted data.
void _dbus_header_byteswap(DBusHeader *header, int new_order)
Swaps the header into the given order if required.
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.
DBusValidationMode
This is used rather than a bool for high visibility.
@ DBUS_VALIDITY_UNKNOWN_OOM_ERROR
can't determine validity due to OOM
@ DBUS_VALID
the data is valid
int _dbus_current_generation
_dbus_current_generation is used to track each time that dbus_shutdown() is called,...
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.
void(* DBusFreeFunction)(void *memory)
The type of a function which frees a block of memory.
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
void * dbus_realloc(void *memory, size_t bytes)
Resizes a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
#define dbus_new(type, count)
Safe macro for using dbus_malloc().
#define dbus_new0(type, count)
Safe macro for using dbus_malloc0().
void dbus_free_string_array(char **str_array)
Frees a NULL-terminated array of strings.
void _dbus_message_loader_set_max_message_size(DBusMessageLoader *loader, long size)
Sets the maximum size message we allow.
dbus_bool_t _dbus_message_remove_unknown_fields(DBusMessage *message)
Remove every header field not known to this version of dbus.
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.
DBusVariant * _dbus_variant_read(DBusMessageIter *reader)
Copy a single D-Bus message item from reader into a newly-allocated DBusVariant.
#define ensure_byte_order(message)
byte-swap the message if it doesn't match our byte order.
#define MAX_MESSAGE_SIZE_TO_CACHE
Avoid caching huge messages.
dbus_bool_t _dbus_variant_write(DBusVariant *self, DBusMessageIter *writer)
Copy the single D-Bus message item from self into writer.
void dbus_message_iter_init_closed(DBusMessageIter *iter)
Initialize iter as if with DBUS_MESSAGE_ITER_INIT_CLOSED.
dbus_bool_t _dbus_message_loader_get_is_corrupted(DBusMessageLoader *loader)
Checks whether the loader is confused due to bad data.
void dbus_message_set_serial(DBusMessage *message, dbus_uint32_t serial)
Sets the serial number of a message.
void dbus_message_lock(DBusMessage *message)
Locks a message.
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.
void _dbus_message_loader_unref(DBusMessageLoader *loader)
Decrements the reference count of the loader and finalizes the loader when the count reaches zero.
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 _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.
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.
DBusMessage * _dbus_message_loader_pop_message(DBusMessageLoader *loader)
Pops a loaded message (passing ownership of the message to the caller).
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.
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...
#define CHANGED_STAMP_BITS
How many bits are in the changed_stamp used to validate iterators.
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_loader_putback_message_link(DBusMessageLoader *loader, DBusList *link)
Returns a popped message link, used to undo a pop.
void * dbus_message_get_data(DBusMessage *message, dbus_int32_t slot)
Retrieves data previously set with dbus_message_set_data().
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_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...
int _dbus_message_loader_get_pending_fds_count(DBusMessageLoader *loader)
Return how many file descriptors are pending in the loader.
const char * _dbus_variant_get_signature(DBusVariant *self)
Return the signature of the item stored in self.
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_STRING_DEFINE_STATIC(_dbus_empty_signature_str, "")
An static string representing an empty signature.
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_message_free_data_slot(dbus_int32_t *slot_p)
Deallocates a global ID for message data slots.
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/...
#define INITIAL_LOADER_DATA_LEN
The initial buffer size of the message loader.
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,...
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_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.
void _dbus_message_loader_set_max_message_unix_fds(DBusMessageLoader *loader, long n)
Sets the maximum unix fds per message we allow.
long _dbus_message_loader_get_max_message_size(DBusMessageLoader *loader)
Gets the maximum allowed message size in bytes.
DBusMessageLoader * _dbus_message_loader_new(void)
Creates a new message loader.
#define MAX_MESSAGE_CACHE_SIZE
Avoid caching too many messages.
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).
dbus_bool_t _dbus_message_loader_queue_messages(DBusMessageLoader *loader)
Converts buffered data into messages, if we have enough data.
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...
DBusMessageLoader * _dbus_message_loader_ref(DBusMessageLoader *loader)
Increments the reference count of the loader.
long _dbus_message_loader_get_max_message_unix_fds(DBusMessageLoader *loader)
Gets the maximum allowed number of unix fds per message.
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,...
DBusValidity _dbus_message_loader_get_corruption_reason(DBusMessageLoader *loader)
Checks what kind of bad data confused the loader.
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...
dbus_bool_t dbus_message_has_destination(DBusMessage *message, const char *name)
Checks whether the message was sent to the given name.
dbus_bool_t dbus_message_set_interface(DBusMessage *message, const char *iface)
Sets the interface this message is being sent to (for DBUS_MESSAGE_TYPE_METHOD_CALL) or the interface...
dbus_bool_t dbus_message_has_interface(DBusMessage *message, const char *iface)
Checks if the message has an interface.
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,...
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.
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...
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...
dbus_bool_t dbus_message_iter_append_basic(DBusMessageIter *iter, int type, const void *value)
Appends a basic-typed value to the 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...
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...
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.
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_uint32_t dbus_message_get_serial(DBusMessage *message)
Returns the serial of a message or 0 if none has been specified.
dbus_bool_t dbus_message_set_member(DBusMessage *message, const char *member)
Sets the interface member being invoked (DBUS_MESSAGE_TYPE_METHOD_CALL) or emitted (DBUS_MESSAGE_TYPE...
void dbus_message_iter_get_basic(DBusMessageIter *iter, void *value)
Reads a basic-typed value from the message iterator.
int dbus_message_get_type(DBusMessage *message)
Gets the type of a message.
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 ...
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_next(DBusMessageIter *iter)
Moves the iterator to the next field, if any.
dbus_bool_t dbus_message_append_args(DBusMessage *message, int first_arg_type,...)
Appends fields to a message given a variable argument list.
int dbus_message_iter_get_arg_type(DBusMessageIter *iter)
Returns the argument type of the argument that the message iterator points to.
dbus_bool_t dbus_message_get_no_reply(DBusMessage *message)
Returns TRUE if the message does not expect a reply.
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_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.
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...
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_is_error(DBusMessage *message, const char *error_name)
Checks whether the message is an error reply with the given error name.
dbus_bool_t dbus_message_contains_unix_fds(DBusMessage *message)
Checks whether a message contains unix fds.
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...
DBusMessage * dbus_message_ref(DBusMessage *message)
Increments the reference count of a DBusMessage.
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.
int dbus_message_iter_get_element_type(DBusMessageIter *iter)
Returns the element type of the array that the message iterator points to.
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_bool_t dbus_message_has_signature(DBusMessage *message, const char *signature)
Checks whether the message has the given signature; see dbus_message_get_signature() for more details...
dbus_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_uint32_t dbus_message_get_reply_serial(DBusMessage *message)
Returns the serial that the message is a reply to or 0 if none.
DBusMessage * dbus_message_new_method_return(DBusMessage *method_call)
Constructs a message that is a reply to a method call.
DBusMessage * dbus_message_new_method_call(const char *destination, const char *path, const char *iface, const char *method)
Constructs a new message to invoke a method on a remote object.
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_set_sender(DBusMessage *message, const char *sender)
Sets the message sender.
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...
const char * dbus_message_get_destination(DBusMessage *message)
Gets the destination of a message or NULL if there is none set.
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...
dbus_bool_t dbus_message_iter_has_next(DBusMessageIter *iter)
Checks if an iterator has any more fields.
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.
char * dbus_message_iter_get_signature(DBusMessageIter *iter)
Returns the current signature of a message iterator.
void dbus_message_unref(DBusMessage *message)
Decrements the reference count of a DBusMessage, freeing the message if the count reaches 0.
int dbus_message_iter_get_array_len(DBusMessageIter *iter)
Returns the number of bytes in the array as marshaled in the wire protocol.
DBusMessage * dbus_message_new(int message_type)
Constructs a new message of the given message type.
dbus_bool_t dbus_set_error_from_message(DBusError *error, DBusMessage *message)
Sets a DBusError based on the contents of the given message.
int dbus_message_iter_get_element_count(DBusMessageIter *iter)
Returns the number of elements in the array-typed value pointed to by the iterator.
dbus_bool_t dbus_message_set_destination(DBusMessage *message, const char *destination)
Sets the message's destination.
dbus_bool_t dbus_message_has_path(DBusMessage *message, const char *path)
Checks if the message has a particular object path.
dbus_bool_t dbus_message_has_member(DBusMessage *message, const char *member)
Checks if the message has an interface member.
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.
dbus_bool_t dbus_message_is_method_call(DBusMessage *message, const char *iface, const char *method)
Checks whether the message is a method call with the given interface and member fields.
void dbus_message_iter_get_fixed_array(DBusMessageIter *iter, void *value, int *n_elements)
Reads a block of fixed-length values from the message iterator.
dbus_bool_t dbus_message_set_reply_serial(DBusMessage *message, dbus_uint32_t reply_serial)
Sets the reply serial of a message (the serial of the message this is a reply to).
dbus_bool_t dbus_message_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.
const char * dbus_message_get_signature(DBusMessage *message)
Gets the type signature of the message, i.e.
dbus_bool_t dbus_message_set_container_instance(DBusMessage *message, const char *object_path)
Sets the container instance this message was sent from.
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_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...
const char * dbus_message_get_member(DBusMessage *message)
Gets the interface member being invoked (DBUS_MESSAGE_TYPE_METHOD_CALL) or emitted (DBUS_MESSAGE_TYPE...
void dbus_message_iter_init_append(DBusMessage *message, DBusMessageIter *iter)
Initializes a DBusMessageIter for appending arguments to the end of a message.
const char * dbus_message_get_container_instance(DBusMessage *message)
Gets the container instance this message was sent from, or NULL if none.
dbus_bool_t _dbus_decompose_path(const char *data, int len, char ***path, int *path_len)
Decompose an object path.
#define DBUS_HEADER_FIELD_UNIX_FDS
Header field code for the number of unix file descriptors associated with this message.
#define DBUS_MESSAGE_TYPE_METHOD_CALL
Message type of a method call message, see dbus_message_get_type()
#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...
#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,...
#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...
#define DBUS_HEADER_FIELD_CONTAINER_INSTANCE
Header field code for the container instance that sent this message.
#define DBUS_TYPE_SIGNATURE
Type code marking a D-Bus type signature.
#define DBUS_MAXIMUM_MESSAGE_UNIX_FDS
The maximum total number of unix fds in a message.
#define DBUS_MAXIMUM_MESSAGE_LENGTH
The maximum total message size including header and body; similar rationale to max array size.
#define DBUS_HEADER_FIELD_INTERFACE
Header field code for the interface containing a member (method or signal).
#define DBUS_ERROR_INCONSISTENT_MESSAGE
The message meta data does not match the payload.
#define DBUS_HEADER_FIELD_MEMBER
Header field code for a member (method or signal).
#define DBUS_MESSAGE_TYPE_ERROR
Message type of an error reply message, see dbus_message_get_type()
#define DBUS_TYPE_OBJECT_PATH
Type code marking a D-Bus object path.
#define DBUS_ERROR_NOT_SUPPORTED
Requested operation isn't supported (like ENOSYS on UNIX).
#define DBUS_HEADER_FIELD_SENDER
Header field code for the sender of a message; usually initialized by the message bus.
#define DBUS_HEADER_FIELD_SIGNATURE
Header field code for the type signature of a message.
#define DBUS_MESSAGE_TYPE_METHOD_RETURN
Message type of a method return message, see dbus_message_get_type()
#define DBUS_TYPE_VARIANT
Type code marking a D-Bus variant type.
#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...
#define DBUS_TYPE_UNIX_FD
Type code marking a unix file descriptor.
#define DBUS_TYPE_BOOLEAN
Type code marking a boolean.
#define DBUS_MESSAGE_TYPE_SIGNAL
Message type of a signal message, see dbus_message_get_type()
#define DBUS_TYPE_STRING
Type code marking a UTF-8 encoded, nul-terminated Unicode string.
#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 ...
#define DBUS_TYPE_ARRAY
Type code marking a D-Bus array 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...
#define DBUS_TYPE_INVALID
Type code that is never equal to a legitimate type code.
#define DBUS_HEADER_FIELD_ERROR_NAME
Header field code for an error name (found in DBUS_MESSAGE_TYPE_ERROR messages).
#define DBUS_TYPE_VARIANT_AS_STRING
DBUS_TYPE_VARIANT as a string literal instead of a int literal
#define DBUS_MESSAGE_TYPE_INVALID
This value is never a valid message type, see dbus_message_get_type()
#define DBUS_ERROR_INVALID_ARGS
Invalid arguments passed to a method call.
#define DBUS_TYPE_DICT_ENTRY
Type code used to represent a dict entry; however, this type code does not appear in type signatures,...
#define DBUS_DICT_ENTRY_BEGIN_CHAR
Code marking the start of a dict entry type in a type signature.
#define DBUS_HEADER_FIELD_DESTINATION
Header field code for the destination bus name of a message.
#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_UINT32
Type code marking a 32-bit unsigned integer.
#define DBUS_MINIMUM_HEADER_SIZE
The smallest header size that can occur.
void _dbus_counter_unref(DBusCounter *counter)
Decrements refcount of the counter and possibly finalizes the counter.
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.
void _dbus_counter_notify(DBusCounter *counter)
Calls the notify function from _dbus_counter_set_notify(), if that function has been specified and th...
DBusCounter * _dbus_counter_ref(DBusCounter *counter)
Increments refcount of the counter.
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.
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...
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.
dbus_bool_t dbus_type_is_container(int typecode)
A "container type" can contain basic types, or nested container types.
dbus_bool_t _dbus_string_set_length(DBusString *str, int length)
Sets the length of a string.
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
void _dbus_string_init_const(DBusString *str, const char *value)
Initializes a constant string.
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...
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.
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_string_init_const_len(DBusString *str, const char *value, int len)
Initializes a constant string with a length.
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.
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init(), and fills it with the same contents as #_DBUS_STRING_I...
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_append_printf_valist(DBusString *str, const char *format, va_list args)
Appends a printf-style formatted string to the DBusString.
dbus_bool_t _dbus_string_compact(DBusString *str, int max_waste)
Compacts the string to avoid wasted memory.
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_close(int fd, DBusError *error)
Closes a file descriptor.
int _dbus_dup(int fd, DBusError *error)
Duplicates a file descriptor.
dbus_int32_t _dbus_atomic_dec(DBusAtomic *atomic)
Atomically decrement an integer.
const char * _dbus_getenv(const char *varname)
Wrapper for getenv().
dbus_int32_t _dbus_atomic_get(DBusAtomic *atomic)
Atomically get the value of an integer.
dbus_int32_t _dbus_atomic_inc(DBusAtomic *atomic)
Atomically increments an integer.
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
Internals of DBusCounter.
An allocator that tracks a set of slot IDs.
Object representing an exception.
const char * message
public error message field
void * data
Data stored at this element.
Layout of a DBusMessageIter on the stack in dbus 1.10.0.
DBusMessageIter struct; contains no public fields.
Implementation details of DBusMessageLoader.
long max_message_size
Maximum size of a message.
long max_message_unix_fds
Maximum unix fds in a message.
DBusString data
Buffered data.
DBusList * messages
Complete messages.
unsigned int corrupted
We got broken data, and are no longer working.
unsigned int buffer_outstanding
Someone is using the buffer to read.
DBusValidity corruption_reason
why we were corrupted
int refcount
Reference count.
Internals of DBusMessageIter.
union DBusMessageRealIter::@6 u
the type writer or reader that does all the work
DBusMessage * message
Message used.
dbus_uint32_t iter_type
whether this is a reader or writer iter
dbus_uint32_t sig_refcount
depth of open_signature()
DBusTypeWriter writer
writer
dbus_uint32_t changed_stamp
stamp to detect invalid iters
DBusTypeReader reader
reader
Internals of DBusMessage.
DBusHeader header
Header network data and associated cache.
DBusString body
Body network data.
DBusDataSlotList slot_list
Data stored by allocated integer ID.
DBusAtomic refcount
Reference count.
dbus_uint32_t changed_stamp
Incremented when iterators are invalidated.
int generation
_dbus_current_generation when message was created
long size_counter_delta
Size we incremented the size counters by.
DBusList * counters
0-N DBusCounter used to track message size/unix fds.
unsigned int in_cache
Has been "freed" since it's in the cache (this is a debug feature)
unsigned int locked
Message being sent, no modifications allowed.
The type reader is an iterator for reading values from a block of values.
dbus_uint32_t byte_order
byte order of the block
The type writer is an iterator for writing to a block of values.
dbus_uint32_t byte_order
byte order to write values with
DBusString * type_str
where to write typecodes (or read type expectations)
dbus_uint32_t container_type
what are we inside? (e.g.
An opaque data structure containing the serialized form of any single D-Bus message item,...
A simple value union that lets you access bytes as if they were various types; useful when dealing wi...
dbus_uint32_t u32
as int32