annotate lisp/w3/url-cookie.el @ 116:9f59509498e1 r20-1b10

Import from CVS: tag r20-1b10
author cvs
date Mon, 13 Aug 2007 09:23:06 +0200
parents 8619ce7e4c50
children 9b50b4588a93
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1 ;;; url-cookie.el --- Netscape Cookie support
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2 ;; Author: wmperry
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 114
diff changeset
3 ;; Created: 1997/03/26 00:06:01
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 114
diff changeset
4 ;; Version: 1.15
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
5 ;; Keywords: comm, data, processes, hypermedia
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
6
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
8 ;;; Copyright (c) 1996 by William M. Perry (wmperry@cs.indiana.edu)
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 14
diff changeset
9 ;;; Copyright (c) 1996, 1997 Free Software Foundation, Inc.
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
10 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
11 ;;; This file is not part of GNU Emacs, but the same permissions apply.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
12 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
13 ;;; GNU Emacs is free software; you can redistribute it and/or modify
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
14 ;;; it under the terms of the GNU General Public License as published by
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
15 ;;; the Free Software Foundation; either version 2, or (at your option)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
16 ;;; any later version.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
17 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
18 ;;; GNU Emacs is distributed in the hope that it will be useful,
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
19 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
20 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
21 ;;; GNU General Public License for more details.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
22 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
23 ;;; You should have received a copy of the GNU General Public License
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
24 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
25 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
26 ;;; Boston, MA 02111-1307, USA.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
28
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
29 (require 'timezone)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
30 (require 'cl)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
31
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 14
diff changeset
32 (eval-and-compile
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 14
diff changeset
33 (let ((keywords
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 14
diff changeset
34 '(:name :value :expires :path :domain :test :secure)))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 14
diff changeset
35 (while keywords
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 14
diff changeset
36 (or (boundp (car keywords))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 14
diff changeset
37 (set (car keywords) (car keywords)))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 14
diff changeset
38 (setq keywords (cdr keywords)))))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
39
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
40 ;; See http://home.netscape.com/newsref/std/cookie_spec.html for the
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
41 ;; 'open standard' defining this crap.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
42 ;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
43 ;; A cookie is stored internally as a vector of 7 slots
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
44 ;; [ 'cookie name value expires path domain secure ]
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
45
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
46 (defsubst url-cookie-name (cookie) (aref cookie 1))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
47 (defsubst url-cookie-value (cookie) (aref cookie 2))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
48 (defsubst url-cookie-expires (cookie) (aref cookie 3))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
49 (defsubst url-cookie-path (cookie) (aref cookie 4))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
50 (defsubst url-cookie-domain (cookie) (aref cookie 5))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
51 (defsubst url-cookie-secure (cookie) (aref cookie 6))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
52
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
53 (defsubst url-cookie-set-name (cookie val) (aset cookie 1 val))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
54 (defsubst url-cookie-set-value (cookie val) (aset cookie 2 val))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
55 (defsubst url-cookie-set-expires (cookie val) (aset cookie 3 val))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
56 (defsubst url-cookie-set-path (cookie val) (aset cookie 4 val))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
57 (defsubst url-cookie-set-domain (cookie val) (aset cookie 5 val))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
58 (defsubst url-cookie-set-secure (cookie val) (aset cookie 6 val))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
59 (defsubst url-cookie-retrieve-arg (key args) (nth 1 (memq key args)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
60
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
61 (defsubst url-cookie-create (&rest args)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
62 (let ((retval (make-vector 7 nil)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
63 (aset retval 0 'cookie)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
64 (url-cookie-set-name retval (url-cookie-retrieve-arg :name args))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
65 (url-cookie-set-value retval (url-cookie-retrieve-arg :value args))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
66 (url-cookie-set-expires retval (url-cookie-retrieve-arg :expires args))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
67 (url-cookie-set-path retval (url-cookie-retrieve-arg :path args))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
68 (url-cookie-set-domain retval (url-cookie-retrieve-arg :domain args))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
69 (url-cookie-set-secure retval (url-cookie-retrieve-arg :secure args))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
70 retval))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
71
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
72 (defun url-cookie-p (obj)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
73 (and (vectorp obj) (= (length obj) 7) (eq (aref obj 0) 'cookie)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
74
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
75 (defun url-cookie-parse-file (&optional fname)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
76 (setq fname (or fname url-cookie-file))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
77 (condition-case ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
78 (load fname nil t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
79 (error (message "Could not load cookie file %s" fname))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
80
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
81 (defun url-cookie-clean-up (&optional secure)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
82 (let* (
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
83 (var (if secure 'url-cookie-secure-storage 'url-cookie-storage))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
84 (val (symbol-value var))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
85 (cur nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
86 (new nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
87 (cookies nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
88 (cur-cookie nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
89 (new-cookies nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
90 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
91 (while val
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
92 (setq cur (car val)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
93 val (cdr val)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
94 new-cookies nil
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
95 cookies (cdr cur))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
96 (while cookies
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
97 (setq cur-cookie (car cookies)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
98 cookies (cdr cookies))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
99 (if (or (not (url-cookie-p cur-cookie))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
100 (url-cookie-expired-p cur-cookie)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
101 (null (url-cookie-expires cur-cookie)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
102 nil
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
103 (setq new-cookies (cons cur-cookie new-cookies))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
104 (if (not new-cookies)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
105 nil
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
106 (setcdr cur new-cookies)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
107 (setq new (cons cur new))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
108 (set var new)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
109
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 14
diff changeset
110 ;;###autoload
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
111 (defun url-cookie-write-file (&optional fname)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
112 (setq fname (or fname url-cookie-file))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
113 (url-cookie-clean-up)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
114 (url-cookie-clean-up t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
115 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
116 (set-buffer (get-buffer-create " *cookies*"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
117 (erase-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
118 (fundamental-mode)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
119 (insert ";; Emacs-W3 HTTP cookies file\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
120 ";; Automatically generated file!!! DO NOT EDIT!!!\n\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
121 "(setq url-cookie-storage\n '")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
122 (pp url-cookie-storage (current-buffer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
123 (insert ")\n(setq url-cookie-secure-storage\n '")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
124 (pp url-cookie-secure-storage (current-buffer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
125 (insert ")\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
126 (write-file fname)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
127 (kill-buffer (current-buffer))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
128
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
129 (defun url-cookie-store (name value &optional expires domain path secure)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
130 "Stores a netscape-style cookie"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
131 (let* ((storage (if secure url-cookie-secure-storage url-cookie-storage))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
132 (tmp storage)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
133 (cur nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
134 (found-domain nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
135
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
136 ;; First, look for a matching domain
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
137 (setq found-domain (assoc domain storage))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
138
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
139 (if found-domain
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
140 ;; Need to either stick the new cookie in existing domain storage
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
141 ;; or possibly replace an existing cookie if the names match.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
142 (progn
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
143 (setq storage (cdr found-domain)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
144 tmp nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
145 (while storage
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
146 (setq cur (car storage)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
147 storage (cdr storage))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
148 (if (and (equal path (url-cookie-path cur))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
149 (equal name (url-cookie-name cur)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
150 (progn
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
151 (url-cookie-set-expires cur expires)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
152 (url-cookie-set-value cur value)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
153 (setq tmp t))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
154 (if (not tmp)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
155 ;; New cookie
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
156 (setcdr found-domain (cons
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
157 (url-cookie-create :name name
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
158 :value value
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
159 :expires expires
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
160 :domain domain
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
161 :path path
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
162 :secure secure)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
163 (cdr found-domain)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
164 ;; Need to add a new top-level domain
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
165 (setq tmp (url-cookie-create :name name
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
166 :value value
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
167 :expires expires
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
168 :domain domain
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
169 :path path
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
170 :secure secure))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
171 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
172 (storage
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
173 (setcdr storage (cons (list domain tmp) (cdr storage))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
174 (secure
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
175 (setq url-cookie-secure-storage (list (list domain tmp))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
176 (t
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
177 (setq url-cookie-storage (list (list domain tmp))))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
178
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
179 (defun url-cookie-expired-p (cookie)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
180 (let* (
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
181 (exp (url-cookie-expires cookie))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
182 (cur-date (and exp (timezone-parse-date (current-time-string))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
183 (exp-date (and exp (timezone-parse-date exp)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
184 (cur-greg (and cur-date (timezone-absolute-from-gregorian
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
185 (string-to-int (aref cur-date 1))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
186 (string-to-int (aref cur-date 2))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
187 (string-to-int (aref cur-date 0)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
188 (exp-greg (and exp (timezone-absolute-from-gregorian
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
189 (string-to-int (aref exp-date 1))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
190 (string-to-int (aref exp-date 2))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
191 (string-to-int (aref exp-date 0)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
192 (diff-in-days (and exp (- cur-greg exp-greg)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
193 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
194 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
195 ((not exp) nil) ; No expiry == expires at browser quit
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
196 ((< diff-in-days 0) nil) ; Expires sometime after today
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
197 ((> diff-in-days 0) t) ; Expired before today
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
198 (t ; Expires sometime today, check times
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
199 (let* ((cur-time (timezone-parse-time (aref cur-date 3)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
200 (exp-time (timezone-parse-time (aref exp-date 3)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
201 (cur-norm (+ (* 360 (string-to-int (aref cur-time 2)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
202 (* 60 (string-to-int (aref cur-time 1)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
203 (* 1 (string-to-int (aref cur-time 0)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
204 (exp-norm (+ (* 360 (string-to-int (aref exp-time 2)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
205 (* 60 (string-to-int (aref exp-time 1)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
206 (* 1 (string-to-int (aref exp-time 0))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
207 (> (- cur-norm exp-norm) 1))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
208
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 14
diff changeset
209 ;;###autoload
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
210 (defun url-cookie-retrieve (host path &optional secure)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
211 "Retrieves all the netscape-style cookies for a specified HOST and PATH"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
212 (let ((storage (if secure
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
213 (append url-cookie-secure-storage url-cookie-storage)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
214 url-cookie-storage))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
215 (case-fold-search t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
216 (cookies nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
217 (cur nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
218 (retval nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
219 (path-regexp nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
220 (while storage
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
221 (setq cur (car storage)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
222 storage (cdr storage)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
223 cookies (cdr cur))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
224 (if (and (car cur)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
225 (string-match (concat "^.*" (regexp-quote (car cur)) "$") host))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
226 ;; The domains match - a possible hit!
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
227 (while cookies
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
228 (setq cur (car cookies)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
229 cookies (cdr cookies)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
230 path-regexp (concat "^" (regexp-quote
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
231 (url-cookie-path cur))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
232 (if (and (string-match path-regexp path)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
233 (not (url-cookie-expired-p cur)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
234 (setq retval (cons cur retval))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
235 retval))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
236
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 14
diff changeset
237 ;;###autolaod
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
238 (defun url-cookie-generate-header-lines (host path secure)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
239 (let* ((cookies (url-cookie-retrieve host path secure))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
240 (retval nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
241 (cur nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
242 (chunk nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
243 ;; Have to sort this for sending most specific cookies first
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
244 (setq cookies (and cookies
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
245 (sort cookies
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
246 (function
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
247 (lambda (x y)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
248 (> (length (url-cookie-path x))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
249 (length (url-cookie-path y))))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
250 (while cookies
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
251 (setq cur (car cookies)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
252 cookies (cdr cookies)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
253 chunk (format "%s=%s" (url-cookie-name cur) (url-cookie-value cur))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
254 retval (if (< 80 (+ (length retval) (length chunk) 4))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
255 (concat retval "\r\nCookie: " chunk)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
256 (if retval
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
257 (concat retval "; " chunk)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
258 (concat "Cookie: " chunk)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
259 (if retval
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
260 (concat retval "\r\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
261 "")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
262
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
263 (defvar url-cookie-two-dot-domains
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
264 (concat "\\.\\("
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
265 (mapconcat 'identity (list "com" "edu" "net" "org" "gov" "mil" "int")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
266 "\\|")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
267 "\\)$")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
268 "A regular expression of top-level domains that only require two matching
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
269 '.'s in the domain name in order to set a cookie.")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
270
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
271 (defvar url-cookie-trusted-urls nil
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
272 "*A list of regular expressions matching URLs to always accept cookies from.")
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
273
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
274 (defvar url-cookie-untrusted-urls nil
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
275 "*A list of regular expressions matching URLs to never accept cookies from.")
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
276
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
277 (defun url-cookie-host-can-set-p (host domain)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
278 (let ((numdots 0)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
279 (tmp domain)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
280 (last nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
281 (case-fold-search t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
282 (mindots 3))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
283 (while (setq last (string-match "\\." host last))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
284 (setq numdots (1+ numdots)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
285 last (1+ last)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
286 (if (string-match url-cookie-two-dot-domains domain)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
287 (setq mindots 2))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
288 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
289 ((string= host domain) ; Apparently netscape lets you do this
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
290 t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
291 ((< numdots mindots) ; Not enough dots in domain name!
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
292 nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
293 (t
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
294 (string-match (concat (regexp-quote domain) "$") host)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
295
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
296 (defun url-header-comparison (x y)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
297 (string= (downcase x) (downcase y)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
298
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 14
diff changeset
299 ;;###autoload
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
300 (defun url-cookie-handle-set-cookie (str)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
301 (let* ((args (mm-parse-args str nil t)) ; Don't downcase names
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
302 (case-fold-search t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
303 (secure (and (assoc* "secure" args :test 'url-header-comparison) t))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
304 (domain (or (cdr-safe (assoc* "domain" args :test
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
305 'url-header-comparison))
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 86
diff changeset
306 (url-host url-current-object)))
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
307 (current-url (url-view-url t))
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
308 (trusted url-cookie-trusted-urls)
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
309 (untrusted url-cookie-untrusted-urls)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
310 (expires (cdr-safe (assoc* "expires" args :test
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
311 'url-header-comparison)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
312 (path (or (cdr-safe (assoc* "path" args :test
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
313 'url-header-comparison))
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 86
diff changeset
314 (file-name-directory
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 86
diff changeset
315 (url-filename url-current-object))))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
316 (rest nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
317 (while args
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
318 (if (not (member (downcase (car (car args)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
319 '("secure" "domain" "expires" "path")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
320 (setq rest (cons (car args) rest)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
321 (setq args (cdr args)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
322
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
323 ;; Sometimes we get dates that the timezone package cannot handle very
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
324 ;; gracefully - take care of this here, instead of in url-cookie-expired-p
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
325 ;; to speed things up.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
326 (if (and expires
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
327 (string-match
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
328 (concat "^[^,]+, +\\(..\\)-\\(...\\)-\\(..\\) +"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
329 "\\(..:..:..\\) +\\[*\\([^\]]+\\)\\]*$")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
330 expires))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
331 (setq expires (concat (url-match expires 1) " "
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
332 (url-match expires 2) " "
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
333 (url-match expires 3) " "
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
334 (url-match expires 4) " ["
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
335 (url-match expires 5) "]")))
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
336 (while (consp trusted)
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
337 (if (string-match (car trusted) current-url)
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
338 (setq trusted (- (match-end 0) (match-beginning 0)))
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
339 (pop trusted)))
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
340 (while (consp untrusted)
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
341 (if (string-match (car untrusted) current-url)
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
342 (setq untrusted (- (match-end 0) (match-beginning 0)))
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
343 (pop untrusted)))
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
344 (if (and trusted untrusted)
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
345 ;; Choose the more specific match
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
346 (if (> trusted untrusted)
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
347 (setq untrusted nil)
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
348 (setq trusted nil)))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
349 (cond
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
350 (untrusted
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
351 ;; The site was explicity marked as untrusted by the user
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
352 nil)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
353 ((and (listp url-privacy-level) (memq 'cookies url-privacy-level))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
354 ;; user never wants cookies
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
355 nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
356 ((and url-cookie-confirmation
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
357 (not trusted)
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
358 (save-window-excursion
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
359 (with-output-to-temp-buffer "*Cookie Warning*"
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
360 (mapcar
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
361 (function
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
362 (lambda (x)
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
363 (princ (format "%s - %s" (car x) (cdr x))))) rest))
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
364 (prog1
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
365 (not (funcall url-confirmation-func
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
366 (format "Allow %s to set these cookies? "
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
367 (url-host url-current-object))))
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
368 (if (get-buffer "*Cookie Warning*")
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
369 (kill-buffer "*Cookie Warning*")))))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
370 ;; user wants to be asked, and declined.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
371 nil)
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 86
diff changeset
372 ((url-cookie-host-can-set-p (url-host url-current-object) domain)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
373 ;; Cookie is accepted by the user, and passes our security checks
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
374 (let ((cur nil))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
375 (while rest
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
376 (setq cur (pop rest))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
377 (url-cookie-store (car cur) (cdr cur)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
378 expires domain path secure))))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
379 (t
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
380 (url-warn 'url (format
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
381 (concat "%s tried to set a cookie for domain %s\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
382 "Permission denied - cookie rejected.\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
383 "Set-Cookie: %s")
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 86
diff changeset
384 (url-host url-current-object) domain str))))))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
385
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
386 (provide 'url-cookie)