Hi Marcel,
On 07/10/2012 03:31 PM, Marcel Holtmann wrote:
Hi Jukka,
We need the list of provisioned services so that
all the hidden ones can be scanned.
---
Makefile.am | 2 +-
include/provision.h | 51 ++++++++++++++++++++++++++++++++++++++
src/config.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 120 insertions(+), 1 deletion(-)
create mode 100644 include/provision.h
+
+struct connman_config_item {
+ char *ident;
+ char *name;
+ void *ssid;
+ unsigned int ssid_len;
+ connman_bool_t hidden;
+};
+
+struct connman_config_item **connman_config_get_configs(void);
this needs to follow with an easy way to free the configs. You are open
coding the free at least twice.
Ok, np
In addition I would call this connman_config_get_entries and the
structure connman_config_entry.
If you wanna keep the _item, the call it at least get_items.
Sure
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_PROVISION_H */
diff --git a/src/config.c b/src/config.c
index 5363dc3..3b66a73 100644
--- a/src/config.c
+++ b/src/config.c
@@ -31,6 +31,7 @@
#include <sys/inotify.h>
#include <glib.h>
+#include <connman/provision.h>
#include "connman.h"
struct connman_config_service {
@@ -51,6 +52,7 @@ struct connman_config_service {
GSList *service_identifiers;
char *config_ident; /* file prefix */
char *config_entry; /* entry name */
+ connman_bool_t hidden;
};
struct connman_config {
@@ -938,3 +940,69 @@ int __connman_config_provision_service_ident(struct
connman_service *service,
return ret;
}
+
+struct connman_config_item **connman_config_get_configs(void)
+{
+ GHashTableIter iter_file, iter_config;
+ gpointer value, key;
+ struct connman_config_item **configs = NULL;
+ int i, count = 0;
+
+ g_hash_table_iter_init(&iter_file, config_table);
+ while (g_hash_table_iter_next(&iter_file, &key, &value) == TRUE) {
+ struct connman_config *config_file = value;
+
+ g_hash_table_iter_init(&iter_config,
+ config_file->service_table);
+ while (g_hash_table_iter_next(&iter_config, &key,
+ &value) == TRUE) {
+ struct connman_config_service *config = value;
+ configs = g_try_realloc(configs, (count + 1) *
+ sizeof(struct connman_config_item *));
+ if (configs == NULL)
+ return NULL;
Why are we doing this? We know the size of hash table. So allocate this
ahead of time,
We need to traverse two hashes so it complicates the issue. I changed
the code but IMHO the code looks now horrible.
+
+ configs[count] =
+ g_try_new0(struct connman_config_item, 1);
+ if (configs[count] == NULL)
+ goto cleanup;
And why this? Is not something simple like
g_try_new0(struct connman_config_item, count)
sufficient?
We have already allocated the array where the pointers should be, so it
makes it much simpler to allocate the individual structs one by one.
+
+ configs[count]->ident = g_strdup(config->ident);
+ configs[count]->name = g_strdup(config->name);
+ configs[count]->ssid = g_malloc0(config->ssid_len + 1);
+ if (configs[count]->ssid == NULL)
+ goto cleanup;
g_malloc0 is not going to fail, and don't bother zeroing the value if
you copy it fully anyway.
My mistake, I forgot to use the "try" version.
+
+ memcpy(configs[count]->ssid, config->ssid,
+ config->ssid_len);
+ configs[count]->ssid_len = config->ssid_len;
+ configs[count]->hidden = config->hidden;
+
+ count++;
+ }
+ }
+
+ if (configs != NULL) {
+ configs = g_try_realloc(configs, (count + 1) *
+ sizeof(struct connman_config_item *));
+ if (configs == NULL)
+ return NULL;
+
+ configs[count] = NULL;
+
+ DBG("%d provisioned AP found", count);
+ }
+
+ return configs;
+
+cleanup:
+ for (i = 0; i < count && configs && configs[i]; i++) {
+ g_free(configs[i]->ident);
+ g_free(configs[i]->name);
+ g_free(configs[i]->ssid);
+ g_free(configs[i]);
+ }
+
+ g_free(configs);
+ return NULL;
+}
Regards
Marcel
Cheers,
Jukka
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman