diff options
author | Jukka Rissanen <jukka.rissanen@linux.intel.com> | 2011-09-13 09:55:11 +0300 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2011-09-13 10:49:08 +0200 |
commit | d454f522bcb20ede1d93d0837625fd73c1062043 (patch) | |
tree | e35d99eddd5bf89dce03c2a73a1e3271f6938d91 /src/storage.c | |
parent | 6ee1229bb52c20131ac1cc0c1cb44b1846bb6d67 (diff) | |
download | connman-d454f522bcb20ede1d93d0837625fd73c1062043.tar.gz connman-d454f522bcb20ede1d93d0837625fd73c1062043.tar.bz2 connman-d454f522bcb20ede1d93d0837625fd73c1062043.zip |
storage: Add services getter
Diffstat (limited to 'src/storage.c')
-rw-r--r-- | src/storage.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/storage.c b/src/storage.c index 4e30a77b..1755650d 100644 --- a/src/storage.c +++ b/src/storage.c @@ -26,6 +26,9 @@ #include <errno.h> #include <unistd.h> #include <sys/stat.h> +#include <dirent.h> + +#include <connman/storage.h> #include "connman.h" @@ -183,6 +186,57 @@ GKeyFile *__connman_storage_open_service(const char *service_id) return keyfile; } +gchar **connman_storage_get_services() +{ + struct dirent *d; + gchar *str; + DIR *dir; + GString *result; + gchar **services = NULL; + struct stat buf; + int ret; + + dir = opendir(STORAGEDIR); + if (dir == NULL) + return NULL; + + result = g_string_new(NULL); + + while ((d = readdir(dir))) { + if (strcmp(d->d_name, ".") == 0 || + strcmp(d->d_name, "..") == 0) + continue; + + switch (d->d_type) { + case DT_DIR: + /* + * If the settings file is not found, then + * assume this directory is not a services dir. + */ + str = g_strdup_printf("%s/%s/settings", STORAGEDIR, + d->d_name); + ret = stat(str, &buf); + g_free(str); + if (ret < 0) + continue; + + g_string_append_printf(result, "%s/", d->d_name); + break; + } + } + + closedir(dir); + + str = g_string_free(result, FALSE); + if (str) { + str[strlen(str) - 1] = '\0'; + services = g_strsplit(str, "/", -1); + } + g_free(str); + + return services; +} + GKeyFile *__connman_storage_load_service(const char *service_id) { gchar *pathname; |