Commit e537e421 authored by Anders Carlsson's avatar Anders Carlsson

2003-03-16 Anders Carlsson <andersca@codefactory.se>

	* dbus/dbus-connection.c:
	(dbus_connection_send_with_reply_and_block):
	Decrease connection->n_incoming when removing an entry
	from the list.
	* dbus/dbus-dict.c: (dbus_dict_entry_free),
	(dbus_dict_set_boolean_array), (dbus_dict_set_int32_array),
	(dbus_dict_set_uint32_array), (dbus_dict_set_double_array),
	(dbus_dict_set_byte_array), (dbus_dict_set_string_array),
	(dbus_dict_get_boolean_array), (dbus_dict_get_double_array),
	(dbus_dict_get_byte_array):
	Handle NULL arrays and strings. Also add support for byte arrays.

	* dbus/dbus-marshal.c: (_dbus_marshal_byte_array),
	(_dbus_marshal_dict), (_dbus_demarshal_byte_array),
	(_dbus_demarshal_int32_array), (_dbus_demarshal_uint32_array),
	(_dbus_demarshal_double_array), (_dbus_demarshal_string_array),
	(_dbus_demarshal_dict), (demarshal_and_validate_len),
	(_dbus_marshal_validate_arg), (_dbus_marshal_test):
	* dbus/dbus-marshal.h:
	Add support for marshalling and demarshalling empty arrays and strings.

	* dbus/dbus-message.c: (dbus_message_append_args_valist),
	(dbus_message_append_string_array),
	(dbus_message_iter_get_boolean),
	(dbus_message_iter_get_boolean_array),
	(dbus_message_iter_get_int32_array),
	(dbus_message_iter_get_uint32_array),
	(dbus_message_iter_get_double_array),
	(dbus_message_iter_get_byte_array),
	(dbus_message_iter_get_string_array), (dbus_message_iter_get_dict),
	(check_message_handling):
	Add support for getting empty arrays and dicts.

	* dbus/dbus-string.c: (_dbus_string_validate_utf8):
	Don't do any validation at all for now, that's better than just checking
	for ASCII.

	* test/data/valid-messages/emptiness.message:
	New test message with lots of empty arrays.
parent 5c53fb2a
2003-03-16 Anders Carlsson <andersca@codefactory.se>
* dbus/dbus-connection.c:
(dbus_connection_send_with_reply_and_block):
Decrease connection->n_incoming when removing an entry
from the list.
* dbus/dbus-dict.c: (dbus_dict_entry_free),
(dbus_dict_set_boolean_array), (dbus_dict_set_int32_array),
(dbus_dict_set_uint32_array), (dbus_dict_set_double_array),
(dbus_dict_set_byte_array), (dbus_dict_set_string_array),
(dbus_dict_get_boolean_array), (dbus_dict_get_double_array),
(dbus_dict_get_byte_array):
Handle NULL arrays and strings. Also add support for byte arrays.
* dbus/dbus-marshal.c: (_dbus_marshal_byte_array),
(_dbus_marshal_dict), (_dbus_demarshal_byte_array),
(_dbus_demarshal_int32_array), (_dbus_demarshal_uint32_array),
(_dbus_demarshal_double_array), (_dbus_demarshal_string_array),
(_dbus_demarshal_dict), (demarshal_and_validate_len),
(_dbus_marshal_validate_arg), (_dbus_marshal_test):
* dbus/dbus-marshal.h:
Add support for marshalling and demarshalling empty arrays and strings.
* dbus/dbus-message.c: (dbus_message_append_args_valist),
(dbus_message_append_string_array),
(dbus_message_iter_get_boolean),
(dbus_message_iter_get_boolean_array),
(dbus_message_iter_get_int32_array),
(dbus_message_iter_get_uint32_array),
(dbus_message_iter_get_double_array),
(dbus_message_iter_get_byte_array),
(dbus_message_iter_get_string_array), (dbus_message_iter_get_dict),
(check_message_handling):
Add support for getting empty arrays and dicts.
* dbus/dbus-string.c: (_dbus_string_validate_utf8):
Don't do any validation at all for now, that's better than just checking
for ASCII.
* test/data/valid-messages/emptiness.message:
New test message with lots of empty arrays.
2003-03-16 Havoc Pennington <hp@pobox.com>
* dbus/dbus-connection.c
......
......@@ -1443,6 +1443,7 @@ dbus_connection_send_with_reply_and_block (DBusConnection *connection,
if (dbus_message_get_reply_serial (reply) == client_serial)
{
_dbus_list_remove_link (&connection->incoming_messages, link);
connection->n_incoming -= 1;
dbus_message_ref (reply);
dbus_mutex_unlock (connection->mutex);
......
......@@ -55,7 +55,7 @@ typedef struct
struct {
unsigned char *value;
int len;
} boolean_array;
} byte_array;
struct {
dbus_int32_t *value;
int len;
......@@ -92,8 +92,9 @@ dbus_dict_entry_free (DBusDictEntry *entry)
case DBUS_TYPE_STRING:
dbus_free (entry->v.string_value);
break;
case DBUS_TYPE_BYTE_ARRAY:
case DBUS_TYPE_BOOLEAN_ARRAY:
dbus_free (entry->v.boolean_array.value);
dbus_free (entry->v.byte_array.value);
break;
case DBUS_TYPE_INT32_ARRAY:
dbus_free (entry->v.int32_array.value);
......@@ -473,18 +474,23 @@ dbus_dict_set_boolean_array (DBusDict *dict,
DBusDictEntry *entry;
unsigned char *tmp;
tmp = dbus_malloc (len);
if (!tmp)
return FALSE;
if (len == 0)
tmp = NULL;
else
{
tmp = dbus_malloc (len);
if (!tmp)
return FALSE;
memcpy (tmp, value, len);
memcpy (tmp, value, len);
}
if (insert_entry (dict, key, &entry))
{
entry->type = DBUS_TYPE_BOOLEAN_ARRAY;
entry->v.boolean_array.value = tmp;
entry->v.boolean_array.len = len;
entry->v.byte_array.value = tmp;
entry->v.byte_array.len = len;
return TRUE;
}
......@@ -511,11 +517,16 @@ dbus_dict_set_int32_array (DBusDict *dict,
DBusDictEntry *entry;
dbus_int32_t *tmp;
tmp = dbus_new (dbus_int32_t, len);
if (!tmp)
return FALSE;
if (len == 0)
tmp = NULL;
else
{
tmp = dbus_new (dbus_int32_t, len);
if (!tmp)
return FALSE;
}
memcpy (tmp, value, len * sizeof (dbus_int32_t));
if (insert_entry (dict, key, &entry))
......@@ -550,12 +561,17 @@ dbus_dict_set_uint32_array (DBusDict *dict,
DBusDictEntry *entry;
dbus_uint32_t *tmp;
tmp = dbus_new (dbus_uint32_t, len);
if (!tmp)
return FALSE;
memcpy (tmp, value, len * sizeof (dbus_uint32_t));
if (len == 0)
tmp = NULL;
else
{
tmp = dbus_new (dbus_uint32_t, len);
if (!tmp)
return FALSE;
memcpy (tmp, value, len * sizeof (dbus_uint32_t));
}
if (insert_entry (dict, key, &entry))
{
......@@ -588,12 +604,17 @@ dbus_dict_set_double_array (DBusDict *dict,
DBusDictEntry *entry;
double *tmp;
tmp = dbus_new (double, len);
if (len == 0)
tmp = NULL;
else
{
tmp = dbus_new (double, len);
if (!tmp)
return FALSE;
if (!tmp)
return FALSE;
memcpy (tmp, value, len * sizeof (double));
memcpy (tmp, value, len * sizeof (double));
}
if (insert_entry (dict, key, &entry))
{
......@@ -607,6 +628,40 @@ dbus_dict_set_double_array (DBusDict *dict,
return FALSE;
}
dbus_bool_t
dbus_dict_set_byte_array (DBusDict *dict,
const char *key,
unsigned const char *value,
int len)
{
DBusDictEntry *entry;
unsigned char *tmp;
if (len == 0)
tmp = NULL;
else
{
tmp = dbus_malloc (len);
if (!tmp)
return FALSE;
memcpy (tmp, value, len);
}
if (insert_entry (dict, key, &entry))
{
entry->type = DBUS_TYPE_BYTE_ARRAY;
entry->v.byte_array.value = tmp;
entry->v.byte_array.len = len;
return TRUE;
}
else
return FALSE;
}
/**
* Adds a string array to the dict. If a value with the same key
* already exists, then it will be replaced by the new value.
......@@ -631,6 +686,8 @@ dbus_dict_set_string_array (DBusDict *dict,
if (!tmp)
return FALSE;
tmp[len] = NULL;
for (i = 0; i < len; i++)
{
tmp[i] = _dbus_strdup (value[i]);
......@@ -806,8 +863,8 @@ dbus_dict_get_boolean_array (DBusDict *dict,
if (!entry || entry->type != DBUS_TYPE_BOOLEAN_ARRAY)
return FALSE;
*value = entry->v.boolean_array.value;
*len = entry->v.boolean_array.len;
*value = entry->v.byte_array.value;
*len = entry->v.byte_array.len;
return TRUE;
}
......@@ -899,6 +956,25 @@ dbus_dict_get_double_array (DBusDict *dict,
return TRUE;
}
dbus_bool_t
dbus_dict_get_byte_array (DBusDict *dict,
const char *key,
unsigned const char **value,
int *len)
{
DBusDictEntry *entry;
entry = _dbus_hash_table_lookup_string (dict->table, key);
if (!entry || entry->type != DBUS_TYPE_BYTE_ARRAY)
return FALSE;
*value = entry->v.byte_array.value;
*len = entry->v.byte_array.len;
return TRUE;
}
/**
* Gets a string array from a dict using a key.
*
......
......@@ -352,7 +352,10 @@ _dbus_marshal_byte_array (DBusString *str,
return FALSE;
}
return _dbus_string_append_len (str, value, len);
if (len == 0)
return TRUE;
else
return _dbus_string_append_len (str, value, len);
}
/**
......@@ -521,7 +524,7 @@ _dbus_marshal_dict (DBusString *str,
return TRUE;
if (!_dbus_marshal_string_array (str, byte_order,
keys, len))
(const char **)keys, len))
goto error;
for (i = 0; i < len; i++)
......@@ -656,13 +659,13 @@ _dbus_marshal_dict (DBusString *str,
if (!dbus_dict_get_string_array (dict, keys[i], &value, &len))
goto error;
if (!_dbus_marshal_string_array (str, byte_order, value, len))
if (!_dbus_marshal_string_array (str, byte_order, (const char **)value, len))
goto error;
break;
}
default:
_dbus_warn ("unknwon value type %d\n", dbus_dict_get_value_type (dict, keys[i]));
_dbus_warn ("unkown value type %d\n", dbus_dict_get_value_type (dict, keys[i]));
_dbus_assert_not_reached ("unknown value type in dict");
}
}
......@@ -826,16 +829,18 @@ _dbus_demarshal_string (const DBusString *str,
* @param str the string containing the data
* @param byte_order the byte order
* @param pos the position in the string
* @param new_pos the new position of the string
* @param array the array
* @param array_len length of the demarshaled data
* @returns the demarshaled data.
* @returns #TRUE on success
*/
unsigned char *
_dbus_demarshal_byte_array (const DBusString *str,
int byte_order,
int pos,
int *new_pos,
int *array_len)
dbus_bool_t
_dbus_demarshal_byte_array (const DBusString *str,
int byte_order,
int pos,
int *new_pos,
unsigned char **array,
int *array_len)
{
int len;
unsigned char *retval;
......@@ -843,25 +848,39 @@ _dbus_demarshal_byte_array (const DBusString *str,
len = _dbus_demarshal_uint32 (str, byte_order, pos, &pos);
if (len == 0)
{
*array_len = len;
*array = NULL;
if (new_pos)
*new_pos = pos;
return TRUE;
}
retval = dbus_malloc (len);
if (!retval)
return NULL;
return FALSE;
_dbus_string_get_const_data_len (str, &data, pos, len);
if (!data)
return NULL;
{
dbus_free (retval);
return FALSE;
}
memcpy (retval, data, len);
if (new_pos)
*new_pos = pos + len;
if (array_len)
*array_len = len;
return retval;
*array = retval;
*array_len = len;
return TRUE;
}
/**
......@@ -871,25 +890,38 @@ _dbus_demarshal_byte_array (const DBusString *str,
* @param byte_order the byte order
* @param pos the position in the string
* @param new_pos the new position of the string
* @param array the array
* @param array_len length of the demarshaled data
* @returns the demarshaled data.
* @returns #TRUE on success
*/
dbus_int32_t *
_dbus_demarshal_int32_array (const DBusString *str,
int byte_order,
int pos,
int *new_pos,
int *array_len)
dbus_bool_t
_dbus_demarshal_int32_array (const DBusString *str,
int byte_order,
int pos,
int *new_pos,
dbus_int32_t **array,
int *array_len)
{
int len, i;
dbus_int32_t *retval;
len = _dbus_demarshal_uint32 (str, byte_order, pos, &pos);
retval = dbus_new (dbus_int32_t, len);
if (len == 0)
{
*array_len = 0;
*array = NULL;
if (new_pos)
*new_pos = pos;
return TRUE;
}
retval = dbus_new (dbus_int32_t, len);
if (!retval)
return NULL;
return FALSE;
for (i = 0; i < len; i++)
retval[i] = _dbus_demarshal_int32 (str, byte_order, pos, &pos);
......@@ -897,10 +929,10 @@ _dbus_demarshal_int32_array (const DBusString *str,
if (new_pos)
*new_pos = pos;
if (array_len)
*array_len = len;
*array_len = len;
*array = retval;
return retval;
return TRUE;
}
/**
......@@ -910,25 +942,38 @@ _dbus_demarshal_int32_array (const DBusString *str,
* @param byte_order the byte order
* @param pos the position in the string
* @param new_pos the new position of the string
* @param array the array
* @param array_len length of the demarshaled data
* @returns the demarshaled data.
* @returns #TRUE on success
*/
dbus_uint32_t *
_dbus_demarshal_uint32_array (const DBusString *str,
int byte_order,
int pos,
int *new_pos,
int *array_len)
dbus_bool_t
_dbus_demarshal_uint32_array (const DBusString *str,
int byte_order,
int pos,
int *new_pos,
dbus_uint32_t **array,
int *array_len)
{
int len, i;
dbus_uint32_t *retval;
len = _dbus_demarshal_uint32 (str, byte_order, pos, &pos);
if (len == 0)
{
*array_len = 0;
*array = NULL;
if (new_pos)
*new_pos = pos;
return TRUE;
}
retval = dbus_new (dbus_uint32_t, len);
if (!retval)
return NULL;
return FALSE;
for (i = 0; i < len; i++)
retval[i] = _dbus_demarshal_uint32 (str, byte_order, pos, &pos);
......@@ -936,10 +981,10 @@ _dbus_demarshal_uint32_array (const DBusString *str,
if (new_pos)
*new_pos = pos;
if (array_len)
*array_len = len;
*array_len = len;
*array = retval;
return retval;
return TRUE;
}
/**
......@@ -949,25 +994,38 @@ _dbus_demarshal_uint32_array (const DBusString *str,
* @param byte_order the byte order
* @param pos the position in the string
* @param new_pos the new position of the string
* @param array the array
* @param array_len length of the demarshaled data
* @returns the demarshaled data.
* @returns #TRUE on success
*/
double *
_dbus_demarshal_double_array (const DBusString *str,
int byte_order,
int pos,
int *new_pos,
int *array_len)
dbus_bool_t
_dbus_demarshal_double_array (const DBusString *str,
int byte_order,
int pos,
int *new_pos,
double **array,
int *array_len)
{
int len, i;
double *retval;
len = _dbus_demarshal_uint32 (str, byte_order, pos, &pos);
if (len == 0)
{
*array_len = 0;
*array = NULL;
if (new_pos)
*new_pos = pos;
return TRUE;
}
retval = dbus_new (double, len);
if (!retval)
return NULL;
return FALSE;
for (i = 0; i < len; i++)
retval[i] = _dbus_demarshal_double (str, byte_order, pos, &pos);
......@@ -975,10 +1033,10 @@ _dbus_demarshal_double_array (const DBusString *str,
if (new_pos)
*new_pos = pos;
if (array_len)
*array_len = len;
*array_len = len;
*array = retval;
return retval;
return TRUE;
}
/**
......@@ -988,25 +1046,38 @@ _dbus_demarshal_double_array (const DBusString *str,
* @param byte_order the byte order
* @param pos the position in the string
* @param new_pos the new position of the string
* @param array the array
* @param array_len length of the demarshaled data
* @returns the demarshaled data.
* @returns #TRUE on success
*/
char **
_dbus_demarshal_string_array (const DBusString *str,
int byte_order,
int pos,
int *new_pos,
int *array_len)
dbus_bool_t
_dbus_demarshal_string_array (const DBusString *str,
int byte_order,
int pos,
int *new_pos,
char ***array,
int *array_len)
{
int len, i, j;
char **retval;
len = _dbus_demarshal_uint32 (str, byte_order, pos, &pos);
if (len == 0)
{
*array_len = 0;
*array = NULL;
if (new_pos)
*new_pos = pos;
return TRUE;
}
retval = dbus_new (char *, len + 1);
if (!retval)
return NULL;
return FALSE;
retval[len] = NULL;
......@@ -1021,17 +1092,17 @@ _dbus_demarshal_string_array (const DBusString *str,
if (new_pos)
*new_pos = pos;
if (array_len)
*array_len = len;
*array = retval;
*array_len = len;
return retval;
return TRUE;
error:
for (j = 0; j < i; j++)
dbus_free (retval[i]);
dbus_free (retval);
return NULL;
return FALSE;
}
/**
......@@ -1041,25 +1112,24 @@ _dbus_demarshal_string_array (const DBusString *str,
* @param byte_order the byte order
* @param pos the position in the string
* @param new_pos the new position in the string
* @returns the demarshalled dict
* @param dict the dict
* @returns #TRUE on success.
*/
DBusDict *
dbus_bool_t
_dbus_demarshal_dict (const DBusString *str,
int byte_order,
int pos,
int *new_pos)
int *new_pos,
DBusDict **dict)
{
char **keys;
int i, len;
DBusDict *dict;
dict = dbus_dict_new ();
if (!dict)
return NULL;
*dict = dbus_dict_new ();
if (!*dict)
return FALSE;
keys = _dbus_demarshal_string_array (str, byte_order, pos, &pos, &len);
if (!keys)
if (!_dbus_demarshal_string_array (str, byte_order, pos, &pos, &keys, &len))
goto error;
for (i = 0; i < len; i++)
......@@ -1074,7 +1144,7 @@ _dbus_demarshal_dict (const DBusString *str,
value = _dbus_string_get_byte (str, pos ++);
if (!dbus_dict_set_boolean (dict, keys[i], value))
if (!dbus_dict_set_boolean (*dict, keys[i], value))
goto error;
break;
}
......@@ -1084,7 +1154,7 @@ _dbus_demarshal_dict (const DBusString *str,
value = _dbus_demarshal_int32 (str, byte_order, pos, &pos);
if (!dbus_dict_set_int32 (dict, keys[i], value))
if (!dbus_dict_set_int32 (*dict, keys[i],