sync busted marshaling work in progress

This commit is contained in:
Havoc Pennington 2004-12-28 04:55:52 +00:00
parent a11bbc91a7
commit 7debfd9ff5
5 changed files with 1108 additions and 158 deletions

View file

@ -743,13 +743,25 @@ marshal_8_octets_array (DBusString *str,
{
int old_string_len;
int array_start;
old_string_len = _dbus_string_get_length (str);
/* The array length is the length in bytes of the array,
* *excluding* alignment padding.
*/
if (!_dbus_marshal_uint32 (str, byte_order, len * 8))
goto error;
array_start = _dbus_string_get_length (str);
/* Note that we do alignment padding unconditionally
* even if the array is empty; this means that
* padding + len is always equal to the number of bytes
* in the array.
*/
if (!_dbus_string_align_length (str, 8))
goto error;
if (!_dbus_string_append_len (str, (const unsigned char*) value,
len * 8))
@ -1350,6 +1362,9 @@ demarshal_8_octets_array (const DBusString *str,
int byte_len;
byte_len = _dbus_demarshal_uint32 (str, byte_order, pos, &pos);
pos = _DBUS_ALIGN_VALUE (pos, 8);
len = byte_len / 8;
if (len == 0)
@ -1827,6 +1842,8 @@ _dbus_marshal_skip_array (const DBusString *str,
len = _dbus_demarshal_uint32 (str, byte_order, *pos, pos);
/* FIXME we need to insert alignment padding according to array type */
*pos += len;
}
@ -1897,8 +1914,9 @@ _dbus_marshal_get_arg_end_pos (const DBusString *str,
/* Demarshal the length */
len = _dbus_demarshal_uint32 (str, byte_order, pos, &pos);
*end_pos = pos + len;
/* FIXME needs to align to the right boundary for the array type */
*end_pos = _DBUS_ALIGN_VALUE (pos, 4) + len;
}
break;
@ -2428,9 +2446,11 @@ _dbus_type_is_valid (int typecode)
case DBUS_TYPE_UINT64:
case DBUS_TYPE_DOUBLE:
case DBUS_TYPE_STRING:
case DBUS_TYPE_OBJECT_PATH:
case DBUS_TYPE_ARRAY:
case DBUS_TYPE_DICT:
case DBUS_TYPE_OBJECT_PATH:
case DBUS_TYPE_STRUCT:
case DBUS_TYPE_VARIANT:
return TRUE;
default:
@ -2438,6 +2458,47 @@ _dbus_type_is_valid (int typecode)
}
}
/**
* Gets the alignment requirement for the given type;
* will be 1, 4, or 8.
*
* @param typecode the type
* @returns alignment of 1, 4, or 8
*/
int
_dbus_type_get_alignment (int typecode)
{
switch (typecode)
{
case DBUS_TYPE_BYTE:
case DBUS_TYPE_BOOLEAN:
return 1;
case DBUS_TYPE_INT32:
case DBUS_TYPE_UINT32:
/* this stuff is 4 since it starts with a length */
case DBUS_TYPE_STRING:
case DBUS_TYPE_OBJECT_PATH:
case DBUS_TYPE_ARRAY:
case DBUS_TYPE_DICT:
case DBUS_TYPE_VARIANT:
return 4;
case DBUS_TYPE_INT64:
case DBUS_TYPE_UINT64:
case DBUS_TYPE_DOUBLE:
/* struct is 8 since it could contain an 8-aligned item
* and it's simpler to just always align structs to 8;
* we want the amount of padding in a struct of a given
* type to be predictable, not location-dependent.
*/
case DBUS_TYPE_STRUCT:
return 8;
default:
_dbus_assert_not_reached ("unknown typecode in _dbus_type_get_alignment()");
return 0;
}
}
/**
* If in verbose mode, print a block of binary data.
*
@ -2445,10 +2506,12 @@ _dbus_type_is_valid (int typecode)
*
* @param data the data
* @param len the length of the data
* @param offset where to start counting for byte indexes
*/
void
_dbus_verbose_bytes (const unsigned char *data,
int len)
int len,
int offset)
{
int i;
const unsigned char *aligned;
@ -2478,7 +2541,7 @@ _dbus_verbose_bytes (const unsigned char *data,
if (_DBUS_ALIGN_ADDRESS (&data[i], 4) == &data[i])
{
_dbus_verbose ("%4d\t%p: ",
i, &data[i]);
offset + i, &data[i]);
}
if (data[i] >= 32 &&
@ -2546,7 +2609,7 @@ _dbus_verbose_bytes_of_string (const DBusString *str,
d = _dbus_string_get_const_data_len (str, start, len);
_dbus_verbose_bytes (d, len);
_dbus_verbose_bytes (d, len, start);
}
/**

View file

@ -53,38 +53,55 @@
#undef DBUS_TYPE_STRUCT
#undef DBUS_NUMBER_OF_TYPES
/* Never a legitimate type */
#define DBUS_TYPE_INVALID ((int) '\0')
#define DBUS_TYPE_INVALID_AS_STRING "\0"
/* Primitive types */
#define DBUS_TYPE_BYTE ((int) 'y')
#define DBUS_TYPE_BYTE_AS_STRING "y"
#define DBUS_TYPE_BOOLEAN ((int) 'b')
#define DBUS_TYPE_BOOLEAN_AS_STRING "b"
#define DBUS_TYPE_INT32 ((int) 'i')
#define DBUS_TYPE_INT32_AS_STRING "i"
#define DBUS_TYPE_UINT32 ((int) 'u')
#define DBUS_TYPE_UINT32_AS_STRING "u"
#define DBUS_TYPE_INT64 ((int) 'x')
#define DBUS_TYPE_INT64_AS_STRING "x"
#define DBUS_TYPE_UINT64 ((int) 't')
#define DBUS_TYPE_UINT64_AS_STRING "t"
#define DBUS_TYPE_DOUBLE ((int) 'd')
#define DBUS_TYPE_DOUBLE_AS_STRING "d"
#define DBUS_TYPE_STRING ((int) 's')
#define DBUS_TYPE_STRING_AS_STRING "s"
#define DBUS_TYPE_OBJECT_PATH ((int) 'o')
#define DBUS_TYPE_OBJECT_PATH_AS_STRING "o"
/* Compound types */
#define DBUS_TYPE_ARRAY ((int) 'a')
#define DBUS_TYPE_DICT ((int) 'm')
#define DBUS_TYPE_ARRAY_AS_STRING "a"
#define DBUS_TYPE_DICT ((int) 'm') /* not parameterized; always map<string,variant> */
#define DBUS_TYPE_DICT_AS_STRING "m"
#define DBUS_TYPE_VARIANT ((int) 'v')
#define DBUS_TYPE_VARIANT_AS_STRING "v"
/* STRUCT is sort of special since its code can't appear in a type string,
* instead DBUS_STRUCT_BEGIN_CHAR has to appear
*/
#define DBUS_TYPE_STRUCT ((int) 'r')
#define DBUS_TYPE_STRUCT_AS_STRING "r"
/* Does not count INVALID */
#define DBUS_NUMBER_OF_TYPES (13)
/* characters other than typecodes that appear in type signatures */
#define DBUS_STRUCT_BEGIN_CHAR ((int) '(')
#define DBUS_STRUCT_BEGIN_CHAR_AS_STRING "("
#define DBUS_STRUCT_END_CHAR ((int) ')')
#define DBUS_STRUCT_END_CHAR_AS_STRING ")"
static const char *
_hack_dbus_type_to_string (int type)
@ -442,4 +459,6 @@ dbus_bool_t _dbus_marshal_validate_arg (const DBusString *str,
dbus_bool_t _dbus_type_is_valid (int typecode);
int _dbus_type_get_alignment (int typecode);
#endif /* DBUS_MARSHAL_H */

File diff suppressed because it is too large Load diff

View file

@ -56,6 +56,26 @@ struct DBusTypeReader
int type_pos;
const DBusString *value_str;
int value_pos;
/* Hmm - it might be cleaner to do TypeReaderClass *vtable for container type */
int container_type;
union
{
struct {
int start_pos;
dbus_uint32_t len;
int element_type;
} array;
struct {
int len_pos;
} dict;
struct {
dbus_uint32_t finished : 1;
} strct;
} u;
};
typedef struct DBusTypeReader DBusTypeReader;
@ -67,7 +87,23 @@ struct DBusTypeWriter
int type_pos;
DBusString *value_str;
int value_pos;
dbus_uint32_t inside_array : 1;
int container_type;
union
{
struct {
int start_pos; /* first element */
int len_pos;
char *element_type;
} array;
struct {
int len_pos;
} dict;
} u;
};
typedef struct DBusTypeWriter DBusTypeWriter;
@ -79,7 +115,7 @@ void _dbus_type_reader_init (DBusTypeReader *reader,
const DBusString *value_str,
int value_pos);
int _dbus_type_reader_get_current_type (DBusTypeReader *reader);
int _dbus_type_reader_get_array_type (DBusTypeReader *reader);
int _dbus_type_reader_get_array_length (DBusTypeReader *reader);
void _dbus_type_reader_read_basic (DBusTypeReader *reader,
void *value);
dbus_bool_t _dbus_type_reader_read_array_of_basic (DBusTypeReader *reader,
@ -90,23 +126,27 @@ void _dbus_type_reader_recurse (DBusTypeReader *reader,
DBusTypeReader *subreader);
dbus_bool_t _dbus_type_reader_next (DBusTypeReader *reader);
void _dbus_type_writer_init (DBusTypeWriter *writer,
int byte_order,
DBusString *type_str,
int type_pos,
DBusString *value_str,
int value_pos);
dbus_bool_t _dbus_type_writer_write_basic (DBusTypeWriter *writer,
int type,
const void *value);
dbus_bool_t _dbus_type_writer_write_array (DBusTypeWriter *writer,
int type,
const void *array,
int array_len);
dbus_bool_t _dbus_type_writer_recurse (DBusTypeWriter *writer,
int container_type,
DBusTypeWriter *sub);
dbus_bool_t _dbus_type_writer_unrecurse (DBusTypeWriter *writer,
DBusTypeWriter *sub);
void _dbus_type_writer_init (DBusTypeWriter *writer,
int byte_order,
DBusString *type_str,
int type_pos,
DBusString *value_str,
int value_pos);
dbus_bool_t _dbus_type_writer_write_basic (DBusTypeWriter *writer,
int type,
const void *value);
dbus_bool_t _dbus_type_writer_write_array (DBusTypeWriter *writer,
int type,
const void *array,
int array_len);
dbus_bool_t _dbus_type_writer_recurse (DBusTypeWriter *writer,
int container_type,
DBusTypeWriter *sub);
dbus_bool_t _dbus_type_writer_recurse_array (DBusTypeWriter *writer,
const char *element_type,
DBusTypeWriter *sub);
dbus_bool_t _dbus_type_writer_unrecurse (DBusTypeWriter *writer,
DBusTypeWriter *sub);
#endif /* DBUS_MARSHAL_RECURSIVE_H */

View file

@ -42,36 +42,52 @@ extern "C" {
/* Never a legitimate type */
#define DBUS_TYPE_INVALID ((int) '\0')
#define DBUS_TYPE_INVALID_AS_STRING "\0"
/* Primitive types */
#define DBUS_TYPE_BYTE ((int) 'y')
#define DBUS_TYPE_BYTE_AS_STRING "y"
#define DBUS_TYPE_BOOLEAN ((int) 'b')
#define DBUS_TYPE_BOOLEAN_AS_STRING "b"
#define DBUS_TYPE_INT32 ((int) 'i')
#define DBUS_TYPE_INT32_AS_STRING "i"
#define DBUS_TYPE_UINT32 ((int) 'u')
#define DBUS_TYPE_UINT32_AS_STRING "u"
#define DBUS_TYPE_INT64 ((int) 'x')
#define DBUS_TYPE_INT64_AS_STRING "x"
#define DBUS_TYPE_UINT64 ((int) 't')
#define DBUS_TYPE_UINT64_AS_STRING "t"
#define DBUS_TYPE_DOUBLE ((int) 'd')
#define DBUS_TYPE_DOUBLE_AS_STRING "d"
#define DBUS_TYPE_STRING ((int) 's')
#define DBUS_TYPE_STRING_AS_STRING "s"
#define DBUS_TYPE_OBJECT_PATH ((int) 'o')
#define DBUS_TYPE_OBJECT_PATH_AS_STRING "o"
/* Compound types */
#define DBUS_TYPE_ARRAY ((int) 'a')
#define DBUS_TYPE_ARRAY_AS_STRING "a"
#define DBUS_TYPE_DICT ((int) 'm') /* not parameterized; always map<string,variant> */
#define DBUS_TYPE_DICT_AS_STRING "m"
#define DBUS_TYPE_VARIANT ((int) 'v')
#define DBUS_TYPE_VARIANT_AS_STRING "v"
/* STRUCT is sort of special since its code can't appear in a type string,
* instead DBUS_STRUCT_BEGIN_CHAR has to appear
*/
#define DBUS_TYPE_STRUCT ((int) 'r')
#define DBUS_TYPE_STRUCT_AS_STRING "r"
/* Does not count INVALID */
#define DBUS_NUMBER_OF_TYPES (13)
/* characters other than typecodes that appear in type signatures */
#define DBUS_STRUCT_BEGIN_CHAR ((int) '(')
#define DBUS_STRUCT_BEGIN_CHAR_AS_STRING "("
#define DBUS_STRUCT_END_CHAR ((int) ')')
#define DBUS_STRUCT_END_CHAR_AS_STRING ")"
/* Max length in bytes of a service or interface or member name */
#define DBUS_MAXIMUM_NAME_LENGTH 256