Mercurial > emacs
annotate lisp/net/dig.el @ 109559:4325622babca
Remove declarations and unused variables.
* src/term.c (Qspace, QCalign_to, QCwidth): Remove declarations.
(encode_terminal_code, produce_composite_glyph): Remove unused variables.
(set_tty_color_mode, term_mouse_highlight, term_get_fkeys): Remove
local extern declarations.
author | Dan Nicolaescu <dann@ics.uci.edu> |
---|---|
date | Mon, 26 Jul 2010 21:20:51 -0700 |
parents | 1d1d5d9bd884 |
children | 8d09094063d0 376148b31b5e |
rev | line source |
---|---|
86911 | 1 ;;; dig.el --- Domain Name System dig interface |
2 | |
3 ;; Copyright (C) 2000, 2001, 2002, 2003, 2004, | |
106815 | 4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
86911 | 5 |
6 ;; Author: Simon Josefsson <simon@josefsson.org> | |
105133
4bd8c41046c4
* net/dig.el: Add "Keywords: comm", as per net-utils.el. (Bug#4501)
Juanma Barranquero <lekktu@gmail.com>
parents:
105132
diff
changeset
|
7 ;; Keywords: DNS BIND dig comm |
86911 | 8 |
9 ;; This file is part of GNU Emacs. | |
10 | |
94677
91e5880a36c1
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
11 ;; GNU Emacs is free software: you can redistribute it and/or modify |
91e5880a36c1
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
12 ;; it under the terms of the GNU General Public License as published by |
91e5880a36c1
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
13 ;; the Free Software Foundation, either version 3 of the License, or |
91e5880a36c1
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
14 ;; (at your option) any later version. |
86911 | 15 |
94677
91e5880a36c1
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
16 ;; GNU Emacs is distributed in the hope that it will be useful, |
91e5880a36c1
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
91e5880a36c1
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
91e5880a36c1
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
19 ;; GNU General Public License for more details. |
86911 | 20 |
21 ;; You should have received a copy of the GNU General Public License | |
94677
91e5880a36c1
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
86911 | 23 |
24 ;;; Commentary: | |
25 | |
26 ;; This provide an interface for "dig". | |
27 ;; | |
28 ;; For interactive use, try M-x dig and type a hostname. Use `q' to quit | |
29 ;; dig buffer. | |
30 ;; | |
31 ;; For use in elisp programs, call `dig-invoke' and use | |
32 ;; `dig-extract-rr' to extract resource records. | |
33 | |
34 ;;; Release history: | |
35 | |
36 ;; 2000-10-28 posted on gnu.emacs.sources | |
37 | |
38 ;;; Code: | |
39 | |
40 (eval-when-compile (require 'cl)) | |
41 | |
42 (defgroup dig nil | |
43 "Dig configuration." | |
44 :group 'comm) | |
45 | |
46 (defcustom dig-program "dig" | |
47 "Name of dig (domain information groper) binary." | |
48 :type 'file | |
49 :group 'dig) | |
50 | |
51 (defcustom dig-dns-server nil | |
52 "DNS server to query. | |
53 If nil, use system defaults." | |
54 :type '(choice (const :tag "System defaults") | |
55 string) | |
56 :group 'dig) | |
57 | |
58 (defcustom dig-font-lock-keywords | |
59 '(("^;; [A-Z]+ SECTION:" 0 font-lock-keyword-face) | |
60 ("^;;.*" 0 font-lock-comment-face) | |
61 ("^; <<>>.*" 0 font-lock-type-face) | |
62 ("^;.*" 0 font-lock-function-name-face)) | |
63 "Default expressions to highlight in dig mode." | |
64 :type 'sexp | |
65 :group 'dig) | |
66 | |
67 (defun dig-invoke (domain &optional | |
68 query-type query-class query-option | |
69 dig-option server) | |
70 "Call dig with given arguments and return buffer containing output. | |
105170 | 71 DOMAIN is a string with a DNS domain. QUERY-TYPE is an optional |
72 string with a DNS type. QUERY-CLASS is an optional string with a DNS | |
73 class. QUERY-OPTION is an optional string with dig \"query options\". | |
74 DIG-OPTION is an optional string with parameters for the dig program. | |
86911 | 75 SERVER is an optional string with a domain name server to query. |
76 | |
77 Dig is an external program found in the BIND name server distribution, | |
78 and is a commonly available debugging tool." | |
79 (let (buf cmdline) | |
80 (setq buf (generate-new-buffer "*dig output*")) | |
81 (if dig-option (push dig-option cmdline)) | |
82 (if query-option (push query-option cmdline)) | |
83 (if query-class (push query-class cmdline)) | |
84 (if query-type (push query-type cmdline)) | |
85 (push domain cmdline) | |
86 (if server (push (concat "@" server) cmdline) | |
87 (if dig-dns-server (push (concat "@" dig-dns-server) cmdline))) | |
88 (apply 'call-process dig-program nil buf nil cmdline) | |
89 buf)) | |
90 | |
91 (defun dig-extract-rr (domain &optional type class) | |
92 "Extract resource records for DOMAIN, TYPE and CLASS from buffer. | |
93 Buffer should contain output generated by `dig-invoke'." | |
94 (save-excursion | |
95 (goto-char (point-min)) | |
96 (if (re-search-forward | |
97 (concat domain "\\.?[\t ]+[0-9wWdDhHmMsS]+[\t ]+" | |
98 (upcase (or class "IN")) "[\t ]+" (upcase (or type "A"))) | |
99 nil t) | |
100 (let (b e) | |
101 (end-of-line) | |
102 (setq e (point)) | |
103 (beginning-of-line) | |
104 (setq b (point)) | |
105 (when (search-forward " (" e t) | |
106 (search-forward " )")) | |
107 (end-of-line) | |
108 (setq e (point)) | |
109 (buffer-substring b e)) | |
110 (and (re-search-forward (concat domain "\\.?[\t ]+[0-9wWdDhHmMsS]+[\t ]+" | |
111 (upcase (or class "IN")) | |
112 "[\t ]+CNAME[\t ]+\\(.*\\)$") nil t) | |
113 (dig-extract-rr (match-string 1) type class))))) | |
114 | |
115 (defun dig-rr-get-pkix-cert (rr) | |
116 (let (b e str) | |
117 (string-match "[^\t ]+[\t ]+[0-9wWdDhHmMsS]+[\t ]+IN[\t ]+CERT[\t ]+\\(1\\|PKIX\\)[\t ]+[0-9]+[\t ]+[0-9]+[\t ]+(?" rr) | |
118 (setq b (match-end 0)) | |
119 (string-match ")" rr) | |
120 (setq e (match-beginning 0)) | |
121 (setq str (substring rr b e)) | |
122 (while (string-match "[\t \n\r]" str) | |
123 (setq str (replace-match "" nil nil str))) | |
124 str)) | |
125 | |
126 ;; XEmacs does it like this. For Emacs, we have to set the | |
127 ;; `font-lock-defaults' buffer-local variable. | |
128 (put 'dig-mode 'font-lock-defaults '(dig-font-lock-keywords t)) | |
129 | |
130 (put 'dig-mode 'mode-class 'special) | |
131 | |
132 (defvar dig-mode-map nil) | |
133 (unless dig-mode-map | |
134 (setq dig-mode-map (make-sparse-keymap)) | |
135 (suppress-keymap dig-mode-map) | |
136 | |
137 (define-key dig-mode-map "q" 'dig-exit)) | |
138 | |
105132
4640c3af38ad
(dig-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104578
diff
changeset
|
139 (define-derived-mode dig-mode nil "Dig" |
86911 | 140 "Major mode for displaying dig output." |
141 (buffer-disable-undo) | |
142 (unless (featurep 'xemacs) | |
143 (set (make-local-variable 'font-lock-defaults) | |
144 '(dig-font-lock-keywords t))) | |
145 (when (featurep 'font-lock) | |
105132
4640c3af38ad
(dig-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104578
diff
changeset
|
146 ;; FIXME: what is this for?? --Stef |
86911 | 147 (font-lock-set-defaults)) |
105132
4640c3af38ad
(dig-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104578
diff
changeset
|
148 ) |
86911 | 149 |
150 (defun dig-exit () | |
151 "Quit dig output buffer." | |
152 (interactive) | |
153 (kill-buffer (current-buffer))) | |
154 | |
104578
e62b8b3e56b3
Kevin Ryde <user42 at zip.com.au>
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
155 ;;;###autoload |
86911 | 156 (defun dig (domain &optional |
157 query-type query-class query-option dig-option server) | |
158 "Query addresses of a DOMAIN using dig, by calling `dig-invoke'. | |
159 Optional arguments are passed to `dig-invoke'." | |
160 (interactive "sHost: ") | |
161 (switch-to-buffer | |
162 (dig-invoke domain query-type query-class query-option dig-option server)) | |
163 (goto-char (point-min)) | |
164 (and (search-forward ";; ANSWER SECTION:" nil t) | |
165 (forward-line)) | |
166 (dig-mode) | |
167 (setq buffer-read-only t) | |
168 (set-buffer-modified-p nil)) | |
169 | |
170 ;; named for consistency with query-dns in dns.el | |
171 (defun query-dig (domain &optional | |
172 query-type query-class query-option dig-option server) | |
173 "Query addresses of a DOMAIN using dig. | |
105170 | 174 It works by calling `dig-invoke' and `dig-extract-rr'. |
175 Optional arguments are passed to `dig-invoke' and `dig-extract-rr'. | |
176 Returns nil for domain/class/type queries that result in no data." | |
86911 | 177 (let ((buffer (dig-invoke domain query-type query-class |
178 query-option dig-option server))) | |
179 (when buffer | |
180 (switch-to-buffer buffer) | |
181 (let ((digger (dig-extract-rr domain query-type query-class))) | |
182 (kill-buffer buffer) | |
183 digger)))) | |
184 | |
185 (provide 'dig) | |
186 | |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
187 ;; arch-tag: 1d61726e-9400-4013-9ae7-4035e0c7f7d6 |
86911 | 188 ;;; dig.el ends here |