From 10da871ac441fe99f5d20dd8f1e9ec3797c0a5a2 Mon Sep 17 00:00:00 2001 From: micah Date: Sat, 28 Jul 2007 19:37:14 -0700 Subject: [PATCH] [svn] Merging fix #20499: MAX_REDIRECTIONS should be configurable. --- doc/ChangeLog | 4 ++++ doc/wget.texi | 7 +++++++ src/ChangeLog | 17 +++++++++++++++++ src/init.c | 2 ++ src/main.c | 3 +++ src/options.h | 4 +++- src/retr.c | 10 ++-------- 7 files changed, 38 insertions(+), 9 deletions(-) diff --git a/doc/ChangeLog b/doc/ChangeLog index 0ac5628a..3b16b9f3 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,7 @@ +2007-07-28 Micah Cowan + + * wget.texi : Added --max-redirect option. + 2007-07-05 Micah Cowan * fdl.texi: diff --git a/doc/wget.texi b/doc/wget.texi index bd4c3916..fcc5cd60 100644 --- a/doc/wget.texi +++ b/doc/wget.texi @@ -1239,6 +1239,13 @@ wget --header="Host: foo.bar" http://localhost/ In versions of Wget prior to 1.10 such use of @samp{--header} caused sending of duplicate headers. +@cindex redirect +@item --max-redirect=@var{number} +Specifies the maximum number of redirections to follow for a resource. +The default is 20, which is usually far more than necessary. However, on +those occasions where you want to allow more (or fewer), this is the +option to use. + @cindex proxy user @cindex proxy password @cindex proxy authentication diff --git a/src/ChangeLog b/src/ChangeLog index 69faa672..4dc66b1f 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,20 @@ +2007-07-28 Micah Cowan + + * options.h, init.c, retr.c, main.c: renamed opt maxredirect + field to max_redirect, for improved consistency. + * init.c: changed max_redirect parser from cmd_number_inf to + cmd_number, as infinite redirects may not be appropriate. + Alternatively, if cmd_number_inf should be used, then + opt.max_redirect's value should be checked a bit differently in + retr.c, to allow for the "infinite" meaning of zero. + +2007-07-16 Joshua David Williams + + * options.h: added maxredirect to options struct + * init.c: added maxredirect to list of variables + * retr.c (retrieve_url): replaced MAX_REDIRECTIONS with opt.maxredirect + * main.c: added option --max-redirect + 2007-07-16 Joshua David Williams * test.h: tests made more verbose; now displays the name diff --git a/src/init.c b/src/init.c index 6ad97f36..7f811563 100644 --- a/src/init.c +++ b/src/init.c @@ -182,6 +182,7 @@ static struct { { "loadcookies", &opt.cookies_input, cmd_file }, { "logfile", &opt.lfilename, cmd_file }, { "login", &opt.ftp_user, cmd_string },/* deprecated*/ + { "maxredirect", &opt.max_redirect, cmd_number }, { "mirror", NULL, cmd_spec_mirror }, { "netrc", &opt.netrc, cmd_boolean }, { "noclobber", &opt.noclobber, cmd_boolean }, @@ -321,6 +322,7 @@ defaults (void) opt.restrict_files_case = restrict_no_case_restriction; opt.content_disposition = true; + opt.max_redirect = 20; } /* Return the user's home directory (strdup-ed), or NULL if none is diff --git a/src/main.c b/src/main.c index 9a30bbf7..ab1786d7 100644 --- a/src/main.c +++ b/src/main.c @@ -189,6 +189,7 @@ static struct cmdline_option option_data[] = { "level", 'l', OPT_VALUE, "reclevel", -1 }, { "limit-rate", 0, OPT_VALUE, "limitrate", -1 }, { "load-cookies", 0, OPT_VALUE, "loadcookies", -1 }, + { "max-redirect", 0, OPT_VALUE, "maxredirect", -1 }, { "mirror", 'm', OPT_BOOLEAN, "mirror", -1 }, { "no", 'n', OPT__NO, NULL, required_argument }, { "no-clobber", 0, OPT_BOOLEAN, "noclobber", -1 }, @@ -496,6 +497,8 @@ HTTP options:\n"), --ignore-length ignore `Content-Length' header field.\n"), N_("\ --header=STRING insert STRING among the headers.\n"), + N_("\ + --max-redirect maximum redirections allowed per page.\n"), N_("\ --proxy-user=USER set USER as proxy username.\n"), N_("\ diff --git a/src/options.h b/src/options.h index 0267e376..7fda95e3 100644 --- a/src/options.h +++ b/src/options.h @@ -36,8 +36,10 @@ struct options bool background; /* Whether we should work in background. */ bool ignore_length; /* Do we heed content-length at all? */ bool recursive; /* Are we recursive? */ - bool spanhost; /* Do we span across hosts in + bool spanhost; /* Do we span across hosts in recursion? */ + int max_redirect; /* Maximum number of times we'll allow + a page to redirect. */ bool relative_only; /* Follow only relative links. */ bool no_parent; /* Restrict access to the parent directory. */ diff --git a/src/retr.c b/src/retr.c index c531be59..92494fc9 100644 --- a/src/retr.c +++ b/src/retr.c @@ -567,12 +567,6 @@ calc_rate (wgint bytes, double secs, int *units) return dlrate; } -/* Maximum number of allowed redirections. 20 was chosen as a - "reasonable" value, which is low enough to not cause havoc, yet - high enough to guarantee that normal retrievals will not be hurt by - the check. */ - -#define MAX_REDIRECTIONS 20 #define SUSPEND_POST_DATA do { \ post_data_suspended = true; \ @@ -746,10 +740,10 @@ retrieve_url (const char *origurl, char **file, char **newloc, mynewloc = xstrdup (newloc_parsed->url); /* Check for max. number of redirections. */ - if (++redirection_count > MAX_REDIRECTIONS) + if (++redirection_count > opt.max_redirect) { logprintf (LOG_NOTQUIET, _("%d redirections exceeded.\n"), - MAX_REDIRECTIONS); + opt.max_redirect); url_free (newloc_parsed); url_free (u); xfree (url); -- 2.39.2