[connman] Added Tizen Wi-Fi Mesh
[platform/upstream/connman.git] / src / wispr.c
index 7ff111a..a2df55a 100644 (file)
@@ -2,7 +2,7 @@
  *
  *  Connection Manager
  *
- *  Copyright (C) 2007-2012  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2007-2013  Intel Corporation. All rights reserved.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License version 2 as
 #define STATUS_URL_IPV4  "http://ipv4.connman.net/online/status.html"
 #define STATUS_URL_IPV6  "http://ipv6.connman.net/online/status.html"
 
-#define wispr_portal_context_ref(_wp_ctxt) \
-       wispr_portal_context_ref_debug(_wp_ctxt, __FILE__, __LINE__, __func__)
-
-#define wispr_portal_context_unref(_wp_ctxt) \
-       wispr_portal_context_unref_debug(_wp_ctxt, __FILE__, __LINE__, __func__)
-
 struct connman_wispr_message {
-       gboolean has_error;
+       bool has_error;
        const char *current_element;
        int message_type;
        int response_code;
@@ -65,8 +59,6 @@ struct wispr_route {
 };
 
 struct connman_wispr_portal_context {
-       int refcount;
-
        struct connman_service *service;
        enum connman_ipconfig_type type;
        struct connman_wispr_portal *wispr_portal;
@@ -91,6 +83,8 @@ struct connman_wispr_portal_context {
        enum connman_wispr_result wispr_result;
 
        GSList *route_list;
+
+       guint timeout;
 };
 
 struct connman_wispr_portal {
@@ -98,7 +92,7 @@ struct connman_wispr_portal {
        struct connman_wispr_portal_context *ipv6_context;
 };
 
-static gboolean wispr_portal_web_result(GWebResult *result, gpointer user_data);
+static bool wispr_portal_web_result(GWebResult *result, gpointer user_data);
 
 static GHashTable *wispr_portal_list = NULL;
 
@@ -106,7 +100,7 @@ static void connman_wispr_message_init(struct connman_wispr_message *msg)
 {
        DBG("");
 
-       msg->has_error = FALSE;
+       msg->has_error = false;
        msg->current_element = NULL;
 
        msg->message_type = -1;
@@ -133,13 +127,13 @@ static void connman_wispr_message_init(struct connman_wispr_message *msg)
 
 static void free_wispr_routes(struct connman_wispr_portal_context *wp_context)
 {
-       while (wp_context->route_list != NULL) {
+       while (wp_context->route_list) {
                struct wispr_route *route = wp_context->route_list->data;
 
                DBG("free route to %s if %d type %d", route->address,
                                route->if_index, wp_context->type);
 
-               switch(wp_context->type) {
+               switch (wp_context->type) {
                case CONNMAN_IPCONFIG_TYPE_IPV4:
                        connman_inet_del_host_route(route->if_index,
                                        route->address);
@@ -149,6 +143,7 @@ static void free_wispr_routes(struct connman_wispr_portal_context *wp_context)
                                        route->address);
                        break;
                case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
+               case CONNMAN_IPCONFIG_TYPE_ALL:
                        break;
                }
 
@@ -161,14 +156,15 @@ static void free_wispr_routes(struct connman_wispr_portal_context *wp_context)
        }
 }
 
-static void free_connman_wispr_portal_context(struct connman_wispr_portal_context *wp_context)
+static void free_connman_wispr_portal_context(
+               struct connman_wispr_portal_context *wp_context)
 {
        DBG("context %p", wp_context);
 
-       if (wp_context == NULL)
+       if (!wp_context)
                return;
 
-       if (wp_context->wispr_portal != NULL) {
+       if (wp_context->wispr_portal) {
                if (wp_context->wispr_portal->ipv4_context == wp_context)
                        wp_context->wispr_portal->ipv4_context = NULL;
 
@@ -176,21 +172,21 @@ static void free_connman_wispr_portal_context(struct connman_wispr_portal_contex
                        wp_context->wispr_portal->ipv6_context = NULL;
        }
 
-       if (wp_context->service != NULL)
-               connman_service_unref(wp_context->service);
-
        if (wp_context->token > 0)
                connman_proxy_lookup_cancel(wp_context->token);
 
        if (wp_context->request_id > 0)
                g_web_cancel_request(wp_context->web, wp_context->request_id);
 
-       if (wp_context->web != NULL)
+       if (wp_context->timeout > 0)
+               g_source_remove(wp_context->timeout);
+
+       if (wp_context->web)
                g_web_unref(wp_context->web);
 
        g_free(wp_context->redirect_url);
 
-       if (wp_context->wispr_parser != NULL)
+       if (wp_context->wispr_parser)
                g_web_parser_unref(wp_context->wispr_parser);
 
        connman_wispr_message_init(&wp_context->wispr_msg);
@@ -204,60 +200,9 @@ static void free_connman_wispr_portal_context(struct connman_wispr_portal_contex
        g_free(wp_context);
 }
 
-static struct connman_wispr_portal_context *
-wispr_portal_context_ref_debug(struct connman_wispr_portal_context *wp_context,
-                               const char *file, int line, const char *caller)
-{
-       DBG("%p ref %d by %s:%d:%s()", wp_context, wp_context->refcount + 1,
-                                                       file, line, caller);
-
-       __sync_fetch_and_add(&wp_context->refcount, 1);
-
-       return wp_context;
-}
-
-static struct connman_wispr_portal_context *
-wispr_portal_context_unref_debug(struct connman_wispr_portal_context *wp_context,
-                               const char *file, int line, const char *caller)
-{
-       DBG("%p ref %d by %s:%d:%s()", wp_context, wp_context->refcount - 1,
-                                                       file, line, caller);
-
-       if (__sync_fetch_and_sub(&wp_context->refcount, 1) != 1)
-               return wp_context;
-
-       free_connman_wispr_portal_context(wp_context);
-
-       return NULL;
-}
-
 static struct connman_wispr_portal_context *create_wispr_portal_context(void)
 {
-       struct connman_wispr_portal_context *wp_context = NULL;
-
-        wp_context = g_try_new0(struct connman_wispr_portal_context, 1);
-        if (wp_context == NULL)
-               return NULL;
-
-        wp_context->refcount = 1;
-
-        return wp_context;
-}
-
-/**
- * This function is usued only by free_connman_wispr_portal, context pointer
- * might still be owned by a third party (gweb, agent dbus call...)
- * so we don't want service to be referenced in any context when it is not
- * valid anymore.
- */
-static void
-reset_service_usage(struct connman_wispr_portal_context *wp_context)
-{
-       if (wp_context->service == NULL)
-               return;
-
-       connman_service_unref(wp_context->service);
-       wp_context->service = NULL;
+       return g_try_new0(struct connman_wispr_portal_context, 1);
 }
 
 static void free_connman_wispr_portal(gpointer data)
@@ -266,18 +211,11 @@ static void free_connman_wispr_portal(gpointer data)
 
        DBG("");
 
-       if (wispr_portal == NULL)
+       if (!wispr_portal)
                return;
 
-       if (wispr_portal->ipv4_context != NULL) {
-               reset_service_usage(wispr_portal->ipv4_context);
-               wispr_portal_context_unref(wispr_portal->ipv4_context);
-       }
-
-       if (wispr_portal->ipv6_context != NULL) {
-               reset_service_usage(wispr_portal->ipv6_context);
-               wispr_portal_context_unref(wispr_portal->ipv6_context);
-       }
+       free_connman_wispr_portal_context(wispr_portal->ipv4_context);
+       free_connman_wispr_portal_context(wispr_portal->ipv6_context);
 
        g_free(wispr_portal);
 }
@@ -390,12 +328,11 @@ static void xml_wispr_text_handler(GMarkupParseContext *context,
        struct connman_wispr_message *msg = user_data;
        int i;
 
-       if (msg->current_element == NULL)
+       if (!msg->current_element)
                return;
 
        for (i = 0; wispr_element_map[i].str; i++) {
-               if (g_str_equal(wispr_element_map[i].str,
-                                       msg->current_element) == FALSE)
+               if (!g_str_equal(wispr_element_map[i].str, msg->current_element))
                        continue;
 
                switch (wispr_element_map[i].element) {
@@ -444,7 +381,7 @@ static void xml_wispr_error_handler(GMarkupParseContext *context,
 {
        struct connman_wispr_message *msg = user_data;
 
-       msg->has_error = TRUE;
+       msg->has_error = true;
 }
 
 static const GMarkupParser xml_wispr_parser_handlers = {
@@ -459,7 +396,7 @@ static void xml_wispr_parser_callback(const char *str, gpointer user_data)
 {
        struct connman_wispr_portal_context *wp_context = user_data;
        GMarkupParseContext *parser_context = NULL;
-       gboolean result;
+       bool result;
 
        DBG("");
 
@@ -469,7 +406,7 @@ static void xml_wispr_parser_callback(const char *str, gpointer user_data)
 
        result = g_markup_parse_context_parse(parser_context,
                                        str, strlen(str), NULL);
-       if (result == TRUE)
+       if (result)
                g_markup_parse_context_end_parse(parser_context, NULL);
 
        g_markup_parse_context_free(parser_context);
@@ -490,29 +427,36 @@ static void wispr_portal_error(struct connman_wispr_portal_context *wp_context)
 static void portal_manage_status(GWebResult *result,
                        struct connman_wispr_portal_context *wp_context)
 {
+       struct connman_service *service = wp_context->service;
+       enum connman_ipconfig_type type = wp_context->type;
        const char *str = NULL;
 
        DBG("");
 
        /* We currently don't do anything with this info */
        if (g_web_result_get_header(result, "X-ConnMan-Client-IP",
-                               &str) == TRUE)
+                               &str))
                connman_info("Client-IP: %s", str);
 
        if (g_web_result_get_header(result, "X-ConnMan-Client-Country",
-                               &str) == TRUE)
+                               &str))
                connman_info("Client-Country: %s", str);
 
        if (g_web_result_get_header(result, "X-ConnMan-Client-Region",
-                               &str) == TRUE)
+                               &str))
                connman_info("Client-Region: %s", str);
 
-       __connman_service_ipconfig_indicate_state(wp_context->service,
-                                               CONNMAN_SERVICE_STATE_ONLINE,
-                                               wp_context->type);
+       if (g_web_result_get_header(result, "X-ConnMan-Client-Timezone",
+                               &str))
+               connman_info("Client-Timezone: %s", str);
+
+       free_connman_wispr_portal_context(wp_context);
+
+       __connman_service_ipconfig_indicate_state(service,
+                                       CONNMAN_SERVICE_STATE_ONLINE, type);
 }
 
-static gboolean wispr_route_request(const char *address, int ai_family,
+static bool wispr_route_request(const char *address, int ai_family,
                int if_index, gpointer user_data)
 {
        int result = -1;
@@ -525,16 +469,16 @@ static gboolean wispr_route_request(const char *address, int ai_family,
 
        DBG("address %s if %d gw %s", address, if_index, gateway);
 
-       if (gateway == NULL)
-               return FALSE;
+       if (!gateway)
+               return false;
 
        route = g_try_new0(struct wispr_route, 1);
        if (route == 0) {
                DBG("could not create struct");
-               return FALSE;
+               return false;
        }
 
-       switch(wp_context->type) {
+       switch (wp_context->type) {
        case CONNMAN_IPCONFIG_TYPE_IPV4:
                result = connman_inet_add_host_route(if_index, address,
                                gateway);
@@ -544,22 +488,24 @@ static gboolean wispr_route_request(const char *address, int ai_family,
                                gateway);
                break;
        case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
+       case CONNMAN_IPCONFIG_TYPE_ALL:
                break;
        }
 
        if (result < 0) {
                g_free(route);
-               return FALSE;
+               return false;
        }
 
        route->address = g_strdup(address);
        route->if_index = if_index;
        wp_context->route_list = g_slist_prepend(wp_context->route_list, route);
 
-       return TRUE;
+       return true;
 }
 
-static void wispr_portal_request_portal(struct connman_wispr_portal_context *wp_context)
+static void wispr_portal_request_portal(
+               struct connman_wispr_portal_context *wp_context)
 {
        DBG("");
 
@@ -571,11 +517,9 @@ static void wispr_portal_request_portal(struct connman_wispr_portal_context *wp_
 
        if (wp_context->request_id == 0)
                wispr_portal_error(wp_context);
-       else
-               wispr_portal_context_ref(wp_context);
 }
 
-static gboolean wispr_input(const guint8 **data, gsize *length,
+static bool wispr_input(const guint8 **data, gsize *length,
                                                gpointer user_data)
 {
        struct connman_wispr_portal_context *wp_context = user_data;
@@ -603,22 +547,21 @@ static gboolean wispr_input(const guint8 **data, gsize *length,
        *data = (guint8 *) wp_context->wispr_formdata;
        *length = count;
 
-       return FALSE;
+       return false;
 }
 
 static void wispr_portal_browser_reply_cb(struct connman_service *service,
-                                       connman_bool_t authentication_done,
+                                       bool authentication_done,
                                        const char *error, void *user_data)
 {
        struct connman_wispr_portal_context *wp_context = user_data;
 
        DBG("");
 
-       wp_context = wispr_portal_context_unref(wp_context);
-       if (service == NULL || wp_context == NULL)
+       if (!service || !wp_context)
                return;
 
-       if (authentication_done == FALSE) {
+       if (!authentication_done) {
                wispr_portal_error(wp_context);
                free_wispr_routes(wp_context);
                return;
@@ -629,30 +572,27 @@ static void wispr_portal_browser_reply_cb(struct connman_service *service,
 }
 
 static void wispr_portal_request_wispr_login(struct connman_service *service,
-                               connman_bool_t success,
+                               bool success,
                                const char *ssid, int ssid_len,
                                const char *username, const char *password,
-                               gboolean wps, const char *wpspin,
+                               bool wps, const char *wpspin,
                                const char *error, void *user_data)
 {
        struct connman_wispr_portal_context *wp_context = user_data;
 
        DBG("");
 
-       wp_context = wispr_portal_context_unref(wp_context);
-       if (wp_context == NULL)
-               return;
-
-       if (error != NULL && g_strcmp0(error,
+       if (error) {
+               if (g_strcmp0(error,
                        "net.connman.Agent.Error.LaunchBrowser") == 0) {
-               wispr_portal_context_ref(wp_context);
-
-               if (__connman_agent_request_browser(service,
-                               wispr_portal_browser_reply_cb,
-                               wp_context->redirect_url,
-                               wp_context) != -EINPROGRESS)
-                       wispr_portal_context_unref(wp_context);
+                       if (__connman_agent_request_browser(service,
+                                       wispr_portal_browser_reply_cb,
+                                       wp_context->redirect_url,
+                                       wp_context) == -EINPROGRESS)
+                               return;
+               }
 
+               free_connman_wispr_portal_context(wp_context);
                return;
        }
 
@@ -662,20 +602,16 @@ static void wispr_portal_request_wispr_login(struct connman_service *service,
        g_free(wp_context->wispr_password);
        wp_context->wispr_password = g_strdup(password);
 
-       wispr_portal_context_ref(wp_context);
-
        wp_context->request_id = g_web_request_post(wp_context->web,
                                        wp_context->wispr_msg.login_url,
                                        "application/x-www-form-urlencoded",
                                        wispr_input, wispr_portal_web_result,
                                        wp_context);
-       if (wp_context->request_id == 0)
-               wispr_portal_context_unref(wp_context);
 
        connman_wispr_message_init(&wp_context->wispr_msg);
 }
 
-static gboolean wispr_manage_message(GWebResult *result,
+static bool wispr_manage_message(GWebResult *result,
                        struct connman_wispr_portal_context *wp_context)
 {
        DBG("Message type: %s (%d)",
@@ -685,21 +621,21 @@ static gboolean wispr_manage_message(GWebResult *result,
                response_code_to_string(wp_context->wispr_msg.response_code),
                                        wp_context->wispr_msg.response_code);
 
-       if (wp_context->wispr_msg.access_procedure != NULL)
+       if (wp_context->wispr_msg.access_procedure)
                DBG("Access procedure: %s",
                        wp_context->wispr_msg.access_procedure);
-       if (wp_context->wispr_msg.access_location != NULL)
+       if (wp_context->wispr_msg.access_location)
                DBG("Access location: %s",
                        wp_context->wispr_msg.access_location);
-       if (wp_context->wispr_msg.location_name != NULL)
+       if (wp_context->wispr_msg.location_name)
                DBG("Location name: %s",
                        wp_context->wispr_msg.location_name);
-       if (wp_context->wispr_msg.login_url != NULL)
+       if (wp_context->wispr_msg.login_url)
                DBG("Login URL: %s", wp_context->wispr_msg.login_url);
-       if (wp_context->wispr_msg.abort_login_url != NULL)
+       if (wp_context->wispr_msg.abort_login_url)
                DBG("Abort login URL: %s",
                        wp_context->wispr_msg.abort_login_url);
-       if (wp_context->wispr_msg.logoff_url != NULL)
+       if (wp_context->wispr_msg.logoff_url)
                DBG("Logoff URL: %s", wp_context->wispr_msg.logoff_url);
 
        switch (wp_context->wispr_msg.message_type) {
@@ -708,14 +644,12 @@ static gboolean wispr_manage_message(GWebResult *result,
 
                wp_context->wispr_result = CONNMAN_WISPR_RESULT_LOGIN;
 
-               wispr_portal_context_ref(wp_context);
-
                if (__connman_agent_request_login_input(wp_context->service,
                                        wispr_portal_request_wispr_login,
-                                       wp_context) != -EINPROGRESS) {
-                       wispr_portal_context_unref(wp_context);
+                                       wp_context) != -EINPROGRESS)
                        wispr_portal_error(wp_context);
-               }
+               else
+                       return true;
 
                break;
        case 120: /* Falling down */
@@ -734,7 +668,7 @@ static gboolean wispr_manage_message(GWebResult *result,
 
                        wispr_portal_request_portal(wp_context);
 
-                       return TRUE;
+                       return true;
                } else
                        wispr_portal_error(wp_context);
 
@@ -743,10 +677,10 @@ static gboolean wispr_manage_message(GWebResult *result,
                break;
        }
 
-       return FALSE;
+       return false;
 }
 
-static gboolean wispr_portal_web_result(GWebResult *result, gpointer user_data)
+static bool wispr_portal_web_result(GWebResult *result, gpointer user_data)
 {
        struct connman_wispr_portal_context *wp_context = user_data;
        const char *redirect = NULL;
@@ -757,28 +691,19 @@ static gboolean wispr_portal_web_result(GWebResult *result, gpointer user_data)
 
        DBG("");
 
-       wp_context = wispr_portal_context_unref(wp_context);
-       if (wp_context == NULL)
-               return FALSE;
-
-       if (wp_context->request_id == 0)
-               return FALSE;
-
        if (wp_context->wispr_result != CONNMAN_WISPR_RESULT_ONLINE) {
                g_web_result_get_chunk(result, &chunk, &length);
 
                if (length > 0) {
-                       wispr_portal_context_ref(wp_context);
-
                        g_web_parser_feed_data(wp_context->wispr_parser,
                                                                chunk, length);
-                       return TRUE;
+                       return true;
                }
 
                g_web_parser_end_data(wp_context->wispr_parser);
 
                if (wp_context->wispr_msg.message_type >= 0) {
-                       if (wispr_manage_message(result, wp_context) == TRUE)
+                       if (wispr_manage_message(result, wp_context))
                                goto done;
                }
        }
@@ -788,27 +713,29 @@ static gboolean wispr_portal_web_result(GWebResult *result, gpointer user_data)
        DBG("status: %03u", status);
 
        switch (status) {
+       case 000:
+               __connman_agent_request_browser(wp_context->service,
+                               wispr_portal_browser_reply_cb,
+                               wp_context->status_url, wp_context);
+               break;
        case 200:
                if (wp_context->wispr_msg.message_type >= 0)
                        break;
 
                if (g_web_result_get_header(result, "X-ConnMan-Status",
-                                                               &str) == TRUE)
+                                               &str)) {
                        portal_manage_status(result, wp_context);
-               else {
-                       wispr_portal_context_ref(wp_context);
-
+                       return false;
+               } else
                        __connman_agent_request_browser(wp_context->service,
                                        wispr_portal_browser_reply_cb,
                                        wp_context->redirect_url, wp_context);
-               }
 
                break;
        case 302:
-               if (g_web_supports_tls() == FALSE ||
-                               g_web_result_get_header(result, "Location",
-                                                       &redirect) == FALSE) {
-                       wispr_portal_context_ref(wp_context);
+               if (!g_web_supports_tls() ||
+                       !g_web_result_get_header(result, "Location",
+                                                       &redirect)) {
 
                        __connman_agent_request_browser(wp_context->service,
                                        wispr_portal_browser_reply_cb,
@@ -823,17 +750,23 @@ static gboolean wispr_portal_web_result(GWebResult *result, gpointer user_data)
                wp_context->request_id = g_web_request_get(wp_context->web,
                                redirect, wispr_portal_web_result,
                                wispr_route_request, wp_context);
-               if (wp_context->request_id != 0)
-                       wispr_portal_context_ref(wp_context);
 
                goto done;
        case 400:
        case 404:
                if (__connman_service_online_check_failed(wp_context->service,
-                                                       wp_context->type) == 0)
+                                               wp_context->type) == 0) {
                        wispr_portal_error(wp_context);
+                       free_connman_wispr_portal_context(wp_context);
+                       return false;
+               }
 
                break;
+       case 505:
+               __connman_agent_request_browser(wp_context->service,
+                               wispr_portal_browser_reply_cb,
+                               wp_context->status_url, wp_context);
+               break;
        default:
                break;
        }
@@ -842,7 +775,7 @@ static gboolean wispr_portal_web_result(GWebResult *result, gpointer user_data)
        wp_context->request_id = 0;
 done:
        wp_context->wispr_msg.message_type = -1;
-       return FALSE;
+       return false;
 }
 
 static void proxy_callback(const char *proxy, void *user_data)
@@ -851,14 +784,18 @@ static void proxy_callback(const char *proxy, void *user_data)
 
        DBG("proxy %s", proxy);
 
-       wp_context = wispr_portal_context_unref(wp_context);
-       if (wp_context == NULL)
+       if (!wp_context)
                return;
 
        wp_context->token = 0;
 
-       if (proxy != NULL && g_strcmp0(proxy, "DIRECT") != 0)
+       if (proxy && g_strcmp0(proxy, "DIRECT") != 0) {
+               if (g_str_has_prefix(proxy, "PROXY")) {
+                       proxy += 5;
+                       for (; *proxy == ' ' && *proxy != '\0'; proxy++);
+               }
                g_web_set_proxy(wp_context->web, proxy);
+       }
 
        g_web_set_accept(wp_context->web, NULL);
        g_web_set_user_agent(wp_context->web, "ConnMan/%s wispr", VERSION);
@@ -878,6 +815,8 @@ static gboolean no_proxy_callback(gpointer user_data)
 {
        struct connman_wispr_portal_context *wp_context = user_data;
 
+       wp_context->timeout = 0;
+
        proxy_callback("DIRECT", wp_context);
 
        return FALSE;
@@ -893,28 +832,31 @@ static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context)
        int err = 0;
        int i;
 
-       DBG("wispr/portal context %p", wp_context);
-       DBG("service %p", wp_context->service);
+       DBG("wispr/portal context %p service %p", wp_context,
+               wp_context->service);
 
        service_type = connman_service_get_type(wp_context->service);
 
        switch (service_type) {
        case CONNMAN_SERVICE_TYPE_ETHERNET:
        case CONNMAN_SERVICE_TYPE_WIFI:
-       case CONNMAN_SERVICE_TYPE_WIMAX:
        case CONNMAN_SERVICE_TYPE_BLUETOOTH:
        case CONNMAN_SERVICE_TYPE_CELLULAR:
+       case CONNMAN_SERVICE_TYPE_GADGET:
                break;
        case CONNMAN_SERVICE_TYPE_UNKNOWN:
        case CONNMAN_SERVICE_TYPE_SYSTEM:
        case CONNMAN_SERVICE_TYPE_GPS:
        case CONNMAN_SERVICE_TYPE_VPN:
-       case CONNMAN_SERVICE_TYPE_GADGET:
+       case CONNMAN_SERVICE_TYPE_P2P:
+#if defined TIZEN_EXT_WIFI_MESH
+       case CONNMAN_SERVICE_TYPE_MESH:
+#endif
                return -EOPNOTSUPP;
        }
 
        interface = connman_service_get_interface(wp_context->service);
-       if (interface == NULL)
+       if (!interface)
                return -EINVAL;
 
        DBG("interface %s", interface);
@@ -927,20 +869,22 @@ static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context)
        }
 
        nameservers = connman_service_get_nameservers(wp_context->service);
-       if (nameservers == NULL) {
+       if (!nameservers) {
                DBG("Could not get nameservers");
                err = -EINVAL;
                goto done;
        }
 
        wp_context->web = g_web_new(if_index);
-       if (wp_context->web == NULL) {
+       if (!wp_context->web) {
                DBG("Could not set up GWeb");
                err = -ENOMEM;
                goto done;
        }
 
+#if !defined TIZEN_EXT
        if (getenv("CONNMAN_WEB_DEBUG"))
+#endif
                g_web_set_debug(wp_context->web, web_debug, "WEB");
 
        if (wp_context->type == CONNMAN_IPCONFIG_TYPE_IPV4) {
@@ -951,7 +895,7 @@ static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context)
                wp_context->status_url = STATUS_URL_IPV6;
        }
 
-       for (i = 0; nameservers[i] != NULL; i++)
+       for (i = 0; nameservers[i]; i++)
                g_web_add_nameserver(wp_context->web, nameservers[i]);
 
        proxy_method = connman_service_get_proxy_method(wp_context->service);
@@ -964,13 +908,12 @@ static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context)
 
                if (wp_context->token == 0) {
                        err = -EINVAL;
-                       goto done;
+                       free_connman_wispr_portal_context(wp_context);
                }
-       } else {
-               g_timeout_add_seconds(0, no_proxy_callback, wp_context);
+       } else if (wp_context->timeout == 0) {
+               wp_context->timeout = g_idle_add(no_proxy_callback, wp_context);
        }
 
-       wispr_portal_context_ref(wp_context);
 done:
        g_strfreev(nameservers);
 
@@ -987,7 +930,12 @@ int __connman_wispr_start(struct connman_service *service,
 
        DBG("service %p", service);
 
-       if (wispr_portal_list == NULL)
+#if defined TIZEN_EXT
+       if (connman_service_get_type(service) == CONNMAN_SERVICE_TYPE_CELLULAR)
+               return -EPERM;
+#endif
+
+       if (!wispr_portal_list)
                return -EINVAL;
 
        index = __connman_service_get_index(service);
@@ -996,9 +944,9 @@ int __connman_wispr_start(struct connman_service *service,
 
        wispr_portal = g_hash_table_lookup(wispr_portal_list,
                                        GINT_TO_POINTER(index));
-       if (wispr_portal == NULL) {
+       if (!wispr_portal) {
                wispr_portal = g_try_new0(struct connman_wispr_portal, 1);
-               if (wispr_portal == NULL)
+               if (!wispr_portal)
                        return -ENOMEM;
 
                g_hash_table_replace(wispr_portal_list,
@@ -1013,15 +961,13 @@ int __connman_wispr_start(struct connman_service *service,
                return -EINVAL;
 
        /* If there is already an existing context, we wipe it */
-       if (wp_context != NULL)
-               wispr_portal_context_unref(wp_context);
+       if (wp_context)
+               free_connman_wispr_portal_context(wp_context);
 
        wp_context = create_wispr_portal_context();
-       if (wp_context == NULL)
+       if (!wp_context)
                return -ENOMEM;
 
-       connman_service_ref(service);
-
        wp_context->service = service;
        wp_context->type = type;
        wp_context->wispr_portal = wispr_portal;
@@ -1040,7 +986,7 @@ void __connman_wispr_stop(struct connman_service *service)
 
        DBG("service %p", service);
 
-       if (wispr_portal_list == NULL)
+       if (!wispr_portal_list)
                return;
 
        index = __connman_service_get_index(service);