mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-25 21:10:08 +01:00
2006-12-18 Dan Williams <dcbw@redhat.com>
* libnm-util/dbus-dict-helpers.c - (_nmu_dbus_dict_entry_get_array, _nmu_dbus_dict_entry_get_string_array, _nmu_dbus_dict_entry_get_byte_array): replace usage of dbus_message_iter_get_array_len() (Gnome.org #382898) git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2189 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
parent
ff1145b930
commit
664b97dbf3
2 changed files with 57 additions and 34 deletions
|
|
@ -1,3 +1,10 @@
|
|||
2006-12-18 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* libnm-util/dbus-dict-helpers.c
|
||||
- (_nmu_dbus_dict_entry_get_array, _nmu_dbus_dict_entry_get_string_array,
|
||||
_nmu_dbus_dict_entry_get_byte_array): replace usage of
|
||||
dbus_message_iter_get_array_len() (Gnome.org #382898)
|
||||
|
||||
2006-12-18 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* gnome/libnm_glib/libnm_glib.c
|
||||
|
|
|
|||
|
|
@ -527,51 +527,71 @@ nmu_dbus_dict_open_read (DBusMessageIter *iter,
|
|||
}
|
||||
|
||||
|
||||
#define BYTE_ARRAY_CHUNK_SIZE 34
|
||||
#define BYTE_ARRAY_ITEM_SIZE (sizeof (char))
|
||||
|
||||
static dbus_bool_t
|
||||
_nmu_dbus_dict_entry_get_byte_array (DBusMessageIter *iter,
|
||||
int array_len,
|
||||
int array_type,
|
||||
NMUDictEntry *entry)
|
||||
{
|
||||
dbus_uint32_t i = 0;
|
||||
dbus_uint32_t count = 0;
|
||||
dbus_bool_t success = FALSE;
|
||||
char byte;
|
||||
char * buffer;
|
||||
|
||||
/* Zero-length arrays are valid. */
|
||||
if (array_len == 0)
|
||||
{
|
||||
entry->bytearray_value = NULL;
|
||||
entry->array_type = DBUS_TYPE_BYTE;
|
||||
success = TRUE;
|
||||
goto done;
|
||||
}
|
||||
entry->bytearray_value = NULL;
|
||||
entry->array_type = DBUS_TYPE_BYTE;
|
||||
|
||||
entry->bytearray_value = malloc (array_len * sizeof (char));
|
||||
if (!entry->bytearray_value)
|
||||
buffer = malloc (BYTE_ARRAY_ITEM_SIZE * BYTE_ARRAY_CHUNK_SIZE);
|
||||
if (!buffer)
|
||||
{
|
||||
fprintf (stderr, "%s out of memory trying to retrieve a byte "
|
||||
"array.\n", __func__);
|
||||
goto done;
|
||||
}
|
||||
|
||||
entry->array_type = DBUS_TYPE_BYTE;
|
||||
entry->array_len = array_len;
|
||||
entry->bytearray_value = buffer;
|
||||
entry->array_len = 0;
|
||||
while (dbus_message_iter_get_arg_type (iter) == DBUS_TYPE_BYTE)
|
||||
{
|
||||
char byte;
|
||||
|
||||
if ((count % BYTE_ARRAY_CHUNK_SIZE) == 0 && count != 0)
|
||||
{
|
||||
buffer = realloc (buffer, BYTE_ARRAY_ITEM_SIZE * (count + BYTE_ARRAY_CHUNK_SIZE));
|
||||
if (buffer == NULL)
|
||||
{
|
||||
fprintf (stderr, "%s() out of memory trying to retrieve"
|
||||
"the string array.\n", __func__);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
entry->bytearray_value = buffer;
|
||||
|
||||
dbus_message_iter_get_basic (iter, &byte);
|
||||
entry->bytearray_value[i++] = byte;
|
||||
entry->bytearray_value[count] = byte;
|
||||
entry->array_len = ++count;
|
||||
dbus_message_iter_next (iter);
|
||||
}
|
||||
|
||||
/* Zero-length arrays are valid. */
|
||||
if (entry->array_len == 0)
|
||||
{
|
||||
free (entry->bytearray_value);
|
||||
entry->strarray_value = NULL;
|
||||
}
|
||||
|
||||
success = TRUE;
|
||||
|
||||
done:
|
||||
return success;
|
||||
}
|
||||
|
||||
#define STR_ARRAY_CHUNK_SIZE 8
|
||||
#define STR_ARRAY_ITEM_SIZE (sizeof (char *))
|
||||
|
||||
static dbus_bool_t
|
||||
_nmu_dbus_dict_entry_get_string_array (DBusMessageIter *iter,
|
||||
int array_len,
|
||||
int array_type,
|
||||
NMUDictEntry *entry)
|
||||
{
|
||||
|
|
@ -582,14 +602,7 @@ _nmu_dbus_dict_entry_get_string_array (DBusMessageIter *iter,
|
|||
entry->strarray_value = NULL;
|
||||
entry->array_type = DBUS_TYPE_STRING;
|
||||
|
||||
/* Zero-length arrays are valid. */
|
||||
if (array_len == 0)
|
||||
{
|
||||
success = TRUE;
|
||||
goto done;
|
||||
}
|
||||
|
||||
buffer = (char **)malloc (sizeof (char *) * 8);
|
||||
buffer = (char **)malloc (STR_ARRAY_ITEM_SIZE * STR_ARRAY_CHUNK_SIZE);
|
||||
if (buffer == NULL)
|
||||
{
|
||||
fprintf (stderr, "%s() out of memory trying to retrieve a string"
|
||||
|
|
@ -604,9 +617,9 @@ _nmu_dbus_dict_entry_get_string_array (DBusMessageIter *iter,
|
|||
const char *value;
|
||||
char *str;
|
||||
|
||||
if ((count % 8) == 0 && count != 0)
|
||||
if ((count % STR_ARRAY_CHUNK_SIZE) == 0 && count != 0)
|
||||
{
|
||||
buffer = realloc (buffer, sizeof (char *) * (count + 8));
|
||||
buffer = realloc (buffer, STR_ARRAY_ITEM_SIZE * (count + STR_ARRAY_CHUNK_SIZE));
|
||||
if (buffer == NULL)
|
||||
{
|
||||
fprintf (stderr, "%s() out of memory trying to retrieve"
|
||||
|
|
@ -628,6 +641,14 @@ _nmu_dbus_dict_entry_get_string_array (DBusMessageIter *iter,
|
|||
entry->array_len = ++count;
|
||||
dbus_message_iter_next (iter);
|
||||
}
|
||||
|
||||
/* Zero-length arrays are valid. */
|
||||
if (entry->array_len == 0)
|
||||
{
|
||||
free (entry->strarray_value);
|
||||
entry->strarray_value = NULL;
|
||||
}
|
||||
|
||||
success = TRUE;
|
||||
|
||||
done:
|
||||
|
|
@ -640,7 +661,6 @@ _nmu_dbus_dict_entry_get_array (DBusMessageIter *iter_dict_val,
|
|||
NMUDictEntry *entry)
|
||||
{
|
||||
int array_type = dbus_message_iter_get_element_type (iter_dict_val);
|
||||
int array_len;
|
||||
dbus_bool_t success = FALSE;
|
||||
DBusMessageIter iter_array;
|
||||
|
||||
|
|
@ -649,21 +669,17 @@ _nmu_dbus_dict_entry_get_array (DBusMessageIter *iter_dict_val,
|
|||
|
||||
dbus_message_iter_recurse (iter_dict_val, &iter_array);
|
||||
|
||||
array_len = dbus_message_iter_get_array_len (&iter_array);
|
||||
if (array_len < 0)
|
||||
return FALSE;
|
||||
|
||||
switch (array_type)
|
||||
{
|
||||
case DBUS_TYPE_BYTE:
|
||||
{
|
||||
success = _nmu_dbus_dict_entry_get_byte_array (&iter_array,
|
||||
array_len, array_type, entry);
|
||||
array_type, entry);
|
||||
break;
|
||||
}
|
||||
case DBUS_TYPE_STRING:
|
||||
success = _nmu_dbus_dict_entry_get_string_array (&iter_array,
|
||||
array_len, array_type, entry);
|
||||
array_type, entry);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue