Simplify proxy toggle
This commit is contained in:
parent
dcabd0239e
commit
ab16fa5e7c
1 changed files with 21 additions and 38 deletions
59
surf.c
59
surf.c
|
@ -198,7 +198,6 @@ static void scroll_v(Client *c, const Arg *arg);
|
||||||
static void scroll(GtkAdjustment *a, const Arg *arg);
|
static void scroll(GtkAdjustment *a, const Arg *arg);
|
||||||
static void setatom(Client *c, int a, const char *v);
|
static void setatom(Client *c, int a, const char *v);
|
||||||
static void setup(void);
|
static void setup(void);
|
||||||
static void setup_proxy(void);
|
|
||||||
static void sigchld(int unused);
|
static void sigchld(int unused);
|
||||||
static void sighup(int unused);
|
static void sighup(int unused);
|
||||||
static void source(Client *c, const Arg *arg);
|
static void source(Client *c, const Arg *arg);
|
||||||
|
@ -1326,7 +1325,6 @@ setup(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *styledirfile, *stylepath;
|
char *styledirfile, *stylepath;
|
||||||
GProxyResolver *pr;
|
|
||||||
SoupSession *s;
|
SoupSession *s;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
|
@ -1400,39 +1398,7 @@ setup(void)
|
||||||
g_object_set(G_OBJECT(s), "tls-database", tlsdb, NULL);
|
g_object_set(G_OBJECT(s), "tls-database", tlsdb, NULL);
|
||||||
g_object_set(G_OBJECT(s), "ssl-strict", strictssl, NULL);
|
g_object_set(G_OBJECT(s), "ssl-strict", strictssl, NULL);
|
||||||
|
|
||||||
setup_proxy();
|
toggleproxy(NULL, NULL);
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -1577,6 +1543,8 @@ twitch(Client *c, const Arg *arg)
|
||||||
void
|
void
|
||||||
toggleproxy(Client *c, const Arg *arg)
|
toggleproxy(Client *c, const Arg *arg)
|
||||||
{
|
{
|
||||||
|
char *proxy, *new_proxy, *no_proxy, **new_no_proxy;
|
||||||
|
GProxyResolver *pr;
|
||||||
SoupSession *s;
|
SoupSession *s;
|
||||||
|
|
||||||
/* request handler */
|
/* request handler */
|
||||||
|
@ -1585,11 +1553,26 @@ toggleproxy(Client *c, const Arg *arg)
|
||||||
if (usingproxy) {
|
if (usingproxy) {
|
||||||
g_object_set(G_OBJECT(s), "proxy-resolver", NULL, NULL);
|
g_object_set(G_OBJECT(s), "proxy-resolver", NULL, NULL);
|
||||||
usingproxy = 0;
|
usingproxy = 0;
|
||||||
} else {
|
} else if ((proxy = getenv("http_proxy")) && strcmp(proxy, "")) {
|
||||||
setup_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. */
|
/* Do not reload. */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue