Browse Source

xap/surf: Improved environment variable support.

slackware-14.2
Damien Goutte-Gattat 12 years ago
parent
commit
bfb8d9e60f
  1. 320
      xap/surf/surf-0.3-http_proxy.patch
  2. 4
      xap/surf/surf.SlackBuild

320
xap/surf/surf-0.3-http_proxy.patch

@ -1,50 +1,286 @@
diff -Naur surf-0.3.orig/surf.c surf-0.3/surf.c
--- surf-0.3.orig/surf.c 2009-10-30 13:41:02.000000000 +0100
+++ surf-0.3/surf.c 2009-12-29 16:22:08.886652325 +0100
@@ -104,6 +104,7 @@
static void scroll(Client *c, const Arg *arg);
static void setatom(Client *c, Atom a, const char *v);
static void setup(void);
+static void set_proxy(void);
static void sigchld(int unused);
static void source(Client *c, const Arg *arg);
static void spawn(Client *c, const Arg *arg);
@@ -707,6 +708,30 @@
reloadcookies();
}
diff -Naur surf-0.3.orig/Makefile surf-0.3/Makefile
--- surf-0.3.orig/Makefile 2009-10-30 13:41:02.000000000 +0100
+++ surf-0.3/Makefile 2009-12-31 13:45:46.359950127 +0100
@@ -3,7 +3,7 @@
include config.mk
-SRC = surf.c
+SRC = surf.c icp_proxy_resolver.c
OBJ = ${SRC:.c=.o}
all: options surf
@@ -26,7 +26,7 @@
surf: ${OBJ}
@echo CC -o $@
- @${CC} -o $@ surf.o ${LDFLAGS}
+ @${CC} -o $@ ${OBJ} ${LDFLAGS}
clean:
@echo cleaning
diff -Naur surf-0.3.orig/icp_proxy_resolver.c surf-0.3/icp_proxy_resolver.c
--- surf-0.3.orig/icp_proxy_resolver.c 1970-01-01 01:00:00.000000000 +0100
+++ surf-0.3/icp_proxy_resolver.c 2009-12-31 13:40:59.185639258 +0100
@@ -0,0 +1,188 @@
+/*
+ * icp_proxy_resolver - Environ-based proxy resolver for libsoup
+ * Copyright (C) 2009 Damien Goutte-Gattat
+ *
+ * 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 3 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, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <icp_proxy_resolver.h>
+#include <libsoup/soup-session-feature.h>
+#include <libsoup/soup-proxy-uri-resolver.h>
+
+#include <stdlib.h>
+#include <string.h>
+
+/*
+ * WebKit does not honor http_proxy environment variable unless libsoup
+ * has been compiled with GNOME support.
+ * TODO: Rant about developers who need GNOME libraries to read the
+ * value of an environment variable.
+ * Helper functions
+ */
+void
+set_proxy(void)
+
+static size_t
+count_hosts(const char *hosts)
+{
+ char *c;
+ size_t n;
+
+ for ( c = (char *)hosts, n = 1; *c != '\0'; c++ )
+ if ( *c == ',' )
+ n += 1;
+
+ return n;
+}
+
+static char **
+make_exceptions_list(const char *hosts)
+{
+ char *data, **index, *copy, *cursor;
+ size_t count, len;
+ int new_host;
+
+ count = count_hosts(hosts);
+ len = strlen(hosts);
+
+ data = malloc((count + 1) * sizeof(char *) + len + 1);
+ index = (char **)data;
+ copy = data + (count + 1) * sizeof(char *);
+ cursor = (char *)hosts;
+ new_host = 1;
+ count = 0;
+
+ while ( *cursor != '\0' ) {
+ if ( *cursor == ',' ) {
+ new_host = 1;
+ *copy++ = '\0';
+ }
+ else {
+ if ( new_host ) {
+ new_host = 0;
+ index[count++] = copy;
+ }
+ *copy++ = *cursor;
+ }
+ cursor += 1;
+ }
+ *copy = '\0';
+ index[count] = NULL;
+
+ return index;
+}
+
+
+/*
+ * SoupProxyURIResolverInterface implementation
+ */
+
+static SoupURI *
+get_proxy_uri(IcpProxyResolver *self,
+ SoupURI *uri)
+{
+ SoupURI *proxy = NULL;
+
+ if ( strcmp(uri->scheme, "http") == 0 )
+ proxy = self->http_proxy;
+
+ if ( strcmp(uri->scheme, "https") == 0 )
+ proxy = self->https_proxy;
+
+ if ( strcmp(uri->scheme, "ftp") == 0 )
+ proxy = self->ftp_proxy;
+
+ if ( proxy != NULL && self->no_proxy_hosts != NULL ) {
+ char **host = self->no_proxy_hosts;
+
+ while ( *host != NULL && proxy != NULL ) {
+ if ( strcmp(*host, uri->host) == 0 )
+ proxy = NULL;
+ host += 1;
+ }
+ }
+
+ return proxy;
+}
+
+static void
+get_proxy_uri_async(SoupProxyURIResolver *self,
+ SoupURI *uri,
+ GMainContext *context,
+ GCancellable *cancellable,
+ SoupProxyURIResolverCallback callback,
+ gpointer user_data)
+{
+ SoupSession *s;
+ SoupURI *proxy_uri;
+ char *http_proxy;
+ IcpProxyResolver *instance;
+
+ http_proxy = getenv("http_proxy");
+ if ( http_proxy ) {
+ proxy_uri = soup_uri_new(http_proxy);
+ if ( proxy_uri ) {
+ s = webkit_get_default_session();
+ g_object_set(s, SOUP_SESSION_PROXY_URI, proxy_uri, NULL);
+ soup_uri_free(proxy_uri);
+ }
+ }
+ instance = ICP_PROXY_RESOLVER(self);
+ callback(self, SOUP_STATUS_OK, get_proxy_uri(instance, uri), user_data);
+}
+
+static guint
+get_proxy_uri_sync(SoupProxyURIResolver *self,
+ SoupURI *uri,
+ GCancellable *cancellable,
+ SoupURI **proxy_uri)
+{
+ IcpProxyResolver *instance;
+
+ instance = ICP_PROXY_RESOLVER(self);
+ *proxy_uri = get_proxy_uri(instance, uri);
+
+ return SOUP_STATUS_OK;
+}
+
+static void
+soup_proxy_uri_resolver_interface_init(SoupProxyURIResolverInterface *iface)
+{
+ iface->get_proxy_uri_async = get_proxy_uri_async;
+ iface->get_proxy_uri_sync = get_proxy_uri_sync;
+}
+
+
+/*
+ * Class definition
+ */
+
+static void
+icp_proxy_resolver_class_init(IcpProxyResolverClass *klass)
+{
+}
+
+static void
+icp_proxy_resolver_init(IcpProxyResolver *self)
+{
+ char *http_proxy, *https_proxy, *ftp_proxy, *no_proxy;
+
+ self->http_proxy = self->https_proxy = self->ftp_proxy = NULL;
+ self->no_proxy_hosts = NULL;
+
+ if ( (http_proxy = getenv("http_proxy")) != NULL )
+ self->http_proxy = soup_uri_new(http_proxy);
+
+ if ( (https_proxy = getenv("https_proxy")) != NULL )
+ self->https_proxy = soup_uri_new(https_proxy);
+
+ if ( (ftp_proxy = getenv("ftp_proxy")) != NULL )
+ self->ftp_proxy = soup_uri_new(ftp_proxy);
+
+ if ( (no_proxy = getenv("no_proxy")) != NULL )
+ self->no_proxy_hosts = make_exceptions_list(no_proxy);
+}
+
+G_DEFINE_TYPE_WITH_CODE(IcpProxyResolver, icp_proxy_resolver,
+ G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE(SOUP_TYPE_PROXY_URI_RESOLVER,
+ soup_proxy_uri_resolver_interface_init)
+ G_IMPLEMENT_INTERFACE(SOUP_TYPE_SESSION_FEATURE, NULL))
diff -Naur surf-0.3.orig/icp_proxy_resolver.h surf-0.3/icp_proxy_resolver.h
--- surf-0.3.orig/icp_proxy_resolver.h 1970-01-01 01:00:00.000000000 +0100
+++ surf-0.3/icp_proxy_resolver.h 2009-12-31 13:40:59.186646091 +0100
@@ -0,0 +1,48 @@
+/*
+ * icp_proxy_resolver - Environ-based proxy resolver for libsoup
+ * Copyright (C) 2009 Damien Goutte-Gattat
+ *
+ * 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 3 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, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef ICP20091231_ICP_PROXY_RESOLVER_H
+#define ICP20091231_ICP_PROXY_RESOLVER_H
+
+#include <glib-object.h>
+#include <libsoup/soup-uri.h>
+
+#define ICP_TYPE_PROXY_RESOLVER (icp_proxy_resolver_get_type())
+#define ICP_PROXY_RESOLVER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), ICP_TYPE_PROXY_RESOLVER, IcpProxyResolver))
+#define ICP_IS_PROXY_RESOLVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), ICP_TYPE_PROXY_RESOLVER))
+#define ICP_PROXY_RESOLVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), ICP_TYPE_PROXY_RESOLVER, IcpProxyResolverClass))
+#define ICP_IS_PROXY_RESOLVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), ICP_TYPE_PROXY_RESOLVER))
+#define ICP_PROXY_RESOLVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), ICP_TYPE_PROXY_RESOLVER, IcpProxyResolverClass))
+
+typedef struct {
+ GObject parent;
+ SoupURI *http_proxy;
+ SoupURI *https_proxy;
+ SoupURI *ftp_proxy;
+ char **no_proxy_hosts;
+} IcpProxyResolver;
+
+typedef struct {
+ GObjectClass base;
+} IcpProxyResolverClass;
+
+GType
+icp_proxy_resolver_get_type(void);
+
+#endif /* !ICP20091231_ICP_PROXY_RESOLVER_H */
diff -Naur surf-0.3.orig/surf.c surf-0.3/surf.c
--- surf-0.3.orig/surf.c 2009-10-30 13:41:02.000000000 +0100
+++ surf-0.3/surf.c 2009-12-31 13:47:56.934274004 +0100
@@ -18,6 +18,7 @@
#include <webkit/webkit.h>
#include <glib/gstdio.h>
#include <JavaScriptCore/JavaScript.h>
+#include <icp_proxy_resolver.h>
#define LENGTH(x) (sizeof x / sizeof x[0])
#define CLEANMASK(mask) (mask & ~(GDK_MOD2_MASK))
@@ -705,6 +706,9 @@
soup_session_add_feature(s, SOUP_SESSION_FEATURE(cookies));
g_signal_connect(cookies, "changed", G_CALLBACK(changecookie), NULL);
reloadcookies();
+
+ /* proxy settings from environment */
+ soup_session_add_feature_by_type(s, ICP_TYPE_PROXY_RESOLVER);
}
void
sigchld(int unused) {
if(signal(SIGCHLD, sigchld) == SIG_ERR)
@@ -843,6 +868,7 @@
if(i < argc)
arg.v = argv[i];
setup();
+ set_proxy();
newclient();
if(arg.v)
loaduri(clients, &arg);

4
xap/surf/surf.SlackBuild

@ -34,7 +34,7 @@ WGET=${WGET:-http://code.suckless.org/dl/surf/$ARCHIVE}
# Build infos
NAMEPKG=${NAMEPKG:-surf}
BUILD=${BUILD:-2GGD}
BUILD=${BUILD:-3GGD}
ARCH=${ARCH:-i486}
EXT=${EXT:-txz}
@ -88,7 +88,7 @@ cd $NAME
# Needed to compile against GTK+ < 2.16.0
patch -p 1 < $CWD/surf-0.3-menu_item_label.patch
# Support for http_proxy environment variable
# Support for *_proxy environment variables
patch -p 1 < $CWD/surf-0.3-http_proxy.patch
sed -i "s,/lib,/lib$LIBDIRSUFFIX,

Loading…
Cancel
Save