Deleted Added
full compact
5,12c5,6
< * This program is free software; you can redistribute it and/or modify
< * it under the terms of the GNU General Public License version 2 as
< * published by the Free Software Foundation.
< *
< * Alternatively, this software may be distributed under the terms of BSD
< * license.
< *
< * See README and COPYING for more details.
---
> * This software may be distributed under the terms of the BSD license.
> * See README for more details.
18a13
> #include "wpabuf.h"
446c441
< * Begin a string array entry in the dict
---
> * Begin an array entry in the dict
450a446
> * @param type The type of the contained data
460,464c456,460
< dbus_bool_t wpa_dbus_dict_begin_string_array(DBusMessageIter *iter_dict,
< const char *key,
< DBusMessageIter *iter_dict_entry,
< DBusMessageIter *iter_dict_val,
< DBusMessageIter *iter_array)
---
> dbus_bool_t wpa_dbus_dict_begin_array(DBusMessageIter *iter_dict,
> const char *key, const char *type,
> DBusMessageIter *iter_dict_entry,
> DBusMessageIter *iter_dict_val,
> DBusMessageIter *iter_array)
465a462,470
> char array_type[10];
> int err;
>
> err = os_snprintf(array_type, sizeof(array_type),
> DBUS_TYPE_ARRAY_AS_STRING "%s",
> type);
> if (err < 0 || err > (int) sizeof(array_type))
> return FALSE;
>
475,476c480
< DBUS_TYPE_ARRAY_AS_STRING
< DBUS_TYPE_STRING_AS_STRING,
---
> array_type,
481,482c485
< DBUS_TYPE_BYTE_AS_STRING,
< iter_array))
---
> type, iter_array))
488a492,504
> dbus_bool_t wpa_dbus_dict_begin_string_array(DBusMessageIter *iter_dict,
> const char *key,
> DBusMessageIter *iter_dict_entry,
> DBusMessageIter *iter_dict_val,
> DBusMessageIter *iter_array)
> {
> return wpa_dbus_dict_begin_array(
> iter_dict, key,
> DBUS_TYPE_STRING_AS_STRING,
> iter_dict_entry, iter_dict_val, iter_array);
> }
>
>
511c527
< * End a string array dict entry
---
> * Add a single byte array element to a string array dict entry
512a529,569
> * @param iter_array A valid DBusMessageIter returned from
> * wpa_dbus_dict_begin_array()'s iter_array
> * parameter -- note that wpa_dbus_dict_begin_array()
> * must have been called with "ay" as the type
> * @param value The data to be added to the dict entry's array
> * @param value_len The length of the data
> * @return TRUE on success, FALSE on failure
> *
> */
> dbus_bool_t wpa_dbus_dict_bin_array_add_element(DBusMessageIter *iter_array,
> const u8 *value,
> size_t value_len)
> {
> DBusMessageIter iter_bytes;
> size_t i;
>
> if (!iter_array || !value)
> return FALSE;
>
> if (!dbus_message_iter_open_container(iter_array, DBUS_TYPE_ARRAY,
> DBUS_TYPE_BYTE_AS_STRING,
> &iter_bytes))
> return FALSE;
>
> for (i = 0; i < value_len; i++) {
> if (!dbus_message_iter_append_basic(&iter_bytes,
> DBUS_TYPE_BYTE,
> &(value[i])))
> return FALSE;
> }
>
> if (!dbus_message_iter_close_container(iter_array, &iter_bytes))
> return FALSE;
>
> return TRUE;
> }
>
>
> /**
> * End an array dict entry
> *
516c573,574
< * wpa_dbus_dict_end_string_array()
---
> * wpa_dbus_dict_begin_string_array() or
> * wpa_dbus_dict_begin_array()
518c576,577
< * wpa_dbus_dict_end_string_array()
---
> * wpa_dbus_dict_begin_string_array() or
> * wpa_dbus_dict_begin_array()
520c579,580
< * wpa_dbus_dict_end_string_array()
---
> * wpa_dbus_dict_begin_string_array() or
> * wpa_dbus_dict_begin_array()
524,527c584,587
< dbus_bool_t wpa_dbus_dict_end_string_array(DBusMessageIter *iter_dict,
< DBusMessageIter *iter_dict_entry,
< DBusMessageIter *iter_dict_val,
< DBusMessageIter *iter_array)
---
> dbus_bool_t wpa_dbus_dict_end_array(DBusMessageIter *iter_dict,
> DBusMessageIter *iter_dict_entry,
> DBusMessageIter *iter_dict_val,
> DBusMessageIter *iter_array)
585a646,691
> /**
> * Convenience function to add an wpabuf binary array to the dict.
> *
> * @param iter_dict A valid DBusMessageIter returned from
> * wpa_dbus_dict_open_write()
> * @param key The key of the dict item
> * @param items The array of wpabuf structures
> * @param num_items The number of strings in the array
> * @return TRUE on success, FALSE on failure
> *
> */
> dbus_bool_t wpa_dbus_dict_append_wpabuf_array(DBusMessageIter *iter_dict,
> const char *key,
> const struct wpabuf **items,
> const dbus_uint32_t num_items)
> {
> DBusMessageIter iter_dict_entry, iter_dict_val, iter_array;
> dbus_uint32_t i;
>
> if (!key)
> return FALSE;
> if (!items && (num_items != 0))
> return FALSE;
>
> if (!wpa_dbus_dict_begin_array(iter_dict, key,
> DBUS_TYPE_ARRAY_AS_STRING
> DBUS_TYPE_BYTE_AS_STRING,
> &iter_dict_entry, &iter_dict_val,
> &iter_array))
> return FALSE;
>
> for (i = 0; i < num_items; i++) {
> if (!wpa_dbus_dict_bin_array_add_element(&iter_array,
> wpabuf_head(items[i]),
> wpabuf_len(items[i])))
> return FALSE;
> }
>
> if (!wpa_dbus_dict_end_array(iter_dict, &iter_dict_entry,
> &iter_dict_val, &iter_array))
> return FALSE;
>
> return TRUE;
> }
>
>
595a702
> * @error on failure a descriptive error
600c707,708
< DBusMessageIter *iter_dict)
---
> DBusMessageIter *iter_dict,
> DBusError *error)
602c710,712
< if (!iter || !iter_dict)
---
> if (!iter || !iter_dict) {
> dbus_set_error_const(error, DBUS_ERROR_FAILED,
> "[internal] missing message iterators");
603a714
> }
606c717,719
< dbus_message_iter_get_element_type(iter) != DBUS_TYPE_DICT_ENTRY)
---
> dbus_message_iter_get_element_type(iter) != DBUS_TYPE_DICT_ENTRY) {
> dbus_set_error_const(error, DBUS_ERROR_INVALID_ARGS,
> "unexpected message argument types");
607a721
> }
618,619c732
< DBusMessageIter *iter, int array_type,
< struct wpa_dbus_dict_entry *entry)
---
> DBusMessageIter *iter, struct wpa_dbus_dict_entry *entry)
623c736
< char *buffer, *nbuffer;;
---
> char *buffer, *nbuffer;
628c741
< buffer = os_zalloc(BYTE_ARRAY_ITEM_SIZE * BYTE_ARRAY_CHUNK_SIZE);
---
> buffer = os_calloc(BYTE_ARRAY_CHUNK_SIZE, BYTE_ARRAY_ITEM_SIZE);
638,639c751,753
< nbuffer = os_realloc(buffer, BYTE_ARRAY_ITEM_SIZE *
< (count + BYTE_ARRAY_CHUNK_SIZE));
---
> nbuffer = os_realloc_array(
> buffer, count + BYTE_ARRAY_CHUNK_SIZE,
> BYTE_ARRAY_ITEM_SIZE);
685c799
< buffer = os_zalloc(STR_ARRAY_ITEM_SIZE * STR_ARRAY_CHUNK_SIZE);
---
> buffer = os_calloc(STR_ARRAY_CHUNK_SIZE, STR_ARRAY_ITEM_SIZE);
696,697c810,812
< nbuffer = os_realloc(buffer, STR_ARRAY_ITEM_SIZE *
< (count + STR_ARRAY_CHUNK_SIZE));
---
> nbuffer = os_realloc_array(
> buffer, count + STR_ARRAY_CHUNK_SIZE,
> STR_ARRAY_ITEM_SIZE);
735a851,910
> #define BIN_ARRAY_CHUNK_SIZE 10
> #define BIN_ARRAY_ITEM_SIZE (sizeof(struct wpabuf *))
>
> static dbus_bool_t _wpa_dbus_dict_entry_get_binarray(
> DBusMessageIter *iter, struct wpa_dbus_dict_entry *entry)
> {
> struct wpa_dbus_dict_entry tmpentry;
> size_t buflen = 0;
> int i;
>
> if (dbus_message_iter_get_element_type(iter) != DBUS_TYPE_BYTE)
> return FALSE;
>
> entry->array_type = WPAS_DBUS_TYPE_BINARRAY;
> entry->array_len = 0;
> entry->binarray_value = NULL;
>
> while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_ARRAY) {
> DBusMessageIter iter_array;
>
> if (entry->array_len == buflen) {
> struct wpabuf **newbuf;
>
> buflen += BIN_ARRAY_CHUNK_SIZE;
>
> newbuf = os_realloc_array(entry->binarray_value,
> buflen, BIN_ARRAY_ITEM_SIZE);
> if (!newbuf)
> goto cleanup;
> entry->binarray_value = newbuf;
> }
>
> dbus_message_iter_recurse(iter, &iter_array);
> if (_wpa_dbus_dict_entry_get_byte_array(&iter_array, &tmpentry)
> == FALSE)
> goto cleanup;
>
> entry->binarray_value[entry->array_len] =
> wpabuf_alloc_ext_data((u8 *) tmpentry.bytearray_value,
> tmpentry.array_len);
> if (entry->binarray_value[entry->array_len] == NULL) {
> wpa_dbus_dict_entry_clear(&tmpentry);
> goto cleanup;
> }
> entry->array_len++;
> dbus_message_iter_next(iter);
> }
>
> return TRUE;
>
> cleanup:
> for (i = 0; i < (int) entry->array_len; i++)
> wpabuf_free(entry->binarray_value[i]);
> os_free(entry->binarray_value);
> entry->array_len = 0;
> entry->binarray_value = NULL;
> return FALSE;
> }
>
>
751d925
< array_type,
758a933,934
> case DBUS_TYPE_ARRAY:
> success = _wpa_dbus_dict_entry_get_binarray(&iter_array, entry);
917a1094,1098
> case WPAS_DBUS_TYPE_BINARRAY:
> for (i = 0; i < entry->array_len; i++)
> wpabuf_free(entry->binarray_value[i]);
> os_free(entry->binarray_value);
> break;
922c1103
< memset(entry, 0, sizeof(struct wpa_dbus_dict_entry));
---
> os_memset(entry, 0, sizeof(struct wpa_dbus_dict_entry));