summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Wagner <daniel.wagner@bmw-carit.de>2012-10-31 10:33:38 +0100
committerPatrik Flykt <patrik.flykt@linux.intel.com>2012-11-05 14:50:16 +0200
commitcd07fd46d60555e345eea0b8c4ddf37100409d55 (patch)
treed97807152b960562925f98b1a6cb7216d6a61610 /src
parent3a017c151a29cc70904634980ae79a71301202a6 (diff)
downloadconnman-cd07fd46d60555e345eea0b8c4ddf37100409d55.tar.gz
connman-cd07fd46d60555e345eea0b8c4ddf37100409d55.tar.bz2
connman-cd07fd46d60555e345eea0b8c4ddf37100409d55.zip
session: Factor out user settings in __connman_session_create()
In order to be able to pass the user configuration provided through from the D-Bus Manager.SessionCreate() call to the callback we need to store the configuration into a local data data structure. This data structure can then be passed into the callback introduced later on.
Diffstat (limited to 'src')
-rw-r--r--src/session.c71
1 files changed, 48 insertions, 23 deletions
diff --git a/src/session.c b/src/session.c
index dea05993..26a9ab1c 100644
--- a/src/session.c
+++ b/src/session.c
@@ -1521,6 +1521,11 @@ static const GDBusMethodTable session_methods[] = {
{ },
};
+struct user_config {
+ enum connman_session_type type;
+ GSList *allowed_bearers;
+};
+
static void session_create_cb(struct connman_session *session,
struct connman_session_config *config,
void *user_data, int err)
@@ -1540,10 +1545,9 @@ int __connman_session_create(DBusMessage *msg)
DBusMessageIter iter, array;
struct connman_session *session = NULL;
struct session_info *info, *info_last;
- enum connman_session_type type = CONNMAN_SESSION_TYPE_ANY;
- GSList *allowed_bearers = NULL;
- connman_bool_t allowed_bearers_valid = FALSE;
- connman_bool_t type_valid = FALSE;
+ struct user_config *user_config = NULL;
+ connman_bool_t user_allowed_bearers = FALSE;
+ connman_bool_t user_connection_type = FALSE;
int err;
owner = dbus_message_get_sender(msg);
@@ -1559,6 +1563,12 @@ int __connman_session_create(DBusMessage *msg)
goto err;
}
+ user_config = g_try_new0(struct user_config, 1);
+ if (user_config == NULL) {
+ err = -ENOMEM;
+ goto err;
+ }
+
dbus_message_iter_init(msg, &iter);
dbus_message_iter_recurse(&iter, &array);
@@ -1575,11 +1585,12 @@ int __connman_session_create(DBusMessage *msg)
switch (dbus_message_iter_get_arg_type(&value)) {
case DBUS_TYPE_ARRAY:
if (g_str_equal(key, "AllowedBearers") == TRUE) {
- err = parse_bearers(&value, &allowed_bearers);
+ err = parse_bearers(&value,
+ &user_config->allowed_bearers);
if (err < 0)
goto err;
- allowed_bearers_valid = TRUE;
+ user_allowed_bearers = TRUE;
} else {
return -EINVAL;
}
@@ -1587,8 +1598,9 @@ int __connman_session_create(DBusMessage *msg)
case DBUS_TYPE_STRING:
if (g_str_equal(key, "ConnectionType") == TRUE) {
dbus_message_iter_get_basic(&value, &val);
- type = string2type(val);
- type_valid = TRUE;
+ user_config->type = string2type(val);
+
+ user_connection_type = TRUE;
} else {
return -EINVAL;
}
@@ -1596,6 +1608,26 @@ int __connman_session_create(DBusMessage *msg)
dbus_message_iter_next(&array);
}
+ /*
+ * If the user hasn't provided a configuration, we set
+ * the default configuration.
+ *
+ * For AllowedBearers this is '*', ...
+ */
+ if (user_allowed_bearers == FALSE) {
+ user_config->allowed_bearers =
+ g_slist_append(NULL,
+ GINT_TO_POINTER(CONNMAN_SERVICE_TYPE_UNKNOWN));
+ if (user_config->allowed_bearers == NULL) {
+ err = -ENOMEM;
+ goto err;
+ }
+ }
+
+ /* ... and for ConnectionType it is 'any'. */
+ if (user_connection_type == FALSE)
+ user_config->type = CONNMAN_SESSION_TYPE_ANY;
+
dbus_message_iter_next(&iter);
dbus_message_iter_get_basic(&iter, &notify_path);
@@ -1656,32 +1688,23 @@ int __connman_session_create(DBusMessage *msg)
ecall_session = session;
info->state = CONNMAN_SESSION_STATE_DISCONNECTED;
- if (type_valid == FALSE)
- type = CONNMAN_SESSION_TYPE_ANY;
info->config.type = apply_policy_on_type(
session->policy_config->type,
- type);
+ user_config->type);
info->config.priority = session->policy_config->priority;
info->config.roaming_policy = session->policy_config->roaming_policy;
info->entry = NULL;
- if (allowed_bearers_valid == FALSE) {
- allowed_bearers =
- g_slist_append(NULL,
- GINT_TO_POINTER(CONNMAN_SERVICE_TYPE_UNKNOWN));
- if (allowed_bearers == NULL) {
- err = -ENOMEM;
- goto err;
- }
- }
-
err = apply_policy_on_bearers(
session->policy_config->allowed_bearers,
- allowed_bearers,
+ user_config->allowed_bearers,
&info->config.allowed_bearers);
if (err < 0)
goto err;
+ g_slist_free(user_config->allowed_bearers);
+ g_free(user_config);
+
g_hash_table_replace(session_hash, session->session_path, session);
DBG("add %s", session->session_path);
@@ -1730,7 +1753,9 @@ err:
g_free(session_path);
- g_slist_free(allowed_bearers);
+ if (user_config != NULL)
+ g_slist_free(user_config->allowed_bearers);
+ g_free(user_config);
return err;
}