wifi: Add support for autoscan request
[framework/connectivity/connman.git] / src / wispr.c
index 0815330..9412f1e 100644 (file)
@@ -386,7 +386,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)
-               result = g_markup_parse_context_end_parse(parser_context, NULL);
+               g_markup_parse_context_end_parse(parser_context, NULL);
 
        g_markup_parse_context_free(parser_context);
 }
@@ -520,17 +520,46 @@ static gboolean wispr_input(const guint8 **data, gsize *length,
        return FALSE;
 }
 
+static void wispr_portal_browser_reply_cb(struct connman_service *service,
+                                       connman_bool_t authentication_done,
+                                       const char *error, void *user_data)
+{
+       struct connman_wispr_portal_context *wp_context = user_data;
+
+       DBG("");
+
+       if (service == NULL || wp_context == NULL)
+               return;
+
+       if (authentication_done == FALSE) {
+               wispr_portal_error(wp_context);
+               free_wispr_routes(wp_context);
+               return;
+       }
+
+       /* Restarting the test */
+       __connman_wispr_start(service, wp_context->type);
+}
+
 static void wispr_portal_request_wispr_login(struct connman_service *service,
                                connman_bool_t success,
                                const char *ssid, int ssid_len,
                                const char *username, const char *password,
                                gboolean wps, const char *wpspin,
-                               void *user_data)
+                               const char *error, void *user_data)
 {
        struct connman_wispr_portal_context *wp_context = user_data;
 
        DBG("");
 
+       if (error != NULL && g_strcmp0(error,
+                       "net.connman.Agent.Error.LaunchBrowser") == 0) {
+               __connman_agent_request_browser(service,
+                               wispr_portal_browser_reply_cb,
+                               wp_context->redirect_url, wp_context);
+               return;
+       }
+
        g_free(wp_context->wispr_username);
        wp_context->wispr_username = g_strdup(username);
 
@@ -581,7 +610,7 @@ static gboolean wispr_manage_message(GWebResult *result,
 
                if (__connman_agent_request_login_input(wp_context->service,
                                        wispr_portal_request_wispr_login,
-                                       wp_context) != -EIO)
+                                       wp_context) != -EINPROGRESS)
                        wispr_portal_error(wp_context);
 
                break;
@@ -613,27 +642,6 @@ static gboolean wispr_manage_message(GWebResult *result,
        return FALSE;
 }
 
-static void wispr_portal_browser_reply_cb(struct connman_service *service,
-                                       connman_bool_t authentication_done,
-                                       void *user_data)
-{
-       struct connman_wispr_portal_context *wp_context = user_data;
-
-       DBG("");
-
-       if (service == NULL || wp_context == NULL)
-               return;
-
-       if (authentication_done == FALSE) {
-               wispr_portal_error(wp_context);
-               free_wispr_routes(wp_context);
-               return;
-       }
-
-       /* Restarting the test */
-       __connman_wispr_start(service, wp_context->type);
-}
-
 static gboolean wispr_portal_web_result(GWebResult *result, gpointer user_data)
 {
        struct connman_wispr_portal_context *wp_context = user_data;
@@ -684,8 +692,9 @@ static gboolean wispr_portal_web_result(GWebResult *result, gpointer user_data)
 
                break;
        case 302:
-               if (g_web_result_get_header(result, "Location",
-                                               &redirect) == FALSE) {
+               if (g_web_supports_tls() == FALSE ||
+                               g_web_result_get_header(result, "Location",
+                                                       &redirect) == FALSE) {
                        __connman_agent_request_browser(wp_context->service,
                                        wispr_portal_browser_reply_cb,
                                        wp_context->status_url, wp_context);
@@ -701,6 +710,7 @@ static gboolean wispr_portal_web_result(GWebResult *result, gpointer user_data)
                                wispr_route_request, wp_context);
 
                goto done;
+       case 400:
        case 404:
                if (__connman_service_online_check_failed(wp_context->service,
                                                        wp_context->type) == 0)
@@ -790,18 +800,21 @@ static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context)
 
        if_index = connman_inet_ifindex(interface);
        if (if_index < 0) {
+               DBG("Could not get ifindex");
                err = -EINVAL;
                goto done;
        }
 
        nameservers = connman_service_get_nameservers(wp_context->service);
        if (nameservers == NULL) {
+               DBG("Could not get nameservers");
                err = -EINVAL;
                goto done;
        }
 
        wp_context->web = g_web_new(if_index);
        if (wp_context->web == NULL) {
+               DBG("Could not set up GWeb");
                err = -ENOMEM;
                goto done;
        }