]> sjero.net Git - wget/commitdiff
[svn] Committed my patches from <sxsbsw16sbu.fsf@florida.arsdigita.de>
authorhniksic <devnull@localhost>
Tue, 31 Oct 2000 19:25:32 +0000 (11:25 -0800)
committerhniksic <devnull@localhost>
Tue, 31 Oct 2000 19:25:32 +0000 (11:25 -0800)
and <sxsvgu824xk.fsf@florida.arsdigita.de>.

src/ChangeLog
src/ftp.c
src/http.c
src/init.c
src/retr.c
src/url.c
src/url.h

index 490dbd09575a282c2678a0a68f29cc6dffb7ba11..6392cc4198b886bb097b4a1af5aa6986f8fec576 100644 (file)
@@ -1,3 +1,20 @@
+2000-10-31  Hrvoje Niksic  <hniksic@arsdigita.com>
+
+       * ftp.c (getftp): Ditto.
+
+       * http.c (gethttp): Rewind the stream when retrying from scratch.
+
+2000-10-31  Hrvoje Niksic  <hniksic@arsdigita.com>
+
+       * retr.c (retrieve_url): Use url_concat() to handle relative
+       redirections instead of /ad hoc/ code.
+
+       * url.c (url_concat): New function encapsulating weird
+       construct().
+       (urllen_http_hack): New function.
+       (construct): When constructing new URLs, recognize that `?' does
+       not form part of the file name in HTTP.
+
 2000-10-13  Adrian Aichner  <adrian@xemacs.org>
 
        * retr.c: Add msec timing support for WINDOWS.
index ab70114b33220b00005bc22e428d730bbeed8005..7496a5aea914a418218a69f0d13031b28697c977 100644 (file)
--- a/src/ftp.c
+++ b/src/ftp.c
@@ -648,6 +648,15 @@ Error in server response, closing control connection.\n"));
       expected_bytes = ftp_expected_bytes (ftp_last_respline);
     } /* cmd & DO_LIST */
 
+  /* Some FTP servers return the total length of file after REST
+     command, others just return the remaining size. */
+  if (*len && restval && expected_bytes
+      && (expected_bytes == *len - restval))
+    {
+      DEBUGP (("Lying FTP server found, adjusting.\n"));
+      expected_bytes = *len;
+    }
+
   /* If no transmission was required, then everything is OK.  */
   if (!(cmd & (DO_LIST | DO_RETR)))
     return RETRFINISHED;
@@ -685,16 +694,16 @@ Error in server response, closing control connection.\n"));
        }
     }
   else
-    fp = opt.dfp;
-  
-  /* Some FTP servers return the total length of file after REST command,
-     others just return the remaining size. */  
-  if (*len && restval && expected_bytes
-      && (expected_bytes == *len - restval))
-  {
-    DEBUGP (("Lying FTP server found, adjusting.\n"));
-    expected_bytes = *len;
-  }
+    {
+      fp = opt.dfp;
+      if (!restval)
+       {
+         /* This will silently fail for streams that don't correspond
+            to regular files, but that's OK.  */
+         rewind (fp);
+         clearerr (fp);
+       }
+    }
 
   if (*len)
     {
index 59cfc04475014f451c1c17fc4af420d96deabc2d..24de9bb8f9d58a8d03329503ca00d54f97298fa7 100644 (file)
@@ -843,8 +843,17 @@ Accept: %s\r\n\
          return FOPENERR;
        }
     }
-  else                      /* opt.dfp */
-    fp = opt.dfp;
+  else                         /* opt.dfp */
+    {
+      fp = opt.dfp;
+      if (!hs->restval)
+       {
+         /* This will silently fail for streams that don't correspond
+            to regular files, but that's OK.  */
+         rewind (fp);
+         clearerr (fp);
+       }
+    }
 
   /* #### This confuses the code that checks for file size.  There
      should be some overhead information.  */
index 9e11944551dbd18cc2ead4e2175672627eccea9f..5b10cdcac6a26e2f44bac6bf36582f45dab5562c 100644 (file)
@@ -76,7 +76,6 @@ CMD_DECLARE (cmd_spec_dotstyle);
 CMD_DECLARE (cmd_spec_header);
 CMD_DECLARE (cmd_spec_htmlify);
 CMD_DECLARE (cmd_spec_mirror);
-CMD_DECLARE (cmd_spec_outputdocument);
 CMD_DECLARE (cmd_spec_recursive);
 CMD_DECLARE (cmd_spec_useragent);
 
@@ -139,7 +138,7 @@ static struct {
   { "noparent",                &opt.no_parent,         cmd_boolean },
   { "noproxy",         &opt.no_proxy,          cmd_vector },
   { "numtries",                &opt.ntry,              cmd_number_inf },/* deprecated*/
-  { "outputdocument",  NULL,                   cmd_spec_outputdocument },
+  { "outputdocument",  &opt.output_document,   cmd_string },
   { "pagerequisites",  &opt.page_requisites,   cmd_boolean },
   { "passiveftp",      &opt.ftp_pasv,          cmd_lockable_boolean },
   { "passwd",          &opt.ftp_pass,          cmd_string },
@@ -915,15 +914,6 @@ cmd_spec_mirror (const char *com, const char *val, void *closure)
   return 1;
 }
 
-static int
-cmd_spec_outputdocument (const char *com, const char *val, void *closure)
-{
-  FREE_MAYBE (opt.output_document);
-  opt.output_document = xstrdup (val);
-  opt.ntry = 1;
-  return 1;
-}
-
 static int
 cmd_spec_recursive (const char *com, const char *val, void *closure)
 {
index 92e787fb7015aefe4287eb406bb3b2ae75f8911b..eceacfe88e7cbe8803352c1a940b120e41096069 100644 (file)
@@ -337,9 +337,7 @@ retrieve_url (const char *origurl, char **file, char **newloc,
 
  again:
   u = newurl ();
-  /* Parse the URL.  RFC2068 requires `Location' to contain an
-     absoluteURI, but many sites break this requirement.  #### We
-     should be liberal and accept a relative location, too.  */
+  /* Parse the URL. */
   result = parseurl (url, u, already_redirected);
   if (result != URLOK)
     {
@@ -426,40 +424,26 @@ retrieve_url (const char *origurl, char **file, char **newloc,
   location_changed = (result == NEWLOCATION);
   if (location_changed)
     {
-      /* Check for redirection to oneself.  */
+      if (mynewloc)
+       {
+         /* The HTTP specs only allow absolute URLs to appear in
+            redirects, but a ton of boneheaded webservers and CGIs
+            out there break the rules and use relative URLs, and
+            popular browsers are lenient about this, so wget should
+            be too. */
+         char *construced_newloc = url_concat (url, mynewloc);
+         free (mynewloc);
+         mynewloc = construced_newloc;
+       }
+      /* Check for redirection to back to itself.  */
       if (url_equal (url, mynewloc))
        {
          logprintf (LOG_NOTQUIET, _("%s: Redirection to itself.\n"),
                     mynewloc);
          return WRONGCODE;
        }
-      if (mynewloc)
-       {
-         /* The HTTP specs only allow absolute URLs to appear in redirects, but
-            a ton of boneheaded webservers and CGIs out there break the rules
-            and use relative URLs, and popular browsers are lenient about this,
-            so wget should be too. */
-         if (strstr(mynewloc, "://") == NULL)
-           /* Doesn't look like an absolute URL (this check will incorrectly
-              think that rare relative URLs containing "://" later in the
-              string are absolute). */
-           {
-             char *temp = malloc(strlen(url) + strlen(mynewloc) + 1);
-             
-             if (mynewloc[0] == '/')
-               /* "Hostless absolute" URL.  Convert to absolute. */
-               sprintf(temp,"%s%s", url, mynewloc);
-             else
-               /* Relative URL.  Convert to absolute. */
-               sprintf(temp,"%s/%s", url, mynewloc);
-
-             free(mynewloc);
-             mynewloc = temp;
-           }
-         
-         free (url);
-         url = mynewloc;
-       }
+      free (url);
+      url = mynewloc;
       freeurl (u, 1);
       already_redirected = 1;
       goto again;
index b6220e3db248e4ab85f4af3bac20f97d54c2d08c..a0747a566d0b07156a9af5007310f20ad0870f46 100644 (file)
--- a/src/url.c
+++ b/src/url.c
@@ -1266,6 +1266,23 @@ url_filename (const struct urlinfo *u)
   return name;
 }
 
+/* Like strlen(), except if `?' is present in the URL and its protocol
+   is HTTP, act as if `?' is the end of the string.  Needed for the
+   correct implementation of `construct' below, at least until we code
+   up proper parsing of URLs.  */
+static int
+urllen_http_hack (const char *url)
+{
+  if ((!strncmp (url, "http://", 7)
+       || !strncmp (url, "https://", 7)))
+    {
+      const char *q = strchr (url, '?');
+      if (q)
+       return q - url;
+    }
+  return strlen (url);
+}
+
 /* Construct an absolute URL, given a (possibly) relative one.  This
    is more tricky than it might seem, but it works.  */
 static char *
@@ -1279,12 +1296,12 @@ construct (const char *url, const char *sub, int subsize, int no_proto)
 
       if (*sub != '/')
        {
-         for (i = strlen (url); i && url[i] != '/'; i--);
+         for (i = urllen_http_hack (url); i && url[i] != '/'; i--);
          if (!i || (url[i] == url[i - 1]))
            {
-             int l = strlen (url);
+             int l = urllen_http_hack (url);
              char *t = (char *)alloca (l + 2);
-             strcpy (t, url);
+             memcpy (t, url, l);
              t[l] = '/';
              t[l + 1] = '\0';
              url = t;
@@ -1312,7 +1329,7 @@ construct (const char *url, const char *sub, int subsize, int no_proto)
          while (fl);
          if (!url[i])
            {
-             int l = strlen (url);
+             int l = urllen_http_hack (url);
              char *t = (char *)alloca (l + 2);
              strcpy (t, url);
              t[l] = '/';
@@ -1334,6 +1351,13 @@ construct (const char *url, const char *sub, int subsize, int no_proto)
     }
   return constr;
 }
+
+/* Like the function above, but with a saner caller interface. */
+char *
+url_concat (const char *base_url, const char *new_url)
+{
+  return construct (base_url, new_url, strlen (new_url), !has_proto (new_url));
+}
 \f
 /* Optimize URL by host, destructively replacing u->host with realhost
    (u->host).  Do this regardless of opt.simple_check.  */
index 02ea9ca54fbe9d11368e042b44260a9ee8a3d25b..0f55ec35b803d81ae97556aaaa0103f5861eb461 100644 (file)
--- a/src/url.h
+++ b/src/url.h
@@ -98,6 +98,8 @@ urlpos *get_urls_file PARAMS ((const char *));
 urlpos *get_urls_html PARAMS ((const char *, const char *, int, int));
 void free_urlpos PARAMS ((urlpos *));
 
+char *url_concat PARAMS ((const char *, const char *));
+
 void rotate_backups PARAMS ((const char *));
 int mkalldirs PARAMS ((const char *));
 char *url_filename PARAMS ((const struct urlinfo *));