Add basic implementation for internal proxy framework
authorMarcel Holtmann <marcel@holtmann.org>
Sat, 6 Nov 2010 21:35:14 +0000 (22:35 +0100)
committerMarcel Holtmann <marcel@holtmann.org>
Sat, 6 Nov 2010 21:35:14 +0000 (22:35 +0100)
Makefile.am
include/proxy.h [new file with mode: 0644]
src/connman.h
src/main.c
src/proxy.c [new file with mode: 0644]

index e07a499..9e5bfeb 100644 (file)
@@ -16,7 +16,7 @@ noinst_HEADERS = include/driver.h include/element.h include/property.h \
                        include/rtnl.h include/wifi.h include/task.h \
                        include/dbus.h include/rfkill.h include/option.h \
                        include/profile.h include/provider.h include/dhcp.h \
-                       include/utsname.h include/timeserver.h \
+                       include/utsname.h include/timeserver.h include/proxy.h \
                        include/location.h include/technology.h
 
 local_headers = $(foreach file,$(include_HEADERS) $(nodist_include_HEADERS) \
@@ -66,8 +66,8 @@ src_connmand_SOURCES = $(gdbus_sources) $(gdhcp_sources) \
                        src/device.c src/network.c src/connection.c \
                        src/manager.c src/profile.c src/service.c \
                        src/agent.c src/notifier.c src/provider.c \
-                       src/resolver.c src/ipconfig.c src/detect.c \
-                       src/ipv4.c src/dhcp.c src/rtnl.c src/inet.c \
+                       src/resolver.c src/ipconfig.c src/detect.c src/inet.c \
+                       src/ipv4.c src/dhcp.c src/rtnl.c src/proxy.c \
                        src/utsname.c src/timeserver.c src/rfkill.c \
                        src/wifi.c src/storage.c src/dbus.c src/config.c \
                        src/technology.c src/counter.c src/location.c \
diff --git a/include/proxy.h b/include/proxy.h
new file mode 100644 (file)
index 0000000..61117a0
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2010  Intel Corporation. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifndef __CONNMAN_PROXY_H
+#define __CONNMAN_PROXY_H
+
+#include <connman/service.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * SECTION:proxy
+ * @title: Proxy premitives
+ * @short_description: Functions for handling proxy configuration
+ */
+
+typedef void (*connman_proxy_lookup_cb) (const char *proxy, void *user_data);
+
+unsigned int connman_proxy_lookup(const char *interface, const char *url,
+                               connman_proxy_lookup_cb cb, void *user_data);
+void connman_proxy_lookup_cancel(unsigned int token);
+
+void connman_proxy_driver_lookup_notify(struct connman_service *service,
+                                       const char *url, const char *result);
+
+struct connman_proxy_driver {
+       const char *name;
+       int priority;
+       int (*request_lookup) (struct connman_service *service,
+                                                       const char *url);
+       void (*cancel_lookup) (struct connman_service *service,
+                                                       const char *url);
+};
+
+int connman_proxy_driver_register(struct connman_proxy_driver *driver);
+void connman_proxy_driver_unregister(struct connman_proxy_driver *driver);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_PROXY_H */
index 69e7de4..27a5b36 100644 (file)
@@ -191,6 +191,11 @@ void __connman_detect_cleanup(void);
 
 void __connman_element_set_driver(struct connman_element *element);
 
+#include <connman/proxy.h>
+
+int __connman_proxy_init(void);
+void __connman_proxy_cleanup(void);
+
 #include <connman/ipconfig.h>
 
 int __connman_ipconfig_init(void);
index c2e6322..56675bd 100644 (file)
@@ -238,6 +238,7 @@ int main(int argc, char *argv[])
        __connman_ipconfig_init();
        __connman_rtnl_init();
        __connman_task_init();
+       __connman_proxy_init();
        __connman_detect_init();
        __connman_session_init();
        __connman_timeserver_init();
@@ -265,6 +266,7 @@ int main(int argc, char *argv[])
        __connman_timeserver_cleanup();
        __connman_session_cleanup();
        __connman_detect_cleanup();
+       __connman_proxy_cleanup();
        __connman_task_cleanup();
        __connman_rtnl_cleanup();
        __connman_ipconfig_cleanup();
diff --git a/src/proxy.c b/src/proxy.c
new file mode 100644 (file)
index 0000000..f31e9f8
--- /dev/null
@@ -0,0 +1,148 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2010  Intel Corporation. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib.h>
+
+#include "connman.h"
+
+static unsigned int next_lookup_token = 1;
+
+static GSList *driver_list = NULL;
+
+struct proxy_lookup {
+       unsigned int token;
+       connman_proxy_lookup_cb cb;
+       void *user_data;
+       guint watch;
+};
+
+static gboolean lookup_callback(gpointer user_data)
+{
+       struct proxy_lookup *lookup = user_data;
+
+       lookup->watch = 0;
+
+       if (lookup->cb)
+               lookup->cb(NULL, lookup->user_data);
+
+       g_free(lookup);
+
+       return FALSE;
+}
+
+unsigned int connman_proxy_lookup(const char *interface, const char *url,
+                               connman_proxy_lookup_cb cb, void *user_data)
+{
+       struct proxy_lookup *lookup;
+
+       DBG("interface %s url %s", interface, url);
+
+       if (interface == NULL)
+               return 0;
+
+       lookup = g_try_new0(struct proxy_lookup, 1);
+       if (lookup == NULL)
+               return 0;
+
+       lookup->token = next_lookup_token++;
+
+       lookup->cb = cb;
+       lookup->user_data = user_data;
+
+       lookup->watch = g_timeout_add_seconds(0, lookup_callback, lookup);
+       if (lookup->watch == 0) {
+               g_free(lookup);
+               return 0;
+       }
+
+       DBG("token %u", lookup->token);
+
+       return lookup->token;
+}
+
+void connman_proxy_lookup_cancel(unsigned int token)
+{
+       DBG("token %u", token);
+}
+
+void connman_proxy_driver_lookup_notify(struct connman_service *service,
+                                        const char *url, const char *result)
+{
+       DBG("service %p url %s result %s", service, url, result);
+
+       if (service == NULL)
+               return;
+}
+
+static gint compare_priority(gconstpointer a, gconstpointer b)
+{
+       const struct connman_proxy_driver *driver1 = a;
+       const struct connman_proxy_driver *driver2 = b;
+
+       return driver2->priority - driver1->priority;
+}
+
+/**
+ * connman_proxy_driver_register:
+ * @driver: Proxy driver definition
+ *
+ * Register a new proxy driver
+ *
+ * Returns: %0 on success
+ */
+int connman_proxy_driver_register(struct connman_proxy_driver *driver)
+{
+       DBG("driver %p name %s", driver, driver->name);
+
+       driver_list = g_slist_insert_sorted(driver_list, driver,
+                                                       compare_priority);
+
+       return 0;
+}
+
+/**
+ * connman_proxy_driver_unregister:
+ * @driver: Proxy driver definition
+ *
+ * Remove a previously registered proxy driver
+ */
+void connman_proxy_driver_unregister(struct connman_proxy_driver *driver)
+{
+       DBG("driver %p name %s", driver, driver->name);
+
+       driver_list = g_slist_remove(driver_list, driver);
+}
+
+int __connman_proxy_init(void)
+{
+       DBG("");
+
+       return 0;
+}
+
+void __connman_proxy_cleanup(void)
+{
+       DBG("");
+}