From 3d3d3056458ba3df7b2ae4a3c6c2adae699eb46f Mon Sep 17 00:00:00 2001 From: Witold Sowa Date: Wed, 11 Nov 2009 17:17:00 +0200 Subject: [PATCH] Add dbus mechanism for fetching all network configuration parameters --- wpa_supplicant/config.c | 53 +++++++++++++++++++ wpa_supplicant/config.h | 1 + wpa_supplicant/ctrl_iface_dbus_new_handlers.c | 8 +-- 3 files changed, 55 insertions(+), 7 deletions(-) diff --git a/wpa_supplicant/config.c b/wpa_supplicant/config.c index 97c303d8b..128fe717d 100644 --- a/wpa_supplicant/config.c +++ b/wpa_supplicant/config.c @@ -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 diff --git a/wpa_supplicant/config.h b/wpa_supplicant/config.h index 4484e91d9..b9f0da67e 100644 --- a/wpa_supplicant/config.h +++ b/wpa_supplicant/config.h @@ -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); diff --git a/wpa_supplicant/ctrl_iface_dbus_new_handlers.c b/wpa_supplicant/ctrl_iface_dbus_new_handlers.c index dab741316..40c5a23d5 100644 --- a/wpa_supplicant/ctrl_iface_dbus_new_handlers.c +++ b/wpa_supplicant/ctrl_iface_dbus_new_handlers.c @@ -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.");