1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-message.c DBusMessage object
4 * Copyright (C) 2002, 2003 Red Hat Inc.
5 * Copyright (C) 2002, 2003 CodeFactory AB
7 * Licensed under the Academic Free License version 1.2
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "dbus-internals.h"
26 #include "dbus-marshal.h"
27 #include "dbus-message.h"
28 #include "dbus-message-internal.h"
29 #include "dbus-memory.h"
30 #include "dbus-list.h"
31 #include "dbus-message-builder.h"
35 * @defgroup DBusMessageInternals DBusMessage implementation details
36 * @ingroup DBusInternals
37 * @brief DBusMessage private implementation details.
39 * The guts of DBusMessage and its methods.
57 static dbus_bool_t field_is_named[FIELD_LAST] =
59 FALSE, /* FIELD_HEADER_LENGTH */
60 FALSE, /* FIELD_BODY_LENGTH */
61 FALSE, /* FIELD_CLIENT_SERIAL */
62 TRUE, /* FIELD_NAME */
63 TRUE, /* FIELD_SERVICE */
64 TRUE, /* FIELD_SENDER */
65 TRUE /* FIELD_REPLY_SERIAL */
70 int offset; /**< Offset to start of field (location of name of field
76 * @brief Internals of DBusMessage
78 * Object representing a message received from or to be sent to
79 * another application. This is an opaque object, all members
84 dbus_atomic_t refcount; /**< Reference count */
86 DBusString header; /**< Header network data, stored
87 * separately from body so we can
88 * independently realloc it.
91 HeaderField header_fields[FIELD_LAST]; /**< Track the location
92 * of each field in "header"
94 int header_padding; /**< bytes of alignment in header */
96 DBusString body; /**< Body network data. */
98 char byte_order; /**< Message byte order. */
100 DBusCounter *size_counter; /**< Counter for the size of the message, or #NULL */
101 long size_counter_delta; /**< Size we incremented the size counter by. */
103 unsigned int locked : 1; /**< Message being sent, no modifications allowed. */
107 * @brief Internals of DBusMessageIter
109 * Object representing a position in a message. All fields are internal.
111 struct DBusMessageIter
113 int refcount; /**< Reference count */
115 int pos; /**< Current position in the string */
117 DBusMessage *message; /**< Message used */
121 * Gets the data to be sent over the network for this message.
122 * The header and then the body should be written out.
123 * This function is guaranteed to always return the same
124 * data once a message is locked (with _dbus_message_lock()).
126 * @param message the message.
127 * @param header return location for message header data.
128 * @param body return location for message body data.
131 _dbus_message_get_network_data (DBusMessage *message,
132 const DBusString **header,
133 const DBusString **body)
135 _dbus_assert (message->locked);
137 *header = &message->header;
138 *body = &message->body;
142 clear_header_padding (DBusMessage *message)
144 _dbus_string_shorten (&message->header,
145 message->header_padding);
146 message->header_padding = 0;
150 append_header_padding (DBusMessage *message)
153 old_len = _dbus_string_get_length (&message->header);
154 if (!_dbus_string_align_length (&message->header, 8))
157 message->header_padding = _dbus_string_get_length (&message->header) - old_len;
163 adjust_field_offsets (DBusMessage *message,
173 while (i < FIELD_LAST)
175 if (message->header_fields[i].offset > offsets_after)
176 message->header_fields[i].offset += delta;
183 get_string_field (DBusMessage *message,
187 int offset = message->header_fields[field].offset;
193 /* offset points to string length, string data follows it */
194 /* FIXME _dbus_demarshal_const_string() that returned
195 * a reference to the string plus its len might be nice.
199 *len = _dbus_demarshal_uint32 (&message->header,
204 _dbus_string_get_const_data (&message->header,
207 return data + (offset + 4);
211 get_int_field (DBusMessage *message,
214 int offset = message->header_fields[field].offset;
217 return -1; /* useless if -1 is a valid value of course */
219 return _dbus_demarshal_int32 (&message->header,
226 append_int_field (DBusMessage *message,
233 _dbus_assert (!message->locked);
235 clear_header_padding (message);
237 orig_len = _dbus_string_get_length (&message->header);
239 if (!_dbus_string_align_length (&message->header, 4))
242 if (!_dbus_string_append_len (&message->header, name, 4))
245 if (!_dbus_string_append_byte (&message->header, DBUS_TYPE_INT32))
248 if (!_dbus_string_align_length (&message->header, 4))
251 message->header_fields[FIELD_REPLY_SERIAL].offset =
252 _dbus_string_get_length (&message->header);
254 if (!_dbus_marshal_int32 (&message->header, message->byte_order,
258 if (!append_header_padding (message))
264 message->header_fields[field].offset = -1;
265 _dbus_string_set_length (&message->header, orig_len);
267 /* this must succeed because it was allocated on function entry and
268 * DBusString doesn't ever realloc smaller
270 if (!append_header_padding (message))
271 _dbus_assert_not_reached ("failed to reappend header padding");
276 append_string_field (DBusMessage *message,
283 _dbus_assert (!message->locked);
285 clear_header_padding (message);
287 orig_len = _dbus_string_get_length (&message->header);
289 if (!_dbus_string_align_length (&message->header, 4))
292 if (!_dbus_string_append_len (&message->header, name, 4))
295 if (!_dbus_string_append_byte (&message->header, DBUS_TYPE_STRING))
298 if (!_dbus_string_align_length (&message->header, 4))
301 message->header_fields[field].offset =
302 _dbus_string_get_length (&message->header);
304 if (!_dbus_marshal_string (&message->header, message->byte_order,
308 if (!append_header_padding (message))
314 message->header_fields[field].offset = -1;
315 _dbus_string_set_length (&message->header, orig_len);
317 /* this must succeed because it was allocated on function entry and
318 * DBusString doesn't ever realloc smaller
320 if (!append_header_padding (message))
321 _dbus_assert_not_reached ("failed to reappend header padding");
327 delete_int_field (DBusMessage *message,
330 int offset = message->header_fields[field].offset;
332 _dbus_assert (!message->locked);
333 _dbus_assert (field_is_named[field]);
338 clear_header_padding (message);
340 /* The field typecode and name take up 8 bytes */
341 _dbus_string_delete (&message->header,
345 message->header_fields[field].offset = -1;
347 adjust_field_offsets (message,
351 append_header_padding (message);
355 delete_string_field (DBusMessage *message,
358 int offset = message->header_fields[field].offset;
362 _dbus_assert (!message->locked);
363 _dbus_assert (field_is_named[field]);
368 clear_header_padding (message);
370 get_string_field (message, field, &len);
372 /* The field typecode and name take up 8 bytes, and the nul
373 * termination is 1 bytes, string length integer is 4 bytes
375 delete_len = 8 + 4 + 1 + len;
377 _dbus_string_delete (&message->header,
381 message->header_fields[field].offset = -1;
383 adjust_field_offsets (message,
387 append_header_padding (message);
391 set_int_field (DBusMessage *message,
395 int offset = message->header_fields[field].offset;
397 _dbus_assert (!message->locked);
401 /* need to append the field */
405 case FIELD_REPLY_SERIAL:
406 return append_int_field (message, field,
407 DBUS_HEADER_FIELD_REPLY,
410 _dbus_assert_not_reached ("appending an int field we don't support appending");
416 _dbus_marshal_set_int32 (&message->header,
425 set_uint_field (DBusMessage *message,
429 int offset = message->header_fields[field].offset;
431 _dbus_assert (!message->locked);
435 /* need to append the field */
440 _dbus_assert_not_reached ("appending a uint field we don't support appending");
446 _dbus_marshal_set_uint32 (&message->header,
455 set_string_field (DBusMessage *message,
459 int offset = message->header_fields[field].offset;
461 _dbus_assert (!message->locked);
462 _dbus_assert (value != NULL);
466 /* need to append the field */
471 return append_string_field (message, field,
472 DBUS_HEADER_FIELD_SENDER,
475 _dbus_assert_not_reached ("appending a string field we don't support appending");
485 old_len = _dbus_string_get_length (&message->header);
487 _dbus_string_init_const_len (&v, value,
488 strlen (value) + 1); /* include nul */
489 if (!_dbus_marshal_set_string (&message->header,
494 new_len = _dbus_string_get_length (&message->header);
496 adjust_field_offsets (message,
505 * Sets the client serial of a message.
506 * This can only be done once on a message.
508 * @todo client_serial should be called simply
509 * "serial"; it's in outgoing messages for both
510 * the client and the server, it's only client-specific
511 * in the message bus case. It's more like origin_serial
514 * @param message the message
515 * @param client_serial the client serial
518 _dbus_message_set_client_serial (DBusMessage *message,
519 dbus_int32_t client_serial)
521 _dbus_assert (!message->locked);
522 _dbus_assert (_dbus_message_get_client_serial (message) < 0);
524 set_int_field (message, FIELD_CLIENT_SERIAL,
529 * Sets the reply serial of a message (the client serial
530 * of the message this is a reply to).
532 * @param message the message
533 * @param reply_serial the client serial
534 * @returns #FALSE if not enough memory
537 _dbus_message_set_reply_serial (DBusMessage *message,
538 dbus_int32_t reply_serial)
540 _dbus_assert (!message->locked);
542 return set_int_field (message, FIELD_REPLY_SERIAL,
547 * Returns the client serial of a message or
548 * -1 if none has been specified.
550 * @todo see note in _dbus_message_set_client_serial()
551 * about how client_serial is a misnomer
553 * @todo this function should be public, after renaming it.
555 * @param message the message
556 * @returns the client serial
559 _dbus_message_get_client_serial (DBusMessage *message)
561 return get_int_field (message, FIELD_CLIENT_SERIAL);
565 * Returns the serial that the message is
566 * a reply to or -1 if none.
568 * @param message the message
569 * @returns the reply serial
572 _dbus_message_get_reply_serial (DBusMessage *message)
574 return get_int_field (message, FIELD_REPLY_SERIAL);
578 * Adds a counter to be incremented immediately with the
579 * size of this message, and decremented by the size
580 * of this message when this message if finalized.
582 * @param message the message
583 * @param counter the counter
586 _dbus_message_add_size_counter (DBusMessage *message,
587 DBusCounter *counter)
589 _dbus_assert (message->size_counter == NULL); /* If this fails we may need to keep a list of
590 * counters instead of just one
593 message->size_counter = counter;
594 _dbus_counter_ref (message->size_counter);
596 /* When we can change message size, we may want to
597 * update this each time we do so, or we may want to
598 * just KISS like this.
600 message->size_counter_delta =
601 _dbus_string_get_length (&message->header) +
602 _dbus_string_get_length (&message->body);
604 _dbus_verbose ("message has size %ld\n",
605 message->size_counter_delta);
607 _dbus_counter_adjust (message->size_counter, message->size_counter_delta);
611 dbus_message_create_header (DBusMessage *message,
617 if (!_dbus_string_append_byte (&message->header, message->byte_order))
621 if (!_dbus_string_append_byte (&message->header, flags))
624 if (!_dbus_string_append_byte (&message->header, DBUS_MAJOR_PROTOCOL_VERSION))
627 if (!_dbus_string_append_byte (&message->header, 0))
630 message->header_fields[FIELD_HEADER_LENGTH].offset = 4;
631 if (!_dbus_marshal_uint32 (&message->header, message->byte_order, 0))
634 message->header_fields[FIELD_BODY_LENGTH].offset = 8;
635 if (!_dbus_marshal_uint32 (&message->header, message->byte_order, 0))
638 message->header_fields[FIELD_CLIENT_SERIAL].offset = 12;
639 if (!_dbus_marshal_int32 (&message->header, message->byte_order, -1))
642 /* Marshal message service */
645 if (!append_string_field (message,
647 DBUS_HEADER_FIELD_SERVICE,
652 _dbus_assert (name != NULL);
653 if (!append_string_field (message,
655 DBUS_HEADER_FIELD_NAME,
663 * Locks a message. Allows checking that applications don't keep a
664 * reference to a message in the outgoing queue and change it
665 * underneath us. Messages are locked when they enter the outgoing
666 * queue (dbus_connection_send_message()), and the library complains
667 * if the message is modified while locked.
669 * @param message the message to lock.
672 _dbus_message_lock (DBusMessage *message)
674 if (!message->locked)
676 /* Fill in our lengths */
677 set_uint_field (message,
679 _dbus_string_get_length (&message->header));
681 set_uint_field (message,
683 _dbus_string_get_length (&message->body));
685 message->locked = TRUE;
692 * @defgroup DBusMessage DBusMessage
694 * @brief Message to be sent or received over a DBusConnection.
696 * A DBusMessage is the most basic unit of communication over a
697 * DBusConnection. A DBusConnection represents a stream of messages
698 * received from a remote application, and a stream of messages
699 * sent to a remote application.
705 * @typedef DBusMessage
707 * Opaque data type representing a message received from or to be
708 * sent to another application.
712 dbus_message_new_empty_header (void)
714 DBusMessage *message;
717 message = dbus_new0 (DBusMessage, 1);
721 message->refcount = 1;
722 message->byte_order = DBUS_COMPILER_BYTE_ORDER;
725 while (i < FIELD_LAST)
727 message->header_fields[i].offset = -1;
731 if (!_dbus_string_init (&message->header, _DBUS_INT_MAX))
737 if (!_dbus_string_init (&message->body, _DBUS_INT_MAX))
739 _dbus_string_free (&message->header);
749 * Constructs a new message. Returns #NULL if memory can't be
750 * allocated for the message. The service may be #NULL in which case
751 * no service is set; this is appropriate when using D-BUS in a
752 * peer-to-peer context (no message bus).
754 * @todo reverse the arguments, first 'name' then 'service'
755 * as 'name' is more fundamental
757 * @param service service that the message should be sent to or #NULL
758 * @param name name of the message
759 * @returns a new DBusMessage, free with dbus_message_unref()
760 * @see dbus_message_unref()
763 dbus_message_new (const char *service,
766 DBusMessage *message;
768 message = dbus_message_new_empty_header ();
772 if (!dbus_message_create_header (message, service, name))
774 dbus_message_unref (message);
782 * Constructs a message that is a reply to some other
783 * message. Returns #NULL if memory can't be allocated
786 * @param original_message the message which the created
787 * message is a reply to.
788 * @returns a new DBusMessage, free with dbus_message_unref()
789 * @see dbus_message_new(), dbus_message_unref()
792 dbus_message_new_reply (DBusMessage *original_message)
794 DBusMessage *message;
795 const char *sender, *name;
797 sender = get_string_field (original_message,
799 name = get_string_field (original_message,
802 _dbus_assert (sender != NULL);
804 message = dbus_message_new (sender, name);
809 if (!_dbus_message_set_reply_serial (message,
810 _dbus_message_get_client_serial (original_message)))
812 dbus_message_unref (message);
820 * Creates a new message that is an error reply to a certain message.
822 * @param original_message the original message
823 * @param error_name the error name
824 * @param error_message the error message string
825 * @returns a new error message
828 dbus_message_new_error_reply (DBusMessage *original_message,
829 const char *error_name,
830 const char *error_message)
832 DBusMessage *message;
835 sender = get_string_field (original_message,
838 _dbus_assert (sender != NULL);
840 message = dbus_message_new (sender, error_name);
845 if (!_dbus_message_set_reply_serial (message,
846 _dbus_message_get_client_serial (original_message)))
848 dbus_message_unref (message);
852 if (!dbus_message_append_string (message, error_message))
854 dbus_message_unref (message);
858 dbus_message_set_is_error (message, TRUE);
864 * Creates a new message that is an exact replica of the message
865 * specified, except that its refcount is set to 1.
867 * @param message the message.
868 * @returns the new message.
871 dbus_message_new_from_message (const DBusMessage *message)
876 retval = dbus_new0 (DBusMessage, 1);
880 retval->refcount = 1;
881 retval->byte_order = message->byte_order;
883 if (!_dbus_string_init (&retval->header, _DBUS_INT_MAX))
889 if (!_dbus_string_init (&retval->body, _DBUS_INT_MAX))
891 _dbus_string_free (&retval->header);
896 if (!_dbus_string_copy (&message->header, 0,
899 _dbus_string_free (&retval->header);
900 _dbus_string_free (&retval->body);
906 if (!_dbus_string_copy (&message->body, 0,
909 _dbus_string_free (&retval->header);
910 _dbus_string_free (&retval->body);
916 for (i = 0; i < FIELD_LAST; i++)
918 retval->header_fields[i].offset = message->header_fields[i].offset;
926 * Increments the reference count of a DBusMessage.
928 * @param message The message
929 * @see dbus_message_unref
932 dbus_message_ref (DBusMessage *message)
934 dbus_atomic_t refcount;
936 refcount = _dbus_atomic_inc (&message->refcount);
937 _dbus_assert (refcount > 1);
941 * Decrements the reference count of a DBusMessage.
943 * @param message The message
944 * @see dbus_message_ref
947 dbus_message_unref (DBusMessage *message)
949 dbus_atomic_t refcount;
951 refcount = _dbus_atomic_dec (&message->refcount);
953 _dbus_assert (refcount >= 0);
957 if (message->size_counter != NULL)
959 _dbus_counter_adjust (message->size_counter,
960 - message->size_counter_delta);
961 _dbus_counter_unref (message->size_counter);
964 _dbus_string_free (&message->header);
965 _dbus_string_free (&message->body);
972 * Gets the name of a message.
974 * @param message the message
975 * @returns the message name (should not be freed)
978 dbus_message_get_name (DBusMessage *message)
980 return get_string_field (message, FIELD_NAME, NULL);
984 * Gets the destination service of a message.
986 * @param message the message
987 * @returns the message destination service (should not be freed)
990 dbus_message_get_service (DBusMessage *message)
992 return get_string_field (message, FIELD_SERVICE, NULL);
996 * Appends fields to a message given a variable argument
997 * list. The variable argument list should contain the type
998 * of the argument followed by the value to add. Array values
999 * are specified by a pointer to the array followed by an int
1000 * giving the length of the array. The list is terminated
1003 * @param message the message
1004 * @param first_arg_type type of the first argument
1005 * @param ... value of first argument, list of additional type-value pairs
1006 * @returns #TRUE on success
1009 dbus_message_append_args (DBusMessage *message,
1016 va_start (var_args, first_arg_type);
1017 retval = dbus_message_append_args_valist (message,
1026 * This function takes a va_list for use by language bindings
1028 * @see dbus_message_append_args.
1029 * @param message the message
1030 * @param first_arg_type type of first argument
1031 * @param var_args value of first argument, then list of type/value pairs
1032 * @returns #TRUE on success
1035 dbus_message_append_args_valist (DBusMessage *message,
1041 old_len = _dbus_string_get_length (&message->body);
1043 type = first_arg_type;
1050 if (!dbus_message_append_nil (message))
1052 case DBUS_TYPE_INT32:
1053 if (!dbus_message_append_int32 (message, va_arg (var_args, dbus_int32_t)))
1056 case DBUS_TYPE_UINT32:
1057 if (!dbus_message_append_uint32 (message, va_arg (var_args, dbus_uint32_t)))
1060 case DBUS_TYPE_DOUBLE:
1061 if (!dbus_message_append_double (message, va_arg (var_args, double)))
1064 case DBUS_TYPE_STRING:
1065 if (!dbus_message_append_string (message, va_arg (var_args, const char *)))
1068 case DBUS_TYPE_INT32_ARRAY:
1073 data = va_arg (var_args, dbus_int32_t *);
1074 len = va_arg (var_args, int);
1076 if (!dbus_message_append_int32_array (message, data, len))
1080 case DBUS_TYPE_UINT32_ARRAY:
1083 dbus_uint32_t *data;
1085 data = va_arg (var_args, dbus_uint32_t *);
1086 len = va_arg (var_args, int);
1088 if (!dbus_message_append_uint32_array (message, data, len))
1092 case DBUS_TYPE_DOUBLE_ARRAY:
1097 data = va_arg (var_args, double *);
1098 len = va_arg (var_args, int);
1100 if (!dbus_message_append_double_array (message, data, len))
1104 case DBUS_TYPE_BYTE_ARRAY:
1107 unsigned char *data;
1109 data = va_arg (var_args, unsigned char *);
1110 len = va_arg (var_args, int);
1112 if (!dbus_message_append_byte_array (message, data, len))
1116 case DBUS_TYPE_STRING_ARRAY:
1121 data = va_arg (var_args, const char **);
1122 len = va_arg (var_args, int);
1124 if (!dbus_message_append_string_array (message, data, len))
1130 _dbus_warn ("Unknown field type %d\n", type);
1133 type = va_arg (var_args, int);
1143 * Appends a nil value to the message
1145 * @param message the message
1146 * @returns #TRUE on success
1149 dbus_message_append_nil (DBusMessage *message)
1151 _dbus_assert (!message->locked);
1153 if (!_dbus_string_append_byte (&message->body, DBUS_TYPE_NIL))
1155 _dbus_string_shorten (&message->body, 1);
1163 * Appends a 32 bit signed integer to the message.
1165 * @param message the message
1166 * @param value the integer value
1167 * @returns #TRUE on success
1170 dbus_message_append_int32 (DBusMessage *message,
1173 _dbus_assert (!message->locked);
1175 if (!_dbus_string_append_byte (&message->body, DBUS_TYPE_INT32))
1177 _dbus_string_shorten (&message->body, 1);
1181 return _dbus_marshal_int32 (&message->body,
1182 message->byte_order, value);
1186 * Appends a 32 bit unsigned integer to the message.
1188 * @param message the message
1189 * @param value the integer value
1190 * @returns #TRUE on success
1193 dbus_message_append_uint32 (DBusMessage *message,
1194 dbus_uint32_t value)
1196 _dbus_assert (!message->locked);
1198 if (!_dbus_string_append_byte (&message->body, DBUS_TYPE_UINT32))
1200 _dbus_string_shorten (&message->body, 1);
1204 return _dbus_marshal_uint32 (&message->body,
1205 message->byte_order, value);
1209 * Appends a double value to the message.
1211 * @param message the message
1212 * @param value the double value
1213 * @returns #TRUE on success
1216 dbus_message_append_double (DBusMessage *message,
1219 _dbus_assert (!message->locked);
1221 if (!_dbus_string_append_byte (&message->body, DBUS_TYPE_DOUBLE))
1223 _dbus_string_shorten (&message->body, 1);
1227 return _dbus_marshal_double (&message->body,
1228 message->byte_order, value);
1232 * Appends a UTF-8 string to the message.
1234 * @param message the message
1235 * @param value the string
1236 * @returns #TRUE on success
1239 dbus_message_append_string (DBusMessage *message,
1242 _dbus_assert (!message->locked);
1244 if (!_dbus_string_append_byte (&message->body, DBUS_TYPE_STRING))
1246 _dbus_string_shorten (&message->body, 1);
1250 return _dbus_marshal_string (&message->body,
1251 message->byte_order, value);
1255 * Appends a 32 bit signed integer array to the message.
1257 * @param message the message
1258 * @param value the array
1259 * @param len the length of the array
1260 * @returns #TRUE on success
1263 dbus_message_append_int32_array (DBusMessage *message,
1264 const dbus_int32_t *value,
1269 _dbus_assert (!message->locked);
1271 old_len = _dbus_string_get_length (&message->body);
1273 if (!_dbus_string_append_byte (&message->body, DBUS_TYPE_INT32_ARRAY))
1276 if (!_dbus_marshal_int32_array (&message->body, message->byte_order,
1283 _dbus_string_set_length (&message->body, old_len);
1288 * Appends a 32 bit unsigned integer array to the message.
1290 * @param message the message
1291 * @param value the array
1292 * @param len the length of the array
1293 * @returns #TRUE on success
1296 dbus_message_append_uint32_array (DBusMessage *message,
1297 const dbus_uint32_t *value,
1302 _dbus_assert (!message->locked);
1304 old_len = _dbus_string_get_length (&message->body);
1306 if (!_dbus_string_append_byte (&message->body, DBUS_TYPE_UINT32_ARRAY))
1309 if (!_dbus_marshal_uint32_array (&message->body, message->byte_order,
1316 _dbus_string_set_length (&message->body, old_len);
1321 * Appends a double array to the message.
1323 * @param message the message
1324 * @param value the array
1325 * @param len the length of the array
1326 * @returns #TRUE on success
1329 dbus_message_append_double_array (DBusMessage *message,
1330 const double *value,
1335 _dbus_assert (!message->locked);
1337 old_len = _dbus_string_get_length (&message->body);
1339 if (!_dbus_string_append_byte (&message->body, DBUS_TYPE_DOUBLE_ARRAY))
1342 if (!_dbus_marshal_double_array (&message->body, message->byte_order,
1349 _dbus_string_set_length (&message->body, old_len);
1354 * Appends a byte array to the message.
1356 * @param message the message
1357 * @param value the array
1358 * @param len the length of the array
1359 * @returns #TRUE on success
1362 dbus_message_append_byte_array (DBusMessage *message,
1363 unsigned const char *value,
1368 _dbus_assert (!message->locked);
1370 old_len = _dbus_string_get_length (&message->body);
1372 if (!_dbus_string_append_byte (&message->body, DBUS_TYPE_BYTE_ARRAY))
1375 if (!_dbus_marshal_byte_array (&message->body, message->byte_order, value, len))
1381 _dbus_string_set_length (&message->body, old_len);
1386 * Appends a string array to the message.
1388 * @param message the message
1389 * @param value the array
1390 * @param len the length of the array
1391 * @returns #TRUE on success
1394 dbus_message_append_string_array (DBusMessage *message,
1400 _dbus_assert (!message->locked);
1402 old_len = _dbus_string_get_length (&message->body);
1404 if (!_dbus_string_append_byte (&message->body, DBUS_TYPE_STRING_ARRAY))
1407 if (!_dbus_marshal_string_array (&message->body, message->byte_order,
1414 _dbus_string_set_length (&message->body, old_len);
1419 * Gets arguments from a message given a variable argument list.
1420 * The variable argument list should contain the type of the
1421 * argumen followed by a pointer to where the value should be
1422 * stored. The list is terminated with 0.
1424 * @param message the message
1425 * @param first_arg_type the first argument type
1426 * @param ... location for first argument value, then list of type-location pairs
1427 * @returns result code
1430 dbus_message_get_args (DBusMessage *message,
1434 DBusResultCode retval;
1437 va_start (var_args, first_arg_type);
1438 retval = dbus_message_get_args_valist (message, first_arg_type, var_args);
1445 * This function takes a va_list for use by language bindings
1447 * @todo this function (or some lower-level non-convenience function)
1448 * needs better error handling; should allow the application to
1449 * distinguish between out of memory, and bad data from the remote
1450 * app. It also needs to not leak a bunch of args when it gets
1451 * to the arg that's bad, as that would be a security hole
1452 * (allow one app to force another to leak memory)
1454 * @todo We need to free the argument data when an error occurs.
1456 * @see dbus_message_get_args
1457 * @param message the message
1458 * @param first_arg_type type of the first argument
1459 * @param var_args return location for first argument, followed by list of type/location pairs
1460 * @returns result code
1463 dbus_message_get_args_valist (DBusMessage *message,
1467 int spec_type, msg_type, i;
1468 DBusMessageIter *iter;
1470 iter = dbus_message_get_args_iter (message);
1473 return DBUS_RESULT_NO_MEMORY;
1475 spec_type = first_arg_type;
1478 while (spec_type != 0)
1480 msg_type = dbus_message_iter_get_arg_type (iter);
1482 if (msg_type != spec_type)
1484 _dbus_verbose ("Argument %d is specified to be of type \"%s\", but "
1485 "is actually of type \"%s\"\n", i,
1486 _dbus_type_to_string (spec_type),
1487 _dbus_type_to_string (msg_type));
1488 dbus_message_iter_unref (iter);
1490 return DBUS_RESULT_INVALID_ARGS;
1495 case DBUS_TYPE_INT32:
1499 ptr = va_arg (var_args, dbus_int32_t *);
1501 *ptr = dbus_message_iter_get_int32 (iter);
1504 case DBUS_TYPE_UINT32:
1508 ptr = va_arg (var_args, dbus_uint32_t *);
1510 *ptr = dbus_message_iter_get_uint32 (iter);
1514 case DBUS_TYPE_DOUBLE:
1518 ptr = va_arg (var_args, double *);
1520 *ptr = dbus_message_iter_get_double (iter);
1524 case DBUS_TYPE_STRING:
1528 ptr = va_arg (var_args, char **);
1530 *ptr = dbus_message_iter_get_string (iter);
1533 return DBUS_RESULT_NO_MEMORY;
1538 case DBUS_TYPE_INT32_ARRAY:
1543 ptr = va_arg (var_args, dbus_int32_t **);
1544 len = va_arg (var_args, int *);
1546 if (!dbus_message_iter_get_int32_array (iter, ptr, len))
1547 return DBUS_RESULT_NO_MEMORY;
1552 case DBUS_TYPE_UINT32_ARRAY:
1554 dbus_uint32_t **ptr;
1557 ptr = va_arg (var_args, dbus_uint32_t **);
1558 len = va_arg (var_args, int *);
1560 if (!dbus_message_iter_get_uint32_array (iter, ptr, len))
1561 return DBUS_RESULT_NO_MEMORY;
1566 case DBUS_TYPE_DOUBLE_ARRAY:
1571 ptr = va_arg (var_args, double **);
1572 len = va_arg (var_args, int *);
1574 if (!dbus_message_iter_get_double_array (iter, ptr, len))
1575 return DBUS_RESULT_NO_MEMORY;
1580 case DBUS_TYPE_BYTE_ARRAY:
1582 unsigned char **ptr;
1585 ptr = va_arg (var_args, unsigned char **);
1586 len = va_arg (var_args, int *);
1588 if (!dbus_message_iter_get_byte_array (iter, ptr, len))
1589 return DBUS_RESULT_NO_MEMORY;
1593 case DBUS_TYPE_STRING_ARRAY:
1598 ptr = va_arg (var_args, char ***);
1599 len = va_arg (var_args, int *);
1601 if (!dbus_message_iter_get_string_array (iter, ptr, len))
1602 return DBUS_RESULT_NO_MEMORY;
1606 _dbus_warn ("Unknown field type %d\n", spec_type);
1609 spec_type = va_arg (var_args, int);
1610 if (spec_type != 0 && !dbus_message_iter_next (iter))
1612 _dbus_verbose ("More fields than exist in the message were specified or field is corrupt\n");
1614 dbus_message_iter_unref (iter);
1615 return DBUS_RESULT_INVALID_ARGS;
1620 dbus_message_iter_unref (iter);
1621 return DBUS_RESULT_SUCCESS;
1625 * Returns a DBusMessageIter representing the arguments of the
1626 * message passed in.
1628 * @todo IMO the message iter should follow the GtkTextIter pattern,
1629 * a static object with a "stamp" value used to detect invalid
1630 * iter uses (uninitialized or after changing the message).
1631 * ref/unref is kind of annoying to deal with, and slower too.
1632 * This implies not ref'ing the message from the iter.
1634 * @param message the message
1635 * @returns a new iter.
1638 dbus_message_get_args_iter (DBusMessage *message)
1640 DBusMessageIter *iter;
1642 iter = dbus_new (DBusMessageIter, 1);
1644 dbus_message_ref (message);
1647 iter->message = message;
1654 * Increments the reference count of a DBusMessageIter.
1656 * @param iter the message iter
1657 * @see dbus_message_iter_unref
1660 dbus_message_iter_ref (DBusMessageIter *iter)
1662 _dbus_assert (iter->refcount > 0);
1664 iter->refcount += 1;
1668 * Decrements the reference count of a DBusMessageIter.
1670 * @param iter The message iter
1671 * @see dbus_message_iter_ref
1674 dbus_message_iter_unref (DBusMessageIter *iter)
1676 _dbus_assert (iter->refcount > 0);
1678 iter->refcount -= 1;
1680 if (iter->refcount == 0)
1682 dbus_message_unref (iter->message);
1689 * Checks if an iterator has any more fields.
1691 * @param iter the message iter
1692 * @returns #TRUE if there are more fields
1696 dbus_message_iter_has_next (DBusMessageIter *iter)
1700 if (!_dbus_marshal_get_arg_end_pos (&iter->message->body,
1701 iter->message->byte_order,
1702 iter->pos, &end_pos))
1705 if (end_pos >= _dbus_string_get_length (&iter->message->body))
1712 * Moves the iterator to the next field.
1714 * @param iter The message iter
1715 * @returns #TRUE if the iterator was moved to the next field
1718 dbus_message_iter_next (DBusMessageIter *iter)
1722 if (!_dbus_marshal_get_arg_end_pos (&iter->message->body,
1723 iter->message->byte_order,
1724 iter->pos, &end_pos))
1727 if (end_pos >= _dbus_string_get_length (&iter->message->body))
1730 iter->pos = end_pos;
1736 * Returns the argument type of the argument that the
1737 * message iterator points at.
1739 * @param iter the message iter
1740 * @returns the field type
1743 dbus_message_iter_get_arg_type (DBusMessageIter *iter)
1747 if (iter->pos >= _dbus_string_get_length (&iter->message->body))
1748 return DBUS_TYPE_INVALID;
1750 _dbus_string_get_const_data_len (&iter->message->body, &data, iter->pos, 1);
1752 if (*data > DBUS_TYPE_INVALID && *data <= DBUS_TYPE_STRING_ARRAY)
1755 return DBUS_TYPE_INVALID;
1759 * Returns the string value that an iterator may point to.
1760 * Note that you need to check that the iterator points to
1761 * a string value before using this function.
1763 * @see dbus_message_iter_get_field_type
1764 * @param iter the message iter
1765 * @returns the string
1768 dbus_message_iter_get_string (DBusMessageIter *iter)
1770 _dbus_assert (dbus_message_iter_get_arg_type (iter) == DBUS_TYPE_STRING);
1772 return _dbus_demarshal_string (&iter->message->body, iter->message->byte_order,
1773 iter->pos + 1, NULL);
1777 * Returns the 32 bit signed integer value that an iterator may point to.
1778 * Note that you need to check that the iterator points to
1779 * an integer value before using this function.
1781 * @see dbus_message_iter_get_field_type
1782 * @param iter the message iter
1783 * @returns the integer
1786 dbus_message_iter_get_int32 (DBusMessageIter *iter)
1788 return _dbus_demarshal_int32 (&iter->message->body, iter->message->byte_order,
1789 iter->pos + 1, NULL);
1793 * Returns the 32 bit unsigned integer value that an iterator may point to.
1794 * Note that you need to check that the iterator points to
1795 * an unsigned integer value before using this function.
1797 * @see dbus_message_iter_get_field_type
1798 * @param iter the message iter
1799 * @returns the integer
1802 dbus_message_iter_get_uint32 (DBusMessageIter *iter)
1804 return _dbus_demarshal_uint32 (&iter->message->body, iter->message->byte_order,
1805 iter->pos + 1, NULL);
1809 * Returns the double value that an iterator may point to.
1810 * Note that you need to check that the iterator points to
1811 * a string value before using this function.
1813 * @see dbus_message_iter_get_field_type
1814 * @param iter the message iter
1815 * @returns the double
1818 dbus_message_iter_get_double (DBusMessageIter *iter)
1820 return _dbus_demarshal_double (&iter->message->body, iter->message->byte_order,
1821 iter->pos + 1, NULL);
1825 * Returns the 32 bit signed integer array that the iterator may point
1826 * to. Note that you need to check that the iterator points to an
1827 * array of the correct type prior to using this function.
1829 * @param iter the iterator
1830 * @param value return location for the array
1831 * @param len return location for the array length
1832 * @returns #TRUE on success
1835 dbus_message_iter_get_int32_array (DBusMessageIter *iter,
1836 dbus_int32_t **value,
1839 _dbus_assert (dbus_message_iter_get_arg_type (iter) == DBUS_TYPE_INT32_ARRAY);
1841 *value = _dbus_demarshal_int32_array (&iter->message->body, iter->message->byte_order,
1842 iter->pos + 1, NULL, len);
1851 * Returns the 32 bit unsigned integer array that the iterator may point
1852 * to. Note that you need to check that the iterator points to an
1853 * array of the correct type prior to using this function.
1855 * @param iter the iterator
1856 * @param value return location for the array
1857 * @param len return location for the array length
1858 * @returns #TRUE on success
1861 dbus_message_iter_get_uint32_array (DBusMessageIter *iter,
1862 dbus_uint32_t **value,
1865 _dbus_assert (dbus_message_iter_get_arg_type (iter) == DBUS_TYPE_UINT32_ARRAY);
1867 *value = _dbus_demarshal_uint32_array (&iter->message->body, iter->message->byte_order,
1868 iter->pos + 1, NULL, len);
1877 * Returns the double array that the iterator may point to. Note that
1878 * you need to check that the iterator points to an array of the
1879 * correct type prior to using this function.
1881 * @param iter the iterator
1882 * @param value return location for the array
1883 * @param len return location for the array length
1884 * @returns #TRUE on success
1887 dbus_message_iter_get_double_array (DBusMessageIter *iter,
1891 _dbus_assert (dbus_message_iter_get_arg_type (iter) == DBUS_TYPE_DOUBLE_ARRAY);
1893 *value = _dbus_demarshal_double_array (&iter->message->body, iter->message->byte_order,
1894 iter->pos + 1, NULL, len);
1903 * Returns the byte array that the iterator may point to.
1904 * Note that you need to check that the iterator points
1905 * to a byte array prior to using this function.
1907 * @param iter the iterator
1908 * @param len return location for length of byte array
1909 * @returns the byte array
1912 dbus_message_iter_get_byte_array (DBusMessageIter *iter,
1913 unsigned char **value,
1916 _dbus_assert (dbus_message_iter_get_arg_type (iter) == DBUS_TYPE_BYTE_ARRAY);
1918 *value = _dbus_demarshal_byte_array (&iter->message->body, iter->message->byte_order,
1919 iter->pos + 1, NULL, len);
1928 * Returns the string array that the iterator may point to.
1929 * Note that you need to check that the iterator points
1930 * to a byte array prior to using this function.
1932 * @todo this function should probably take "char **" as
1933 * an out param argument, and return boolean or result code.
1935 * @param iter the iterator
1936 * @param len return location for length of byte array
1937 * @returns the byte array
1940 dbus_message_iter_get_string_array (DBusMessageIter *iter,
1944 _dbus_assert (dbus_message_iter_get_arg_type (iter) == DBUS_TYPE_STRING_ARRAY);
1946 *value = _dbus_demarshal_string_array (&iter->message->body, iter->message->byte_order,
1947 iter->pos + 1, NULL, len);
1956 * Sets the message sender.
1958 * @param message the message
1959 * @param sender the sender
1960 * @returns #FALSE if not enough memory
1963 dbus_message_set_sender (DBusMessage *message,
1966 _dbus_assert (!message->locked);
1970 delete_string_field (message, FIELD_SENDER);
1975 return set_string_field (message,
1982 * Sets a flag indicating that the message is an error reply
1983 * message, i.e. an "exception" rather than a normal response.
1985 * @param message the message
1986 * @param is_error_reply #TRUE if this is an error message.
1989 dbus_message_set_is_error (DBusMessage *message,
1990 dbus_bool_t is_error_reply)
1994 _dbus_assert (!message->locked);
1996 _dbus_string_get_data_len (&message->header, &header, 1, 1);
1999 *header |= DBUS_HEADER_FLAG_ERROR;
2001 *header &= ~DBUS_HEADER_FLAG_ERROR;
2005 * Returns #TRUE if the message is an error
2006 * reply to some previous message we sent.
2008 * @param message the message
2009 * @returns #TRUE if the message is an error
2012 dbus_message_get_is_error (DBusMessage *message)
2016 _dbus_string_get_const_data_len (&message->header, &header, 1, 1);
2018 return (*header & DBUS_HEADER_FLAG_ERROR) != 0;
2022 * Gets the service which originated this message,
2023 * or #NULL if unknown or inapplicable.
2025 * @param message the message
2026 * @returns the service name or #NULL
2029 dbus_message_get_sender (DBusMessage *message)
2031 return get_string_field (message, FIELD_SENDER, NULL);
2035 * Checks whether the message has the given name.
2036 * If the message has no name or has a different
2037 * name, returns #FALSE.
2039 * @param message the message
2040 * @param name the name to check (must not be #NULL)
2042 * @returns #TRUE if the message has the given name
2045 dbus_message_name_is (DBusMessage *message,
2050 _dbus_assert (name != NULL);
2052 n = dbus_message_get_name (message);
2054 if (n && strcmp (n, name) == 0)
2063 * @addtogroup DBusMessageInternals
2068 * @typedef DBusMessageLoader
2070 * The DBusMessageLoader object encapsulates the process of converting
2071 * a byte stream into a series of DBusMessage. It buffers the incoming
2072 * bytes as efficiently as possible, and generates a queue of
2073 * messages. DBusMessageLoader is typically used as part of a
2074 * DBusTransport implementation. The DBusTransport then hands off
2075 * the loaded messages to a DBusConnection, making the messages
2076 * visible to the application.
2080 /* we definitely use signed ints for sizes, so don't exceed
2081 * _DBUS_INT_MAX; and add 16 for paranoia, since a message
2082 * over 128M is pretty nuts anyhow.
2086 * The maximum sane message size.
2088 #define MAX_SANE_MESSAGE_SIZE (_DBUS_INT_MAX/16)
2091 * Implementation details of DBusMessageLoader.
2092 * All members are private.
2094 struct DBusMessageLoader
2096 int refcount; /**< Reference count. */
2098 DBusString data; /**< Buffered data */
2100 DBusList *messages; /**< Complete messages. */
2102 long max_message_size; /**< Maximum size of a message */
2104 unsigned int buffer_outstanding : 1; /**< Someone is using the buffer to read */
2106 unsigned int corrupted : 1; /**< We got broken data, and are no longer working */
2110 * The initial buffer size of the message loader.
2112 * @todo this should be based on min header size plus some average
2113 * body size, or something. Or rather, the min header size only, if we
2114 * want to try to read only the header, store that in a DBusMessage,
2115 * then read only the body and store that, etc., depends on
2116 * how we optimize _dbus_message_loader_get_buffer() and what
2117 * the exact message format is.
2119 #define INITIAL_LOADER_DATA_LEN 32
2122 * Creates a new message loader. Returns #NULL if memory can't
2125 * @returns new loader, or #NULL.
2128 _dbus_message_loader_new (void)
2130 DBusMessageLoader *loader;
2132 loader = dbus_new0 (DBusMessageLoader, 1);
2136 loader->refcount = 1;
2138 /* Try to cap message size at something that won't *totally* hose
2139 * the system if we have a couple of them.
2141 loader->max_message_size = _DBUS_ONE_MEGABYTE * 32;
2143 if (!_dbus_string_init (&loader->data, _DBUS_INT_MAX))
2149 /* preallocate the buffer for speed, ignore failure */
2150 _dbus_string_set_length (&loader->data, INITIAL_LOADER_DATA_LEN);
2151 _dbus_string_set_length (&loader->data, 0);
2157 * Increments the reference count of the loader.
2159 * @param loader the loader.
2162 _dbus_message_loader_ref (DBusMessageLoader *loader)
2164 loader->refcount += 1;
2168 * Decrements the reference count of the loader and finalizes the
2169 * loader when the count reaches zero.
2171 * @param loader the loader.
2174 _dbus_message_loader_unref (DBusMessageLoader *loader)
2176 loader->refcount -= 1;
2177 if (loader->refcount == 0)
2179 _dbus_list_foreach (&loader->messages,
2180 (DBusForeachFunction) dbus_message_unref,
2182 _dbus_list_clear (&loader->messages);
2183 _dbus_string_free (&loader->data);
2189 * Gets the buffer to use for reading data from the network. Network
2190 * data is read directly into an allocated buffer, which is then used
2191 * in the DBusMessage, to avoid as many extra memcpy's as possible.
2192 * The buffer must always be returned immediately using
2193 * _dbus_message_loader_return_buffer(), even if no bytes are
2194 * successfully read.
2196 * @todo this function can be a lot more clever. For example
2197 * it can probably always return a buffer size to read exactly
2198 * the body of the next message, thus avoiding any memory wastage
2201 * @param loader the message loader.
2202 * @param buffer the buffer
2205 _dbus_message_loader_get_buffer (DBusMessageLoader *loader,
2206 DBusString **buffer)
2208 _dbus_assert (!loader->buffer_outstanding);
2210 *buffer = &loader->data;
2212 loader->buffer_outstanding = TRUE;
2216 * The smallest header size that can occur.
2217 * (It won't be valid)
2219 #define DBUS_MINIMUM_HEADER_SIZE 16
2221 /** Pack four characters as in "abcd" into a uint32 */
2222 #define FOUR_CHARS_TO_UINT32(a, b, c, d) \
2223 ((((dbus_uint32_t)a) << 24) | \
2224 (((dbus_uint32_t)b) << 16) | \
2225 (((dbus_uint32_t)c) << 8) | \
2228 /** DBUS_HEADER_FIELD_NAME packed into a dbus_uint32_t */
2229 #define DBUS_HEADER_FIELD_NAME_AS_UINT32 \
2230 FOUR_CHARS_TO_UINT32 ('n', 'a', 'm', 'e')
2232 /** DBUS_HEADER_FIELD_SERVICE packed into a dbus_uint32_t */
2233 #define DBUS_HEADER_FIELD_SERVICE_AS_UINT32 \
2234 FOUR_CHARS_TO_UINT32 ('s', 'r', 'v', 'c')
2236 /** DBUS_HEADER_FIELD_REPLY packed into a dbus_uint32_t */
2237 #define DBUS_HEADER_FIELD_REPLY_AS_UINT32 \
2238 FOUR_CHARS_TO_UINT32 ('r', 'p', 'l', 'y')
2240 /** DBUS_HEADER_FIELD_SENDER Packed into a dbus_uint32_t */
2241 #define DBUS_HEADER_FIELD_SENDER_AS_UINT32 \
2242 FOUR_CHARS_TO_UINT32 ('s', 'n', 'd', 'r')
2245 decode_header_data (const DBusString *data,
2248 HeaderField fields[FIELD_LAST],
2249 int *message_padding)
2255 if (header_len < 16)
2259 while (i < FIELD_LAST)
2261 fields[i].offset = -1;
2265 fields[FIELD_HEADER_LENGTH].offset = 4;
2266 fields[FIELD_BODY_LENGTH].offset = 8;
2267 fields[FIELD_CLIENT_SERIAL].offset = 12;
2269 /* Now handle the named fields. A real named field is at least 4
2270 * bytes for the name, plus a type code (1 byte) plus padding. So
2271 * if we have less than 8 bytes left, it must be alignment padding,
2272 * not a field. While >= 8 bytes can't be entirely alignment
2276 while ((pos + 7) < header_len)
2278 pos = _DBUS_ALIGN_VALUE (pos, 4);
2280 if ((pos + 4) > header_len)
2283 _dbus_string_get_const_data_len (data, &field, pos, 4);
2286 _dbus_assert (_DBUS_ALIGN_ADDRESS (field, 4) == field);
2288 /* I believe FROM_BE is right, but if not we'll find out
2291 switch (DBUS_UINT32_FROM_BE (*(int*)field))
2293 case DBUS_HEADER_FIELD_SERVICE_AS_UINT32:
2294 if (fields[FIELD_SERVICE].offset >= 0)
2296 _dbus_verbose ("%s field provided twice\n",
2297 DBUS_HEADER_FIELD_SERVICE);
2301 fields[FIELD_SERVICE].offset = _DBUS_ALIGN_VALUE (pos + 1, 4);
2302 _dbus_verbose ("Found service name at offset %d\n",
2303 fields[FIELD_SERVICE].offset);
2306 case DBUS_HEADER_FIELD_NAME_AS_UINT32:
2307 if (fields[FIELD_NAME].offset >= 0)
2309 _dbus_verbose ("%s field provided twice\n",
2310 DBUS_HEADER_FIELD_NAME);
2314 fields[FIELD_NAME].offset = _DBUS_ALIGN_VALUE (pos + 1, 4);
2316 _dbus_verbose ("Found message name at offset %d\n",
2317 fields[FIELD_NAME].offset);
2319 case DBUS_HEADER_FIELD_SENDER_AS_UINT32:
2320 if (fields[FIELD_SENDER].offset >= 0)
2322 _dbus_verbose ("%s field provided twice\n",
2323 DBUS_HEADER_FIELD_SENDER);
2327 fields[FIELD_SENDER].offset = _DBUS_ALIGN_VALUE (pos + 1, 4);
2329 _dbus_verbose ("Found sender name at offset %d\n",
2330 fields[FIELD_NAME].offset);
2333 case DBUS_HEADER_FIELD_REPLY_AS_UINT32:
2334 if (fields[FIELD_REPLY_SERIAL].offset >= 0)
2336 _dbus_verbose ("%s field provided twice\n",
2337 DBUS_HEADER_FIELD_REPLY);
2341 fields[FIELD_REPLY_SERIAL].offset = _DBUS_ALIGN_VALUE (pos + 1, 4);
2343 _dbus_verbose ("Found reply serial at offset %d\n",
2344 fields[FIELD_REPLY_SERIAL].offset);
2348 _dbus_verbose ("Ignoring an unknown header field: %c%c%c%c at offset %d\n",
2349 field[0], field[1], field[2], field[3], pos);
2352 if (!_dbus_marshal_validate_arg (data, byte_order, pos, &new_pos))
2354 _dbus_verbose ("Failed to validate argument to named header field\n");
2358 if (new_pos > header_len)
2360 _dbus_verbose ("Named header field tries to extend beyond header length\n");
2367 if (pos < header_len)
2369 /* Alignment padding, verify that it's nul */
2370 _dbus_assert ((header_len - pos) < 8);
2372 if (!_dbus_string_validate_nul (data,
2373 pos, (header_len - pos)))
2375 _dbus_verbose ("header alignment padding is not nul\n");
2379 if (message_padding)
2380 *message_padding = header_len - pos;
2387 * Returns a buffer obtained from _dbus_message_loader_get_buffer(),
2388 * indicating to the loader how many bytes of the buffer were filled
2389 * in. This function must always be called, even if no bytes were
2390 * successfully read.
2392 * @todo if we run out of memory in here, we offer no way for calling
2393 * code to handle it, i.e. they can't re-run the message parsing
2394 * attempt. Perhaps much of this code could be moved to pop_message()?
2395 * But then that may need to distinguish NULL return for no messages
2396 * from NULL return for errors.
2398 * @param loader the loader.
2399 * @param buffer the buffer.
2400 * @param bytes_read number of bytes that were read into the buffer.
2403 _dbus_message_loader_return_buffer (DBusMessageLoader *loader,
2407 _dbus_assert (loader->buffer_outstanding);
2408 _dbus_assert (buffer == &loader->data);
2410 loader->buffer_outstanding = FALSE;
2412 if (loader->corrupted)
2415 while (_dbus_string_get_length (&loader->data) >= 16)
2417 DBusMessage *message;
2418 const char *header_data;
2419 int byte_order, header_len, body_len, header_padding;
2420 dbus_uint32_t header_len_unsigned, body_len_unsigned;
2422 _dbus_string_get_const_data_len (&loader->data, &header_data, 0, 16);
2424 _dbus_assert (_DBUS_ALIGN_ADDRESS (header_data, 4) == header_data);
2426 if (header_data[2] != DBUS_MAJOR_PROTOCOL_VERSION)
2428 _dbus_verbose ("Message has protocol version %d ours is %d\n",
2429 (int) header_data[2], DBUS_MAJOR_PROTOCOL_VERSION);
2430 loader->corrupted = TRUE;
2434 byte_order = header_data[0];
2436 if (byte_order != DBUS_LITTLE_ENDIAN &&
2437 byte_order != DBUS_BIG_ENDIAN)
2439 _dbus_verbose ("Message with bad byte order '%c' received\n",
2441 loader->corrupted = TRUE;
2445 header_len_unsigned = _dbus_unpack_uint32 (byte_order, header_data + 4);
2446 body_len_unsigned = _dbus_unpack_uint32 (byte_order, header_data + 8);
2448 if (header_len_unsigned < 16)
2450 _dbus_verbose ("Message had broken too-small header length %u\n",
2451 header_len_unsigned);
2452 loader->corrupted = TRUE;
2456 if (header_len_unsigned > (unsigned) MAX_SANE_MESSAGE_SIZE ||
2457 body_len_unsigned > (unsigned) MAX_SANE_MESSAGE_SIZE)
2459 _dbus_verbose ("Header or body length too large (%u %u)\n",
2460 header_len_unsigned,
2462 loader->corrupted = TRUE;
2466 /* Now that we know the values are in signed range, get
2467 * rid of stupid unsigned, just causes bugs
2469 header_len = header_len_unsigned;
2470 body_len = body_len_unsigned;
2472 if (_DBUS_ALIGN_VALUE (header_len, 8) != header_len_unsigned)
2474 _dbus_verbose ("header length %d is not aligned to 8 bytes\n",
2476 loader->corrupted = TRUE;
2480 if (header_len + body_len > loader->max_message_size)
2482 _dbus_verbose ("Message claimed length header = %d body = %d exceeds max message length %d\n",
2483 header_len, body_len, loader->max_message_size);
2484 loader->corrupted = TRUE;
2488 if (_dbus_string_get_length (&loader->data) >= (header_len + body_len))
2490 HeaderField fields[FIELD_LAST];
2494 _dbus_verbose_bytes_of_string (&loader->data, 0, header_len);
2495 if (!decode_header_data (&loader->data, header_len, byte_order,
2496 fields, &header_padding))
2498 _dbus_verbose ("Header was invalid\n");
2499 loader->corrupted = TRUE;
2503 next_arg = header_len;
2504 while (next_arg < (header_len + body_len))
2506 int prev = next_arg;
2508 if (!_dbus_marshal_validate_arg (&loader->data,
2513 loader->corrupted = TRUE;
2517 _dbus_assert (next_arg > prev);
2520 if (next_arg > (header_len + body_len))
2522 _dbus_verbose ("end of last arg at %d but message has len %d+%d=%d\n",
2523 next_arg, header_len, body_len,
2524 header_len + body_len);
2525 loader->corrupted = TRUE;
2529 message = dbus_message_new_empty_header ();
2530 if (message == NULL)
2531 break; /* ugh, postpone this I guess. */
2533 message->byte_order = byte_order;
2534 message->header_padding = header_padding;
2536 /* Copy in the offsets we found */
2538 while (i < FIELD_LAST)
2540 message->header_fields[i] = fields[i];
2544 if (!_dbus_list_append (&loader->messages, message))
2546 dbus_message_unref (message);
2550 _dbus_assert (_dbus_string_get_length (&message->header) == 0);
2551 _dbus_assert (_dbus_string_get_length (&message->body) == 0);
2553 _dbus_assert (_dbus_string_get_length (&loader->data) >=
2554 (header_len + body_len));
2556 if (!_dbus_string_move_len (&loader->data, 0, header_len, &message->header, 0))
2558 _dbus_list_remove_last (&loader->messages, message);
2559 dbus_message_unref (message);
2563 if (!_dbus_string_move_len (&loader->data, 0, body_len, &message->body, 0))
2567 /* put the header back, we'll try again later */
2568 result = _dbus_string_copy_len (&message->header, 0, header_len,
2570 _dbus_assert (result); /* because DBusString never reallocs smaller */
2572 _dbus_list_remove_last (&loader->messages, message);
2573 dbus_message_unref (message);
2577 _dbus_assert (_dbus_string_get_length (&message->header) == header_len);
2578 _dbus_assert (_dbus_string_get_length (&message->body) == body_len);
2580 _dbus_verbose ("Loaded message %p\n", message);
2588 * Pops a loaded message (passing ownership of the message
2589 * to the caller). Returns #NULL if no messages have been
2592 * @param loader the loader.
2593 * @returns the next message, or #NULL if none.
2596 _dbus_message_loader_pop_message (DBusMessageLoader *loader)
2598 return _dbus_list_pop_first (&loader->messages);
2603 * Checks whether the loader is confused due to bad data.
2604 * If messages are received that are invalid, the
2605 * loader gets confused and gives up permanently.
2606 * This state is called "corrupted."
2608 * @param loader the loader
2609 * @returns #TRUE if the loader is hosed.
2612 _dbus_message_loader_get_is_corrupted (DBusMessageLoader *loader)
2614 return loader->corrupted;
2618 * Sets the maximum size message we allow.
2620 * @param loader the loader
2621 * @param size the max message size in bytes
2624 _dbus_message_loader_set_max_message_size (DBusMessageLoader *loader,
2627 if (size > MAX_SANE_MESSAGE_SIZE)
2629 _dbus_verbose ("clamping requested max message size %ld to %d\n",
2630 size, MAX_SANE_MESSAGE_SIZE);
2631 size = MAX_SANE_MESSAGE_SIZE;
2633 loader->max_message_size = size;
2637 * Gets the maximum allowed message size in bytes.
2639 * @param loader the loader
2640 * @returns max size in bytes
2643 _dbus_message_loader_get_max_message_size (DBusMessageLoader *loader)
2645 return loader->max_message_size;
2649 #ifdef DBUS_BUILD_TESTS
2650 #include "dbus-test.h"
2654 message_iter_test (DBusMessage *message)
2656 DBusMessageIter *iter;
2659 iter = dbus_message_get_args_iter (message);
2662 if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_STRING)
2663 _dbus_assert_not_reached ("Argument type isn't string");
2665 str = dbus_message_iter_get_string (iter);
2666 if (strcmp (str, "Test string") != 0)
2667 _dbus_assert_not_reached ("Strings differ");
2670 if (!dbus_message_iter_next (iter))
2671 _dbus_assert_not_reached ("Reached end of arguments");
2673 /* Signed integer tests */
2674 if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_INT32)
2675 _dbus_assert_not_reached ("Argument type isn't int32");
2677 if (dbus_message_iter_get_int32 (iter) != -0x12345678)
2678 _dbus_assert_not_reached ("Signed integers differ");
2680 if (!dbus_message_iter_next (iter))
2681 _dbus_assert_not_reached ("Reached end of fields");
2683 /* Unsigned integer tests */
2684 if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_UINT32)
2685 _dbus_assert_not_reached ("Argument type isn't int32");
2687 if (dbus_message_iter_get_int32 (iter) != 0xedd1e)
2688 _dbus_assert_not_reached ("Unsigned integers differ");
2690 if (!dbus_message_iter_next (iter))
2691 _dbus_assert_not_reached ("Reached end of arguments");
2694 if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_DOUBLE)
2695 _dbus_assert_not_reached ("Argument type isn't double");
2697 if (dbus_message_iter_get_double (iter) != 3.14159)
2698 _dbus_assert_not_reached ("Doubles differ");
2700 if (dbus_message_iter_next (iter))
2701 _dbus_assert_not_reached ("Didn't reach end of arguments");
2703 dbus_message_iter_unref (iter);
2707 check_message_handling (DBusMessage *message)
2709 DBusMessageIter *iter;
2712 dbus_int32_t client_serial;
2717 client_serial = _dbus_message_get_client_serial (message);
2719 /* can't use set_client_serial due to the assertions at the start of it */
2720 set_int_field (message, FIELD_CLIENT_SERIAL,
2723 if (client_serial != _dbus_message_get_client_serial (message))
2725 _dbus_warn ("get/set cycle for client_serial did not succeed\n");
2729 /* If we implement message_set_arg (message, n, value)
2730 * then we would want to test it here
2733 iter = dbus_message_get_args_iter (message);
2734 while ((type = dbus_message_iter_get_arg_type (iter)) != DBUS_TYPE_INVALID)
2738 case DBUS_TYPE_STRING:
2741 str = dbus_message_iter_get_string (iter);
2747 if (!dbus_message_iter_next (iter))
2755 dbus_message_iter_unref (iter);
2761 check_have_valid_message (DBusMessageLoader *loader)
2763 DBusMessage *message;
2769 if (_dbus_message_loader_get_is_corrupted (loader))
2771 _dbus_warn ("loader corrupted on message that was expected to be valid\n");
2775 message = _dbus_message_loader_pop_message (loader);
2776 if (message == NULL)
2778 _dbus_warn ("didn't load message that was expected to be valid (message not popped)\n");
2782 if (_dbus_string_get_length (&loader->data) > 0)
2784 _dbus_warn ("had leftover bytes from expected-to-be-valid single message\n");
2788 /* Verify that we're able to properly deal with the message.
2789 * For example, this would detect improper handling of messages
2790 * in nonstandard byte order.
2792 if (!check_message_handling (message))
2799 dbus_message_unref (message);
2804 check_invalid_message (DBusMessageLoader *loader)
2810 if (!_dbus_message_loader_get_is_corrupted (loader))
2812 _dbus_warn ("loader not corrupted on message that was expected to be invalid\n");
2823 check_incomplete_message (DBusMessageLoader *loader)
2825 DBusMessage *message;
2831 if (_dbus_message_loader_get_is_corrupted (loader))
2833 _dbus_warn ("loader corrupted on message that was expected to be valid (but incomplete)\n");
2837 message = _dbus_message_loader_pop_message (loader);
2838 if (message != NULL)
2840 _dbus_warn ("loaded message that was expected to be incomplete\n");
2848 dbus_message_unref (message);
2853 check_loader_results (DBusMessageLoader *loader,
2854 DBusMessageValidity validity)
2858 case _DBUS_MESSAGE_VALID:
2859 return check_have_valid_message (loader);
2860 case _DBUS_MESSAGE_INVALID:
2861 return check_invalid_message (loader);
2862 case _DBUS_MESSAGE_INCOMPLETE:
2863 return check_incomplete_message (loader);
2864 case _DBUS_MESSAGE_UNKNOWN:
2868 _dbus_assert_not_reached ("bad DBusMessageValidity");
2874 * Loads the message in the given message file.
2876 * @param filename filename to load
2877 * @param is_raw if #TRUE load as binary data, if #FALSE as message builder language
2878 * @param data string to load message into
2879 * @returns #TRUE if the message was loaded
2882 dbus_internal_do_not_use_load_message_file (const DBusString *filename,
2892 DBusResultCode result;
2894 result = _dbus_file_get_contents (data, filename);
2895 if (result != DBUS_RESULT_SUCCESS)
2898 _dbus_string_get_const_data (filename, &s);
2899 _dbus_warn ("Could not load message file %s\n", s);
2905 if (!_dbus_message_data_load (data, filename))
2908 _dbus_string_get_const_data (filename, &s);
2909 _dbus_warn ("Could not load message file %s\n", s);
2922 * Tries loading the message in the given message file
2923 * and verifies that DBusMessageLoader can handle it.
2925 * @param filename filename to load
2926 * @param is_raw if #TRUE load as binary data, if #FALSE as message builder language
2927 * @param expected_validity what the message has to be like to return #TRUE
2928 * @returns #TRUE if the message has the expected validity
2931 dbus_internal_do_not_use_try_message_file (const DBusString *filename,
2933 DBusMessageValidity expected_validity)
2940 if (!_dbus_string_init (&data, _DBUS_INT_MAX))
2941 _dbus_assert_not_reached ("could not allocate string\n");
2943 if (!dbus_internal_do_not_use_load_message_file (filename, is_raw,
2947 retval = dbus_internal_do_not_use_try_message_data (&data, expected_validity);
2955 if (_dbus_string_get_length (&data) > 0)
2956 _dbus_verbose_bytes_of_string (&data, 0,
2957 _dbus_string_get_length (&data));
2959 _dbus_string_get_const_data (filename, &s);
2960 _dbus_warn ("Failed message loader test on %s\n",
2964 _dbus_string_free (&data);
2970 * Tries loading the given message data.
2973 * @param data the message data
2974 * @param expected_validity what the message has to be like to return #TRUE
2975 * @returns #TRUE if the message has the expected validity
2978 dbus_internal_do_not_use_try_message_data (const DBusString *data,
2979 DBusMessageValidity expected_validity)
2981 DBusMessageLoader *loader;
2989 /* Write the data one byte at a time */
2991 loader = _dbus_message_loader_new ();
2993 len = _dbus_string_get_length (data);
2994 for (i = 0; i < len; i++)
2998 _dbus_message_loader_get_buffer (loader, &buffer);
2999 _dbus_string_append_byte (buffer,
3000 _dbus_string_get_byte (data, i));
3001 _dbus_message_loader_return_buffer (loader, buffer, 1);
3004 if (!check_loader_results (loader, expected_validity))
3007 _dbus_message_loader_unref (loader);
3010 /* Write the data all at once */
3012 loader = _dbus_message_loader_new ();
3017 _dbus_message_loader_get_buffer (loader, &buffer);
3018 _dbus_string_copy (data, 0, buffer,
3019 _dbus_string_get_length (buffer));
3020 _dbus_message_loader_return_buffer (loader, buffer, 1);
3023 if (!check_loader_results (loader, expected_validity))
3026 _dbus_message_loader_unref (loader);
3029 /* Write the data 2 bytes at a time */
3031 loader = _dbus_message_loader_new ();
3033 len = _dbus_string_get_length (data);
3034 for (i = 0; i < len; i += 2)
3038 _dbus_message_loader_get_buffer (loader, &buffer);
3039 _dbus_string_append_byte (buffer,
3040 _dbus_string_get_byte (data, i));
3042 _dbus_string_append_byte (buffer,
3043 _dbus_string_get_byte (data, i+1));
3044 _dbus_message_loader_return_buffer (loader, buffer, 1);
3047 if (!check_loader_results (loader, expected_validity))
3050 _dbus_message_loader_unref (loader);
3058 _dbus_message_loader_unref (loader);
3064 process_test_subdir (const DBusString *test_base_dir,
3066 DBusMessageValidity validity,
3067 DBusForeachMessageFileFunc function,
3070 DBusString test_directory;
3071 DBusString filename;
3074 DBusResultCode result;
3079 if (!_dbus_string_init (&test_directory, _DBUS_INT_MAX))
3080 _dbus_assert_not_reached ("didn't allocate test_directory\n");
3082 _dbus_string_init_const (&filename, subdir);
3084 if (!_dbus_string_copy (test_base_dir, 0,
3085 &test_directory, 0))
3086 _dbus_assert_not_reached ("couldn't copy test_base_dir to test_directory");
3088 if (!_dbus_concat_dir_and_file (&test_directory, &filename))
3089 _dbus_assert_not_reached ("couldn't allocate full path");
3091 _dbus_string_free (&filename);
3092 if (!_dbus_string_init (&filename, _DBUS_INT_MAX))
3093 _dbus_assert_not_reached ("didn't allocate filename string\n");
3095 dir = _dbus_directory_open (&test_directory, &result);
3099 _dbus_string_get_const_data (&test_directory, &s);
3100 _dbus_warn ("Could not open %s: %s\n", s,
3101 dbus_result_to_string (result));
3105 printf ("Testing:\n");
3107 result = DBUS_RESULT_SUCCESS;
3109 while (_dbus_directory_get_next_file (dir, &filename, &result))
3111 DBusString full_path;
3114 if (!_dbus_string_init (&full_path, _DBUS_INT_MAX))
3115 _dbus_assert_not_reached ("couldn't init string");
3117 if (!_dbus_string_copy (&test_directory, 0, &full_path, 0))
3118 _dbus_assert_not_reached ("couldn't copy dir to full_path");
3120 if (!_dbus_concat_dir_and_file (&full_path, &filename))
3121 _dbus_assert_not_reached ("couldn't concat file to dir");
3123 if (_dbus_string_ends_with_c_str (&filename, ".message"))
3125 else if (_dbus_string_ends_with_c_str (&filename, ".message-raw"))
3129 const char *filename_c;
3130 _dbus_string_get_const_data (&filename, &filename_c);
3131 _dbus_verbose ("Skipping non-.message file %s\n",
3133 _dbus_string_free (&full_path);
3139 _dbus_string_get_const_data (&filename, &s);
3140 printf (" %s\n", s);
3143 _dbus_verbose (" expecting %s\n",
3144 validity == _DBUS_MESSAGE_VALID ? "valid" :
3145 (validity == _DBUS_MESSAGE_INVALID ? "invalid" :
3146 (validity == _DBUS_MESSAGE_INCOMPLETE ? "incomplete" : "unknown")));
3148 if (! (*function) (&full_path, is_raw, validity, user_data))
3150 _dbus_string_free (&full_path);
3154 _dbus_string_free (&full_path);
3157 if (result != DBUS_RESULT_SUCCESS)
3160 _dbus_string_get_const_data (&test_directory, &s);
3161 _dbus_warn ("Could not get next file in %s: %s\n",
3162 s, dbus_result_to_string (result));
3171 _dbus_directory_close (dir);
3172 _dbus_string_free (&test_directory);
3173 _dbus_string_free (&filename);
3179 * Runs the given function on every message file in the test suite.
3180 * The function should return #FALSE on test failure or fatal error.
3182 * @param test_data_dir root dir of the test suite data files (top_srcdir/test/data)
3183 * @param func the function to run
3184 * @param user_data data for function
3185 * @returns #FALSE if there's a failure
3188 dbus_internal_do_not_use_foreach_message_file (const char *test_data_dir,
3189 DBusForeachMessageFileFunc func,
3192 DBusString test_directory;
3197 _dbus_string_init_const (&test_directory, test_data_dir);
3199 if (!process_test_subdir (&test_directory, "valid-messages",
3200 _DBUS_MESSAGE_VALID, func, user_data))
3203 if (!process_test_subdir (&test_directory, "invalid-messages",
3204 _DBUS_MESSAGE_INVALID, func, user_data))
3207 if (!process_test_subdir (&test_directory, "incomplete-messages",
3208 _DBUS_MESSAGE_INCOMPLETE, func, user_data))
3215 _dbus_string_free (&test_directory);
3221 * @ingroup DBusMessageInternals
3222 * Unit test for DBusMessage.
3224 * @returns #TRUE on success.
3227 _dbus_message_test (const char *test_data_dir)
3229 DBusMessage *message;
3230 DBusMessageLoader *loader;
3233 dbus_int32_t our_int;
3237 /* Test the vararg functions */
3238 message = dbus_message_new ("org.freedesktop.DBus.Test", "testMessage");
3239 _dbus_message_set_client_serial (message, 1);
3240 dbus_message_append_args (message,
3241 DBUS_TYPE_INT32, -0x12345678,
3242 DBUS_TYPE_STRING, "Test string",
3243 DBUS_TYPE_DOUBLE, 3.14159,
3245 _dbus_verbose_bytes_of_string (&message->header, 0,
3246 _dbus_string_get_length (&message->header));
3247 _dbus_verbose_bytes_of_string (&message->body, 0,
3248 _dbus_string_get_length (&message->body));
3250 if (dbus_message_get_args (message,
3251 DBUS_TYPE_INT32, &our_int,
3252 DBUS_TYPE_STRING, &our_str,
3253 DBUS_TYPE_DOUBLE, &our_double,
3254 0) != DBUS_RESULT_SUCCESS)
3255 _dbus_assert_not_reached ("Could not get arguments");
3257 if (our_int != -0x12345678)
3258 _dbus_assert_not_reached ("integers differ!");
3260 if (our_double != 3.14159)
3261 _dbus_assert_not_reached ("doubles differ!");
3263 if (strcmp (our_str, "Test string") != 0)
3264 _dbus_assert_not_reached ("strings differ!");
3266 dbus_free (our_str);
3267 dbus_message_unref (message);
3269 message = dbus_message_new ("org.freedesktop.DBus.Test", "testMessage");
3270 _dbus_message_set_client_serial (message, 1);
3271 _dbus_message_set_reply_serial (message, 0x12345678);
3273 dbus_message_append_string (message, "Test string");
3274 dbus_message_append_int32 (message, -0x12345678);
3275 dbus_message_append_uint32 (message, 0xedd1e);
3276 dbus_message_append_double (message, 3.14159);
3278 message_iter_test (message);
3280 /* Message loader test */
3281 _dbus_message_lock (message);
3282 loader = _dbus_message_loader_new ();
3284 /* Write the header data one byte at a time */
3285 _dbus_string_get_const_data (&message->header, &data);
3286 for (i = 0; i < _dbus_string_get_length (&message->header); i++)
3290 _dbus_message_loader_get_buffer (loader, &buffer);
3291 _dbus_string_append_byte (buffer, data[i]);
3292 _dbus_message_loader_return_buffer (loader, buffer, 1);
3295 /* Write the body data one byte at a time */
3296 _dbus_string_get_const_data (&message->body, &data);
3297 for (i = 0; i < _dbus_string_get_length (&message->body); i++)
3301 _dbus_message_loader_get_buffer (loader, &buffer);
3302 _dbus_string_append_byte (buffer, data[i]);
3303 _dbus_message_loader_return_buffer (loader, buffer, 1);
3306 dbus_message_unref (message);
3308 /* Now pop back the message */
3309 if (_dbus_message_loader_get_is_corrupted (loader))
3310 _dbus_assert_not_reached ("message loader corrupted");
3312 message = _dbus_message_loader_pop_message (loader);
3314 _dbus_assert_not_reached ("received a NULL message");
3316 if (_dbus_message_get_reply_serial (message) != 0x12345678)
3317 _dbus_assert_not_reached ("reply serial fields differ");
3319 message_iter_test (message);
3321 dbus_message_unref (message);
3322 _dbus_message_loader_unref (loader);
3324 /* Now load every message in test_data_dir if we have one */
3325 if (test_data_dir == NULL)
3328 return dbus_internal_do_not_use_foreach_message_file (test_data_dir,
3329 (DBusForeachMessageFileFunc)
3330 dbus_internal_do_not_use_try_message_file,
3334 #endif /* DBUS_BUILD_TESTS */