[hackers] [surf] Simplify proxy toggle || Quentin Rameau

From: <git_AT_suckless.org>
Date: Wed, 8 Feb 2017 16:02:29 +0100 (CET)

commit ab16fa5e7c14bb1eb3f4513bd993401b1197cb52
Author: Quentin Rameau <quinq_AT_fifth.space>
AuthorDate: Mon Feb 6 11:56:19 2017 +0100
Commit: Quentin Rameau <quinq_AT_fifth.space>
CommitDate: Wed Feb 8 15:59:55 2017 +0100

    Simplify proxy toggle

diff --git a/surf.c b/surf.c
index e8da563..d75e589 100644
--- a/surf.c
+++ b/surf.c
_AT_@ -198,7 +198,6 @@ static void scroll_v(Client *c, const Arg *arg);
 static void scroll(GtkAdjustment *a, const Arg *arg);
 static void setatom(Client *c, int a, const char *v);
 static void setup(void);
-static void setup_proxy(void);
 static void sigchld(int unused);
 static void sighup(int unused);
 static void source(Client *c, const Arg *arg);
_AT_@ -1326,7 +1325,6 @@ setup(void)
 {
         int i;
         char *styledirfile, *stylepath;
- GProxyResolver *pr;
         SoupSession *s;
         GError *error = NULL;
 
_AT_@ -1400,39 +1398,7 @@ setup(void)
         g_object_set(G_OBJECT(s), "tls-database", tlsdb, NULL);
         g_object_set(G_OBJECT(s), "ssl-strict", strictssl, NULL);
 
- setup_proxy();
-}
-
-void
-setup_proxy(void)
-{
- char *proxy, *new_proxy, *no_proxy, **new_no_proxy;
- GProxyResolver *pr;
- SoupSession *s;
-
- /* request handler */
- s = webkit_get_default_session();
-
- /* proxy */
- if ((proxy = getenv("http_proxy")) && strcmp(proxy, "")) {
- new_proxy = g_strrstr(proxy, "http://")
- || g_strrstr(proxy, "https://")
- || g_strrstr(proxy, "socks://")
- || g_strrstr(proxy, "socks4://")
- || g_strrstr(proxy, "socks4a://")
- || g_strrstr(proxy, "socks5://")
- ? g_strdup(proxy)
- : g_strdup_printf("http://%s", proxy);
- new_no_proxy = ((no_proxy = getenv("no_proxy")) && strcmp(no_proxy, ""))
- ? g_strsplit(no_proxy, ",", -1) : NULL;
- pr = g_simple_proxy_resolver_new(new_proxy, new_no_proxy);
- g_object_set(G_OBJECT(s), "proxy-resolver", pr, NULL);
- g_free(new_proxy);
- g_strfreev(new_no_proxy);
- usingproxy = 1;
- } else {
- usingproxy = 0;
- }
+ toggleproxy(NULL, NULL);
 }
 
 void
_AT_@ -1577,6 +1543,8 @@ twitch(Client *c, const Arg *arg)
 void
 toggleproxy(Client *c, const Arg *arg)
 {
+ char *proxy, *new_proxy, *no_proxy, **new_no_proxy;
+ GProxyResolver *pr;
         SoupSession *s;
 
         /* request handler */
_AT_@ -1585,11 +1553,26 @@ toggleproxy(Client *c, const Arg *arg)
         if (usingproxy) {
                 g_object_set(G_OBJECT(s), "proxy-resolver", NULL, NULL);
                 usingproxy = 0;
- } else {
- setup_proxy();
+ } else if ((proxy = getenv("http_proxy")) && strcmp(proxy, "")) {
+ new_proxy = g_strrstr(proxy, "http://")
+ || g_strrstr(proxy, "https://")
+ || g_strrstr(proxy, "socks://")
+ || g_strrstr(proxy, "socks4://")
+ || g_strrstr(proxy, "socks4a://")
+ || g_strrstr(proxy, "socks5://")
+ ? g_strdup(proxy)
+ : g_strdup_printf("http://%s", proxy);
+ new_no_proxy = ((no_proxy = getenv("no_proxy")) && strcmp(no_proxy, ""))
+ ? g_strsplit(no_proxy, ",", -1) : NULL;
+ pr = g_simple_proxy_resolver_new(new_proxy, new_no_proxy);
+ g_object_set(G_OBJECT(s), "proxy-resolver", pr, NULL);
+ g_free(new_proxy);
+ g_strfreev(new_no_proxy);
+ usingproxy = 1;
         }
 
- updatetitle(c);
+ if (c)
+ updatetitle(c);
         /* Do not reload. */
 }
 
Received on Wed Feb 08 2017 - 16:02:29 CET

This archive was generated by hypermail 2.3.0 : Wed Feb 08 2017 - 16:12:27 CET