| Index: plugins/portal_check.c
|
| diff --git a/plugins/portal_check.c b/plugins/portal_check.c
|
| index da284fd971cc4ce64641c74341f0232afac6c4cb..8025e1f48b10ba8e45de036c2b196e48f05793ff 100644
|
| --- a/plugins/portal_check.c
|
| +++ b/plugins/portal_check.c
|
| @@ -87,20 +87,33 @@ static long get_http_code(CURL *curl_handle)
|
| }
|
|
|
| /**
|
| - * Returns true iff we received an HTTP 204.
|
| + * Returns a connectivity state based on the status of an HTTP request
|
| + * to kGoogle204Url
|
| */
|
| -static gboolean check_ip_pool(CURLMsg *request_status)
|
| +static enum connman_service_connectivity_state check_connectivity_state(
|
| + CURLMsg *request_status)
|
| {
|
| - // Check the request state
|
| + CURLcode code = (CURLcode)request_status->data.result;
|
| +
|
| + /* Check the request state */
|
| _DBG_PORTAL("curl code is %d", (int)request_status->data.result);
|
| - if (CURLE_OK == (CURLcode)request_status->data.result) {
|
| + if (CURLE_COULDNT_RESOLVE_HOST == code) {
|
| + /*
|
| + * TODO(jglasgow): test resolving the address of the
|
| + * captive portal web server instead
|
| + */
|
| + _DBG_PORTAL("Cannot resolve %s", kGoogle204Url);
|
| + return CONNMAN_SERVICE_CONNECTIVITY_STATE_NONE;
|
| + }
|
| +
|
| + if (CURLE_OK == code) {
|
| if (get_http_code(request_status->easy_handle) == 204) {
|
| _DBG_PORTAL("The user can route traffic");
|
| - return FALSE;
|
| + return CONNMAN_SERVICE_CONNECTIVITY_STATE_UNRESTRICTED;
|
| }
|
| }
|
| _DBG_PORTAL("We're in an IP restrict pool");
|
| - return TRUE;
|
| + return CONNMAN_SERVICE_CONNECTIVITY_STATE_RESTRICTED;
|
| }
|
|
|
| /**
|
| @@ -109,8 +122,10 @@ static gboolean check_ip_pool(CURLMsg *request_status)
|
| */
|
| static void handle_multi_perform()
|
| {
|
| - // Multi perform may need to be called multiple times to set
|
| - // the request up successfully.
|
| + /*
|
| + * Multi perform may need to be called multiple times to set
|
| + * the request up successfully.
|
| + */
|
| CURLMcode err;
|
| do {
|
| err = curl_multi_perform(curl_multi_handle_,
|
| @@ -134,6 +149,8 @@ static gboolean pending_request_callback(gpointer data)
|
| {
|
| int remaining_updates;
|
| CURLMsg* request_status;
|
| + struct portal_request *portal_request = NULL;
|
| + struct connman_service *service;
|
|
|
| _DBG_PORTAL("callback fired, %d jobs remain", pending_requests_);
|
|
|
| @@ -142,32 +159,32 @@ static gboolean pending_request_callback(gpointer data)
|
| request_status =
|
| curl_multi_info_read(curl_multi_handle_, &remaining_updates);
|
|
|
| - if (request_status != NULL && CURLMSG_DONE == request_status->msg) {
|
| - struct portal_request *portal_request = NULL;
|
| - struct connman_service *service;
|
| + if (request_status == NULL || CURLMSG_DONE != request_status->msg) {
|
| + _DBG_PORTAL("remaining status is %d", remaining_updates);
|
| + return TRUE;
|
| + }
|
|
|
| - curl_easy_getinfo(request_status->easy_handle, CURLINFO_PRIVATE,
|
| - (char **)&portal_request);
|
| - service = portal_request->service;
|
|
|
| - _DBG_PORTAL("service = %s",
|
| - connman_service_get_identifier(service));
|
| + curl_easy_getinfo(request_status->easy_handle, CURLINFO_PRIVATE,
|
| + (char **)&portal_request);
|
| + service = portal_request->service;
|
|
|
| - if (portal_request == latest_request) {
|
| - gboolean restricted = check_ip_pool(request_status);
|
| + _DBG_PORTAL("service = %s", connman_service_get_identifier(service));
|
|
|
| - connman_service_set_restricted_pool(service, restricted);
|
| - } else {
|
| - _DBG_PORTAL("Ignoring stale results");
|
| - }
|
| - curl_multi_remove_handle(curl_multi_handle_,
|
| - request_status->easy_handle);
|
| - free_request(portal_request);
|
| - _DBG_PORTAL("Cancelling the timer");
|
| - return FALSE;
|
| + if (portal_request == latest_request) {
|
| + enum connman_service_connectivity_state state =
|
| + check_connectivity_state(request_status);
|
| +
|
| + connman_service_set_connectivity_state(service, state);
|
| +
|
| + } else {
|
| + _DBG_PORTAL("Ignoring stale results");
|
| }
|
| - _DBG_PORTAL("remaining status is %d", remaining_updates);
|
| - return TRUE;
|
| + curl_multi_remove_handle(curl_multi_handle_,
|
| + request_status->easy_handle);
|
| + free_request(portal_request);
|
| + _DBG_PORTAL("Cancelling the timer");
|
| + return FALSE;
|
| }
|
|
|
| /**
|
| @@ -283,10 +300,12 @@ static void portal_default_changed(struct connman_service *service)
|
| }
|
| handle_multi_perform();
|
|
|
| - // The timer will fire once per second until the request
|
| - // has been processed.
|
| - //
|
| - // TODO(rtc): Consider using fd_sets instead.
|
| + /*
|
| + * The timer will fire once per second until the request
|
| + * has been processed.
|
| + *
|
| + * TODO(rtc): Consider using fd_sets instead.
|
| + */
|
| g_timeout_add_seconds(1, pending_request_callback, NULL);
|
| return;
|
|
|
| @@ -308,9 +327,10 @@ void portal_service_state_changed(struct connman_service *service)
|
| }
|
|
|
| if (g_strcmp0(service_state, "ready") != 0) {
|
| - _DBG_PORTAL("%s: Clearing restricted pool flag, not ready",
|
| + _DBG_PORTAL("%s: Setting connectivity state unknown, not ready",
|
| connman_service_get_identifier(service));
|
| - connman_service_set_restricted_pool(service, FALSE);
|
| + connman_service_set_connectivity_state(service,
|
| + CONNMAN_SERVICE_CONNECTIVITY_STATE_UNKNOWN);
|
| }
|
| }
|
|
|
|
|