]> sjero.net Git - wget/commitdiff
Make -i work with FTP.
authorSteven Schubiger <stsc@member.fsf.org>
Mon, 1 Mar 2010 23:00:17 +0000 (00:00 +0100)
committerSteven Schubiger <stsc@member.fsf.org>
Mon, 1 Mar 2010 23:00:17 +0000 (00:00 +0100)
src/ChangeLog
src/ftp.c
src/ftp.h
src/retr.c
tests/ChangeLog
tests/Makefile.am
tests/Test-i-ftp.px [new file with mode: 0755]
tests/run-px

index be1eea4bd76be53c40111fc88b5679e392272dab..1b8cb04dc042dba9baf9a87a63bf9a062abb2d6c 100644 (file)
@@ -1,3 +1,15 @@
+2010-03-01  Steven Schubiger  <stsc@member.fsf.org>
+
+       * retr.c (retrieve_url): Retrieve the local filename from ftp_loop. 
+       (retrieve_from_file): Return if there's no input file.
+
+       * ftp.c (ftp_loop_internal): Duplicate the local filename into
+       retrieve_url's scope when a valid reference is being passed.
+       (ftp_loop): Call ftp_loop_internal here with passing a
+       reference to the local filename, elsewhere with NULL.
+
+       * ftp.h: Adjust declaration of ftp_loop.
+       
 2010-01-27  Paul Townsend  <aab@purdue.edu>  (tiny change)
 
        * retr.c (fd_read_body): Be sure to measure timer when time has
index d141b024a601aa2e51db1f707db83269a3e5bf1b..dfe2354869f3eaee26da9d038d72cb30718f6752 100644 (file)
--- a/src/ftp.c
+++ b/src/ftp.c
@@ -1348,7 +1348,7 @@ Error in server response, closing control connection.\n"));
    This loop either gets commands from con, or (if ON_YOUR_OWN is
    set), makes them up to retrieve the file given by the URL.  */
 static uerr_t
-ftp_loop_internal (struct url *u, struct fileinfo *f, ccon *con)
+ftp_loop_internal (struct url *u, struct fileinfo *f, ccon *con, char **local_file)
 {
   int count, orig_lp;
   wgint restval, len = 0, qtyread = 0;
@@ -1576,6 +1576,10 @@ Removing file due to --delete-after in ftp_loop_internal():\n"));
         con->cmd |= LEAVE_PENDING;
       else
         con->cmd &= ~LEAVE_PENDING;
+
+      if (local_file)
+        *local_file = xstrdup (locf);
+
       return RETROK;
     } while (!opt.ntry || (count < opt.ntry));
 
@@ -1611,7 +1615,7 @@ ftp_get_listing (struct url *u, ccon *con, struct fileinfo **f)
 
   con->target = xstrdup (lf);
   xfree (lf);
-  err = ftp_loop_internal (u, NULL, con);
+  err = ftp_loop_internal (u, NULL, con, NULL);
   lf = xstrdup (con->target);
   xfree (con->target);
   con->target = old_target;
@@ -1806,7 +1810,7 @@ Already have correct symlink %s -> %s\n\n"),
           else                /* opt.retr_symlinks */
             {
               if (dlthis)
-                err = ftp_loop_internal (u, f, con);
+                err = ftp_loop_internal (u, f, con, NULL);
             } /* opt.retr_symlinks */
           break;
         case FT_DIRECTORY:
@@ -1817,7 +1821,7 @@ Already have correct symlink %s -> %s\n\n"),
         case FT_PLAINFILE:
           /* Call the retrieve loop.  */
           if (dlthis)
-            err = ftp_loop_internal (u, f, con);
+            err = ftp_loop_internal (u, f, con, NULL);
           break;
         case FT_UNKNOWN:
           logprintf (LOG_NOTQUIET, _("%s: unknown/unsupported file type.\n"),
@@ -2096,7 +2100,7 @@ ftp_retrieve_glob (struct url *u, ccon *con, int action)
         {
           /* Let's try retrieving it anyway.  */
           con->st |= ON_YOUR_OWN;
-          res = ftp_loop_internal (u, NULL, con);
+          res = ftp_loop_internal (u, NULL, con, NULL);
           return res;
         }
 
@@ -2117,7 +2121,8 @@ ftp_retrieve_glob (struct url *u, ccon *con, int action)
    of URL.  Inherently, its capabilities are limited on what can be
    encoded into a URL.  */
 uerr_t
-ftp_loop (struct url *u, int *dt, struct url *proxy, bool recursive, bool glob)
+ftp_loop (struct url *u, char **local_file, int *dt, struct url *proxy, 
+          bool recursive, bool glob)
 {
   ccon con;                     /* FTP connection */
   uerr_t res;
@@ -2196,7 +2201,7 @@ ftp_loop (struct url *u, int *dt, struct url *proxy, bool recursive, bool glob)
                                    ispattern ? GLOB_GLOBALL : GLOB_GETONE);
         }
       else
-        res = ftp_loop_internal (u, NULL, &con);
+        res = ftp_loop_internal (u, NULL, &con, local_file);
     }
   if (res == FTPOK)
     res = RETROK;
index a93c1371cfaa447cc463a8dff4d64c11f888ad28..c0ee354a9a5c3dde9b2e3afbd9723856dbe40610 100644 (file)
--- a/src/ftp.h
+++ b/src/ftp.h
@@ -120,7 +120,7 @@ enum wget_ftp_fstatus
 };
 
 struct fileinfo *ftp_parse_ls (const char *, const enum stype);
-uerr_t ftp_loop (struct url *, int *, struct url *, bool, bool);
+uerr_t ftp_loop (struct url *, char **, int *, struct url *, bool, bool);
 
 uerr_t ftp_index (const char *, struct url *, struct fileinfo *);
 
index c9cec0fc60001520b14d8c62c604b2e449e29dfa..ebcc3c20ae9f0eacb5e13958830f0f1ebf1b43c7 100644 (file)
@@ -700,7 +700,7 @@ retrieve_url (struct url * orig_parsed, const char *origurl, char **file,
       if (redirection_count)
         oldrec = glob = false;
 
-      result = ftp_loop (u, dt, proxy_url, recursive, glob);
+      result = ftp_loop (u, &local_file, dt, proxy_url, recursive, glob);
       recursive = oldrec;
 
       /* There is a possibility of having HTTP being redirected to
@@ -918,7 +918,9 @@ retrieve_from_file (const char *file, bool html, int *count)
 
       status = retrieve_url (url_parsed, url, &input_file, NULL, NULL, &dt,
                              false, iri, true);
-      if (status != RETROK)
+      url_free (url_parsed);
+
+      if (!input_file || (status != RETROK))
         return status;
 
       if (dt & TEXTHTML)
index 17624f0d0f5d9335eb7565e047f259829ea196cd..09b0fe5857e166a627a2a2870f7c615a7a387415 100644 (file)
@@ -1,3 +1,8 @@
+2010-03-01  Steven Schubiger  <stsc@member.fsf.org>
+
+       * Test-i-ftp.px: Test --input-file in conjunction with FTP.
+       * run-px, Makefile.am (EXTRA_DIST): Added Test-i-ftp.px.
+
 2010-02-26  Steven Schubiger  <stsc@member.fsf.org>
 
        * Test-i-http.px: Test --input-file in conjunction with HTTP.
index e002b3210743fabb068854864c2b01490935858a..e83b03a8c1b4d650b821ef5f70b08839db62fd90 100644 (file)
@@ -84,6 +84,7 @@ EXTRA_DIST = FTPServer.pm FTPTest.pm HTTPServer.pm HTTPTest.pm \
              Test-HTTP-Content-Disposition-1.px \
              Test-HTTP-Content-Disposition-2.px \
              Test-HTTP-Content-Disposition.px \
+             Test-i-ftp.px \
              Test-i-http.px \
              Test-idn-headers.px \
              Test-idn-meta.px \
diff --git a/tests/Test-i-ftp.px b/tests/Test-i-ftp.px
new file mode 100755 (executable)
index 0000000..1d3bc1c
--- /dev/null
@@ -0,0 +1,80 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use FTPTest;
+
+
+###############################################################################
+
+my $urls = <<EOF;
+ftp://localhost:{{port}}/site1.html
+ftp://localhost:{{port}}/site2.html
+EOF
+
+my $site1 = <<EOF;
+<html>
+  <head>
+    <title>Site 1</title>
+  </head>
+  <body>
+    <p>Nunc eu ligula sed mauris sollicitudin scelerisque. Suspendisse viverra, dolor.</p>
+  </body>
+</html>
+EOF
+
+my $site2 = <<EOF;
+<html>
+  <head>
+    <title>Site 2</title>
+  </head>
+  <body>
+    <p>Suspendisse potenti. Phasellus et magna est, quis consectetur ligula. Integer.</p>
+  </body>
+</html>
+EOF
+
+foreach ($urls, $site1, $site2) {
+    s/\n/\r\n/g;
+}
+
+my %urls = (
+    '/urls.txt' => {
+        content => $urls,
+    },
+    '/site1.html' => {
+        content => $site1,
+    },
+    '/site2.html' => {
+        content => $site2,
+    },
+);
+
+my $cmdline = $WgetTest::WGETPATH . " -i ftp://localhost:{{port}}/urls.txt";
+
+my $expected_error_code = 0;
+
+my %expected_downloaded_files = (
+    'urls.txt' => {
+        content => $urls,
+    },
+    'site1.html' => {
+        content => $site1,
+    },
+    'site2.html' => {
+        content => $site2,
+    },
+);
+
+###############################################################################
+
+my $the_test = FTPTest->new (name => "Test-i-ftp",
+                             input => \%urls,
+                             cmdline => $cmdline,
+                             errcode => $expected_error_code,
+                             output => \%expected_downloaded_files);
+exit $the_test->run();
+
+# vim: et ts=4 sw=4
+
index 6c31dc5e24fd7bc3165b9cfcb86ac2a0b605d67d..64dca1a2d391608a4b56dede9a6e3682b7f59987 100755 (executable)
@@ -37,6 +37,7 @@ my @tests = (
     'Test-HTTP-Content-Disposition-1.px',
     'Test-HTTP-Content-Disposition-2.px',
     'Test-HTTP-Content-Disposition.px',
+    'Test-i-ftp.px',
     'Test-i-http.px',
     'Test-idn-headers.px',
     'Test-idn-meta.px',