]> sjero.net Git - wget/blobdiff - src/http.c
[svn] Minor fixes prompted by `lint'.
[wget] / src / http.c
index a886f4883834d39e6533cc29d7a576173730a62e..95bb31eacccbea7d7ab8b0ad987382471330c124 100644 (file)
@@ -44,12 +44,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 # endif
 #endif
 
-#ifdef WINDOWS
-# include <winsock.h>
-#else
-# include <netdb.h>            /* for h_errno */
-#endif
-
 #include "wget.h"
 #include "utils.h"
 #include "url.h"
@@ -64,17 +58,15 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 # include "gen_sslfunc.h"
 #endif /* HAVE_SSL */
 #include "cookies.h"
+#ifdef USE_DIGEST
+# include "gen-md5.h"
+#endif
 
 extern char *version_string;
 
 #ifndef errno
 extern int errno;
 #endif
-#ifndef h_errno
-# ifndef __CYGWIN__
-extern int h_errno;
-# endif
-#endif
 \f
 static int cookies_loaded_p;
 
@@ -202,6 +194,10 @@ http_process_range (const char *hdr, void *arg)
   if (!strncasecmp (hdr, "bytes", 5))
     {
       hdr += 5;
+      /* "JavaWebServer/1.1.1" sends "bytes: x-y/z", contrary to the
+        HTTP spec. */
+      if (*hdr == ':')
+       ++hdr;
       hdr += skip_lws (hdr);
       if (!*hdr)
        return 0;
@@ -367,6 +363,15 @@ register_persistent (const char *host, unsigned short port, int fd
   DEBUGP (("Registered fd %d for persistent reuse.\n", fd));
 }
 
+#ifdef HAVE_SSL
+# define SHUTDOWN_SSL(ssl) do {                \
+  if (ssl)                             \
+    shutdown_ssl (ssl);                        \
+} while (0)
+#else
+# define SHUTDOWN_SSL(ssl) 
+#endif
+
 /* Return non-zero if a persistent connection is available for
    connecting to HOST:PORT.  */
 
@@ -422,21 +427,16 @@ persistent_available_p (const char *host, unsigned short port
          let's invalidate the persistent connection before returning
          0.  */
       CLOSE (pc_last_fd);
+#ifdef HAVE_SSL
+      SHUTDOWN_SSL (pc_last_ssl);
+      pc_last_ssl = NULL;
+#endif
       invalidate_persistent ();
       return 0;
     }
   return 1;
 }
 
-#ifdef HAVE_SSL
-# define SHUTDOWN_SSL(ssl) do {                \
-  if (ssl)                             \
-    shutdown_ssl (ssl);                        \
-} while (0)
-#else
-# define SHUTDOWN_SSL(ssl) 
-#endif
-
 /* The idea behind these two CLOSE macros is to distinguish between
    two cases: one when the job we've been doing is finished, and we
    want to close the connection and leave, and two when something is
@@ -546,7 +546,6 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy)
   static SSL_CTX *ssl_ctx = NULL;
   SSL *ssl = NULL;
 #endif /* HAVE_SSL */
-  struct wget_timer *timer;
   char *cookies = NULL;
 
   /* Whether this connection will be kept alive after the HTTP request
@@ -564,7 +563,7 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy)
   /* initialize ssl_ctx on first run */
   if (!ssl_ctx)
     {
-      err = init_ssl (&ssl_ctx);
+      uerr_t err = init_ssl (&ssl_ctx);
       if (err != 0)
        {
          switch (err)
@@ -746,8 +745,13 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy)
        }
       else
        {
+         /* Use the full path, i.e. one that includes the leading
+            slash and the query string, but is independent of proxy
+            setting.  */
+         char *pth = url_full_path (u);
          wwwauth = create_authorization_line (authenticate_h, user, passwd,
-                                              command, u->path);
+                                              command, pth);
+         xfree (pth);
        }
     }
 
@@ -802,6 +806,9 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy)
   if (proxy)
     full_path = xstrdup (u->url);
   else
+    /* Use the full path, i.e. one that includes the leading slash and
+       the query string.  E.g. if u->path is "foo/bar" and u->query is
+       "param=value", full_path will be "/foo/bar?param=value".  */
     full_path = url_full_path (u);
 
   /* Allocate the memory for the request.  */
@@ -1344,13 +1351,12 @@ Refusing to truncate existing file `%s'.\n\n"), *hs->local_file);
      should be some overhead information.  */
   if (opt.save_headers)
     fwrite (all_headers, 1, all_length, fp);
-  timer = wtimer_new ();
+
   /* Get the contents of the document.  */
   hs->res = get_contents (sock, fp, &hs->len, hs->restval,
                          (contlen != -1 ? contlen : 0),
-                         &rbuf, keep_alive);
-  hs->dltime = wtimer_elapsed (timer);
-  wtimer_delete (timer);
+                         &rbuf, keep_alive, &hs->dltime);
+
   {
     /* Close or flush the file.  We have to be careful to check for
        error here.  Checking the result of fwrite() is not enough --
@@ -2158,7 +2164,7 @@ dump_hash (unsigned char *buf, const unsigned char *hash)
 
 /* Take the line apart to find the challenge, and compose a digest
    authorization header.  See RFC2069 section 2.1.2.  */
-char *
+static char *
 digest_authentication_encode (const char *au, const char *user,
                              const char *passwd, const char *method,
                              const char *path)
@@ -2231,37 +2237,37 @@ digest_authentication_encode (const char *au, const char *user,
 
   /* Calculate the digest value.  */
   {
-    MD5_CONTEXT_TYPE ctx;
+    ALLOCA_MD5_CONTEXT (ctx);
     unsigned char hash[MD5_HASHLEN];
     unsigned char a1buf[MD5_HASHLEN * 2 + 1], a2buf[MD5_HASHLEN * 2 + 1];
     unsigned char response_digest[MD5_HASHLEN * 2 + 1];
 
     /* A1BUF = H(user ":" realm ":" password) */
-    MD5_INIT (&ctx);
-    MD5_UPDATE (user, strlen (user), &ctx);
-    MD5_UPDATE (":", 1, &ctx);
-    MD5_UPDATE (realm, strlen (realm), &ctx);
-    MD5_UPDATE (":", 1, &ctx);
-    MD5_UPDATE (passwd, strlen (passwd), &ctx);
-    MD5_FINISH (&ctx, hash);
+    gen_md5_init (ctx);
+    gen_md5_update ((unsigned char *)user, strlen (user), ctx);
+    gen_md5_update ((unsigned char *)":", 1, ctx);
+    gen_md5_update ((unsigned char *)realm, strlen (realm), ctx);
+    gen_md5_update ((unsigned char *)":", 1, ctx);
+    gen_md5_update ((unsigned char *)passwd, strlen (passwd), ctx);
+    gen_md5_finish (ctx, hash);
     dump_hash (a1buf, hash);
 
     /* A2BUF = H(method ":" path) */
-    MD5_INIT (&ctx);
-    MD5_UPDATE (method, strlen (method), &ctx);
-    MD5_UPDATE (":", 1, &ctx);
-    MD5_UPDATE (path, strlen (path), &ctx);
-    MD5_FINISH (&ctx, hash);
+    gen_md5_init (ctx);
+    gen_md5_update ((unsigned char *)method, strlen (method), ctx);
+    gen_md5_update ((unsigned char *)":", 1, ctx);
+    gen_md5_update ((unsigned char *)path, strlen (path), ctx);
+    gen_md5_finish (ctx, hash);
     dump_hash (a2buf, hash);
 
     /* RESPONSE_DIGEST = H(A1BUF ":" nonce ":" A2BUF) */
-    MD5_INIT (&ctx);
-    MD5_UPDATE (a1buf, MD5_HASHLEN * 2, &ctx);
-    MD5_UPDATE (":", 1, &ctx);
-    MD5_UPDATE (nonce, strlen (nonce), &ctx);
-    MD5_UPDATE (":", 1, &ctx);
-    MD5_UPDATE (a2buf, MD5_HASHLEN * 2, &ctx);
-    MD5_FINISH (&ctx, hash);
+    gen_md5_init (ctx);
+    gen_md5_update (a1buf, MD5_HASHLEN * 2, ctx);
+    gen_md5_update ((unsigned char *)":", 1, ctx);
+    gen_md5_update ((unsigned char *)nonce, strlen (nonce), ctx);
+    gen_md5_update ((unsigned char *)":", 1, ctx);
+    gen_md5_update (a2buf, MD5_HASHLEN * 2, ctx);
+    gen_md5_finish (ctx, hash);
     dump_hash (response_digest, hash);
 
     res = (char*) xmalloc (strlen (user)