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
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)|" $< > $@
--- /dev/null
+/* 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;
+}