wget support for no_proxy env var
dann frazier
dannf at dannf.org
Thu Jun 21 00:15:32 UTC 2007
On Tue, Jun 19, 2007 at 10:30:55AM +0200, Bernhard Fischer wrote:
> On Mon, Jun 18, 2007 at 03:23:20PM -0600, dann frazier wrote:
> >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.
>
> Yes, please wrap that in a config option.
ok
> >+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;
> >+}
>
> This sounds alike index_in_substr_array(). Perhaps you can reuse this
> instead? (See also str_tolower())
I don't see a good way to use index_in_substr_array() since I only
care if the last part of the string matches. str_tolower() does come
in handy though, thanks for the suggestion.
Here's a new version of the patch with these changes:
--- 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
More information about the busybox
mailing list