]> code.delx.au - gnu-emacs-elpa/blobdiff - packages/url-http-ntlm/url-http-ntlm.el
url-http-ntlm.el (url-ntlm-auth): Move defun near end of file
[gnu-emacs-elpa] / packages / url-http-ntlm / url-http-ntlm.el
index 6975fa714b37fc45cf985e1c59055f39722873cf..302915f9dd7c2c94a44966135c63c3d55be592c3 100644 (file)
@@ -2,7 +2,7 @@
 
 ;; Copyright (C) 2008, 2015 Free Software Foundation, Inc.
 
-;; Author: Tom Schutzer-Weissmann <tom@schutzer-weissmann.net>
+;; Author: Tom Schutzer-Weissmann <tom.weissmann@gmail.com>
 ;; Maintainer: Thomas Fitzsimmons <fitzsim@fitzsim.org>
 ;; Keywords: comm, data, processes, hypermedia
 
@@ -53,59 +53,24 @@ The username can contain the domain name, in the form \"user@domain\".
 
 Note that for any server, only one user and password is ever stored.")
 
-(defun url-ntlm-auth (url &optional prompt overwrite realm args)
-  "Return an NTLM HTTP authorization header.
-Get the contents of the Authorization header for a HTTP response
-using NTLM authentication, to access URL.  Because NTLM is a
-two-step process, this function expects to be called twice, first
-to generate the NTLM type 1 message (request), then to respond to
-the server's type 2 message (challenge) with a suitable response.
-
-PROMPT, OVERWRITE, and REALM are ignored.
-
-ARGS is expected to contain the WWW-Authentication header from
-the server's last response.  These are used by
-`url-http-get-stage' to determine what stage we are at."
-  (url-ntlm-ensure-keepalive)
-  (let ((stage (url-ntlm-get-stage args)))
-    (case stage
-      ;; NTLM Type 1 message: the request
-      (:request
-       (destructuring-bind (&optional server user hash)
-          (url-http-ntlm-authorisation url)
-        (when server
-          (url-http-ntlm-string
-           (ntlm-build-auth-request user server)))))
-      ;; NTLM Type 3 message: the response
-      (:response
-       (let ((challenge (url-http-ntlm-get-challenge)))
-        (destructuring-bind (server user hash)
-            (url-http-ntlm-authorisation url)
-          (url-http-ntlm-string
-           (ntlm-build-auth-response challenge
-                                     user
-                                     hash)))))
-      (:error
-       (url-http-ntlm-authorisation url :clear)))))
-
-(defun url-ntlm-ensure-keepalive ()
+(defun url-http-ntlm-ensure-keepalive ()
   "Report an error if `url-http-attempt-keepalives' is not set."
   (assert url-http-attempt-keepalives
          nil
          (concat "NTLM authentication won't work unless"
                  " `url-http-attempt-keepalives' is set!")))
 
-(defun url-ntlm-clean-headers ()
+(defun url-http-ntlm-clean-headers ()
   "Remove Authorization element from `url-http-extra-headers' alist."
   (setq url-http-extra-headers
        (url-http-ntlm-rmssoc "Authorization" url-http-extra-headers)))
 
-(defvar url-ntlm-last-args nil
-  "Stores the last ARGS argument to `url-ntlm-get-stage' and the return value.
+(defvar url-http-ntlm-last-args nil
+  "Stores the last `url-http-ntlm-get-stage' arguments and return value.
 This is used to detect multiple calls.")
-(make-variable-buffer-local 'url-ntlm-last-args)
+(make-variable-buffer-local 'url-http-ntlm-last-args)
 
-(defun url-ntlm-get-stage (args)
+(defun url-http-ntlm-get-stage (args)
   "Determine what stage of the NTLM handshake we are at.
 PROMPT and ARGS come from `url-ntlm-auth''s caller,
 `url-get-authentication'.  Their meaning depends on the current
@@ -122,9 +87,9 @@ response's \"WWW-Authenticate\" header, munged by
         (auth-header      (assoc "Authorization" url-http-extra-headers))
         (case-fold-search t)
         stage)
-    (if (eq args (car url-ntlm-last-args))
+    (if (eq args (car url-http-ntlm-last-args))
        ;; multiple calls, return the same argument we returned last time
-       (cdr url-ntlm-last-args)
+       (cdr url-http-ntlm-last-args)
       (let ((stage
             (cond ((and auth-header (string-match response-rxp
                                                   (cdr auth-header)))
@@ -137,8 +102,8 @@ response's \"WWW-Authenticate\" header, munged by
                    :response)
                   (t
                    :request))))
-       (url-ntlm-clean-headers)
-       (setq url-ntlm-last-args (cons args stage))
+       (url-http-ntlm-clean-headers)
+       (setq url-http-ntlm-last-args (cons args stage))
        stage))))
 
 (defun url-http-ntlm-authorisation (url &optional clear)
@@ -204,6 +169,41 @@ stored."
   "Return DATA encoded as an NTLM string."
   (concat "NTLM " (base64-encode-string data :nobreak)))
 
+(defun url-ntlm-auth (url &optional prompt overwrite realm args)
+  "Return an NTLM HTTP authorization header.
+Get the contents of the Authorization header for a HTTP response
+using NTLM authentication, to access URL.  Because NTLM is a
+two-step process, this function expects to be called twice, first
+to generate the NTLM type 1 message (request), then to respond to
+the server's type 2 message (challenge) with a suitable response.
+
+PROMPT, OVERWRITE, and REALM are ignored.
+
+ARGS is expected to contain the WWW-Authentication header from
+the server's last response.  These are used by
+`url-http-get-stage' to determine what stage we are at."
+  (url-http-ntlm-ensure-keepalive)
+  (let ((stage (url-http-ntlm-get-stage args)))
+    (case stage
+      ;; NTLM Type 1 message: the request
+      (:request
+       (destructuring-bind (&optional server user hash)
+          (url-http-ntlm-authorisation url)
+        (when server
+          (url-http-ntlm-string
+           (ntlm-build-auth-request user server)))))
+      ;; NTLM Type 3 message: the response
+      (:response
+       (let ((challenge (url-http-ntlm-get-challenge)))
+        (destructuring-bind (server user hash)
+            (url-http-ntlm-authorisation url)
+          (url-http-ntlm-string
+           (ntlm-build-auth-response challenge
+                                     user
+                                     hash)))))
+      (:error
+       (url-http-ntlm-authorisation url :clear)))))
+
 (url-register-auth-scheme "ntlm" nil 8)
 
 (provide 'url-http-ntlm)