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).
Originally submitted here: http://article.gmane.org/gmane.linux.busybox/20296 The only outstanding feedback I have is the request to use argz if available. I certainly don't mind adding this if someone can tell me how to properly check for its availability. fyi, my goal with this patch is to enhance the debian installer to allow users who specify a proxy to disable proxy access for certain servers. For example, to use an internal mirror while still using the proxy to install security updates. --- busybox-1.6.0/networking/wget.c.orig 2007-06-18 20:09:36.000000000 +0100 +++ busybox-1.6.0/networking/wget.c 2007-06-21 00:36:21.000000000 +0100 @@ -84,6 +84,51 @@ } #endif +#if ENABLE_FEATURE_WGET_NOPROXY +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; +} +#endif + int wget_main(int argc, char **argv); int wget_main(int argc, char **argv) { @@ -108,6 +153,11 @@ bool got_clen = 0; /* got content-length: from server */ int output_fd = -1; bool use_proxy = 1; /* Use proxies if env vars are set */ +#if ENABLE_FEATURE_WGET_NOPROXY + int i, j; + char *tmp; + char **no_proxy = NULL; +#endif 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[] = { @@ -175,6 +225,22 @@ server.host = target.host; server.port = target.port; +#if ENABLE_FEATURE_WGET_NOPROXY + tmp = getenv ("no_proxy"); + if (tmp) + no_proxy = sepstring((const char *)str_tolower(tmp)); + + for (i = 0; no_proxy && no_proxy[i]; i++){ + j = strlen(server.host) - strlen(no_proxy[i]); + if (j < 0) + continue; + if (!strcmp(str_tolower(server.host + j), + no_proxy[i])) { + use_proxy = 0; + break; + } + } +#endif /* Use the proxy if necessary */ if (use_proxy) { proxy = getenv(target.is_ftp ? "ftp_proxy" : "http_proxy"); --- busybox-1.6.0/networking/Config.in.orig 2007-06-21 00:38:52.000000000 +0100 +++ busybox-1.6.0/networking/Config.in 2007-06-21 00:59:51.000000000 +0100 @@ -722,6 +722,15 @@ help Support long options for the wget applet. +config FEATURE_WGET_NOPROXY + bool "Support the no_proxy environment variable" + default n + depends on WGET && GETOPT_LONG + help + Support the no_proxy environment variable. This variable can be used + to specify a comma-separated list of host suffixes for which a proxy + should not be used. + config ZCIP bool "zcip" default n -- dann frazier ----- End forwarded message ----- -- dann frazier _______________________________________________ busybox mailing list [email protected] http://busybox.net/cgi-bin/mailman/listinfo/busybox
