;;; url-cookie.el --- Netscape Cookie support
-;; Copyright (C) 1996, 1997, 1998, 1999, 2004,
-;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 1996, 1997, 1998, 1999, 2004, 2005, 2006, 2007, 2008,
+;; 2009, 2010 Free Software Foundation, Inc.
;; Keywords: comm, data, processes, hypermedia
;; This file is part of GNU Emacs.
;;
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
-;;
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
-;;
+
;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;; Code:
-(require 'timezone)
(require 'url-util)
(require 'url-parse)
(eval-when-compile (require 'cl))
(setq url-cookie-storage (list (list domain tmp))))))))
(defun url-cookie-expired-p (cookie)
- (let* (
- (exp (url-cookie-expires cookie))
- (cur-date (and exp (timezone-parse-date (current-time-string))))
- (exp-date (and exp (timezone-parse-date exp)))
- (cur-greg (and cur-date (timezone-absolute-from-gregorian
- (string-to-number (aref cur-date 1))
- (string-to-number (aref cur-date 2))
- (string-to-number (aref cur-date 0)))))
- (exp-greg (and exp (timezone-absolute-from-gregorian
- (string-to-number (aref exp-date 1))
- (string-to-number (aref exp-date 2))
- (string-to-number (aref exp-date 0)))))
- (diff-in-days (and exp (- cur-greg exp-greg)))
- )
- (cond
- ((not exp) nil) ; No expiry == expires at browser quit
- ((< diff-in-days 0) nil) ; Expires sometime after today
- ((> diff-in-days 0) t) ; Expired before today
- (t ; Expires sometime today, check times
- (let* ((cur-time (timezone-parse-time (aref cur-date 3)))
- (exp-time (timezone-parse-time (aref exp-date 3)))
- (cur-norm (+ (* 360 (string-to-number (aref cur-time 2)))
- (* 60 (string-to-number (aref cur-time 1)))
- (* 1 (string-to-number (aref cur-time 0)))))
- (exp-norm (+ (* 360 (string-to-number (aref exp-time 2)))
- (* 60 (string-to-number (aref exp-time 1)))
- (* 1 (string-to-number (aref exp-time 0))))))
- (> (- cur-norm exp-norm) 1))))))
-
-(defun url-cookie-retrieve (host localpart &optional secure)
+ "Return non-nil if COOKIE is expired."
+ (let ((exp (url-cookie-expires cookie)))
+ (and exp (> (float-time) (float-time (date-to-time exp))))))
+
+(defun url-cookie-retrieve (host &optional localpart 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)
(cookies nil)
(cur nil)
(retval nil)
- (localpart-regexp nil))
+ (localpart-match nil))
(while storage
(setq cur (car storage)
storage (cdr storage)
(while cookies
(setq cur (car cookies)
cookies (cdr cookies)
- localpart-regexp (concat "^" (regexp-quote
- (url-cookie-localpart cur))))
- (if (and (string-match localpart-regexp localpart)
+ localpart-match (url-cookie-localpart cur))
+ (if (and (if (stringp localpart-match)
+ (string-match (concat "^" (regexp-quote
+ localpart-match))
+ localpart)
+ (equal localpart localpart-match))
(not (url-cookie-expired-p cur)))
(setq retval (cons cur retval))))))
retval))
(url-cookie-store (car cur) (cdr cur)
expires domain localpart secure))))
(t
- (message "%s tried to set a cookie for domain %s - rejected."
- (url-host url-current-object) domain)))))
+ (url-lazy-message "%s tried to set a cookie for domain %s - rejected."
+ (url-host url-current-object) domain)))))
(defvar url-cookie-timer nil)