]> sjero.net Git - wget/blobdiff - src/retr.c
Automated merge.
[wget] / src / retr.c
index e70f6e6e5433e02a88d1024e270e9347bbcad909..0aa95072777b370475705b657568c78ee51983c6 100644 (file)
@@ -51,7 +51,6 @@ as that of the covered work.  */
 #include "hash.h"
 #include "convert.h"
 #include "ptimer.h"
-#include "iri.h"
 #include "html-url.h"
 
 /* Total size of downloaded files.  Used to enforce quota.  */
@@ -630,12 +629,16 @@ retrieve_url (const char *origurl, char **file, char **newloc,
   u = url_parse (url, &up_error_code, iri);
   if (!u)
     {
-      logprintf (LOG_NOTQUIET, "%s: %s.\n", url, url_error (up_error_code));
+      char *error = url_error (url, up_error_code);
+      logprintf (LOG_NOTQUIET, "%s: %s.\n", url, error);
       xfree (url);
+      xfree (error);
       return URLERROR;
     }
 
-  printf ("[Retrieving %s with %s (UTF-8=%d)\n", url, iri->uri_encoding, iri->utf8_encode);
+  DEBUGP (("[IRI Retrieving %s with %s (UTF-8=%d)\n", quote (url),
+           iri->uri_encoding ? quote (iri->uri_encoding) : "None",
+           iri->utf8_encode));
 
   if (!refurl)
     refurl = opt.referer;
@@ -650,18 +653,19 @@ retrieve_url (const char *origurl, char **file, char **newloc,
   proxy = getproxy (u);
   if (proxy)
     {
-      /* sXXXav : could a proxy include a path ??? */
       struct iri *pi = iri_new ();
-      set_uri_encoding (pi, opt.locale);
+      set_uri_encoding (pi, opt.locale, true);
       pi->utf8_encode = false;
 
       /* Parse the proxy URL.  */
       proxy_url = url_parse (proxy, &up_error_code, NULL);
       if (!proxy_url)
         {
+          char *error = url_error (proxy, up_error_code);
           logprintf (LOG_NOTQUIET, _("Error parsing proxy URL %s: %s.\n"),
-                     proxy, url_error (up_error_code));
+                     proxy, error);
           xfree (url);
+          xfree (error);
           RESTORE_POST_DATA;
           return PROXERR;
         }
@@ -740,11 +744,13 @@ retrieve_url (const char *origurl, char **file, char **newloc,
       newloc_parsed = url_parse (mynewloc, &up_error_code, iri);
       if (!newloc_parsed)
         {
+          char *error = url_error (mynewloc, up_error_code);
           logprintf (LOG_NOTQUIET, "%s: %s.\n", escnonprint_uri (mynewloc),
-                     url_error (up_error_code));
+                     error);
           url_free (u);
           xfree (url);
           xfree (mynewloc);
+          xfree (error);
           RESTORE_POST_DATA;
           return result;
         }
@@ -788,7 +794,7 @@ retrieve_url (const char *origurl, char **file, char **newloc,
   if (!(*dt & RETROKF) && iri->utf8_encode)
     {
       iri->utf8_encode = false;
-      printf ("[Fallbacking to non-utf8 for `%s'\n", url);
+      DEBUGP (("[IRI Fallbacking to non-utf8 for %s\n", quote (url)));
       goto second_try;
     }
 
@@ -857,14 +863,23 @@ retrieve_from_file (const char *file, bool html, int *count)
   *count = 0;                  /* Reset the URL count.  */
 
   /* sXXXav : Assume filename and links in the file are in the locale */
+  set_uri_encoding (iri, opt.locale, true);
   set_content_encoding (iri, opt.locale);
 
   if (url_has_scheme (url))
     {
+      int dt;
       uerr_t status;
-      status = retrieve_url (url, &input_file, NULL, NULL, NULL, false, iri);
+
+      if (!opt.base_href)
+        opt.base_href = xstrdup (url);
+
+      status = retrieve_url (url, &input_file, NULL, NULL, &dt, false, iri);
       if (status != RETROK)
         return status;
+
+      if (dt & TEXTHTML)
+        html = true;
     }
   else
     input_file = (char *) file;
@@ -885,6 +900,10 @@ retrieve_from_file (const char *file, bool html, int *count)
           status = QUOTEXC;
           break;
         }
+
+      /* Reset UTF-8 encode status */
+      iri->utf8_encode = opt.enable_iri;
+
       if ((opt.recursive || opt.page_requisites)
           && (cur_url->url->scheme != SCHEME_FTP || getproxy (cur_url->url)))
         {
@@ -894,7 +913,7 @@ 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);
+          status = retrieve_tree (cur_url->url->url, iri);
 
           opt.follow_ftp = old_follow_ftp;
         }
@@ -919,6 +938,8 @@ Removing file due to --delete-after in retrieve_from_file():\n"));
   /* Free the linked list of URL-s.  */
   free_urlpos (url_list);
 
+  iri_free (iri);
+
   return status;
 }
 
@@ -1074,7 +1095,7 @@ url_uses_proxy (const char *url)
   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);
+  set_uri_encoding (i, opt.locale, true);
   u= url_parse (url, NULL, i);
   if (!u)
     return false;