Type signature parsing
[D-Bus low-level public API]

Parsing D-Bus type signatures. More...

Defines

#define TYPE_IS_CONTAINER(typecode)
 macro that checks whether a typecode is a container type

Functions

void dbus_signature_iter_init (DBusSignatureIter *iter, const char *signature)
 Initializes a DBusSignatureIter for reading a type signature.
int dbus_signature_iter_get_current_type (const DBusSignatureIter *iter)
 Returns the current type pointed to by the iterator.
char * dbus_signature_iter_get_signature (const DBusSignatureIter *iter)
 Returns the full type signature represented by the current iterator as a C string.
int dbus_signature_iter_get_element_type (const DBusSignatureIter *iter)
 Convenience function for returning the element type of an array; This function allows you to avoid initializing a sub-iterator and getting its current type.
dbus_bool_t dbus_signature_iter_next (DBusSignatureIter *iter)
 Skip to the next value on this "level".
void dbus_signature_iter_recurse (const DBusSignatureIter *iter, DBusSignatureIter *subiter)
 Initialize a new iterator pointing to the first type current container.
dbus_bool_t dbus_signature_validate (const char *signature, DBusError *error)
 Check a type signature for validity.
dbus_bool_t dbus_signature_validate_single (const char *signature, DBusError *error)
 Check that a type signature is both valid and contains exactly one complete type.
dbus_bool_t dbus_type_is_container (int typecode)
 A "container type" can contain basic types, or nested container types.
dbus_bool_t dbus_type_is_basic (int typecode)
 A "basic type" is a somewhat arbitrary concept, but the intent is to include those types that are fully-specified by a single typecode, with no additional type information or nested values.
dbus_bool_t dbus_type_is_fixed (int typecode)
 Tells you whether values of this type can change length if you set them to some other value.

Detailed Description

Parsing D-Bus type signatures.


Define Documentation

#define TYPE_IS_CONTAINER ( typecode   ) 

Value:

((typecode) == DBUS_TYPE_STRUCT ||          \
     (typecode) == DBUS_TYPE_DICT_ENTRY ||      \
     (typecode) == DBUS_TYPE_VARIANT ||         \
     (typecode) == DBUS_TYPE_ARRAY)
macro that checks whether a typecode is a container type

Definition at line 251 of file dbus-signature.c.

Referenced by dbus_type_is_basic(), and dbus_type_is_container().


Function Documentation

int dbus_signature_iter_get_current_type ( const DBusSignatureIter iter  ) 

Returns the current type pointed to by the iterator.

If the iterator is pointing at a type code such as 's', then it will be returned directly.

However, when the parser encounters a container type start character such as '(' for a structure, the corresponding type for the container will be returned, e.g. DBUS_TYPE_STRUCT, not '('. In this case, you should initialize a sub-iterator with dbus_signature_iter_recurse to parse the container type.

Parameters:
iter pointer to an iterator
Returns:
current type (e.g. DBUS_TYPE_STRING, DBUS_TYPE_ARRAY)

Definition at line 79 of file dbus-signature.c.

References _dbus_first_type_in_signature_c_str(), and DBusSignatureRealIter::pos.

Referenced by dbus_signature_iter_get_element_type(), dbus_signature_iter_recurse(), and dbus_signature_validate_single().

int dbus_signature_iter_get_element_type ( const DBusSignatureIter iter  ) 

Convenience function for returning the element type of an array; This function allows you to avoid initializing a sub-iterator and getting its current type.

It is an error to invoke this function if the current type of the iterator is not DBUS_TYPE_ARRAY.

Parameters:
iter pointer to an iterator
Returns:
current array element type

Definition at line 128 of file dbus-signature.c.

References _dbus_first_type_in_signature_c_str(), dbus_signature_iter_get_current_type(), DBUS_TYPE_ARRAY, DBUS_TYPE_INVALID, and DBusSignatureRealIter::pos.

char* dbus_signature_iter_get_signature ( const DBusSignatureIter iter  ) 

Returns the full type signature represented by the current iterator as a C string.

Parameters:
iter pointer to an iterator
Returns:
current signature; or NULL on OOM. Should be freed with dbus_free

Definition at line 94 of file dbus-signature.c.

References _dbus_string_append_len(), _dbus_string_free(), _dbus_string_init(), _dbus_string_steal_data(), _dbus_type_signature_next(), NULL, and DBusSignatureRealIter::pos.

void dbus_signature_iter_init ( DBusSignatureIter iter,
const char *  signature 
)

Initializes a DBusSignatureIter for reading a type signature.

This function is not safe to use on invalid signatures; be sure to validate potentially invalid signatures with dbus_signature_validate before using this function.

Parameters:
iter pointer to an iterator to initialize
signature the type signature

Definition at line 54 of file dbus-signature.c.

References FALSE, DBusSignatureRealIter::finished, DBusSignatureRealIter::in_array, and DBusSignatureRealIter::pos.

Referenced by dbus_signature_validate_single().

dbus_bool_t dbus_signature_iter_next ( DBusSignatureIter iter  ) 

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:
iter the iterator
Returns:
FALSE if nothing more to read at or below this level

Definition at line 146 of file dbus-signature.c.

References _dbus_type_signature_next(), DBUS_DICT_ENTRY_END_CHAR, DBUS_STRUCT_END_CHAR, DBUS_TYPE_INVALID, FALSE, DBusSignatureRealIter::finished, DBusSignatureRealIter::in_array, DBusSignatureRealIter::pos, and TRUE.

Referenced by dbus_signature_validate_single().

void dbus_signature_iter_recurse ( const DBusSignatureIter iter,
DBusSignatureIter subiter 
)

Initialize a new iterator pointing to the first type current container.

It's an error to call this if the current type is a non-container (i.e. if dbus_type_is_container returns FALSE).

Parameters:
iter the current interator
subiter an iterator to initialize pointing to the first child

Definition at line 186 of file dbus-signature.c.

References dbus_signature_iter_get_current_type(), DBUS_TYPE_ARRAY, dbus_type_is_container(), FALSE, DBusSignatureRealIter::in_array, DBusSignatureRealIter::pos, and TRUE.

dbus_bool_t dbus_signature_validate ( const char *  signature,
DBusError error 
)

Check a type signature for validity.

Parameters:
signature a potentially invalid type signature
error error return
Returns:
TRUE iif signature is valid

Definition at line 210 of file dbus-signature.c.

References _dbus_string_init_const(), _dbus_validate_signature(), DBUS_ERROR_INVALID_SIGNATURE, dbus_set_error(), FALSE, and TRUE.

Referenced by dbus_signature_validate_single().

dbus_bool_t dbus_signature_validate_single ( const char *  signature,
DBusError error 
)

Check that a type signature is both valid and contains exactly one complete type.

Parameters:
signature a potentially invalid type signature
error error return
Returns:
TRUE iif signature is valid and has exactly one complete type

Definition at line 232 of file dbus-signature.c.

References DBUS_ERROR_INVALID_SIGNATURE, dbus_set_error(), dbus_signature_iter_get_current_type(), dbus_signature_iter_init(), dbus_signature_iter_next(), dbus_signature_validate(), DBUS_TYPE_INVALID, FALSE, and TRUE.

dbus_bool_t dbus_type_is_basic ( int  typecode  ) 

A "basic type" is a somewhat arbitrary concept, but the intent is to include those types that are fully-specified by a single typecode, with no additional type information or nested values.

So all numbers and strings are basic types and structs, arrays, and variants are not basic types. DBUS_TYPE_INVALID is not a basic type.

This function will crash if passed a typecode that isn't in dbus-protocol.h

Returns:
TRUE if type is basic

Definition at line 288 of file dbus-signature.c.

References _dbus_type_is_valid(), DBUS_TYPE_INVALID, FALSE, and TYPE_IS_CONTAINER.

Referenced by _dbus_marshal_read_basic(), _dbus_marshal_write_basic(), _dbus_message_iter_get_args_valist(), _dbus_type_reader_set_basic(), _dbus_validate_signature_with_reason(), dbus_message_append_args_valist(), and dbus_message_iter_append_basic().

dbus_bool_t dbus_type_is_container ( int  typecode  ) 

A "container type" can contain basic types, or nested container types.

DBUS_TYPE_INVALID is not a container type. This function will crash if passed a typecode that isn't in dbus-protocol.h

Returns:
TRUE if type is a container

Definition at line 266 of file dbus-signature.c.

References _dbus_type_is_valid(), DBUS_TYPE_INVALID, FALSE, and TYPE_IS_CONTAINER.

Referenced by dbus_message_iter_open_container(), and dbus_signature_iter_recurse().

dbus_bool_t dbus_type_is_fixed ( int  typecode  ) 

Tells you whether values of this type can change length if you set them to some other value.

For this purpose, you assume that the first byte of the old and new value would be in the same location, so alignment padding is not a factor.

This function is useful to determine whether dbus_message_iter_get_fixed_array may be used.

Returns:
FALSE if the type can occupy different lengths

Definition at line 310 of file dbus-signature.c.

References DBUS_TYPE_BOOLEAN, DBUS_TYPE_BYTE, DBUS_TYPE_DOUBLE, DBUS_TYPE_INT16, DBUS_TYPE_INT32, DBUS_TYPE_INT64, DBUS_TYPE_UINT16, DBUS_TYPE_UINT32, DBUS_TYPE_UINT64, FALSE, and TRUE.

Referenced by _dbus_marshal_write_fixed_multi(), _dbus_message_iter_get_args_valist(), _dbus_type_reader_read_fixed_multi(), _dbus_type_reader_set_basic(), _dbus_type_writer_write_fixed_multi(), dbus_message_append_args_valist(), dbus_message_iter_append_fixed_array(), and dbus_message_iter_get_fixed_array().


Generated on Fri Oct 20 11:46:26 2006 for D-Bus by  doxygen 1.4.7