]> sjero.net Git - wget/commitdiff
[svn] Change orders of parameters of base64_encode, so it makes more sense.
authorhniksic <devnull@localhost>
Mon, 18 Apr 2005 14:23:23 +0000 (07:23 -0700)
committerhniksic <devnull@localhost>
Mon, 18 Apr 2005 14:23:23 +0000 (07:23 -0700)
Mention NTLM support in http.c.

src/ChangeLog
src/http-ntlm.c
src/http.c
src/utils.c
src/utils.h

index c0dd819f1f0a359af44e0e80c4fac8c7c9e7ad3c..5d93f603359426dcfb8998dc305868c3584d46c2 100644 (file)
@@ -1,3 +1,9 @@
+2005-04-18  Hrvoje Niksic  <hniksic@xemacs.org>
+
+       * utils.c (base64_encode): Use the parameter order that makes more
+       sense.  Return the length of the base64 written.  Updated all
+       callers.
+
 2005-04-17  Hrvoje Niksic  <hniksic@xemacs.org>
 
        * http.c (request_set_header): Free NAME when VALUE is NULL and
index 6e35cbbe50e8c116ba9e0afba84fde3c7a26dfb7..9f17e9eb7663f11a161155c53123b5082ec5786a 100644 (file)
@@ -378,7 +378,7 @@ char *ntlm_output (struct ntlmdata *ntlm, const char *user, const char *passwd,
     size = 32 + hostlen + domlen;
 
     base64 = (char *) alloca (BASE64_LENGTH (size) + 1);
-    base64_encode (ntlmbuf, base64, size);
+    base64_encode (ntlmbuf, size, base64);
 
     output = concat_strings ("NTLM ", base64, (char *) 0);
     break;
@@ -538,7 +538,7 @@ char *ntlm_output (struct ntlmdata *ntlm, const char *user, const char *passwd,
 
     /* convert the binary blob into base64 */
     base64 = (char *) alloca (BASE64_LENGTH (size) + 1);
-    base64_encode (ntlmbuf, base64, size);
+    base64_encode (ntlmbuf, size, base64);
 
     output = concat_strings ("NTLM ", base64, (char *) 0);
 
index c54eadf499bf92e02785cf1ef462f95159a9d9d4..19ba3a8314cdd3c45c391abefd82834e9c6a17ce 100644 (file)
@@ -2607,29 +2607,35 @@ http_atotm (const char *time_string)
   return -1;
 }
 \f
-/* Authorization support: We support two authorization schemes:
+/* Authorization support: We support three authorization schemes:
 
    * `Basic' scheme, consisting of base64-ing USER:PASSWORD string;
 
    * `Digest' scheme, added by Junio Hamano <junio@twinsun.com>,
    consisting of answering to the server's challenge with the proper
-   MD5 digests.  */
+   MD5 digests.
+
+   * `NTLM' ("NT Lan Manager") scheme, based on code written by Daniel
+   Stenberg for libcurl.  Like digest, NTLM is based on a
+   challenge-response mechanism, but unlike digest, it is non-standard
+   (authenticates TCP connections rather than requests), undocumented
+   and Microsoft-specific.  */
 
 /* Create the authentication header contents for the `Basic' scheme.
    This is done by encoding the string `USER:PASS' in base64 and
    prepending `HEADER: Basic ' to it.  */
+
 static char *
 basic_authentication_encode (const char *user, const char *passwd)
 {
   char *t1, *t2;
   int len1 = strlen (user) + 1 + strlen (passwd);
-  int len2 = BASE64_LENGTH (len1);
 
   t1 = (char *)alloca (len1 + 1);
   sprintf (t1, "%s:%s", user, passwd);
 
-  t2 = (char *)alloca (len2 + 1);
-  base64_encode (t1, t2, len1);
+  t2 = (char *)alloca (BASE64_LENGTH (len1) + 1);
+  base64_encode (t1, len1, t2);
 
   return concat_strings ("Basic ", t2, (char *) 0);
 }
index dc16d55afc5940d095b9ada5d33f4d6d77deb809..0692bcb339776b28d132f96e8fa2c4961ac5f21d 100644 (file)
@@ -1826,11 +1826,16 @@ xsleep (double seconds)
 #endif /* not WINDOWS */
 
 /* Encode the string S of length LENGTH to base64 format and place it
-   to STORE.  STORE will be 0-terminated, and must point to a writable
-   buffer of at least 1+BASE64_LENGTH(length) bytes.  */
+   to B64STORE.  The output will be \0-terminated, and must point to a
+   writable buffer of at least 1+BASE64_LENGTH(length) bytes.  It
+   returns the length of the resulting base64 data, not counting the
+   terminating zero.
 
-void
-base64_encode (const char *s, char *store, int length)
+   This implementation will not emit newlines after 76 characters of
+   base64 data.  */
+
+int
+base64_encode (const char *s, int length, char *b64store)
 {
   /* Conversion table.  */
   static char tbl[64] = {
@@ -1844,7 +1849,7 @@ base64_encode (const char *s, char *store, int length)
     '4','5','6','7','8','9','+','/'
   };
   int i;
-  unsigned char *p = (unsigned char *)store;
+  unsigned char *p = (unsigned char *) b64store;
 
   /* Transform the 3x8 bits to 4x6 bits, as required by base64.  */
   for (i = 0; i < length; i += 3)
@@ -1855,13 +1860,17 @@ base64_encode (const char *s, char *store, int length)
       *p++ = tbl[s[2] & 0x3f];
       s += 3;
     }
+
   /* Pad the result if necessary...  */
   if (i == length + 1)
     *(p - 1) = '=';
   else if (i == length + 2)
     *(p - 1) = *(p - 2) = '=';
+
   /* ...and zero-terminate it.  */
   *p = '\0';
+
+  return p - (unsigned char *) b64store;
 }
 
 #define IS_ASCII(c) (((c) & 0x80) == 0)
@@ -1886,7 +1895,8 @@ base64_encode (const char *s, char *store, int length)
 int
 base64_decode (const char *base64, char *to)
 {
-  /* Table of base64 values for first 128 characters.  */
+  /* Table of base64 values for first 128 characters.  Note that this
+     assumes ASCII (but so does Wget in other places).  */
   static short base64_char_to_value[128] =
     {
       -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, /*   0-  9 */
index afef13c9402f2d105110fe1aa7959b944d841531..57992a607672aba224de7b63403a578b2f1c63bf 100644 (file)
@@ -116,7 +116,7 @@ void xsleep PARAMS ((double));
 /* How many bytes it will take to store LEN bytes in base64.  */
 #define BASE64_LENGTH(len) (4 * (((len) + 2) / 3))
 
-void base64_encode PARAMS ((const char *, char *, int));
+int base64_encode PARAMS ((const char *, int, char *));
 int base64_decode PARAMS ((const char *, char *));
 
 #endif /* UTILS_H */