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;
73 /* Portal/WISPr common */
78 const char *status_url;
83 GWebParser *wispr_parser;
84 struct connman_wispr_message wispr_msg;
90 enum connman_wispr_result wispr_result;
95 struct connman_wispr_portal {
96 struct connman_wispr_portal_context *ipv4_context;
97 struct connman_wispr_portal_context *ipv6_context;
100 static gboolean wispr_portal_web_result(GWebResult *result, gpointer user_data);
102 static GHashTable *wispr_portal_list = NULL;
104 static void connman_wispr_message_init(struct connman_wispr_message *msg)
108 msg->has_error = FALSE;
109 msg->current_element = NULL;
111 msg->message_type = -1;
112 msg->response_code = -1;
114 g_free(msg->login_url);
115 msg->login_url = NULL;
117 g_free(msg->abort_login_url);
118 msg->abort_login_url = NULL;
120 g_free(msg->logoff_url);
121 msg->logoff_url = NULL;
123 g_free(msg->access_procedure);
124 msg->access_procedure = NULL;
126 g_free(msg->access_location);
127 msg->access_location = NULL;
129 g_free(msg->location_name);
130 msg->location_name = NULL;
133 static void free_wispr_routes(struct connman_wispr_portal_context *wp_context)
135 while (wp_context->route_list != NULL) {
136 struct wispr_route *route = wp_context->route_list->data;
138 DBG("free route to %s if %d type %d", route->address,
139 route->if_index, wp_context->type);
141 switch(wp_context->type) {
142 case CONNMAN_IPCONFIG_TYPE_IPV4:
143 connman_inet_del_host_route(route->if_index,
146 case CONNMAN_IPCONFIG_TYPE_IPV6:
147 connman_inet_del_ipv6_host_route(route->if_index,
150 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
154 g_free(route->address);
157 wp_context->route_list =
158 g_slist_delete_link(wp_context->route_list,
159 wp_context->route_list);
163 static void free_connman_wispr_portal_context(struct connman_wispr_portal_context *wp_context)
165 DBG("context %p", wp_context);
167 if (wp_context == NULL)
170 if (wp_context->service != NULL)
171 connman_service_unref(wp_context->service);
173 if (wp_context->token > 0)
174 connman_proxy_lookup_cancel(wp_context->token);
176 if (wp_context->request_id > 0)
177 g_web_cancel_request(wp_context->web, wp_context->request_id);
179 if (wp_context->web != NULL)
180 g_web_unref(wp_context->web);
182 g_free(wp_context->redirect_url);
184 if (wp_context->wispr_parser != NULL)
185 g_web_parser_unref(wp_context->wispr_parser);
187 connman_wispr_message_init(&wp_context->wispr_msg);
189 g_free(wp_context->wispr_username);
190 g_free(wp_context->wispr_password);
191 g_free(wp_context->wispr_formdata);
193 free_wispr_routes(wp_context);
198 static struct connman_wispr_portal_context *
199 wispr_portal_context_ref_debug(struct connman_wispr_portal_context *wp_context,
200 const char *file, int line, const char *caller)
202 DBG("%p ref %d by %s:%d:%s()", wp_context, wp_context->refcount + 1,
205 __sync_fetch_and_add(&wp_context->refcount, 1);
210 static struct connman_wispr_portal_context *
211 wispr_portal_context_unref_debug(struct connman_wispr_portal_context *wp_context,
212 const char *file, int line, const char *caller)
214 DBG("%p ref %d by %s:%d:%s()", wp_context, wp_context->refcount - 1,
217 if (__sync_fetch_and_sub(&wp_context->refcount, 1) != 1)
220 free_connman_wispr_portal_context(wp_context);
225 static struct connman_wispr_portal_context *create_wispr_portal_context(void)
227 struct connman_wispr_portal_context *wp_context = NULL;
229 wp_context = g_try_new0(struct connman_wispr_portal_context, 1);
230 if (wp_context == NULL)
233 wp_context->refcount = 1;
239 * This function is usued only by free_connman_wispr_portal, context pointer
240 * might still be owned by a third party (gweb, agent dbus call...)
241 * so we don't want service to be referenced in any context when it is not
245 reset_service_usage(struct connman_wispr_portal_context *wp_context)
247 if (wp_context->service == NULL)
250 connman_service_unref(wp_context->service);
251 wp_context->service = NULL;
254 static void free_connman_wispr_portal(gpointer data)
256 struct connman_wispr_portal *wispr_portal = data;
260 if (wispr_portal == NULL)
263 if (wispr_portal->ipv4_context != NULL) {
264 reset_service_usage(wispr_portal->ipv4_context);
265 wispr_portal_context_unref(wispr_portal->ipv4_context);
268 if (wispr_portal->ipv6_context != NULL) {
269 reset_service_usage(wispr_portal->ipv6_context);
270 wispr_portal_context_unref(wispr_portal->ipv6_context);
273 g_free(wispr_portal);
276 static const char *message_type_to_string(int message_type)
278 switch (message_type) {
280 return "Initial redirect message";
282 return "Proxy notification";
284 return "Authentication notification";
286 return "Logoff notification";
288 return "Response to Authentication Poll";
290 return "Response to Abort Login";
296 static const char *response_code_to_string(int response_code)
298 switch (response_code) {
302 return "Login succeeded";
304 return "Login failed";
306 return "RADIUS server error/timeout";
308 return "RADIUS server not enabled";
310 return "Logoff succeeded";
312 return "Login aborted";
314 return "Proxy detection/repeat operation";
316 return "Authentication pending";
318 return "Access gateway internal error";
327 WISPR_ELEMENT_NONE = 0,
328 WISPR_ELEMENT_ACCESS_PROCEDURE = 1,
329 WISPR_ELEMENT_ACCESS_LOCATION = 2,
330 WISPR_ELEMENT_LOCATION_NAME = 3,
331 WISPR_ELEMENT_LOGIN_URL = 4,
332 WISPR_ELEMENT_ABORT_LOGIN_URL = 5,
333 WISPR_ELEMENT_MESSAGE_TYPE = 6,
334 WISPR_ELEMENT_RESPONSE_CODE = 7,
335 WISPR_ELEMENT_NEXT_URL = 8,
336 WISPR_ELEMENT_DELAY = 9,
337 WISPR_ELEMENT_REPLY_MESSAGE = 10,
338 WISPR_ELEMENT_LOGIN_RESULTS_URL = 11,
339 WISPR_ELEMENT_LOGOFF_URL = 12,
341 } wispr_element_map[] = {
342 { "AccessProcedure", WISPR_ELEMENT_ACCESS_PROCEDURE },
343 { "AccessLocation", WISPR_ELEMENT_ACCESS_LOCATION },
344 { "LocationName", WISPR_ELEMENT_LOCATION_NAME },
345 { "LoginURL", WISPR_ELEMENT_LOGIN_URL },
346 { "AbortLoginURL", WISPR_ELEMENT_ABORT_LOGIN_URL },
347 { "MessageType", WISPR_ELEMENT_MESSAGE_TYPE },
348 { "ResponseCode", WISPR_ELEMENT_RESPONSE_CODE },
349 { "NextURL", WISPR_ELEMENT_NEXT_URL },
350 { "Delay", WISPR_ELEMENT_DELAY },
351 { "ReplyMessage", WISPR_ELEMENT_REPLY_MESSAGE },
352 { "LoginResultsURL", WISPR_ELEMENT_LOGIN_RESULTS_URL },
353 { "LogoffURL", WISPR_ELEMENT_LOGOFF_URL },
354 { NULL, WISPR_ELEMENT_NONE },
357 static void xml_wispr_start_element_handler(GMarkupParseContext *context,
358 const gchar *element_name,
359 const gchar **attribute_names,
360 const gchar **attribute_values,
361 gpointer user_data, GError **error)
363 struct connman_wispr_message *msg = user_data;
365 msg->current_element = element_name;
368 static void xml_wispr_end_element_handler(GMarkupParseContext *context,
369 const gchar *element_name,
370 gpointer user_data, GError **error)
372 struct connman_wispr_message *msg = user_data;
374 msg->current_element = NULL;
377 static void xml_wispr_text_handler(GMarkupParseContext *context,
378 const gchar *text, gsize text_len,
379 gpointer user_data, GError **error)
381 struct connman_wispr_message *msg = user_data;
384 if (msg->current_element == NULL)
387 for (i = 0; wispr_element_map[i].str; i++) {
388 if (g_str_equal(wispr_element_map[i].str,
389 msg->current_element) == FALSE)
392 switch (wispr_element_map[i].element) {
393 case WISPR_ELEMENT_NONE:
394 case WISPR_ELEMENT_ACCESS_PROCEDURE:
395 g_free(msg->access_procedure);
396 msg->access_procedure = g_strdup(text);
398 case WISPR_ELEMENT_ACCESS_LOCATION:
399 g_free(msg->access_location);
400 msg->access_location = g_strdup(text);
402 case WISPR_ELEMENT_LOCATION_NAME:
403 g_free(msg->location_name);
404 msg->location_name = g_strdup(text);
406 case WISPR_ELEMENT_LOGIN_URL:
407 g_free(msg->login_url);
408 msg->login_url = g_strdup(text);
410 case WISPR_ELEMENT_ABORT_LOGIN_URL:
411 g_free(msg->abort_login_url);
412 msg->abort_login_url = g_strdup(text);
414 case WISPR_ELEMENT_MESSAGE_TYPE:
415 msg->message_type = atoi(text);
417 case WISPR_ELEMENT_RESPONSE_CODE:
418 msg->response_code = atoi(text);
420 case WISPR_ELEMENT_NEXT_URL:
421 case WISPR_ELEMENT_DELAY:
422 case WISPR_ELEMENT_REPLY_MESSAGE:
423 case WISPR_ELEMENT_LOGIN_RESULTS_URL:
425 case WISPR_ELEMENT_LOGOFF_URL:
426 g_free(msg->logoff_url);
427 msg->logoff_url = g_strdup(text);
433 static void xml_wispr_error_handler(GMarkupParseContext *context,
434 GError *error, gpointer user_data)
436 struct connman_wispr_message *msg = user_data;
438 msg->has_error = TRUE;
441 static const GMarkupParser xml_wispr_parser_handlers = {
442 xml_wispr_start_element_handler,
443 xml_wispr_end_element_handler,
444 xml_wispr_text_handler,
446 xml_wispr_error_handler,
449 static void xml_wispr_parser_callback(const char *str, gpointer user_data)
451 struct connman_wispr_portal_context *wp_context = user_data;
452 GMarkupParseContext *parser_context = NULL;
457 parser_context = g_markup_parse_context_new(&xml_wispr_parser_handlers,
458 G_MARKUP_TREAT_CDATA_AS_TEXT,
459 &(wp_context->wispr_msg), NULL);
461 result = g_markup_parse_context_parse(parser_context,
462 str, strlen(str), NULL);
464 g_markup_parse_context_end_parse(parser_context, NULL);
466 g_markup_parse_context_free(parser_context);
469 static void web_debug(const char *str, void *data)
471 connman_info("%s: %s\n", (const char *) data, str);
474 static void wispr_portal_error(struct connman_wispr_portal_context *wp_context)
476 DBG("Failed to proceed wispr/portal web request");
478 wp_context->wispr_result = CONNMAN_WISPR_RESULT_FAILED;
481 static void portal_manage_status(GWebResult *result,
482 struct connman_wispr_portal_context *wp_context)
484 const char *str = NULL;
488 /* We currently don't do anything with this info */
489 if (g_web_result_get_header(result, "X-ConnMan-Client-IP",
491 connman_info("Client-IP: %s", str);
493 if (g_web_result_get_header(result, "X-ConnMan-Client-Country",
495 connman_info("Client-Country: %s", str);
497 if (g_web_result_get_header(result, "X-ConnMan-Client-Region",
499 connman_info("Client-Region: %s", str);
501 __connman_service_ipconfig_indicate_state(wp_context->service,
502 CONNMAN_SERVICE_STATE_ONLINE,
506 static gboolean wispr_route_request(const char *address, int ai_family,
507 int if_index, gpointer user_data)
510 struct connman_wispr_portal_context *wp_context = user_data;
512 struct wispr_route *route;
514 gateway = __connman_ipconfig_get_gateway_from_index(if_index,
517 DBG("address %s if %d gw %s", address, if_index, gateway);
522 route = g_try_new0(struct wispr_route, 1);
524 DBG("could not create struct");
528 switch(wp_context->type) {
529 case CONNMAN_IPCONFIG_TYPE_IPV4:
530 result = connman_inet_add_host_route(if_index, address,
533 case CONNMAN_IPCONFIG_TYPE_IPV6:
534 result = connman_inet_add_ipv6_host_route(if_index, address,
537 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
546 route->address = g_strdup(address);
547 route->if_index = if_index;
548 wp_context->route_list = g_slist_prepend(wp_context->route_list, route);
553 static void wispr_portal_request_portal(struct connman_wispr_portal_context *wp_context)
557 wp_context->request_id = g_web_request_get(wp_context->web,
558 wp_context->status_url,
559 wispr_portal_web_result,
563 if (wp_context->request_id == 0)
564 wispr_portal_error(wp_context);
566 wispr_portal_context_ref(wp_context);
569 static gboolean wispr_input(const guint8 **data, gsize *length,
572 struct connman_wispr_portal_context *wp_context = user_data;
578 buf = g_string_sized_new(100);
580 g_string_append(buf, "button=Login&UserName=");
581 g_string_append_uri_escaped(buf, wp_context->wispr_username,
583 g_string_append(buf, "&Password=");
584 g_string_append_uri_escaped(buf, wp_context->wispr_password,
586 g_string_append(buf, "&FNAME=0&OriginatingServer=");
587 g_string_append_uri_escaped(buf, wp_context->status_url, NULL, FALSE);
591 g_free(wp_context->wispr_formdata);
592 wp_context->wispr_formdata = g_string_free(buf, FALSE);
594 *data = (guint8 *) wp_context->wispr_formdata;
600 static void wispr_portal_browser_reply_cb(struct connman_service *service,
601 connman_bool_t authentication_done,
602 const char *error, void *user_data)
604 struct connman_wispr_portal_context *wp_context = user_data;
608 wp_context = wispr_portal_context_unref(wp_context);
609 if (service == NULL || wp_context == NULL)
612 if (authentication_done == FALSE) {
613 wispr_portal_error(wp_context);
614 free_wispr_routes(wp_context);
618 /* Restarting the test */
619 __connman_wispr_start(service, wp_context->type);
622 static void wispr_portal_request_wispr_login(struct connman_service *service,
623 connman_bool_t success,
624 const char *ssid, int ssid_len,
625 const char *username, const char *password,
626 gboolean wps, const char *wpspin,
627 const char *error, void *user_data)
629 struct connman_wispr_portal_context *wp_context = user_data;
633 wp_context = wispr_portal_context_unref(wp_context);
634 if (wp_context == NULL)
637 if (error != NULL && g_strcmp0(error,
638 "net.connman.Agent.Error.LaunchBrowser") == 0) {
639 wispr_portal_context_ref(wp_context);
641 __connman_agent_request_browser(service,
642 wispr_portal_browser_reply_cb,
643 wp_context->redirect_url, wp_context);
647 g_free(wp_context->wispr_username);
648 wp_context->wispr_username = g_strdup(username);
650 g_free(wp_context->wispr_password);
651 wp_context->wispr_password = g_strdup(password);
653 wp_context->request_id = g_web_request_post(wp_context->web,
654 wp_context->wispr_msg.login_url,
655 "application/x-www-form-urlencoded",
656 wispr_input, wispr_portal_web_result,
658 if (wp_context->request_id != 0)
659 wispr_portal_context_ref(wp_context);
661 connman_wispr_message_init(&wp_context->wispr_msg);
664 static gboolean wispr_manage_message(GWebResult *result,
665 struct connman_wispr_portal_context *wp_context)
667 DBG("Message type: %s (%d)",
668 message_type_to_string(wp_context->wispr_msg.message_type),
669 wp_context->wispr_msg.message_type);
670 DBG("Response code: %s (%d)",
671 response_code_to_string(wp_context->wispr_msg.response_code),
672 wp_context->wispr_msg.response_code);
674 if (wp_context->wispr_msg.access_procedure != NULL)
675 DBG("Access procedure: %s",
676 wp_context->wispr_msg.access_procedure);
677 if (wp_context->wispr_msg.access_location != NULL)
678 DBG("Access location: %s",
679 wp_context->wispr_msg.access_location);
680 if (wp_context->wispr_msg.location_name != NULL)
681 DBG("Location name: %s",
682 wp_context->wispr_msg.location_name);
683 if (wp_context->wispr_msg.login_url != NULL)
684 DBG("Login URL: %s", wp_context->wispr_msg.login_url);
685 if (wp_context->wispr_msg.abort_login_url != NULL)
686 DBG("Abort login URL: %s",
687 wp_context->wispr_msg.abort_login_url);
688 if (wp_context->wispr_msg.logoff_url != NULL)
689 DBG("Logoff URL: %s", wp_context->wispr_msg.logoff_url);
691 switch (wp_context->wispr_msg.message_type) {
693 DBG("Login required");
695 wp_context->wispr_result = CONNMAN_WISPR_RESULT_LOGIN;
697 wispr_portal_context_ref(wp_context);
699 if (__connman_agent_request_login_input(wp_context->service,
700 wispr_portal_request_wispr_login,
701 wp_context) != -EINPROGRESS) {
702 wispr_portal_context_unref(wp_context);
703 wispr_portal_error(wp_context);
707 case 120: /* Falling down */
709 if (wp_context->wispr_msg.response_code == 50) {
710 wp_context->wispr_result = CONNMAN_WISPR_RESULT_ONLINE;
712 g_free(wp_context->wispr_username);
713 wp_context->wispr_username = NULL;
715 g_free(wp_context->wispr_password);
716 wp_context->wispr_password = NULL;
718 g_free(wp_context->wispr_formdata);
719 wp_context->wispr_formdata = NULL;
721 wispr_portal_request_portal(wp_context);
725 wispr_portal_error(wp_context);
735 static gboolean wispr_portal_web_result(GWebResult *result, gpointer user_data)
737 struct connman_wispr_portal_context *wp_context = user_data;
738 const char *redirect = NULL;
739 const guint8 *chunk = NULL;
740 const char *str = NULL;
746 wp_context = wispr_portal_context_unref(wp_context);
747 if (wp_context == NULL)
750 if (wp_context->request_id == 0)
753 if (wp_context->wispr_result != CONNMAN_WISPR_RESULT_ONLINE) {
754 g_web_result_get_chunk(result, &chunk, &length);
757 wispr_portal_context_ref(wp_context);
759 g_web_parser_feed_data(wp_context->wispr_parser,
764 g_web_parser_end_data(wp_context->wispr_parser);
766 if (wp_context->wispr_msg.message_type >= 0) {
767 if (wispr_manage_message(result, wp_context) == TRUE)
772 status = g_web_result_get_status(result);
774 DBG("status: %03u", status);
778 if (wp_context->wispr_msg.message_type >= 0)
781 if (g_web_result_get_header(result, "X-ConnMan-Status",
783 portal_manage_status(result, wp_context);
785 wispr_portal_context_ref(wp_context);
787 __connman_agent_request_browser(wp_context->service,
788 wispr_portal_browser_reply_cb,
789 wp_context->redirect_url, wp_context);
794 if (g_web_supports_tls() == FALSE ||
795 g_web_result_get_header(result, "Location",
796 &redirect) == FALSE) {
797 wispr_portal_context_ref(wp_context);
799 __connman_agent_request_browser(wp_context->service,
800 wispr_portal_browser_reply_cb,
801 wp_context->status_url, wp_context);
805 DBG("Redirect URL: %s", redirect);
807 wp_context->redirect_url = g_strdup(redirect);
809 wp_context->request_id = g_web_request_get(wp_context->web,
810 redirect, wispr_portal_web_result,
811 wispr_route_request, wp_context);
812 if (wp_context->request_id != 0)
813 wispr_portal_context_ref(wp_context);
818 if (__connman_service_online_check_failed(wp_context->service,
819 wp_context->type) == 0)
820 wispr_portal_error(wp_context);
827 free_wispr_routes(wp_context);
828 wp_context->request_id = 0;
830 wp_context->wispr_msg.message_type = -1;
834 static void proxy_callback(const char *proxy, void *user_data)
836 struct connman_wispr_portal_context *wp_context = user_data;
838 DBG("proxy %s", proxy);
840 wp_context = wispr_portal_context_unref(wp_context);
841 if (wp_context == NULL)
844 wp_context->token = 0;
846 if (proxy != NULL && g_strcmp0(proxy, "DIRECT") != 0)
847 g_web_set_proxy(wp_context->web, proxy);
849 g_web_set_accept(wp_context->web, NULL);
850 g_web_set_user_agent(wp_context->web, "ConnMan/%s wispr", VERSION);
851 g_web_set_close_connection(wp_context->web, TRUE);
853 connman_wispr_message_init(&wp_context->wispr_msg);
855 wp_context->wispr_parser = g_web_parser_new(
856 "<WISPAccessGatewayParam",
857 "WISPAccessGatewayParam>",
858 xml_wispr_parser_callback, wp_context);
860 wispr_portal_request_portal(wp_context);
863 static gboolean no_proxy_callback(gpointer user_data)
865 struct connman_wispr_portal_context *wp_context = user_data;
867 proxy_callback("DIRECT", wp_context);
872 static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context)
874 enum connman_service_proxy_method proxy_method;
875 enum connman_service_type service_type;
876 char *interface = NULL;
877 char **nameservers = NULL;
882 DBG("wispr/portal context %p", wp_context);
883 DBG("service %p", wp_context->service);
885 service_type = connman_service_get_type(wp_context->service);
887 switch (service_type) {
888 case CONNMAN_SERVICE_TYPE_ETHERNET:
889 case CONNMAN_SERVICE_TYPE_WIFI:
890 case CONNMAN_SERVICE_TYPE_WIMAX:
891 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
892 case CONNMAN_SERVICE_TYPE_CELLULAR:
894 case CONNMAN_SERVICE_TYPE_UNKNOWN:
895 case CONNMAN_SERVICE_TYPE_SYSTEM:
896 case CONNMAN_SERVICE_TYPE_GPS:
897 case CONNMAN_SERVICE_TYPE_VPN:
898 case CONNMAN_SERVICE_TYPE_GADGET:
902 interface = connman_service_get_interface(wp_context->service);
903 if (interface == NULL)
906 DBG("interface %s", interface);
908 if_index = connman_inet_ifindex(interface);
910 DBG("Could not get ifindex");
915 nameservers = connman_service_get_nameservers(wp_context->service);
916 if (nameservers == NULL) {
917 DBG("Could not get nameservers");
922 wp_context->web = g_web_new(if_index);
923 if (wp_context->web == NULL) {
924 DBG("Could not set up GWeb");
929 if (getenv("CONNMAN_WEB_DEBUG"))
930 g_web_set_debug(wp_context->web, web_debug, "WEB");
932 if (wp_context->type == CONNMAN_IPCONFIG_TYPE_IPV4) {
933 g_web_set_address_family(wp_context->web, AF_INET);
934 wp_context->status_url = STATUS_URL_IPV4;
936 g_web_set_address_family(wp_context->web, AF_INET6);
937 wp_context->status_url = STATUS_URL_IPV6;
940 for (i = 0; nameservers[i] != NULL; i++)
941 g_web_add_nameserver(wp_context->web, nameservers[i]);
943 proxy_method = connman_service_get_proxy_method(wp_context->service);
945 if (proxy_method != CONNMAN_SERVICE_PROXY_METHOD_DIRECT) {
946 wp_context->token = connman_proxy_lookup(interface,
947 wp_context->status_url,
949 proxy_callback, wp_context);
951 if (wp_context->token == 0) {
956 g_timeout_add_seconds(0, no_proxy_callback, wp_context);
959 wispr_portal_context_ref(wp_context);
961 g_strfreev(nameservers);
967 int __connman_wispr_start(struct connman_service *service,
968 enum connman_ipconfig_type type)
970 struct connman_wispr_portal_context *wp_context = NULL;
971 struct connman_wispr_portal *wispr_portal = NULL;
974 DBG("service %p", service);
976 if (wispr_portal_list == NULL)
979 index = __connman_service_get_index(service);
983 wispr_portal = g_hash_table_lookup(wispr_portal_list,
984 GINT_TO_POINTER(index));
985 if (wispr_portal == NULL) {
986 wispr_portal = g_try_new0(struct connman_wispr_portal, 1);
987 if (wispr_portal == NULL)
990 g_hash_table_replace(wispr_portal_list,
991 GINT_TO_POINTER(index), wispr_portal);
994 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
995 wp_context = wispr_portal->ipv4_context;
996 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
997 wp_context = wispr_portal->ipv6_context;
1001 /* If there is already an existing context, we wipe it */
1002 if (wp_context != NULL)
1003 wispr_portal_context_unref(wp_context);
1005 wp_context = create_wispr_portal_context();
1006 if (wp_context == NULL)
1009 connman_service_ref(service);
1011 wp_context->service = service;
1012 wp_context->type = type;
1014 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
1015 wispr_portal->ipv4_context = wp_context;
1017 wispr_portal->ipv6_context = wp_context;
1019 return wispr_portal_detect(wp_context);
1022 void __connman_wispr_stop(struct connman_service *service)
1026 DBG("service %p", service);
1028 if (wispr_portal_list == NULL)
1031 index = __connman_service_get_index(service);
1035 g_hash_table_remove(wispr_portal_list, GINT_TO_POINTER(index));
1038 int __connman_wispr_init(void)
1042 wispr_portal_list = g_hash_table_new_full(g_direct_hash,
1043 g_direct_equal, NULL,
1044 free_connman_wispr_portal);
1049 void __connman_wispr_cleanup(void)
1053 g_hash_table_destroy(wispr_portal_list);
1054 wispr_portal_list = NULL;