Mercurial > emacs
annotate lisp/url/url-auth.el @ 94750:61756b574ffd
Renamed org-infojs.el to org-jsinfo.el.
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Thu, 08 May 2008 10:54:20 +0000 |
parents | 8259d0d8e107 |
children | fc66ed3d9938 |
rev | line source |
---|---|
54695 | 1 ;;; url-auth.el --- Uniform Resource Locator authorization modules |
57612 | 2 |
64748
875dcc490074
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64084
diff
changeset
|
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2004, |
79720 | 4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
57612 | 5 |
54695 | 6 ;; Keywords: comm, data, processes, hypermedia |
7 | |
57612 | 8 ;; This file is part of GNU Emacs. |
9 | |
94668
8259d0d8e107
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
88054
diff
changeset
|
10 ;; GNU Emacs is free software: you can redistribute it and/or modify |
57612 | 11 ;; it under the terms of the GNU General Public License as published by |
94668
8259d0d8e107
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
88054
diff
changeset
|
12 ;; the Free Software Foundation, either version 3 of the License, or |
8259d0d8e107
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
88054
diff
changeset
|
13 ;; (at your option) any later version. |
57612 | 14 |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
94668
8259d0d8e107
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
88054
diff
changeset
|
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
57612 | 22 |
23 ;;; Code: | |
54695 | 24 |
25 (require 'url-vars) | |
26 (require 'url-parse) | |
27 (autoload 'url-warn "url") | |
28 | |
29 (defsubst url-auth-user-prompt (url realm) | |
30 "String to usefully prompt for a username." | |
31 (concat "Username [for " | |
32 (or realm (url-truncate-url-for-viewing | |
33 (url-recreate-url url) | |
34 (- (window-width) 10 20))) | |
35 "]: ")) | |
36 | |
37 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
38 ;;; Basic authorization code | |
39 ;;; ------------------------ | |
40 ;;; This implements the BASIC authorization type. See the online | |
41 ;;; documentation at | |
42 ;;; http://www.w3.org/hypertext/WWW/AccessAuthorization/Basic.html | |
43 ;;; for the complete documentation on this type. | |
44 ;;; | |
45 ;;; This is very insecure, but it works as a proof-of-concept | |
46 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
47 (defvar url-basic-auth-storage 'url-http-real-basic-auth-storage | |
48 "Where usernames and passwords are stored. | |
49 | |
50 Must be a symbol pointing to another variable that will actually store | |
51 the information. The value of this variable is an assoc list of assoc | |
52 lists. The first assoc list is keyed by the server name. The cdr of | |
53 this is an assoc list based on the 'directory' specified by the url we | |
54 are looking up.") | |
55 | |
56 (defun url-basic-auth (url &optional prompt overwrite realm args) | |
57 "Get the username/password for the specified URL. | |
58 If optional argument PROMPT is non-nil, ask for the username/password | |
59 to use for the url and its descendants. If optional third argument | |
60 OVERWRITE is non-nil, overwrite the old username/password pair if it | |
61 is found in the assoc list. If REALM is specified, use that as the realm | |
79065
de62e8014967
(url-digest-auth, url-basic-auth):
Richard M. Stallman <rms@gnu.org>
parents:
79056
diff
changeset
|
62 instead of the filename inheritance method." |
54695 | 63 (let* ((href (if (stringp url) |
64 (url-generic-parse-url url) | |
65 url)) | |
66 (server (url-host href)) | |
67 (port (url-port href)) | |
79065
de62e8014967
(url-digest-auth, url-basic-auth):
Richard M. Stallman <rms@gnu.org>
parents:
79056
diff
changeset
|
68 (file (url-filename href)) |
78514
364329b928dc
username and password default
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
78481
diff
changeset
|
69 (user (url-user href)) |
364329b928dc
username and password default
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
78481
diff
changeset
|
70 (pass (url-password href)) |
364329b928dc
username and password default
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
78481
diff
changeset
|
71 byserv retval data) |
54695 | 72 (setq server (format "%s:%d" server port) |
79065
de62e8014967
(url-digest-auth, url-basic-auth):
Richard M. Stallman <rms@gnu.org>
parents:
79056
diff
changeset
|
73 file (cond |
54695 | 74 (realm realm) |
79065
de62e8014967
(url-digest-auth, url-basic-auth):
Richard M. Stallman <rms@gnu.org>
parents:
79056
diff
changeset
|
75 ((string= "" file) "/") |
de62e8014967
(url-digest-auth, url-basic-auth):
Richard M. Stallman <rms@gnu.org>
parents:
79056
diff
changeset
|
76 ((string-match "/$" file) file) |
de62e8014967
(url-digest-auth, url-basic-auth):
Richard M. Stallman <rms@gnu.org>
parents:
79056
diff
changeset
|
77 (t (url-file-directory file))) |
54695 | 78 byserv (cdr-safe (assoc server |
79 (symbol-value url-basic-auth-storage)))) | |
80 (cond | |
81 ((and prompt (not byserv)) | |
82 (setq user (read-string (url-auth-user-prompt url realm) | |
78514
364329b928dc
username and password default
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
78481
diff
changeset
|
83 (or user (user-real-login-name))) |
364329b928dc
username and password default
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
78481
diff
changeset
|
84 pass (read-passwd "Password: " nil (or pass ""))) |
54695 | 85 (set url-basic-auth-storage |
86 (cons (list server | |
79065
de62e8014967
(url-digest-auth, url-basic-auth):
Richard M. Stallman <rms@gnu.org>
parents:
79056
diff
changeset
|
87 (cons file |
54695 | 88 (setq retval |
89 (base64-encode-string | |
90 (format "%s:%s" user pass))))) | |
91 (symbol-value url-basic-auth-storage)))) | |
92 (byserv | |
79065
de62e8014967
(url-digest-auth, url-basic-auth):
Richard M. Stallman <rms@gnu.org>
parents:
79056
diff
changeset
|
93 (setq retval (cdr-safe (assoc file byserv))) |
54695 | 94 (if (and (not retval) |
79065
de62e8014967
(url-digest-auth, url-basic-auth):
Richard M. Stallman <rms@gnu.org>
parents:
79056
diff
changeset
|
95 (string-match "/" file)) |
54695 | 96 (while (and byserv (not retval)) |
97 (setq data (car (car byserv))) | |
75519
b271481fb8d2
(url-get-authentication): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
75347
diff
changeset
|
98 (if (or (not (string-match "/" data)) ; It's a realm - take it! |
54695 | 99 (and |
79065
de62e8014967
(url-digest-auth, url-basic-auth):
Richard M. Stallman <rms@gnu.org>
parents:
79056
diff
changeset
|
100 (>= (length file) (length data)) |
de62e8014967
(url-digest-auth, url-basic-auth):
Richard M. Stallman <rms@gnu.org>
parents:
79056
diff
changeset
|
101 (string= data (substring file 0 (length data))))) |
54695 | 102 (setq retval (cdr (car byserv)))) |
103 (setq byserv (cdr byserv)))) | |
104 (if (or (and (not retval) prompt) overwrite) | |
105 (progn | |
106 (setq user (read-string (url-auth-user-prompt url realm) | |
107 (user-real-login-name)) | |
57509
e5a1e83cfb02
(url-basic-auth, url-digest-auth): Use read-passwd.
Richard M. Stallman <rms@gnu.org>
parents:
57427
diff
changeset
|
108 pass (read-passwd "Password: ") |
54695 | 109 retval (base64-encode-string (format "%s:%s" user pass)) |
110 byserv (assoc server (symbol-value url-basic-auth-storage))) | |
111 (setcdr byserv | |
79065
de62e8014967
(url-digest-auth, url-basic-auth):
Richard M. Stallman <rms@gnu.org>
parents:
79056
diff
changeset
|
112 (cons (cons file retval) (cdr byserv)))))) |
54695 | 113 (t (setq retval nil))) |
114 (if retval (setq retval (concat "Basic " retval))) | |
115 retval)) | |
116 | |
117 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
118 ;;; Digest authorization code | |
119 ;;; ------------------------ | |
120 ;;; This implements the DIGEST authorization type. See the internet draft | |
121 ;;; ftp://ds.internic.net/internet-drafts/draft-ietf-http-digest-aa-01.txt | |
122 ;;; for the complete documentation on this type. | |
123 ;;; | |
124 ;;; This is very secure | |
125 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
126 (defvar url-digest-auth-storage nil | |
127 "Where usernames and passwords are stored. Its value is an assoc list of | |
128 assoc lists. The first assoc list is keyed by the server name. The cdr of | |
129 this is an assoc list based on the 'directory' specified by the url we are | |
130 looking up.") | |
131 | |
132 (defun url-digest-auth-create-key (username password realm method uri) | |
133 "Create a key for digest authentication method" | |
134 (let* ((info (if (stringp uri) | |
135 (url-generic-parse-url uri) | |
136 uri)) | |
137 (a1 (md5 (concat username ":" realm ":" password))) | |
138 (a2 (md5 (concat method ":" (url-filename info))))) | |
139 (list a1 a2))) | |
140 | |
141 (defun url-digest-auth (url &optional prompt overwrite realm args) | |
142 "Get the username/password for the specified URL. | |
143 If optional argument PROMPT is non-nil, ask for the username/password | |
144 to use for the url and its descendants. If optional third argument | |
145 OVERWRITE is non-nil, overwrite the old username/password pair if it | |
146 is found in the assoc list. If REALM is specified, use that as the realm | |
147 instead of hostname:portnum." | |
148 (if args | |
149 (let* ((href (if (stringp url) | |
150 (url-generic-parse-url url) | |
151 url)) | |
152 (server (url-host href)) | |
153 (port (url-port href)) | |
79065
de62e8014967
(url-digest-auth, url-basic-auth):
Richard M. Stallman <rms@gnu.org>
parents:
79056
diff
changeset
|
154 (file (url-filename href)) |
54695 | 155 user pass byserv retval data) |
79065
de62e8014967
(url-digest-auth, url-basic-auth):
Richard M. Stallman <rms@gnu.org>
parents:
79056
diff
changeset
|
156 (setq file (cond |
54695 | 157 (realm realm) |
79065
de62e8014967
(url-digest-auth, url-basic-auth):
Richard M. Stallman <rms@gnu.org>
parents:
79056
diff
changeset
|
158 ((string-match "/$" file) file) |
de62e8014967
(url-digest-auth, url-basic-auth):
Richard M. Stallman <rms@gnu.org>
parents:
79056
diff
changeset
|
159 (t (url-file-directory file))) |
54695 | 160 server (format "%s:%d" server port) |
161 byserv (cdr-safe (assoc server url-digest-auth-storage))) | |
162 (cond | |
163 ((and prompt (not byserv)) | |
164 (setq user (read-string (url-auth-user-prompt url realm) | |
165 (user-real-login-name)) | |
57509
e5a1e83cfb02
(url-basic-auth, url-digest-auth): Use read-passwd.
Richard M. Stallman <rms@gnu.org>
parents:
57427
diff
changeset
|
166 pass (read-passwd "Password: ") |
54695 | 167 url-digest-auth-storage |
168 (cons (list server | |
79065
de62e8014967
(url-digest-auth, url-basic-auth):
Richard M. Stallman <rms@gnu.org>
parents:
79056
diff
changeset
|
169 (cons file |
54695 | 170 (setq retval |
171 (cons user | |
172 (url-digest-auth-create-key | |
173 user pass realm | |
174 (or url-request-method "GET") | |
175 url))))) | |
176 url-digest-auth-storage))) | |
177 (byserv | |
79065
de62e8014967
(url-digest-auth, url-basic-auth):
Richard M. Stallman <rms@gnu.org>
parents:
79056
diff
changeset
|
178 (setq retval (cdr-safe (assoc file byserv))) |
54695 | 179 (if (and (not retval) ; no exact match, check directories |
79065
de62e8014967
(url-digest-auth, url-basic-auth):
Richard M. Stallman <rms@gnu.org>
parents:
79056
diff
changeset
|
180 (string-match "/" file)) ; not looking for a realm |
54695 | 181 (while (and byserv (not retval)) |
182 (setq data (car (car byserv))) | |
183 (if (or (not (string-match "/" data)) | |
184 (and | |
79065
de62e8014967
(url-digest-auth, url-basic-auth):
Richard M. Stallman <rms@gnu.org>
parents:
79056
diff
changeset
|
185 (>= (length file) (length data)) |
de62e8014967
(url-digest-auth, url-basic-auth):
Richard M. Stallman <rms@gnu.org>
parents:
79056
diff
changeset
|
186 (string= data (substring file 0 (length data))))) |
54695 | 187 (setq retval (cdr (car byserv)))) |
188 (setq byserv (cdr byserv)))) | |
88054
eae3aec0f807
2008-01-29 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
87649
diff
changeset
|
189 (if overwrite |
eae3aec0f807
2008-01-29 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
87649
diff
changeset
|
190 (if (and (not retval) prompt) |
eae3aec0f807
2008-01-29 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
87649
diff
changeset
|
191 (setq user (read-string (url-auth-user-prompt url realm) |
eae3aec0f807
2008-01-29 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
87649
diff
changeset
|
192 (user-real-login-name)) |
eae3aec0f807
2008-01-29 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
87649
diff
changeset
|
193 pass (read-passwd "Password: ") |
eae3aec0f807
2008-01-29 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
87649
diff
changeset
|
194 retval (setq retval |
eae3aec0f807
2008-01-29 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
87649
diff
changeset
|
195 (cons user |
eae3aec0f807
2008-01-29 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
87649
diff
changeset
|
196 (url-digest-auth-create-key |
eae3aec0f807
2008-01-29 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
87649
diff
changeset
|
197 user pass realm |
eae3aec0f807
2008-01-29 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
87649
diff
changeset
|
198 (or url-request-method "GET") |
eae3aec0f807
2008-01-29 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
87649
diff
changeset
|
199 url))) |
eae3aec0f807
2008-01-29 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
87649
diff
changeset
|
200 byserv (assoc server url-digest-auth-storage)) |
54695 | 201 (setcdr byserv |
79065
de62e8014967
(url-digest-auth, url-basic-auth):
Richard M. Stallman <rms@gnu.org>
parents:
79056
diff
changeset
|
202 (cons (cons file retval) (cdr byserv)))))) |
54695 | 203 (t (setq retval nil))) |
204 (if retval | |
88054
eae3aec0f807
2008-01-29 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
87649
diff
changeset
|
205 (if (cdr-safe (assoc "opaque" args)) |
eae3aec0f807
2008-01-29 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
87649
diff
changeset
|
206 (let ((nonce (or (cdr-safe (assoc "nonce" args)) "nonegiven")) |
eae3aec0f807
2008-01-29 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
87649
diff
changeset
|
207 (opaque (cdr-safe (assoc "opaque" args)))) |
eae3aec0f807
2008-01-29 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
87649
diff
changeset
|
208 (format |
eae3aec0f807
2008-01-29 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
87649
diff
changeset
|
209 (concat "Digest username=\"%s\", realm=\"%s\"," |
eae3aec0f807
2008-01-29 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
87649
diff
changeset
|
210 "nonce=\"%s\", uri=\"%s\"," |
eae3aec0f807
2008-01-29 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
87649
diff
changeset
|
211 "response=\"%s\", opaque=\"%s\"") |
eae3aec0f807
2008-01-29 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
87649
diff
changeset
|
212 (nth 0 retval) realm nonce (url-filename href) |
eae3aec0f807
2008-01-29 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
87649
diff
changeset
|
213 (md5 (concat (nth 1 retval) ":" nonce ":" |
eae3aec0f807
2008-01-29 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
87649
diff
changeset
|
214 (nth 2 retval))) opaque)) |
eae3aec0f807
2008-01-29 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
87649
diff
changeset
|
215 (let ((nonce (or (cdr-safe (assoc "nonce" args)) "nonegiven"))) |
eae3aec0f807
2008-01-29 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
87649
diff
changeset
|
216 (format |
eae3aec0f807
2008-01-29 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
87649
diff
changeset
|
217 (concat "Digest username=\"%s\", realm=\"%s\"," |
eae3aec0f807
2008-01-29 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
87649
diff
changeset
|
218 "nonce=\"%s\", uri=\"%s\"," |
eae3aec0f807
2008-01-29 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
87649
diff
changeset
|
219 "response=\"%s\"") |
eae3aec0f807
2008-01-29 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
87649
diff
changeset
|
220 (nth 0 retval) realm nonce (url-filename href) |
eae3aec0f807
2008-01-29 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
87649
diff
changeset
|
221 (md5 (concat (nth 1 retval) ":" nonce ":" |
eae3aec0f807
2008-01-29 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
87649
diff
changeset
|
222 (nth 2 retval)))))))))) |
54695 | 223 |
224 (defvar url-registered-auth-schemes nil | |
225 "A list of the registered authorization schemes and various and sundry | |
226 information associated with them.") | |
227 | |
228 ;;;###autoload | |
229 (defun url-get-authentication (url realm type prompt &optional args) | |
230 "Return an authorization string suitable for use in the WWW-Authenticate | |
231 header in an HTTP/1.0 request. | |
232 | |
233 URL is the url you are requesting authorization to. This can be either a | |
234 string representing the URL, or the parsed representation returned by | |
235 `url-generic-parse-url' | |
236 REALM is the realm at a specific site we are looking for. This should be a | |
237 string specifying the exact realm, or nil or the symbol 'any' to | |
238 specify that the filename portion of the URL should be used as the | |
239 realm | |
240 TYPE is the type of authentication to be returned. This is either a string | |
241 representing the type (basic, digest, etc), or nil or the symbol 'any' | |
242 to specify that any authentication is acceptable. If requesting 'any' | |
243 the strongest matching authentication will be returned. If this is | |
75519
b271481fb8d2
(url-get-authentication): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
75347
diff
changeset
|
244 wrong, it's no big deal, the error from the server will specify exactly |
54695 | 245 what type of auth to use |
246 PROMPT is boolean - specifies whether to ask the user for a username/password | |
247 if one cannot be found in the cache" | |
248 (if (not realm) | |
249 (setq realm (cdr-safe (assoc "realm" args)))) | |
250 (if (stringp url) | |
251 (setq url (url-generic-parse-url url))) | |
252 (if (or (null type) (eq type 'any)) | |
253 ;; Whooo doogies! | |
254 ;; Go through and get _all_ the authorization strings that could apply | |
255 ;; to this URL, store them along with the 'rating' we have in the list | |
256 ;; of schemes, then sort them so that the 'best' is at the front of the | |
257 ;; list, then get the car, then get the cdr. | |
258 ;; Zooom zooom zoooooom | |
259 (cdr-safe | |
260 (car-safe | |
261 (sort | |
262 (mapcar | |
263 (function | |
264 (lambda (scheme) | |
265 (if (fboundp (car (cdr scheme))) | |
266 (cons (cdr (cdr scheme)) | |
267 (funcall (car (cdr scheme)) url nil nil realm)) | |
268 (cons 0 nil)))) | |
269 url-registered-auth-schemes) | |
270 (function | |
271 (lambda (x y) | |
272 (cond | |
273 ((null (cdr x)) nil) | |
274 ((and (cdr x) (null (cdr y))) t) | |
275 ((and (cdr x) (cdr y)) | |
276 (>= (car x) (car y))) | |
277 (t nil))))))) | |
278 (if (symbolp type) (setq type (symbol-name type))) | |
279 (let* ((scheme (car-safe | |
280 (cdr-safe (assoc (downcase type) | |
281 url-registered-auth-schemes))))) | |
282 (if (and scheme (fboundp scheme)) | |
283 (funcall scheme url prompt | |
284 (and prompt | |
285 (funcall scheme url nil nil realm args)) | |
286 realm args))))) | |
287 | |
288 ;;;###autoload | |
289 (defun url-register-auth-scheme (type &optional function rating) | |
290 "Register an HTTP authentication method. | |
291 | |
292 TYPE is a string or symbol specifying the name of the method. This | |
293 should be the same thing you expect to get returned in an Authenticate | |
294 header in HTTP/1.0 - it will be downcased. | |
295 FUNCTION is the function to call to get the authorization information. This | |
296 defaults to `url-?-auth', where ? is TYPE | |
297 RATING a rating between 1 and 10 of the strength of the authentication. | |
298 This is used when asking for the best authentication for a specific | |
299 URL. The item with the highest rating is returned." | |
300 (let* ((type (cond | |
301 ((stringp type) (downcase type)) | |
302 ((symbolp type) (downcase (symbol-name type))) | |
303 (t (error "Bad call to `url-register-auth-scheme'")))) | |
304 (function (or function (intern (concat "url-" type "-auth")))) | |
305 (rating (cond | |
306 ((null rating) 2) | |
62400
e30c08177a3b
Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents:
57612
diff
changeset
|
307 ((stringp rating) (string-to-number rating)) |
54695 | 308 (t rating))) |
309 (node (assoc type url-registered-auth-schemes))) | |
310 (if (not (fboundp function)) | |
311 (url-warn 'security | |
54792
369ef3f04d8e
(url-register-auth-scheme): Fix `format' call.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
312 (format (concat |
369ef3f04d8e
(url-register-auth-scheme): Fix `format' call.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
313 "Tried to register `%s' as an auth scheme" |
369ef3f04d8e
(url-register-auth-scheme): Fix `format' call.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
314 ", but it is not a function!") function))) |
54695 | 315 |
316 (if node | |
317 (setcdr node (cons function rating)) | |
318 (setq url-registered-auth-schemes | |
319 (cons (cons type (cons function rating)) | |
320 url-registered-auth-schemes))))) | |
321 | |
322 (defun url-auth-registered (scheme) | |
78481
bc53aa750f3b
Replace `iff' in doc-strings and comments.
Glenn Morris <rgm@gnu.org>
parents:
78222
diff
changeset
|
323 "Return non-nil if SCHEME is registered as an auth type." |
54695 | 324 (assoc scheme url-registered-auth-schemes)) |
325 | |
326 (provide 'url-auth) | |
54699 | 327 |
84378 | 328 ;; arch-tag: 04058625-616d-44e4-9dbf-4b46b00b2a91 |
57612 | 329 ;;; url-auth.el ends here |