]> sjero.net Git - wget/blobdiff - src/http.c
[svn] Use Solaris's libmd5 when available.
[wget] / src / http.c
index 93b3a12f197c4fe28fc14c29de81f5ca444e90e3..f95a53f531a02e4e2f15a7ac544d2266a8a5c5ca 100644 (file)
@@ -1,20 +1,21 @@
 /* HTTP support.
-   Copyright (C) 1995, 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
+   Copyright (C) 1995, 1996, 1997, 1998, 2000, 2001
+   Free Software Foundation, Inc.
 
-This file is part of Wget.
+This file is part of GNU Wget.
 
-This program is free software; you can redistribute it and/or modify
+GNU Wget is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.
 
-This program is distributed in the hope that it will be useful,
+GNU Wget is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+along with Wget; if not, write to the Free Software
 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #include <config.h>
@@ -59,9 +60,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "connect.h"
 #include "fnmatch.h"
 #include "netrc.h"
-#if USE_DIGEST
-# include "md5.h"
-#endif
 #ifdef HAVE_SSL
 # include "gen_sslfunc.h"
 #endif /* HAVE_SSL */
@@ -660,6 +658,7 @@ gethttp (struct urlinfo *u, struct http_stat *hs, int *dt)
         {
           logputs (LOG_VERBOSE, "\n");
           logprintf (LOG_NOTQUIET, _("Unable to establish SSL connection.\n"));
+          ssl_printerrors ();
           CLOSE (sock);
           return CONSSLERR;
         }
@@ -717,7 +716,7 @@ gethttp (struct urlinfo *u, struct http_stat *hs, int *dt)
   /* Construct the authentication, if userid is present.  */
   user = ou->user;
   passwd = ou->passwd;
-  search_netrc (u->host, (const char **)&user, (const char **)&passwd, 0);
+  search_netrc (ou->host, (const char **)&user, (const char **)&passwd, 0);
   user = user ? user : opt.http_user;
   passwd = passwd ? passwd : opt.http_passwd;
 
@@ -937,10 +936,6 @@ Accept: %s\r\n\
          all_headers[all_length] = '\0';
        }
 
-      /* Print the header if requested.  */
-      if (opt.server_response && hcount != 1)
-       logprintf (LOG_VERBOSE, "\n%d %s", hcount, hdr);
-
       /* Check for status line.  */
       if (hcount == 1)
        {
@@ -971,7 +966,12 @@ Accept: %s\r\n\
              && !opt.debug
 #endif
              )
-           logprintf (LOG_VERBOSE, "%d %s", statcode, error);
+           {
+             if (opt.server_response)
+              logprintf (LOG_VERBOSE, "\n%2d %s", hcount, hdr);
+             else
+              logprintf (LOG_VERBOSE, "%2d %s", statcode, error);
+           }
 
          goto done_header;
        }
@@ -983,6 +983,10 @@ Accept: %s\r\n\
          break;
        }
 
+      /* Print the header if requested.  */
+      if (opt.server_response && hcount != 1)
+       logprintf (LOG_VERBOSE, "\n%2d %s", hcount, hdr);
+
       /* Try getting content-length.  */
       if (contlen == -1 && !opt.ignore_length)
        if (header_process (hdr, "Content-Length", header_extract_number,
@@ -1214,7 +1218,7 @@ Accept: %s\r\n\
              logprintf (LOG_NOTQUIET,
                         _("\
 \n\
-The server does not support continued downloads, which conflicts with `-c'.\n\
+Continued download failed on this file, which conflicts with `-c'.\n\
 Refusing to truncate existing file `%s'.\n\n"), u->local);
              FREE_MAYBE (type);
              FREE_MAYBE (all_headers);
@@ -2195,37 +2199,37 @@ digest_authentication_encode (const char *au, const char *user,
 
   /* Calculate the digest value.  */
   {
-    struct md5_ctx ctx;
+    MD5_CONTEXT_TYPE 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 (&ctx);
-    md5_process_bytes (user, strlen (user), &ctx);
-    md5_process_bytes (":", 1, &ctx);
-    md5_process_bytes (realm, strlen (realm), &ctx);
-    md5_process_bytes (":", 1, &ctx);
-    md5_process_bytes (passwd, strlen (passwd), &ctx);
-    md5_finish_ctx (&ctx, hash);
+    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);
     dump_hash (a1buf, hash);
 
     /* A2BUF = H(method ":" path) */
-    md5_init_ctx (&ctx);
-    md5_process_bytes (method, strlen (method), &ctx);
-    md5_process_bytes (":", 1, &ctx);
-    md5_process_bytes (path, strlen (path), &ctx);
-    md5_finish_ctx (&ctx, hash);
+    MD5_INIT (&ctx);
+    MD5_UPDATE (method, strlen (method), &ctx);
+    MD5_UPDATE (":", 1, &ctx);
+    MD5_UPDATE (path, strlen (path), &ctx);
+    MD5_FINISH (&ctx, hash);
     dump_hash (a2buf, hash);
 
     /* RESPONSE_DIGEST = H(A1BUF ":" nonce ":" A2BUF) */
-    md5_init_ctx (&ctx);
-    md5_process_bytes (a1buf, MD5_HASHLEN * 2, &ctx);
-    md5_process_bytes (":", 1, &ctx);
-    md5_process_bytes (nonce, strlen (nonce), &ctx);
-    md5_process_bytes (":", 1, &ctx);
-    md5_process_bytes (a2buf, MD5_HASHLEN * 2, &ctx);
-    md5_finish_ctx (&ctx, hash);
+    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);
     dump_hash (response_digest, hash);
 
     res = (char*) xmalloc (strlen (user)