Imported Upstream version 1.38
[platform/upstream/connman.git] / src / wispr.c
index dcce93c..4115758 100644 (file)
@@ -143,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;
                }
 
@@ -487,6 +488,7 @@ static bool wispr_route_request(const char *address, int ai_family,
                                gateway);
                break;
        case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
+       case CONNMAN_IPCONFIG_TYPE_ALL:
                break;
        }
 
@@ -553,12 +555,31 @@ static void wispr_portal_browser_reply_cb(struct connman_service *service,
                                        const char *error, void *user_data)
 {
        struct connman_wispr_portal_context *wp_context = user_data;
+       struct connman_wispr_portal *wispr_portal;
+       int index;
 
        DBG("");
 
        if (!service || !wp_context)
                return;
 
+       /*
+        * No way to cancel this if wp_context has been freed, so we lookup
+        * from the service and check that this is still the right context.
+        */
+       index = __connman_service_get_index(service);
+       if (index < 0)
+               return;
+
+       wispr_portal = g_hash_table_lookup(wispr_portal_list,
+                                       GINT_TO_POINTER(index));
+       if (!wispr_portal)
+               return;
+
+       if (wp_context != wispr_portal->ipv4_context &&
+               wp_context != wispr_portal->ipv6_context)
+               return;
+
        if (!authentication_done) {
                wispr_portal_error(wp_context);
                free_wispr_routes(wp_context);
@@ -566,7 +587,7 @@ static void wispr_portal_browser_reply_cb(struct connman_service *service,
        }
 
        /* Restarting the test */
-       __connman_wispr_start(service, wp_context->type);
+       __connman_service_wispr_start(service, wp_context->type);
 }
 
 static void wispr_portal_request_wispr_login(struct connman_service *service,
@@ -711,6 +732,11 @@ static bool 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;
@@ -755,6 +781,11 @@ static bool wispr_portal_web_result(GWebResult *result, gpointer user_data)
                }
 
                break;
+       case 505:
+               __connman_agent_request_browser(wp_context->service,
+                               wispr_portal_browser_reply_cb,
+                               wp_context->status_url, wp_context);
+               break;
        default:
                break;
        }
@@ -820,8 +851,8 @@ 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);
 
@@ -894,8 +925,7 @@ static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context)
                        free_connman_wispr_portal_context(wp_context);
                }
        } else if (wp_context->timeout == 0) {
-               wp_context->timeout =
-                       g_timeout_add_seconds(0, no_proxy_callback, wp_context);
+               wp_context->timeout = g_idle_add(no_proxy_callback, wp_context);
        }
 
 done: