Home
Reading
Searching
Subscribe
Sponsors
Statistics
Posting
Contact
Spam
Lists
Links
About
Hosting
Filtering
Features Download
Marketing
Archives
FAQ
Blog
 
Gmane
From: dann frazier <dannf <at> dannf.org>
Subject: wget support for no_proxy env var
Newsgroups: gmane.linux.busybox
Date: Monday 18th June 2007 21:23:20 UTC (over 10 years ago)
hey,
 The following patch adds support for the no_proxy envvar to the wget
applet. Most of the code is lifted directly from GNU's wget source
(with a few simplifications). This is my first contribution to
busybox and a rare attempt at C for me - let me know if I should
reduce wrap this code in a config option, etc.

Index: networking/wget.c
===================================================================
--- networking/wget.c	(revision 18847)
+++ networking/wget.c	(working copy)
@@ -83,6 +83,66 @@
 }
 #endif
 
+bool sufmatch (char **list, const char *what);
+bool sufmatch (char **list, const char *what)
+{
+	int i, j, k, lw;
+
+	lw = strlen (what);
+	for (i = 0; list[i]; i++) {
+		for (j = strlen (list[i]), k = lw; j >= 0 && k >= 0; j--, k--) 
+			if (tolower (list[i][j]) != tolower (what[k]))
+				break;
+		/* The domain must be first to reach to beginning.  */
+		if (j == -1)
+			return true;
+	}
+	return false;
+}
+
+char *strdupdelim (const char *beg, const char *end);
+char *strdupdelim (const char *beg, const char *end)
+{
+	char *res = xmalloc (end - beg + 1);
+	memcpy (res, beg, end - beg);
+	res[end - beg] = '\0';
+	return res;
+}
+
+/* Parse a string containing comma-separated elements, and return a
+   vector of char pointers with the elements.  Spaces following the
+   commas are ignored.  */
+char **sepstring (const char *s);
+char **sepstring (const char *s)
+{
+	char **res;
+	const char *p;
+	int i = 0;
+
+	if (!s || !*s)
+		return NULL;
+	res = NULL;
+	p = s;
+	while (*s) {
+		if (*s == ',') {
+			res = xrealloc (res, (i + 2) * sizeof (char *));
+			res[i] = strdupdelim (p, s);
+			res[++i] = NULL;
+			++s;
+			/* Skip the blanks following the ','.  */
+			while (*s == ' ')
+				++s;
+				p = s;
+		} else {
+			++s;
+		}
+	}
+	res = xrealloc (res, (i + 2) * sizeof (char *));
+	res[i] = strdupdelim (p, s);
+	res[i + 1] = NULL;
+	return res;
+}
+
 int wget_main(int argc, char **argv);
 int wget_main(int argc, char **argv)
 {
@@ -107,6 +167,8 @@
 	bool got_clen = 0;               /* got content-length: from server  */
 	int output_fd = -1;
 	bool use_proxy = 1;              /* Use proxies if env vars are set  */
+	char *tmp;
+	char **no_proxy = NULL;
 	const char *proxy_flag = "on";  /* Use proxies if env vars are set  */
 	const char *user_agent = "Wget";/* "User-Agent" header field        */
 	static const char * const keywords[] = {
@@ -174,6 +236,13 @@
 	server.host = target.host;
 	server.port = target.port;
 
+	tmp = getenv ("no_proxy");
+	if (tmp)
+		no_proxy = sepstring(tmp);
+
+	if (no_proxy && sufmatch(no_proxy, server.host))
+		use_proxy = 0;
+
 	/* Use the proxy if necessary */
 	if (use_proxy) {
 		proxy = getenv(target.is_ftp ? "ftp_proxy" : "http_proxy");


-- 
dann frazier
 
CD: 4ms