2017-07-27 00:13:27 -04:00
|
|
|
|
;;; url-cookie.el --- URL cookie support -*- lexical-binding:t -*-
|
2004-04-12 04:03:06 +00:00
|
|
|
|
|
2019-01-01 00:59:58 +00:00
|
|
|
|
;; Copyright (C) 1996-1999, 2004-2019 Free Software Foundation, Inc.
|
2004-04-12 04:03:06 +00:00
|
|
|
|
|
2004-04-04 01:21:46 +00:00
|
|
|
|
;; Keywords: comm, data, processes, hypermedia
|
|
|
|
|
|
2004-04-12 04:03:06 +00:00
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
;;
|
2008-05-06 04:29:13 +00:00
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2004-04-12 04:03:06 +00:00
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 04:29:13 +00:00
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
2004-04-12 04:03:06 +00:00
|
|
|
|
;; 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.
|
2008-05-06 04:29:13 +00:00
|
|
|
|
|
2004-04-12 04:03:06 +00:00
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 15:52:52 -07:00
|
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2004-04-12 04:03:06 +00:00
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
|
|
|
|
(require 'url-util)
|
|
|
|
|
(require 'url-parse)
|
2012-04-10 03:57:45 +02:00
|
|
|
|
(require 'url-domsuf)
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(eval-when-compile (require 'cl-lib))
|
2010-12-16 13:14:48 +09:00
|
|
|
|
|
2004-04-04 01:21:46 +00:00
|
|
|
|
(defgroup url-cookie nil
|
2005-07-04 01:04:33 +00:00
|
|
|
|
"URL cookies."
|
2004-04-04 01:21:46 +00:00
|
|
|
|
:prefix "url-"
|
|
|
|
|
:prefix "url-cookie-"
|
|
|
|
|
:group 'url)
|
|
|
|
|
|
(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-06-12 18:24:25 +00:00
|
|
|
|
;; A cookie is stored internally as a vector of 7 slots
|
2011-05-29 10:45:03 +08:00
|
|
|
|
;; [ url-cookie NAME VALUE EXPIRES LOCALPART DOMAIN SECURE ]
|
(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-06-12 18:24:25 +00:00
|
|
|
|
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-defstruct (url-cookie
|
(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-06-12 18:24:25 +00:00
|
|
|
|
(:constructor url-cookie-create)
|
|
|
|
|
(:copier nil)
|
2011-05-29 10:45:03 +08:00
|
|
|
|
(:type vector)
|
|
|
|
|
:named)
|
(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-06-12 18:24:25 +00:00
|
|
|
|
name value expires localpart domain secure)
|
|
|
|
|
|
2004-04-04 01:21:46 +00:00
|
|
|
|
(defvar url-cookie-storage nil "Where cookies are stored.")
|
|
|
|
|
(defvar url-cookie-secure-storage nil "Where secure cookies are stored.")
|
2005-06-28 00:47:07 +00:00
|
|
|
|
(defcustom url-cookie-file nil
|
2006-07-11 15:03:24 +00:00
|
|
|
|
"File where cookies are stored on disk."
|
2004-04-04 01:21:46 +00:00
|
|
|
|
:type '(choice (const :tag "Default" :value nil) file)
|
|
|
|
|
:group 'url-file
|
|
|
|
|
:group 'url-cookie)
|
|
|
|
|
|
|
|
|
|
(defcustom url-cookie-confirmation nil
|
2006-07-11 15:03:24 +00:00
|
|
|
|
"If non-nil, confirmation by the user is required to accept HTTP cookies."
|
2004-04-04 01:21:46 +00:00
|
|
|
|
:type 'boolean
|
|
|
|
|
:group 'url-cookie)
|
|
|
|
|
|
|
|
|
|
(defcustom url-cookie-multiple-line nil
|
2006-07-11 15:03:24 +00:00
|
|
|
|
"If nil, HTTP requests put all cookies for the server on one line.
|
2004-04-04 01:21:46 +00:00
|
|
|
|
Some web servers, such as http://www.hotmail.com/, only accept cookies
|
2005-06-10 13:19:09 +00:00
|
|
|
|
when they are on one line. This is broken behavior, but just try
|
2005-05-19 17:59:58 +00:00
|
|
|
|
telling Microsoft that."
|
|
|
|
|
:type 'boolean
|
|
|
|
|
:group 'url-cookie)
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
|
|
|
|
(defvar url-cookies-changed-since-last-save nil
|
|
|
|
|
"Whether the cookies list has changed since the last save operation.")
|
|
|
|
|
|
|
|
|
|
(defun url-cookie-parse-file (&optional fname)
|
2010-12-13 20:18:22 -08:00
|
|
|
|
"Load FNAME, default `url-cookie-file'."
|
|
|
|
|
;; It's completely normal for the cookies file not to exist yet.
|
|
|
|
|
(load (or fname url-cookie-file) t t))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
2017-10-06 15:52:39 +02:00
|
|
|
|
(defun url-cookie-parse-file-netscape (filename &optional long-session)
|
|
|
|
|
"Load cookies from FILENAME in Netscape/Mozilla format.
|
|
|
|
|
When LONG-SESSION is non-nil, session cookies (expiring at t=0
|
|
|
|
|
i.e. 1970-1-1) are loaded as expiring one year from now instead."
|
|
|
|
|
(interactive "fLoad Netscape/Mozilla cookie file: ")
|
|
|
|
|
(let ((n 0))
|
|
|
|
|
(with-temp-buffer
|
|
|
|
|
(insert-file-contents-literally filename)
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(when (not (looking-at-p "# Netscape HTTP Cookie File\n"))
|
|
|
|
|
(error (format "File %s doesn't look like a netscape cookie file" filename)))
|
|
|
|
|
(while (not (eobp))
|
|
|
|
|
(when (not (looking-at-p (rx bol (* space) "#")))
|
|
|
|
|
(let* ((line (buffer-substring (point) (save-excursion (end-of-line) (point))))
|
|
|
|
|
(fields (split-string line "\t")))
|
|
|
|
|
(cond
|
|
|
|
|
;;((>= 1 (length line) 0)
|
|
|
|
|
;; (message "skipping empty line"))
|
|
|
|
|
((= (length fields) 7)
|
|
|
|
|
(let ((dom (nth 0 fields))
|
2017-10-10 14:57:37 -04:00
|
|
|
|
;; (match (nth 1 fields))
|
2017-10-06 15:52:39 +02:00
|
|
|
|
(path (nth 2 fields))
|
|
|
|
|
(secure (string= (nth 3 fields) "TRUE"))
|
|
|
|
|
;; session cookies (expire time = 0) are supposed
|
|
|
|
|
;; to be removed when the browser is closed, but
|
|
|
|
|
;; the main point of loading external cookie is to
|
|
|
|
|
;; reuse a browser session, so to prevent the
|
|
|
|
|
;; cookie from being detected as expired straight
|
|
|
|
|
;; away, make it expire a year from now
|
|
|
|
|
(expires (format-time-string
|
|
|
|
|
"%d %b %Y %T [GMT]"
|
Avoid some double-rounding of Lisp timestamps
Also, simplify some time-related Lisp timestamp code
while we’re in the neighborhood.
* lisp/battery.el (battery-linux-proc-acpi)
(battery-linux-sysfs, battery-upower, battery-bsd-apm):
* lisp/calendar/timeclock.el (timeclock-seconds-to-string)
(timeclock-log, timeclock-last-period)
(timeclock-entry-length, timeclock-entry-list-span)
(timeclock-find-discrep, timeclock-generate-report):
* lisp/cedet/ede/detect.el (ede-detect-qtest):
* lisp/completion.el (cmpl-hours-since-origin):
* lisp/ecomplete.el (ecomplete-decay-1):
* lisp/emacs-lisp/ert.el (ert--results-update-stats-display)
(ert--results-update-stats-display-maybe):
* lisp/emacs-lisp/timer-list.el (list-timers):
* lisp/emacs-lisp/timer.el (timer-until)
(timer-event-handler):
* lisp/erc/erc-backend.el (erc-server-send-ping)
(erc-server-send-queue, erc-handle-parsed-server-response)
(erc-handle-unknown-server-response):
* lisp/erc/erc-track.el (erc-buffer-visible):
* lisp/erc/erc.el (erc-lurker-cleanup, erc-lurker-p)
(erc-cmd-PING, erc-send-current-line):
* lisp/eshell/em-pred.el (eshell-pred-file-time):
* lisp/eshell/em-unix.el (eshell-show-elapsed-time):
* lisp/gnus/gnus-icalendar.el (gnus-icalendar-event:org-timestamp):
* lisp/gnus/gnus-int.el (gnus-backend-trace):
* lisp/gnus/gnus-sum.el (gnus-user-date):
* lisp/gnus/mail-source.el (mail-source-delete-crash-box):
* lisp/gnus/nnmaildir.el (nnmaildir--scan):
* lisp/ibuf-ext.el (ibuffer-mark-old-buffers):
* lisp/gnus/nnmaildir.el (nnmaildir--scan):
* lisp/mouse.el (mouse--down-1-maybe-follows-link)
(mouse--click-1-maybe-follows-link):
* lisp/mpc.el (mpc--faster-toggle):
* lisp/net/rcirc.el (rcirc-handler-ctcp-KEEPALIVE)
(rcirc-sentinel):
* lisp/net/tramp-cache.el (tramp-get-file-property):
* lisp/net/tramp-sh.el (tramp-sh-handle-file-newer-than-file-p)
(tramp-maybe-open-connection):
* lisp/net/tramp-smb.el (tramp-smb-maybe-open-connection):
* lisp/org/org-clock.el (org-clock-resolve):
(org-resolve-clocks, org-clock-in, org-clock-out, org-clock-sum):
* lisp/org/org-timer.el (org-timer-start)
(org-timer-pause-or-continue, org-timer-seconds):
* lisp/org/org.el (org-evaluate-time-range):
* lisp/org/ox-publish.el (org-publish-cache-ctime-of-src):
* lisp/pixel-scroll.el (pixel-scroll-in-rush-p):
* lisp/play/hanoi.el (hanoi-move-ring):
* lisp/proced.el (proced-format-time):
* lisp/progmodes/cpp.el (cpp-progress-message):
* lisp/progmodes/flymake.el (flymake--handle-report):
* lisp/progmodes/js.el (js--wait-for-matching-output):
* lisp/subr.el (progress-reporter-do-update):
* lisp/term/xterm.el (xterm--read-event-for-query):
* lisp/time.el (display-time-update, emacs-uptime):
* lisp/tooltip.el (tooltip-delay):
* lisp/url/url-cookie.el (url-cookie-parse-file-netscape):
* lisp/url/url-queue.el (url-queue-prune-old-entries):
* lisp/url/url.el (url-retrieve-synchronously):
* lisp/xt-mouse.el (xterm-mouse-event):
Avoid double-rounding of time-related values. Simplify.
* lisp/calendar/icalendar.el (icalendar--decode-isodatetime):
When hoping for the best (unlikely), use a better decoded time.
(icalendar--convert-sexp-to-ical): Avoid unnecessary encode-time.
* lisp/calendar/timeclock.el (timeclock-when-to-leave):
* lisp/cedet/ede/detect.el (ede-detect-qtest):
* lisp/desktop.el (desktop-create-buffer):
* lisp/emacs-lisp/benchmark.el (benchmark-elapse):
* lisp/gnus/gnus-art.el (article-lapsed-string):
* lisp/gnus/gnus-group.el (gnus-group-timestamp-delta):
* lisp/gnus/nnmail.el (nnmail-expired-article-p):
* lisp/gnus/nnmaildir.el (nnmaildir-request-expire-articles):
* lisp/nxml/rng-maint.el (rng-time-function):
* lisp/org/org-clock.el (org-clock-get-clocked-time)
(org-clock-resolve, org-resolve-clocks, org-resolve-clocks-if-idle):
* lisp/org/org-habit.el (org-habit-insert-consistency-graphs):
* lisp/progmodes/vhdl-mode.el (vhdl-update-progress-info)
(vhdl-fix-case-region-1):
Use time-since instead of open-coding most of it.
* lisp/erc/erc-dcc.el (erc-dcc-get-sentinel):
* lisp/erc/erc.el (erc-string-to-emacs-time, erc-time-gt):
Now obsolete. All uses changed.
(erc-time-diff): Accept all Lisp time values.
All uses changed.
* lisp/gnus/gnus-demon.el (gnus-demon-idle-since):
* lisp/gnus/gnus-score.el (gnus-score-headers):
* lisp/gnus/nneething.el (nneething-make-head):
* lisp/gnus/nnheader.el (nnheader-message-maybe):
* lisp/gnus/nnimap.el (nnimap-keepalive):
* lisp/image.el (image-animate-timeout):
* lisp/mail/feedmail.el (feedmail-rfc822-date):
* lisp/net/imap.el (imap-wait-for-tag):
* lisp/net/newst-backend.el (newsticker--image-get):
* lisp/net/rcirc.el (rcirc-handler-317, rcirc-handler-333):
* lisp/obsolete/xesam.el (xesam-refresh-entry):
* lisp/org/org-agenda.el (org-agenda-show-clocking-issues)
(org-agenda-check-clock-gap, org-agenda-to-appt):
* lisp/org/org-capture.el (org-capture-set-target-location):
* lisp/org/org-clock.el (org-clock-resolve-clock)
(org-clocktable-steps):
* lisp/org/org-colview.el (org-columns-edit-value)
(org-columns, org-agenda-columns):
* lisp/org/org-duration.el (org-duration-from-minutes):
* lisp/org/org-element.el (org-element-cache-sync-duration)
(org-element-cache-sync-break)
(org-element--cache-interrupt-p, org-element--cache-sync):
* lisp/org/org-habit.el (org-habit-get-faces)
* lisp/org/org-indent.el (org-indent-add-properties):
* lisp/org/org-table.el (org-table-sum):
* lisp/org/org-timer.el (org-timer-show-remaining-time)
(org-timer-set-timer):
* lisp/org/org.el (org-babel-load-file, org-today)
(org-auto-repeat-maybe, org-2ft, org-time-stamp)
(org-read-date-analyze, org-time-stamp-to-now)
(org-small-year-to-year, org-goto-calendar):
* lisp/org/ox.el (org-export-insert-default-template):
* lisp/ses.el (ses--time-check):
* lisp/type-break.el (type-break-time-warning)
(type-break-statistics, type-break-demo-boring):
* lisp/url/url-cache.el (url-cache-expired)
(url-cache-prune-cache):
* lisp/vc/vc-git.el (vc-git-stash-snapshot):
* lisp/erc/erc-match.el (erc-log-matches-come-back):
Simplify.
2019-02-22 18:32:31 -08:00
|
|
|
|
(let ((s (string-to-number (nth 4 fields))))
|
|
|
|
|
(if (and (zerop s) long-session)
|
|
|
|
|
(time-add nil (* 365 24 60 60))
|
|
|
|
|
s))))
|
2017-10-06 15:52:39 +02:00
|
|
|
|
(key (nth 5 fields))
|
|
|
|
|
(val (nth 6 fields)))
|
2017-10-10 14:57:37 -04:00
|
|
|
|
(cl-incf n)
|
2017-10-06 15:52:39 +02:00
|
|
|
|
;;(message "adding <%s>=<%s> exp=<%s> dom=<%s> path=<%s> sec=%S" key val expires dom path secure)
|
|
|
|
|
(url-cookie-store key val expires dom path secure)
|
|
|
|
|
))
|
|
|
|
|
(t
|
|
|
|
|
(message "ignoring malformed cookie line <%s>" line)))))
|
|
|
|
|
(forward-line))
|
|
|
|
|
(when (< 0 n)
|
|
|
|
|
(setq url-cookies-changed-since-last-save t))
|
|
|
|
|
(message "added %d cookies from file %s" n filename))))
|
|
|
|
|
|
2004-04-04 01:21:46 +00:00
|
|
|
|
(defun url-cookie-clean-up (&optional secure)
|
2010-12-13 20:18:22 -08:00
|
|
|
|
(let ((var (if secure 'url-cookie-secure-storage 'url-cookie-storage))
|
|
|
|
|
new new-cookies)
|
|
|
|
|
(dolist (cur (symbol-value var))
|
|
|
|
|
(setq new-cookies nil)
|
|
|
|
|
(dolist (cur-cookie (cdr cur))
|
|
|
|
|
(or (not (url-cookie-p cur-cookie))
|
|
|
|
|
(url-cookie-expired-p cur-cookie)
|
|
|
|
|
(null (url-cookie-expires cur-cookie))
|
|
|
|
|
(setq new-cookies (cons cur-cookie new-cookies))))
|
|
|
|
|
(when new-cookies
|
2004-04-04 01:21:46 +00:00
|
|
|
|
(setcdr cur new-cookies)
|
|
|
|
|
(setq new (cons cur new))))
|
|
|
|
|
(set var new)))
|
|
|
|
|
|
|
|
|
|
(defun url-cookie-write-file (&optional fname)
|
2018-04-15 21:50:38 +02:00
|
|
|
|
(when (and url-cookies-changed-since-last-save
|
|
|
|
|
url-cookie-file)
|
2007-12-11 05:49:10 +00:00
|
|
|
|
(or fname (setq fname (expand-file-name url-cookie-file)))
|
|
|
|
|
(if (condition-case nil
|
|
|
|
|
(progn
|
|
|
|
|
(url-make-private-file fname)
|
|
|
|
|
nil)
|
|
|
|
|
(error t))
|
|
|
|
|
(message "Error accessing cookie file `%s'" fname)
|
2004-04-04 01:21:46 +00:00
|
|
|
|
(url-cookie-clean-up)
|
|
|
|
|
(url-cookie-clean-up t)
|
2007-12-11 05:49:10 +00:00
|
|
|
|
(with-temp-buffer
|
2004-04-04 01:21:46 +00:00
|
|
|
|
(insert ";; Emacs-W3 HTTP cookies file\n"
|
|
|
|
|
";; Automatically generated file!!! DO NOT EDIT!!!\n\n"
|
|
|
|
|
"(setq url-cookie-storage\n '")
|
2015-01-17 18:42:31 +00:00
|
|
|
|
(let ((print-length nil) (print-level nil))
|
|
|
|
|
(pp url-cookie-storage (current-buffer))
|
|
|
|
|
(insert ")\n(setq url-cookie-secure-storage\n '")
|
|
|
|
|
(pp url-cookie-secure-storage (current-buffer)))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
(insert ")\n")
|
2006-08-29 14:00:27 +00:00
|
|
|
|
(insert "\n;; Local Variables:\n"
|
2006-07-11 15:03:24 +00:00
|
|
|
|
";; version-control: never\n"
|
|
|
|
|
";; no-byte-compile: t\n"
|
|
|
|
|
";; End:\n")
|
2006-08-29 14:00:27 +00:00
|
|
|
|
(set (make-local-variable 'version-control) 'never)
|
2007-12-11 05:49:10 +00:00
|
|
|
|
(write-file fname))
|
|
|
|
|
(setq url-cookies-changed-since-last-save nil))))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
2005-06-28 00:47:07 +00:00
|
|
|
|
(defun url-cookie-store (name value &optional expires domain localpart secure)
|
2010-12-13 20:18:22 -08:00
|
|
|
|
"Store a cookie."
|
2015-12-25 06:33:25 +01:00
|
|
|
|
(when (> (length name) 0)
|
|
|
|
|
(let ((storage (if secure url-cookie-secure-storage url-cookie-storage))
|
|
|
|
|
tmp found-domain)
|
|
|
|
|
;; First, look for a matching domain.
|
|
|
|
|
(if (setq found-domain (assoc domain storage))
|
|
|
|
|
;; Need to either stick the new cookie in existing domain storage
|
|
|
|
|
;; or possibly replace an existing cookie if the names match.
|
|
|
|
|
(unless (dolist (cur (setq storage (cdr found-domain)) tmp)
|
|
|
|
|
(and (equal localpart (url-cookie-localpart cur))
|
|
|
|
|
(equal name (url-cookie-name cur))
|
|
|
|
|
(progn
|
|
|
|
|
(setf (url-cookie-expires cur) expires)
|
|
|
|
|
(setf (url-cookie-value cur) value)
|
|
|
|
|
(setq tmp t))))
|
|
|
|
|
;; New cookie.
|
|
|
|
|
(setcdr found-domain (cons
|
|
|
|
|
(url-cookie-create :name name
|
|
|
|
|
:value value
|
|
|
|
|
:expires expires
|
|
|
|
|
:domain domain
|
|
|
|
|
:localpart localpart
|
|
|
|
|
:secure secure)
|
|
|
|
|
(cdr found-domain))))
|
|
|
|
|
;; Need to add a new top-level domain.
|
|
|
|
|
(setq tmp (url-cookie-create :name name
|
|
|
|
|
:value value
|
|
|
|
|
:expires expires
|
|
|
|
|
:domain domain
|
|
|
|
|
:localpart localpart
|
|
|
|
|
:secure secure))
|
|
|
|
|
(cond (storage
|
|
|
|
|
(setcdr storage (cons (list domain tmp) (cdr storage))))
|
|
|
|
|
(secure
|
|
|
|
|
(setq url-cookie-secure-storage (list (list domain tmp))))
|
|
|
|
|
(t
|
|
|
|
|
(setq url-cookie-storage (list (list domain tmp)))))))))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
|
|
|
|
(defun url-cookie-expired-p (cookie)
|
2010-09-08 22:38:43 -07:00
|
|
|
|
"Return non-nil if COOKIE is expired."
|
|
|
|
|
(let ((exp (url-cookie-expires cookie)))
|
2011-11-03 22:53:59 +01:00
|
|
|
|
(and (> (length exp) 0)
|
2014-08-03 08:38:52 -07:00
|
|
|
|
(condition-case ()
|
2017-11-08 21:30:26 -08:00
|
|
|
|
(time-less-p (date-to-time exp) nil)
|
2014-08-03 08:38:52 -07:00
|
|
|
|
(error nil)))))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
2009-01-14 20:47:02 +00:00
|
|
|
|
(defun url-cookie-retrieve (host &optional localpart secure)
|
2010-12-04 17:41:41 -05:00
|
|
|
|
"Retrieve all cookies for a specified HOST and LOCALPART."
|
2004-04-04 01:21:46 +00:00
|
|
|
|
(let ((storage (if secure
|
|
|
|
|
(append url-cookie-secure-storage url-cookie-storage)
|
|
|
|
|
url-cookie-storage))
|
|
|
|
|
(case-fold-search t)
|
2010-12-13 20:18:22 -08:00
|
|
|
|
cookies retval localpart-match)
|
|
|
|
|
(dolist (cur storage)
|
|
|
|
|
(setq cookies (cdr cur))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
(if (and (car cur)
|
2007-04-01 15:38:50 +00:00
|
|
|
|
(string-match
|
|
|
|
|
(concat "^.*"
|
|
|
|
|
(regexp-quote
|
|
|
|
|
;; Remove the dot from wildcard domains
|
|
|
|
|
;; before matching.
|
|
|
|
|
(if (eq ?. (aref (car cur) 0))
|
|
|
|
|
(substring (car cur) 1)
|
|
|
|
|
(car cur)))
|
|
|
|
|
"$") host))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
;; The domains match - a possible hit!
|
2010-12-13 20:18:22 -08:00
|
|
|
|
(dolist (cur cookies)
|
|
|
|
|
(and (if (and (stringp
|
|
|
|
|
(setq localpart-match (url-cookie-localpart cur)))
|
|
|
|
|
(stringp localpart))
|
|
|
|
|
(string-match (concat "^" (regexp-quote localpart-match))
|
|
|
|
|
localpart)
|
|
|
|
|
(equal localpart localpart-match))
|
|
|
|
|
(not (url-cookie-expired-p cur))
|
|
|
|
|
(setq retval (cons cur retval))))))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
retval))
|
|
|
|
|
|
2005-06-28 00:47:07 +00:00
|
|
|
|
(defun url-cookie-generate-header-lines (host localpart secure)
|
2010-12-13 20:18:22 -08:00
|
|
|
|
(let ((cookies (url-cookie-retrieve host localpart secure))
|
|
|
|
|
retval chunk)
|
|
|
|
|
;; Have to sort this for sending most specific cookies first.
|
2004-04-04 01:21:46 +00:00
|
|
|
|
(setq cookies (and cookies
|
|
|
|
|
(sort cookies
|
2010-12-13 20:18:22 -08:00
|
|
|
|
(lambda (x y)
|
|
|
|
|
(> (length (url-cookie-localpart x))
|
|
|
|
|
(length (url-cookie-localpart y)))))))
|
|
|
|
|
(dolist (cur cookies)
|
|
|
|
|
(setq chunk (format "%s=%s" (url-cookie-name cur) (url-cookie-value cur))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
retval (if (and url-cookie-multiple-line
|
|
|
|
|
(< 80 (+ (length retval) (length chunk) 4)))
|
|
|
|
|
(concat retval "\r\nCookie: " chunk)
|
|
|
|
|
(if retval
|
|
|
|
|
(concat retval "; " chunk)
|
|
|
|
|
(concat "Cookie: " chunk)))))
|
|
|
|
|
(if retval
|
|
|
|
|
(concat retval "\r\n")
|
|
|
|
|
"")))
|
|
|
|
|
|
|
|
|
|
(defcustom url-cookie-trusted-urls nil
|
2006-07-11 15:03:24 +00:00
|
|
|
|
"A list of regular expressions matching URLs to always accept cookies from."
|
2004-04-04 01:21:46 +00:00
|
|
|
|
:type '(repeat regexp)
|
|
|
|
|
:group 'url-cookie)
|
|
|
|
|
|
|
|
|
|
(defcustom url-cookie-untrusted-urls nil
|
2006-07-11 15:03:24 +00:00
|
|
|
|
"A list of regular expressions matching URLs to never accept cookies from."
|
2004-04-04 01:21:46 +00:00
|
|
|
|
:type '(repeat regexp)
|
|
|
|
|
:group 'url-cookie)
|
|
|
|
|
|
|
|
|
|
(defun url-cookie-host-can-set-p (host domain)
|
2017-07-27 00:13:27 -04:00
|
|
|
|
(cond
|
|
|
|
|
((string= host domain) ; Apparently netscape lets you do this
|
|
|
|
|
t)
|
|
|
|
|
((zerop (length domain))
|
|
|
|
|
nil)
|
|
|
|
|
(t
|
|
|
|
|
;; Remove the dot from wildcard domains before matching.
|
|
|
|
|
(when (eq ?. (aref domain 0))
|
|
|
|
|
(setq domain (substring domain 1)))
|
|
|
|
|
(and (url-domsuf-cookie-allowed-p domain)
|
|
|
|
|
(string-suffix-p domain host 'ignore-case)))))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
|
|
|
|
(defun url-cookie-handle-set-cookie (str)
|
|
|
|
|
(setq url-cookies-changed-since-last-save t)
|
2017-11-13 23:56:26 +00:00
|
|
|
|
(let* ((args (nreverse (url-parse-args str t)))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
(case-fold-search t)
|
2004-04-12 10:39:09 +00:00
|
|
|
|
(secure (and (assoc-string "secure" args t) t))
|
|
|
|
|
(domain (or (cdr-safe (assoc-string "domain" args t))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
(url-host url-current-object)))
|
|
|
|
|
(current-url (url-view-url t))
|
|
|
|
|
(trusted url-cookie-trusted-urls)
|
|
|
|
|
(untrusted url-cookie-untrusted-urls)
|
2017-11-13 23:56:26 +00:00
|
|
|
|
(max-age (cdr-safe (assoc-string "max-age" args t)))
|
2005-06-28 00:47:07 +00:00
|
|
|
|
(localpart (or (cdr-safe (assoc-string "path" args t))
|
|
|
|
|
(file-name-directory
|
|
|
|
|
(url-filename url-current-object))))
|
2017-11-13 23:56:26 +00:00
|
|
|
|
(expires nil))
|
|
|
|
|
(if (and max-age (string-match "\\`-?[0-9]+\\'" max-age))
|
|
|
|
|
(setq expires (format-time-string "%a %b %d %H:%M:%S %Y GMT"
|
|
|
|
|
(time-add nil (read max-age))
|
|
|
|
|
t))
|
|
|
|
|
(setq expires (cdr-safe (assoc-string "expires" args t))))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
(while (consp trusted)
|
|
|
|
|
(if (string-match (car trusted) current-url)
|
|
|
|
|
(setq trusted (- (match-end 0) (match-beginning 0)))
|
|
|
|
|
(pop trusted)))
|
|
|
|
|
(while (consp untrusted)
|
|
|
|
|
(if (string-match (car untrusted) current-url)
|
|
|
|
|
(setq untrusted (- (match-end 0) (match-beginning 0)))
|
|
|
|
|
(pop untrusted)))
|
2010-12-13 20:18:22 -08:00
|
|
|
|
(and trusted untrusted
|
|
|
|
|
;; Choose the more specific match.
|
|
|
|
|
(set (if (> trusted untrusted) 'untrusted 'trusted) nil))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
(cond
|
|
|
|
|
(untrusted
|
2011-12-11 21:32:49 -08:00
|
|
|
|
;; The site was explicitly marked as untrusted by the user.
|
2004-04-04 01:21:46 +00:00
|
|
|
|
nil)
|
|
|
|
|
((or (eq url-privacy-level 'paranoid)
|
|
|
|
|
(and (listp url-privacy-level) (memq 'cookies url-privacy-level)))
|
2010-12-13 20:18:22 -08:00
|
|
|
|
;; User never wants cookies.
|
2004-04-04 01:21:46 +00:00
|
|
|
|
nil)
|
|
|
|
|
((and url-cookie-confirmation
|
|
|
|
|
(not trusted)
|
|
|
|
|
(save-window-excursion
|
|
|
|
|
(with-output-to-temp-buffer "*Cookie Warning*"
|
2017-11-13 23:56:26 +00:00
|
|
|
|
(princ (format "%s=\"%s\"\n" (caar args) (cdar args)))
|
|
|
|
|
(dolist (x (cdr args))
|
|
|
|
|
(princ (format " %s=\"%s\"\n" (car x) (cdr x)))))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
(prog1
|
|
|
|
|
(not (funcall url-confirmation-func
|
|
|
|
|
(format "Allow %s to set these cookies? "
|
|
|
|
|
(url-host url-current-object))))
|
|
|
|
|
(if (get-buffer "*Cookie Warning*")
|
|
|
|
|
(kill-buffer "*Cookie Warning*")))))
|
2010-12-13 20:18:22 -08:00
|
|
|
|
;; User wants to be asked, and declined.
|
2004-04-04 01:21:46 +00:00
|
|
|
|
nil)
|
|
|
|
|
((url-cookie-host-can-set-p (url-host url-current-object) domain)
|
2010-12-13 20:18:22 -08:00
|
|
|
|
;; Cookie is accepted by the user, and passes our security checks.
|
2017-11-13 23:56:26 +00:00
|
|
|
|
(url-cookie-store (caar args) (cdar args)
|
|
|
|
|
expires domain localpart secure))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
(t
|
2010-10-01 16:49:14 +02:00
|
|
|
|
(url-lazy-message "%s tried to set a cookie for domain %s - rejected."
|
|
|
|
|
(url-host url-current-object) domain)))))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
|
|
|
|
(defvar url-cookie-timer nil)
|
|
|
|
|
|
|
|
|
|
(defcustom url-cookie-save-interval 3600
|
2006-07-11 15:03:24 +00:00
|
|
|
|
"The number of seconds between automatic saves of cookies.
|
2004-04-04 01:21:46 +00:00
|
|
|
|
Default is 1 hour. Note that if you change this variable outside of
|
|
|
|
|
the `customize' interface after `url-do-setup' has been run, you need
|
|
|
|
|
to run the `url-cookie-setup-save-timer' function manually."
|
2005-12-08 00:01:48 +00:00
|
|
|
|
:set #'(lambda (var val)
|
|
|
|
|
(set-default var val)
|
|
|
|
|
(if (bound-and-true-p url-setup-done)
|
|
|
|
|
(url-cookie-setup-save-timer)))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
:type 'integer
|
2006-07-11 15:03:24 +00:00
|
|
|
|
:group 'url-cookie)
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
|
|
|
|
(defun url-cookie-setup-save-timer ()
|
|
|
|
|
"Reset the cookie saver timer."
|
|
|
|
|
(interactive)
|
2005-12-08 00:01:48 +00:00
|
|
|
|
(ignore-errors (cancel-timer url-cookie-timer))
|
2004-04-12 04:03:06 +00:00
|
|
|
|
(setq url-cookie-timer nil)
|
|
|
|
|
(if url-cookie-save-interval
|
2005-12-08 00:01:48 +00:00
|
|
|
|
(setq url-cookie-timer (run-at-time url-cookie-save-interval
|
|
|
|
|
url-cookie-save-interval
|
|
|
|
|
#'url-cookie-write-file))))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
2016-02-23 12:51:24 +11:00
|
|
|
|
(defun url-cookie-delete-cookies (&optional regexp keep)
|
2016-02-21 16:57:04 +11:00
|
|
|
|
"Delete all cookies from the cookie store where the domain matches REGEXP.
|
2016-02-23 12:51:24 +11:00
|
|
|
|
If REGEXP is nil, all cookies are deleted. If KEEP is non-nil,
|
|
|
|
|
instead delete all cookies that do not match REGEXP."
|
2016-02-21 16:57:04 +11:00
|
|
|
|
(dolist (variable '(url-cookie-secure-storage url-cookie-storage))
|
|
|
|
|
(let ((cookies (symbol-value variable)))
|
|
|
|
|
(dolist (elem cookies)
|
2016-02-23 12:51:24 +11:00
|
|
|
|
(when (or (and (null keep)
|
|
|
|
|
(or (null regexp)
|
|
|
|
|
(string-match regexp (car elem))))
|
|
|
|
|
(and keep
|
|
|
|
|
regexp
|
|
|
|
|
(not (string-match regexp (car elem)))))
|
2016-02-21 16:57:04 +11:00
|
|
|
|
(setq cookies (delq elem cookies))))
|
|
|
|
|
(set variable cookies)))
|
|
|
|
|
(setq url-cookies-changed-since-last-save t)
|
|
|
|
|
(url-cookie-write-file))
|
|
|
|
|
|
2013-06-26 14:54:33 +02:00
|
|
|
|
;;; Mode for listing and editing cookies.
|
|
|
|
|
|
2018-04-15 22:48:28 +02:00
|
|
|
|
(defvar url-cookie--deleted-cookies nil)
|
|
|
|
|
|
2013-06-26 14:54:33 +02:00
|
|
|
|
(defun url-cookie-list ()
|
2014-02-04 23:46:40 -08:00
|
|
|
|
"Display a buffer listing the current URL cookies, if there are any.
|
2015-09-17 16:08:20 -07:00
|
|
|
|
Use \\<url-cookie-mode-map>\\[url-cookie-delete] to remove cookies."
|
2013-06-26 14:54:33 +02:00
|
|
|
|
(interactive)
|
2017-07-27 00:13:27 -04:00
|
|
|
|
(unless (or url-cookie-secure-storage
|
|
|
|
|
url-cookie-storage)
|
2013-06-26 14:54:33 +02:00
|
|
|
|
(error "No cookies are defined"))
|
|
|
|
|
|
|
|
|
|
(pop-to-buffer "*url cookies*")
|
2018-04-15 22:36:16 +02:00
|
|
|
|
(url-cookie-mode)
|
|
|
|
|
(url-cookie--generate-buffer)
|
|
|
|
|
(goto-char (point-min)))
|
|
|
|
|
|
|
|
|
|
(defun url-cookie--generate-buffer ()
|
2013-06-26 14:54:33 +02:00
|
|
|
|
(let ((inhibit-read-only t)
|
|
|
|
|
(domains (sort
|
|
|
|
|
(copy-sequence
|
|
|
|
|
(append url-cookie-secure-storage
|
|
|
|
|
url-cookie-storage))
|
|
|
|
|
(lambda (e1 e2)
|
|
|
|
|
(string< (car e1) (car e2)))))
|
|
|
|
|
(domain-length 0)
|
|
|
|
|
start name format domain)
|
|
|
|
|
(erase-buffer)
|
|
|
|
|
(dolist (elem domains)
|
|
|
|
|
(setq domain-length (max domain-length (length (car elem)))))
|
|
|
|
|
(setq format (format "%%-%ds %%-20s %%s" domain-length)
|
|
|
|
|
header-line-format
|
|
|
|
|
(concat " " (format format "Domain" "Name" "Value")))
|
|
|
|
|
(dolist (elem domains)
|
|
|
|
|
(setq domain (car elem))
|
|
|
|
|
(dolist (cookie (sort (copy-sequence (cdr elem))
|
|
|
|
|
(lambda (c1 c2)
|
|
|
|
|
(string< (url-cookie-name c1)
|
|
|
|
|
(url-cookie-name c2)))))
|
2018-04-15 22:36:16 +02:00
|
|
|
|
(setq start (point)
|
2013-06-26 14:54:33 +02:00
|
|
|
|
name (url-cookie-name cookie))
|
2018-04-15 22:36:16 +02:00
|
|
|
|
(when (> (length name) 20)
|
2013-06-26 14:54:33 +02:00
|
|
|
|
(setq name (substring name 0 20)))
|
2018-04-15 22:36:16 +02:00
|
|
|
|
(insert (format format domain name
|
|
|
|
|
(url-cookie-value cookie))
|
|
|
|
|
"\n")
|
|
|
|
|
(setq domain "")
|
|
|
|
|
(put-text-property start (1+ start) 'url-cookie cookie)))))
|
2013-06-26 14:54:33 +02:00
|
|
|
|
|
|
|
|
|
(defun url-cookie-delete ()
|
|
|
|
|
"Delete the cookie on the current line."
|
|
|
|
|
(interactive)
|
|
|
|
|
(let ((cookie (get-text-property (line-beginning-position) 'url-cookie))
|
|
|
|
|
(inhibit-read-only t)
|
|
|
|
|
variable)
|
|
|
|
|
(unless cookie
|
|
|
|
|
(error "No cookie on the current line"))
|
|
|
|
|
(setq variable (if (url-cookie-secure cookie)
|
|
|
|
|
'url-cookie-secure-storage
|
|
|
|
|
'url-cookie-storage))
|
|
|
|
|
(let* ((list (symbol-value variable))
|
|
|
|
|
(elem (assoc (url-cookie-domain cookie) list)))
|
|
|
|
|
(setq elem (delq cookie elem))
|
|
|
|
|
(when (zerop (length (cdr elem)))
|
|
|
|
|
(setq list (delq elem list)))
|
|
|
|
|
(set variable list))
|
|
|
|
|
(setq url-cookies-changed-since-last-save t)
|
|
|
|
|
(url-cookie-write-file)
|
|
|
|
|
(delete-region (line-beginning-position)
|
|
|
|
|
(progn
|
|
|
|
|
(forward-line 1)
|
2018-04-15 22:36:16 +02:00
|
|
|
|
(point)))
|
|
|
|
|
(let ((point (point)))
|
|
|
|
|
(erase-buffer)
|
|
|
|
|
(url-cookie--generate-buffer)
|
2018-04-15 22:48:28 +02:00
|
|
|
|
(goto-char point))
|
|
|
|
|
(push cookie url-cookie--deleted-cookies)))
|
|
|
|
|
|
|
|
|
|
(defun url-cookie-undo ()
|
|
|
|
|
"Undo deletion of a cookie."
|
|
|
|
|
(interactive)
|
|
|
|
|
(unless url-cookie--deleted-cookies
|
|
|
|
|
(error "No cookie deletions to undo"))
|
|
|
|
|
(let* ((cookie (pop url-cookie--deleted-cookies))
|
|
|
|
|
(variable (if (url-cookie-secure cookie)
|
|
|
|
|
'url-cookie-secure-storage
|
|
|
|
|
'url-cookie-storage))
|
|
|
|
|
(list (symbol-value variable))
|
|
|
|
|
(elem (assoc (url-cookie-domain cookie) list)))
|
|
|
|
|
(if elem
|
|
|
|
|
(nconc elem (list cookie))
|
|
|
|
|
(setq elem (list (url-cookie-domain cookie) cookie))
|
|
|
|
|
(set variable (cons elem list)))
|
|
|
|
|
(setq url-cookies-changed-since-last-save t)
|
|
|
|
|
(url-cookie-write-file)
|
|
|
|
|
(let ((point (point))
|
|
|
|
|
(inhibit-read-only t))
|
|
|
|
|
(erase-buffer)
|
|
|
|
|
(url-cookie--generate-buffer)
|
2018-04-15 22:36:16 +02:00
|
|
|
|
(goto-char point))))
|
2013-06-26 14:54:33 +02:00
|
|
|
|
|
|
|
|
|
(defvar url-cookie-mode-map
|
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
|
(define-key map [delete] 'url-cookie-delete)
|
2013-06-26 18:54:48 +02:00
|
|
|
|
(define-key map [(control k)] 'url-cookie-delete)
|
2018-04-15 22:48:28 +02:00
|
|
|
|
(define-key map [(control _)] 'url-cookie-undo)
|
2013-06-26 14:54:33 +02:00
|
|
|
|
map))
|
|
|
|
|
|
2017-07-27 00:13:27 -04:00
|
|
|
|
(define-derived-mode url-cookie-mode special-mode "URL Cookie"
|
2013-06-26 14:54:33 +02:00
|
|
|
|
"Mode for listing cookies.
|
|
|
|
|
|
|
|
|
|
\\{url-cookie-mode-map}"
|
|
|
|
|
(buffer-disable-undo)
|
|
|
|
|
(setq buffer-read-only t
|
|
|
|
|
truncate-lines t))
|
|
|
|
|
|
2004-04-04 01:21:46 +00:00
|
|
|
|
(provide 'url-cookie)
|
|
|
|
|
|
2004-04-12 04:03:06 +00:00
|
|
|
|
;;; url-cookie.el ends here
|