wispr: Requesting login input through the agent
[platform/upstream/connman.git] / src / wispr.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2010  Intel Corporation. All rights reserved.
6  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <errno.h>
27 #include <stdlib.h>
28
29 #include <gweb/gweb.h>
30
31 #include "connman.h"
32
33 #define STATUS_URL  "http://www.connman.net/online/status.html"
34
35 struct connman_wispr_message {
36         gboolean has_error;
37         const char *current_element;
38         int message_type;
39         int response_code;
40         char *login_url;
41         char *abort_login_url;
42         char *logoff_url;
43         char *access_procedure;
44         char *access_location;
45         char *location_name;
46 };
47
48 enum connman_wispr_result {
49         CONNMAN_WISPR_RESULT_UNKNOWN = 0,
50         CONNMAN_WISPR_RESULT_LOGIN   = 1,
51         CONNMAN_WISPR_RESULT_ONLINE  = 2,
52         CONNMAN_WISPR_RESULT_FAILED  = 3,
53 };
54
55 struct connman_wispr_portal_context {
56         struct connman_service *service;
57         enum connman_ipconfig_type type;
58
59         /* Portal/WISPr common */
60         GWeb *web;
61         unsigned int token;
62         guint request_id;
63
64         /* WISPr specific */
65         GWebParser *wispr_parser;
66         struct connman_wispr_message wispr_msg;
67
68         char *wispr_username;
69         char *wispr_password;
70         char *wispr_formdata;
71
72         enum connman_wispr_result wispr_result;
73 };
74
75 struct connman_wispr_portal {
76         struct connman_wispr_portal_context *ipv4_context;
77         struct connman_wispr_portal_context *ipv6_context;
78 };
79
80 static gboolean wispr_portal_web_result(GWebResult *result, gpointer user_data);
81
82 static GHashTable *wispr_portal_list = NULL;
83
84 static void connman_wispr_message_init(struct connman_wispr_message *msg)
85 {
86         DBG("");
87
88         msg->has_error = FALSE;
89         msg->current_element = NULL;
90
91         msg->message_type = -1;
92         msg->response_code = -1;
93
94         g_free(msg->login_url);
95         msg->login_url = NULL;
96
97         g_free(msg->abort_login_url);
98         msg->abort_login_url = NULL;
99
100         g_free(msg->logoff_url);
101         msg->logoff_url = NULL;
102
103         g_free(msg->access_procedure);
104         msg->access_procedure = NULL;
105
106         g_free(msg->access_location);
107         msg->access_location = NULL;
108
109         g_free(msg->location_name);
110         msg->location_name = NULL;
111 }
112
113 static void free_connman_wispr_portal_context(struct connman_wispr_portal_context *wp_context)
114 {
115         DBG("");
116
117         if (wp_context == NULL)
118                 return;
119
120         if (wp_context->token > 0)
121                 connman_proxy_lookup_cancel(wp_context->token);
122
123         if (wp_context->request_id > 0)
124                 g_web_cancel_request(wp_context->web, wp_context->request_id);
125
126         g_web_unref(wp_context->web);
127
128         g_web_parser_unref(wp_context->wispr_parser);
129         connman_wispr_message_init(&wp_context->wispr_msg);
130
131         g_free(wp_context->wispr_username);
132         g_free(wp_context->wispr_password);
133         g_free(wp_context->wispr_formdata);
134
135         g_free(wp_context);
136 }
137
138 static void free_connman_wispr_portal(gpointer data)
139 {
140         struct connman_wispr_portal *wispr_portal = data;
141
142         DBG("");
143
144         if (wispr_portal == NULL)
145                 return;
146
147         free_connman_wispr_portal_context(wispr_portal->ipv4_context);
148         free_connman_wispr_portal_context(wispr_portal->ipv6_context);
149
150         g_free(wispr_portal);
151 }
152
153 static const char *message_type_to_string(int message_type)
154 {
155         switch (message_type) {
156         case 100:
157                 return "Initial redirect message";
158         case 110:
159                 return "Proxy notification";
160         case 120:
161                 return "Authentication notification";
162         case 130:
163                 return "Logoff notification";
164         case 140:
165                 return "Response to Authentication Poll";
166         case 150:
167                 return "Response to Abort Login";
168         }
169
170         return NULL;
171 }
172
173 static const char *response_code_to_string(int response_code)
174 {
175         switch (response_code) {
176         case 0:
177                 return "No error";
178         case 50:
179                 return "Login succeeded";
180         case 100:
181                 return "Login failed";
182         case 102:
183                 return "RADIUS server error/timeout";
184         case 105:
185                 return "RADIUS server not enabled";
186         case 150:
187                 return "Logoff succeeded";
188         case 151:
189                 return "Login aborted";
190         case 200:
191                 return "Proxy detection/repeat operation";
192         case 201:
193                 return "Authentication pending";
194         case 255:
195                 return "Access gateway internal error";
196         }
197
198         return NULL;
199 }
200
201 static struct {
202         const char *str;
203         enum {
204                 WISPR_ELEMENT_NONE              = 0,
205                 WISPR_ELEMENT_ACCESS_PROCEDURE  = 1,
206                 WISPR_ELEMENT_ACCESS_LOCATION   = 2,
207                 WISPR_ELEMENT_LOCATION_NAME     = 3,
208                 WISPR_ELEMENT_LOGIN_URL         = 4,
209                 WISPR_ELEMENT_ABORT_LOGIN_URL   = 5,
210                 WISPR_ELEMENT_MESSAGE_TYPE      = 6,
211                 WISPR_ELEMENT_RESPONSE_CODE     = 7,
212                 WISPR_ELEMENT_NEXT_URL          = 8,
213                 WISPR_ELEMENT_DELAY             = 9,
214                 WISPR_ELEMENT_REPLY_MESSAGE     = 10,
215                 WISPR_ELEMENT_LOGIN_RESULTS_URL = 11,
216                 WISPR_ELEMENT_LOGOFF_URL        = 12,
217         } element;
218 } wispr_element_map[] = {
219         { "AccessProcedure",    WISPR_ELEMENT_ACCESS_PROCEDURE  },
220         { "AccessLocation",     WISPR_ELEMENT_ACCESS_LOCATION   },
221         { "LocationName",       WISPR_ELEMENT_LOCATION_NAME     },
222         { "LoginURL",           WISPR_ELEMENT_LOGIN_URL         },
223         { "AbortLoginURL",      WISPR_ELEMENT_ABORT_LOGIN_URL   },
224         { "MessageType",        WISPR_ELEMENT_MESSAGE_TYPE      },
225         { "ResponseCode",       WISPR_ELEMENT_RESPONSE_CODE     },
226         { "NextURL",            WISPR_ELEMENT_NEXT_URL          },
227         { "Delay",              WISPR_ELEMENT_DELAY             },
228         { "ReplyMessage",       WISPR_ELEMENT_REPLY_MESSAGE     },
229         { "LoginResultsURL",    WISPR_ELEMENT_LOGIN_RESULTS_URL },
230         { "LogoffURL",          WISPR_ELEMENT_LOGOFF_URL        },
231         { NULL,                 WISPR_ELEMENT_NONE              },
232 };
233
234 static void xml_wispr_start_element_handler(GMarkupParseContext *context,
235                                         const gchar *element_name,
236                                         const gchar **attribute_names,
237                                         const gchar **attribute_values,
238                                         gpointer user_data, GError **error)
239 {
240         struct connman_wispr_message *msg = user_data;
241
242         msg->current_element = element_name;
243 }
244
245 static void xml_wispr_end_element_handler(GMarkupParseContext *context,
246                                         const gchar *element_name,
247                                         gpointer user_data, GError **error)
248 {
249         struct connman_wispr_message *msg = user_data;
250
251         msg->current_element = NULL;
252 }
253
254 static void xml_wispr_text_handler(GMarkupParseContext *context,
255                                         const gchar *text, gsize text_len,
256                                         gpointer user_data, GError **error)
257 {
258         struct connman_wispr_message *msg = user_data;
259         int i;
260
261         if (msg->current_element == NULL)
262                 return;
263
264         for (i = 0; wispr_element_map[i].str; i++) {
265                 if (g_str_equal(wispr_element_map[i].str,
266                                         msg->current_element) == FALSE)
267                         continue;
268
269                 switch (wispr_element_map[i].element) {
270                 case WISPR_ELEMENT_NONE:
271                 case WISPR_ELEMENT_ACCESS_PROCEDURE:
272                         g_free(msg->access_procedure);
273                         msg->access_procedure = g_strdup(text);
274                         break;
275                 case WISPR_ELEMENT_ACCESS_LOCATION:
276                         g_free(msg->access_location);
277                         msg->access_location = g_strdup(text);
278                         break;
279                 case WISPR_ELEMENT_LOCATION_NAME:
280                         g_free(msg->location_name);
281                         msg->location_name = g_strdup(text);
282                         break;
283                 case WISPR_ELEMENT_LOGIN_URL:
284                         g_free(msg->login_url);
285                         msg->login_url = g_strdup(text);
286                         break;
287                 case WISPR_ELEMENT_ABORT_LOGIN_URL:
288                         g_free(msg->abort_login_url);
289                         msg->abort_login_url = g_strdup(text);
290                         break;
291                 case WISPR_ELEMENT_MESSAGE_TYPE:
292                         msg->message_type = atoi(text);
293                         break;
294                 case WISPR_ELEMENT_RESPONSE_CODE:
295                         msg->response_code = atoi(text);
296                         break;
297                 case WISPR_ELEMENT_NEXT_URL:
298                 case WISPR_ELEMENT_DELAY:
299                 case WISPR_ELEMENT_REPLY_MESSAGE:
300                 case WISPR_ELEMENT_LOGIN_RESULTS_URL:
301                         break;
302                 case WISPR_ELEMENT_LOGOFF_URL:
303                         g_free(msg->logoff_url);
304                         msg->logoff_url = g_strdup(text);
305                         break;
306                 }
307         }
308 }
309
310 static void xml_wispr_error_handler(GMarkupParseContext *context,
311                                         GError *error, gpointer user_data)
312 {
313         struct connman_wispr_message *msg = user_data;
314
315         msg->has_error = TRUE;
316 }
317
318 static const GMarkupParser xml_wispr_parser_handlers = {
319         xml_wispr_start_element_handler,
320         xml_wispr_end_element_handler,
321         xml_wispr_text_handler,
322         NULL,
323         xml_wispr_error_handler,
324 };
325
326 static void xml_wispr_parser_callback(const char *str, gpointer user_data)
327 {
328         struct connman_wispr_portal_context *wp_context = user_data;
329         GMarkupParseContext *parser_context = NULL;
330         gboolean result;
331
332         DBG("");
333
334         parser_context = g_markup_parse_context_new(&xml_wispr_parser_handlers,
335                                         G_MARKUP_TREAT_CDATA_AS_TEXT,
336                                         &(wp_context->wispr_msg), NULL);
337
338         result = g_markup_parse_context_parse(parser_context,
339                                         str, strlen(str), NULL);
340         if (result == TRUE)
341                 result = g_markup_parse_context_end_parse(parser_context, NULL);
342
343         g_markup_parse_context_free(parser_context);
344 }
345
346 static void web_debug(const char *str, void *data)
347 {
348         connman_info("%s: %s\n", (const char *) data, str);
349 }
350
351 static void wispr_portal_error(struct connman_wispr_portal_context *wp_context)
352 {
353         DBG("Failed to proceed wispr/portal web request");
354
355         wp_context->wispr_result = CONNMAN_WISPR_RESULT_FAILED;
356 }
357
358 static void portal_manage_status(GWebResult *result,
359                         struct connman_wispr_portal_context *wp_context)
360 {
361         const char *str = NULL;
362
363         DBG("");
364
365         /* We currently don't do anything with this info */
366         if (g_web_result_get_header(result, "X-ConnMan-Client-IP",
367                                 &str) == TRUE)
368                 connman_info("Client-IP: %s", str);
369
370         if (g_web_result_get_header(result, "X-ConnMan-Client-Country",
371                                 &str) == TRUE)
372                 connman_info("Client-Country: %s", str);
373
374         if (g_web_result_get_header(result, "X-ConnMan-Client-Region",
375                                 &str) == TRUE)
376                 connman_info("Client-Region: %s", str);
377
378         __connman_service_ipconfig_indicate_state(wp_context->service,
379                                                 CONNMAN_SERVICE_STATE_ONLINE,
380                                                 wp_context->type);
381 }
382
383 static void wispr_portal_request_portal(struct connman_wispr_portal_context *wp_context)
384 {
385         DBG("");
386
387         wp_context->request_id = g_web_request_get(wp_context->web,
388                         STATUS_URL, wispr_portal_web_result, wp_context);
389
390         if (wp_context->request_id == 0)
391                 wispr_portal_error(wp_context);
392 }
393
394 static gboolean wispr_input(const guint8 **data, gsize *length,
395                                                 gpointer user_data)
396 {
397         struct connman_wispr_portal_context *wp_context = user_data;
398         GString *buf;
399         gsize count;
400
401         DBG("");
402
403         buf = g_string_sized_new(100);
404
405         g_string_append(buf, "button=Login&UserName=");
406         g_string_append_uri_escaped(buf, wp_context->wispr_username,
407                                                                 NULL, FALSE);
408         g_string_append(buf, "&Password=");
409         g_string_append_uri_escaped(buf, wp_context->wispr_password,
410                                                                 NULL, FALSE);
411         g_string_append(buf, "&FNAME=0&OriginatingServer=");
412         g_string_append_uri_escaped(buf, STATUS_URL, NULL, FALSE);
413
414         count = buf->len;
415
416         g_free(wp_context->wispr_formdata);
417         wp_context->wispr_formdata = g_string_free(buf, FALSE);
418
419         *data = (guint8 *) wp_context->wispr_formdata;
420         *length = count;
421
422         return FALSE;
423 }
424
425 static void wispr_portal_request_wispr_login(struct connman_service *service,
426                                 const char *username, const char *password,
427                                 void *user_data)
428 {
429         struct connman_wispr_portal_context *wp_context = user_data;
430
431         DBG("");
432
433         g_free(wp_context->wispr_username);
434         wp_context->wispr_username = g_strdup(username);
435
436         g_free(wp_context->wispr_password);
437         wp_context->wispr_password = g_strdup(password);
438
439         wp_context->request_id = g_web_request_post(wp_context->web,
440                                         wp_context->wispr_msg.login_url,
441                                         "application/x-www-form-urlencoded",
442                                         wispr_input, wispr_portal_web_result,
443                                         wp_context);
444
445         connman_wispr_message_init(&wp_context->wispr_msg);
446 }
447
448 static gboolean wispr_manage_message(GWebResult *result,
449                         struct connman_wispr_portal_context *wp_context)
450 {
451         DBG("Message type: %s (%d)",
452                 message_type_to_string(wp_context->wispr_msg.message_type),
453                                         wp_context->wispr_msg.message_type);
454         DBG("Response code: %s (%d)",
455                 response_code_to_string(wp_context->wispr_msg.response_code),
456                                         wp_context->wispr_msg.response_code);
457
458         if (wp_context->wispr_msg.access_procedure != NULL)
459                 DBG("Access procedure: %s",
460                         wp_context->wispr_msg.access_procedure);
461         if (wp_context->wispr_msg.access_location != NULL)
462                 DBG("Access location: %s",
463                         wp_context->wispr_msg.access_location);
464         if (wp_context->wispr_msg.location_name != NULL)
465                 DBG("Location name: %s",
466                         wp_context->wispr_msg.location_name);
467         if (wp_context->wispr_msg.login_url != NULL)
468                 DBG("Login URL: %s", wp_context->wispr_msg.login_url);
469         if (wp_context->wispr_msg.abort_login_url != NULL)
470                 DBG("Abort login URL: %s",
471                         wp_context->wispr_msg.abort_login_url);
472         if (wp_context->wispr_msg.logoff_url != NULL)
473                 DBG("Logoff URL: %s", wp_context->wispr_msg.logoff_url);
474
475         switch (wp_context->wispr_msg.message_type) {
476         case 100:
477                 DBG("Login required");
478
479                 wp_context->wispr_result = CONNMAN_WISPR_RESULT_LOGIN;
480
481                 __connman_agent_request_login_input(wp_context->service,
482                                         wispr_portal_request_wispr_login,
483                                         wp_context);
484                 break;
485         case 120: /* Falling down */
486         case 140:
487                 if (wp_context->wispr_msg.response_code == 50) {
488                         wp_context->wispr_result = CONNMAN_WISPR_RESULT_ONLINE;
489
490                         g_free(wp_context->wispr_username);
491                         wp_context->wispr_username = NULL;
492
493                         g_free(wp_context->wispr_password);
494                         wp_context->wispr_password = NULL;
495
496                         g_free(wp_context->wispr_formdata);
497                         wp_context->wispr_formdata = NULL;
498
499                         wispr_portal_request_portal(wp_context);
500
501                         return TRUE;
502                 } else
503                         wispr_portal_error(wp_context);
504
505                 break;
506         default:
507                 break;
508         }
509
510         return FALSE;
511 }
512
513 static gboolean wispr_portal_web_result(GWebResult *result, gpointer user_data)
514 {
515         struct connman_wispr_portal_context *wp_context = user_data;
516         const char *redirect = NULL;
517         const guint8 *chunk = NULL;
518         const char *str = NULL;
519         guint16 status;
520         gsize length;
521
522         DBG("");
523
524         if (wp_context->request_id == 0)
525                 return FALSE;
526
527         if (wp_context->wispr_result != CONNMAN_WISPR_RESULT_ONLINE) {
528                 g_web_result_get_chunk(result, &chunk, &length);
529
530                 if (length > 0) {
531                         g_web_parser_feed_data(wp_context->wispr_parser,
532                                                                 chunk, length);
533                         return TRUE;
534                 }
535
536                 g_web_parser_end_data(wp_context->wispr_parser);
537
538                 if (wp_context->wispr_msg.message_type >= 0) {
539                         if (wispr_manage_message(result, wp_context) == TRUE)
540                                 goto done;
541                 }
542         }
543
544         status = g_web_result_get_status(result);
545
546         DBG("status: %03u", status);
547
548         switch (status) {
549         case 200:
550                 if (wp_context->wispr_msg.message_type >= 0)
551                         break;
552
553                 if (g_web_result_get_header(result, "X-ConnMan-Status",
554                                                                 &str) == TRUE)
555                         portal_manage_status(result, wp_context);
556                 else
557                         __connman_service_request_login(wp_context->service);
558
559                 break;
560         case 302:
561                 if (g_web_result_get_header(result, "Location",
562                                                 &redirect) == FALSE)
563                         break;
564
565                 DBG("Redirect URL: %s", redirect);
566
567                 wp_context->request_id = g_web_request_get(wp_context->web,
568                                 redirect, wispr_portal_web_result, wp_context);
569
570                 goto done;
571         case 404:
572                 wispr_portal_error(wp_context);
573
574                 break;
575         default:
576                 break;
577         }
578
579         wp_context->request_id = 0;
580 done:
581         wp_context->wispr_msg.message_type = -1;
582         return FALSE;
583 }
584
585 static void proxy_callback(const char *proxy, void *user_data)
586 {
587         struct connman_wispr_portal_context *wp_context = user_data;
588
589         DBG("proxy %s", proxy);
590
591         wp_context->token = 0;
592
593         if (proxy == NULL)
594                 proxy = getenv("http_proxy");
595
596         if (getenv("CONNMAN_WEB_DEBUG"))
597                 g_web_set_debug(wp_context->web, web_debug, "WEB");
598
599         if (proxy != NULL && g_strcmp0(proxy, "DIRECT") != 0)
600                 g_web_set_proxy(wp_context->web, proxy);
601
602         g_web_set_accept(wp_context->web, NULL);
603         g_web_set_user_agent(wp_context->web, "ConnMan/%s", VERSION);
604         g_web_set_close_connection(wp_context->web, TRUE);
605
606         connman_wispr_message_init(&wp_context->wispr_msg);
607
608         wp_context->wispr_parser = g_web_parser_new(
609                                         "<WISPAccessGatewayParam",
610                                         "WISPAccessGatewayParam>",
611                                         xml_wispr_parser_callback, wp_context);
612
613         wispr_portal_request_portal(wp_context);
614 }
615
616 static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context)
617 {
618         enum connman_service_type service_type;
619         char *interface = NULL;
620         int err = 0;
621
622         DBG("wispr/portal context %p", wp_context);
623         DBG("service %p", wp_context->service);
624
625         service_type = connman_service_get_type(wp_context->service);
626
627         switch (service_type) {
628         case CONNMAN_SERVICE_TYPE_ETHERNET:
629         case CONNMAN_SERVICE_TYPE_WIFI:
630         case CONNMAN_SERVICE_TYPE_WIMAX:
631         case CONNMAN_SERVICE_TYPE_BLUETOOTH:
632         case CONNMAN_SERVICE_TYPE_CELLULAR:
633                 break;
634         case CONNMAN_SERVICE_TYPE_UNKNOWN:
635         case CONNMAN_SERVICE_TYPE_SYSTEM:
636         case CONNMAN_SERVICE_TYPE_GPS:
637         case CONNMAN_SERVICE_TYPE_VPN:
638         case CONNMAN_SERVICE_TYPE_GADGET:
639                 return -EOPNOTSUPP;
640         }
641
642         interface = connman_service_get_interface(wp_context->service);
643         if (interface == NULL)
644                 return -EINVAL;
645
646         DBG("interface %s", interface);
647
648         wp_context->web = g_web_new(0);
649         if (wp_context->web == NULL) {
650                 err = -ENOMEM;
651                 goto done;
652         }
653
654         if (wp_context->type == CONNMAN_IPCONFIG_TYPE_IPV4)
655                 g_web_set_address_family(wp_context->web, AF_INET);
656         else
657                 g_web_set_address_family(wp_context->web, AF_INET6);
658
659         wp_context->token = connman_proxy_lookup(interface,
660                                         STATUS_URL, wp_context->service,
661                                         proxy_callback, wp_context);
662         if (wp_context->token == 0)
663                 err = -EINVAL;
664
665 done:
666         g_free(interface);
667         return err;
668 }
669
670 int __connman_wispr_start(struct connman_service *service,
671                                         enum connman_ipconfig_type type)
672 {
673         struct connman_wispr_portal_context *wp_context = NULL;
674         struct connman_wispr_portal *wispr_portal = NULL;
675         int index;
676
677         DBG("service %p", service);
678
679         if (wispr_portal_list == NULL)
680                 return -EINVAL;
681
682         index = __connman_service_get_index(service);
683         if (index < 0)
684                 return -EINVAL;
685
686         wispr_portal = g_hash_table_lookup(wispr_portal_list,
687                                         GINT_TO_POINTER(index));
688         if (wispr_portal == NULL) {
689                 wispr_portal = g_try_new0(struct connman_wispr_portal, 1);
690                 if (wispr_portal == NULL)
691                         return -ENOMEM;
692
693                 g_hash_table_replace(wispr_portal_list,
694                                         GINT_TO_POINTER(index), wispr_portal);
695         }
696
697         if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
698                 wp_context = wispr_portal->ipv4_context;
699         else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
700                 wp_context = wispr_portal->ipv6_context;
701         else
702                 return -EINVAL;
703
704         if (wp_context == NULL) {
705                 wp_context = g_try_new0(struct connman_wispr_portal_context, 1);
706                 if (wp_context == NULL)
707                         return -ENOMEM;
708
709                 wp_context->service = service;
710                 wp_context->type = type;
711
712                 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
713                         wispr_portal->ipv4_context = wp_context;
714                 else
715                         wispr_portal->ipv6_context = wp_context;
716
717                 return wispr_portal_detect(wp_context);
718         }
719
720         return 0;
721 }
722
723 void __connman_wispr_stop(struct connman_service *service)
724 {
725         int index;
726
727         DBG("service %p", service);
728
729         if (wispr_portal_list == NULL)
730                 return;
731
732         index = __connman_service_get_index(service);
733         if (index < 0)
734                 return;
735
736         g_hash_table_remove(wispr_portal_list, GINT_TO_POINTER(index));
737 }
738
739 int __connman_wispr_init(void)
740 {
741         DBG("");
742
743         wispr_portal_list = g_hash_table_new_full(g_direct_hash,
744                                                 g_direct_equal, NULL,
745                                                 free_connman_wispr_portal);
746
747         return 0;
748 }
749
750 void __connman_wispr_cleanup(void)
751 {
752         DBG("");
753
754         g_hash_table_destroy(wispr_portal_list);
755         wispr_portal_list = NULL;
756 }