X-Git-Url: http://sjero.net/git/?p=wget;a=blobdiff_plain;f=src%2Fretr.c;fp=src%2Fretr.c;h=0fd936d0d9f540061cf6274c8d869d19259ad823;hp=1d9d74782126dcd9e134a0f7e421e2edd903e384;hb=4f3dd6817348433eafde04a3c2946f43364de7ef;hpb=5d0073b8f290dee2e9bad3e83230f6b57dd06beb diff --git a/src/retr.c b/src/retr.c index 1d9d7478..0fd936d0 100644 --- a/src/retr.c +++ b/src/retr.c @@ -226,7 +226,8 @@ fd_read_body (int fd, FILE *out, wgint toread, wgint startpos, /* If we're skipping STARTPOS bytes, pass 0 as the INITIAL argument to progress_create because the indicator doesn't (yet) know about "skipping" data. */ - progress = progress_create (skip ? 0 : startpos, startpos + toread); + wgint start = skip ? 0 : startpos; + progress = progress_create (start, start + toread); progress_interactive = progress_interactive_p (progress); } @@ -596,15 +597,16 @@ static char *getproxy (struct url *); multiple points. */ uerr_t -retrieve_url (const char *origurl, char **file, char **newloc, - const char *refurl, int *dt, bool recursive, struct iri *iri) +retrieve_url (struct url * orig_parsed, const char *origurl, char **file, + char **newloc, const char *refurl, int *dt, bool recursive, + struct iri *iri) { uerr_t result; char *url; bool location_changed; int dummy; char *mynewloc, *proxy; - struct url *u, *proxy_url; + struct url *u = orig_parsed, *proxy_url; int up_error_code; /* url parse error code */ char *local_file; int redirection_count = 0; @@ -626,16 +628,6 @@ retrieve_url (const char *origurl, char **file, char **newloc, *file = NULL; second_try: - u = url_parse (url, &up_error_code, iri, true); - if (!u) - { - char *error = url_error (url, up_error_code); - logprintf (LOG_NOTQUIET, "%s: %s.\n", url, error); - xfree (url); - xfree (error); - return URLERROR; - } - DEBUGP (("[IRI Retrieving %s with %s (UTF-8=%d)\n", quote_n (0, url), iri->uri_encoding ? quote_n (1, iri->uri_encoding) : "None", iri->utf8_encode)); @@ -748,7 +740,10 @@ retrieve_url (const char *origurl, char **file, char **newloc, char *error = url_error (mynewloc, up_error_code); logprintf (LOG_NOTQUIET, "%s: %s.\n", escnonprint_uri (mynewloc), error); - url_free (u); + if (orig_parsed != u) + { + url_free (u); + } xfree (url); xfree (mynewloc); xfree (error); @@ -768,7 +763,10 @@ retrieve_url (const char *origurl, char **file, char **newloc, logprintf (LOG_NOTQUIET, _("%d redirections exceeded.\n"), opt.max_redirect); url_free (newloc_parsed); - url_free (u); + if (orig_parsed != u) + { + url_free (u); + } xfree (url); xfree (mynewloc); RESTORE_POST_DATA; @@ -777,7 +775,10 @@ retrieve_url (const char *origurl, char **file, char **newloc, xfree (url); url = mynewloc; - url_free (u); + if (orig_parsed != u) + { + url_free (u); + } u = newloc_parsed; /* If we're being redirected from POST, we don't want to POST @@ -823,7 +824,10 @@ retrieve_url (const char *origurl, char **file, char **newloc, else xfree_null (local_file); - url_free (u); + if (orig_parsed != u) + { + url_free (u); + } if (redirection_count) { @@ -869,13 +873,23 @@ retrieve_from_file (const char *file, bool html, int *count) if (url_has_scheme (url)) { - int dt; + int dt,url_err; uerr_t status; + struct url * url_parsed = url_parse(url, &url_err, NULL, true); + + if (!url_parsed) + { + char *error = url_error (url, url_err); + logprintf (LOG_NOTQUIET, "%s: %s.\n", url, error); + xfree (error); + return URLERROR; + } if (!opt.base_href) opt.base_href = xstrdup (url); - status = retrieve_url (url, &input_file, NULL, NULL, &dt, false, iri); + status = retrieve_url (url_parsed, url, &input_file, NULL, NULL, &dt, + false, iri); if (status != RETROK) return status; @@ -920,13 +934,13 @@ retrieve_from_file (const char *file, bool html, int *count) if (cur_url->url->scheme == SCHEME_FTP) opt.follow_ftp = 1; - status = retrieve_tree (cur_url->url->url, iri); + status = retrieve_tree (cur_url->url, iri); opt.follow_ftp = old_follow_ftp; } else - status = retrieve_url (cur_url->url->url, &filename, &new_file, NULL, - &dt, opt.recursive, iri); + status = retrieve_url (cur_url->url, cur_url->url->url, &filename, + &new_file, NULL, &dt, opt.recursive, iri); if (filename && opt.delete_after && file_exists_p (filename)) { @@ -1096,18 +1110,12 @@ getproxy (struct url *u) /* Returns true if URL would be downloaded through a proxy. */ bool -url_uses_proxy (const char *url) +url_uses_proxy (struct url * u) { bool ret; - struct url *u; - struct iri *i = iri_new(); - /* url was given in the command line, so use locale as encoding */ - set_uri_encoding (i, opt.locale, true); - u= url_parse (url, NULL, i, false); if (!u) return false; ret = getproxy (u) != NULL; - url_free (u); return ret; } @@ -1120,3 +1128,16 @@ no_proxy_match (const char *host, const char **no_proxy) else return sufmatch (no_proxy, host); } + +/* Set the file parameter to point to the local file string. */ +void +set_local_file (const char **file, const char *default_file) +{ + if (opt.output_document) + { + if (output_stream_regular) + *file = opt.output_document; + } + else + *file = default_file; +}