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