From: Daniel Wagner <[email protected]>
---
plugins/session_policy_ivi.c | 116 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 116 insertions(+)
diff --git a/plugins/session_policy_ivi.c b/plugins/session_policy_ivi.c
index 063e763..5e6b04b 100644
--- a/plugins/session_policy_ivi.c
+++ b/plugins/session_policy_ivi.c
@@ -24,6 +24,7 @@
#endif
#include <errno.h>
+#include <string.h>
#include <glib.h>
@@ -38,6 +39,7 @@
static DBusConnection *connection;
static GHashTable *session_hash;
+static GHashTable *ident_hash;
struct create_data {
struct connman_session *session;
@@ -46,6 +48,7 @@ struct create_data {
};
struct policy_data {
+ char *ident;
struct connman_session *session;
struct connman_session_config *config;
@@ -59,6 +62,7 @@ static void cleanup_policy(struct policy_data *policy)
if (policy->config != NULL)
connman_session_free_bearers(policy->config->allowed_bearers);
+ g_free(policy->ident);
g_free(policy->config);
g_free(policy);
}
@@ -174,6 +178,101 @@ static struct connman_session_policy session_policy_ivi =
{
.destroy = policy_ivi_destroy,
};
+static int load_policy(struct policy_data *policy)
+{
+ return 0;
+}
+
+static struct policy_data *create_policy(const char *ident)
+{
+ struct policy_data *policy;
+ char *key;
+
+ DBG("ident %s", ident);
+
+ if (g_hash_table_lookup(ident_hash, ident) != NULL)
+ return NULL;
+
+ policy = g_try_new0(struct policy_data, 1);
+ if (policy == NULL)
+ return NULL;
+
+ key = g_strdup(ident);
+ policy->ident = g_strdup(ident);
+ policy->config = new_config();
+
+ if (key == NULL || policy->ident == NULL || policy->config == NULL) {
+ g_free(key);
+ cleanup_policy(policy);
+ return NULL;
+ }
+
+ g_hash_table_replace(ident_hash, key, policy);
+
+ connman_info("Adding configuration %s", ident);
+
+ return policy;
+}
+
+static connman_bool_t validate_ident(const char *ident)
+{
+ unsigned int i;
+
+ if (ident == NULL)
+ return FALSE;
+
+ for (i = 0; i < strlen(ident); i++)
+ if (g_ascii_isprint(ident[i]) == FALSE)
+ return FALSE;
+
+ return TRUE;
+}
+
+static int read_policies(void)
+{
+ GDir *dir;
+
+ DBG("");
+
+ dir = g_dir_open(STORAGEDIR, 0, NULL);
+ if (dir != NULL) {
+ const gchar *file;
+
+ while ((file = g_dir_read_name(dir)) != NULL) {
+ GString *str;
+ gchar *ident;
+
+ if (g_str_has_suffix(file, ".policy") == FALSE)
+ continue;
+
+ ident = g_strrstr(file, ".policy");
+ if (ident == NULL)
+ continue;
+
+ str = g_string_new_len(file, ident - file);
+ if (str == NULL)
+ continue;
+
+ ident = g_string_free(str, FALSE);
+
+ if (validate_ident(ident) == TRUE) {
+ struct policy_data *policy;
+
+ policy = create_policy(ident);
+ if (policy != NULL)
+ load_policy(policy);
+ } else {
+ connman_error("Invalid config ident %s", ident);
+ }
+ g_free(ident);
+ }
+
+ g_dir_close(dir);
+ }
+
+ return 0;
+}
+
static int session_policy_ivi_init(void)
{
int err;
@@ -194,9 +293,25 @@ static int session_policy_ivi_init(void)
goto err;
}
+ ident_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+ g_free, NULL);
+ if (ident_hash == NULL) {
+ err = -ENOMEM;
+ connman_session_policy_unregister(&session_policy_ivi);
+ goto err;
+ }
+
+ read_policies();
+
return 0;
err:
+ if (session_hash != NULL)
+ g_hash_table_destroy(session_hash);
+
+ if (ident_hash != NULL)
+ g_hash_table_destroy(ident_hash);
+
dbus_connection_unref(connection);
return err;
@@ -216,6 +331,7 @@ static void session_policy_ivi_exit(void)
}
g_hash_table_destroy(session_hash);
+ g_hash_table_destroy(ident_hash);
connman_session_policy_unregister(&session_policy_ivi);
--
1.7.12.1.382.gb0576a6
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman