D-Bus: marshaling and unmarshaling

D-Bus 1.14.10

Data Structures | Macros | Enumerations | Functions
marshaling and unmarshaling
D-Bus secret internal implementation details

functions to marshal/unmarshal data from the wire More...

## Data Structures
struct | HeaderFieldType
struct | DBusTypeReaderClass
| Virtual table for a type reader. More...
struct | ReplacementBlock

## Macros
#define | FIELDS_ARRAY_SIGNATURE_OFFSET 6
| Offset from start of _dbus_header_signature_str to the signature of the fields array.
#define | FIELDS_ARRAY_ELEMENT_SIGNATURE_OFFSET 7
| Offset from start of _dbus_header_signature_str to the signature of an element of the fields array.
#define | BYTE_ORDER_OFFSET 0
| Offset to byte order from start of header.
#define | TYPE_OFFSET 1
| Offset to type from start of header.
#define | FLAGS_OFFSET 2
| Offset to flags from start of header.
#define | VERSION_OFFSET 3
| Offset to version from start of header.
#define | BODY_LENGTH_OFFSET 4
| Offset to body length from start of header.
#define | SERIAL_OFFSET 8
| Offset to client serial from start of header.
#define | FIELDS_ARRAY_LENGTH_OFFSET 12
| Offset to fields array length from start of header.
#define | FIRST_FIELD_OFFSET 16
| Offset to first field in header.
#define | EXPECTED_TYPE_OF_FIELD(field) (_dbus_header_field_types[field].type)
| Macro to look up the correct type for a field.
#define | MAX_POSSIBLE_HEADER_PADDING 7
| The most padding we could ever need for a header.
#define | HEADER_END_BEFORE_PADDING(header) (_dbus_string_get_length (&(header)->data) - (header)->padding)
| Compute the end of the header, ignoring padding.
#define | RECURSIVE_MARSHAL_READ_TRACE 0
| turn this on to get deluged in TypeReader verbose spam
#define | RECURSIVE_MARSHAL_WRITE_TRACE 0
| turn this on to get deluged in TypeWriter verbose spam
#define | ARRAY_READER_LEN_POS(reader) ((reader)->u.array.start_pos - ((int)(reader)->array_len_offset) - 4)
| compute position of array length given array_len_offset, which is the offset back from start_pos to end of the len
#define | VALID_INITIAL_NAME_CHARACTER(c)
| Determine wether the given character is valid as the first character in a name.
#define | VALID_NAME_CHARACTER(c)
| Determine wether the given character is valid as a second or later character in a name.
#define | VALID_INITIAL_BUS_NAME_CHARACTER(c)
| Determine wether the given character is valid as the first character in a bus name.
#define | VALID_BUS_NAME_CHARACTER(c)
| Determine wether the given character is valid as a second or later character in a bus name.
#define | _dbus_validate_utf8(s, b, e) _dbus_string_validate_utf8 (s, b, e)
#define | DECLARE_DBUS_NAME_CHECK(what) dbus_bool_t _dbus_check_is_valid_##what (const char *name)
| A name check is used in _dbus_return_if_fail(), it's not suitable for validating untrusted data.
#define | DEFINE_DBUS_NAME_CHECK(what)
| Define a name check to be used in _dbus_return_if_fail() statements.

## Enumerations
enum | { MARSHAL_AS_STRING , MARSHAL_AS_SIGNATURE , MARSHAL_AS_BYTE_ARRAY }
enum | DBusValidationMode { DBUS_VALIDATION_MODE_WE_TRUST_THIS_DATA_ABSOLUTELY , DBUS_VALIDATION_MODE_DATA_IS_UNTRUSTED }
| This is used rather than a bool for high visibility. More...
enum | DBusValidity { DBUS_VALIDITY_UNKNOWN_OOM_ERROR = -4 , DBUS_INVALID_FOR_UNKNOWN_REASON = -3 , DBUS_VALID_BUT_INCOMPLETE = -2 , DBUS_VALIDITY_UNKNOWN = -1 , DBUS_VALID = 0 , DBUS_INVALID_UNKNOWN_TYPECODE = 1 , DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE = 2 , DBUS_INVALID_SIGNATURE_TOO_LONG = 3 , DBUS_INVALID_EXCEEDED_MAXIMUM_ARRAY_RECURSION = 4 , DBUS_INVALID_EXCEEDED_MAXIMUM_STRUCT_RECURSION = 5 , DBUS_INVALID_STRUCT_ENDED_BUT_NOT_STARTED = 6 , DBUS_INVALID_STRUCT_STARTED_BUT_NOT_ENDED = 7 , DBUS_INVALID_STRUCT_HAS_NO_FIELDS = 8 , DBUS_INVALID_ALIGNMENT_PADDING_NOT_NUL = 9 , DBUS_INVALID_BOOLEAN_NOT_ZERO_OR_ONE = 10 , DBUS_INVALID_NOT_ENOUGH_DATA = 11 , DBUS_INVALID_TOO_MUCH_DATA = 12 , DBUS_INVALID_BAD_BYTE_ORDER = 13 , DBUS_INVALID_BAD_PROTOCOL_VERSION = 14 , DBUS_INVALID_BAD_MESSAGE_TYPE = 15 , DBUS_INVALID_BAD_SERIAL = 16 , DBUS_INVALID_INSANE_FIELDS_ARRAY_LENGTH = 17 , DBUS_INVALID_INSANE_BODY_LENGTH = 18 , DBUS_INVALID_MESSAGE_TOO_LONG = 19 , DBUS_INVALID_HEADER_FIELD_CODE = 20 , DBUS_INVALID_HEADER_FIELD_HAS_WRONG_TYPE = 21 , DBUS_INVALID_USES_LOCAL_INTERFACE = 22 , DBUS_INVALID_USES_LOCAL_PATH = 23 , DBUS_INVALID_HEADER_FIELD_APPEARS_TWICE = 24 , DBUS_INVALID_BAD_DESTINATION = 25 , DBUS_INVALID_BAD_INTERFACE = 26 , DBUS_INVALID_BAD_MEMBER = 27 , DBUS_INVALID_BAD_ERROR_NAME = 28 , DBUS_INVALID_BAD_SENDER = 29 , DBUS_INVALID_MISSING_PATH = 30 , DBUS_INVALID_MISSING_INTERFACE = 31 , DBUS_INVALID_MISSING_MEMBER = 32 , DBUS_INVALID_MISSING_ERROR_NAME = 33 , DBUS_INVALID_MISSING_REPLY_SERIAL = 34 , DBUS_INVALID_LENGTH_OUT_OF_BOUNDS = 35 , DBUS_INVALID_ARRAY_LENGTH_EXCEEDS_MAXIMUM = 36 , DBUS_INVALID_BAD_PATH = 37 , DBUS_INVALID_SIGNATURE_LENGTH_OUT_OF_BOUNDS = 38 , DBUS_INVALID_BAD_UTF8_IN_STRING = 39 , DBUS_INVALID_ARRAY_LENGTH_INCORRECT = 40 , DBUS_INVALID_VARIANT_SIGNATURE_LENGTH_OUT_OF_BOUNDS = 41 , DBUS_INVALID_VARIANT_SIGNATURE_BAD = 42 , DBUS_INVALID_VARIANT_SIGNATURE_EMPTY = 43 , DBUS_INVALID_VARIANT_SIGNATURE_SPECIFIES_MULTIPLE_VALUES = 44 , DBUS_INVALID_VARIANT_SIGNATURE_MISSING_NUL = 45 , DBUS_INVALID_STRING_MISSING_NUL = 46 , DBUS_INVALID_SIGNATURE_MISSING_NUL = 47 , DBUS_INVALID_EXCEEDED_MAXIMUM_DICT_ENTRY_RECURSION = 48 , DBUS_INVALID_DICT_ENTRY_ENDED_BUT_NOT_STARTED = 49 , DBUS_INVALID_DICT_ENTRY_STARTED_BUT_NOT_ENDED = 50 , DBUS_INVALID_DICT_ENTRY_HAS_NO_FIELDS = 51 , DBUS_INVALID_DICT_ENTRY_HAS_ONLY_ONE_FIELD = 52 , DBUS_INVALID_DICT_ENTRY_HAS_TOO_MANY_FIELDS = 53 , DBUS_INVALID_DICT_ENTRY_NOT_INSIDE_ARRAY = 54 , DBUS_INVALID_DICT_KEY_MUST_BE_BASIC_TYPE = 55 , DBUS_INVALID_MISSING_UNIX_FDS = 56 , DBUS_INVALID_NESTED_TOO_DEEPLY = 57 , DBUS_VALIDITY_LAST }
| This is primarily used in unit testing, so we can verify that each invalid message is invalid for the expected reasons. More...

## Functions
void | _dbus_pack_uint32 (dbus_uint32_t value, int byte_order, unsigned char *data)
| Packs a 32 bit unsigned integer into a data pointer.
dbus_uint16_t | _dbus_unpack_uint16 (int byte_order, const unsigned char *data)
| Unpacks a 16 bit unsigned integer from a data pointer.
dbus_uint32_t | _dbus_unpack_uint32 (int byte_order, const unsigned char *data)
| Unpacks a 32 bit unsigned integer from a data pointer.
void | _dbus_marshal_set_uint32 (DBusString *str, int pos, dbus_uint32_t value, int byte_order)
| Sets the 4 bytes at the given offset to a marshaled unsigned integer, replacing anything found there previously.
dbus_bool_t | _dbus_marshal_set_basic (DBusString *str, int pos, int type, const void *value, int byte_order, int *old_end_pos, int *new_end_pos)
| Sets an existing basic type value to a new value.
dbus_uint32_t | _dbus_marshal_read_uint32 (const DBusString *str, int pos, int byte_order, int *new_pos)
| Convenience function to demarshal a 32 bit unsigned integer.
void | _dbus_marshal_read_basic (const DBusString *str, int pos, int type, void *value, int byte_order, int *new_pos)
| Demarshals a basic-typed value.
dbus_bool_t | _dbus_marshal_write_basic (DBusString *str, int insert_at, int type, const void *value, int byte_order, int *pos_after)
| Marshals a basic-typed value.
void | _dbus_swap_array (unsigned char *data, int n_elements, int alignment)
| Swaps the elements of an array to the opposite byte order.
dbus_bool_t | _dbus_marshal_write_fixed_multi (DBusString *str, int insert_at, int element_type, const void *value, int n_elements, int byte_order, int *pos_after)
| Marshals a block of values of fixed-length type all at once, as an optimization.
void | _dbus_marshal_skip_basic (const DBusString *str, int type, int byte_order, int *pos)
| Skips over a basic-typed value, reporting the following position.
void | _dbus_marshal_skip_array (const DBusString *str, int element_type, int byte_order, int *pos)
| Skips an array, returning the next position.
int | _dbus_type_get_alignment (int typecode)
| Gets the alignment requirement for the given type; will be 1, 4, or 8.
const char * | _dbus_type_to_string (int typecode)
| Returns a string describing the given type.
void | _dbus_verbose_bytes (const unsigned char *data, int len, int offset)
| If in verbose mode, print a block of binary data.
void | _dbus_verbose_bytes_of_string (const DBusString *str, int start, int len)
| Dump the given part of the string to verbose log.
int | _dbus_first_type_in_signature (const DBusString *str, int pos)
| Get the first type in the signature.
int | _dbus_first_type_in_signature_c_str (const char *str, int pos)
| Similar to _dbus_first_type_in_signature, but operates on a C string buffer.
void | _dbus_marshal_byteswap (const DBusString *signature, int signature_start, int old_byte_order, int new_byte_order, DBusString *value_str, int value_pos)
| Byteswaps the marshaled data in the given value_str.
| _DBUS_STRING_DEFINE_STATIC (_dbus_header_signature_str, DBUS_HEADER_SIGNATURE)
| Static DBusString containing the signature of a message header.
| _DBUS_STRING_DEFINE_STATIC (_dbus_local_interface_str, DBUS_INTERFACE_LOCAL)
| Static DBusString containing the local interface.
| _DBUS_STRING_DEFINE_STATIC (_dbus_local_path_str, DBUS_PATH_LOCAL)
| Static DBusString containing the local path.
char | _dbus_header_get_byte_order (const DBusHeader *header)
| Returns the header's byte order.
int | _dbus_header_get_message_type (DBusHeader *header)
| Gets the type of the message.
void | _dbus_header_set_serial (DBusHeader *header, dbus_uint32_t serial)
| Sets the serial number of a header.
dbus_uint32_t | _dbus_header_get_serial (DBusHeader *header)
| See dbus_message_get_serial()
void | _dbus_header_reinit (DBusHeader *header)
| Re-initializes a header that was previously initialized and never freed.
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 _dbus_header_create().
void | _dbus_header_free (DBusHeader *header)
| Frees a header.
dbus_bool_t | _dbus_header_copy (const DBusHeader *header, DBusHeader *dest)
| Initializes dest with a copy of the given header.
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_header_have_message_untrusted (int max_message_length, DBusValidity *validity, int *byte_order, int *fields_array_len, int *header_len, int *body_len, const DBusString *str, int start, int len)
| Given data long enough to contain the length of the message body and the fields array, check whether the data is long enough to contain the entire message (assuming the claimed lengths are accurate).
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_update_lengths (DBusHeader *header, int body_len)
| Fills in the correct body length.
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.
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_header_get_field_raw (DBusHeader *header, int field, const DBusString **str, int *pos)
| Gets the raw marshaled data for a field.
dbus_bool_t | _dbus_header_delete_field (DBusHeader *header, int field)
| Deletes a field, if it exists.
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.
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_header_byteswap (DBusHeader *header, int new_order)
| Swaps the header into the given order if required.
dbus_bool_t | _dbus_header_remove_unknown_fields (DBusHeader *header)
| Remove every header field not known to this version of dbus.
void | _dbus_type_signature_next (const char *type_str, int *type_pos)
| Skips to the next "complete" type inside a type signature.
void | _dbus_type_reader_init (DBusTypeReader *reader, int byte_order, const DBusString *type_str, int type_pos, const DBusString *value_str, int value_pos)
| Initializes a type reader.
void | _dbus_type_reader_init_types_only (DBusTypeReader *reader, const DBusString *type_str, int type_pos)
| Like _dbus_type_reader_init() but the iteration is over the signature, not over values.
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 type it's currently pointing to.
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.
int | _dbus_type_reader_get_value_pos (const DBusTypeReader *reader)
| Gets the current position in the value block.
void | _dbus_type_reader_read_raw (const DBusTypeReader *reader, const unsigned char **value_location)
| Get the address of the marshaled value in the data being read.
void | _dbus_type_reader_read_basic (const DBusTypeReader *reader, void *value)
| Reads a basic-typed value, as with _dbus_marshal_read_basic().
int | _dbus_type_reader_get_array_length (const DBusTypeReader *reader)
| Returns the number of bytes in the array.
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 array.
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 current container.
dbus_bool_t | _dbus_type_reader_next (DBusTypeReader *reader)
| Skip to the next value on this "level".
dbus_bool_t | _dbus_type_reader_has_next (const DBusTypeReader *reader)
| Check whether there's another value on this "level".
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_reader_set_basic (DBusTypeReader *reader, const void *value, const DBusTypeReader *realign_root)
| Sets a new value for the basic type value pointed to by the reader, leaving the reader valid to continue reading.
dbus_bool_t | _dbus_type_reader_delete (DBusTypeReader *reader, const DBusTypeReader *realign_root)
| Recursively deletes any value pointed to by the reader, leaving the reader valid to continue reading.
void | _dbus_type_writer_init (DBusTypeWriter *writer, int byte_order, DBusString *type_str, int type_pos, DBusString *value_str, int value_pos)
| Initialize a write iterator, which is used to write out values in serialized D-Bus format.
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.
void | _dbus_type_writer_add_types (DBusTypeWriter *writer, DBusString *type_str, int type_pos)
| Adds type string to the writer, if it had none.
void | _dbus_type_writer_remove_types (DBusTypeWriter *writer)
| Removes type string from the writer.
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 signature that matches what you're going to write out.
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_type_writer_append_array (DBusTypeWriter *writer, const DBusString *contained_type, int contained_type_start, DBusTypeWriter *sub)
| Append to an existing array.
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 the values block.
dbus_bool_t | _dbus_type_writer_write_basic (DBusTypeWriter *writer, int type, const void *value)
| Writes out a basic type.
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.
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.
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.
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 expected_signature.
dbus_bool_t | _dbus_validate_path (const DBusString *str, int start, int len)
| Checks that the given range of the string is a valid object path name in the D-Bus protocol.
const char * | _dbus_validity_to_error_message (DBusValidity validity)
dbus_bool_t | _dbus_validate_interface (const DBusString *str, int start, int len)
| Checks that the given range of the string is a valid interface name in the D-Bus protocol.
dbus_bool_t | _dbus_validate_member (const DBusString *str, int start, int len)
| Checks that the given range of the string is a valid member name in the D-Bus protocol.
dbus_bool_t | _dbus_validate_error_name (const DBusString *str, int start, int len)
| Checks that the given range of the string is a valid error name in the D-Bus protocol.
dbus_bool_t | _dbus_validate_bus_name (const DBusString *str, int start, int len)
| Checks that the given range of the string is a valid bus name in the D-Bus protocol.
dbus_bool_t | _dbus_validate_bus_namespace (const DBusString *str, int start, int len)
| Checks that the given range of the string is a prefix of a valid bus name in the D-Bus protocol.
| DECLARE_DBUS_NAME_CHECK (path)
| defines _dbus_check_is_valid_path()
| DECLARE_DBUS_NAME_CHECK (interface)
| defines _dbus_check_is_valid_interface()
| DECLARE_DBUS_NAME_CHECK (member)
| defines _dbus_check_is_valid_member()
| DECLARE_DBUS_NAME_CHECK (error_name)
| defines _dbus_check_is_valid_error_name()
| DECLARE_DBUS_NAME_CHECK (bus_name)
| defines _dbus_check_is_valid_bus_name()
| DECLARE_DBUS_NAME_CHECK (utf8)
| defines _dbus_check_is_valid_utf8()

## Detailed Description

functions to marshal/unmarshal data from the wire

Types and functions related to converting primitive data types from wire format to native machine format, and vice versa.

A signature is just a string with multiple types one after the other. for example a type is "i" or "(ii)", a signature is "i(ii)" where i is int and (ii) is struct { int; int; }

## Macro Definition Documentation

## ◆ _dbus_validate_utf8

#define _dbus_validate_utf8 | ( |  | s,
|  |  | b,
|  |  | e
| ) |  | _dbus_string_validate_utf8 (s, b, e)

Definition at line 161 of file dbus-marshal-validate.h.

## ◆ ARRAY_READER_LEN_POS

#define ARRAY_READER_LEN_POS | ( |  | reader | ) | ((reader)->u.array.start_pos - ((int)(reader)->array_len_offset) - 4)

compute position of array length given array_len_offset, which is the offset back from start_pos to end of the len

Definition at line 214 of file dbus-marshal-recursive.c.

## ◆ BODY_LENGTH_OFFSET

#define BODY_LENGTH_OFFSET 4

Offset to body length from start of header.

Definition at line 61 of file dbus-marshal-header.c.

## ◆ BYTE_ORDER_OFFSET

#define BYTE_ORDER_OFFSET 0

Offset to byte order from start of header.

Definition at line 53 of file dbus-marshal-header.c.

## ◆ DECLARE_DBUS_NAME_CHECK

#define DECLARE_DBUS_NAME_CHECK | ( |  | what | ) | dbus_bool_t _dbus_check_is_valid_##what (const char *name)

A name check is used in _dbus_return_if_fail(), it's not suitable for validating untrusted data.

use _dbus_validate_whatever for that.

Definition at line 176 of file dbus-marshal-validate.h.

## ◆ DEFINE_DBUS_NAME_CHECK

#define DEFINE_DBUS_NAME_CHECK | ( |  | what | ) |

Value:
dbus_bool_t \
_dbus_check_is_valid_##what (const char *name) \
{ \
DBusString str; \
\
if (name == NULL) \
return FALSE; \
\
_dbus_string_init_const (&str, name); \
return _dbus_validate_##what (&str, 0, \
_dbus_string_get_length (&str)); \
}
NULL
#define NULL
A null pointer, defined appropriately for C or C++.
Definition dbus-macros.h:49
FALSE
#define FALSE
Expands to "0".
Definition dbus-macros.h:42
DBusString
Definition dbus-string.h:43

Define a name check to be used in _dbus_return_if_fail() statements.

Definition at line 181 of file dbus-marshal-validate.h.

## ◆ EXPECTED_TYPE_OF_FIELD

#define EXPECTED_TYPE_OF_FIELD | ( |  | field | ) | (_dbus_header_field_types[field].type)

Macro to look up the correct type for a field.

Definition at line 91 of file dbus-marshal-header.c.

## ◆ FIELDS_ARRAY_ELEMENT_SIGNATURE_OFFSET

#define FIELDS_ARRAY_ELEMENT_SIGNATURE_OFFSET 7

Offset from start of _dbus_header_signature_str to the signature of an element of the fields array.

Definition at line 49 of file dbus-marshal-header.c.

## ◆ FIELDS_ARRAY_LENGTH_OFFSET

#define FIELDS_ARRAY_LENGTH_OFFSET 12

Offset to fields array length from start of header.

Definition at line 65 of file dbus-marshal-header.c.

## ◆ FIELDS_ARRAY_SIGNATURE_OFFSET

#define FIELDS_ARRAY_SIGNATURE_OFFSET 6

Offset from start of _dbus_header_signature_str to the signature of the fields array.

Definition at line 47 of file dbus-marshal-header.c.

## ◆ FIRST_FIELD_OFFSET

#define FIRST_FIELD_OFFSET 16

Offset to first field in header.

Definition at line 67 of file dbus-marshal-header.c.

## ◆ FLAGS_OFFSET

#define FLAGS_OFFSET 2

Offset to flags from start of header.

Definition at line 57 of file dbus-marshal-header.c.

## ◆ HEADER_END_BEFORE_PADDING

#define HEADER_END_BEFORE_PADDING | ( |  | header | ) | (_dbus_string_get_length (&(header)->data) - (header)->padding)

Compute the end of the header, ignoring padding.

In the DBusHeader diagram, this is the distance from 0 to [B].

Definition at line 126 of file dbus-marshal-header.c.

## ◆ MAX_POSSIBLE_HEADER_PADDING

#define MAX_POSSIBLE_HEADER_PADDING 7

The most padding we could ever need for a header.

Definition at line 94 of file dbus-marshal-header.c.

## ◆ RECURSIVE_MARSHAL_READ_TRACE

#define RECURSIVE_MARSHAL_READ_TRACE 0

turn this on to get deluged in TypeReader verbose spam

Definition at line 48 of file dbus-marshal-recursive.c.

## ◆ RECURSIVE_MARSHAL_WRITE_TRACE

#define RECURSIVE_MARSHAL_WRITE_TRACE 0

turn this on to get deluged in TypeWriter verbose spam

Definition at line 51 of file dbus-marshal-recursive.c.

## ◆ SERIAL_OFFSET

#define SERIAL_OFFSET 8

Offset to client serial from start of header.

Definition at line 63 of file dbus-marshal-header.c.

## ◆ TYPE_OFFSET

#define TYPE_OFFSET 1

Offset to type from start of header.

Definition at line 55 of file dbus-marshal-header.c.

## ◆ VALID_BUS_NAME_CHARACTER

#define VALID_BUS_NAME_CHARACTER | ( |  | c | ) |

Value:
( ((c) >= '0' && (c) <= '9') || \
((c) >= 'A' && (c) <= 'Z') || \
((c) >= 'a' && (c) <= 'z') || \
((c) == '_') || ((c) == '-'))

Determine wether the given character is valid as a second or later character in a bus name.

Definition at line 1133 of file dbus-marshal-validate.c.

## ◆ VALID_INITIAL_BUS_NAME_CHARACTER

#define VALID_INITIAL_BUS_NAME_CHARACTER | ( |  | c | ) |

Value:
( ((c) >= 'A' && (c) <= 'Z') || \
((c) >= 'a' && (c) <= 'z') || \
((c) == '_') || ((c) == '-'))

Determine wether the given character is valid as the first character in a bus name.

Definition at line 1124 of file dbus-marshal-validate.c.

## ◆ VALID_INITIAL_NAME_CHARACTER

#define VALID_INITIAL_NAME_CHARACTER | ( |  | c | ) |

Value:
( ((c) >= 'A' && (c) <= 'Z') || \
((c) >= 'a' && (c) <= 'z') || \
((c) == '_') )

Determine wether the given character is valid as the first character in a name.

Definition at line 805 of file dbus-marshal-validate.c.

## ◆ VALID_NAME_CHARACTER

#define VALID_NAME_CHARACTER | ( |  | c | ) |

Value:
( ((c) >= '0' && (c) <= '9') || \
((c) >= 'A' && (c) <= 'Z') || \
((c) >= 'a' && (c) <= 'z') || \
((c) == '_') )

Determine wether the given character is valid as a second or later character in a name.

Definition at line 814 of file dbus-marshal-validate.c.

## ◆ VERSION_OFFSET

#define VERSION_OFFSET 3

Offset to version from start of header.

Definition at line 59 of file dbus-marshal-header.c.

## Enumeration Type Documentation

## ◆ anonymous enum

anonymous enum

Definition at line 708 of file dbus-marshal-basic.c.

## ◆ DBusValidationMode

enum DBusValidationMode

This is used rather than a bool for high visibility.

Definition at line 38 of file dbus-marshal-validate.h.

## ◆ DBusValidity

enum DBusValidity

This is primarily used in unit testing, so we can verify that each invalid message is invalid for the expected reasons.

Thus we really want a distinct enum value for every codepath leaving the validator functions. Enum values are specified manually for ease of debugging (so you can see the enum value given a printf)

Enumerator
DBUS_VALIDITY_UNKNOWN_OOM_ERROR | can't determine validity due to OOM
DBUS_VALID | the data is valid
DBUS_INVALID_TOO_MUCH_DATA | trailing junk makes it invalid

Definition at line 51 of file dbus-marshal-validate.h.

## Function Documentation

## ◆ _dbus_first_type_in_signature()

int _dbus_first_type_in_signature | ( | const DBusString * | str,
|  | int | pos
| ) |  |

Get the first type in the signature.

The difference between this and just getting the first byte of the signature is that you won't get DBUS_STRUCT_BEGIN_CHAR, you'll get DBUS_TYPE_STRUCT instead.

Parameters

  str | string containing signature
  pos | where the signature starts

Returns
  the first type in the signature

Definition at line 1477 of file dbus-marshal-basic.c.

Referenced by _dbus_type_reader_get_current_type(), _dbus_type_reader_get_element_type(), _dbus_type_reader_read_fixed_multi(), and _dbus_type_reader_recurse().

## ◆ _dbus_first_type_in_signature_c_str()

int _dbus_first_type_in_signature_c_str | ( | const char * | str,
|  | int | pos
| ) |  |

Similar to _dbus_first_type_in_signature, but operates on a C string buffer.

Parameters

  str | a C string buffer
  pos | where the signature starts

Returns
  the first type in the signature

Definition at line 1492 of file dbus-marshal-basic.c.

Referenced by dbus_signature_iter_get_current_type(), and dbus_signature_iter_get_element_type().

## ◆ _dbus_header_byteswap()

void _dbus_header_byteswap | ( | DBusHeader * | header,
|  | int | new_order
| ) |  |

Swaps the header into the given order if required.

Parameters

  header | the header
  new_order | the new byte order

Definition at line 1505 of file dbus-marshal-header.c.

References _dbus_header_get_byte_order(), _dbus_marshal_byteswap(), BYTE_ORDER_OFFSET, and DBusHeader::data.

## ◆ _dbus_header_copy()

dbus_bool_t _dbus_header_copy | ( | const DBusHeader * | header,
|  | DBusHeader * | dest
| ) |  |

Initializes dest with a copy of the given header.

Resets the message serial to 0 on the copy.

Parameters

  header | header to copy
  dest | destination for copy

Returns
  FALSE if not enough memory

Definition at line 493 of file dbus-marshal-header.c.

References _dbus_header_set_serial(), _dbus_string_copy(), _dbus_string_free(), _dbus_string_init_preallocated(), DBusHeader::data, FALSE, and TRUE.

Referenced by dbus_message_copy().

## ◆ _dbus_header_create()

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.

NULL may be specified for some or all of the fields to avoid adding those fields. Some combinations of fields don't make sense, and passing them in will trigger an assertion failure.

Parameters

  header | the header
  byte_order | byte order of the header
  message_type | the message type
  destination | destination field or NULL
  path | path field or NULL
  interface | interface field or NULL
  member | member field or NULL
  error_name | error name or NULL

Returns
  FALSE if not enough memory

Definition at line 531 of file dbus-marshal-header.c.

References _dbus_assert, _dbus_string_delete(), _dbus_type_writer_init_values_only(), _dbus_type_writer_recurse(), _dbus_type_writer_unrecurse(), _dbus_type_writer_write_basic(), DBusHeader::data, DBUS_BIG_ENDIAN, DBUS_HEADER_FIELD_DESTINATION, DBUS_HEADER_FIELD_ERROR_NAME, DBUS_HEADER_FIELD_INTERFACE, DBUS_HEADER_FIELD_MEMBER, DBUS_HEADER_FIELD_PATH, DBUS_LITTLE_ENDIAN, DBUS_MAJOR_PROTOCOL_VERSION, DBUS_MESSAGE_TYPE_SIGNAL, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, DBUS_TYPE_OBJECT_PATH, DBUS_TYPE_STRING, DBUS_TYPE_UINT32, FALSE, FIELDS_ARRAY_SIGNATURE_OFFSET, HEADER_END_BEFORE_PADDING, NULL, DBusHeader::padding, and TRUE.

Referenced by dbus_message_new(), dbus_message_new_error(), dbus_message_new_method_call(), dbus_message_new_method_return(), and dbus_message_new_signal().

## ◆ _dbus_header_delete_field()

dbus_bool_t _dbus_header_delete_field | ( | DBusHeader * | header,
|  | int | field
| ) |  |

Deletes a field, if it exists.

Parameters

  header | the header
  field | the field to delete

Returns
  FALSE if no memory

Definition at line 1425 of file dbus-marshal-header.c.

References _dbus_assert, _dbus_type_reader_delete(), FALSE, and TRUE.

## ◆ _dbus_header_free()

void _dbus_header_free | ( | DBusHeader * | header | ) |

Frees a header.

Parameters

  header | the header

Definition at line 479 of file dbus-marshal-header.c.

References _dbus_string_free(), and DBusHeader::data.

Referenced by dbus_message_copy().

## ◆ _dbus_header_get_byte_order()

char _dbus_header_get_byte_order | ( | const DBusHeader * | header | ) |

Returns the header's byte order.

Parameters

  header | the header

Returns
  the byte order

Definition at line 177 of file dbus-marshal-header.c.

References _dbus_assert, BYTE_ORDER_OFFSET, and DBusHeader::data.

Referenced by _dbus_header_byteswap(), _dbus_header_get_field_basic(), _dbus_header_get_serial(), _dbus_header_remove_unknown_fields(), _dbus_header_set_field_basic(), _dbus_header_set_serial(), _dbus_header_update_lengths(), dbus_message_iter_init(), and dbus_message_iter_init_append().

## ◆ _dbus_header_get_field_basic()

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.

If the field doesn't exist, returns FALSE, otherwise returns TRUE.

Parameters

  header | the header
  field | the field to get
  type | the type of the value
  value | the value as for _dbus_marshal_read_basic()

Returns
  FALSE if the field doesn't exist

Definition at line 1360 of file dbus-marshal-header.c.

References _dbus_assert, _dbus_header_get_byte_order(), _dbus_marshal_read_basic(), DBusHeader::data, DBUS_HEADER_FIELD_INVALID, DBUS_HEADER_FIELD_LAST, EXPECTED_TYPE_OF_FIELD, FALSE, DBusHeader::fields, NULL, TRUE, and DBusHeaderField::value_pos.

Referenced by dbus_message_get_container_instance(), dbus_message_get_destination(), dbus_message_get_error_name(), dbus_message_get_interface(), dbus_message_get_member(), dbus_message_get_path(), dbus_message_get_reply_serial(), and dbus_message_get_sender().

## ◆ _dbus_header_get_field_raw()

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.

If the field doesn't exist, returns FALSE, otherwise returns TRUE. Returns the start of the marshaled data, i.e. usually the byte where the length starts (for strings and arrays) or for basic types just the value itself.

Parameters

  header | the header
  field | the field to get
  str | return location for the data string
  pos | return location for start of field value

Returns
  FALSE if the field doesn't exist

Definition at line 1401 of file dbus-marshal-header.c.

References DBusHeader::data, FALSE, DBusHeader::fields, TRUE, and DBusHeaderField::value_pos.

## ◆ _dbus_header_get_flag()

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.

Parameters

  header | the header
  flag | the message flag to get

Returns
  TRUE if the flag is set

Definition at line 1488 of file dbus-marshal-header.c.

References DBusHeader::data, and FLAGS_OFFSET.

Referenced by dbus_message_get_allow_interactive_authorization(), dbus_message_get_auto_start(), and dbus_message_get_no_reply().

## ◆ _dbus_header_get_message_type()

int _dbus_header_get_message_type | ( | DBusHeader * | header | ) |

Gets the type of the message.

Parameters

  header | the header

Returns
  the type

Definition at line 389 of file dbus-marshal-header.c.

References _dbus_assert, DBusHeader::data, DBUS_MESSAGE_TYPE_INVALID, and TYPE_OFFSET.

Referenced by dbus_message_get_type().

## ◆ _dbus_header_get_serial()

dbus_uint32_t _dbus_header_get_serial | ( | DBusHeader * | header | ) |

See dbus_message_get_serial()

Parameters

  header | the header

Returns
  the client serial

Definition at line 430 of file dbus-marshal-header.c.

References _dbus_header_get_byte_order(), _dbus_marshal_read_uint32(), DBusHeader::data, NULL, and SERIAL_OFFSET.

Referenced by _dbus_header_set_serial(), and dbus_message_get_serial().

## ◆ _dbus_header_have_message_untrusted()

dbus_bool_t _dbus_header_have_message_untrusted | ( | int | max_message_length,
|  | DBusValidity * | validity,
|  | int * | byte_order,
|  | int * | fields_array_len,
|  | int * | header_len,
|  | int * | body_len,
|  | const DBusString * | str,
|  | int | start,
|  | int | len
| ) |  |

Given data long enough to contain the length of the message body and the fields array, check whether the data is long enough to contain the entire message (assuming the claimed lengths are accurate).

Also checks that the lengths are in sanity parameters.

Parameters

  max_message_length | maximum length of a valid message
  validity | return location for why the data is invalid if it is
  byte_order | return location for byte order
  fields_array_len | return location for claimed fields array length
  header_len | return location for claimed header length
  body_len | return location for claimed body length
  str | the data
  start | start of data, 8-aligned
  len | length of data

Returns
  TRUE if the data is long enough for the claimed length, and the lengths were valid

Definition at line 679 of file dbus-marshal-header.c.

References _dbus_assert, _DBUS_INT32_MAX, _dbus_marshal_read_uint32(), BODY_LENGTH_OFFSET, BYTE_ORDER_OFFSET, DBUS_BIG_ENDIAN, DBUS_LITTLE_ENDIAN, DBUS_VALID, FALSE, FIELDS_ARRAY_LENGTH_OFFSET, FIRST_FIELD_OFFSET, and NULL.

Referenced by _dbus_message_loader_get_buffer(), _dbus_message_loader_queue_messages(), and dbus_message_demarshal_bytes_needed().

## ◆ _dbus_header_init()

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 _dbus_header_create().

Parameters

  header | header to initialize

Returns
  FALSE if not enough memory

Definition at line 463 of file dbus-marshal-header.c.

References _dbus_header_reinit(), _dbus_string_init_preallocated(), DBusHeader::data, FALSE, and TRUE.

## ◆ _dbus_header_load()

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.

The return value is TRUE if there was enough memory and the data was valid. If it returns TRUE, the header will be created. If it returns FALSE and *validity == DBUS_VALIDITY_UNKNOWN_OOM_ERROR, then there wasn't enough memory. If it returns FALSE and *validity != DBUS_VALIDITY_UNKNOWN_OOM_ERROR then the data was invalid.

The byte_order, fields_array_len, and body_len args should be from _dbus_header_have_message_untrusted(). Validation performed in _dbus_header_have_message_untrusted() is assumed to have been already done.

Parameters

  header | the header (must be initialized)
  mode | whether to do validation
  validity | return location for invalidity reason
  byte_order | byte order from header
  fields_array_len | claimed length of fields array
  body_len | claimed length of body
  header_len | claimed length of header
  str | a string starting with the header

Returns
  FALSE if no memory or data was invalid, TRUE otherwise

Definition at line 979 of file dbus-marshal-header.c.

References _dbus_assert, _dbus_string_copy_len(), _dbus_string_set_length(), _dbus_string_validate_nul(), _dbus_type_reader_get_current_type(), _dbus_type_reader_get_value_pos(), _dbus_type_reader_init(), _dbus_type_reader_next(), _dbus_type_reader_read_basic(), _dbus_type_reader_recurse(), _dbus_validate_body_with_reason(), BODY_LENGTH_OFFSET, BYTE_ORDER_OFFSET, DBusHeader::data, DBUS_HEADER_FIELD_INVALID, DBUS_HEADER_FIELD_LAST, DBUS_MAJOR_PROTOCOL_VERSION, DBUS_MESSAGE_TYPE_INVALID, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, DBUS_TYPE_INVALID, DBUS_TYPE_STRUCT, DBUS_TYPE_UINT32, DBUS_TYPE_VARIANT, DBUS_VALID, DBUS_VALIDITY_UNKNOWN_OOM_ERROR, FALSE, DBusHeader::fields, FIELDS_ARRAY_LENGTH_OFFSET, FIRST_FIELD_OFFSET, FLAGS_OFFSET, DBusHeader::padding, SERIAL_OFFSET, TRUE, TYPE_OFFSET, DBusHeaderField::value_pos, and VERSION_OFFSET.

## ◆ _dbus_header_reinit()

void _dbus_header_reinit | ( | DBusHeader * | header | ) |

Re-initializes a header that was previously initialized and never freed.

After this, to make the header valid you have to call _dbus_header_create().

Parameters

  header | header to re-initialize

Definition at line 446 of file dbus-marshal-header.c.

References _dbus_string_set_length(), DBusHeader::data, and DBusHeader::padding.

Referenced by _dbus_header_init().

## ◆ _dbus_header_remove_unknown_fields()

dbus_bool_t _dbus_header_remove_unknown_fields | ( | DBusHeader * | header | ) |

Remove every header field not known to this version of dbus.

Parameters

  header | the header

Returns
  FALSE if no memory

Definition at line 1530 of file dbus-marshal-header.c.

References _dbus_assert, _dbus_header_get_byte_order(), _dbus_type_reader_delete(), _dbus_type_reader_get_current_type(), _dbus_type_reader_init(), _dbus_type_reader_next(), _dbus_type_reader_read_basic(), _dbus_type_reader_recurse(), DBusHeader::data, DBUS_HEADER_FIELD_LAST, DBUS_TYPE_BYTE, DBUS_TYPE_INVALID, FALSE, FIELDS_ARRAY_LENGTH_OFFSET, FIELDS_ARRAY_SIGNATURE_OFFSET, and TRUE.

Referenced by _dbus_message_remove_unknown_fields().

## ◆ _dbus_header_set_field_basic()

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.

If the value is a string value, it isn't allowed to be NULL. If the field doesn't exist, it will be created.

Parameters

  header | the header
  field | the field to set
  type | the type of the value
  value | the value as for _dbus_marshal_set_basic()

Returns
  FALSE if no memory

Definition at line 1282 of file dbus-marshal-header.c.

References _dbus_assert, _dbus_assert_not_reached, _dbus_header_get_byte_order(), _dbus_type_writer_append_array(), _dbus_type_writer_init_values_only(), _dbus_type_writer_unrecurse(), DBusHeader::data, DBUS_HEADER_FIELD_LAST, FALSE, FIELDS_ARRAY_ELEMENT_SIGNATURE_OFFSET, FIELDS_ARRAY_LENGTH_OFFSET, FIELDS_ARRAY_SIGNATURE_OFFSET, FIRST_FIELD_OFFSET, HEADER_END_BEFORE_PADDING, DBusTypeWriter::len_pos, DBusTypeWriter::start_pos, TRUE, DBusTypeWriter::u, and DBusTypeWriter::value_pos.

Referenced by dbus_message_iter_append_basic(), and dbus_message_set_reply_serial().

## ◆ _dbus_header_set_serial()

void _dbus_header_set_serial | ( | DBusHeader * | header,
|  | dbus_uint32_t | serial
| ) |  |

Sets the serial number of a header.

This can only be done once on a header.

Parameters

  header | the header
  serial | the serial

Definition at line 407 of file dbus-marshal-header.c.

References _dbus_assert, _dbus_header_get_byte_order(), _dbus_header_get_serial(), _dbus_marshal_set_uint32(), DBusHeader::data, and SERIAL_OFFSET.

Referenced by _dbus_header_copy(), and dbus_message_set_serial().

## ◆ _dbus_header_toggle_flag()

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.

Parameters

  header | the header
  flag | the message flag to toggle
  value | toggle on or off

Definition at line 1466 of file dbus-marshal-header.c.

References DBusHeader::data, and FLAGS_OFFSET.

Referenced by dbus_message_set_allow_interactive_authorization(), dbus_message_set_auto_start(), and dbus_message_set_no_reply().

## ◆ _dbus_header_update_lengths()

void _dbus_header_update_lengths | ( | DBusHeader * | header,
|  | int | body_len
| ) |  |

Fills in the correct body length.

Parameters

  header | the header
  body_len | the length of the body

Definition at line 1205 of file dbus-marshal-header.c.

References _dbus_header_get_byte_order(), _dbus_marshal_set_uint32(), BODY_LENGTH_OFFSET, and DBusHeader::data.

Referenced by dbus_message_lock().

## ◆ _dbus_marshal_byteswap()

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.

Parameters

  signature | the types in the value_str
  signature_start | where in signature is the signature
  old_byte_order | the old byte order
  new_byte_order | the new byte order
  value_str | the string containing the body
  value_pos | where the values start

Definition at line 218 of file dbus-marshal-byteswap.c.

References _dbus_assert, _dbus_type_reader_init_types_only(), NULL, and TRUE.

Referenced by _dbus_header_byteswap().

## ◆ _dbus_marshal_read_basic()

void _dbus_marshal_read_basic | ( | const DBusString * | str,
|  | int | pos,
|  | int | type,
|  | void * | value,
|  | int | byte_order,
|  | int * | new_pos
| ) |  |

Demarshals a basic-typed value.

The "value" pointer is always the address of a variable of the basic type. So e.g. if the basic type is "double" then the pointer is a double*, and if it's "char*" then the pointer is a "char**".

A value of type DBusBasicValue is guaranteed to be large enough to hold any of the types that may be returned, which is handy if you are trying to do things generically. For example you can pass a DBusBasicValue* in to this function, and then pass the same DBusBasicValue* in to _dbus_marshal_basic_type() in order to move a value from one place to another.

Parameters

  str | the string containing the data
  pos | position in the string
  type | type of value to demarshal
  value | pointer to return value data
  byte_order | the byte order
  new_pos | pointer to update with new position, or NULL

Definition at line 525 of file dbus-marshal-basic.c.

References _dbus_assert, _dbus_assert_not_reached, _dbus_marshal_read_uint32(), _dbus_type_to_string(), _dbus_warn_check_failed(), DBUS_TYPE_BOOLEAN, DBUS_TYPE_BYTE, DBUS_TYPE_DOUBLE, DBUS_TYPE_INT16, DBUS_TYPE_INT32, DBUS_TYPE_INT64, dbus_type_is_basic(), DBUS_TYPE_OBJECT_PATH, DBUS_TYPE_SIGNATURE, DBUS_TYPE_STRING, DBUS_TYPE_UINT16, DBUS_TYPE_UINT32, DBUS_TYPE_UINT64, and DBUS_TYPE_UNIX_FD.

Referenced by _dbus_header_get_field_basic(), and _dbus_type_reader_read_basic().

## ◆ _dbus_marshal_read_uint32()

dbus_uint32_t _dbus_marshal_read_uint32 | ( | const DBusString * | str,
|  | int | pos,
|  | int | byte_order,
|  | int * | new_pos
| ) |  |

Convenience function to demarshal a 32 bit unsigned integer.

Parameters

  str | the string containing the data
  byte_order | the byte order
  pos | the position in the string
  new_pos | the new position of the string

Returns
  the demarshaled integer.

Definition at line 487 of file dbus-marshal-basic.c.

References _dbus_assert, and _dbus_unpack_uint32().

Referenced by _dbus_header_get_serial(), _dbus_header_have_message_untrusted(), _dbus_marshal_read_basic(), _dbus_marshal_skip_array(), and _dbus_marshal_skip_basic().

## ◆ _dbus_marshal_set_basic()

dbus_bool_t _dbus_marshal_set_basic | ( | DBusString * | str,
|  | int | pos,
|  | int | type,
|  | const void * | value,
|  | int | byte_order,
|  | int * | old_end_pos,
|  | int * | new_end_pos
| ) |  |

Sets an existing basic type value to a new value.

Arguments work the same way as _dbus_marshal_basic_type().

Parameters

  str | the string
  pos | location of the current value
  type | the type of the current and new values
  value | the address of the new value
  byte_order | byte order for marshaling
  old_end_pos | location to store end position of the old value, or NULL
  new_end_pos | location to store end position of the new value, or NULL

Returns
  FALSE if no memory

Definition at line 388 of file dbus-marshal-basic.c.

References _dbus_assert, _dbus_assert_not_reached, DBUS_TYPE_BOOLEAN, DBUS_TYPE_BYTE, DBUS_TYPE_DOUBLE, DBUS_TYPE_INT16, DBUS_TYPE_INT32, DBUS_TYPE_INT64, DBUS_TYPE_OBJECT_PATH, DBUS_TYPE_SIGNATURE, DBUS_TYPE_STRING, DBUS_TYPE_UINT16, DBUS_TYPE_UINT32, DBUS_TYPE_UINT64, DBUS_TYPE_UNIX_FD, FALSE, NULL, and TRUE.

## ◆ _dbus_marshal_set_uint32()

void _dbus_marshal_set_uint32 | ( | DBusString * | str,
|  | int | pos,
|  | dbus_uint32_t | value,
|  | int | byte_order
| ) |  |

Sets the 4 bytes at the given offset to a marshaled unsigned integer, replacing anything found there previously.

Parameters

  str | the string to write the marshalled int to
  pos | the byte offset where int should be written
  value | the value
  byte_order | the byte order to use

Definition at line 271 of file dbus-marshal-basic.c.

Referenced by _dbus_header_set_serial(), _dbus_header_update_lengths(), and _dbus_type_writer_unrecurse().

## ◆ _dbus_marshal_skip_array()

void _dbus_marshal_skip_array | ( | const DBusString * | str,
|  | int | element_type,
|  | int | byte_order,
|  | int * | pos
| ) |  |

Skips an array, returning the next position.

Parameters

  str | the string containing the data
  element_type | the type of array elements
  byte_order | the byte order
  pos | pointer to position in the string, updated on return to new position

Definition at line 1208 of file dbus-marshal-basic.c.

References _dbus_marshal_read_uint32(), and _dbus_type_get_alignment().

## ◆ _dbus_marshal_skip_basic()

void _dbus_marshal_skip_basic | ( | const DBusString * | str,
|  | int | type,
|  | int | byte_order,
|  | int * | pos
| ) |  |

Skips over a basic-typed value, reporting the following position.

Parameters

  str | the string containing the data
  type | type of value to read
  byte_order | the byte order
  pos | pointer to position in the string, updated on return to new position

Definition at line 1140 of file dbus-marshal-basic.c.

References _dbus_assert, _dbus_assert_not_reached, _dbus_marshal_read_uint32(), _dbus_type_to_string(), _dbus_warn(), DBUS_BIG_ENDIAN, DBUS_LITTLE_ENDIAN, DBUS_TYPE_BOOLEAN, DBUS_TYPE_BYTE, DBUS_TYPE_DOUBLE, DBUS_TYPE_INT16, DBUS_TYPE_INT32, DBUS_TYPE_INT64, DBUS_TYPE_OBJECT_PATH, DBUS_TYPE_SIGNATURE, DBUS_TYPE_STRING, DBUS_TYPE_UINT16, DBUS_TYPE_UINT32, DBUS_TYPE_UINT64, and DBUS_TYPE_UNIX_FD.

## ◆ _dbus_marshal_write_basic()

dbus_bool_t _dbus_marshal_write_basic | ( | DBusString * | str,
|  | int | insert_at,
|  | int | type,
|  | const void * | value,
|  | int | byte_order,
|  | int * | pos_after
| ) |  |

Marshals a basic-typed value.

The "value" pointer is always the address of a variable containing the basic type value. So for example for int32 it will be dbus_int32_t*, and for string it will be const char**. This is for symmetry with _dbus_marshal_read_basic() and to have a simple consistent rule.

Parameters

  str | string to marshal to
  insert_at | where to insert the value
  type | type of value
  value | pointer to a variable containing the value
  byte_order | byte order
  pos_after | NULL or the position after the type

Returns
  TRUE on success

Definition at line 827 of file dbus-marshal-basic.c.

References _dbus_assert, _dbus_assert_not_reached, _dbus_string_insert_byte(), DBUS_TYPE_BOOLEAN, DBUS_TYPE_BYTE, DBUS_TYPE_DOUBLE, DBUS_TYPE_INT16, DBUS_TYPE_INT32, DBUS_TYPE_INT64, dbus_type_is_basic(), DBUS_TYPE_OBJECT_PATH, DBUS_TYPE_SIGNATURE, DBUS_TYPE_STRING, DBUS_TYPE_UINT16, DBUS_TYPE_UINT32, DBUS_TYPE_UINT64, DBUS_TYPE_UNIX_FD, FALSE, NULL, and TRUE.

## ◆ _dbus_marshal_write_fixed_multi()

dbus_bool_t _dbus_marshal_write_fixed_multi | ( | DBusString * | str,
|  | int | insert_at,
|  | int | element_type,
|  | const void * | value,
|  | int | n_elements,
|  | int | byte_order,
|  | int * | pos_after
| ) |  |

Marshals a block of values of fixed-length type all at once, as an optimization.

dbus_type_is_fixed() returns TRUE for fixed-length types, which are the basic types minus the string-like types.

The value argument should be the adddress of an array, so e.g. "const dbus_uint32_t**"

Parameters

  str | string to marshal to
  insert_at | where to insert the value
  element_type | type of array elements
  value | address of an array to marshal
  n_elements | number of elements in the array
  byte_order | byte order
  pos_after | NULL or the position after the type

Returns
  TRUE on success

Definition at line 1069 of file dbus-marshal-basic.c.

References _dbus_assert, _dbus_assert_not_reached, _dbus_type_to_string(), DBUS_TYPE_BOOLEAN, DBUS_TYPE_BYTE, DBUS_TYPE_DOUBLE, DBUS_TYPE_INT16, DBUS_TYPE_INT32, DBUS_TYPE_INT64, dbus_type_is_fixed(), DBUS_TYPE_UINT16, DBUS_TYPE_UINT32, DBUS_TYPE_UINT64, DBUS_TYPE_UNIX_FD, and FALSE.

Referenced by _dbus_type_writer_write_fixed_multi().

## ◆ _dbus_pack_uint32()

void _dbus_pack_uint32 | ( | dbus_uint32_t | value,
|  | int | byte_order,
|  | unsigned char * | data
| ) |  |

Packs a 32 bit unsigned integer into a data pointer.

Parameters

  value | the value
  byte_order | the byte order to use
  data | the data pointer

Definition at line 153 of file dbus-marshal-basic.c.

## ◆ _dbus_swap_array()

void _dbus_swap_array | ( | unsigned char * | data,
|  | int | n_elements,
|  | int | alignment
| ) |  |

Swaps the elements of an array to the opposite byte order.

Parameters

  data | start of array
  n_elements | number of elements
  alignment | size of each element

Definition at line 937 of file dbus-marshal-basic.c.

References _dbus_assert.

## ◆ _dbus_type_get_alignment()

int _dbus_type_get_alignment | ( | int | typecode | ) |

Gets the alignment requirement for the given type; will be 1, 4, or 8.

Parameters

  typecode | the type

Returns
  alignment of 1, 4, or 8

Definition at line 1236 of file dbus-marshal-basic.c.

References _dbus_assert_not_reached, DBUS_TYPE_ARRAY, DBUS_TYPE_BOOLEAN, DBUS_TYPE_BYTE, DBUS_TYPE_DICT_ENTRY, DBUS_TYPE_DOUBLE, DBUS_TYPE_INT16, DBUS_TYPE_INT32, DBUS_TYPE_INT64, DBUS_TYPE_OBJECT_PATH, DBUS_TYPE_SIGNATURE, DBUS_TYPE_STRING, DBUS_TYPE_STRUCT, DBUS_TYPE_UINT16, DBUS_TYPE_UINT32, DBUS_TYPE_UINT64, DBUS_TYPE_UNIX_FD, and DBUS_TYPE_VARIANT.

Referenced by _dbus_marshal_skip_array(), _dbus_type_reader_read_fixed_multi(), dbus_message_iter_append_fixed_array(), and dbus_message_iter_get_element_count().

## ◆ _dbus_type_reader_delete()

dbus_bool_t _dbus_type_reader_delete | ( | DBusTypeReader * | reader,
|  | const DBusTypeReader * | realign_root
| ) |  |

Recursively deletes any value pointed to by the reader, leaving the reader valid to continue reading.

Any other readers will be invalidated.

The provided realign_root is the reader to start from when realigning the data that follows the newly-set value. See _dbus_type_reader_set_basic() for more details on the realign_root paramter.

Parameters

  reader | reader indicating where to delete a value
  realign_root | realign from here

Returns
  FALSE if not enough memory

Definition at line 1420 of file dbus-marshal-recursive.c.

References _dbus_assert, FALSE, DBusTypeReader::klass, NULL, and TRUE.

Referenced by _dbus_header_delete_field(), and _dbus_header_remove_unknown_fields().

## ◆ _dbus_type_reader_get_array_length()

int _dbus_type_reader_get_array_length | ( | const DBusTypeReader * | reader | ) |

Returns the number of bytes in the array.

Parameters

  reader | the reader to read from

Returns
  the number of bytes in the array

Definition at line 900 of file dbus-marshal-recursive.c.

References _dbus_assert, DBusTypeReader::klass, and DBusTypeReaderClass::types_only.

Referenced by dbus_message_iter_get_array_len(), and dbus_message_iter_get_element_count().

## ◆ _dbus_type_reader_get_current_type()

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 type it's currently pointing to.

If the reader is at the end of a block or end of a container such as an array, returns DBUS_TYPE_INVALID.

Parameters

  reader | the reader

Definition at line 786 of file dbus-marshal-recursive.c.

References _dbus_assert, _dbus_first_type_in_signature(), _dbus_type_to_string(), DBusTypeReaderClass::check_finished, DBUS_DICT_ENTRY_BEGIN_CHAR, DBUS_DICT_ENTRY_END_CHAR, DBUS_STRUCT_BEGIN_CHAR, DBUS_STRUCT_END_CHAR, DBUS_TYPE_INVALID, DBusTypeReader::finished, DBusTypeReader::klass, DBusTypeReader::type_pos, and DBusTypeReader::type_str.

Referenced by _dbus_header_load(), _dbus_header_remove_unknown_fields(), _dbus_message_iter_get_args_valist(), _dbus_type_reader_get_element_type(), _dbus_type_reader_next(), _dbus_type_reader_read_basic(), _dbus_type_reader_set_basic(), dbus_message_iter_get_arg_type(), dbus_message_iter_get_element_count(), dbus_message_iter_get_fixed_array(), and dbus_message_iter_init().

## ◆ _dbus_type_reader_get_element_type()

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.

It's an error to call this if _dbus_type_reader_get_current_type() doesn't return DBUS_TYPE_ARRAY for this reader.

Parameters

  reader | the reader

Definition at line 821 of file dbus-marshal-recursive.c.

References _dbus_assert, _dbus_first_type_in_signature(), _dbus_type_reader_get_current_type(), DBUS_TYPE_ARRAY, DBusTypeReader::type_pos, and DBusTypeReader::type_str.

Referenced by _dbus_message_iter_get_args_valist(), dbus_message_iter_get_element_count(), and dbus_message_iter_get_element_type().

## ◆ _dbus_type_reader_get_signature()

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.

Essentially a more complete version of _dbus_type_reader_get_current_type() (returns the full type rather than only the outside of the onion).

Note though that the first byte in a struct signature is DBUS_STRUCT_BEGIN_CHAR while the current type will be DBUS_TYPE_STRUCT so it isn't true that the first byte of the signature is always the same as the current type. Another difference is that this function will still return a signature when inside an empty array; say you recurse into empty array of int32, the signature is "i" but the current type will always be DBUS_TYPE_INVALID since there are no elements to be currently pointing to.

Parameters

  reader | the reader
  str_p | place to return the string with the type in it
  start_p | place to return start of the type
  len_p | place to return the length of the type

Definition at line 1125 of file dbus-marshal-recursive.c.

References DBusTypeReader::type_pos, and DBusTypeReader::type_str.

Referenced by _dbus_variant_read(), and dbus_message_iter_get_signature().

## ◆ _dbus_type_reader_get_value_pos()

int _dbus_type_reader_get_value_pos | ( | const DBusTypeReader * | reader | ) |

Gets the current position in the value block.

Parameters

  reader | the reader

Definition at line 838 of file dbus-marshal-recursive.c.

References DBusTypeReader::value_pos.

Referenced by _dbus_header_load().

## ◆ _dbus_type_reader_has_next()

dbus_bool_t _dbus_type_reader_has_next | ( | const DBusTypeReader * | reader | ) |

Check whether there's another value on this "level".

e.g. the next field in a struct, the next value in an array. Returns FALSE at the end of the current container.

You probably don't want to use this; it makes for an awkward for/while loop. A nicer one is "while ((current_type = get_current_type()) != INVALID)"

Parameters

  reader | the reader

Returns
  FALSE if nothing more to read at or below this level

Definition at line 1094 of file dbus-marshal-recursive.c.

References _dbus_type_reader_next().

Referenced by dbus_message_iter_has_next().

## ◆ _dbus_type_reader_init()

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.

Parameters

  reader | the reader
  byte_order | the byte order of the block to read
  type_str | the signature of the block to read
  type_pos | location of signature
  value_str | the string containing values block
  value_pos | start of values block

Definition at line 733 of file dbus-marshal-recursive.c.

References DBusTypeReader::klass, DBusTypeReader::type_pos, DBusTypeReader::type_str, and DBusTypeReader::value_pos.

Referenced by _dbus_header_load(), _dbus_header_remove_unknown_fields(), _dbus_variant_write(), and dbus_message_iter_init().

## ◆ _dbus_type_reader_init_types_only()

void _dbus_type_reader_init_types_only | ( | DBusTypeReader * | reader,
|  | const DBusString * | type_str,
|  | int | type_pos
| ) |  |

Like _dbus_type_reader_init() but the iteration is over the signature, not over values.

Parameters

  reader | the reader
  type_str | the signature string
  type_pos | location in the signature string

Definition at line 761 of file dbus-marshal-recursive.c.

References _DBUS_INT_MAX, DBusTypeReader::klass, NULL, DBusTypeReader::type_pos, and DBusTypeReader::type_str.

Referenced by _dbus_marshal_byteswap(), and _dbus_validate_body_with_reason().

## ◆ _dbus_type_reader_next()

dbus_bool_t _dbus_type_reader_next | ( | DBusTypeReader * | reader | ) |

Skip to the next value on this "level".

e.g. the next field in a struct, the next value in an array. Returns FALSE at the end of the current container.

Parameters

  reader | the reader

Returns
  FALSE if nothing more to read at or below this level

Definition at line 1054 of file dbus-marshal-recursive.c.

References _dbus_type_reader_get_current_type(), _dbus_type_to_string(), DBUS_TYPE_INVALID, FALSE, DBusTypeReader::klass, DBusTypeReaderClass::next, DBusTypeReader::type_pos, DBusTypeReader::type_str, and DBusTypeReader::value_pos.

Referenced by _dbus_header_load(), _dbus_header_remove_unknown_fields(), _dbus_message_iter_get_args_valist(), _dbus_type_reader_has_next(), dbus_message_iter_get_element_count(), and dbus_message_iter_next().

## ◆ _dbus_type_reader_read_basic()

void _dbus_type_reader_read_basic | ( | const DBusTypeReader * | reader,
|  | void * | value
| ) |  |

Reads a basic-typed value, as with _dbus_marshal_read_basic().

Parameters

  reader | the reader
  value | the address of the value

Definition at line 870 of file dbus-marshal-recursive.c.

References _dbus_assert, _dbus_marshal_read_basic(), _dbus_type_reader_get_current_type(), DBusTypeReader::byte_order, DBusTypeReader::klass, NULL, DBusTypeReader::type_pos, DBusTypeReader::type_str, DBusTypeReaderClass::types_only, DBusTypeReader::value_pos, and DBusTypeReader::value_str.

Referenced by _dbus_header_load(), _dbus_header_remove_unknown_fields(), _dbus_message_iter_get_args_valist(), and dbus_message_iter_get_basic().

## ◆ _dbus_type_reader_read_fixed_multi()

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 array.

Does not work for arrays of string or container types.

This function returns the array in-place; it does not make a copy, and it does not swap the bytes.

If you ask for DBUS_TYPE_DOUBLE you will get a "const double*" back and the "value" argument should be a "const double**" and so on.

Parameters

  reader | the reader to read from
  value | place to return the array values
  n_elements | place to return number of array elements

Definition at line 924 of file dbus-marshal-recursive.c.

References _dbus_assert, _dbus_first_type_in_signature(), _dbus_type_get_alignment(), DBUS_TYPE_INVALID, dbus_type_is_fixed(), DBusTypeReader::klass, NULL, DBusTypeReader::start_pos, DBusTypeReader::type_pos, DBusTypeReader::type_str, DBusTypeReaderClass::types_only, DBusTypeReader::u, DBusTypeReader::value_pos, and DBusTypeReader::value_str.

Referenced by _dbus_message_iter_get_args_valist(), and dbus_message_iter_get_fixed_array().

## ◆ _dbus_type_reader_read_raw()

void _dbus_type_reader_read_raw | ( | const DBusTypeReader * | reader,
|  | const unsigned char ** | value_location
| ) |  |

Get the address of the marshaled value in the data being read.

The address may not be aligned; you have to align it to the type of the value you want to read. Most of the demarshal routines do this for you.

Parameters

  reader | the reader
  value_location | the address of the marshaled value

Definition at line 853 of file dbus-marshal-recursive.c.

References _dbus_assert, DBusTypeReader::klass, DBusTypeReaderClass::types_only, DBusTypeReader::value_pos, and DBusTypeReader::value_str.

## ◆ _dbus_type_reader_recurse()

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 current container.

It's an error to call this if the current type is a non-container.

Note that DBusTypeReader traverses values, not types. So if you have an empty array of array of int, you can't recurse into it. You can only recurse into each element.

Parameters

  reader | the reader
  sub | a reader to init pointing to the first child

Definition at line 988 of file dbus-marshal-recursive.c.

References _dbus_assert, _dbus_assert_not_reached, _dbus_first_type_in_signature(), _dbus_type_to_string(), _dbus_warn_check_failed(), DBUS_TYPE_ARRAY, DBUS_TYPE_DICT_ENTRY, DBUS_TYPE_INVALID, DBUS_TYPE_STRUCT, DBUS_TYPE_VARIANT, DBusTypeReaderClass::id, DBusTypeReader::klass, NULL, DBusTypeReaderClass::recurse, DBusTypeReader::type_pos, DBusTypeReader::type_str, DBusTypeReaderClass::types_only, and DBusTypeReader::value_pos.

Referenced by _dbus_header_load(), _dbus_header_remove_unknown_fields(), _dbus_message_iter_get_args_valist(), _dbus_variant_write(), dbus_message_iter_get_element_count(), and dbus_message_iter_recurse().

## ◆ _dbus_type_reader_set_basic()

dbus_bool_t _dbus_type_reader_set_basic | ( | DBusTypeReader * | reader,
|  | const void * | value,
|  | const DBusTypeReader * | realign_root
| ) |  |

Sets a new value for the basic type value pointed to by the reader, leaving the reader valid to continue reading.

Any other readers will be invalidated if you set a variable-length type such as a string.

The provided realign_root is the reader to start from when realigning the data that follows the newly-set value. The reader parameter must point to a value below the realign_root parameter. If the type being set is fixed-length, then realign_root may be NULL. Only values reachable from realign_root will be realigned, so if your string contains other values you will need to deal with those somehow yourself. It is OK if realign_root is the same reader as the reader parameter, though if you aren't setting the root it may not be such a good idea.

Parameters

  reader | reader indicating where to set a new value
  value | address of the value to set
  realign_root | realign from here

Returns
  FALSE if not enough memory

Definition at line 1363 of file dbus-marshal-recursive.c.

References _dbus_assert, _dbus_type_reader_get_current_type(), _dbus_type_to_string(), _dbus_verbose_bytes_of_string(), dbus_type_is_basic(), dbus_type_is_fixed(), DBusTypeReader::klass, NULL, TRUE, DBusTypeReader::type_pos, DBusTypeReader::type_str, DBusTypeReaderClass::types_only, DBusTypeReader::value_pos, and DBusTypeReader::value_str.

## ◆ _dbus_type_signature_next()

void _dbus_type_signature_next | ( | const char * | type_str,
|  | int * | type_pos
| ) |  |

Skips to the next "complete" type inside a type signature.

The signature is read starting at type_pos, and the next type position is stored in the same variable.

Parameters

  type_str | a type signature (must be valid)
  type_pos | an integer position in the type signature (in and out)

Definition at line 341 of file dbus-marshal-recursive.c.

References _dbus_assert, DBUS_DICT_ENTRY_BEGIN_CHAR, DBUS_DICT_ENTRY_END_CHAR, DBUS_STRUCT_BEGIN_CHAR, DBUS_STRUCT_END_CHAR, DBUS_TYPE_ARRAY, DBUS_TYPE_INVALID, NULL, and TRUE.

Referenced by dbus_signature_iter_get_signature(), and dbus_signature_iter_next().

## ◆ _dbus_type_to_string()

const char * _dbus_type_to_string | ( | int | typecode | ) |

Returns a string describing the given type.

Parameters

  typecode | the type to describe

Returns
  a constant string describing the type

Definition at line 1282 of file dbus-marshal-basic.c.

References DBUS_DICT_ENTRY_BEGIN_CHAR, DBUS_DICT_ENTRY_END_CHAR, DBUS_STRUCT_BEGIN_CHAR, DBUS_STRUCT_END_CHAR, DBUS_TYPE_ARRAY, DBUS_TYPE_BOOLEAN, DBUS_TYPE_BYTE, DBUS_TYPE_DICT_ENTRY, DBUS_TYPE_DOUBLE, DBUS_TYPE_INT16, DBUS_TYPE_INT32, DBUS_TYPE_INT64, DBUS_TYPE_INVALID, DBUS_TYPE_OBJECT_PATH, DBUS_TYPE_SIGNATURE, DBUS_TYPE_STRING, DBUS_TYPE_STRUCT, DBUS_TYPE_UINT16, DBUS_TYPE_UINT32, DBUS_TYPE_UINT64, DBUS_TYPE_UNIX_FD, and DBUS_TYPE_VARIANT.

Referenced by _dbus_marshal_read_basic(), _dbus_marshal_skip_basic(), _dbus_marshal_write_fixed_multi(), _dbus_message_iter_get_args_valist(), _dbus_type_reader_get_current_type(), _dbus_type_reader_next(), _dbus_type_reader_recurse(), _dbus_type_reader_set_basic(), _dbus_type_writer_unrecurse(), and dbus_message_append_args_valist().

## ◆ _dbus_type_writer_add_types()

void _dbus_type_writer_add_types | ( | DBusTypeWriter * | writer,
|  | DBusString * | type_str,
|  | int | type_pos
| ) |  |

Adds type string to the writer, if it had none.

Parameters

  writer | the writer to init
  type_str | type string to add
  type_pos | type position

Definition at line 1546 of file dbus-marshal-recursive.c.

References NULL, DBusTypeWriter::type_pos, and DBusTypeWriter::type_str.

## ◆ _dbus_type_writer_append_array()

dbus_bool_t _dbus_type_writer_append_array | ( | DBusTypeWriter * | writer,
|  | const DBusString * | contained_type,
|  | int | contained_type_start,
|  | DBusTypeWriter * | sub
| ) |  |

Append to an existing array.

Essentially, the writer will read an existing length at the write location; jump over that length; and write new fields. On unrecurse(), the existing length will be updated.

Parameters

  writer | the writer
  contained_type | element type
  contained_type_start | position of element type
  sub | the subwriter to init

Returns
  FALSE if no memory

Definition at line 2143 of file dbus-marshal-recursive.c.

References DBUS_TYPE_ARRAY, and TRUE.

Referenced by _dbus_header_set_field_basic().

## ◆ _dbus_type_writer_init()

void _dbus_type_writer_init | ( | DBusTypeWriter * | writer,
|  | int | byte_order,
|  | DBusString * | type_str,
|  | int | type_pos,
|  | DBusString * | value_str,
|  | int | value_pos
| ) |  |

Initialize a write iterator, which is used to write out values in serialized D-Bus format.

The type_pos passed in is expected to be inside an already-valid, though potentially empty, type signature. This means that the byte after type_pos must be either DBUS_TYPE_INVALID (aka nul) or some other valid type. DBusTypeWriter won't enforce that the signature is already valid (you can append the nul byte at the end if you like), but just be aware that you need the nul byte eventually and DBusTypeWriter isn't going to write it for you.

Parameters

  writer | the writer to init
  byte_order | the byte order to marshal into
  type_str | the string to write typecodes into
  type_pos | where to insert typecodes
  value_str | the string to write values into
  value_pos | where to insert values

Definition at line 1493 of file dbus-marshal-recursive.c.

References DBusTypeWriter::byte_order, DBusTypeWriter::container_type, DBUS_TYPE_INVALID, DBusTypeWriter::enabled, FALSE, TRUE, DBusTypeWriter::type_pos, DBusTypeWriter::type_pos_is_expectation, DBusTypeWriter::type_str, DBusTypeWriter::value_pos, and DBusTypeWriter::value_str.

Referenced by _dbus_type_writer_init_types_delayed(), and _dbus_type_writer_init_values_only().

## ◆ _dbus_type_writer_init_types_delayed()

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.

Parameters

  writer | the writer to init
  byte_order | the byte order to marshal into
  value_str | the string to write values into
  value_pos | where to insert values

Definition at line 1528 of file dbus-marshal-recursive.c.

References _dbus_type_writer_init(), and NULL.

Referenced by dbus_message_iter_init_append().

## ◆ _dbus_type_writer_init_values_only()

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 signature that matches what you're going to write out.

The writer will check what you write vs. this existing signature.

Parameters

  writer | the writer to init
  byte_order | the byte order to marshal into
  type_str | the string with signature
  type_pos | start of signature
  value_str | the string to write values into
  value_pos | where to insert values

Definition at line 1584 of file dbus-marshal-recursive.c.

References _dbus_type_writer_init(), TRUE, and DBusTypeWriter::type_pos_is_expectation.

Referenced by _dbus_header_create(), _dbus_header_set_field_basic(), and _dbus_variant_read().

## ◆ _dbus_type_writer_recurse()

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.

Parameters

  writer | the writer
  container_type | the type of the container to open
  contained_type | the array element type or variant content type
  contained_type_start | position to look for the type
  sub | the new sub-writer to write container contents

Returns
  FALSE if no memory

Definition at line 2109 of file dbus-marshal-recursive.c.

References FALSE.

Referenced by _dbus_header_create(), _dbus_variant_read(), and dbus_message_iter_open_container().

## ◆ _dbus_type_writer_remove_types()

void _dbus_type_writer_remove_types | ( | DBusTypeWriter * | writer | ) |

Removes type string from the writer.

Parameters

  writer | the writer to remove from

Definition at line 1563 of file dbus-marshal-recursive.c.

References NULL, DBusTypeWriter::type_pos, and DBusTypeWriter::type_str.

## ◆ _dbus_type_writer_unrecurse()

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 the values block.

Parameters

  writer | the writer
  sub | the sub-writer created by _dbus_type_writer_recurse()

Returns
  FALSE if no memory

Definition at line 2179 of file dbus-marshal-recursive.c.

References _dbus_assert, _dbus_marshal_set_uint32(), _dbus_type_to_string(), DBusTypeWriter::byte_order, DBusTypeWriter::container_type, DBUS_DICT_ENTRY_END_CHAR, DBUS_STRUCT_END_CHAR, DBUS_TYPE_ARRAY, DBUS_TYPE_DICT_ENTRY, DBUS_TYPE_INVALID, DBUS_TYPE_STRUCT, FALSE, DBusTypeWriter::len_pos, NULL, TRUE, DBusTypeWriter::type_pos, DBusTypeWriter::type_pos_is_expectation, DBusTypeWriter::type_str, DBusTypeWriter::u, DBusTypeWriter::value_pos, and DBusTypeWriter::value_str.

Referenced by _dbus_header_create(), _dbus_header_set_field_basic(), _dbus_variant_read(), and dbus_message_iter_close_container().

## ◆ _dbus_type_writer_write_basic()

dbus_bool_t _dbus_type_writer_write_basic | ( | DBusTypeWriter * | writer,
|  | int | type,
|  | const void * | value
| ) |  |

Writes out a basic type.

Parameters

  writer | the writer
  type | the type to write
  value | the address of the value to write

Returns
  FALSE if no memory

Definition at line 2311 of file dbus-marshal-recursive.c.

References _dbus_assert_not_reached, _dbus_string_alloc_space(), DBusTypeWriter::enabled, FALSE, NULL, TRUE, DBusTypeWriter::type_pos, DBusTypeWriter::type_pos_is_expectation, DBusTypeWriter::type_str, and DBusTypeWriter::value_pos.

Referenced by _dbus_header_create(), _dbus_variant_read(), and dbus_message_iter_append_basic().

## ◆ _dbus_type_writer_write_fixed_multi()

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.

those that are both dbus_type_is_fixed() and _dbus_type_is_basic(). The block must be written inside an array.

The value parameter should be the address of said array of values, so e.g. if it's an array of double, pass in "const double**"

Parameters

  writer | the writer
  element_type | type of stuff in the array
  value | address of the array
  n_elements | number of elements in the array

Returns
  FALSE if no memory

Definition at line 2359 of file dbus-marshal-recursive.c.

References _dbus_assert, _dbus_assert_not_reached, _dbus_marshal_write_fixed_multi(), DBusTypeWriter::byte_order, DBusTypeWriter::container_type, DBUS_TYPE_ARRAY, dbus_type_is_fixed(), DBusTypeWriter::enabled, FALSE, TRUE, DBusTypeWriter::type_pos, DBusTypeWriter::type_pos_is_expectation, DBusTypeWriter::value_pos, and DBusTypeWriter::value_str.

Referenced by dbus_message_iter_append_fixed_array().

## ◆ _dbus_type_writer_write_reader()

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.

The reader will be moved forward to its end position.

Parameters

  writer | the writer to copy to
  reader | the reader to copy from

Returns
  FALSE if no memory

Definition at line 2731 of file dbus-marshal-recursive.c.

References NULL.

Referenced by _dbus_variant_read(), and _dbus_variant_write().

## ◆ _dbus_unpack_uint16()

dbus_uint16_t _dbus_unpack_uint16 | ( | int | byte_order,
|  | const unsigned char * | data
| ) |  |

Unpacks a 16 bit unsigned integer from a data pointer.

Parameters

  byte_order | The byte order to use
  data | the data pointer

Returns
  the integer

Definition at line 179 of file dbus-marshal-basic.c.

References _dbus_assert, and DBUS_LITTLE_ENDIAN.

## ◆ _dbus_unpack_uint32()

dbus_uint32_t _dbus_unpack_uint32 | ( | int | byte_order,
|  | const unsigned char * | data
| ) |  |

Unpacks a 32 bit unsigned integer from a data pointer.

Parameters

  byte_order | The byte order to use
  data | the data pointer

Returns
  the integer

Definition at line 200 of file dbus-marshal-basic.c.

References _dbus_assert, and DBUS_LITTLE_ENDIAN.

Referenced by _dbus_marshal_read_uint32(), and _dbus_verbose_bytes().

## ◆ _dbus_validate_body_with_reason()

DBUS_PRIVATE_EXPORT 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 expected_signature.

If this function returns TRUE, it will be safe to iterate over the values with DBusTypeReader. The signature is assumed to be already valid.

If bytes_remaining is not NULL, then leftover bytes will be stored there and DBUS_VALID returned. If it is NULL, then DBUS_INVALID_TOO_MUCH_DATA will be returned if bytes are left over.

Parameters

  expected_signature | the expected types in the value_str
  expected_signature_start | where in expected_signature is the signature
  byte_order | the byte order
  bytes_remaining | place to store leftover bytes
  value_str | the string containing the body
  value_pos | where the values start
  len | length of values after value_pos

Returns
  DBUS_VALID if valid, reason why invalid otherwise

Definition at line 755 of file dbus-marshal-validate.c.

References _dbus_assert, _dbus_type_reader_init_types_only(), DBUS_INVALID_TOO_MUCH_DATA, DBUS_VALID, and TRUE.

Referenced by _dbus_header_load().

## ◆ _dbus_validate_bus_name()

DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_validate_bus_name | ( | const DBusString * | str,
|  | int | start,
|  | int | len
| ) |  |

Checks that the given range of the string is a valid bus name in the D-Bus protocol.

This includes a length restriction, etc., see the specification.

Parameters

  str | the string
  start | first byte index to check
  len | number of bytes to check

Returns
  TRUE if the byte range exists and is a valid name

Definition at line 1241 of file dbus-marshal-validate.c.

References FALSE.

Referenced by dbus_validate_bus_name().

## ◆ _dbus_validate_bus_namespace()

DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_validate_bus_namespace | ( | const DBusString * | str,
|  | int | start,
|  | int | len
| ) |  |

Checks that the given range of the string is a prefix of a valid bus name in the D-Bus protocol.

Unlike _dbus_validate_bus_name(), this accepts strings with only one period-separated component.

Parameters

  str | the string
  start | first byte index to check
  len | number of bytes to check

Returns
  TRUE if the byte range exists and is a valid name

Definition at line 1262 of file dbus-marshal-validate.c.

References TRUE.

## ◆ _dbus_validate_error_name()

DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_validate_error_name | ( | const DBusString * | str,
|  | int | start,
|  | int | len
| ) |  |

Checks that the given range of the string is a valid error name in the D-Bus protocol.

This includes a length restriction, etc., see the specification.

Parameters

  str | the string
  start | first byte index to check
  len | number of bytes to check

Returns
  TRUE if the byte range exists and is a valid name

Definition at line 1112 of file dbus-marshal-validate.c.

References _dbus_validate_interface().

Referenced by dbus_validate_error_name().

## ◆ _dbus_validate_interface()

DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_validate_interface | ( | const DBusString * | str,
|  | int | start,
|  | int | len
| ) |  |

Checks that the given range of the string is a valid interface name in the D-Bus protocol.

This includes a length restriction and an ASCII subset, see the specification.

Parameters

  str | the string
  start | first byte index to check
  len | number of bytes to check

Returns
  TRUE if the byte range exists and is a valid name

Definition at line 975 of file dbus-marshal-validate.c.

References _dbus_assert, DBUS_MAXIMUM_NAME_LENGTH, FALSE, NULL, TRUE, VALID_INITIAL_NAME_CHARACTER, and VALID_NAME_CHARACTER.

Referenced by _dbus_validate_error_name(), and dbus_validate_interface().

## ◆ _dbus_validate_member()

DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_validate_member | ( | const DBusString * | str,
|  | int | start,
|  | int | len
| ) |  |

Checks that the given range of the string is a valid member name in the D-Bus protocol.

This includes a length restriction, etc., see the specification.

Parameters

  str | the string
  start | first byte index to check
  len | number of bytes to check

Returns
  TRUE if the byte range exists and is a valid name

Definition at line 1051 of file dbus-marshal-validate.c.

References _dbus_assert, DBUS_MAXIMUM_NAME_LENGTH, FALSE, TRUE, VALID_INITIAL_NAME_CHARACTER, and VALID_NAME_CHARACTER.

Referenced by dbus_validate_member().

## ◆ _dbus_validate_path()

DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_validate_path | ( | const DBusString * | str,
|  | int | start,
|  | int | len
| ) |  |

Checks that the given range of the string is a valid object path name in the D-Bus protocol.

Part of the validation ensures that the object path contains only ASCII.

Parameters

  str | the string
  start | first byte index to check
  len | number of bytes to check

Returns
  TRUE if the byte range exists and is a valid name

Definition at line 837 of file dbus-marshal-validate.c.

References _dbus_assert, FALSE, TRUE, and VALID_NAME_CHARACTER.

Referenced by dbus_validate_path().

## ◆ _dbus_validate_signature_with_reason()

DBUS_PRIVATE_EXPORT 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.

If this function returns TRUE, it will be safe to iterate over the signature with a types-only DBusTypeReader. The range passed in should NOT include the terminating nul/DBUS_TYPE_INVALID.

Parameters

  type_str | the string
  type_pos | where the typecodes start
  len | length of typecodes

Returns
  DBUS_VALID if valid, reason why invalid otherwise

Definition at line 51 of file dbus-marshal-validate.c.

References _dbus_assert, _DBUS_INT32_MAX, _DBUS_INT_TO_POINTER, _dbus_list_append(), _dbus_list_clear(), _dbus_list_pop_last(), _DBUS_N_ELEMENTS, _DBUS_POINTER_TO_INT, DBUS_DICT_ENTRY_BEGIN_CHAR, DBUS_DICT_ENTRY_END_CHAR, DBUS_MAXIMUM_SIGNATURE_LENGTH, DBUS_MAXIMUM_TYPE_RECURSION_DEPTH, DBUS_STRUCT_BEGIN_CHAR, DBUS_STRUCT_END_CHAR, DBUS_TYPE_ARRAY, DBUS_TYPE_BOOLEAN, DBUS_TYPE_BYTE, DBUS_TYPE_DICT_ENTRY, DBUS_TYPE_DOUBLE, DBUS_TYPE_INT16, DBUS_TYPE_INT32, DBUS_TYPE_INT64, DBUS_TYPE_INVALID, dbus_type_is_basic(), dbus_type_is_valid(), DBUS_TYPE_OBJECT_PATH, DBUS_TYPE_SIGNATURE, DBUS_TYPE_STRING, DBUS_TYPE_STRUCT, DBUS_TYPE_UINT16, DBUS_TYPE_UINT32, DBUS_TYPE_UINT64, DBUS_TYPE_UNIX_FD, DBUS_TYPE_VARIANT, DBUS_VALID, DBUS_VALIDITY_UNKNOWN_OOM_ERROR, and NULL.

Referenced by dbus_message_iter_append_basic(), dbus_message_iter_open_container(), and dbus_signature_validate().

## ◆ _dbus_validity_to_error_message()

const char * _dbus_validity_to_error_message | ( | DBusValidity | validity | ) |

Definition at line 889 of file dbus-marshal-validate.c.

## ◆ _dbus_verbose_bytes()

void _dbus_verbose_bytes | ( | const unsigned char * | data,
|  | int | len,
|  | int | offset
| ) |  |

If in verbose mode, print a block of binary data.

Parameters

  data | the data
  len | the length of the data
  offset | where to start counting for byte indexes

Definition at line 1343 of file dbus-marshal-basic.c.

References _dbus_assert, _dbus_unpack_uint32(), DBUS_BIG_ENDIAN, and DBUS_LITTLE_ENDIAN.

Referenced by _dbus_verbose_bytes_of_string().

## ◆ _dbus_verbose_bytes_of_string()

void _dbus_verbose_bytes_of_string | ( | const DBusString * | str,
|  | int | start,
|  | int | len
| ) |  |

Dump the given part of the string to verbose log.

Parameters

  str | the string
  start | the start of range to dump
  len | length of range

Definition at line 1421 of file dbus-marshal-basic.c.

References _dbus_assert, and _dbus_verbose_bytes().

Referenced by _dbus_read(), _dbus_read_socket(), _dbus_read_socket_with_unix_fds(), _dbus_type_reader_set_basic(), _dbus_write(), and _dbus_write_socket().