summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am3
-rw-r--r--include/storage.h37
-rw-r--r--src/storage.c54
3 files changed, 93 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am
index b3849917..9b1b3745 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -6,7 +6,8 @@ includedir = @includedir@/connman
include_HEADERS = include/types.h include/log.h include/plugin.h \
include/notifier.h include/service.h \
include/resolver.h include/ipconfig.h \
- include/device.h include/network.h include/inet.h
+ include/device.h include/network.h include/inet.h \
+ include/storage.h
nodist_include_HEADERS = include/version.h
diff --git a/include/storage.h b/include/storage.h
new file mode 100644
index 00000000..cd05c60b
--- /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 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;