(info-other-window, info): Rename function argument
[bpt/emacs.git] / lisp / url / url-ns.el
1 ;;; url-ns.el --- Various netscape-ish functions for proxy definitions
2
3 ;; Copyright (C) 1997, 1998, 1999, 2004, 2005 Free Software Foundation, Inc.
4
5 ;; Keywords: comm, data, processes, hypermedia
6
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., 51 Franklin Street, Fifth Floor,
22 ;; Boston, MA 02110-1301, USA.
23
24 ;;; Code:
25
26 (require 'url-gw)
27
28 ;;;###autoload
29 (defun isPlainHostName (host)
30 (not (string-match "\\." host)))
31
32 ;;;###autoload
33 (defun dnsDomainIs (host dom)
34 (string-match (concat (regexp-quote dom) "$") host))
35
36 ;;;###autoload
37 (defun dnsResolve (host)
38 (url-gateway-nslookup-host host))
39
40 ;;;###autoload
41 (defun isResolvable (host)
42 (if (string-match "^[0-9.]+$" host)
43 t
44 (not (string= host (url-gateway-nslookup-host host)))))
45
46 ;;;###autoload
47 (defun isInNet (ip net mask)
48 (let ((netc (split-string ip "\\."))
49 (ipc (split-string net "\\."))
50 (maskc (split-string mask "\\.")))
51 (if (or (/= (length netc) (length ipc))
52 (/= (length ipc) (length maskc)))
53 nil
54 (setq netc (mapcar 'string-to-number netc)
55 ipc (mapcar 'string-to-number ipc)
56 maskc (mapcar 'string-to-number maskc))
57 (and
58 (= (logand (nth 0 netc) (nth 0 maskc))
59 (logand (nth 0 ipc) (nth 0 maskc)))
60 (= (logand (nth 1 netc) (nth 1 maskc))
61 (logand (nth 1 ipc) (nth 1 maskc)))
62 (= (logand (nth 2 netc) (nth 2 maskc))
63 (logand (nth 2 ipc) (nth 2 maskc)))
64 (= (logand (nth 3 netc) (nth 3 maskc))
65 (logand (nth 3 ipc) (nth 3 maskc)))))))
66
67 ;; Netscape configuration file parsing
68 (defvar url-ns-user-prefs nil
69 "Internal, do not use.")
70
71 ;;;###autoload
72 (defun url-ns-prefs (&optional file)
73 (if (not file)
74 (setq file (expand-file-name "~/.netscape/preferences.js")))
75 (if (not (and (file-exists-p file)
76 (file-readable-p file)))
77 (message "Could not open %s for reading" file)
78 (save-excursion
79 (let ((false nil)
80 (true t))
81 (setq url-ns-user-prefs (make-hash-table :size 13 :test 'equal))
82 (set-buffer (get-buffer-create " *ns-parse*"))
83 (erase-buffer)
84 (insert-file-contents file)
85 (goto-char (point-min))
86 (while (re-search-forward "^//" nil t)
87 (replace-match ";;"))
88 (goto-char (point-min))
89 (while (re-search-forward "^user_pref(" nil t)
90 (replace-match "(url-ns-set-user-pref "))
91 (goto-char (point-min))
92 (while (re-search-forward "\"," nil t)
93 (replace-match "\""))
94 (goto-char (point-min))
95 (eval-buffer)))))
96
97 (defun url-ns-set-user-pref (key val)
98 (puthash key val url-ns-user-prefs))
99
100 ;;;###autoload
101 (defun url-ns-user-pref (key &optional default)
102 (gethash key url-ns-user-prefs default))
103
104 (provide 'url-ns)
105
106 ;;; arch-tag: 69520992-cf97-40b4-9ad1-c866d3cae5bf
107 ;;; url-ns.el ends here