D-Bus: Check driver capability for IBSS in Modes property of Capabilities
[mech_eap.git] / wpa_supplicant / dbus / dbus_dict_helpers.c
index 7826e9c..e4e9b8d 100644 (file)
@@ -66,7 +66,7 @@ dbus_bool_t wpa_dbus_dict_close_write(DBusMessageIter *iter,
 
 const char * wpa_dbus_type_as_string(const int type)
 {
-       switch(type) {
+       switch (type) {
        case DBUS_TYPE_BYTE:
                return DBUS_TYPE_BYTE_AS_STRING;
        case DBUS_TYPE_BOOLEAN:
@@ -205,24 +205,6 @@ dbus_bool_t wpa_dbus_dict_append_string(DBusMessageIter *iter_dict,
 
 
 /**
- * Add a byte entry 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 value The byte value
- * @return TRUE on success, FALSE on failure
- *
- */
-dbus_bool_t wpa_dbus_dict_append_byte(DBusMessageIter *iter_dict,
-                                     const char *key, const char value)
-{
-       return _wpa_dbus_add_dict_entry_basic(iter_dict, key, DBUS_TYPE_BYTE,
-                                             &value);
-}
-
-
-/**
  * Add a boolean entry to the dict.
  *
  * @param iter_dict A valid DBusMessageIter returned from
@@ -317,62 +299,6 @@ dbus_bool_t wpa_dbus_dict_append_uint32(DBusMessageIter *iter_dict,
 
 
 /**
- * Add a 64-bit integer entry 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 value The 64-bit integer value
- * @return TRUE on success, FALSE on failure
- *
- */
-dbus_bool_t wpa_dbus_dict_append_int64(DBusMessageIter *iter_dict,
-                                      const char *key,
-                                      const dbus_int64_t value)
-{
-       return _wpa_dbus_add_dict_entry_basic(iter_dict, key, DBUS_TYPE_INT64,
-                                             &value);
-}
-
-
-/**
- * Add a 64-bit unsigned integer entry 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 value The 64-bit unsigned integer value
- * @return TRUE on success, FALSE on failure
- *
- */
-dbus_bool_t wpa_dbus_dict_append_uint64(DBusMessageIter *iter_dict,
-                                       const char *key,
-                                       const dbus_uint64_t value)
-{
-       return _wpa_dbus_add_dict_entry_basic(iter_dict, key, DBUS_TYPE_UINT64,
-                                             &value);
-}
-
-
-/**
- * Add a double-precision floating point entry 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 value The double-precision floating point value
- * @return TRUE on success, FALSE on failure
- *
- */
-dbus_bool_t wpa_dbus_dict_append_double(DBusMessageIter *iter_dict,
-                                       const char *key, const double value)
-{
-       return _wpa_dbus_add_dict_entry_basic(iter_dict, key, DBUS_TYPE_DOUBLE,
-                                             &value);
-}
-
-
-/**
  * Add a DBus object path entry to the dict.
  *
  * @param iter_dict A valid DBusMessageIter returned from
@@ -661,7 +587,7 @@ dbus_bool_t wpa_dbus_dict_open_read(DBusMessageIter *iter,
        wpa_printf(MSG_MSGDUMP, "%s: start reading a dict entry", __func__);
        if (!iter || !iter_dict) {
                dbus_set_error_const(error, DBUS_ERROR_FAILED,
-                                    "[internal] missing message iterators");
+                                    "[internal] missing message iterators");
                return FALSE;
        }
 
@@ -674,7 +600,7 @@ dbus_bool_t wpa_dbus_dict_open_read(DBusMessageIter *iter,
                           type != DBUS_TYPE_ARRAY ? '?' :
                           dbus_message_iter_get_element_type(iter));
                dbus_set_error_const(error, DBUS_ERROR_INVALID_ARGS,
-                                    "unexpected message argument types");
+                                    "unexpected message argument types");
                return FALSE;
        }
 
@@ -700,7 +626,6 @@ static dbus_bool_t _wpa_dbus_dict_entry_get_byte_array(
        if (!buffer)
                return FALSE;
 
-       entry->bytearray_value = buffer;
        entry->array_len = 0;
        while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_BYTE) {
                char byte;
@@ -711,21 +636,20 @@ static dbus_bool_t _wpa_dbus_dict_entry_get_byte_array(
                                BYTE_ARRAY_ITEM_SIZE);
                        if (nbuffer == NULL) {
                                os_free(buffer);
-                               wpa_printf(MSG_ERROR, "dbus: _wpa_dbus_dict_"
-                                          "entry_get_byte_array out of "
-                                          "memory trying to retrieve the "
-                                          "string array");
+                               wpa_printf(MSG_ERROR,
+                                          "dbus: %s out of memory trying to retrieve the string array",
+                                          __func__);
                                goto done;
                        }
                        buffer = nbuffer;
                }
-               entry->bytearray_value = buffer;
 
                dbus_message_iter_get_basic(iter, &byte);
-               entry->bytearray_value[count] = byte;
+               buffer[count] = byte;
                entry->array_len = ++count;
                dbus_message_iter_next(iter);
        }
+       entry->bytearray_value = buffer;
        wpa_hexdump_key(MSG_MSGDUMP, "dbus: byte array contents",
                        entry->bytearray_value, entry->array_len);
 
@@ -750,18 +674,16 @@ static dbus_bool_t _wpa_dbus_dict_entry_get_string_array(
        struct wpa_dbus_dict_entry *entry)
 {
        dbus_uint32_t count = 0;
-       dbus_bool_t success = FALSE;
        char **buffer, **nbuffer;
 
        entry->strarray_value = NULL;
+       entry->array_len = 0;
        entry->array_type = DBUS_TYPE_STRING;
 
        buffer = os_calloc(STR_ARRAY_CHUNK_SIZE, STR_ARRAY_ITEM_SIZE);
        if (buffer == NULL)
                return FALSE;
 
-       entry->strarray_value = buffer;
-       entry->array_len = 0;
        while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING) {
                const char *value;
                char *str;
@@ -771,31 +693,29 @@ static dbus_bool_t _wpa_dbus_dict_entry_get_string_array(
                                buffer, count + STR_ARRAY_CHUNK_SIZE,
                                STR_ARRAY_ITEM_SIZE);
                        if (nbuffer == NULL) {
-                               os_free(buffer);
-                               wpa_printf(MSG_ERROR, "dbus: _wpa_dbus_dict_"
-                                          "entry_get_string_array out of "
-                                          "memory trying to retrieve the "
-                                          "string array");
-                               goto done;
+                               wpa_printf(MSG_ERROR,
+                                          "dbus: %s out of memory trying to retrieve the string array",
+                                          __func__);
+                               goto fail;
                        }
                        buffer = nbuffer;
                }
-               entry->strarray_value = buffer;
 
                dbus_message_iter_get_basic(iter, &value);
                wpa_printf(MSG_MSGDUMP, "%s: string_array value: %s",
                           __func__, wpa_debug_show_keys ? value : "[omitted]");
                str = os_strdup(value);
                if (str == NULL) {
-                       wpa_printf(MSG_ERROR, "dbus: _wpa_dbus_dict_entry_get_"
-                                  "string_array out of memory trying to "
-                                  "duplicate the string array");
-                       goto done;
+                       wpa_printf(MSG_ERROR,
+                                  "dbus: %s out of memory trying to duplicate the string array",
+                                  __func__);
+                       goto fail;
                }
-               entry->strarray_value[count] = str;
-               entry->array_len = ++count;
+               buffer[count++] = str;
                dbus_message_iter_next(iter);
        }
+       entry->strarray_value = buffer;
+       entry->array_len = count;
        wpa_printf(MSG_MSGDUMP, "%s: string_array length %u",
                   __func__, entry->array_len);
 
@@ -805,10 +725,15 @@ static dbus_bool_t _wpa_dbus_dict_entry_get_string_array(
                entry->strarray_value = NULL;
        }
 
-       success = TRUE;
+       return TRUE;
 
-done:
-       return success;
+fail:
+       while (count > 0) {
+               count--;
+               os_free(buffer[count]);
+       }
+       os_free(buffer);
+       return FALSE;
 }
 
 
@@ -864,7 +789,7 @@ static dbus_bool_t _wpa_dbus_dict_entry_get_binarray(
                os_memset(&tmpentry, 0, sizeof(tmpentry));
                tmpentry.type = DBUS_TYPE_ARRAY;
                if (_wpa_dbus_dict_entry_get_byte_array(&iter_array, &tmpentry)
-                                       == FALSE)
+                   == FALSE)
                        goto cleanup;
 
                entry->binarray_value[entry->array_len] =
@@ -903,7 +828,7 @@ static dbus_bool_t _wpa_dbus_dict_entry_get_array(
 
        dbus_message_iter_recurse(iter_dict_val, &iter_array);
 
-       switch (array_type) {
+       switch (array_type) {
        case DBUS_TYPE_BYTE:
                success = _wpa_dbus_dict_entry_get_byte_array(&iter_array,
                                                              entry);
@@ -1117,6 +1042,8 @@ void wpa_dbus_dict_entry_clear(struct wpa_dbus_dict_entry *entry)
                        os_free(entry->bytearray_value);
                        break;
                case DBUS_TYPE_STRING:
+                       if (!entry->strarray_value)
+                               break;
                        for (i = 0; i < entry->array_len; i++)
                                os_free(entry->strarray_value[i]);
                        os_free(entry->strarray_value);