]> sjero.net Git - wget/blobdiff - src/url.c
[svn] Remove K&R support.
[wget] / src / url.c
index fee88593ceb0f5405d7ed67613e1b28540ba991a..4aa51b5eb13fb5cfc58a9969880e41c3a69c4326 100644 (file)
--- a/src/url.c
+++ b/src/url.c
@@ -31,12 +31,7 @@ so, delete this exception statement from your version.  */
 
 #include <stdio.h>
 #include <stdlib.h>
-#ifdef HAVE_STRING_H
-# include <string.h>
-#else
-# include <strings.h>
-#endif
-#include <sys/types.h>
+#include <string.h>
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
 #endif
@@ -48,10 +43,6 @@ so, delete this exception statement from your version.  */
 #include "url.h"
 #include "host.h"  /* for is_valid_ipv6_address */
 
-#ifndef errno
-extern int errno;
-#endif
-
 struct scheme_data
 {
   const char *name;
@@ -75,7 +66,7 @@ static struct scheme_data supported_schemes[] =
 
 /* Forward declarations: */
 
-static int path_simplify PARAMS ((char *));
+static int path_simplify (char *);
 \f
 /* Support for escaping and unescaping of URL strings.  */
 
@@ -297,15 +288,14 @@ char_needs_escaping (const char *p)
 
        GET /abc%20def HTTP/1.0
 
-   It appears that the unsafe chars need to be quoted, for example
-   with url_escape.  But what if we're requested to download
+   It would appear that the unsafe chars need to be quoted, for
+   example with url_escape.  But what if we're requested to download
    `abc%20def'?  url_escape transforms "%" to "%25", which would leave
    us with `abc%2520def'.  This is incorrect -- since %-escapes are
    part of URL syntax, "%20" is the correct way to denote a literal
-   space on the Wget command line.  This leaves us in the conclusion
-   that in that case Wget should not call url_escape, but leave the
-   `%20' as is.  This is clearly contradictory, but it only gets
-   worse.
+   space on the Wget command line.  This leads to the conclusion that
+   in that case Wget should not call url_escape, but leave the `%20'
+   as is.  This is clearly contradictory, but it only gets worse.
 
    What if the requested URI is `abc%20 def'?  If we call url_escape,
    we end up with `/abc%2520%20def', which is almost certainly not
@@ -535,6 +525,12 @@ rewrite_shorthand_url (const char *url)
   if (p == url)
     return NULL;
 
+  /* If we're looking at "://", it means the URL uses a scheme we
+     don't support, which may include "https" when compiled without
+     SSL support.  Don't bogusly rewrite such URLs.  */
+  if (p[0] == ':' && p[1] == '/' && p[2] == '/')
+    return NULL;
+
   if (*p == ':')
     {
       const char *pp;
@@ -565,7 +561,7 @@ rewrite_shorthand_url (const char *url)
     }
 }
 \f
-static void split_path PARAMS ((const char *, char **, char **));
+static void split_path (const char *, char **, char **);
 
 /* Like strpbrk, with the exception that it returns the pointer to the
    terminating zero (end-of-string aka "eos") if no matching character
@@ -579,7 +575,7 @@ static void split_path PARAMS ((const char *, char **, char **));
    help because the check for literal accept is in the
    preprocessor.)  */
 
-#ifdef __GNUC__
+#if defined(__GNUC__) && __GNUC__ >= 3
 
 #define strpbrk_or_eos(s, accept) ({           \
   char *SOE_p = strpbrk (s, accept);           \
@@ -588,7 +584,7 @@ static void split_path PARAMS ((const char *, char **, char **));
   SOE_p;                                       \
 })
 
-#else  /* not __GNUC__ */
+#else  /* not __GNUC__ or old gcc */
 
 static inline char *
 strpbrk_or_eos (const char *s, const char *accept)
@@ -598,7 +594,7 @@ strpbrk_or_eos (const char *s, const char *accept)
     p = strchr (s, '\0');
   return p;
 }
-#endif /* not __GNUC__ */
+#endif /* not __GNUC__ or old gcc */
 
 /* Turn STR into lowercase; return non-zero if a character was
    actually changed. */
@@ -667,7 +663,7 @@ url_parse (const char *url, int *error)
   if (scheme == SCHEME_INVALID)
     {
       error_code = PE_UNSUPPORTED_SCHEME;
-      goto err;
+      goto error;
     }
 
   url_encoded = reencode_escapes (url);
@@ -705,7 +701,7 @@ url_parse (const char *url, int *error)
       if (!host_e)
        {
          error_code = PE_UNTERMINATED_IPV6_ADDRESS;
-         goto err;
+         goto error;
        }
 
 #ifdef ENABLE_IPV6
@@ -713,14 +709,14 @@ url_parse (const char *url, int *error)
       if (!is_valid_ipv6_address(host_b, host_e))
        {
          error_code = PE_INVALID_IPV6_ADDRESS;
-         goto err;
+         goto error;
        }
 
       /* Continue parsing after the closing ']'. */
       p = host_e + 1;
 #else
       error_code = PE_IPV6_NOT_SUPPORTED;
-      goto err;
+      goto error;
 #endif
     }
   else
@@ -732,7 +728,7 @@ url_parse (const char *url, int *error)
   if (host_b == host_e)
     {
       error_code = PE_EMPTY_HOST;
-      goto err;
+      goto error;
     }
 
   port = scheme_default_port (scheme);
@@ -757,7 +753,7 @@ url_parse (const char *url, int *error)
                  /* http://host:12randomgarbage/blah */
                  /*               ^                  */
                  error_code = PE_BAD_PORT_NUMBER;
-                 goto err;
+                 goto error;
                }
              port = 10 * port + (*pp - '0');
              /* Check for too large port numbers here, before we have
@@ -765,7 +761,7 @@ url_parse (const char *url, int *error)
              if (port > 65535)
                {
                  error_code = PE_BAD_PORT_NUMBER;
-                 goto err;
+                 goto error;
                }
            }
        }
@@ -824,7 +820,7 @@ url_parse (const char *url, int *error)
       if (!parse_credentials (uname_b, uname_e - 1, &user, &passwd))
        {
          error_code = PE_INVALID_USER_NAME;
-         goto err;
+         goto error;
        }
     }
 
@@ -875,11 +871,10 @@ url_parse (const char *url, int *error)
       else
        u->url = url_encoded;
     }
-  url_encoded = NULL;
 
   return u;
 
- err:
+ error:
   /* Cleanup in case of error: */
   if (url_encoded && url_encoded != url)
     xfree (url_encoded);
@@ -1068,7 +1063,7 @@ sync_path (struct url *u)
       *p++ = '/';
       memcpy (p, efile, filelen);
       p += filelen;
-      *p++ = '\0';
+      *p = '\0';
     }
 
   u->path = newpath;
@@ -1122,7 +1117,7 @@ url_free (struct url *url)
 }
 \f
 /* Create all the necessary directories for PATH (a file).  Calls
-   mkdirhier() internally.  */
+   make_directory internally.  */
 int
 mkalldirs (const char *path)
 {