aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRonald Tessier <ronald.tessier@linux.intel.com>2012-08-06 17:30:57 +0200
committerDenis Kenzior <denkenz@gmail.com>2012-08-07 02:16:14 -0500
commit41b558061680fc9b79c12e5a15a94c53ceca8741 (patch)
tree969ef132c1f69fc8bd7b658187680e05ae2abbad
parentd72e509e2c7513da887076740470c34c0e24bf61 (diff)
downloadmmsd-41b558061680fc9b79c12e5a15a94c53ceca8741.tar.gz
store: Add utilities for mms settings file access
-rw-r--r--src/store.c56
-rw-r--r--src/store.h4
2 files changed, 60 insertions, 0 deletions
diff --git a/src/store.c b/src/store.c
index 88d9e77..b09c17b 100644
--- a/src/store.c
+++ b/src/store.c
@@ -358,3 +358,59 @@ void mms_store_meta_close(const char *service_id, const char *uuid,
g_key_file_free(keyfile);
}
+
+GKeyFile *mms_settings_open(const char *service_id, const char *store)
+{
+ GKeyFile *keyfile;
+ char *path;
+
+ if (store == NULL)
+ return NULL;
+
+ path = mms_store_get_path(service_id, store);
+ if (path == NULL)
+ return NULL;
+
+ if (create_dirs(path, S_IRUSR | S_IWUSR | S_IXUSR) != 0) {
+ mms_error("Failed to create path %s", path);
+
+ g_free(path);
+ return NULL;
+ }
+
+ keyfile = g_key_file_new();
+
+ g_key_file_load_from_file(keyfile, path, 0, NULL);
+
+ g_free(path);
+
+ return keyfile;
+}
+
+static void settings_sync(const char *service_id, const char *store,
+ GKeyFile *keyfile)
+{
+ char *path;
+ char *data;
+ gsize length = 0;
+
+ path = mms_store_get_path(service_id, store);
+ if (path == NULL)
+ return;
+
+ data = g_key_file_to_data(keyfile, &length, NULL);
+
+ g_file_set_contents(path, data, length, NULL);
+
+ g_free(data);
+ g_free(path);
+}
+
+void mms_settings_close(const char *service_id, const char *store,
+ GKeyFile *keyfile, gboolean save)
+{
+ if (save == TRUE)
+ settings_sync(service_id, store, keyfile);
+
+ g_key_file_free(keyfile);
+}
diff --git a/src/store.h b/src/store.h
index 21f11be..ba2c080 100644
--- a/src/store.h
+++ b/src/store.h
@@ -28,3 +28,7 @@ char *mms_store_get_path(const char *service_id, const char *uuid);
GKeyFile *mms_store_meta_open(const char *service_id, const char *uuid);
void mms_store_meta_close(const char *service_id, const char *uuid,
GKeyFile *keyfile, gboolean save);
+
+GKeyFile *mms_settings_open(const char *service_id, const char *store);
+void mms_settings_close(const char *service_id, const char *store,
+ GKeyFile *keyfile, gboolean save);