summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2009-07-22 13:50:17 +0200
committerMarcel Holtmann <marcel@holtmann.org>2009-07-22 13:50:17 +0200
commit3075ba51dfe9811150992de995419cb1f10701a7 (patch)
tree4e56f5cf3cedc0fa9071a7416ec04eb6926903a0
parentb739e1450da442f2e9ce46e6add0db9c019cceab (diff)
downloadconnman-3075ba51dfe9811150992de995419cb1f10701a7.tar.gz
connman-3075ba51dfe9811150992de995419cb1f10701a7.tar.bz2
connman-3075ba51dfe9811150992de995419cb1f10701a7.zip
Add common helpers for keyfile storage
-rw-r--r--src/connman.h3
-rw-r--r--src/storage.c66
2 files changed, 69 insertions, 0 deletions
diff --git a/src/connman.h b/src/connman.h
index 0b5c091b..ce286fc4 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -128,6 +128,9 @@ int __connman_resolver_selftest(void);
int __connman_storage_init(void);
void __connman_storage_cleanup(void);
+GKeyFile *__connman_storage_open(void);
+void __connman_storage_close(GKeyFile *keyfile, gboolean save);
+
int __connman_storage_load_global();
int __connman_storage_save_global();
diff --git a/src/storage.c b/src/storage.c
index 2018cf25..88443f9e 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -66,6 +66,72 @@ void connman_storage_unregister(struct connman_storage *storage)
storage_list = g_slist_remove(storage_list, storage);
}
+GKeyFile *__connman_storage_open(void)
+{
+ GKeyFile *keyfile;
+ gchar *pathname, *data = NULL;
+ gboolean result;
+ gsize length;
+
+ DBG("");
+
+ pathname = g_strdup_printf("%s/%s.conf", STORAGEDIR,
+ __connman_profile_active_ident());
+ if (pathname == NULL)
+ return NULL;
+
+ result = g_file_get_contents(pathname, &data, &length, NULL);
+
+ g_free(pathname);
+
+ if (result == FALSE)
+ return NULL;
+
+ keyfile = g_key_file_new();
+
+ if (length > 0) {
+ if (g_key_file_load_from_data(keyfile, data, length,
+ 0, NULL) == FALSE)
+ goto done;
+ }
+
+done:
+ g_free(data);
+
+ DBG("keyfile %p", keyfile);
+
+ return keyfile;
+}
+
+void __connman_storage_close(GKeyFile *keyfile, gboolean save)
+{
+ gchar *pathname, *data = NULL;
+ gsize length = 0;
+
+ DBG("keyfile %p save %d", keyfile, save);
+
+ if (save == FALSE) {
+ g_key_file_free(keyfile);
+ return;
+ }
+
+ pathname = g_strdup_printf("%s/%s.conf", STORAGEDIR,
+ __connman_profile_active_ident());
+ if (pathname == NULL)
+ return;
+
+ data = g_key_file_to_data(keyfile, &length, NULL);
+
+ if (g_file_set_contents(pathname, data, length, NULL) == FALSE)
+ connman_error("Failed to store information");
+
+ g_free(data);
+
+ g_free(pathname);
+
+ g_key_file_free(keyfile);
+}
+
int __connman_storage_load_global(void)
{
GSList *list;