]> sjero.net Git - wget/blobdiff - src/recur.c
Merge with mainline.
[wget] / src / recur.c
index 95581486b28e5e06a9d43ff023e73b7cf3e4a8ba..83a9b4ee84d5b155196263841ea37214fd3d014c 100644 (file)
@@ -161,7 +161,7 @@ url_dequeue (struct url_queue *queue, struct iri **i,
 \f
 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 +187,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;
 
@@ -199,7 +199,6 @@ retrieve_tree (const char *start_url, struct iri *pi)
   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, true);
-  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, false);
 
-          status = retrieve_url (url, &file, &redirected, referer, &dt,
-                                 false, i);
+          status = retrieve_url (url_parsed, url, &file, &redirected, referer,
+                                 &dt, false, i);
 
           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,7 @@ retrieve_tree (const char *start_url, struct iri *pi)
               xfree (url);
               url = redirected;
             }
+          url_free(url_parsed);
         }
 
       if (opt.spider)
@@ -468,8 +460,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,15 +676,14 @@ 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, false);
   assert (orig_parsed != NULL);
 
   new_parsed = url_parse (redirected, NULL, NULL, false);
@@ -706,7 +695,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);