Commit 9f8a95cd authored by Richard M. Stallman's avatar Richard M. Stallman
Browse files

(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.
parent e327a62d
......@@ -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 ]
(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))
(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:
(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 @@ telling Microsoft that."
(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 @@ telling Microsoft that."
(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)))
(url-cookie-set-expires cur expires)
......@@ -186,7 +200,7 @@ telling Microsoft that."
: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 @@ telling Microsoft that."
:value value
:expires expires
:domain domain
:path path
:localpart localpart
:secure secure))
......@@ -235,8 +249,8 @@ telling Microsoft that."
(> (- cur-norm exp-norm) 1))))))
(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)
......@@ -244,7 +258,7 @@ telling Microsoft that."
(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 @@ telling Microsoft that."
(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))))))
(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
(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 @@ telling Microsoft that."
(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))
(url-filename url-current-object))))
(localpart (or (cdr-safe (assoc-string "path" args t))
(url-filename url-current-object))))
(rest nil))
(while args
(if (not (member (downcase (car (car args)))
......@@ -422,7 +436,7 @@ telling Microsoft that."
(while rest
(setq cur (pop rest))
(url-cookie-store (car cur) (cdr cur)
expires domain path secure))))
expires domain localpart secure))))
(message "%s tried to set a cookie for domain %s - rejected."
(url-host url-current-object) domain)))))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment