1 ;;; url-domsuf.el --- Say what domain names can have cookies set.
3 ;; Copyright (C) 2011 Free Software Foundation, Inc.
5 ;; Keywords: comm, data, processes, hypermedia
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;; The rules for what domains can have cookies set is defined here:
25 ;; http://publicsuffix.org/list/
29 (defvar url-domsuf-domains nil
)
31 (defun url-domsuf-parse-file ()
34 (expand-file-name "publicsuffix.txt" data-directory
))
38 (when (not (looking-at "[/\n\t ]"))
39 ;; !pref.aichi.jp means that it's allowed.
40 (if (not (eq (following-char) ?
!))
44 (setq domain
(buffer-substring (point) (line-end-position)))
46 ((string-match "\\`\\*\\." domain
)
47 (setq domain
(substring domain
2))
48 (push (cons domain
(1+ (length (split-string domain
"[.]"))))
51 (push (cons domain t
) domains
))
53 (push (cons domain nil
) domains
))))
55 (setq url-domsuf-domains
(nreverse domains
)))))
57 (defun url-domsuf-cookie-allowed-p (domain)
58 (unless url-domsuf-domains
59 (url-domsuf-parse-file))
61 (domain-bits (split-string domain
"[.]"))
62 (length (length domain-bits
))
63 (upper-domain (mapconcat 'identity
(cdr domain-bits
) "."))
65 (dolist (elem url-domsuf-domains
)
66 (setq entry
(car elem
)
71 (string= domain entry
))
73 ;; "!pref.hokkaido.jp"
75 (string= domain entry
))
78 ((and (numberp modifier
)
80 (string= entry upper-domain
))
81 (setq allowedp nil
))))
86 ;; (url-domsuf-cookie-allowed-p "com") => nil
87 ;; (url-domsuf-cookie-allowed-p "foo.bar.ar") => t
88 ;; (url-domsuf-cookie-allowed-p "bar.ar") => nil
89 ;; (url-domsuf-cookie-allowed-p "co.uk") => nil
90 ;; (url-domsuf-cookie-allowed-p "foo.bar.hokkaido.jo") => t
91 ;; (url-domsuf-cookie-allowed-p "bar.hokkaido.jp") => nil
92 ;; (url-domsuf-cookie-allowed-p "pref.hokkaido.jp") => t
96 ;;; url-domsuf.el ends here