Mercurial > emacs
comparison lisp/url/url-cookie.el @ 83331:efa9e4606e7e
Merged from miles@gnu.org--gnu-2005 (patch 83-87, 449-468)
Patches applied:
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-449
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-450
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-451
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-452
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-453
Update from CVS: lisp/subr.el (add-to-ordered-list): Doc fix.
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-454
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-455
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-456
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-457
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-458
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-459
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-460
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-461
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-462
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-463
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-464
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-465
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-466
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-467
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-468
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-83
Merge from emacs--cvs-trunk--0
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-84
Merge from emacs--cvs-trunk--0
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-85
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-86
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-87
Update from CVS
git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-371
author | Karoly Lorentey <lorentey@elte.hu> |
---|---|
date | Tue, 05 Jul 2005 22:12:55 +0000 |
parents | d07fdd5d7d4e 8d2417e75fe5 |
children | 6c13700d1c13 |
comparison
equal
deleted
inserted
replaced
83330:233c9974025b | 83331:efa9e4606e7e |
---|---|
32 | 32 |
33 ;; See http://home.netscape.com/newsref/std/cookie_spec.html for the | 33 ;; See http://home.netscape.com/newsref/std/cookie_spec.html for the |
34 ;; 'open standard' defining this crap. | 34 ;; 'open standard' defining this crap. |
35 ;; | 35 ;; |
36 ;; A cookie is stored internally as a vector of 7 slots | 36 ;; A cookie is stored internally as a vector of 7 slots |
37 ;; [ 'cookie name value expires path domain secure ] | 37 ;; [ cookie NAME VALUE EXPIRES LOCALPART DOMAIN SECURE ] |
38 | 38 |
39 (defsubst url-cookie-name (cookie) (aref cookie 1)) | 39 (defsubst url-cookie-name (cookie) (aref cookie 1)) |
40 (defsubst url-cookie-value (cookie) (aref cookie 2)) | 40 (defsubst url-cookie-value (cookie) (aref cookie 2)) |
41 (defsubst url-cookie-expires (cookie) (aref cookie 3)) | 41 (defsubst url-cookie-expires (cookie) (aref cookie 3)) |
42 (defsubst url-cookie-path (cookie) (aref cookie 4)) | 42 (defsubst url-cookie-localpart (cookie) (aref cookie 4)) |
43 (defsubst url-cookie-domain (cookie) (aref cookie 5)) | 43 (defsubst url-cookie-domain (cookie) (aref cookie 5)) |
44 (defsubst url-cookie-secure (cookie) (aref cookie 6)) | 44 (defsubst url-cookie-secure (cookie) (aref cookie 6)) |
45 | 45 |
46 (defsubst url-cookie-set-name (cookie val) (aset cookie 1 val)) | 46 (defsubst url-cookie-set-name (cookie val) (aset cookie 1 val)) |
47 (defsubst url-cookie-set-value (cookie val) (aset cookie 2 val)) | 47 (defsubst url-cookie-set-value (cookie val) (aset cookie 2 val)) |
48 (defsubst url-cookie-set-expires (cookie val) (aset cookie 3 val)) | 48 (defsubst url-cookie-set-expires (cookie val) (aset cookie 3 val)) |
49 (defsubst url-cookie-set-path (cookie val) (aset cookie 4 val)) | 49 (defsubst url-cookie-set-localpart (cookie val) (aset cookie 4 val)) |
50 (defsubst url-cookie-set-domain (cookie val) (aset cookie 5 val)) | 50 (defsubst url-cookie-set-domain (cookie val) (aset cookie 5 val)) |
51 (defsubst url-cookie-set-secure (cookie val) (aset cookie 6 val)) | 51 (defsubst url-cookie-set-secure (cookie val) (aset cookie 6 val)) |
52 (defsubst url-cookie-retrieve-arg (key args) (nth 1 (memq key args))) | 52 (defsubst url-cookie-retrieve-arg (key args) (nth 1 (memq key args))) |
53 | 53 |
54 (defsubst url-cookie-create (&rest args) | 54 (defsubst url-cookie-create (&rest args) |
55 "Create a cookie vector object from keyword-value pairs ARGS. | |
56 The keywords allowed are | |
57 :name NAME | |
58 :value VALUE | |
59 :expires TIME | |
60 :localpart LOCALPAR | |
61 :domain DOMAIN | |
62 :secure ??? | |
63 Could someone fill in more information?" | |
55 (let ((retval (make-vector 7 nil))) | 64 (let ((retval (make-vector 7 nil))) |
56 (aset retval 0 'cookie) | 65 (aset retval 0 'cookie) |
57 (url-cookie-set-name retval (url-cookie-retrieve-arg :name args)) | 66 (url-cookie-set-name retval (url-cookie-retrieve-arg :name args)) |
58 (url-cookie-set-value retval (url-cookie-retrieve-arg :value args)) | 67 (url-cookie-set-value retval (url-cookie-retrieve-arg :value args)) |
59 (url-cookie-set-expires retval (url-cookie-retrieve-arg :expires args)) | 68 (url-cookie-set-expires retval (url-cookie-retrieve-arg :expires args)) |
60 (url-cookie-set-path retval (url-cookie-retrieve-arg :path args)) | 69 (url-cookie-set-localpart retval (url-cookie-retrieve-arg :localpart args)) |
61 (url-cookie-set-domain retval (url-cookie-retrieve-arg :domain args)) | 70 (url-cookie-set-domain retval (url-cookie-retrieve-arg :domain args)) |
62 (url-cookie-set-secure retval (url-cookie-retrieve-arg :secure args)) | 71 (url-cookie-set-secure retval (url-cookie-retrieve-arg :secure args)) |
63 retval)) | 72 retval)) |
64 | 73 |
65 (defun url-cookie-p (obj) | 74 (defun url-cookie-p (obj) |
75 "Return non-nil if OBJ is a cookie vector object. | |
76 These objects represent cookies in the URL package. | |
77 A cookie vector object is a vector of 7 slots: | |
78 [cookie NAME VALUE EXPIRES LOCALPART DOMAIN SECURE]." | |
66 (and (vectorp obj) (= (length obj) 7) (eq (aref obj 0) 'cookie))) | 79 (and (vectorp obj) (= (length obj) 7) (eq (aref obj 0) 'cookie))) |
67 | 80 |
68 (defgroup url-cookie nil | 81 (defgroup url-cookie nil |
69 "URL cookies" | 82 "URL cookies." |
70 :prefix "url-" | 83 :prefix "url-" |
71 :prefix "url-cookie-" | 84 :prefix "url-cookie-" |
72 :group 'url) | 85 :group 'url) |
73 | 86 |
74 (defvar url-cookie-storage nil "Where cookies are stored.") | 87 (defvar url-cookie-storage nil "Where cookies are stored.") |
75 (defvar url-cookie-secure-storage nil "Where secure cookies are stored.") | 88 (defvar url-cookie-secure-storage nil "Where secure cookies are stored.") |
76 (defcustom url-cookie-file nil "*Where cookies are stored on disk." | 89 (defcustom url-cookie-file nil |
90 "*File where cookies are stored on disk." | |
77 :type '(choice (const :tag "Default" :value nil) file) | 91 :type '(choice (const :tag "Default" :value nil) file) |
78 :group 'url-file | 92 :group 'url-file |
79 :group 'url-cookie) | 93 :group 'url-cookie) |
80 | 94 |
81 (defcustom url-cookie-confirmation nil | 95 (defcustom url-cookie-confirmation nil |
152 (pp url-cookie-secure-storage (current-buffer)) | 166 (pp url-cookie-secure-storage (current-buffer)) |
153 (insert ")\n") | 167 (insert ")\n") |
154 (write-file fname) | 168 (write-file fname) |
155 (kill-buffer (current-buffer)))))) | 169 (kill-buffer (current-buffer)))))) |
156 | 170 |
157 (defun url-cookie-store (name value &optional expires domain path secure) | 171 (defun url-cookie-store (name value &optional expires domain localpart secure) |
158 "Store a netscape-style cookie." | 172 "Store a netscape-style cookie." |
159 (let* ((storage (if secure url-cookie-secure-storage url-cookie-storage)) | 173 (let* ((storage (if secure url-cookie-secure-storage url-cookie-storage)) |
160 (tmp storage) | 174 (tmp storage) |
161 (cur nil) | 175 (cur nil) |
162 (found-domain nil)) | 176 (found-domain nil)) |
171 (setq storage (cdr found-domain) | 185 (setq storage (cdr found-domain) |
172 tmp nil) | 186 tmp nil) |
173 (while storage | 187 (while storage |
174 (setq cur (car storage) | 188 (setq cur (car storage) |
175 storage (cdr storage)) | 189 storage (cdr storage)) |
176 (if (and (equal path (url-cookie-path cur)) | 190 (if (and (equal localpart (url-cookie-localpart cur)) |
177 (equal name (url-cookie-name cur))) | 191 (equal name (url-cookie-name cur))) |
178 (progn | 192 (progn |
179 (url-cookie-set-expires cur expires) | 193 (url-cookie-set-expires cur expires) |
180 (url-cookie-set-value cur value) | 194 (url-cookie-set-value cur value) |
181 (setq tmp t)))) | 195 (setq tmp t)))) |
184 (setcdr found-domain (cons | 198 (setcdr found-domain (cons |
185 (url-cookie-create :name name | 199 (url-cookie-create :name name |
186 :value value | 200 :value value |
187 :expires expires | 201 :expires expires |
188 :domain domain | 202 :domain domain |
189 :path path | 203 :localpart localpart |
190 :secure secure) | 204 :secure secure) |
191 (cdr found-domain))))) | 205 (cdr found-domain))))) |
192 ;; Need to add a new top-level domain | 206 ;; Need to add a new top-level domain |
193 (setq tmp (url-cookie-create :name name | 207 (setq tmp (url-cookie-create :name name |
194 :value value | 208 :value value |
195 :expires expires | 209 :expires expires |
196 :domain domain | 210 :domain domain |
197 :path path | 211 :localpart localpart |
198 :secure secure)) | 212 :secure secure)) |
199 (cond | 213 (cond |
200 (storage | 214 (storage |
201 (setcdr storage (cons (list domain tmp) (cdr storage)))) | 215 (setcdr storage (cons (list domain tmp) (cdr storage)))) |
202 (secure | 216 (secure |
233 (* 60 (string-to-number (aref exp-time 1))) | 247 (* 60 (string-to-number (aref exp-time 1))) |
234 (* 1 (string-to-number (aref exp-time 0)))))) | 248 (* 1 (string-to-number (aref exp-time 0)))))) |
235 (> (- cur-norm exp-norm) 1)))))) | 249 (> (- cur-norm exp-norm) 1)))))) |
236 | 250 |
237 ;;;###autoload | 251 ;;;###autoload |
238 (defun url-cookie-retrieve (host path &optional secure) | 252 (defun url-cookie-retrieve (host localpart &optional secure) |
239 "Retrieve all the netscape-style cookies for a specified HOST and PATH." | 253 "Retrieve all the netscape-style cookies for a specified HOST and LOCALPART." |
240 (let ((storage (if secure | 254 (let ((storage (if secure |
241 (append url-cookie-secure-storage url-cookie-storage) | 255 (append url-cookie-secure-storage url-cookie-storage) |
242 url-cookie-storage)) | 256 url-cookie-storage)) |
243 (case-fold-search t) | 257 (case-fold-search t) |
244 (cookies nil) | 258 (cookies nil) |
245 (cur nil) | 259 (cur nil) |
246 (retval nil) | 260 (retval nil) |
247 (path-regexp nil)) | 261 (localpart-regexp nil)) |
248 (while storage | 262 (while storage |
249 (setq cur (car storage) | 263 (setq cur (car storage) |
250 storage (cdr storage) | 264 storage (cdr storage) |
251 cookies (cdr cur)) | 265 cookies (cdr cur)) |
252 (if (and (car cur) | 266 (if (and (car cur) |
253 (string-match (concat "^.*" (regexp-quote (car cur)) "$") host)) | 267 (string-match (concat "^.*" (regexp-quote (car cur)) "$") host)) |
254 ;; The domains match - a possible hit! | 268 ;; The domains match - a possible hit! |
255 (while cookies | 269 (while cookies |
256 (setq cur (car cookies) | 270 (setq cur (car cookies) |
257 cookies (cdr cookies) | 271 cookies (cdr cookies) |
258 path-regexp (concat "^" (regexp-quote | 272 localpart-regexp (concat "^" (regexp-quote |
259 (url-cookie-path cur)))) | 273 (url-cookie-localpart cur)))) |
260 (if (and (string-match path-regexp path) | 274 (if (and (string-match localpart-regexp localpart) |
261 (not (url-cookie-expired-p cur))) | 275 (not (url-cookie-expired-p cur))) |
262 (setq retval (cons cur retval)))))) | 276 (setq retval (cons cur retval)))))) |
263 retval)) | 277 retval)) |
264 | 278 |
265 ;;;###autoload | 279 ;;;###autoload |
266 (defun url-cookie-generate-header-lines (host path secure) | 280 (defun url-cookie-generate-header-lines (host localpart secure) |
267 (let* ((cookies (url-cookie-retrieve host path secure)) | 281 (let* ((cookies (url-cookie-retrieve host localpart secure)) |
268 (retval nil) | 282 (retval nil) |
269 (cur nil) | 283 (cur nil) |
270 (chunk nil)) | 284 (chunk nil)) |
271 ;; Have to sort this for sending most specific cookies first | 285 ;; Have to sort this for sending most specific cookies first |
272 (setq cookies (and cookies | 286 (setq cookies (and cookies |
273 (sort cookies | 287 (sort cookies |
274 (function | 288 (function |
275 (lambda (x y) | 289 (lambda (x y) |
276 (> (length (url-cookie-path x)) | 290 (> (length (url-cookie-localpart x)) |
277 (length (url-cookie-path y)))))))) | 291 (length (url-cookie-localpart y)))))))) |
278 (while cookies | 292 (while cookies |
279 (setq cur (car cookies) | 293 (setq cur (car cookies) |
280 cookies (cdr cookies) | 294 cookies (cdr cookies) |
281 chunk (format "%s=%s" (url-cookie-name cur) (url-cookie-value cur)) | 295 chunk (format "%s=%s" (url-cookie-name cur) (url-cookie-value cur)) |
282 retval (if (and url-cookie-multiple-line | 296 retval (if (and url-cookie-multiple-line |
338 (url-host url-current-object))) | 352 (url-host url-current-object))) |
339 (current-url (url-view-url t)) | 353 (current-url (url-view-url t)) |
340 (trusted url-cookie-trusted-urls) | 354 (trusted url-cookie-trusted-urls) |
341 (untrusted url-cookie-untrusted-urls) | 355 (untrusted url-cookie-untrusted-urls) |
342 (expires (cdr-safe (assoc-string "expires" args t))) | 356 (expires (cdr-safe (assoc-string "expires" args t))) |
343 (path (or (cdr-safe (assoc-string "path" args t)) | 357 (localpart (or (cdr-safe (assoc-string "path" args t)) |
344 (file-name-directory | 358 (file-name-directory |
345 (url-filename url-current-object)))) | 359 (url-filename url-current-object)))) |
346 (rest nil)) | 360 (rest nil)) |
347 (while args | 361 (while args |
348 (if (not (member (downcase (car (car args))) | 362 (if (not (member (downcase (car (car args))) |
349 '("secure" "domain" "expires" "path"))) | 363 '("secure" "domain" "expires" "path"))) |
350 (setq rest (cons (car args) rest))) | 364 (setq rest (cons (car args) rest))) |
420 ;; Cookie is accepted by the user, and passes our security checks | 434 ;; Cookie is accepted by the user, and passes our security checks |
421 (let ((cur nil)) | 435 (let ((cur nil)) |
422 (while rest | 436 (while rest |
423 (setq cur (pop rest)) | 437 (setq cur (pop rest)) |
424 (url-cookie-store (car cur) (cdr cur) | 438 (url-cookie-store (car cur) (cdr cur) |
425 expires domain path secure)))) | 439 expires domain localpart secure)))) |
426 (t | 440 (t |
427 (message "%s tried to set a cookie for domain %s - rejected." | 441 (message "%s tried to set a cookie for domain %s - rejected." |
428 (url-host url-current-object) domain))))) | 442 (url-host url-current-object) domain))))) |
429 | 443 |
430 (defvar url-cookie-timer nil) | 444 (defvar url-cookie-timer nil) |