changeset 81328:99942c448a6f

(url-cookie-name, url-cookie-value, url-cookie-expires, url-cookie-localpart) (url-cookie-domain, url-cookie-secure, url-cookie-set-name) (url-cookie-set-value, url-cookie-set-expires, url-cookie-set-localpart) (url-cookie-set-domain, url-cookie-set-secure, url-cookie-retrieve-arg) (url-cookie-create, url-cookie-p): Remove. (url-cookie): New struct. (url-cookie-store): Use setf instead of url-cookie-set-*.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Tue, 12 Jun 2007 18:24:25 +0000
parents f43a57ce897e
children 465e2d55267d
files lisp/url/ChangeLog lisp/url/url-cookie.el
diffstat 2 files changed, 27 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/url/ChangeLog	Tue Jun 12 16:33:39 2007 +0000
+++ b/lisp/url/ChangeLog	Tue Jun 12 18:24:25 2007 +0000
@@ -1,3 +1,14 @@
+2007-06-12  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+	* url-cookie.el (url-cookie-name, url-cookie-value)
+	(url-cookie-expires, url-cookie-localpart, url-cookie-domain)
+	(url-cookie-secure, url-cookie-set-name, url-cookie-set-value)
+	(url-cookie-set-expires, url-cookie-set-localpart)
+	(url-cookie-set-domain, url-cookie-set-secure)
+	(url-cookie-retrieve-arg, url-cookie-create, url-cookie-p): Remove.
+	(url-cookie): New struct.
+	(url-cookie-store): Use setf instead of url-cookie-set-*.
+
 2007-05-29  Chong Yidong  <cyd@stupidchicken.com>
 
 	* url-mailto.el (url-mailto): Insert body after
--- a/lisp/url/url-cookie.el	Tue Jun 12 16:33:39 2007 +0000
+++ b/lisp/url/url-cookie.el	Tue Jun 12 18:24:25 2007 +0000
@@ -33,51 +33,6 @@
 
 ;; See http://home.netscape.com/newsref/std/cookie_spec.html for the
 ;; 'open standard' defining this crap.
-;;
-;; A cookie is stored internally as a vector of 7 slots
-;; [ cookie NAME VALUE EXPIRES LOCALPART DOMAIN SECURE ]
-
-(defsubst url-cookie-name    (cookie) (aref cookie 1))
-(defsubst url-cookie-value   (cookie) (aref cookie 2))
-(defsubst url-cookie-expires (cookie) (aref cookie 3))
-(defsubst url-cookie-localpart    (cookie) (aref cookie 4))
-(defsubst url-cookie-domain  (cookie) (aref cookie 5))
-(defsubst url-cookie-secure  (cookie) (aref cookie 6))
-
-(defsubst url-cookie-set-name    (cookie val) (aset cookie 1 val))
-(defsubst url-cookie-set-value   (cookie val) (aset cookie 2 val))
-(defsubst url-cookie-set-expires (cookie val) (aset cookie 3 val))
-(defsubst url-cookie-set-localpart (cookie val) (aset cookie 4 val))
-(defsubst url-cookie-set-domain  (cookie val) (aset cookie 5 val))
-(defsubst url-cookie-set-secure  (cookie val) (aset cookie 6 val))
-(defsubst url-cookie-retrieve-arg (key args) (nth 1 (memq key args)))
-
-(defsubst url-cookie-create (&rest args)
-  "Create a cookie vector object from keyword-value pairs ARGS.
-The keywords allowed are
-  :name NAME
-  :value VALUE
-  :expires TIME
-  :localpart LOCALPAR
-  :domain DOMAIN
-  :secure ???
-Could someone fill in more information?"
-  (let ((retval (make-vector 7 nil)))
-    (aset retval 0 'cookie)
-    (url-cookie-set-name retval (url-cookie-retrieve-arg :name args))
-    (url-cookie-set-value retval (url-cookie-retrieve-arg :value args))
-    (url-cookie-set-expires retval (url-cookie-retrieve-arg :expires args))
-    (url-cookie-set-localpart retval (url-cookie-retrieve-arg :localpart args))
-    (url-cookie-set-domain retval (url-cookie-retrieve-arg :domain args))
-    (url-cookie-set-secure retval (url-cookie-retrieve-arg :secure args))
-    retval))
-
-(defun url-cookie-p (obj)
-  "Return non-nil if OBJ is a cookie vector object.
-These objects represent cookies in the URL package.
-A cookie vector object is a vector of 7 slots:
- [cookie NAME VALUE EXPIRES LOCALPART DOMAIN SECURE]."
-  (and (vectorp obj) (= (length obj) 7) (eq (aref obj 0) 'cookie)))
 
 (defgroup url-cookie nil
   "URL cookies."
@@ -85,6 +40,20 @@
   :prefix "url-cookie-"
   :group 'url)
 
+;; A cookie is stored internally as a vector of 7 slots
+;; [ cookie NAME VALUE EXPIRES LOCALPART DOMAIN SECURE ]
+
+(defstruct (url-cookie
+            (:constructor url-cookie-create)
+            (:copier nil)
+            ;; For compatibility with a previous version which did not use
+            ;; defstruct, and also in order to make sure that the printed
+            ;; representation does not depend on CL internals, we use an
+            ;; explicitly managed tag.
+            (:type vector))
+  (tag 'cookie :read-only t)
+  name value expires localpart domain secure)
+
 (defvar url-cookie-storage nil         "Where cookies are stored.")
 (defvar url-cookie-secure-storage nil  "Where secure cookies are stored.")
 (defcustom url-cookie-file nil
@@ -199,8 +168,8 @@
 	    (if (and (equal localpart (url-cookie-localpart cur))
 		     (equal name (url-cookie-name cur)))
 		(progn
-		  (url-cookie-set-expires cur expires)
-		  (url-cookie-set-value cur value)
+		  (setf (url-cookie-expires cur) expires)
+		  (setf (url-cookie-value cur) value)
 		  (setq tmp t))))
 	  (if (not tmp)
 	      ;; New cookie