;; '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
(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)
(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)
(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)
:value value
:expires expires
:domain domain
- :path path
+ :localpart localpart
:secure secure)
(cdr found-domain)))))
;; Need to add a new top-level domain
:value value
:expires expires
:domain domain
- :path path
+ :localpart localpart
:secure secure))
(cond
(storage
(> (- 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))
(cookies nil)
(cur nil)
(retval nil)
- (path-regexp nil))
+ (localpart-regexp nil))
(while storage
(setq cur (car storage)
storage (cdr storage)
(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)
(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)))
(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)))))