From 8b47a6c99ab920165ff2919cbf7a2b214fb0b0c1 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 5 Jan 2009 02:23:44 +0100 Subject: [PATCH] Remove element specific storage functions --- src/connman.h | 3 -- src/element.c | 4 -- src/storage.c | 165 ---------------------------------------------------------- 3 files changed, 172 deletions(-) diff --git a/src/connman.h b/src/connman.h index 4e59e53..e36b45d 100644 --- a/src/connman.h +++ b/src/connman.h @@ -120,9 +120,6 @@ const char *__connman_element_subtype2string(enum connman_element_subtype type); const char *__connman_element_policy2string(enum connman_element_policy policy); enum connman_element_policy __connman_element_string2policy(const char *policy); -int __connman_element_load(struct connman_element *element); -int __connman_element_store(struct connman_element *element); - static inline void __connman_element_lock(struct connman_element *element) { } diff --git a/src/element.c b/src/element.c index 28d362e..ebe52c6 100644 --- a/src/element.c +++ b/src/element.c @@ -1586,8 +1586,6 @@ static void register_element(gpointer data, gpointer user_data) DBG("element %p path %s", element, element->path); - __connman_element_load(element); - g_node_append_data(node, element); if (element->type == CONNMAN_ELEMENT_TYPE_CONNECTION) { @@ -1606,8 +1604,6 @@ static void register_element(gpointer data, gpointer user_data) emit_element_signal(connection, "ElementAdded", element); - __connman_element_store(element); - if (started == FALSE) return; diff --git a/src/storage.c b/src/storage.c index 6bbe051..d881a5c 100644 --- a/src/storage.c +++ b/src/storage.c @@ -149,168 +149,3 @@ void __connman_storage_cleanup(void) { DBG(""); } - -static int do_load(GKeyFile *keyfile, struct connman_element *element) -{ - const gchar *value; - - DBG("element %p name %s", element, element->name); - - value = g_key_file_get_string(keyfile, element->path, - "Policy", NULL); - if (value != NULL) - element->policy = __connman_element_string2policy(value); - - if (element->type == CONNMAN_ELEMENT_TYPE_NETWORK) - element->remember = g_key_file_get_boolean(keyfile, - element->path, "Remember", NULL); - - value = g_key_file_get_string(keyfile, element->path, - "WiFi.Security", NULL); - if (value != NULL) - connman_element_set_property(element, - CONNMAN_PROPERTY_ID_WIFI_SECURITY, &value); - - value = g_key_file_get_string(keyfile, element->path, - "WiFi.Passphrase", NULL); - if (value != NULL) - connman_element_set_property(element, - CONNMAN_PROPERTY_ID_WIFI_PASSPHRASE, &value); - - return 0; -} - -int __connman_element_load(struct connman_element *element) -{ - GKeyFile *keyfile; - gchar *pathname, *data = NULL; - gsize length; - - 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 (g_file_get_contents(pathname, &data, &length, NULL) == FALSE) { - g_free(pathname); - return -ENOENT; - } - - g_free(pathname); - - if (g_key_file_load_from_data(keyfile, data, length, - 0, NULL) == FALSE) { - g_free(data); - return -EILSEQ; - } - - g_free(data); - - do_load(keyfile, element); - - g_key_file_free(keyfile); - - return 0; -} - -static void do_update(GKeyFile *keyfile, struct connman_element *element) -{ - GSList *list; - char *value; - const char *str; - - DBG("element %p name %s", element, element->name); - - g_key_file_set_string(keyfile, element->path, "Name", element->name); - - str = __connman_element_policy2string(element->policy); - if (str != NULL) - g_key_file_set_string(keyfile, element->path, "Policy", str); - - //g_key_file_set_boolean(keyfile, element->path, "Enabled", - // element->enabled); - - if (element->type == CONNMAN_ELEMENT_TYPE_NETWORK) - g_key_file_set_boolean(keyfile, element->path, "Remember", - element->remember); - - __connman_element_lock(element); - - for (list = element->properties; list; list = list->next) { - struct connman_property *property = list->data; - - if (property->flags & CONNMAN_PROPERTY_FLAG_STATIC) - continue; - - if (property->flags & CONNMAN_PROPERTY_FLAG_REFERENCE) - continue; - - if (property->type == DBUS_TYPE_STRING) - g_key_file_set_string(keyfile, element->path, - property->name, property->value); - } - - __connman_element_unlock(element); - - if (connman_element_get_value(element, - CONNMAN_PROPERTY_ID_WIFI_SECURITY, &value) == 0) - g_key_file_set_string(keyfile, element->path, - "WiFi.Security", value); - - if (connman_element_get_value(element, - CONNMAN_PROPERTY_ID_WIFI_PASSPHRASE, &value) == 0) - g_key_file_set_string(keyfile, element->path, - "WiFi.Passphrase", value); -} - -int __connman_element_store(struct connman_element *element) -{ - GKeyFile *keyfile; - gchar *pathname, *data = NULL; - gsize length; - - DBG("element %p name %s", element, element->name); - - if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE && - element->type != CONNMAN_ELEMENT_TYPE_NETWORK) - return -EINVAL; - - if (element->subtype == CONNMAN_ELEMENT_SUBTYPE_FAKE) - return -EINVAL; - - pathname = g_strdup_printf("%s/elements.conf", STORAGEDIR); - if (pathname == NULL) - return -ENOMEM; - - keyfile = g_key_file_new(); - - if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE) - goto update; - - if (length > 0) { - if (g_key_file_load_from_data(keyfile, data, length, - 0, NULL) == FALSE) - goto done; - } - - 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; -} -- 2.7.4