changeset 63801:c234ee23e519

(url-cookie-store): Rename arg PATH to LOCALPART. (url-cookie-retrieve): Likewise. (url-cookie-generate-header-lines): Likewise. (url-cookie-handle-set-cookie): Likewise. (url-cookie-create): Expect :localpart instead of :path. (url-cookie-localpart): Renamed from url-cookie-path. (url-cookie-set-localpart): Renamed from url-cookie-set-path. (url-cookie-file): Doc fix. (url-cookie-p): Add doc string.
author Richard M. Stallman <rms@gnu.org>
date Tue, 28 Jun 2005 00:47:07 +0000
parents b9819eae04f1
children 58812680c2fd
files lisp/url/url-cookie.el
diffstat 1 files changed, 40 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/url/url-cookie.el	Mon Jun 27 21:57:00 2005 +0000
+++ b/lisp/url/url-cookie.el	Tue Jun 28 00:47:07 2005 +0000
@@ -34,35 +34,48 @@
 ;; 'open standard' defining this crap.
 ;;
 ;; A cookie is stored internally as a vector of 7 slots
-;; [ 'cookie name value expires path domain secure ]
+;; [ 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-path    (cookie) (aref cookie 4))
+(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-path    (cookie val) (aset cookie 4 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-path retval (url-cookie-retrieve-arg :path 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
@@ -73,7 +86,8 @@
 
 (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         "*Where cookies are stored on disk."
+(defcustom url-cookie-file nil
+  "*File where cookies are stored on disk."
   :type '(choice (const :tag "Default" :value nil) file)
   :group 'url-file
   :group 'url-cookie)
@@ -154,7 +168,7 @@
       (write-file fname)
       (kill-buffer (current-buffer))))))
 
-(defun url-cookie-store (name value &optional expires domain path secure)
+(defun url-cookie-store (name value &optional expires domain localpart secure)
   "Store a netscape-style cookie."
   (let* ((storage (if secure url-cookie-secure-storage url-cookie-storage))
 	 (tmp storage)
@@ -173,7 +187,7 @@
 	  (while storage
 	    (setq cur (car storage)
 		  storage (cdr storage))
-	    (if (and (equal path (url-cookie-path cur))
+	    (if (and (equal localpart (url-cookie-localpart cur))
 		     (equal name (url-cookie-name cur)))
 		(progn
 		  (url-cookie-set-expires cur expires)
@@ -186,7 +200,7 @@
 						       :value value
 						       :expires expires
 						       :domain domain
-						       :path path
+						       :localpart localpart
 						       :secure secure)
 				    (cdr found-domain)))))
       ;; Need to add a new top-level domain
@@ -194,7 +208,7 @@
 				   :value value
 				   :expires expires
 				   :domain domain
-				   :path path
+				   :localpart localpart
 				   :secure secure))
       (cond
        (storage
@@ -235,8 +249,8 @@
 	(> (- cur-norm exp-norm) 1))))))
 
 ;;;###autoload
-(defun url-cookie-retrieve (host path &optional secure)
-  "Retrieve all the netscape-style cookies for a specified HOST and PATH."
+(defun url-cookie-retrieve (host localpart &optional secure)
+  "Retrieve all the netscape-style cookies for a specified HOST and LOCALPART."
   (let ((storage (if secure
 		     (append url-cookie-secure-storage url-cookie-storage)
 		   url-cookie-storage))
@@ -244,7 +258,7 @@
 	(cookies nil)
 	(cur nil)
 	(retval nil)
-	(path-regexp nil))
+	(localpart-regexp nil))
     (while storage
       (setq cur (car storage)
 	    storage (cdr storage)
@@ -255,26 +269,26 @@
 	  (while cookies
 	    (setq cur (car cookies)
 		  cookies (cdr cookies)
-		  path-regexp (concat "^" (regexp-quote
-					   (url-cookie-path cur))))
-	    (if (and (string-match path-regexp path)
+		  localpart-regexp (concat "^" (regexp-quote
+						(url-cookie-localpart cur))))
+	    (if (and (string-match localpart-regexp localpart)
 		     (not (url-cookie-expired-p cur)))
 		(setq retval (cons cur retval))))))
     retval))
 
 ;;;###autoload
-(defun url-cookie-generate-header-lines (host path secure)
-  (let* ((cookies (url-cookie-retrieve host path secure))
-	(retval nil)
-	(cur nil)
-	(chunk nil))
+(defun url-cookie-generate-header-lines (host localpart secure)
+  (let* ((cookies (url-cookie-retrieve host localpart secure))
+	 (retval nil)
+	 (cur nil)
+	 (chunk nil))
     ;; Have to sort this for sending most specific cookies first
     (setq cookies (and cookies
 		       (sort cookies
 			     (function
 			      (lambda (x y)
-				(> (length (url-cookie-path x))
-				   (length (url-cookie-path y))))))))
+				(> (length (url-cookie-localpart x))
+				   (length (url-cookie-localpart y))))))))
     (while cookies
       (setq cur (car cookies)
 	    cookies (cdr cookies)
@@ -340,9 +354,9 @@
 	 (trusted url-cookie-trusted-urls)
 	 (untrusted url-cookie-untrusted-urls)
 	 (expires (cdr-safe (assoc-string "expires" args t)))
-	 (path (or (cdr-safe (assoc-string "path" args t))
-		   (file-name-directory
-		    (url-filename url-current-object))))
+	 (localpart (or (cdr-safe (assoc-string "path" args t))
+			(file-name-directory
+			 (url-filename url-current-object))))
 	 (rest nil))
     (while args
       (if (not (member (downcase (car (car args)))
@@ -422,7 +436,7 @@
 	(while rest
 	  (setq cur (pop rest))
 	  (url-cookie-store (car cur) (cdr cur)
-			    expires domain path secure))))
+			    expires domain localpart secure))))
      (t
       (message "%s tried to set a cookie for domain %s - rejected."
 	       (url-host url-current-object) domain)))))