From d58d6a1fc8aea4ac47f815d3217e3f6a19be378a Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 5 Dec 2008 21:52:06 +0100 Subject: [PATCH] Load policy configuration from storage --- src/connman.h | 1 + src/element.c | 14 ++++++++++++++ src/storage.c | 12 +++++++++--- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/connman.h b/src/connman.h index 82916f1..c42859f 100644 --- a/src/connman.h +++ b/src/connman.h @@ -80,6 +80,7 @@ const char *__connman_element_type2string(enum connman_element_type type); 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); diff --git a/src/element.c b/src/element.c index 0fd230b..36f4090 100644 --- a/src/element.c +++ b/src/element.c @@ -166,6 +166,20 @@ const char *__connman_element_policy2string(enum connman_element_policy policy) return NULL; } +enum connman_element_policy __connman_element_string2policy(const char *policy) +{ + if (strcasecmp(policy, "off") == 0) + return CONNMAN_ELEMENT_POLICY_OFF; + else if (strcasecmp(policy, "ignore") == 0) + return CONNMAN_ELEMENT_POLICY_IGNORE; + else if (strcasecmp(policy, "auto") == 0) + return CONNMAN_ELEMENT_POLICY_AUTO; + else if (strcasecmp(policy, "ask") == 0) + return CONNMAN_ELEMENT_POLICY_ASK; + else + return CONNMAN_ELEMENT_POLICY_UNKNOWN; +} + static void append_property(DBusMessageIter *dict, struct connman_property *property) { diff --git a/src/storage.c b/src/storage.c index 1aeda88..d8c32f4 100644 --- a/src/storage.c +++ b/src/storage.c @@ -44,6 +44,11 @@ static int do_load(GKeyFile *keyfile, struct connman_element *element) 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); + + value = g_key_file_get_string(keyfile, element->path, "WiFi.Security", NULL); if (value != NULL) connman_element_set_property(element, @@ -98,14 +103,15 @@ 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); - value = __connman_element_policy2string(element->policy); - if (value != NULL) - g_key_file_set_string(keyfile, element->path, "Policy", value); + 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); -- 2.7.4