about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMarco Peereboom <marco@conformal.com>2011-11-16 11:18:35 -0600
committerMarco Peereboom <marco@conformal.com>2011-11-16 11:18:35 -0600
commit0853ea91c4383cbf8adbb990410e051b53343f90 (patch)
tree6ea07292a82d6ef1e734fca608c637b3a48a255d
parent02709f21fe7340b3204d2a9526a1f7f8f64855a2 (diff)
downloadxombrero-0853ea91c4383cbf8adbb990410e051b53343f90.tar.gz
Add proxy command.
We can now toggle a proxy with F2 and we also look at HTTP_PROXY
environment variable.  This is handy for toggling Tor on and off.
-rw-r--r--settings.c1
-rw-r--r--xxxterm.118
-rw-r--r--xxxterm.c48
-rw-r--r--xxxterm.h4
4 files changed, 69 insertions, 2 deletions
diff --git a/settings.c b/settings.c
index cb4d1eb..d1de255 100644
--- a/settings.c
+++ b/settings.c
@@ -661,6 +661,7 @@ struct key_binding	keys[] = {
 	{ "toplevel toggle",	0,	1,	GDK_F4		},
 	{ "help",		0,	1,	GDK_F1		},
 	{ "run_script",		MOD1,	1,	GDK_r		},
+	{ "proxy toggle",	0,	1,	GDK_F2		},
 
 	/* search */
 	{ "searchnext",		0,	0,	GDK_n		},
diff --git a/xxxterm.1 b/xxxterm.1
index 5c6711c..fdc0643 100644
--- a/xxxterm.1
+++ b/xxxterm.1
@@ -213,6 +213,8 @@ option is used.
 .Bl -tag -width Ds -offset indent -compact
 .It Cm F1
 Alias for ":help"
+.It Cm F2
+Alias for ":proxy toggle"
 .It Cm F4
 Alias for ":toplevel toggle"
 .It Cm F9
@@ -532,6 +534,22 @@ Toggle plugin execution for the current FQDN.
 Toggle plugin execution for the current top level domain.
 .It Cm print
 Print page.
+.It Cm proxy
+The
+.Cm proxy
+command is used to manipulate the currently set proxy.
+Used by itself it expands to
+.Cm proxy show .
+.It Cm proxy show
+Displays the current
+.Cm http_proxy
+setting.
+.It Cm proxy toggle
+Enables or disables the proxy for
+.Nm .
+Note that
+.Cm http_proxy
+must be set before it can be toggled.
 .It Cm qa , qall , quitall
 Quit
 .Nm .
diff --git a/xxxterm.c b/xxxterm.c
index d904bbf..a26211c 100644
--- a/xxxterm.c
+++ b/xxxterm.c
@@ -2892,6 +2892,41 @@ restart(struct tab *t, struct karg *args)
 	return (0);
 }
 
+char		*http_proxy_save; /* not a setting, used to toggle */
+
+int
+proxy_cmd(struct tab *t, struct karg *args)
+{
+	DNPRINTF(XT_D_CMD, "%s: tab %d\n", __func__, t->tab_id);
+
+	if (t == NULL)
+		return (1);
+
+	/* setup */
+	if (http_proxy) {
+		if (http_proxy_save)
+			g_free(http_proxy_save);
+		http_proxy_save = g_strdup(http_proxy);
+	}
+
+	if (args->i & XT_PRXY_SHOW) {
+		if (http_proxy)
+			show_oops(t, "http_proxy = %s", http_proxy);
+		else
+			show_oops(t, "proxy is currently disabled");
+	} else if (args->i & XT_PRXY_TOGGLE) {
+		if (http_proxy_save == NULL && http_proxy == NULL) {
+			show_oops(t, "can't toggle proxy");
+			goto done;
+		}
+		if (http_proxy)
+			setup_proxy(NULL);
+		else
+			setup_proxy(http_proxy_save);
+	}
+done:
+	return (XT_CB_PASSTHROUGH);
+}
 struct cmd {
 	char		*cmd;
 	int		level;
@@ -3079,6 +3114,10 @@ struct cmd {
 	{ "inspector",		0,	inspector_cmd,		XT_INS_SHOW,		0 },
 	{ "show",		1,	inspector_cmd,		XT_INS_SHOW,		0 },
 	{ "hide",		1,	inspector_cmd,		XT_INS_HIDE,		0 },
+
+	/* proxy */
+	{ "proxy",		0,	proxy_cmd,		XT_PRXY_SHOW,		0 },
+	{ "toggle",		1,	proxy_cmd,		XT_PRXY_TOGGLE,		0 },
 };
 
 struct {
@@ -7324,8 +7363,13 @@ main(int argc, char *argv[])
 	env_proxy = getenv("http_proxy");
 	if (env_proxy)
 		setup_proxy(env_proxy);
-	else
-		setup_proxy(http_proxy);
+	else {
+		env_proxy = getenv("HTTP_PROXY");
+		if (env_proxy)
+			setup_proxy(env_proxy);
+		else
+			setup_proxy(http_proxy);
+	}
 
 	if (opte) {
 		send_cmd_to_socket(argv[0]);
diff --git a/xxxterm.h b/xxxterm.h
index b23be70..49b281b 100644
--- a/xxxterm.h
+++ b/xxxterm.h
@@ -280,6 +280,10 @@ int			remove_cookie(int);
 void			print_cookie(char *msg, SoupCookie *);
 void			setup_cookies(void);
 
+/* proxy */
+#define XT_PRXY_SHOW		(1<<0)
+#define XT_PRXY_TOGGLE		(1<<1)
+
 /* inspector */
 #define XT_INS_SHOW		(1<<0)
 #define XT_INS_HIDE		(1<<1)