diff options
author | Patrik Flykt <patrik.flykt@linux.intel.com> | 2012-01-25 13:49:38 +0200 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2012-01-27 11:21:24 +0100 |
commit | 69e9601413d310a4dfc4b41944a0a34b94ddb4c5 (patch) | |
tree | 58e3cca7e6150a357421480600d183863befaca3 /src/storage.c | |
parent | b2704afd9588cdbdd1f68aa0d3b78473dec26c55 (diff) | |
download | connman-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/storage.c')
-rw-r--r-- | src/storage.c | 49 |
1 files changed, 49 insertions, 0 deletions
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. |