---
Makefile.plugins | 7 ++
configure.ac | 10 +++
plugins/proxygconf.c | 183 ++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 200 insertions(+), 0 deletions(-)
create mode 100644 plugins/proxygconf.c
diff --git a/Makefile.plugins b/Makefile.plugins
index 4ca78d3..2f15d85 100644
--- a/Makefile.plugins
+++ b/Makefile.plugins
@@ -230,6 +230,13 @@ plugins_ntpd_la_LDFLAGS = $(plugin_ldflags)
endif
endif
+if PROXYGCONF
+plugin_LTLIBRARIES += plugins/proxygconf.la
+plugin_objects += $(plugins_proxygconf_la_OBJECTS)
+plugins_proxygconf_la_CFLAGS = $(plugin_cflags) @GCONF_CFLAGS@
+plugins_proxygconf_la_LDFLAGS = $(plugin_ldflags) @GCONF_LIBS@
+endif
+
EXTRA_DIST += plugins/polkit.policy scripts/dhclient.conf
plugins/connman.policy: plugins/polkit.policy
diff --git a/configure.ac b/configure.ac
index 6923aa1..ddba330 100644
--- a/configure.ac
+++ b/configure.ac
@@ -368,5 +368,15 @@ AC_ARG_ENABLE(datafiles,
AC_HELP_STRING([--disable-datafiles],
[enable_datafiles=${enableval}])
AM_CONDITIONAL(DATAFILES, test "${enable_datafiles}" != "no")
+AC_ARG_ENABLE(proxygconf, AC_HELP_STRING([--enable-proxygconf],
+ [enable proxy GConf support]), [enable_proxygconf=${enableval}])
+AM_CONDITIONAL(PROXYGCONF, test "${enable_proxygconf}" = "yes")
+if (test "${enable_proxygconf}" = "yes"); then
+ PKG_CHECK_MODULES(GCONF, gconf-2.0, dummy=yes,
+ AC_MSG_ERROR(gconf library is required))
+ AC_SUBST(GCONF_CFLAGS)
+ AC_SUBST(GCONF_LIBS)
+fi
+
AC_OUTPUT(Makefile include/version.h src/connman.service
scripts/connman doc/version.xml connman.pc)
diff --git a/plugins/proxygconf.c b/plugins/proxygconf.c
new file mode 100644
index 0000000..2987567
--- /dev/null
+++ b/plugins/proxygconf.c
@@ -0,0 +1,183 @@
+/*
+ * Save proxy settings to gconf.
+ *
+ * Copyright (C) 2010 Nokia 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 <stdio.h>
+
+#define CONNMAN_API_SUBJECT_TO_CHANGE
+#include <connman/plugin.h>
+#include <connman/storage.h>
+#include <connman/log.h>
+
+#include <gconf/gconf-client.h>
+
+#define CONF_PROXY "/system/proxy"
+#define HTTP_PROXY "/system/http_proxy"
+
+
+static void set(GConfClient *gconf,
+ const char *host_path, const char *host,
+ const char *port_path, uint16_t port)
+{
+ if (host && host[0]) {
+ gconf_client_set_string(gconf, host_path, host, NULL);
+ if (port_path)
+ gconf_client_set_int(gconf, port_path, port, NULL);
+ } else {
+ gconf_client_unset(gconf, host_path, NULL);
+ if (port_path)
+ gconf_client_unset(gconf, port_path, NULL);
+ }
+}
+
+static void clear_entries(GConfClient *gconf)
+{
+ gconf_client_unset(gconf, CONF_PROXY "/mode", NULL);
+ gconf_client_unset(gconf, CONF_PROXY "/secure_host", NULL);
+ gconf_client_unset(gconf, CONF_PROXY "/secure_port", NULL);
+ gconf_client_unset(gconf, CONF_PROXY "/ftp_host", NULL);
+ gconf_client_unset(gconf, CONF_PROXY "/ftp_port", NULL);
+ gconf_client_unset(gconf, CONF_PROXY "/socks_host", NULL);
+ gconf_client_unset(gconf, CONF_PROXY "/socks_port", NULL);
+ gconf_client_unset(gconf, CONF_PROXY "/rtsp_host", NULL);
+ gconf_client_unset(gconf, CONF_PROXY "/rtsp_port", NULL);
+
+ gconf_client_unset(gconf, HTTP_PROXY "/host", NULL);
+ gconf_client_unset(gconf, HTTP_PROXY "/port", NULL);
+ gconf_client_unset(gconf, HTTP_PROXY "/ignore_hosts", NULL);
+ gconf_client_unset(gconf, HTTP_PROXY "/use_http_proxy", NULL);
+}
+
+static int proxy_save(struct connman_service *service)
+{
+ GConfClient *gconf;
+ struct connman_manual_proxy *proxy;
+ enum connman_service_proxy_method method;
+
+ DBG("");
+
+ gconf = gconf_client_get_default();
+
+ proxy = connman_service_get_default_proxy(service, &method);
+ if (!proxy) {
+ clear_entries(gconf);
+ goto out;
+ }
+
+ if (method != CONNMAN_SERVICE_PROXY_METHOD_MANUAL) {
+ clear_entries(gconf);
+ goto out;
+ }
+
+ set(gconf, CONF_PROXY "/mode", "manual", NULL, 0);
+
+ set(gconf, CONF_PROXY "/secure_host", proxy->https,
+ CONF_PROXY "/secure_port", proxy->https_port);
+
+ set(gconf, CONF_PROXY "/ftp_host", proxy->ftp,
+ CONF_PROXY "/ftp_port", proxy->ftp_port);
+
+ set(gconf, CONF_PROXY "/socks_host", proxy->socks,
+ CONF_PROXY "/socks_port", proxy->socks_port);
+
+ set(gconf, CONF_PROXY "/rtsp_host", proxy->rtsp,
+ CONF_PROXY "/rtsp_port", proxy->rtsp_port);
+
+ if (proxy->http)
+ gconf_client_set_bool(gconf,
+ HTTP_PROXY "/use_http_proxy",
+ TRUE, NULL);
+ else
+ gconf_client_unset(gconf, HTTP_PROXY "/use_http_proxy", NULL);
+
+ set(gconf, HTTP_PROXY "/host", proxy->http,
+ HTTP_PROXY "/port", proxy->http_port);
+
+ if (proxy->ignore)
+ gconf_client_set_list(gconf, HTTP_PROXY "/ignore_hosts",
+ GCONF_VALUE_STRING, proxy->ignore, NULL);
+ else
+ gconf_client_unset(gconf, HTTP_PROXY "/ignore_hosts", NULL);
+
+out:
+ gconf_client_suggest_sync(gconf, NULL);
+ g_object_unref(gconf);
+ return -1;
+}
+
+static int proxy_clear(struct connman_service *service)
+{
+ GConfClient *gconf;
+ struct connman_manual_proxy *proxy;
+ enum connman_service_proxy_method method;
+
+ DBG("");
+
+ gconf = gconf_client_get_default();
+
+ proxy = connman_service_get_default_proxy(service, &method);
+ if (!proxy) {
+ clear_entries(gconf);
+ goto out;
+ }
+ proxy = connman_service_get_default_proxy(service, &method);
+ if (!proxy) {
+ clear_entries(gconf);
+ goto out;
+ }
+
+ clear_entries(gconf);
+
+out:
+ gconf_client_suggest_sync(gconf, NULL);
+ g_object_unref(gconf);
+ return -1;
+}
+
+static struct connman_storage proxygconf_storage = {
+ .name = "proxygconf",
+ .priority = CONNMAN_STORAGE_PRIORITY_HIGH,
+ .service_load = proxy_clear,
+ .service_save = proxy_save,
+};
+
+static int proxygconf_init(void)
+{
+ DBG("");
+
+ g_type_init();
+
+ if (connman_storage_register(&proxygconf_storage) < 0)
+ connman_error("Failed to register proxy gconf storage");
+
+ return 0;
+}
+
+static void proxygconf_exit(void)
+{
+ connman_storage_unregister(&proxygconf_storage);
+}
+
+CONNMAN_PLUGIN_DEFINE(proxygconf, "Proxy GConf plugin", VERSION,
+ CONNMAN_PLUGIN_PRIORITY_DEFAULT,
+ proxygconf_init, proxygconf_exit)
--
1.7.0.4
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman