--- include/storage.h | 37 ++++++++++++++++++++++++++++++++++++ src/storage.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 0 deletions(-) create mode 100644 include/storage.h
diff --git a/include/storage.h b/include/storage.h new file mode 100644 index 0000000..cd05c60 --- /dev/null +++ b/include/storage.h @@ -0,0 +1,37 @@ +/* + * + * Connection Manager + * + * Copyright (C) 2011 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __CONNMAN_STORAGE_H +#define __CONNMAN_STORAGE_H + +#include <glib.h> + +#ifdef __cplusplus +extern "C" { +#endif + +gchar **connman_storage_get_services(); + +#ifdef __cplusplus +} +#endif + +#endif /* __CONNMAN_STORAGE_H */ diff --git a/src/storage.c b/src/storage.c index 4e30a77..1755650 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; -- 1.7.1 _______________________________________________ connman mailing list connman@connman.net http://lists.connman.net/listinfo/connman