Mercurial > emacs
annotate lisp/url/url-ns.el @ 94837:55eb2a3c59b4
Merge from gnus--devo--0
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-1153
author | Miles Bader <miles@gnu.org> |
---|---|
date | Sat, 10 May 2008 05:34:55 +0000 |
parents | 8259d0d8e107 |
children | a9dc0e7c3f2b |
rev | line source |
---|---|
54695 | 1 ;;; url-ns.el --- Various netscape-ish functions for proxy definitions |
57612 | 2 |
68640
e8a3fb527b77
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64748
diff
changeset
|
3 ;; Copyright (C) 1997, 1998, 1999, 2004, 2005, |
79720 | 4 ;; 2006, 2007, 2008 Free Software Foundation, Inc. |
57612 | 5 |
54695 | 6 ;; Keywords: comm, data, processes, hypermedia |
7 | |
57612 | 8 ;; This file is part of GNU Emacs. |
9 | |
94668
8259d0d8e107
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
10 ;; GNU Emacs is free software: you can redistribute it and/or modify |
57612 | 11 ;; it under the terms of the GNU General Public License as published by |
94668
8259d0d8e107
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
12 ;; the Free Software Foundation, either version 3 of the License, or |
8259d0d8e107
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
13 ;; (at your option) any later version. |
57612 | 14 |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
94668
8259d0d8e107
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
57612 | 22 |
23 ;;; Code: | |
54695 | 24 |
25 (require 'url-gw) | |
26 | |
27 ;;;###autoload | |
28 (defun isPlainHostName (host) | |
29 (not (string-match "\\." host))) | |
30 | |
31 ;;;###autoload | |
32 (defun dnsDomainIs (host dom) | |
33 (string-match (concat (regexp-quote dom) "$") host)) | |
34 | |
35 ;;;###autoload | |
36 (defun dnsResolve (host) | |
37 (url-gateway-nslookup-host host)) | |
38 | |
39 ;;;###autoload | |
40 (defun isResolvable (host) | |
41 (if (string-match "^[0-9.]+$" host) | |
42 t | |
43 (not (string= host (url-gateway-nslookup-host host))))) | |
44 | |
45 ;;;###autoload | |
46 (defun isInNet (ip net mask) | |
47 (let ((netc (split-string ip "\\.")) | |
48 (ipc (split-string net "\\.")) | |
49 (maskc (split-string mask "\\."))) | |
50 (if (or (/= (length netc) (length ipc)) | |
51 (/= (length ipc) (length maskc))) | |
52 nil | |
62400
e30c08177a3b
Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents:
57612
diff
changeset
|
53 (setq netc (mapcar 'string-to-number netc) |
e30c08177a3b
Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents:
57612
diff
changeset
|
54 ipc (mapcar 'string-to-number ipc) |
e30c08177a3b
Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents:
57612
diff
changeset
|
55 maskc (mapcar 'string-to-number maskc)) |
54695 | 56 (and |
57 (= (logand (nth 0 netc) (nth 0 maskc)) | |
58 (logand (nth 0 ipc) (nth 0 maskc))) | |
59 (= (logand (nth 1 netc) (nth 1 maskc)) | |
60 (logand (nth 1 ipc) (nth 1 maskc))) | |
61 (= (logand (nth 2 netc) (nth 2 maskc)) | |
62 (logand (nth 2 ipc) (nth 2 maskc))) | |
63 (= (logand (nth 3 netc) (nth 3 maskc)) | |
64 (logand (nth 3 ipc) (nth 3 maskc))))))) | |
65 | |
66 ;; Netscape configuration file parsing | |
67 (defvar url-ns-user-prefs nil | |
68 "Internal, do not use.") | |
69 | |
70 ;;;###autoload | |
71 (defun url-ns-prefs (&optional file) | |
72 (if (not file) | |
73 (setq file (expand-file-name "~/.netscape/preferences.js"))) | |
74 (if (not (and (file-exists-p file) | |
75 (file-readable-p file))) | |
76 (message "Could not open %s for reading" file) | |
77 (save-excursion | |
78 (let ((false nil) | |
79 (true t)) | |
80 (setq url-ns-user-prefs (make-hash-table :size 13 :test 'equal)) | |
81 (set-buffer (get-buffer-create " *ns-parse*")) | |
82 (erase-buffer) | |
83 (insert-file-contents file) | |
84 (goto-char (point-min)) | |
85 (while (re-search-forward "^//" nil t) | |
86 (replace-match ";;")) | |
87 (goto-char (point-min)) | |
88 (while (re-search-forward "^user_pref(" nil t) | |
89 (replace-match "(url-ns-set-user-pref ")) | |
90 (goto-char (point-min)) | |
91 (while (re-search-forward "\"," nil t) | |
92 (replace-match "\"")) | |
93 (goto-char (point-min)) | |
94 (eval-buffer))))) | |
95 | |
96 (defun url-ns-set-user-pref (key val) | |
97 (puthash key val url-ns-user-prefs)) | |
98 | |
99 ;;;###autoload | |
100 (defun url-ns-user-pref (key &optional default) | |
101 (gethash key url-ns-user-prefs default)) | |
102 | |
103 (provide 'url-ns) | |
54699 | 104 |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79720
diff
changeset
|
105 ;; arch-tag: 69520992-cf97-40b4-9ad1-c866d3cae5bf |
57612 | 106 ;;; url-ns.el ends here |