summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPatrik Flykt <patrik.flykt@linux.intel.com>2012-01-25 13:49:38 +0200
committerSamuel Ortiz <sameo@linux.intel.com>2012-01-27 11:21:24 +0100
commit69e9601413d310a4dfc4b41944a0a34b94ddb4c5 (patch)
tree58e3cca7e6150a357421480600d183863befaca3 /src
parentb2704afd9588cdbdd1f68aa0d3b78473dec26c55 (diff)
downloadconnman-69e9601413d310a4dfc4b41944a0a34b94ddb4c5.tar.gz
connman-69e9601413d310a4dfc4b41944a0a34b94ddb4c5.tar.bz2
connman-69e9601413d310a4dfc4b41944a0a34b94ddb4c5.zip
storage: Function to fetch all saved providers
Implement __connman_storage_get_providers() to fetch all stored providers.
Diffstat (limited to 'src')
-rw-r--r--src/connman.h1
-rw-r--r--src/storage.c49
2 files changed, 50 insertions, 0 deletions
diff --git a/src/connman.h b/src/connman.h
index 8e725f41..d60e601d 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -165,6 +165,7 @@ GKeyFile *__connman_storage_open_service(const char *ident);
void __connman_storage_save_service(GKeyFile *keyfile, const char *ident);
GKeyFile *__connman_storage_load_provider(const char *identifier);
void __connman_storage_save_provider(GKeyFile *keyfile, const char *identifier);
+char **__connman_storage_get_providers(void);
int __connman_detect_init(void);
void __connman_detect_cleanup(void);
diff --git a/src/storage.c b/src/storage.c
index 54c023dd..75a1b0b8 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -328,6 +328,55 @@ void __connman_storage_save_provider(GKeyFile *keyfile, const char *identifier)
g_free(pathname);
}
+gchar **__connman_storage_get_providers(void)
+{
+ GSList *list = NULL;
+ int num = 0, i = 0;
+ struct dirent *d;
+ gchar *str;
+ DIR *dir;
+ struct stat buf;
+ int ret;
+ char **providers;
+ GSList *iter;
+
+ dir = opendir(STORAGEDIR);
+ if (dir == NULL)
+ return NULL;
+
+ while ((d = readdir(dir))) {
+ if (strcmp(d->d_name, ".") == 0 ||
+ strcmp(d->d_name, "..") == 0 ||
+ strncmp(d->d_name, "provider_", 9) != 0)
+ continue;
+
+ if (d->d_type == DT_DIR) {
+ str = g_strdup_printf("%s/%s/settings", STORAGEDIR,
+ d->d_name);
+ ret = stat(str, &buf);
+ g_free(str);
+ if (ret < 0)
+ continue;
+ list = g_slist_prepend(list, g_strdup(d->d_name));
+ num += 1;
+ }
+ }
+
+ closedir(dir);
+
+ providers = g_try_new0(char *, num + 1);
+ for (iter = list; iter != NULL; iter = g_slist_next(iter)) {
+ if (providers != NULL)
+ providers[i] = iter->data;
+ else
+ g_free(iter->data);
+ i += 1;
+ }
+ g_slist_free(list);
+
+ return providers;
+}
+
/*
* This function migrates keys from default.profile to settings file.
* This can be removed once the migration is over.