]> sjero.net Git - wget/blobdiff - src/ftp.c
Duplicate string to circumvent eventual memory corruption.
[wget] / src / ftp.c
index 9f65cc340332957fed6968a2c7fd07b85a14fec5..d58d67dfe87ff107ab59ed0b9c65c76f34356bb3 100644 (file)
--- a/src/ftp.c
+++ b/src/ftp.c
@@ -1,6 +1,6 @@
 /* File Transfer Protocol support.
    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
-   2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+   2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
 
 This file is part of GNU Wget.
 
@@ -69,6 +69,7 @@ typedef struct
   struct url *proxy;            /* FTWK-style proxy */
 } ccon;
 
+extern int numurls;
 
 /* Look for regexp "( *[0-9]+ *byte" (literal parenthesis) anywhere in
    the string S, and return the number converted to wgint, if found, 0
@@ -1274,8 +1275,17 @@ ftp_loop_internal (struct url *u, struct fileinfo *f, ccon *con)
           con->csock = -1;
         }
       if (!opt.spider)
-        logprintf (LOG_VERBOSE, _("%s (%s) - %s saved [%s]\n\n"),
-                   tms, tmrate, quote (locf), number_to_static_string (len));
+        {
+          bool write_to_stdout = (opt.output_document && HYPHENP (opt.output_document));
+
+          logprintf (LOG_VERBOSE,
+                     write_to_stdout
+                     ? _("%s (%s) - written to stdout %s[%s]\n\n")
+                     : _("%s (%s) - %s saved [%s]\n\n"),
+                     tms, tmrate,
+                     write_to_stdout ? "" : quote (locf),
+                     number_to_static_string (len));
+        }
       if (!opt.verbose && !opt.quiet)
         {
           /* Need to hide the password from the URL.  The `if' is here
@@ -1295,7 +1305,7 @@ ftp_loop_internal (struct url *u, struct fileinfo *f, ccon *con)
                number of bytes and files downloaded. */
             {
               total_downloaded_bytes += len;
-              opt.numurls++;
+              numurls++;
             }
 
           /* Deletion of listing files is not controlled by --delete-after, but
@@ -1310,7 +1320,7 @@ ftp_loop_internal (struct url *u, struct fileinfo *f, ccon *con)
              for instance, may want to know how many bytes and files they've
              downloaded through it. */
           total_downloaded_bytes += len;
-          opt.numurls++;
+          numurls++;
 
           if (opt.delete_after)
             {
@@ -1360,8 +1370,9 @@ ftp_get_listing (struct url *u, ccon *con, struct fileinfo **f)
   xfree (uf);
   DEBUGP ((_("Using %s as listing tmp file.\n"), quote (lf)));
 
-  con->target = lf;
+  con->target = xstrdup (lf);
   err = ftp_loop_internal (u, NULL, con);
+  xfree (con->target);
   con->target = old_target;
 
   if (err == RETROK)
@@ -1580,16 +1591,8 @@ Already have correct symlink %s -> %s\n\n"),
           && dlthis
           && file_exists_p (con->target))
         {
-          /* #### This code repeats in http.c and ftp.c.  Move it to a
-             function!  */
           const char *fl = NULL;
-          if (opt.output_document)
-            {
-              if (output_stream_regular)
-                fl = opt.output_document;
-            }
-          else
-            fl = con->target;
+          set_local_file (&fl, con->target);
           if (fl)
             touch (fl, f->tstamp);
         }