5 * Copyright (C) 2007-2010 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
30 struct connman_wispr_portal_context {
31 struct connman_service *service;
32 enum connman_ipconfig_type type;
35 struct connman_wispr_portal {
36 struct connman_wispr_portal_context *ipv4_context;
37 struct connman_wispr_portal_context *ipv6_context;
40 static GHashTable *wispr_portal_list = NULL;
42 static void free_connman_wispr_portal_context(struct connman_wispr_portal_context *wp_context)
46 if (wp_context == NULL)
52 static void free_connman_wispr_portal(gpointer data)
54 struct connman_wispr_portal *wispr_portal = data;
58 if (wispr_portal == NULL)
61 free_connman_wispr_portal_context(wispr_portal->ipv4_context);
62 free_connman_wispr_portal_context(wispr_portal->ipv6_context);
67 int __connman_wispr_start(struct connman_service *service,
68 enum connman_ipconfig_type type)
70 struct connman_wispr_portal_context *wp_context = NULL;
71 struct connman_wispr_portal *wispr_portal = NULL;
74 DBG("service %p", service);
76 if (wispr_portal_list == NULL)
79 index = __connman_service_get_index(service);
83 wispr_portal = g_hash_table_lookup(wispr_portal_list,
84 GINT_TO_POINTER(index));
85 if (wispr_portal == NULL) {
86 wispr_portal = g_try_new0(struct connman_wispr_portal, 1);
87 if (wispr_portal == NULL)
90 g_hash_table_replace(wispr_portal_list,
91 GINT_TO_POINTER(index), wispr_portal);
94 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
95 wp_context = wispr_portal->ipv4_context;
96 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
97 wp_context = wispr_portal->ipv6_context;
101 if (wp_context == NULL) {
102 wp_context = g_try_new0(struct connman_wispr_portal_context, 1);
103 if (wp_context == NULL)
106 wp_context->service = service;
107 wp_context->type = type;
109 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
110 wispr_portal->ipv4_context = wp_context;
112 wispr_portal->ipv6_context = wp_context;
118 void __connman_wispr_stop(struct connman_service *service)
122 DBG("service %p", service);
124 if (wispr_portal_list == NULL)
127 index = __connman_service_get_index(service);
131 g_hash_table_remove(wispr_portal_list, GINT_TO_POINTER(index));
134 int __connman_wispr_init(void)
138 wispr_portal_list = g_hash_table_new_full(g_direct_hash,
139 g_direct_equal, NULL,
140 free_connman_wispr_portal);
145 void __connman_wispr_cleanup(void)
149 g_hash_table_destroy(wispr_portal_list);
150 wispr_portal_list = NULL;