diff options
author | Alok Barsode <alok.barsode@linux.intel.com> | 2011-08-25 16:52:17 +0300 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2011-09-12 11:40:47 +0200 |
commit | d60b5edf7fd2ed4eb779e68a139359b4573385eb (patch) | |
tree | f63f4fc13f44bc0bf13e0f755342ec36a4a47b97 /src/storage.c | |
parent | 39245ddf5d1a220702a03683b78f1b868606c60a (diff) | |
download | connman-d60b5edf7fd2ed4eb779e68a139359b4573385eb.tar.gz connman-d60b5edf7fd2ed4eb779e68a139359b4573385eb.tar.bz2 connman-d60b5edf7fd2ed4eb779e68a139359b4573385eb.zip |
storage: Switch to <service_id> directories
Service settings would now reside in /var/lib/connman/service_id/settings.
we fallback on /var/lib/connman/default.profile for a smooth transition.
Diffstat (limited to 'src/storage.c')
-rw-r--r-- | src/storage.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/storage.c b/src/storage.c index faf2652e..4e30a77b 100644 --- a/src/storage.c +++ b/src/storage.c @@ -25,12 +25,16 @@ #include <errno.h> #include <unistd.h> +#include <sys/stat.h> #include "connman.h" #define SETTINGS "settings" #define DEFAULT "default.profile" +#define MODE (S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | \ + S_IXGRP | S_IROTH | S_IXOTH) + static GKeyFile *storage_load(const char *pathname) { GKeyFile *keyfile = NULL; @@ -157,6 +161,83 @@ void __connman_storage_delete_config(const char *ident) g_free(pathname); } +GKeyFile *__connman_storage_open_service(const char *service_id) +{ + gchar *pathname; + GKeyFile *keyfile = NULL; + + pathname = g_strdup_printf("%s/%s/%s", STORAGEDIR, service_id, SETTINGS); + if(pathname == NULL) + return NULL; + + keyfile = storage_load(pathname); + if (keyfile) { + g_free(pathname); + return keyfile; + } + + g_free(pathname); + + keyfile = g_key_file_new(); + + return keyfile; +} + +GKeyFile *__connman_storage_load_service(const char *service_id) +{ + gchar *pathname; + GKeyFile *keyfile = NULL; + + pathname = g_strdup_printf("%s/%s/%s", STORAGEDIR, service_id, SETTINGS); + if(pathname == NULL) + return NULL; + + keyfile = storage_load(pathname); + if (keyfile) { + g_free(pathname); + return keyfile; + } + + g_free(pathname); + + pathname = g_strdup_printf("%s/%s", STORAGEDIR, DEFAULT); + if(pathname == NULL) + return NULL; + + keyfile = storage_load(pathname); + + g_free(pathname); + + return keyfile; +} + +void __connman_storage_save_service(GKeyFile *keyfile, const char *service_id) +{ + gchar *pathname, *dirname; + + dirname = g_strdup_printf("%s/%s", STORAGEDIR, service_id); + if(dirname == NULL) + return; + + /* If the dir doesn't exist, create it */ + if (!g_file_test(dirname, G_FILE_TEST_IS_DIR)) { + if(mkdir(dirname, MODE) < 0) { + if (errno != EEXIST) { + g_free(dirname); + return; + } + } + } + + pathname = g_strdup_printf("%s/%s", dirname, SETTINGS); + + g_free(dirname); + + storage_save(keyfile, pathname); + + g_free(pathname); +} + /* * This function migrates keys from default.profile to settings file. * This can be removed once the migration is over. |