mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-09 09:28:06 +02: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>
|
2006-12-18 Dan Williams <dcbw@redhat.com>
|
||||||
|
|
||||||
* gnome/libnm_glib/libnm_glib.c
|
* 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
|
static dbus_bool_t
|
||||||
_nmu_dbus_dict_entry_get_byte_array (DBusMessageIter *iter,
|
_nmu_dbus_dict_entry_get_byte_array (DBusMessageIter *iter,
|
||||||
int array_len,
|
|
||||||
int array_type,
|
int array_type,
|
||||||
NMUDictEntry *entry)
|
NMUDictEntry *entry)
|
||||||
{
|
{
|
||||||
dbus_uint32_t i = 0;
|
dbus_uint32_t count = 0;
|
||||||
dbus_bool_t success = FALSE;
|
dbus_bool_t success = FALSE;
|
||||||
char byte;
|
char * buffer;
|
||||||
|
|
||||||
/* Zero-length arrays are valid. */
|
entry->bytearray_value = NULL;
|
||||||
if (array_len == 0)
|
entry->array_type = DBUS_TYPE_BYTE;
|
||||||
{
|
|
||||||
entry->bytearray_value = NULL;
|
|
||||||
entry->array_type = DBUS_TYPE_BYTE;
|
|
||||||
success = TRUE;
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
entry->bytearray_value = malloc (array_len * sizeof (char));
|
buffer = malloc (BYTE_ARRAY_ITEM_SIZE * BYTE_ARRAY_CHUNK_SIZE);
|
||||||
if (!entry->bytearray_value)
|
if (!buffer)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "%s out of memory trying to retrieve a byte "
|
fprintf (stderr, "%s out of memory trying to retrieve a byte "
|
||||||
"array.\n", __func__);
|
"array.\n", __func__);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
entry->array_type = DBUS_TYPE_BYTE;
|
entry->bytearray_value = buffer;
|
||||||
entry->array_len = array_len;
|
entry->array_len = 0;
|
||||||
while (dbus_message_iter_get_arg_type (iter) == DBUS_TYPE_BYTE)
|
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);
|
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);
|
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;
|
success = TRUE;
|
||||||
|
|
||||||
done:
|
done:
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define STR_ARRAY_CHUNK_SIZE 8
|
||||||
|
#define STR_ARRAY_ITEM_SIZE (sizeof (char *))
|
||||||
|
|
||||||
static dbus_bool_t
|
static dbus_bool_t
|
||||||
_nmu_dbus_dict_entry_get_string_array (DBusMessageIter *iter,
|
_nmu_dbus_dict_entry_get_string_array (DBusMessageIter *iter,
|
||||||
int array_len,
|
|
||||||
int array_type,
|
int array_type,
|
||||||
NMUDictEntry *entry)
|
NMUDictEntry *entry)
|
||||||
{
|
{
|
||||||
|
|
@ -582,14 +602,7 @@ _nmu_dbus_dict_entry_get_string_array (DBusMessageIter *iter,
|
||||||
entry->strarray_value = NULL;
|
entry->strarray_value = NULL;
|
||||||
entry->array_type = DBUS_TYPE_STRING;
|
entry->array_type = DBUS_TYPE_STRING;
|
||||||
|
|
||||||
/* Zero-length arrays are valid. */
|
buffer = (char **)malloc (STR_ARRAY_ITEM_SIZE * STR_ARRAY_CHUNK_SIZE);
|
||||||
if (array_len == 0)
|
|
||||||
{
|
|
||||||
success = TRUE;
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer = (char **)malloc (sizeof (char *) * 8);
|
|
||||||
if (buffer == NULL)
|
if (buffer == NULL)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "%s() out of memory trying to retrieve a string"
|
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;
|
const char *value;
|
||||||
char *str;
|
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)
|
if (buffer == NULL)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "%s() out of memory trying to retrieve"
|
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;
|
entry->array_len = ++count;
|
||||||
dbus_message_iter_next (iter);
|
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;
|
success = TRUE;
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
|
@ -640,7 +661,6 @@ _nmu_dbus_dict_entry_get_array (DBusMessageIter *iter_dict_val,
|
||||||
NMUDictEntry *entry)
|
NMUDictEntry *entry)
|
||||||
{
|
{
|
||||||
int array_type = dbus_message_iter_get_element_type (iter_dict_val);
|
int array_type = dbus_message_iter_get_element_type (iter_dict_val);
|
||||||
int array_len;
|
|
||||||
dbus_bool_t success = FALSE;
|
dbus_bool_t success = FALSE;
|
||||||
DBusMessageIter iter_array;
|
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);
|
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)
|
switch (array_type)
|
||||||
{
|
{
|
||||||
case DBUS_TYPE_BYTE:
|
case DBUS_TYPE_BYTE:
|
||||||
{
|
{
|
||||||
success = _nmu_dbus_dict_entry_get_byte_array (&iter_array,
|
success = _nmu_dbus_dict_entry_get_byte_array (&iter_array,
|
||||||
array_len, array_type, entry);
|
array_type, entry);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DBUS_TYPE_STRING:
|
case DBUS_TYPE_STRING:
|
||||||
success = _nmu_dbus_dict_entry_get_string_array (&iter_array,
|
success = _nmu_dbus_dict_entry_get_string_array (&iter_array,
|
||||||
array_len, array_type, entry);
|
array_type, entry);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue