5 * Copyright (C) 2007-2013 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 struct connman_wispr_message {
38 const char *current_element;
42 char *abort_login_url;
44 char *access_procedure;
45 char *access_location;
49 enum connman_wispr_result {
50 CONNMAN_WISPR_RESULT_UNKNOWN = 0,
51 CONNMAN_WISPR_RESULT_LOGIN = 1,
52 CONNMAN_WISPR_RESULT_ONLINE = 2,
53 CONNMAN_WISPR_RESULT_FAILED = 3,
61 struct connman_wispr_portal_context {
62 struct connman_service *service;
63 enum connman_ipconfig_type type;
64 struct connman_wispr_portal *wispr_portal;
66 /* Portal/WISPr common */
71 const char *status_url;
76 GWebParser *wispr_parser;
77 struct connman_wispr_message wispr_msg;
83 enum connman_wispr_result wispr_result;
90 struct connman_wispr_portal {
91 struct connman_wispr_portal_context *ipv4_context;
92 struct connman_wispr_portal_context *ipv6_context;
95 static bool wispr_portal_web_result(GWebResult *result, gpointer user_data);
97 static GHashTable *wispr_portal_list = NULL;
99 static void connman_wispr_message_init(struct connman_wispr_message *msg)
103 msg->has_error = false;
104 msg->current_element = NULL;
106 msg->message_type = -1;
107 msg->response_code = -1;
109 g_free(msg->login_url);
110 msg->login_url = NULL;
112 g_free(msg->abort_login_url);
113 msg->abort_login_url = NULL;
115 g_free(msg->logoff_url);
116 msg->logoff_url = NULL;
118 g_free(msg->access_procedure);
119 msg->access_procedure = NULL;
121 g_free(msg->access_location);
122 msg->access_location = NULL;
124 g_free(msg->location_name);
125 msg->location_name = NULL;
128 static void free_wispr_routes(struct connman_wispr_portal_context *wp_context)
130 while (wp_context->route_list) {
131 struct wispr_route *route = wp_context->route_list->data;
133 DBG("free route to %s if %d type %d", route->address,
134 route->if_index, wp_context->type);
136 switch (wp_context->type) {
137 case CONNMAN_IPCONFIG_TYPE_IPV4:
138 connman_inet_del_host_route(route->if_index,
141 case CONNMAN_IPCONFIG_TYPE_IPV6:
142 connman_inet_del_ipv6_host_route(route->if_index,
145 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
146 case CONNMAN_IPCONFIG_TYPE_ALL:
150 g_free(route->address);
153 wp_context->route_list =
154 g_slist_delete_link(wp_context->route_list,
155 wp_context->route_list);
159 static void free_connman_wispr_portal_context(
160 struct connman_wispr_portal_context *wp_context)
162 DBG("context %p", wp_context);
167 if (wp_context->wispr_portal) {
168 if (wp_context->wispr_portal->ipv4_context == wp_context)
169 wp_context->wispr_portal->ipv4_context = NULL;
171 if (wp_context->wispr_portal->ipv6_context == wp_context)
172 wp_context->wispr_portal->ipv6_context = NULL;
175 if (wp_context->token > 0)
176 connman_proxy_lookup_cancel(wp_context->token);
178 if (wp_context->request_id > 0)
179 g_web_cancel_request(wp_context->web, wp_context->request_id);
181 if (wp_context->timeout > 0)
182 g_source_remove(wp_context->timeout);
185 g_web_unref(wp_context->web);
187 g_free(wp_context->redirect_url);
189 if (wp_context->wispr_parser)
190 g_web_parser_unref(wp_context->wispr_parser);
192 connman_wispr_message_init(&wp_context->wispr_msg);
194 g_free(wp_context->wispr_username);
195 g_free(wp_context->wispr_password);
196 g_free(wp_context->wispr_formdata);
198 free_wispr_routes(wp_context);
203 static struct connman_wispr_portal_context *create_wispr_portal_context(void)
205 return g_try_new0(struct connman_wispr_portal_context, 1);
208 static void free_connman_wispr_portal(gpointer data)
210 struct connman_wispr_portal *wispr_portal = data;
217 free_connman_wispr_portal_context(wispr_portal->ipv4_context);
218 free_connman_wispr_portal_context(wispr_portal->ipv6_context);
220 g_free(wispr_portal);
223 static const char *message_type_to_string(int message_type)
225 switch (message_type) {
227 return "Initial redirect message";
229 return "Proxy notification";
231 return "Authentication notification";
233 return "Logoff notification";
235 return "Response to Authentication Poll";
237 return "Response to Abort Login";
243 static const char *response_code_to_string(int response_code)
245 switch (response_code) {
249 return "Login succeeded";
251 return "Login failed";
253 return "RADIUS server error/timeout";
255 return "RADIUS server not enabled";
257 return "Logoff succeeded";
259 return "Login aborted";
261 return "Proxy detection/repeat operation";
263 return "Authentication pending";
265 return "Access gateway internal error";
274 WISPR_ELEMENT_NONE = 0,
275 WISPR_ELEMENT_ACCESS_PROCEDURE = 1,
276 WISPR_ELEMENT_ACCESS_LOCATION = 2,
277 WISPR_ELEMENT_LOCATION_NAME = 3,
278 WISPR_ELEMENT_LOGIN_URL = 4,
279 WISPR_ELEMENT_ABORT_LOGIN_URL = 5,
280 WISPR_ELEMENT_MESSAGE_TYPE = 6,
281 WISPR_ELEMENT_RESPONSE_CODE = 7,
282 WISPR_ELEMENT_NEXT_URL = 8,
283 WISPR_ELEMENT_DELAY = 9,
284 WISPR_ELEMENT_REPLY_MESSAGE = 10,
285 WISPR_ELEMENT_LOGIN_RESULTS_URL = 11,
286 WISPR_ELEMENT_LOGOFF_URL = 12,
288 } wispr_element_map[] = {
289 { "AccessProcedure", WISPR_ELEMENT_ACCESS_PROCEDURE },
290 { "AccessLocation", WISPR_ELEMENT_ACCESS_LOCATION },
291 { "LocationName", WISPR_ELEMENT_LOCATION_NAME },
292 { "LoginURL", WISPR_ELEMENT_LOGIN_URL },
293 { "AbortLoginURL", WISPR_ELEMENT_ABORT_LOGIN_URL },
294 { "MessageType", WISPR_ELEMENT_MESSAGE_TYPE },
295 { "ResponseCode", WISPR_ELEMENT_RESPONSE_CODE },
296 { "NextURL", WISPR_ELEMENT_NEXT_URL },
297 { "Delay", WISPR_ELEMENT_DELAY },
298 { "ReplyMessage", WISPR_ELEMENT_REPLY_MESSAGE },
299 { "LoginResultsURL", WISPR_ELEMENT_LOGIN_RESULTS_URL },
300 { "LogoffURL", WISPR_ELEMENT_LOGOFF_URL },
301 { NULL, WISPR_ELEMENT_NONE },
304 static void xml_wispr_start_element_handler(GMarkupParseContext *context,
305 const gchar *element_name,
306 const gchar **attribute_names,
307 const gchar **attribute_values,
308 gpointer user_data, GError **error)
310 struct connman_wispr_message *msg = user_data;
312 msg->current_element = element_name;
315 static void xml_wispr_end_element_handler(GMarkupParseContext *context,
316 const gchar *element_name,
317 gpointer user_data, GError **error)
319 struct connman_wispr_message *msg = user_data;
321 msg->current_element = NULL;
324 static void xml_wispr_text_handler(GMarkupParseContext *context,
325 const gchar *text, gsize text_len,
326 gpointer user_data, GError **error)
328 struct connman_wispr_message *msg = user_data;
331 if (!msg->current_element)
334 for (i = 0; wispr_element_map[i].str; i++) {
335 if (!g_str_equal(wispr_element_map[i].str, msg->current_element))
338 switch (wispr_element_map[i].element) {
339 case WISPR_ELEMENT_NONE:
340 case WISPR_ELEMENT_ACCESS_PROCEDURE:
341 g_free(msg->access_procedure);
342 msg->access_procedure = g_strdup(text);
344 case WISPR_ELEMENT_ACCESS_LOCATION:
345 g_free(msg->access_location);
346 msg->access_location = g_strdup(text);
348 case WISPR_ELEMENT_LOCATION_NAME:
349 g_free(msg->location_name);
350 msg->location_name = g_strdup(text);
352 case WISPR_ELEMENT_LOGIN_URL:
353 g_free(msg->login_url);
354 msg->login_url = g_strdup(text);
356 case WISPR_ELEMENT_ABORT_LOGIN_URL:
357 g_free(msg->abort_login_url);
358 msg->abort_login_url = g_strdup(text);
360 case WISPR_ELEMENT_MESSAGE_TYPE:
361 msg->message_type = atoi(text);
363 case WISPR_ELEMENT_RESPONSE_CODE:
364 msg->response_code = atoi(text);
366 case WISPR_ELEMENT_NEXT_URL:
367 case WISPR_ELEMENT_DELAY:
368 case WISPR_ELEMENT_REPLY_MESSAGE:
369 case WISPR_ELEMENT_LOGIN_RESULTS_URL:
371 case WISPR_ELEMENT_LOGOFF_URL:
372 g_free(msg->logoff_url);
373 msg->logoff_url = g_strdup(text);
379 static void xml_wispr_error_handler(GMarkupParseContext *context,
380 GError *error, gpointer user_data)
382 struct connman_wispr_message *msg = user_data;
384 msg->has_error = true;
387 static const GMarkupParser xml_wispr_parser_handlers = {
388 xml_wispr_start_element_handler,
389 xml_wispr_end_element_handler,
390 xml_wispr_text_handler,
392 xml_wispr_error_handler,
395 static void xml_wispr_parser_callback(const char *str, gpointer user_data)
397 struct connman_wispr_portal_context *wp_context = user_data;
398 GMarkupParseContext *parser_context = NULL;
403 parser_context = g_markup_parse_context_new(&xml_wispr_parser_handlers,
404 G_MARKUP_TREAT_CDATA_AS_TEXT,
405 &(wp_context->wispr_msg), NULL);
407 result = g_markup_parse_context_parse(parser_context,
408 str, strlen(str), NULL);
410 g_markup_parse_context_end_parse(parser_context, NULL);
412 g_markup_parse_context_free(parser_context);
415 static void web_debug(const char *str, void *data)
417 connman_info("%s: %s\n", (const char *) data, str);
420 static void wispr_portal_error(struct connman_wispr_portal_context *wp_context)
422 DBG("Failed to proceed wispr/portal web request");
424 wp_context->wispr_result = CONNMAN_WISPR_RESULT_FAILED;
426 #if defined TIZEN_EXT
427 connman_service_set_internet_connection(wp_context->service, false);
431 static void portal_manage_status(GWebResult *result,
432 struct connman_wispr_portal_context *wp_context)
434 struct connman_service *service = wp_context->service;
435 enum connman_ipconfig_type type = wp_context->type;
436 const char *str = NULL;
440 /* We currently don't do anything with this info */
441 if (g_web_result_get_header(result, "X-ConnMan-Client-IP",
443 connman_info("Client-IP: %s", str);
445 if (g_web_result_get_header(result, "X-ConnMan-Client-Country",
447 connman_info("Client-Country: %s", str);
449 if (g_web_result_get_header(result, "X-ConnMan-Client-Region",
451 connman_info("Client-Region: %s", str);
453 if (g_web_result_get_header(result, "X-ConnMan-Client-Timezone",
455 connman_info("Client-Timezone: %s", str);
457 free_connman_wispr_portal_context(wp_context);
459 __connman_service_ipconfig_indicate_state(service,
460 CONNMAN_SERVICE_STATE_ONLINE, type);
463 static bool wispr_route_request(const char *address, int ai_family,
464 int if_index, gpointer user_data)
467 struct connman_wispr_portal_context *wp_context = user_data;
469 struct wispr_route *route;
471 gateway = __connman_ipconfig_get_gateway_from_index(if_index,
474 DBG("address %s if %d gw %s", address, if_index, gateway);
479 route = g_try_new0(struct wispr_route, 1);
481 DBG("could not create struct");
485 switch (wp_context->type) {
486 case CONNMAN_IPCONFIG_TYPE_IPV4:
487 result = connman_inet_add_host_route(if_index, address,
490 case CONNMAN_IPCONFIG_TYPE_IPV6:
491 result = connman_inet_add_ipv6_host_route(if_index, address,
494 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
495 case CONNMAN_IPCONFIG_TYPE_ALL:
504 route->address = g_strdup(address);
505 route->if_index = if_index;
506 wp_context->route_list = g_slist_prepend(wp_context->route_list, route);
511 static void wispr_portal_request_portal(
512 struct connman_wispr_portal_context *wp_context)
516 wp_context->request_id = g_web_request_get(wp_context->web,
517 wp_context->status_url,
518 wispr_portal_web_result,
522 if (wp_context->request_id == 0)
523 wispr_portal_error(wp_context);
526 static bool wispr_input(const guint8 **data, gsize *length,
529 struct connman_wispr_portal_context *wp_context = user_data;
535 buf = g_string_sized_new(100);
537 g_string_append(buf, "button=Login&UserName=");
538 g_string_append_uri_escaped(buf, wp_context->wispr_username,
540 g_string_append(buf, "&Password=");
541 g_string_append_uri_escaped(buf, wp_context->wispr_password,
543 g_string_append(buf, "&FNAME=0&OriginatingServer=");
544 g_string_append_uri_escaped(buf, wp_context->status_url, NULL, FALSE);
548 g_free(wp_context->wispr_formdata);
549 wp_context->wispr_formdata = g_string_free(buf, FALSE);
551 *data = (guint8 *) wp_context->wispr_formdata;
557 static void wispr_portal_browser_reply_cb(struct connman_service *service,
558 bool authentication_done,
559 const char *error, void *user_data)
561 struct connman_wispr_portal_context *wp_context = user_data;
562 struct connman_wispr_portal *wispr_portal;
567 if (!service || !wp_context)
571 * No way to cancel this if wp_context has been freed, so we lookup
572 * from the service and check that this is still the right context.
574 index = __connman_service_get_index(service);
578 wispr_portal = g_hash_table_lookup(wispr_portal_list,
579 GINT_TO_POINTER(index));
583 if (wp_context != wispr_portal->ipv4_context &&
584 wp_context != wispr_portal->ipv6_context)
587 if (!authentication_done) {
588 wispr_portal_error(wp_context);
589 free_wispr_routes(wp_context);
593 /* Restarting the test */
594 __connman_service_wispr_start(service, wp_context->type);
597 static void wispr_portal_request_wispr_login(struct connman_service *service,
599 const char *ssid, int ssid_len,
600 const char *username, const char *password,
601 bool wps, const char *wpspin,
602 const char *error, void *user_data)
604 struct connman_wispr_portal_context *wp_context = user_data;
610 "net.connman.Agent.Error.LaunchBrowser") == 0) {
611 if (__connman_agent_request_browser(service,
612 wispr_portal_browser_reply_cb,
613 wp_context->redirect_url,
614 wp_context) == -EINPROGRESS)
618 free_connman_wispr_portal_context(wp_context);
622 g_free(wp_context->wispr_username);
623 wp_context->wispr_username = g_strdup(username);
625 g_free(wp_context->wispr_password);
626 wp_context->wispr_password = g_strdup(password);
628 wp_context->request_id = g_web_request_post(wp_context->web,
629 wp_context->wispr_msg.login_url,
630 "application/x-www-form-urlencoded",
631 wispr_input, wispr_portal_web_result,
634 connman_wispr_message_init(&wp_context->wispr_msg);
637 static bool wispr_manage_message(GWebResult *result,
638 struct connman_wispr_portal_context *wp_context)
640 DBG("Message type: %s (%d)",
641 message_type_to_string(wp_context->wispr_msg.message_type),
642 wp_context->wispr_msg.message_type);
643 DBG("Response code: %s (%d)",
644 response_code_to_string(wp_context->wispr_msg.response_code),
645 wp_context->wispr_msg.response_code);
647 if (wp_context->wispr_msg.access_procedure)
648 DBG("Access procedure: %s",
649 wp_context->wispr_msg.access_procedure);
650 if (wp_context->wispr_msg.access_location)
651 DBG("Access location: %s",
652 wp_context->wispr_msg.access_location);
653 if (wp_context->wispr_msg.location_name)
654 DBG("Location name: %s",
655 wp_context->wispr_msg.location_name);
656 if (wp_context->wispr_msg.login_url)
657 DBG("Login URL: %s", wp_context->wispr_msg.login_url);
658 if (wp_context->wispr_msg.abort_login_url)
659 DBG("Abort login URL: %s",
660 wp_context->wispr_msg.abort_login_url);
661 if (wp_context->wispr_msg.logoff_url)
662 DBG("Logoff URL: %s", wp_context->wispr_msg.logoff_url);
664 switch (wp_context->wispr_msg.message_type) {
666 DBG("Login required");
668 wp_context->wispr_result = CONNMAN_WISPR_RESULT_LOGIN;
670 if (__connman_agent_request_login_input(wp_context->service,
671 wispr_portal_request_wispr_login,
672 wp_context) != -EINPROGRESS)
673 wispr_portal_error(wp_context);
678 case 120: /* Falling down */
680 if (wp_context->wispr_msg.response_code == 50) {
681 wp_context->wispr_result = CONNMAN_WISPR_RESULT_ONLINE;
683 g_free(wp_context->wispr_username);
684 wp_context->wispr_username = NULL;
686 g_free(wp_context->wispr_password);
687 wp_context->wispr_password = NULL;
689 g_free(wp_context->wispr_formdata);
690 wp_context->wispr_formdata = NULL;
692 wispr_portal_request_portal(wp_context);
696 wispr_portal_error(wp_context);
706 static bool wispr_portal_web_result(GWebResult *result, gpointer user_data)
708 struct connman_wispr_portal_context *wp_context = user_data;
709 const char *redirect = NULL;
710 const guint8 *chunk = NULL;
711 const char *str = NULL;
714 #if defined TIZEN_MAINTAIN_ONLINE
715 static int retried = 0;
720 if (wp_context->wispr_result != CONNMAN_WISPR_RESULT_ONLINE) {
721 g_web_result_get_chunk(result, &chunk, &length);
724 g_web_parser_feed_data(wp_context->wispr_parser,
729 g_web_parser_end_data(wp_context->wispr_parser);
731 if (wp_context->wispr_msg.message_type >= 0) {
732 if (wispr_manage_message(result, wp_context))
737 status = g_web_result_get_status(result);
739 DBG("status: %03u", status);
743 __connman_agent_request_browser(wp_context->service,
744 wispr_portal_browser_reply_cb,
745 wp_context->status_url, wp_context);
748 #if defined TIZEN_MAINTAIN_ONLINE
751 if (wp_context->wispr_msg.message_type >= 0)
754 if (g_web_result_get_header(result, "X-ConnMan-Status",
756 portal_manage_status(result, wp_context);
759 __connman_agent_request_browser(wp_context->service,
760 wispr_portal_browser_reply_cb,
761 wp_context->redirect_url, wp_context);
765 if (!g_web_supports_tls() ||
766 !g_web_result_get_header(result, "Location",
769 __connman_agent_request_browser(wp_context->service,
770 wispr_portal_browser_reply_cb,
771 wp_context->status_url, wp_context);
775 DBG("Redirect URL: %s", redirect);
777 wp_context->redirect_url = g_strdup(redirect);
779 wp_context->request_id = g_web_request_get(wp_context->web,
780 redirect, wispr_portal_web_result,
781 wispr_route_request, wp_context);
786 if (__connman_service_online_check_failed(wp_context->service,
787 wp_context->type) == 0) {
788 #if defined TIZEN_MAINTAIN_ONLINE
789 if (wp_context->type == CONNMAN_IPCONFIG_TYPE_IPV4) {
791 connman_agent_report_error(wp_context->service,
792 __connman_service_get_path(wp_context->service),
793 "internet-unreachable",
801 wispr_portal_error(wp_context);
802 free_connman_wispr_portal_context(wp_context);
808 __connman_agent_request_browser(wp_context->service,
809 wispr_portal_browser_reply_cb,
810 wp_context->status_url, wp_context);
816 free_wispr_routes(wp_context);
817 wp_context->request_id = 0;
819 wp_context->wispr_msg.message_type = -1;
823 static void proxy_callback(const char *proxy, void *user_data)
825 struct connman_wispr_portal_context *wp_context = user_data;
827 DBG("proxy %s", proxy);
832 wp_context->token = 0;
834 if (proxy && g_strcmp0(proxy, "DIRECT") != 0) {
835 if (g_str_has_prefix(proxy, "PROXY")) {
837 for (; *proxy == ' ' && *proxy != '\0'; proxy++);
839 g_web_set_proxy(wp_context->web, proxy);
842 g_web_set_accept(wp_context->web, NULL);
843 g_web_set_user_agent(wp_context->web, "ConnMan/%s wispr", VERSION);
844 g_web_set_close_connection(wp_context->web, TRUE);
846 connman_wispr_message_init(&wp_context->wispr_msg);
848 wp_context->wispr_parser = g_web_parser_new(
849 "<WISPAccessGatewayParam",
850 "WISPAccessGatewayParam>",
851 xml_wispr_parser_callback, wp_context);
853 wispr_portal_request_portal(wp_context);
856 static gboolean no_proxy_callback(gpointer user_data)
858 struct connman_wispr_portal_context *wp_context = user_data;
860 wp_context->timeout = 0;
862 proxy_callback("DIRECT", wp_context);
867 static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context)
869 enum connman_service_proxy_method proxy_method;
870 enum connman_service_type service_type;
871 char *interface = NULL;
872 char **nameservers = NULL;
877 DBG("wispr/portal context %p service %p", wp_context,
878 wp_context->service);
880 service_type = connman_service_get_type(wp_context->service);
882 switch (service_type) {
883 case CONNMAN_SERVICE_TYPE_ETHERNET:
884 case CONNMAN_SERVICE_TYPE_WIFI:
885 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
886 case CONNMAN_SERVICE_TYPE_CELLULAR:
887 case CONNMAN_SERVICE_TYPE_GADGET:
889 case CONNMAN_SERVICE_TYPE_UNKNOWN:
890 case CONNMAN_SERVICE_TYPE_SYSTEM:
891 case CONNMAN_SERVICE_TYPE_GPS:
892 case CONNMAN_SERVICE_TYPE_VPN:
893 case CONNMAN_SERVICE_TYPE_P2P:
894 #if defined TIZEN_EXT_WIFI_MESH
895 case CONNMAN_SERVICE_TYPE_MESH:
900 interface = connman_service_get_interface(wp_context->service);
904 DBG("interface %s", interface);
906 if_index = connman_inet_ifindex(interface);
908 DBG("Could not get ifindex");
913 nameservers = connman_service_get_nameservers(wp_context->service);
915 DBG("Could not get nameservers");
920 wp_context->web = g_web_new(if_index);
921 if (!wp_context->web) {
922 DBG("Could not set up GWeb");
927 #if !defined TIZEN_EXT
928 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]; 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) {
953 free_connman_wispr_portal_context(wp_context);
955 } else if (wp_context->timeout == 0) {
956 wp_context->timeout = g_idle_add(no_proxy_callback, wp_context);
960 g_strfreev(nameservers);
966 int __connman_wispr_start(struct connman_service *service,
967 enum connman_ipconfig_type type)
969 struct connman_wispr_portal_context *wp_context = NULL;
970 struct connman_wispr_portal *wispr_portal = NULL;
973 DBG("service %p", service);
975 #if defined TIZEN_EXT
976 if (connman_service_get_type(service) == CONNMAN_SERVICE_TYPE_CELLULAR)
980 if (!wispr_portal_list)
983 index = __connman_service_get_index(service);
987 wispr_portal = g_hash_table_lookup(wispr_portal_list,
988 GINT_TO_POINTER(index));
990 wispr_portal = g_try_new0(struct connman_wispr_portal, 1);
994 g_hash_table_replace(wispr_portal_list,
995 GINT_TO_POINTER(index), wispr_portal);
998 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
999 wp_context = wispr_portal->ipv4_context;
1000 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
1001 wp_context = wispr_portal->ipv6_context;
1005 /* If there is already an existing context, we wipe it */
1007 free_connman_wispr_portal_context(wp_context);
1009 wp_context = create_wispr_portal_context();
1013 wp_context->service = service;
1014 wp_context->type = type;
1015 wp_context->wispr_portal = wispr_portal;
1017 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
1018 wispr_portal->ipv4_context = wp_context;
1020 wispr_portal->ipv6_context = wp_context;
1022 return wispr_portal_detect(wp_context);
1025 void __connman_wispr_stop(struct connman_service *service)
1029 DBG("service %p", service);
1031 if (!wispr_portal_list)
1034 index = __connman_service_get_index(service);
1038 g_hash_table_remove(wispr_portal_list, GINT_TO_POINTER(index));
1041 int __connman_wispr_init(void)
1045 wispr_portal_list = g_hash_table_new_full(g_direct_hash,
1046 g_direct_equal, NULL,
1047 free_connman_wispr_portal);
1052 void __connman_wispr_cleanup(void)
1056 g_hash_table_destroy(wispr_portal_list);
1057 wispr_portal_list = NULL;