X-Git-Url: http://sjero.net/git/?p=wget;a=blobdiff_plain;f=src%2Frecur.c;h=00e7603163c1b2be1998c0f7dc74339af35253fc;hp=786824583c1553fd66254ac3c4fae055f8799e56;hb=2f6aa1d7417df1dfc58597777686fbd77179b9fd;hpb=26a3eea8e2f42c621ce6c40a93acf5ff1cd12220 diff --git a/src/recur.c b/src/recur.c index 78682458..00e76031 100644 --- a/src/recur.c +++ b/src/recur.c @@ -1,6 +1,7 @@ /* Handling of recursive HTTP retrieving. - Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, - 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. + Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, + 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, + Inc. This file is part of GNU Wget. @@ -33,9 +34,7 @@ as that of the covered work. */ #include #include #include -#ifdef HAVE_UNISTD_H -# include -#endif /* HAVE_UNISTD_H */ +#include #include #include @@ -111,7 +110,8 @@ url_enqueue (struct url_queue *queue, struct iri *i, if (queue->count > queue->maxcount) queue->maxcount = queue->count; - DEBUGP (("Enqueuing %s at depth %d\n", url, depth)); + DEBUGP (("Enqueuing %s at depth %d\n", + quotearg_n_style (0, escape_quoting_style, url), depth)); DEBUGP (("Queue count %d, maxcount %d.\n", queue->count, queue->maxcount)); if (i) @@ -152,7 +152,8 @@ url_dequeue (struct url_queue *queue, struct iri **i, --queue->count; - DEBUGP (("Dequeuing %s at depth %d\n", qel->url, qel->depth)); + DEBUGP (("Dequeuing %s at depth %d\n", + quotearg_n_style (0, escape_quoting_style, qel->url), qel->depth)); DEBUGP (("Queue count %d, maxcount %d.\n", queue->count, queue->maxcount)); xfree (qel); @@ -161,7 +162,7 @@ url_dequeue (struct url_queue *queue, struct iri **i, static bool download_child_p (const struct urlpos *, struct url *, int, struct url *, struct hash_table *, struct iri *); -static bool descend_redirect_p (const char *, const char *, int, +static bool descend_redirect_p (const char *, struct url *, int, struct url *, struct hash_table *, struct iri *); @@ -187,7 +188,7 @@ static bool descend_redirect_p (const char *, const char *, int, options, add it to the queue. */ uerr_t -retrieve_tree (const char *start_url, struct iri *pi) +retrieve_tree (struct url *start_url_parsed, struct iri *pi) { uerr_t status = RETROK; @@ -198,8 +199,6 @@ retrieve_tree (const char *start_url, struct iri *pi) the queue, but haven't been downloaded yet. */ struct hash_table *blacklist; - int up_error_code; - struct url *start_url_parsed; struct iri *i = iri_new (); #define COPYSTR(x) (x) ? xstrdup(x) : NULL; @@ -214,15 +213,6 @@ retrieve_tree (const char *start_url, struct iri *pi) set_uri_encoding (i, opt.locale, true); #undef COPYSTR - start_url_parsed = url_parse (start_url, &up_error_code, i); - if (!start_url_parsed) - { - char *error = url_error (start_url, up_error_code); - logprintf (LOG_NOTQUIET, "%s: %s.\n", start_url, error); - xfree (error); - return URLERROR; - } - queue = url_queue_new (); blacklist = make_string_hash_table (0); @@ -286,11 +276,12 @@ retrieve_tree (const char *start_url, struct iri *pi) } else { - int dt = 0; + int dt = 0, url_err; char *redirected = NULL; + struct url *url_parsed = url_parse (url, &url_err, i, true); - status = retrieve_url (url, &file, &redirected, referer, &dt, - false, i); + status = retrieve_url (url_parsed, url, &file, &redirected, referer, + &dt, false, i, true); if (html_allowed && file && status == RETROK && (dt & RETROKF) && (dt & TEXTHTML)) @@ -317,7 +308,7 @@ retrieve_tree (const char *start_url, struct iri *pi) want to follow it. */ if (descend) { - if (!descend_redirect_p (redirected, url, depth, + if (!descend_redirect_p (redirected, url_parsed, depth, start_url_parsed, blacklist, i)) descend = false; else @@ -329,6 +320,12 @@ retrieve_tree (const char *start_url, struct iri *pi) xfree (url); url = redirected; } + else + { + xfree (url); + url = xstrdup (url_parsed->url); + } + url_free(url_parsed); } if (opt.spider) @@ -381,7 +378,7 @@ retrieve_tree (const char *start_url, struct iri *pi) if (children) { struct urlpos *child = children; - struct url *url_parsed = url_parse (url, NULL, i); + struct url *url_parsed = url_parse (url, NULL, i, true); struct iri *ci; char *referer_url = url; bool strip_auth = (url_parsed != NULL @@ -468,8 +465,6 @@ retrieve_tree (const char *start_url, struct iri *pi) } url_queue_delete (queue); - if (start_url_parsed) - url_free (start_url_parsed); string_set_free (blacklist); if (opt.quota && total_downloaded_bytes > opt.quota) @@ -686,18 +681,17 @@ download_child_p (const struct urlpos *upos, struct url *parent, int depth, it is merely a simple-minded wrapper around download_child_p. */ static bool -descend_redirect_p (const char *redirected, const char *original, int depth, +descend_redirect_p (const char *redirected, struct url *orig_parsed, int depth, struct url *start_url_parsed, struct hash_table *blacklist, struct iri *iri) { - struct url *orig_parsed, *new_parsed; + struct url *new_parsed; struct urlpos *upos; bool success; - orig_parsed = url_parse (original, NULL, NULL); assert (orig_parsed != NULL); - new_parsed = url_parse (redirected, NULL, NULL); + new_parsed = url_parse (redirected, NULL, NULL, false); assert (new_parsed != NULL); upos = xnew0 (struct urlpos); @@ -706,7 +700,6 @@ descend_redirect_p (const char *redirected, const char *original, int depth, success = download_child_p (upos, orig_parsed, depth, start_url_parsed, blacklist, iri); - url_free (orig_parsed); url_free (new_parsed); xfree (upos);