wispr will be ran on ipv4/ipv6 depending on service configuration.
Due to that it maintains 2 respectives contexts.
---
 src/connman.h |    3 ++
 src/wispr.c   |  113 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 116 insertions(+), 0 deletions(-)

diff --git a/src/connman.h b/src/connman.h
index 7273a95..e49d53c 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -304,6 +304,9 @@ void __connman_wpad_stop(struct connman_service *service);
 
 int __connman_wispr_init(void);
 void __connman_wispr_cleanup(void);
+int __connman_wispr_portal_start(struct connman_service *service,
+                                       enum connman_ipconfig_type type);
+void __connman_wispr_portal_stop(struct connman_service *service);
 
 #include <connman/technology.h>
 
diff --git a/src/wispr.c b/src/wispr.c
index 41f7ca3..9267eb9 100644
--- a/src/wispr.c
+++ b/src/wispr.c
@@ -23,16 +23,129 @@
 #include <config.h>
 #endif
 
+#include <errno.h>
+
 #include "connman.h"
 
+struct connman_wispr_portal_context {
+       struct connman_service *service;
+       enum connman_ipconfig_type type;
+};
+
+struct connman_wispr_portal {
+       struct connman_wispr_portal_context *ipv4_context;
+       struct connman_wispr_portal_context *ipv6_context;
+};
+
+static GHashTable *wispr_portal_list = NULL;
+
+static void free_connman_wispr_portal_context(struct 
connman_wispr_portal_context *wp_context)
+{
+       DBG("");
+
+       if (wp_context == NULL)
+               return;
+
+       g_free(wp_context);
+}
+
+static void free_connman_wispr_portal(gpointer data)
+{
+       struct connman_wispr_portal *wispr_portal = data;
+
+       DBG("");
+
+       if (wispr_portal == NULL)
+               return;
+
+       free_connman_wispr_portal_context(wispr_portal->ipv4_context);
+       free_connman_wispr_portal_context(wispr_portal->ipv6_context);
+
+       g_free(wispr_portal);
+}
+
+int __connman_wispr_portal_start(struct connman_service *service,
+                                       enum connman_ipconfig_type type)
+{
+       struct connman_wispr_portal_context *wp_context = NULL;
+       struct connman_wispr_portal *wispr_portal = NULL;
+       int index;
+
+       DBG("service %p", service);
+
+       if (wispr_portal_list == NULL)
+               return -EINVAL;
+
+       index = __connman_service_get_index(service);
+       if (index < 0)
+               return -EINVAL;
+
+       wispr_portal = g_hash_table_lookup(wispr_portal_list,
+                                       GINT_TO_POINTER(index));
+       if (wispr_portal == NULL) {
+               wispr_portal = g_try_new0(struct connman_wispr_portal, 1);
+               if (wispr_portal == NULL)
+                       return -ENOMEM;
+
+               g_hash_table_replace(wispr_portal_list,
+                                       GINT_TO_POINTER(index), wispr_portal);
+       }
+
+       if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+               wp_context = wispr_portal->ipv4_context;
+       else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
+               wp_context = wispr_portal->ipv6_context;
+       else
+               return -EINVAL;
+
+       if (wp_context == NULL) {
+               wp_context = g_try_new0(struct connman_wispr_portal_context, 1);
+               if (wp_context == NULL)
+                       return -ENOMEM;
+
+               wp_context->service = service;
+               wp_context->type = type;
+
+               if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+                       wispr_portal->ipv4_context = wp_context;
+               else
+                       wispr_portal->ipv6_context = wp_context;
+       }
+
+       return 0;
+}
+
+void __connman_wispr_portal_stop(struct connman_service *service)
+{
+       int index;
+
+       DBG("service %p", service);
+
+       if (wispr_portal_list == NULL)
+               return;
+
+       index = __connman_service_get_index(service);
+       if (index < 0)
+               return;
+
+       g_hash_table_remove(wispr_portal_list, GINT_TO_POINTER(index));
+}
+
 int __connman_wispr_init(void)
 {
        DBG("");
 
+       wispr_portal_list = g_hash_table_new_full(g_direct_hash,
+                                               g_direct_equal, NULL,
+                                               free_connman_wispr_portal);
+
        return 0;
 }
 
 void __connman_wispr_cleanup(void)
 {
        DBG("");
+
+       g_hash_table_destroy(wispr_portal_list);
+       wispr_portal_list = NULL;
 }
-- 
1.7.3.4

_______________________________________________
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman

Reply via email to