5 * Copyright (C) 2007-2012 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 #include <gweb/gweb.h>
33 #define STATUS_URL_IPV4 "http://ipv4.connman.net/online/status.html"
34 #define STATUS_URL_IPV6 "http://ipv6.connman.net/online/status.html"
36 #define wispr_portal_context_unref(_wp_ctxt) \
37 wispr_portal_context_unref_debug(_wp_ctxt, __FILE__, __LINE__, __func__)
39 struct connman_wispr_message {
41 const char *current_element;
45 char *abort_login_url;
47 char *access_procedure;
48 char *access_location;
52 enum connman_wispr_result {
53 CONNMAN_WISPR_RESULT_UNKNOWN = 0,
54 CONNMAN_WISPR_RESULT_LOGIN = 1,
55 CONNMAN_WISPR_RESULT_ONLINE = 2,
56 CONNMAN_WISPR_RESULT_FAILED = 3,
64 struct connman_wispr_portal_context {
67 struct connman_service *service;
68 enum connman_ipconfig_type type;
69 struct connman_wispr_portal *wispr_portal;
71 /* Portal/WISPr common */
76 const char *status_url;
81 GWebParser *wispr_parser;
82 struct connman_wispr_message wispr_msg;
88 enum connman_wispr_result wispr_result;
93 struct connman_wispr_portal {
94 struct connman_wispr_portal_context *ipv4_context;
95 struct connman_wispr_portal_context *ipv6_context;
98 static gboolean wispr_portal_web_result(GWebResult *result, gpointer user_data);
100 static GHashTable *wispr_portal_list = NULL;
102 static void connman_wispr_message_init(struct connman_wispr_message *msg)
106 msg->has_error = FALSE;
107 msg->current_element = NULL;
109 msg->message_type = -1;
110 msg->response_code = -1;
112 g_free(msg->login_url);
113 msg->login_url = NULL;
115 g_free(msg->abort_login_url);
116 msg->abort_login_url = NULL;
118 g_free(msg->logoff_url);
119 msg->logoff_url = NULL;
121 g_free(msg->access_procedure);
122 msg->access_procedure = NULL;
124 g_free(msg->access_location);
125 msg->access_location = NULL;
127 g_free(msg->location_name);
128 msg->location_name = NULL;
131 static void free_wispr_routes(struct connman_wispr_portal_context *wp_context)
133 while (wp_context->route_list != NULL) {
134 struct wispr_route *route = wp_context->route_list->data;
136 DBG("free route to %s if %d type %d", route->address,
137 route->if_index, wp_context->type);
139 switch(wp_context->type) {
140 case CONNMAN_IPCONFIG_TYPE_IPV4:
141 connman_inet_del_host_route(route->if_index,
144 case CONNMAN_IPCONFIG_TYPE_IPV6:
145 connman_inet_del_ipv6_host_route(route->if_index,
148 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
152 g_free(route->address);
155 wp_context->route_list =
156 g_slist_delete_link(wp_context->route_list,
157 wp_context->route_list);
161 static void free_connman_wispr_portal_context(struct connman_wispr_portal_context *wp_context)
163 DBG("context %p", wp_context);
165 if (wp_context == NULL)
168 if (wp_context->wispr_portal != NULL) {
169 if (wp_context->wispr_portal->ipv4_context == wp_context)
170 wp_context->wispr_portal->ipv4_context = NULL;
172 if (wp_context->wispr_portal->ipv6_context == wp_context)
173 wp_context->wispr_portal->ipv6_context = NULL;
176 if (wp_context->service != NULL)
177 connman_service_unref(wp_context->service);
179 if (wp_context->token > 0)
180 connman_proxy_lookup_cancel(wp_context->token);
182 if (wp_context->request_id > 0)
183 g_web_cancel_request(wp_context->web, wp_context->request_id);
185 if (wp_context->web != NULL)
186 g_web_unref(wp_context->web);
188 g_free(wp_context->redirect_url);
190 if (wp_context->wispr_parser != NULL)
191 g_web_parser_unref(wp_context->wispr_parser);
193 connman_wispr_message_init(&wp_context->wispr_msg);
195 g_free(wp_context->wispr_username);
196 g_free(wp_context->wispr_password);
197 g_free(wp_context->wispr_formdata);
199 free_wispr_routes(wp_context);
204 static struct connman_wispr_portal_context *
205 wispr_portal_context_unref_debug(struct connman_wispr_portal_context *wp_context,
206 const char *file, int line, const char *caller)
208 DBG("%p ref %d by %s:%d:%s()", wp_context, wp_context->refcount - 1,
211 if (__sync_fetch_and_sub(&wp_context->refcount, 1) != 1)
214 free_connman_wispr_portal_context(wp_context);
219 static struct connman_wispr_portal_context *create_wispr_portal_context(void)
221 struct connman_wispr_portal_context *wp_context = NULL;
223 wp_context = g_try_new0(struct connman_wispr_portal_context, 1);
224 if (wp_context == NULL)
227 wp_context->refcount = 1;
233 * This function is usued only by free_connman_wispr_portal, context pointer
234 * might still be owned by a third party (gweb, agent dbus call...)
235 * so we don't want service to be referenced in any context when it is not
239 reset_service_usage(struct connman_wispr_portal_context *wp_context)
241 if (wp_context->service == NULL)
244 connman_service_unref(wp_context->service);
245 wp_context->service = NULL;
248 static void free_connman_wispr_portal(gpointer data)
250 struct connman_wispr_portal *wispr_portal = data;
254 if (wispr_portal == NULL)
257 if (wispr_portal->ipv4_context != NULL) {
258 reset_service_usage(wispr_portal->ipv4_context);
259 wispr_portal_context_unref(wispr_portal->ipv4_context);
262 if (wispr_portal->ipv6_context != NULL) {
263 reset_service_usage(wispr_portal->ipv6_context);
264 wispr_portal_context_unref(wispr_portal->ipv6_context);
267 g_free(wispr_portal);
270 static const char *message_type_to_string(int message_type)
272 switch (message_type) {
274 return "Initial redirect message";
276 return "Proxy notification";
278 return "Authentication notification";
280 return "Logoff notification";
282 return "Response to Authentication Poll";
284 return "Response to Abort Login";
290 static const char *response_code_to_string(int response_code)
292 switch (response_code) {
296 return "Login succeeded";
298 return "Login failed";
300 return "RADIUS server error/timeout";
302 return "RADIUS server not enabled";
304 return "Logoff succeeded";
306 return "Login aborted";
308 return "Proxy detection/repeat operation";
310 return "Authentication pending";
312 return "Access gateway internal error";
321 WISPR_ELEMENT_NONE = 0,
322 WISPR_ELEMENT_ACCESS_PROCEDURE = 1,
323 WISPR_ELEMENT_ACCESS_LOCATION = 2,
324 WISPR_ELEMENT_LOCATION_NAME = 3,
325 WISPR_ELEMENT_LOGIN_URL = 4,
326 WISPR_ELEMENT_ABORT_LOGIN_URL = 5,
327 WISPR_ELEMENT_MESSAGE_TYPE = 6,
328 WISPR_ELEMENT_RESPONSE_CODE = 7,
329 WISPR_ELEMENT_NEXT_URL = 8,
330 WISPR_ELEMENT_DELAY = 9,
331 WISPR_ELEMENT_REPLY_MESSAGE = 10,
332 WISPR_ELEMENT_LOGIN_RESULTS_URL = 11,
333 WISPR_ELEMENT_LOGOFF_URL = 12,
335 } wispr_element_map[] = {
336 { "AccessProcedure", WISPR_ELEMENT_ACCESS_PROCEDURE },
337 { "AccessLocation", WISPR_ELEMENT_ACCESS_LOCATION },
338 { "LocationName", WISPR_ELEMENT_LOCATION_NAME },
339 { "LoginURL", WISPR_ELEMENT_LOGIN_URL },
340 { "AbortLoginURL", WISPR_ELEMENT_ABORT_LOGIN_URL },
341 { "MessageType", WISPR_ELEMENT_MESSAGE_TYPE },
342 { "ResponseCode", WISPR_ELEMENT_RESPONSE_CODE },
343 { "NextURL", WISPR_ELEMENT_NEXT_URL },
344 { "Delay", WISPR_ELEMENT_DELAY },
345 { "ReplyMessage", WISPR_ELEMENT_REPLY_MESSAGE },
346 { "LoginResultsURL", WISPR_ELEMENT_LOGIN_RESULTS_URL },
347 { "LogoffURL", WISPR_ELEMENT_LOGOFF_URL },
348 { NULL, WISPR_ELEMENT_NONE },
351 static void xml_wispr_start_element_handler(GMarkupParseContext *context,
352 const gchar *element_name,
353 const gchar **attribute_names,
354 const gchar **attribute_values,
355 gpointer user_data, GError **error)
357 struct connman_wispr_message *msg = user_data;
359 msg->current_element = element_name;
362 static void xml_wispr_end_element_handler(GMarkupParseContext *context,
363 const gchar *element_name,
364 gpointer user_data, GError **error)
366 struct connman_wispr_message *msg = user_data;
368 msg->current_element = NULL;
371 static void xml_wispr_text_handler(GMarkupParseContext *context,
372 const gchar *text, gsize text_len,
373 gpointer user_data, GError **error)
375 struct connman_wispr_message *msg = user_data;
378 if (msg->current_element == NULL)
381 for (i = 0; wispr_element_map[i].str; i++) {
382 if (g_str_equal(wispr_element_map[i].str,
383 msg->current_element) == FALSE)
386 switch (wispr_element_map[i].element) {
387 case WISPR_ELEMENT_NONE:
388 case WISPR_ELEMENT_ACCESS_PROCEDURE:
389 g_free(msg->access_procedure);
390 msg->access_procedure = g_strdup(text);
392 case WISPR_ELEMENT_ACCESS_LOCATION:
393 g_free(msg->access_location);
394 msg->access_location = g_strdup(text);
396 case WISPR_ELEMENT_LOCATION_NAME:
397 g_free(msg->location_name);
398 msg->location_name = g_strdup(text);
400 case WISPR_ELEMENT_LOGIN_URL:
401 g_free(msg->login_url);
402 msg->login_url = g_strdup(text);
404 case WISPR_ELEMENT_ABORT_LOGIN_URL:
405 g_free(msg->abort_login_url);
406 msg->abort_login_url = g_strdup(text);
408 case WISPR_ELEMENT_MESSAGE_TYPE:
409 msg->message_type = atoi(text);
411 case WISPR_ELEMENT_RESPONSE_CODE:
412 msg->response_code = atoi(text);
414 case WISPR_ELEMENT_NEXT_URL:
415 case WISPR_ELEMENT_DELAY:
416 case WISPR_ELEMENT_REPLY_MESSAGE:
417 case WISPR_ELEMENT_LOGIN_RESULTS_URL:
419 case WISPR_ELEMENT_LOGOFF_URL:
420 g_free(msg->logoff_url);
421 msg->logoff_url = g_strdup(text);
427 static void xml_wispr_error_handler(GMarkupParseContext *context,
428 GError *error, gpointer user_data)
430 struct connman_wispr_message *msg = user_data;
432 msg->has_error = TRUE;
435 static const GMarkupParser xml_wispr_parser_handlers = {
436 xml_wispr_start_element_handler,
437 xml_wispr_end_element_handler,
438 xml_wispr_text_handler,
440 xml_wispr_error_handler,
443 static void xml_wispr_parser_callback(const char *str, gpointer user_data)
445 struct connman_wispr_portal_context *wp_context = user_data;
446 GMarkupParseContext *parser_context = NULL;
451 parser_context = g_markup_parse_context_new(&xml_wispr_parser_handlers,
452 G_MARKUP_TREAT_CDATA_AS_TEXT,
453 &(wp_context->wispr_msg), NULL);
455 result = g_markup_parse_context_parse(parser_context,
456 str, strlen(str), NULL);
458 g_markup_parse_context_end_parse(parser_context, NULL);
460 g_markup_parse_context_free(parser_context);
463 static void web_debug(const char *str, void *data)
465 connman_info("%s: %s\n", (const char *) data, str);
468 static void wispr_portal_error(struct connman_wispr_portal_context *wp_context)
470 DBG("Failed to proceed wispr/portal web request");
472 wp_context->wispr_result = CONNMAN_WISPR_RESULT_FAILED;
475 static void portal_manage_status(GWebResult *result,
476 struct connman_wispr_portal_context *wp_context)
478 const char *str = NULL;
482 /* We currently don't do anything with this info */
483 if (g_web_result_get_header(result, "X-ConnMan-Client-IP",
485 connman_info("Client-IP: %s", str);
487 if (g_web_result_get_header(result, "X-ConnMan-Client-Country",
489 connman_info("Client-Country: %s", str);
491 if (g_web_result_get_header(result, "X-ConnMan-Client-Region",
493 connman_info("Client-Region: %s", str);
495 __connman_service_ipconfig_indicate_state(wp_context->service,
496 CONNMAN_SERVICE_STATE_ONLINE,
500 static gboolean wispr_route_request(const char *address, int ai_family,
501 int if_index, gpointer user_data)
504 struct connman_wispr_portal_context *wp_context = user_data;
506 struct wispr_route *route;
508 gateway = __connman_ipconfig_get_gateway_from_index(if_index,
511 DBG("address %s if %d gw %s", address, if_index, gateway);
516 route = g_try_new0(struct wispr_route, 1);
518 DBG("could not create struct");
522 switch(wp_context->type) {
523 case CONNMAN_IPCONFIG_TYPE_IPV4:
524 result = connman_inet_add_host_route(if_index, address,
527 case CONNMAN_IPCONFIG_TYPE_IPV6:
528 result = connman_inet_add_ipv6_host_route(if_index, address,
531 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
540 route->address = g_strdup(address);
541 route->if_index = if_index;
542 wp_context->route_list = g_slist_prepend(wp_context->route_list, route);
547 static void wispr_portal_request_portal(struct connman_wispr_portal_context *wp_context)
551 wp_context->request_id = g_web_request_get(wp_context->web,
552 wp_context->status_url,
553 wispr_portal_web_result,
557 if (wp_context->request_id == 0)
558 wispr_portal_error(wp_context);
561 static gboolean wispr_input(const guint8 **data, gsize *length,
564 struct connman_wispr_portal_context *wp_context = user_data;
570 buf = g_string_sized_new(100);
572 g_string_append(buf, "button=Login&UserName=");
573 g_string_append_uri_escaped(buf, wp_context->wispr_username,
575 g_string_append(buf, "&Password=");
576 g_string_append_uri_escaped(buf, wp_context->wispr_password,
578 g_string_append(buf, "&FNAME=0&OriginatingServer=");
579 g_string_append_uri_escaped(buf, wp_context->status_url, NULL, FALSE);
583 g_free(wp_context->wispr_formdata);
584 wp_context->wispr_formdata = g_string_free(buf, FALSE);
586 *data = (guint8 *) wp_context->wispr_formdata;
592 static void wispr_portal_browser_reply_cb(struct connman_service *service,
593 connman_bool_t authentication_done,
594 const char *error, void *user_data)
596 struct connman_wispr_portal_context *wp_context = user_data;
600 if (service == NULL || wp_context == NULL)
603 if (authentication_done == FALSE) {
604 wispr_portal_error(wp_context);
605 free_wispr_routes(wp_context);
609 /* Restarting the test */
610 __connman_wispr_start(service, wp_context->type);
613 static void wispr_portal_request_wispr_login(struct connman_service *service,
614 connman_bool_t success,
615 const char *ssid, int ssid_len,
616 const char *username, const char *password,
617 gboolean wps, const char *wpspin,
618 const char *error, void *user_data)
620 struct connman_wispr_portal_context *wp_context = user_data;
624 if (error != NULL && g_strcmp0(error,
625 "net.connman.Agent.Error.LaunchBrowser") == 0) {
627 if (__connman_agent_request_browser(service,
628 wispr_portal_browser_reply_cb,
629 wp_context->redirect_url,
630 wp_context) != -EINPROGRESS)
631 wispr_portal_context_unref(wp_context);
636 g_free(wp_context->wispr_username);
637 wp_context->wispr_username = g_strdup(username);
639 g_free(wp_context->wispr_password);
640 wp_context->wispr_password = g_strdup(password);
642 wp_context->request_id = g_web_request_post(wp_context->web,
643 wp_context->wispr_msg.login_url,
644 "application/x-www-form-urlencoded",
645 wispr_input, wispr_portal_web_result,
648 connman_wispr_message_init(&wp_context->wispr_msg);
651 static gboolean wispr_manage_message(GWebResult *result,
652 struct connman_wispr_portal_context *wp_context)
654 DBG("Message type: %s (%d)",
655 message_type_to_string(wp_context->wispr_msg.message_type),
656 wp_context->wispr_msg.message_type);
657 DBG("Response code: %s (%d)",
658 response_code_to_string(wp_context->wispr_msg.response_code),
659 wp_context->wispr_msg.response_code);
661 if (wp_context->wispr_msg.access_procedure != NULL)
662 DBG("Access procedure: %s",
663 wp_context->wispr_msg.access_procedure);
664 if (wp_context->wispr_msg.access_location != NULL)
665 DBG("Access location: %s",
666 wp_context->wispr_msg.access_location);
667 if (wp_context->wispr_msg.location_name != NULL)
668 DBG("Location name: %s",
669 wp_context->wispr_msg.location_name);
670 if (wp_context->wispr_msg.login_url != NULL)
671 DBG("Login URL: %s", wp_context->wispr_msg.login_url);
672 if (wp_context->wispr_msg.abort_login_url != NULL)
673 DBG("Abort login URL: %s",
674 wp_context->wispr_msg.abort_login_url);
675 if (wp_context->wispr_msg.logoff_url != NULL)
676 DBG("Logoff URL: %s", wp_context->wispr_msg.logoff_url);
678 switch (wp_context->wispr_msg.message_type) {
680 DBG("Login required");
682 wp_context->wispr_result = CONNMAN_WISPR_RESULT_LOGIN;
684 if (__connman_agent_request_login_input(wp_context->service,
685 wispr_portal_request_wispr_login,
686 wp_context) != -EINPROGRESS) {
687 wispr_portal_error(wp_context);
688 wispr_portal_context_unref(wp_context);
692 case 120: /* Falling down */
694 if (wp_context->wispr_msg.response_code == 50) {
695 wp_context->wispr_result = CONNMAN_WISPR_RESULT_ONLINE;
697 g_free(wp_context->wispr_username);
698 wp_context->wispr_username = NULL;
700 g_free(wp_context->wispr_password);
701 wp_context->wispr_password = NULL;
703 g_free(wp_context->wispr_formdata);
704 wp_context->wispr_formdata = NULL;
706 wispr_portal_request_portal(wp_context);
710 wispr_portal_error(wp_context);
720 static gboolean wispr_portal_web_result(GWebResult *result, gpointer user_data)
722 struct connman_wispr_portal_context *wp_context = user_data;
723 const char *redirect = NULL;
724 const guint8 *chunk = NULL;
725 const char *str = NULL;
731 if (wp_context->wispr_result != CONNMAN_WISPR_RESULT_ONLINE) {
732 g_web_result_get_chunk(result, &chunk, &length);
735 g_web_parser_feed_data(wp_context->wispr_parser,
740 g_web_parser_end_data(wp_context->wispr_parser);
742 if (wp_context->wispr_msg.message_type >= 0) {
743 if (wispr_manage_message(result, wp_context) == TRUE)
748 status = g_web_result_get_status(result);
750 DBG("status: %03u", status);
754 if (wp_context->wispr_msg.message_type >= 0)
757 if (g_web_result_get_header(result, "X-ConnMan-Status",
759 portal_manage_status(result, wp_context);
760 wispr_portal_context_unref(wp_context);
764 __connman_agent_request_browser(wp_context->service,
765 wispr_portal_browser_reply_cb,
766 wp_context->redirect_url, wp_context);
770 if (g_web_supports_tls() == FALSE ||
771 g_web_result_get_header(result, "Location",
772 &redirect) == FALSE) {
774 __connman_agent_request_browser(wp_context->service,
775 wispr_portal_browser_reply_cb,
776 wp_context->status_url, wp_context);
780 DBG("Redirect URL: %s", redirect);
782 wp_context->redirect_url = g_strdup(redirect);
784 wp_context->request_id = g_web_request_get(wp_context->web,
785 redirect, wispr_portal_web_result,
786 wispr_route_request, wp_context);
791 if (__connman_service_online_check_failed(wp_context->service,
792 wp_context->type) == 0) {
793 wispr_portal_error(wp_context);
794 wispr_portal_context_unref(wp_context);
803 free_wispr_routes(wp_context);
804 wp_context->request_id = 0;
806 wp_context->wispr_msg.message_type = -1;
810 static void proxy_callback(const char *proxy, void *user_data)
812 struct connman_wispr_portal_context *wp_context = user_data;
814 DBG("proxy %s", proxy);
816 if (wp_context == NULL)
819 wp_context->token = 0;
821 if (proxy != NULL && g_strcmp0(proxy, "DIRECT") != 0)
822 g_web_set_proxy(wp_context->web, proxy);
824 g_web_set_accept(wp_context->web, NULL);
825 g_web_set_user_agent(wp_context->web, "ConnMan/%s wispr", VERSION);
826 g_web_set_close_connection(wp_context->web, TRUE);
828 connman_wispr_message_init(&wp_context->wispr_msg);
830 wp_context->wispr_parser = g_web_parser_new(
831 "<WISPAccessGatewayParam",
832 "WISPAccessGatewayParam>",
833 xml_wispr_parser_callback, wp_context);
835 wispr_portal_request_portal(wp_context);
838 static gboolean no_proxy_callback(gpointer user_data)
840 struct connman_wispr_portal_context *wp_context = user_data;
842 proxy_callback("DIRECT", wp_context);
847 static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context)
849 enum connman_service_proxy_method proxy_method;
850 enum connman_service_type service_type;
851 char *interface = NULL;
852 char **nameservers = NULL;
857 DBG("wispr/portal context %p", wp_context);
858 DBG("service %p", wp_context->service);
860 service_type = connman_service_get_type(wp_context->service);
862 switch (service_type) {
863 case CONNMAN_SERVICE_TYPE_ETHERNET:
864 case CONNMAN_SERVICE_TYPE_WIFI:
865 case CONNMAN_SERVICE_TYPE_WIMAX:
866 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
867 case CONNMAN_SERVICE_TYPE_CELLULAR:
869 case CONNMAN_SERVICE_TYPE_UNKNOWN:
870 case CONNMAN_SERVICE_TYPE_SYSTEM:
871 case CONNMAN_SERVICE_TYPE_GPS:
872 case CONNMAN_SERVICE_TYPE_VPN:
873 case CONNMAN_SERVICE_TYPE_GADGET:
877 interface = connman_service_get_interface(wp_context->service);
878 if (interface == NULL)
881 DBG("interface %s", interface);
883 if_index = connman_inet_ifindex(interface);
885 DBG("Could not get ifindex");
890 nameservers = connman_service_get_nameservers(wp_context->service);
891 if (nameservers == NULL) {
892 DBG("Could not get nameservers");
897 wp_context->web = g_web_new(if_index);
898 if (wp_context->web == NULL) {
899 DBG("Could not set up GWeb");
904 if (getenv("CONNMAN_WEB_DEBUG"))
905 g_web_set_debug(wp_context->web, web_debug, "WEB");
907 if (wp_context->type == CONNMAN_IPCONFIG_TYPE_IPV4) {
908 g_web_set_address_family(wp_context->web, AF_INET);
909 wp_context->status_url = STATUS_URL_IPV4;
911 g_web_set_address_family(wp_context->web, AF_INET6);
912 wp_context->status_url = STATUS_URL_IPV6;
915 for (i = 0; nameservers[i] != NULL; i++)
916 g_web_add_nameserver(wp_context->web, nameservers[i]);
918 proxy_method = connman_service_get_proxy_method(wp_context->service);
920 if (proxy_method != CONNMAN_SERVICE_PROXY_METHOD_DIRECT) {
921 wp_context->token = connman_proxy_lookup(interface,
922 wp_context->status_url,
924 proxy_callback, wp_context);
926 if (wp_context->token == 0) {
928 wispr_portal_context_unref(wp_context);
931 g_timeout_add_seconds(0, no_proxy_callback, wp_context);
935 g_strfreev(nameservers);
941 int __connman_wispr_start(struct connman_service *service,
942 enum connman_ipconfig_type type)
944 struct connman_wispr_portal_context *wp_context = NULL;
945 struct connman_wispr_portal *wispr_portal = NULL;
948 DBG("service %p", service);
950 if (wispr_portal_list == NULL)
953 index = __connman_service_get_index(service);
957 wispr_portal = g_hash_table_lookup(wispr_portal_list,
958 GINT_TO_POINTER(index));
959 if (wispr_portal == NULL) {
960 wispr_portal = g_try_new0(struct connman_wispr_portal, 1);
961 if (wispr_portal == NULL)
964 g_hash_table_replace(wispr_portal_list,
965 GINT_TO_POINTER(index), wispr_portal);
968 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
969 wp_context = wispr_portal->ipv4_context;
970 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
971 wp_context = wispr_portal->ipv6_context;
975 /* If there is already an existing context, we wipe it */
976 if (wp_context != NULL)
977 wispr_portal_context_unref(wp_context);
979 wp_context = create_wispr_portal_context();
980 if (wp_context == NULL)
983 connman_service_ref(service);
985 wp_context->service = service;
986 wp_context->type = type;
987 wp_context->wispr_portal = wispr_portal;
989 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
990 wispr_portal->ipv4_context = wp_context;
992 wispr_portal->ipv6_context = wp_context;
994 return wispr_portal_detect(wp_context);
997 void __connman_wispr_stop(struct connman_service *service)
1001 DBG("service %p", service);
1003 if (wispr_portal_list == NULL)
1006 index = __connman_service_get_index(service);
1010 g_hash_table_remove(wispr_portal_list, GINT_TO_POINTER(index));
1013 int __connman_wispr_init(void)
1017 wispr_portal_list = g_hash_table_new_full(g_direct_hash,
1018 g_direct_equal, NULL,
1019 free_connman_wispr_portal);
1024 void __connman_wispr_cleanup(void)
1028 g_hash_table_destroy(wispr_portal_list);
1029 wispr_portal_list = NULL;