From: Daniel Wagner <[email protected]>

---
 plugins/session_policy_ivi.c | 94 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 92 insertions(+), 2 deletions(-)

diff --git a/plugins/session_policy_ivi.c b/plugins/session_policy_ivi.c
index c4e0e42..d52b345 100644
--- a/plugins/session_policy_ivi.c
+++ b/plugins/session_policy_ivi.c
@@ -58,6 +58,8 @@ struct policy_data {
 
 static void cleanup_policy(struct policy_data *policy)
 {
+       DBG("policy %p", policy);
+
        if (policy == NULL)
                return;
 
@@ -212,9 +214,96 @@ static struct connman_session_policy session_policy_ivi = {
        .destroy = policy_ivi_destroy,
 };
 
+static GKeyFile *load_keyfile(const char *pathname)
+{
+       GKeyFile *keyfile = NULL;
+       GError *error = NULL;
+
+       DBG("Loading %s", pathname);
+
+       keyfile = g_key_file_new();
+
+       if (!g_key_file_load_from_file(keyfile, pathname, 0, &error)) {
+               DBG("Unable to load %s: %s", pathname, error->message);
+               g_clear_error(&error);
+
+               g_key_file_free(keyfile);
+               keyfile = NULL;
+       }
+
+       return keyfile;
+}
+
 static int load_policy(struct policy_data *policy)
 {
-       return 0;
+       struct connman_session_config *config = policy->config;
+       GKeyFile *keyfile;
+       char *pathname;
+       char *str, **tokens;
+       int i, err = 0;
+
+       pathname = g_strdup_printf("%s/%s.policy", STORAGEDIR, policy->ident);
+       if(pathname == NULL)
+               return -ENOMEM;
+
+       keyfile = load_keyfile(pathname);
+       if (keyfile == NULL) {
+               g_free(pathname);
+               return -ENOMEM;
+       }
+
+       config->priority = g_key_file_get_boolean(keyfile, "Default",
+                                               "Priority", NULL);
+
+       str = g_key_file_get_string(keyfile, "Default", "RoamingPolicy",
+                               NULL);
+       if (str != NULL) {
+               config->roaming_policy = 
connman_session_parse_roaming_policy(str);
+               g_free(str);
+       } else {
+               config->roaming_policy = CONNMAN_SESSION_ROAMING_POLICY_DEFAULT;
+       }
+
+       str = g_key_file_get_string(keyfile, "Default", "ConnectionType",
+                               NULL);
+       if (str != NULL) {
+               config->type = connman_session_parse_connection_type(str);
+               g_free(str);
+       } else {
+               config->type = CONNMAN_SESSION_TYPE_ANY;
+       }
+
+       config->ecall = g_key_file_get_boolean(keyfile, "Default",
+                                               "EmergencyCall", NULL);
+
+       connman_session_free_bearers(config->allowed_bearers);
+       config->allowed_bearers = NULL;
+
+       str = g_key_file_get_string(keyfile, "Default", "AllowedBearers",
+                               NULL);
+
+       if (str != NULL) {
+               tokens = g_strsplit(str, " ", 0);
+
+               for (i = 0; tokens[i] != NULL; i++) {
+                       err = connman_session_parse_allowed_bearers(tokens[i],
+                                       &config->allowed_bearers);
+                       if (err < 0)
+                               break;
+               }
+
+               g_free(str);
+               g_strfreev(tokens);
+       } else {
+               config->allowed_bearers = connman_session_allowed_bearers_any();
+               if (config->allowed_bearers == NULL)
+                       err = -ENOMEM;
+       }
+
+       g_key_file_free(keyfile);
+       g_free(pathname);
+
+       return err;
 }
 
 static struct policy_data *create_policy(const char *ident)
@@ -293,7 +382,8 @@ static void notify_handler(struct inotify_event *event,
                if (policy != NULL) {
                        load_policy(policy);
 
-                       connman_session_config_update(policy->session);
+                       if (policy->session != NULL)
+                               connman_session_config_update(policy->session);
                }
        }
 
-- 
1.7.12.1.382.gb0576a6

_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman

Reply via email to