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);
575 wispr_portal_context_ref(wp_context);
578 static gboolean wispr_input(const guint8 **data, gsize *length,
581 struct connman_wispr_portal_context *wp_context = user_data;
587 buf = g_string_sized_new(100);
589 g_string_append(buf, "button=Login&UserName=");
590 g_string_append_uri_escaped(buf, wp_context->wispr_username,
592 g_string_append(buf, "&Password=");
593 g_string_append_uri_escaped(buf, wp_context->wispr_password,
595 g_string_append(buf, "&FNAME=0&OriginatingServer=");
596 g_string_append_uri_escaped(buf, wp_context->status_url, NULL, FALSE);
600 g_free(wp_context->wispr_formdata);
601 wp_context->wispr_formdata = g_string_free(buf, FALSE);
603 *data = (guint8 *) wp_context->wispr_formdata;
609 static void wispr_portal_browser_reply_cb(struct connman_service *service,
610 connman_bool_t authentication_done,
611 const char *error, void *user_data)
613 struct connman_wispr_portal_context *wp_context = user_data;
617 wp_context = wispr_portal_context_unref(wp_context);
618 if (service == NULL || wp_context == NULL)
621 if (authentication_done == FALSE) {
622 wispr_portal_error(wp_context);
623 free_wispr_routes(wp_context);
627 /* Restarting the test */
628 __connman_wispr_start(service, wp_context->type);
631 static void wispr_portal_request_wispr_login(struct connman_service *service,
632 connman_bool_t success,
633 const char *ssid, int ssid_len,
634 const char *username, const char *password,
635 gboolean wps, const char *wpspin,
636 const char *error, void *user_data)
638 struct connman_wispr_portal_context *wp_context = user_data;
642 wp_context = wispr_portal_context_unref(wp_context);
643 if (wp_context == NULL)
646 if (error != NULL && g_strcmp0(error,
647 "net.connman.Agent.Error.LaunchBrowser") == 0) {
648 wispr_portal_context_ref(wp_context);
650 if (__connman_agent_request_browser(service,
651 wispr_portal_browser_reply_cb,
652 wp_context->redirect_url,
653 wp_context) != -EINPROGRESS)
654 wispr_portal_context_unref(wp_context);
659 g_free(wp_context->wispr_username);
660 wp_context->wispr_username = g_strdup(username);
662 g_free(wp_context->wispr_password);
663 wp_context->wispr_password = g_strdup(password);
665 wispr_portal_context_ref(wp_context);
667 wp_context->request_id = g_web_request_post(wp_context->web,
668 wp_context->wispr_msg.login_url,
669 "application/x-www-form-urlencoded",
670 wispr_input, wispr_portal_web_result,
672 if (wp_context->request_id == 0)
673 wispr_portal_context_unref(wp_context);
675 connman_wispr_message_init(&wp_context->wispr_msg);
678 static gboolean wispr_manage_message(GWebResult *result,
679 struct connman_wispr_portal_context *wp_context)
681 DBG("Message type: %s (%d)",
682 message_type_to_string(wp_context->wispr_msg.message_type),
683 wp_context->wispr_msg.message_type);
684 DBG("Response code: %s (%d)",
685 response_code_to_string(wp_context->wispr_msg.response_code),
686 wp_context->wispr_msg.response_code);
688 if (wp_context->wispr_msg.access_procedure != NULL)
689 DBG("Access procedure: %s",
690 wp_context->wispr_msg.access_procedure);
691 if (wp_context->wispr_msg.access_location != NULL)
692 DBG("Access location: %s",
693 wp_context->wispr_msg.access_location);
694 if (wp_context->wispr_msg.location_name != NULL)
695 DBG("Location name: %s",
696 wp_context->wispr_msg.location_name);
697 if (wp_context->wispr_msg.login_url != NULL)
698 DBG("Login URL: %s", wp_context->wispr_msg.login_url);
699 if (wp_context->wispr_msg.abort_login_url != NULL)
700 DBG("Abort login URL: %s",
701 wp_context->wispr_msg.abort_login_url);
702 if (wp_context->wispr_msg.logoff_url != NULL)
703 DBG("Logoff URL: %s", wp_context->wispr_msg.logoff_url);
705 switch (wp_context->wispr_msg.message_type) {
707 DBG("Login required");
709 wp_context->wispr_result = CONNMAN_WISPR_RESULT_LOGIN;
711 wispr_portal_context_ref(wp_context);
713 if (__connman_agent_request_login_input(wp_context->service,
714 wispr_portal_request_wispr_login,
715 wp_context) != -EINPROGRESS) {
716 wispr_portal_context_unref(wp_context);
717 wispr_portal_error(wp_context);
721 case 120: /* Falling down */
723 if (wp_context->wispr_msg.response_code == 50) {
724 wp_context->wispr_result = CONNMAN_WISPR_RESULT_ONLINE;
726 g_free(wp_context->wispr_username);
727 wp_context->wispr_username = NULL;
729 g_free(wp_context->wispr_password);
730 wp_context->wispr_password = NULL;
732 g_free(wp_context->wispr_formdata);
733 wp_context->wispr_formdata = NULL;
735 wispr_portal_request_portal(wp_context);
739 wispr_portal_error(wp_context);
749 static gboolean wispr_portal_web_result(GWebResult *result, gpointer user_data)
751 struct connman_wispr_portal_context *wp_context = user_data;
752 const char *redirect = NULL;
753 const guint8 *chunk = NULL;
754 const char *str = NULL;
760 wp_context = wispr_portal_context_unref(wp_context);
761 if (wp_context == NULL)
764 if (wp_context->request_id == 0)
767 if (wp_context->wispr_result != CONNMAN_WISPR_RESULT_ONLINE) {
768 g_web_result_get_chunk(result, &chunk, &length);
771 wispr_portal_context_ref(wp_context);
773 g_web_parser_feed_data(wp_context->wispr_parser,
778 g_web_parser_end_data(wp_context->wispr_parser);
780 if (wp_context->wispr_msg.message_type >= 0) {
781 if (wispr_manage_message(result, wp_context) == TRUE)
786 status = g_web_result_get_status(result);
788 DBG("status: %03u", status);
792 if (wp_context->wispr_msg.message_type >= 0)
795 if (g_web_result_get_header(result, "X-ConnMan-Status",
797 portal_manage_status(result, wp_context);
799 wispr_portal_context_ref(wp_context);
801 __connman_agent_request_browser(wp_context->service,
802 wispr_portal_browser_reply_cb,
803 wp_context->redirect_url, wp_context);
808 if (g_web_supports_tls() == FALSE ||
809 g_web_result_get_header(result, "Location",
810 &redirect) == FALSE) {
811 wispr_portal_context_ref(wp_context);
813 __connman_agent_request_browser(wp_context->service,
814 wispr_portal_browser_reply_cb,
815 wp_context->status_url, wp_context);
819 DBG("Redirect URL: %s", redirect);
821 wp_context->redirect_url = g_strdup(redirect);
823 wp_context->request_id = g_web_request_get(wp_context->web,
824 redirect, wispr_portal_web_result,
825 wispr_route_request, wp_context);
826 if (wp_context->request_id != 0)
827 wispr_portal_context_ref(wp_context);
832 if (__connman_service_online_check_failed(wp_context->service,
833 wp_context->type) == 0)
834 wispr_portal_error(wp_context);
841 free_wispr_routes(wp_context);
842 wp_context->request_id = 0;
844 wp_context->wispr_msg.message_type = -1;
848 static void proxy_callback(const char *proxy, void *user_data)
850 struct connman_wispr_portal_context *wp_context = user_data;
852 DBG("proxy %s", proxy);
854 wp_context = wispr_portal_context_unref(wp_context);
855 if (wp_context == NULL)
858 wp_context->token = 0;
860 if (proxy != NULL && g_strcmp0(proxy, "DIRECT") != 0)
861 g_web_set_proxy(wp_context->web, proxy);
863 g_web_set_accept(wp_context->web, NULL);
864 g_web_set_user_agent(wp_context->web, "ConnMan/%s wispr", VERSION);
865 g_web_set_close_connection(wp_context->web, TRUE);
867 connman_wispr_message_init(&wp_context->wispr_msg);
869 wp_context->wispr_parser = g_web_parser_new(
870 "<WISPAccessGatewayParam",
871 "WISPAccessGatewayParam>",
872 xml_wispr_parser_callback, wp_context);
874 wispr_portal_request_portal(wp_context);
877 static gboolean no_proxy_callback(gpointer user_data)
879 struct connman_wispr_portal_context *wp_context = user_data;
881 proxy_callback("DIRECT", wp_context);
886 static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context)
888 enum connman_service_proxy_method proxy_method;
889 enum connman_service_type service_type;
890 char *interface = NULL;
891 char **nameservers = NULL;
896 DBG("wispr/portal context %p", wp_context);
897 DBG("service %p", wp_context->service);
899 service_type = connman_service_get_type(wp_context->service);
901 switch (service_type) {
902 case CONNMAN_SERVICE_TYPE_ETHERNET:
903 case CONNMAN_SERVICE_TYPE_WIFI:
904 case CONNMAN_SERVICE_TYPE_WIMAX:
905 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
906 case CONNMAN_SERVICE_TYPE_CELLULAR:
908 case CONNMAN_SERVICE_TYPE_UNKNOWN:
909 case CONNMAN_SERVICE_TYPE_SYSTEM:
910 case CONNMAN_SERVICE_TYPE_GPS:
911 case CONNMAN_SERVICE_TYPE_VPN:
912 case CONNMAN_SERVICE_TYPE_GADGET:
916 interface = connman_service_get_interface(wp_context->service);
917 if (interface == NULL)
920 DBG("interface %s", interface);
922 if_index = connman_inet_ifindex(interface);
924 DBG("Could not get ifindex");
929 nameservers = connman_service_get_nameservers(wp_context->service);
930 if (nameservers == NULL) {
931 DBG("Could not get nameservers");
936 wp_context->web = g_web_new(if_index);
937 if (wp_context->web == NULL) {
938 DBG("Could not set up GWeb");
943 if (getenv("CONNMAN_WEB_DEBUG"))
944 g_web_set_debug(wp_context->web, web_debug, "WEB");
946 if (wp_context->type == CONNMAN_IPCONFIG_TYPE_IPV4) {
947 g_web_set_address_family(wp_context->web, AF_INET);
948 wp_context->status_url = STATUS_URL_IPV4;
950 g_web_set_address_family(wp_context->web, AF_INET6);
951 wp_context->status_url = STATUS_URL_IPV6;
954 for (i = 0; nameservers[i] != NULL; i++)
955 g_web_add_nameserver(wp_context->web, nameservers[i]);
957 proxy_method = connman_service_get_proxy_method(wp_context->service);
959 if (proxy_method != CONNMAN_SERVICE_PROXY_METHOD_DIRECT) {
960 wp_context->token = connman_proxy_lookup(interface,
961 wp_context->status_url,
963 proxy_callback, wp_context);
965 if (wp_context->token == 0) {
970 g_timeout_add_seconds(0, no_proxy_callback, wp_context);
973 wispr_portal_context_ref(wp_context);
975 g_strfreev(nameservers);
981 int __connman_wispr_start(struct connman_service *service,
982 enum connman_ipconfig_type type)
984 struct connman_wispr_portal_context *wp_context = NULL;
985 struct connman_wispr_portal *wispr_portal = NULL;
988 DBG("service %p", service);
990 if (wispr_portal_list == NULL)
993 index = __connman_service_get_index(service);
997 wispr_portal = g_hash_table_lookup(wispr_portal_list,
998 GINT_TO_POINTER(index));
999 if (wispr_portal == NULL) {
1000 wispr_portal = g_try_new0(struct connman_wispr_portal, 1);
1001 if (wispr_portal == NULL)
1004 g_hash_table_replace(wispr_portal_list,
1005 GINT_TO_POINTER(index), wispr_portal);
1008 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
1009 wp_context = wispr_portal->ipv4_context;
1010 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
1011 wp_context = wispr_portal->ipv6_context;
1015 /* If there is already an existing context, we wipe it */
1016 if (wp_context != NULL)
1017 wispr_portal_context_unref(wp_context);
1019 wp_context = create_wispr_portal_context();
1020 if (wp_context == NULL)
1023 connman_service_ref(service);
1025 wp_context->service = service;
1026 wp_context->type = type;
1027 wp_context->wispr_portal = wispr_portal;
1029 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
1030 wispr_portal->ipv4_context = wp_context;
1032 wispr_portal->ipv6_context = wp_context;
1034 return wispr_portal_detect(wp_context);
1037 void __connman_wispr_stop(struct connman_service *service)
1041 DBG("service %p", service);
1043 if (wispr_portal_list == NULL)
1046 index = __connman_service_get_index(service);
1050 g_hash_table_remove(wispr_portal_list, GINT_TO_POINTER(index));
1053 int __connman_wispr_init(void)
1057 wispr_portal_list = g_hash_table_new_full(g_direct_hash,
1058 g_direct_equal, NULL,
1059 free_connman_wispr_portal);
1064 void __connman_wispr_cleanup(void)
1068 g_hash_table_destroy(wispr_portal_list);
1069 wispr_portal_list = NULL;