From: Daniel Wagner <[email protected]>
Instead using glib's cleanup hooks for the hash table, we implement
it ourself. The reason for doing this is that we will use the
policy_data structure via a second hash table. So there is no
direct ownership between session_hash and policy_data after we add the
second hash table.
---
plugins/session_policy_ivi.c | 80 ++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 78 insertions(+), 2 deletions(-)
diff --git a/plugins/session_policy_ivi.c b/plugins/session_policy_ivi.c
index 8a7503a..1218523 100644
--- a/plugins/session_policy_ivi.c
+++ b/plugins/session_policy_ivi.c
@@ -37,29 +37,76 @@
static DBusConnection *connection;
+static GHashTable *session_hash;
+
struct create_data {
struct connman_session *session;
connman_session_config_cb callback;
void *user_data;
};
+struct policy_data {
+ struct connman_session *session;
+
+ struct connman_session_config *config;
+};
+
+static void cleanup_policy(struct policy_data *policy)
+{
+ if (policy == NULL)
+ return;
+
+ if (policy->config != NULL)
+ connman_session_free_bearers(policy->config->allowed_bearers);
+
+ g_free(policy->config);
+ g_free(policy);
+}
+
static void selinux_context_reply(unsigned char *context, unsigned int size,
void *user_data)
{
struct create_data *data = user_data;
+ struct policy_data *policy;
char *str;
DBG("session %p", data->session);
str = g_strndup((const gchar*)context, (gsize) size);
if (str == NULL)
- goto out;
+ goto err;
DBG("SELinux context %s", str);
-out:
+ policy = g_try_new0(struct policy_data, 1);
+ if (policy == NULL)
+ goto err;
+
+ policy->config = g_try_new0(struct connman_session_config, 1);
+ if (policy->config == NULL)
+ goto err;
+
+ policy->config->priority = FALSE;
+ policy->config->roaming_policy = CONNMAN_SESSION_ROAMING_POLICY_DEFAULT;
+ policy->config->type = CONNMAN_SESSION_TYPE_ANY;
+ policy->config->ecall = FALSE;
+ policy->config->allowed_bearers = connman_session_allowed_bearers_any();
+ if (policy->config->allowed_bearers == NULL)
+ goto err;
+
+ g_hash_table_replace(session_hash, data->session, policy);
+
+ (*data->callback)(data->session, policy->config, data->user_data);
+
+ g_free(data);
+ g_free(str);
+
+ return;
+err:
(*data->callback)(data->session, NULL, data->user_data);
+ cleanup_policy(policy);
+
g_free(data);
g_free(str);
}
@@ -96,7 +143,15 @@ static int policy_ivi_create(struct connman_session
*session,
static void policy_ivi_destroy(struct connman_session *session)
{
+ struct policy_data *policy;
+
DBG("session %p", session);
+
+ policy = g_hash_table_lookup(session_hash, session);
+
+ g_hash_table_remove(session_hash, session);
+
+ cleanup_policy(policy);
}
static struct connman_session_policy session_policy_ivi = {
@@ -118,6 +173,14 @@ static int session_policy_ivi_init(void)
if (err < 0)
goto err;
+ session_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal,
+ NULL, NULL);
+ if (session_hash == NULL) {
+ err = -ENOMEM;
+ connman_session_policy_unregister(&session_policy_ivi);
+ goto err;
+ }
+
return 0;
err:
@@ -128,6 +191,19 @@ err:
static void session_policy_ivi_exit(void)
{
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init(&iter, session_hash);
+
+ while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
+ struct policy_data *data = value;
+
+ cleanup_policy(data);
+ }
+
+ g_hash_table_destroy(session_hash);
+
connman_session_policy_unregister(&session_policy_ivi);
dbus_connection_unref(connection);
--
1.7.12.1.382.gb0576a6
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman