Load policy configuration from storage
authorMarcel Holtmann <marcel@holtmann.org>
Fri, 5 Dec 2008 20:52:06 +0000 (21:52 +0100)
committerMarcel Holtmann <marcel@holtmann.org>
Fri, 5 Dec 2008 20:52:06 +0000 (21:52 +0100)
src/connman.h
src/element.c
src/storage.c

index 82916f1..c42859f 100644 (file)
@@ -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);
index 0fd230b..36f4090 100644 (file)
@@ -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)
 {
index 1aeda88..d8c32f4 100644 (file)
@@ -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);