[glib-networking] libproxy: add a PAC/WPAD handling D-Bus service
- From: Dan Winship <danw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib-networking] libproxy: add a PAC/WPAD handling D-Bus service
- Date: Wed, 16 Mar 2011 14:10:26 +0000 (UTC)
commit eaaa73ebab6485edaa763f6d4627977ce7a97cfb
Author: Dan Winship <danw gnome org>
Date: Thu Mar 10 12:07:18 2011 -0500
libproxy: add a PAC/WPAD handling D-Bus service
libproxy can deal with PAC and WPAD; other proxy resolvers may not be
able to, so let them use libproxy to do it.
Having it out-of-process is good because the only way to force
libproxy to do exactly what we want is to fiddle with environment
variables, and we don't want those to leak into the environment.
https://bugzilla.gnome.org/show_bug.cgi?id=644211
.gitignore | 4 +
configure.ac | 1 +
proxy/libproxy/Makefile.am | 35 ++++-
proxy/libproxy/glibpacrunner.c | 166 ++++++++++++++++++++++
proxy/libproxy/glibproxyresolver.c | 19 ++-
proxy/libproxy/org.gtk.GLib.PACRunner.service.in | 3 +
6 files changed, 217 insertions(+), 11 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index ed6e2f5..20f00a3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,7 +22,11 @@ install-sh
glib-gettextize
glib-zip
gtk-doc.make
+compile
INSTALL
ChangeLog
m4
+
+proxy/libproxy/glib-pacrunner
+proxy/libproxy/org.gtk.GLib.PACRunner.service
diff --git a/configure.ac b/configure.ac
index ca700a0..0218196 100644
--- a/configure.ac
+++ b/configure.ac
@@ -14,6 +14,7 @@ LT_INIT
dnl Checks for programs.
AC_PROG_CC
+AM_PROG_CC_C_O
AC_PROG_CPP
dnl Checks for libraries.
diff --git a/proxy/libproxy/Makefile.am b/proxy/libproxy/Makefile.am
index e0d9ef8..edcd908 100644
--- a/proxy/libproxy/Makefile.am
+++ b/proxy/libproxy/Makefile.am
@@ -2,6 +2,12 @@ include $(top_srcdir)/Makefile.decl
NULL =
+INCLUDES = \
+ -DG_LOG_DOMAIN=\"GLib-Net\" \
+ $(GLIB_CFLAGS) \
+ $(LIBPROXY_CFLAGS) \
+ -DG_DISABLE_DEPRECATED
+
module_flags = -export_dynamic -avoid-version -module -no-undefined -export-symbols-regex '^g_io_module_(load|unload|query)'
giomodule_LTLIBRARIES = libgiolibproxy.la
@@ -13,15 +19,30 @@ libgiolibproxy_la_SOURCES = \
libproxy-module.c \
$(NULL)
-libgiolibproxy_la_CFLAGS = \
- -DG_LOG_DOMAIN=\"GLib-Net\" \
- $(GLIB_CFLAGS) \
- $(LIBPROXY_CFLAGS) \
- -DGIO_MODULE_DIR=\"$(GIO_MODULE_DIR)\" \
- -DG_DISABLE_DEPRECATED
-
+libgiolibproxy_la_CFLAGS = -DGLIBPROXY_MODULE
libgiolibproxy_la_LDFLAGS = $(module_flags)
libgiolibproxy_la_LIBADD = \
$(GLIB_LIBS) \
$(LIBPROXY_LIBS) \
$(NULL)
+
+libexec_PROGRAMS = glib-pacrunner
+
+glib_pacrunner_SOURCES = \
+ glibproxyresolver.c \
+ glibproxyresolver.h \
+ glibpacrunner.c \
+ $(NULL)
+
+glib_pacrunner_CFLAGS = -DGLIBPROXY_PACRUNNER
+glib_pacrunner_LDADD = \
+ $(GLIB_LIBS) \
+ $(LIBPROXY_LIBS) \
+ $(NULL)
+
+servicedir = $(datadir)/dbus-1/services
+service_in_files = org.gtk.GLib.PACRunner.service.in
+service_DATA = $(service_in_files:.service.in=.service)
+
+org.gtk.GLib.PACRunner.service: org.gtk.GLib.PACRunner.service.in Makefile
+ $(AM_V_GEN) sed -e "s|\ libexecdir\@|$(libexecdir)|" $< > $@
diff --git a/proxy/libproxy/glibpacrunner.c b/proxy/libproxy/glibpacrunner.c
new file mode 100644
index 0000000..0044723
--- /dev/null
+++ b/proxy/libproxy/glibpacrunner.c
@@ -0,0 +1,166 @@
+/* GIO - GLib Input, Output and Streaming Library
+ *
+ * Copyright 2011 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+
+#include <gio/gio.h>
+#include "glibproxyresolver.h"
+
+static const gchar introspection_xml[] =
+ "<node>"
+ " <interface name='org.gtk.GLib.PACRunner'>"
+ " <method name='Lookup'>"
+ " <arg type='s' name='pac_url' direction='in'/>"
+ " <arg type='s' name='lookup_url' direction='in'/>"
+ " <arg type='as' name='proxies' direction='out'/>"
+ " </method>"
+ " </interface>"
+ "</node>";
+
+static GProxyResolver *resolver;
+static GMainLoop *loop;
+
+static void
+got_proxies (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GDBusMethodInvocation *invocation = user_data;
+ gchar **proxies;
+ GError *error = NULL;
+
+ proxies = g_proxy_resolver_lookup_finish (resolver, result, &error);
+ g_assert (!error);
+
+ g_dbus_method_invocation_return_value (invocation,
+ g_variant_new ("(^as)", proxies));
+ g_strfreev (proxies);
+}
+
+static void
+handle_method_call (GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *method_name,
+ GVariant *parameters,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
+{
+ const gchar *pac_url, *lookup_url;
+
+ g_variant_get (parameters, "(&s&s)", &pac_url, &lookup_url);
+
+ if (!g_ascii_strncasecmp (pac_url, "http", 4))
+ {
+ gchar *libproxy_url = g_strdup_printf ("pac+%s", pac_url);
+ g_setenv ("http_proxy", libproxy_url, TRUE);
+ g_free (libproxy_url);
+ }
+ else
+ g_setenv ("http_proxy", "wpad://", TRUE);
+
+ g_proxy_resolver_lookup_async (resolver, lookup_url,
+ NULL, got_proxies, invocation);
+}
+
+static const GDBusInterfaceVTable interface_vtable =
+ {
+ handle_method_call,
+ NULL,
+ NULL
+ };
+
+static void
+on_bus_acquired (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+ GDBusNodeInfo *introspection_data;
+ GError *error = NULL;
+
+ introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
+ g_dbus_connection_register_object (connection,
+ "/org/gtk/GLib/PACRunner",
+ introspection_data->interfaces[0],
+ &interface_vtable,
+ NULL,
+ NULL,
+ &error);
+ if (error)
+ g_error ("Could not register server: %s", error->message);
+}
+
+static void
+on_name_acquired (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+}
+
+static void
+on_name_lost (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+ g_main_loop_quit (loop);
+}
+
+int
+main (int argc, char *argv[])
+{
+ int owner_id;
+
+ g_type_init ();
+
+ /* Unset variables that would make libproxy try to use gconf or ksettings */
+ g_unsetenv ("GNOME_DESKTOP_SESSION_ID");
+ g_unsetenv ("DESKTOP_SESSION");
+ g_unsetenv ("KDE_FULL_SESSION");
+
+ /* Unset static proxy settings */
+ g_unsetenv ("http_proxy");
+ g_unsetenv ("HTTP_PROXY");
+ g_unsetenv ("https_proxy");
+ g_unsetenv ("HTTPS_PROXY");
+ g_unsetenv ("ftp_proxy");
+ g_unsetenv ("FTP_PROXY");
+ g_unsetenv ("no_proxy");
+ g_unsetenv ("NO_PROXY");
+
+ resolver = g_object_new (G_TYPE_LIBPROXY_RESOLVER, NULL);
+
+ owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
+ "org.gtk.GLib.PACRunner",
+ G_BUS_NAME_OWNER_FLAGS_NONE,
+ on_bus_acquired,
+ on_name_acquired,
+ on_name_lost,
+ NULL,
+ NULL);
+
+ loop = g_main_loop_new (NULL, FALSE);
+ g_main_loop_run (loop);
+
+ g_bus_unown_name (owner_id);
+ return 0;
+}
diff --git a/proxy/libproxy/glibproxyresolver.c b/proxy/libproxy/glibproxyresolver.c
index e55b730..7612751 100644
--- a/proxy/libproxy/glibproxyresolver.c
+++ b/proxy/libproxy/glibproxyresolver.c
@@ -38,15 +38,24 @@ struct _GLibProxyResolver {
static void g_libproxy_resolver_iface_init (GProxyResolverInterface *iface);
+#ifdef GLIBPROXY_MODULE
+static void
+g_libproxy_resolver_class_finalize (GLibProxyResolverClass *klass)
+{
+}
+
G_DEFINE_DYNAMIC_TYPE_EXTENDED (GLibProxyResolver,
g_libproxy_resolver,
G_TYPE_OBJECT, 0,
G_IMPLEMENT_INTERFACE_DYNAMIC (G_TYPE_PROXY_RESOLVER,
g_libproxy_resolver_iface_init))
-
-static void g_libproxy_resolver_class_finalize (GLibProxyResolverClass *klass)
-{
-}
+#else
+G_DEFINE_TYPE_EXTENDED (GLibProxyResolver,
+ g_libproxy_resolver,
+ G_TYPE_OBJECT, 0,
+ G_IMPLEMENT_INTERFACE (G_TYPE_PROXY_RESOLVER,
+ g_libproxy_resolver_iface_init))
+#endif
static void
g_libproxy_resolver_finalize (GObject *object)
@@ -256,6 +265,7 @@ g_libproxy_resolver_iface_init (GProxyResolverInterface *iface)
iface->lookup_finish = g_libproxy_resolver_lookup_finish;
}
+#ifdef GLIBPROXY_MODULE
void
g_libproxy_resolver_register (GIOModule *module)
{
@@ -265,3 +275,4 @@ g_libproxy_resolver_register (GIOModule *module)
"libproxy",
0);
}
+#endif
diff --git a/proxy/libproxy/org.gtk.GLib.PACRunner.service.in b/proxy/libproxy/org.gtk.GLib.PACRunner.service.in
new file mode 100644
index 0000000..df736ce
--- /dev/null
+++ b/proxy/libproxy/org.gtk.GLib.PACRunner.service.in
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.gtk.GLib.PACRunner
+Exec= libexecdir@/glib-pacrunner
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]