54695
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1 ;;; url-ns.el --- Various netscape-ish functions for proxy definitions
|
57612
|
2
|
|
3 ;; Copyright (c) 1997 - 1999 Free Software Foundation, Inc.
|
|
4
|
54695
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
5 ;; Keywords: comm, data, processes, hypermedia
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
6
|
57612
|
7 ;; This file is part of GNU Emacs.
|
|
8
|
|
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 2, or (at your option)
|
|
12 ;; any later version.
|
|
13
|
|
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.
|
|
18
|
|
19 ;; You should have received a copy of the GNU General Public License
|
|
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 ;; Boston, MA 02111-1307, USA.
|
|
23
|
|
24 ;;; Code:
|
54695
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
25
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
26 (require 'url-gw)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
27
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
28 ;;;###autoload
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
29 (defun isPlainHostName (host)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
30 (not (string-match "\\." host)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
31
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
32 ;;;###autoload
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
33 (defun dnsDomainIs (host dom)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
34 (string-match (concat (regexp-quote dom) "$") host))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
35
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
36 ;;;###autoload
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
37 (defun dnsResolve (host)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
38 (url-gateway-nslookup-host host))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
39
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
40 ;;;###autoload
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
41 (defun isResolvable (host)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
42 (if (string-match "^[0-9.]+$" host)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
43 t
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
44 (not (string= host (url-gateway-nslookup-host host)))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
45
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
46 ;;;###autoload
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
47 (defun isInNet (ip net mask)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
48 (let ((netc (split-string ip "\\."))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
49 (ipc (split-string net "\\."))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
50 (maskc (split-string mask "\\.")))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
51 (if (or (/= (length netc) (length ipc))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
52 (/= (length ipc) (length maskc)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
53 nil
|
62400
|
54 (setq netc (mapcar 'string-to-number netc)
|
|
55 ipc (mapcar 'string-to-number ipc)
|
|
56 maskc (mapcar 'string-to-number maskc))
|
54695
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
57 (and
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
58 (= (logand (nth 0 netc) (nth 0 maskc))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
59 (logand (nth 0 ipc) (nth 0 maskc)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
60 (= (logand (nth 1 netc) (nth 1 maskc))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
61 (logand (nth 1 ipc) (nth 1 maskc)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
62 (= (logand (nth 2 netc) (nth 2 maskc))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
63 (logand (nth 2 ipc) (nth 2 maskc)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
64 (= (logand (nth 3 netc) (nth 3 maskc))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
65 (logand (nth 3 ipc) (nth 3 maskc)))))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
66
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
67 ;; Netscape configuration file parsing
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
68 (defvar url-ns-user-prefs nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
69 "Internal, do not use.")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
70
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
71 ;;;###autoload
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
72 (defun url-ns-prefs (&optional file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
73 (if (not file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
74 (setq file (expand-file-name "~/.netscape/preferences.js")))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
75 (if (not (and (file-exists-p file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
76 (file-readable-p file)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
77 (message "Could not open %s for reading" file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
78 (save-excursion
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
79 (let ((false nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
80 (true t))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
81 (setq url-ns-user-prefs (make-hash-table :size 13 :test 'equal))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
82 (set-buffer (get-buffer-create " *ns-parse*"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
83 (erase-buffer)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
84 (insert-file-contents file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
85 (goto-char (point-min))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
86 (while (re-search-forward "^//" nil t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
87 (replace-match ";;"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
88 (goto-char (point-min))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
89 (while (re-search-forward "^user_pref(" nil t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
90 (replace-match "(url-ns-set-user-pref "))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
91 (goto-char (point-min))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
92 (while (re-search-forward "\"," nil t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
93 (replace-match "\""))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
94 (goto-char (point-min))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
95 (eval-buffer)))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
96
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
97 (defun url-ns-set-user-pref (key val)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
98 (puthash key val url-ns-user-prefs))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
99
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
100 ;;;###autoload
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
101 (defun url-ns-user-pref (key &optional default)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
102 (gethash key url-ns-user-prefs default))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
103
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
104 (provide 'url-ns)
|
54699
|
105
|
|
106 ;;; arch-tag: 69520992-cf97-40b4-9ad1-c866d3cae5bf
|
57612
|
107 ;;; url-ns.el ends here
|