summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2008-11-19 07:45:25 +0100
committerMarcel Holtmann <marcel@holtmann.org>2008-11-19 07:45:25 +0100
commitbf3f80d905bf9dadc9ad108625b6eb5fa15edd12 (patch)
tree5b8c096ba6dc1f8418bad7e203faa4f1571d2428 /src
parente204b1b0150df1d5904e509a1fbf5c12a66ed6f8 (diff)
downloadconnman-bf3f80d905bf9dadc9ad108625b6eb5fa15edd12.tar.gz
connman-bf3f80d905bf9dadc9ad108625b6eb5fa15edd12.tar.bz2
connman-bf3f80d905bf9dadc9ad108625b6eb5fa15edd12.zip
Store element properties in key files
Diffstat (limited to 'src')
-rw-r--r--src/storage.c128
1 files changed, 62 insertions, 66 deletions
diff --git a/src/storage.c b/src/storage.c
index d67d0d2c..24d0a5c8 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -23,99 +23,95 @@
#include <config.h>
#endif
-#if 0
-#include <sqlite3.h>
-#endif
-
#include "connman.h"
-#if 0
-static sqlite3 *db = NULL;
-
-static int create_tables(void)
+int __connman_storage_init(void)
{
- char *msg;
- int err;
+ DBG("");
+ return 0;
+}
+
+void __connman_storage_cleanup(void)
+{
DBG("");
+}
- err = sqlite3_exec(db, "CREATE TABLE properties ("
- "element TEXT NOT NULL,"
- "name TEXT NOT NULL,"
- "value TEXT NOT NULL,"
- "PRIMARY KEY(element, name))",
- NULL, NULL, &msg);
-
- if (err != SQLITE_OK) {
- connman_error("SQL error: %s", msg);
- sqlite3_free(msg);
- return -1;
- }
+int __connman_element_load(struct connman_element *element)
+{
+ DBG("element %p name %s", element, element->name);
return 0;
}
-#endif
-int __connman_storage_init(void)
+static void do_update(GKeyFile *keyfile, struct connman_element *element)
{
-#if 0
- int err;
+ GSList *list;
- DBG("");
+ DBG("element %p name %s", element, element->name);
-#if 0
- if (!sqlite3_threadsafe()) {
- connman_error("SQLite is missing thread support");
- return -1;
- }
-#endif
+ g_key_file_set_string(keyfile, element->path, "Name", element->name);
- err = sqlite3_open(STORAGEDIR "/config.db", &db);
- if (err != SQLITE_OK) {
- connman_error("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- return -1;
- }
+ g_key_file_set_boolean(keyfile, element->path, "Enabled",
+ element->enabled);
- create_tables();
-#endif
+ connman_element_lock(element);
- return 0;
-}
+ for (list = element->properties; list; list = list->next) {
+ struct connman_property *property = list->data;
-void __connman_storage_cleanup(void)
-{
-#if 0
- DBG("");
+ if (property->flags & CONNMAN_PROPERTY_FLAG_STATIC)
+ continue;
- sqlite3_close(db);
-#endif
-}
+ if (property->flags & CONNMAN_PROPERTY_FLAG_REFERENCE)
+ continue;
-int __connman_element_load(struct connman_element *element)
-{
- return 0;
+ if (property->type == DBUS_TYPE_STRING)
+ g_key_file_set_string(keyfile, element->path,
+ property->name, property->value);
+ }
+
+ connman_element_unlock(element);
}
int __connman_element_store(struct connman_element *element)
{
-#if 0
- char *sql, *msg;
+ GKeyFile *keyfile;
+ gchar *pathname, *data = NULL;
+ gsize length;
- DBG("");
+ DBG("element %p name %s", element, element->name);
+
+ pathname = g_strdup_printf("%s/elements.conf", STORAGEDIR);
+ if (pathname == NULL)
+ return -ENOMEM;
+
+ keyfile = g_key_file_new();
- if (element->priority > 0) {
- sql = g_strdup_printf("INSERT INTO properties "
- "VALUES ('%s','%s','%d')",
- element->path, "Priority",
- element->priority);
+ if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE)
+ goto update;
- if (sqlite3_exec(db, sql, NULL, NULL, &msg) != SQLITE_OK) {
- connman_error("SQL error: %s", msg);
- sqlite3_free(msg);
- }
+ if (length > 0) {
+ if (g_key_file_load_from_data(keyfile, data, length,
+ G_KEY_FILE_KEEP_COMMENTS, NULL) == FALSE)
+ goto done;
}
-#endif
+
+ g_free(data);
+
+update:
+ do_update(keyfile, element);
+
+ data = g_key_file_to_data(keyfile, &length, NULL);
+
+ g_file_set_contents(pathname, data, length, NULL);
+
+done:
+ g_free(data);
+
+ g_key_file_free(keyfile);
+
+ g_free(pathname);
return 0;
}