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_ref(_wp_ctxt) \
37 wispr_portal_context_ref_debug(_wp_ctxt, __FILE__, __LINE__, __func__)
39 #define wispr_portal_context_unref(_wp_ctxt) \
40 wispr_portal_context_unref_debug(_wp_ctxt, __FILE__, __LINE__, __func__)
42 struct connman_wispr_message {
44 const char *current_element;
48 char *abort_login_url;
50 char *access_procedure;
51 char *access_location;
55 enum connman_wispr_result {
56 CONNMAN_WISPR_RESULT_UNKNOWN = 0,
57 CONNMAN_WISPR_RESULT_LOGIN = 1,
58 CONNMAN_WISPR_RESULT_ONLINE = 2,
59 CONNMAN_WISPR_RESULT_FAILED = 3,
67 struct connman_wispr_portal_context {
70 struct connman_service *service;
71 enum connman_ipconfig_type type;
72 struct connman_wispr_portal *wispr_portal;
74 /* Portal/WISPr common */
79 const char *status_url;
84 GWebParser *wispr_parser;
85 struct connman_wispr_message wispr_msg;
91 enum connman_wispr_result wispr_result;
96 struct connman_wispr_portal {
97 struct connman_wispr_portal_context *ipv4_context;
98 struct connman_wispr_portal_context *ipv6_context;
101 static gboolean wispr_portal_web_result(GWebResult *result, gpointer user_data);
103 static GHashTable *wispr_portal_list = NULL;
105 static void connman_wispr_message_init(struct connman_wispr_message *msg)
109 msg->has_error = FALSE;
110 msg->current_element = NULL;
112 msg->message_type = -1;
113 msg->response_code = -1;
115 g_free(msg->login_url);
116 msg->login_url = NULL;
118 g_free(msg->abort_login_url);
119 msg->abort_login_url = NULL;
121 g_free(msg->logoff_url);
122 msg->logoff_url = NULL;
124 g_free(msg->access_procedure);
125 msg->access_procedure = NULL;
127 g_free(msg->access_location);
128 msg->access_location = NULL;
130 g_free(msg->location_name);
131 msg->location_name = NULL;
134 static void free_wispr_routes(struct connman_wispr_portal_context *wp_context)
136 while (wp_context->route_list != NULL) {
137 struct wispr_route *route = wp_context->route_list->data;
139 DBG("free route to %s if %d type %d", route->address,
140 route->if_index, wp_context->type);
142 switch(wp_context->type) {
143 case CONNMAN_IPCONFIG_TYPE_IPV4:
144 connman_inet_del_host_route(route->if_index,
147 case CONNMAN_IPCONFIG_TYPE_IPV6:
148 connman_inet_del_ipv6_host_route(route->if_index,
151 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
155 g_free(route->address);
158 wp_context->route_list =
159 g_slist_delete_link(wp_context->route_list,
160 wp_context->route_list);
164 static void free_connman_wispr_portal_context(struct connman_wispr_portal_context *wp_context)
166 DBG("context %p", wp_context);
168 if (wp_context == NULL)
171 if (wp_context->wispr_portal != NULL) {
172 if (wp_context->wispr_portal->ipv4_context == wp_context)
173 wp_context->wispr_portal->ipv4_context = NULL;
175 if (wp_context->wispr_portal->ipv6_context == wp_context)
176 wp_context->wispr_portal->ipv6_context = NULL;
179 if (wp_context->service != NULL)
180 connman_service_unref(wp_context->service);
182 if (wp_context->token > 0)
183 connman_proxy_lookup_cancel(wp_context->token);
185 if (wp_context->request_id > 0)
186 g_web_cancel_request(wp_context->web, wp_context->request_id);
188 if (wp_context->web != NULL)
189 g_web_unref(wp_context->web);
191 g_free(wp_context->redirect_url);
193 if (wp_context->wispr_parser != NULL)
194 g_web_parser_unref(wp_context->wispr_parser);
196 connman_wispr_message_init(&wp_context->wispr_msg);
198 g_free(wp_context->wispr_username);
199 g_free(wp_context->wispr_password);
200 g_free(wp_context->wispr_formdata);
202 free_wispr_routes(wp_context);
207 static struct connman_wispr_portal_context *
208 wispr_portal_context_ref_debug(struct connman_wispr_portal_context *wp_context,
209 const char *file, int line, const char *caller)
211 DBG("%p ref %d by %s:%d:%s()", wp_context, wp_context->refcount + 1,
214 __sync_fetch_and_add(&wp_context->refcount, 1);
219 static struct connman_wispr_portal_context *
220 wispr_portal_context_unref_debug(struct connman_wispr_portal_context *wp_context,
221 const char *file, int line, const char *caller)
223 DBG("%p ref %d by %s:%d:%s()", wp_context, wp_context->refcount - 1,
226 if (__sync_fetch_and_sub(&wp_context->refcount, 1) != 1)
229 free_connman_wispr_portal_context(wp_context);
234 static struct connman_wispr_portal_context *create_wispr_portal_context(void)
236 struct connman_wispr_portal_context *wp_context = NULL;
238 wp_context = g_try_new0(struct connman_wispr_portal_context, 1);
239 if (wp_context == NULL)
242 wp_context->refcount = 1;
248 * This function is usued only by free_connman_wispr_portal, context pointer
249 * might still be owned by a third party (gweb, agent dbus call...)
250 * so we don't want service to be referenced in any context when it is not
254 reset_service_usage(struct connman_wispr_portal_context *wp_context)
256 if (wp_context->service == NULL)
259 connman_service_unref(wp_context->service);
260 wp_context->service = NULL;
263 static void free_connman_wispr_portal(gpointer data)
265 struct connman_wispr_portal *wispr_portal = data;
269 if (wispr_portal == NULL)
272 if (wispr_portal->ipv4_context != NULL) {
273 reset_service_usage(wispr_portal->ipv4_context);
274 wispr_portal_context_unref(wispr_portal->ipv4_context);
277 if (wispr_portal->ipv6_context != NULL) {
278 reset_service_usage(wispr_portal->ipv6_context);
279 wispr_portal_context_unref(wispr_portal->ipv6_context);
282 g_free(wispr_portal);
285 static const char *message_type_to_string(int message_type)
287 switch (message_type) {
289 return "Initial redirect message";
291 return "Proxy notification";
293 return "Authentication notification";
295 return "Logoff notification";
297 return "Response to Authentication Poll";
299 return "Response to Abort Login";
305 static const char *response_code_to_string(int response_code)
307 switch (response_code) {
311 return "Login succeeded";
313 return "Login failed";
315 return "RADIUS server error/timeout";
317 return "RADIUS server not enabled";
319 return "Logoff succeeded";
321 return "Login aborted";
323 return "Proxy detection/repeat operation";
325 return "Authentication pending";
327 return "Access gateway internal error";
336 WISPR_ELEMENT_NONE = 0,
337 WISPR_ELEMENT_ACCESS_PROCEDURE = 1,
338 WISPR_ELEMENT_ACCESS_LOCATION = 2,
339 WISPR_ELEMENT_LOCATION_NAME = 3,
340 WISPR_ELEMENT_LOGIN_URL = 4,
341 WISPR_ELEMENT_ABORT_LOGIN_URL = 5,
342 WISPR_ELEMENT_MESSAGE_TYPE = 6,
343 WISPR_ELEMENT_RESPONSE_CODE = 7,
344 WISPR_ELEMENT_NEXT_URL = 8,
345 WISPR_ELEMENT_DELAY = 9,
346 WISPR_ELEMENT_REPLY_MESSAGE = 10,
347 WISPR_ELEMENT_LOGIN_RESULTS_URL = 11,
348 WISPR_ELEMENT_LOGOFF_URL = 12,
350 } wispr_element_map[] = {
351 { "AccessProcedure", WISPR_ELEMENT_ACCESS_PROCEDURE },
352 { "AccessLocation", WISPR_ELEMENT_ACCESS_LOCATION },
353 { "LocationName", WISPR_ELEMENT_LOCATION_NAME },
354 { "LoginURL", WISPR_ELEMENT_LOGIN_URL },
355 { "AbortLoginURL", WISPR_ELEMENT_ABORT_LOGIN_URL },
356 { "MessageType", WISPR_ELEMENT_MESSAGE_TYPE },
357 { "ResponseCode", WISPR_ELEMENT_RESPONSE_CODE },
358 { "NextURL", WISPR_ELEMENT_NEXT_URL },
359 { "Delay", WISPR_ELEMENT_DELAY },
360 { "ReplyMessage", WISPR_ELEMENT_REPLY_MESSAGE },
361 { "LoginResultsURL", WISPR_ELEMENT_LOGIN_RESULTS_URL },
362 { "LogoffURL", WISPR_ELEMENT_LOGOFF_URL },
363 { NULL, WISPR_ELEMENT_NONE },
366 static void xml_wispr_start_element_handler(GMarkupParseContext *context,
367 const gchar *element_name,
368 const gchar **attribute_names,
369 const gchar **attribute_values,
370 gpointer user_data, GError **error)
372 struct connman_wispr_message *msg = user_data;
374 msg->current_element = element_name;
377 static void xml_wispr_end_element_handler(GMarkupParseContext *context,
378 const gchar *element_name,
379 gpointer user_data, GError **error)
381 struct connman_wispr_message *msg = user_data;
383 msg->current_element = NULL;
386 static void xml_wispr_text_handler(GMarkupParseContext *context,
387 const gchar *text, gsize text_len,
388 gpointer user_data, GError **error)
390 struct connman_wispr_message *msg = user_data;
393 if (msg->current_element == NULL)
396 for (i = 0; wispr_element_map[i].str; i++) {
397 if (g_str_equal(wispr_element_map[i].str,
398 msg->current_element) == FALSE)
401 switch (wispr_element_map[i].element) {
402 case WISPR_ELEMENT_NONE:
403 case WISPR_ELEMENT_ACCESS_PROCEDURE:
404 g_free(msg->access_procedure);
405 msg->access_procedure = g_strdup(text);
407 case WISPR_ELEMENT_ACCESS_LOCATION:
408 g_free(msg->access_location);
409 msg->access_location = g_strdup(text);
411 case WISPR_ELEMENT_LOCATION_NAME:
412 g_free(msg->location_name);
413 msg->location_name = g_strdup(text);
415 case WISPR_ELEMENT_LOGIN_URL:
416 g_free(msg->login_url);
417 msg->login_url = g_strdup(text);
419 case WISPR_ELEMENT_ABORT_LOGIN_URL:
420 g_free(msg->abort_login_url);
421 msg->abort_login_url = g_strdup(text);
423 case WISPR_ELEMENT_MESSAGE_TYPE:
424 msg->message_type = atoi(text);
426 case WISPR_ELEMENT_RESPONSE_CODE:
427 msg->response_code = atoi(text);
429 case WISPR_ELEMENT_NEXT_URL:
430 case WISPR_ELEMENT_DELAY:
431 case WISPR_ELEMENT_REPLY_MESSAGE:
432 case WISPR_ELEMENT_LOGIN_RESULTS_URL:
434 case WISPR_ELEMENT_LOGOFF_URL:
435 g_free(msg->logoff_url);
436 msg->logoff_url = g_strdup(text);
442 static void xml_wispr_error_handler(GMarkupParseContext *context,
443 GError *error, gpointer user_data)
445 struct connman_wispr_message *msg = user_data;
447 msg->has_error = TRUE;
450 static const GMarkupParser xml_wispr_parser_handlers = {
451 xml_wispr_start_element_handler,
452 xml_wispr_end_element_handler,
453 xml_wispr_text_handler,
455 xml_wispr_error_handler,
458 static void xml_wispr_parser_callback(const char *str, gpointer user_data)
460 struct connman_wispr_portal_context *wp_context = user_data;
461 GMarkupParseContext *parser_context = NULL;
466 parser_context = g_markup_parse_context_new(&xml_wispr_parser_handlers,
467 G_MARKUP_TREAT_CDATA_AS_TEXT,
468 &(wp_context->wispr_msg), NULL);
470 result = g_markup_parse_context_parse(parser_context,
471 str, strlen(str), NULL);
473 g_markup_parse_context_end_parse(parser_context, NULL);
475 g_markup_parse_context_free(parser_context);
478 static void web_debug(const char *str, void *data)
480 connman_info("%s: %s\n", (const char *) data, str);
483 static void wispr_portal_error(struct connman_wispr_portal_context *wp_context)
485 DBG("Failed to proceed wispr/portal web request");
487 wp_context->wispr_result = CONNMAN_WISPR_RESULT_FAILED;
490 static void portal_manage_status(GWebResult *result,
491 struct connman_wispr_portal_context *wp_context)
493 const char *str = NULL;
497 /* We currently don't do anything with this info */
498 if (g_web_result_get_header(result, "X-ConnMan-Client-IP",
500 connman_info("Client-IP: %s", str);
502 if (g_web_result_get_header(result, "X-ConnMan-Client-Country",
504 connman_info("Client-Country: %s", str);
506 if (g_web_result_get_header(result, "X-ConnMan-Client-Region",
508 connman_info("Client-Region: %s", str);
510 __connman_service_ipconfig_indicate_state(wp_context->service,
511 CONNMAN_SERVICE_STATE_ONLINE,
515 static gboolean wispr_route_request(const char *address, int ai_family,
516 int if_index, gpointer user_data)
519 struct connman_wispr_portal_context *wp_context = user_data;
521 struct wispr_route *route;
523 gateway = __connman_ipconfig_get_gateway_from_index(if_index,
526 DBG("address %s if %d gw %s", address, if_index, gateway);
531 route = g_try_new0(struct wispr_route, 1);
533 DBG("could not create struct");
537 switch(wp_context->type) {
538 case CONNMAN_IPCONFIG_TYPE_IPV4:
539 result = connman_inet_add_host_route(if_index, address,
542 case CONNMAN_IPCONFIG_TYPE_IPV6:
543 result = connman_inet_add_ipv6_host_route(if_index, address,
546 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
555 route->address = g_strdup(address);
556 route->if_index = if_index;
557 wp_context->route_list = g_slist_prepend(wp_context->route_list, route);
562 static void wispr_portal_request_portal(struct connman_wispr_portal_context *wp_context)
566 wp_context->request_id = g_web_request_get(wp_context->web,
567 wp_context->status_url,
568 wispr_portal_web_result,
572 if (wp_context->request_id == 0)
573 wispr_portal_error(wp_context);
576 static gboolean wispr_input(const guint8 **data, gsize *length,
579 struct connman_wispr_portal_context *wp_context = user_data;
585 buf = g_string_sized_new(100);
587 g_string_append(buf, "button=Login&UserName=");
588 g_string_append_uri_escaped(buf, wp_context->wispr_username,
590 g_string_append(buf, "&Password=");
591 g_string_append_uri_escaped(buf, wp_context->wispr_password,
593 g_string_append(buf, "&FNAME=0&OriginatingServer=");
594 g_string_append_uri_escaped(buf, wp_context->status_url, NULL, FALSE);
598 g_free(wp_context->wispr_formdata);
599 wp_context->wispr_formdata = g_string_free(buf, FALSE);
601 *data = (guint8 *) wp_context->wispr_formdata;
607 static void wispr_portal_browser_reply_cb(struct connman_service *service,
608 connman_bool_t authentication_done,
609 const char *error, void *user_data)
611 struct connman_wispr_portal_context *wp_context = user_data;
615 wp_context = wispr_portal_context_unref(wp_context);
616 if (service == NULL || wp_context == NULL)
619 if (authentication_done == FALSE) {
620 wispr_portal_error(wp_context);
621 free_wispr_routes(wp_context);
625 /* Restarting the test */
626 __connman_wispr_start(service, wp_context->type);
629 static void wispr_portal_request_wispr_login(struct connman_service *service,
630 connman_bool_t success,
631 const char *ssid, int ssid_len,
632 const char *username, const char *password,
633 gboolean wps, const char *wpspin,
634 const char *error, void *user_data)
636 struct connman_wispr_portal_context *wp_context = user_data;
640 wp_context = wispr_portal_context_unref(wp_context);
641 if (wp_context == NULL)
644 if (error != NULL && g_strcmp0(error,
645 "net.connman.Agent.Error.LaunchBrowser") == 0) {
646 wispr_portal_context_ref(wp_context);
648 if (__connman_agent_request_browser(service,
649 wispr_portal_browser_reply_cb,
650 wp_context->redirect_url,
651 wp_context) != -EINPROGRESS)
652 wispr_portal_context_unref(wp_context);
657 g_free(wp_context->wispr_username);
658 wp_context->wispr_username = g_strdup(username);
660 g_free(wp_context->wispr_password);
661 wp_context->wispr_password = g_strdup(password);
663 wp_context->request_id = g_web_request_post(wp_context->web,
664 wp_context->wispr_msg.login_url,
665 "application/x-www-form-urlencoded",
666 wispr_input, wispr_portal_web_result,
669 connman_wispr_message_init(&wp_context->wispr_msg);
672 static gboolean wispr_manage_message(GWebResult *result,
673 struct connman_wispr_portal_context *wp_context)
675 DBG("Message type: %s (%d)",
676 message_type_to_string(wp_context->wispr_msg.message_type),
677 wp_context->wispr_msg.message_type);
678 DBG("Response code: %s (%d)",
679 response_code_to_string(wp_context->wispr_msg.response_code),
680 wp_context->wispr_msg.response_code);
682 if (wp_context->wispr_msg.access_procedure != NULL)
683 DBG("Access procedure: %s",
684 wp_context->wispr_msg.access_procedure);
685 if (wp_context->wispr_msg.access_location != NULL)
686 DBG("Access location: %s",
687 wp_context->wispr_msg.access_location);
688 if (wp_context->wispr_msg.location_name != NULL)
689 DBG("Location name: %s",
690 wp_context->wispr_msg.location_name);
691 if (wp_context->wispr_msg.login_url != NULL)
692 DBG("Login URL: %s", wp_context->wispr_msg.login_url);
693 if (wp_context->wispr_msg.abort_login_url != NULL)
694 DBG("Abort login URL: %s",
695 wp_context->wispr_msg.abort_login_url);
696 if (wp_context->wispr_msg.logoff_url != NULL)
697 DBG("Logoff URL: %s", wp_context->wispr_msg.logoff_url);
699 switch (wp_context->wispr_msg.message_type) {
701 DBG("Login required");
703 wp_context->wispr_result = CONNMAN_WISPR_RESULT_LOGIN;
705 wispr_portal_context_ref(wp_context);
707 if (__connman_agent_request_login_input(wp_context->service,
708 wispr_portal_request_wispr_login,
709 wp_context) != -EINPROGRESS) {
710 wispr_portal_context_unref(wp_context);
711 wispr_portal_error(wp_context);
715 case 120: /* Falling down */
717 if (wp_context->wispr_msg.response_code == 50) {
718 wp_context->wispr_result = CONNMAN_WISPR_RESULT_ONLINE;
720 g_free(wp_context->wispr_username);
721 wp_context->wispr_username = NULL;
723 g_free(wp_context->wispr_password);
724 wp_context->wispr_password = NULL;
726 g_free(wp_context->wispr_formdata);
727 wp_context->wispr_formdata = NULL;
729 wispr_portal_request_portal(wp_context);
733 wispr_portal_error(wp_context);
743 static gboolean wispr_portal_web_result(GWebResult *result, gpointer user_data)
745 struct connman_wispr_portal_context *wp_context = user_data;
746 const char *redirect = NULL;
747 const guint8 *chunk = NULL;
748 const char *str = NULL;
754 if (wp_context->wispr_result != CONNMAN_WISPR_RESULT_ONLINE) {
755 g_web_result_get_chunk(result, &chunk, &length);
758 g_web_parser_feed_data(wp_context->wispr_parser,
763 g_web_parser_end_data(wp_context->wispr_parser);
765 if (wp_context->wispr_msg.message_type >= 0) {
766 if (wispr_manage_message(result, wp_context) == TRUE)
771 status = g_web_result_get_status(result);
773 DBG("status: %03u", status);
777 if (wp_context->wispr_msg.message_type >= 0)
780 if (g_web_result_get_header(result, "X-ConnMan-Status",
782 portal_manage_status(result, wp_context);
783 wispr_portal_context_unref(wp_context);
787 wispr_portal_context_ref(wp_context);
789 __connman_agent_request_browser(wp_context->service,
790 wispr_portal_browser_reply_cb,
791 wp_context->redirect_url, wp_context);
796 if (g_web_supports_tls() == FALSE ||
797 g_web_result_get_header(result, "Location",
798 &redirect) == FALSE) {
799 wispr_portal_context_ref(wp_context);
801 __connman_agent_request_browser(wp_context->service,
802 wispr_portal_browser_reply_cb,
803 wp_context->status_url, wp_context);
807 DBG("Redirect URL: %s", redirect);
809 wp_context->redirect_url = g_strdup(redirect);
811 wp_context->request_id = g_web_request_get(wp_context->web,
812 redirect, wispr_portal_web_result,
813 wispr_route_request, wp_context);
818 if (__connman_service_online_check_failed(wp_context->service,
819 wp_context->type) == 0) {
820 wispr_portal_error(wp_context);
821 wispr_portal_context_unref(wp_context);
830 free_wispr_routes(wp_context);
831 wp_context->request_id = 0;
833 wp_context->wispr_msg.message_type = -1;
837 static void proxy_callback(const char *proxy, void *user_data)
839 struct connman_wispr_portal_context *wp_context = user_data;
841 DBG("proxy %s", proxy);
843 if (wp_context == NULL)
846 wp_context->token = 0;
848 if (proxy != NULL && g_strcmp0(proxy, "DIRECT") != 0)
849 g_web_set_proxy(wp_context->web, proxy);
851 g_web_set_accept(wp_context->web, NULL);
852 g_web_set_user_agent(wp_context->web, "ConnMan/%s wispr", VERSION);
853 g_web_set_close_connection(wp_context->web, TRUE);
855 connman_wispr_message_init(&wp_context->wispr_msg);
857 wp_context->wispr_parser = g_web_parser_new(
858 "<WISPAccessGatewayParam",
859 "WISPAccessGatewayParam>",
860 xml_wispr_parser_callback, wp_context);
862 wispr_portal_request_portal(wp_context);
865 static gboolean no_proxy_callback(gpointer user_data)
867 struct connman_wispr_portal_context *wp_context = user_data;
869 proxy_callback("DIRECT", wp_context);
874 static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context)
876 enum connman_service_proxy_method proxy_method;
877 enum connman_service_type service_type;
878 char *interface = NULL;
879 char **nameservers = NULL;
884 DBG("wispr/portal context %p", wp_context);
885 DBG("service %p", wp_context->service);
887 service_type = connman_service_get_type(wp_context->service);
889 switch (service_type) {
890 case CONNMAN_SERVICE_TYPE_ETHERNET:
891 case CONNMAN_SERVICE_TYPE_WIFI:
892 case CONNMAN_SERVICE_TYPE_WIMAX:
893 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
894 case CONNMAN_SERVICE_TYPE_CELLULAR:
896 case CONNMAN_SERVICE_TYPE_UNKNOWN:
897 case CONNMAN_SERVICE_TYPE_SYSTEM:
898 case CONNMAN_SERVICE_TYPE_GPS:
899 case CONNMAN_SERVICE_TYPE_VPN:
900 case CONNMAN_SERVICE_TYPE_GADGET:
904 interface = connman_service_get_interface(wp_context->service);
905 if (interface == NULL)
908 DBG("interface %s", interface);
910 if_index = connman_inet_ifindex(interface);
912 DBG("Could not get ifindex");
917 nameservers = connman_service_get_nameservers(wp_context->service);
918 if (nameservers == NULL) {
919 DBG("Could not get nameservers");
924 wp_context->web = g_web_new(if_index);
925 if (wp_context->web == NULL) {
926 DBG("Could not set up GWeb");
931 if (getenv("CONNMAN_WEB_DEBUG"))
932 g_web_set_debug(wp_context->web, web_debug, "WEB");
934 if (wp_context->type == CONNMAN_IPCONFIG_TYPE_IPV4) {
935 g_web_set_address_family(wp_context->web, AF_INET);
936 wp_context->status_url = STATUS_URL_IPV4;
938 g_web_set_address_family(wp_context->web, AF_INET6);
939 wp_context->status_url = STATUS_URL_IPV6;
942 for (i = 0; nameservers[i] != NULL; i++)
943 g_web_add_nameserver(wp_context->web, nameservers[i]);
945 proxy_method = connman_service_get_proxy_method(wp_context->service);
947 if (proxy_method != CONNMAN_SERVICE_PROXY_METHOD_DIRECT) {
948 wp_context->token = connman_proxy_lookup(interface,
949 wp_context->status_url,
951 proxy_callback, wp_context);
953 if (wp_context->token == 0) {
955 wispr_portal_context_unref(wp_context);
958 g_timeout_add_seconds(0, no_proxy_callback, wp_context);
962 g_strfreev(nameservers);
968 int __connman_wispr_start(struct connman_service *service,
969 enum connman_ipconfig_type type)
971 struct connman_wispr_portal_context *wp_context = NULL;
972 struct connman_wispr_portal *wispr_portal = NULL;
975 DBG("service %p", service);
977 if (wispr_portal_list == NULL)
980 index = __connman_service_get_index(service);
984 wispr_portal = g_hash_table_lookup(wispr_portal_list,
985 GINT_TO_POINTER(index));
986 if (wispr_portal == NULL) {
987 wispr_portal = g_try_new0(struct connman_wispr_portal, 1);
988 if (wispr_portal == NULL)
991 g_hash_table_replace(wispr_portal_list,
992 GINT_TO_POINTER(index), wispr_portal);
995 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
996 wp_context = wispr_portal->ipv4_context;
997 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
998 wp_context = wispr_portal->ipv6_context;
1002 /* If there is already an existing context, we wipe it */
1003 if (wp_context != NULL)
1004 wispr_portal_context_unref(wp_context);
1006 wp_context = create_wispr_portal_context();
1007 if (wp_context == NULL)
1010 connman_service_ref(service);
1012 wp_context->service = service;
1013 wp_context->type = type;
1014 wp_context->wispr_portal = wispr_portal;
1016 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
1017 wispr_portal->ipv4_context = wp_context;
1019 wispr_portal->ipv6_context = wp_context;
1021 return wispr_portal_detect(wp_context);
1024 void __connman_wispr_stop(struct connman_service *service)
1028 DBG("service %p", service);
1030 if (wispr_portal_list == NULL)
1033 index = __connman_service_get_index(service);
1037 g_hash_table_remove(wispr_portal_list, GINT_TO_POINTER(index));
1040 int __connman_wispr_init(void)
1044 wispr_portal_list = g_hash_table_new_full(g_direct_hash,
1045 g_direct_equal, NULL,
1046 free_connman_wispr_portal);
1051 void __connman_wispr_cleanup(void)
1055 g_hash_table_destroy(wispr_portal_list);
1056 wispr_portal_list = NULL;