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