Add dbus mechanism for fetching all network configuration parameters
authorWitold Sowa <witold.sowa@gmail.com>
Wed, 11 Nov 2009 15:17:00 +0000 (17:17 +0200)
committerJouni Malinen <j@w1.fi>
Wed, 11 Nov 2009 15:17:00 +0000 (17:17 +0200)
wpa_supplicant/config.c
wpa_supplicant/config.h
wpa_supplicant/ctrl_iface_dbus_new_handlers.c

index 97c303d..128fe71 100644 (file)
@@ -1832,6 +1832,59 @@ int wpa_config_set(struct wpa_ssid *ssid, const char *var, const char *value,
 }
 
 
+/**
+ * wpa_config_get_all - Get all options from network configuration
+ * @ssid: Pointer to network configuration data
+ * @get_keys: Determines if keys/passwords will be included in returned list
+ * Returns: %NULL terminated list of all set keys and their values in the form
+ * of [key1, val1, key2, val2, ... , NULL]
+ *
+ * This function can be used to get list of all configured network properties.
+ * The caller is responsible for freeing the returned list and all its
+ * elements.
+ */
+char ** wpa_config_get_all(struct wpa_ssid *ssid, int get_keys)
+{
+       const struct parse_data *field;
+       char *key, *value;
+       size_t i;
+       char **props;
+       int fields_num;
+
+       props = os_zalloc(sizeof(char *) * ((2 * NUM_SSID_FIELDS) + 1));
+       if (!props)
+               return NULL;
+
+       fields_num = 0;
+       for (i = 0; i < NUM_SSID_FIELDS; i++) {
+               field = &ssid_fields[i];
+               if (field->key_data && !get_keys)
+                       continue;
+               value = field->writer(field, ssid);
+               if (value == NULL || os_strlen(value) == 0)
+                       continue;
+
+               key = os_strdup(field->name);
+               if (key == NULL)
+                       goto err;
+
+               props[fields_num * 2] = key;
+               props[fields_num * 2 + 1] = value;
+
+               fields_num++;
+       }
+
+       return props;
+
+err:
+       value = *props;
+       while (value)
+               os_free(value++);
+       os_free(props);
+       return NULL;
+}
+
+
 #ifndef NO_CONFIG_WRITE
 /**
  * wpa_config_get - Get a variable in network configuration
index 4484e91..b9f0da6 100644 (file)
@@ -336,6 +336,7 @@ int wpa_config_remove_network(struct wpa_config *config, int id);
 void wpa_config_set_network_defaults(struct wpa_ssid *ssid);
 int wpa_config_set(struct wpa_ssid *ssid, const char *var, const char *value,
                   int line);
+char ** wpa_config_get_all(struct wpa_ssid *ssid, int get_keys);
 char * wpa_config_get(struct wpa_ssid *ssid, const char *var);
 char * wpa_config_get_no_key(struct wpa_ssid *ssid, const char *var);
 void wpa_config_update_psk(struct wpa_ssid *ssid);
index dab7413..40c5a23 100644 (file)
@@ -3026,13 +3026,7 @@ DBusMessage * wpas_dbus_getter_network_properties(
        DBusMessage *reply = NULL;
        DBusMessageIter iter, variant_iter, dict_iter;
        char **iterator;
-
-#if 0
-       /* FIX: decide what to do with wpa_config_get_all */
-       char** props = wpa_config_get_all(net->ssid, 0);
-#else
-       char **props = NULL;
-#endif
+       char **props = wpa_config_get_all(net->ssid, 0);
        if (!props) {
                perror("wpas_dbus_getter_network_properties[dbus] couldn't "
                       "read network properties. out of memory.");