From 2882f67ff02adbb2ce64b74cb4fe25e834b2021e Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Tue, 13 Nov 2012 09:01:48 +0100 Subject: session: Factor out set default config helper Whenever a configuration gets invalid (e.g. a configuration is removed) then we need to be able to drop back to the default configutation. --- src/session.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src/session.c') diff --git a/src/session.c b/src/session.c index 0b0321fc..c2327886 100644 --- a/src/session.c +++ b/src/session.c @@ -352,6 +352,22 @@ void connman_session_policy_unregister(struct connman_session_policy *policy) remove_policy(policy); } +int connman_session_set_default_config(struct connman_session_config *config) +{ + config->priority = FALSE; + config->roaming_policy = CONNMAN_SESSION_ROAMING_POLICY_DEFAULT; + config->type = CONNMAN_SESSION_TYPE_ANY; + config->ecall = FALSE; + + g_slist_free(config->allowed_bearers); + config->allowed_bearers = g_slist_prepend(NULL, + GINT_TO_POINTER(CONNMAN_SERVICE_TYPE_UNKNOWN)); + if (config->allowed_bearers == NULL) + return -ENOMEM; + + return 0; +} + struct connman_session_config *connman_session_create_default_config(void) { struct connman_session_config *config; @@ -360,13 +376,7 @@ struct connman_session_config *connman_session_create_default_config(void) if (config == NULL) return NULL; - config->priority = FALSE; - config->roaming_policy = CONNMAN_SESSION_ROAMING_POLICY_DEFAULT; - config->type = CONNMAN_SESSION_TYPE_ANY; - config->ecall = FALSE; - config->allowed_bearers = g_slist_prepend(NULL, - GINT_TO_POINTER(CONNMAN_SERVICE_TYPE_UNKNOWN)); - if (config->allowed_bearers == NULL) { + if (connman_session_set_default_config(config) < 0) { g_free(config); return NULL; } -- cgit v1.2.3