url-ns.el 3.1 KB

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