Merge from gnus--rel--5.10
[gnus] / lisp / dig.el
1 ;;; dig.el --- Domain Name System dig interface
2
3 ;; Copyright (C) 2000, 2001, 2002, 2003, 2004,
4 ;;   2005, 2006, 2007 Free Software Foundation, Inc.
5
6 ;; Author: Simon Josefsson <simon@josefsson.org>
7 ;; Keywords: DNS BIND dig
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published
13 ;; by the Free Software Foundation; either version 2, or (at your
14 ;; option) any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 ;; General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;; This provide an interface for "dig".
29 ;;
30 ;; For interactive use, try M-x dig and type a hostname.  Use `q' to quit
31 ;; dig buffer.
32 ;;
33 ;; For use in elisp programs, call `dig-invoke' and use
34 ;; `dig-extract-rr' to extract resource records.
35
36 ;;; Release history:
37
38 ;; 2000-10-28  posted on gnu.emacs.sources
39
40 ;;; Code:
41
42 (eval-when-compile (require 'cl))
43
44 (defgroup dig nil
45   "Dig configuration."
46   :group 'comm)
47
48 (defcustom dig-program "dig"
49   "Name of dig (domain information groper) binary."
50   :type 'file
51   :group 'dig)
52
53 (defcustom dig-dns-server nil
54   "DNS server to query.
55 If nil, use system defaults."
56   :type '(choice (const :tag "System defaults")
57                  string)
58   :group 'dig)
59
60 (defcustom dig-font-lock-keywords
61   '(("^;; [A-Z]+ SECTION:" 0 font-lock-keyword-face)
62     ("^;;.*" 0 font-lock-comment-face)
63     ("^; <<>>.*" 0 font-lock-type-face)
64     ("^;.*" 0 font-lock-function-name-face))
65   "Default expressions to highlight in dig mode."
66   :type 'sexp
67   :group 'dig)
68
69 (defun dig-invoke (domain &optional
70                           query-type query-class query-option
71                           dig-option server)
72   "Call dig with given arguments and return buffer containing output.
73 DOMAIN is a string with a DNS domain. QUERY-TYPE is an optional string
74 with a DNS type. QUERY-CLASS is an optional string with a DNS class.
75 QUERY-OPTION is an optional string with dig \"query options\".
76 DIG-OPTIONS is an optional string with parameters for the dig program.
77 SERVER is an optional string with a domain name server to query.
78
79 Dig is an external program found in the BIND name server distribution,
80 and is a commonly available debugging tool."
81   (let (buf cmdline)
82     (setq buf (generate-new-buffer "*dig output*"))
83     (if dig-option (push dig-option cmdline))
84     (if query-option (push query-option cmdline))
85     (if query-class (push query-class cmdline))
86     (if query-type (push query-type cmdline))
87     (push domain cmdline)
88     (if server (push (concat "@" server) cmdline)
89       (if dig-dns-server (push (concat "@" dig-dns-server) cmdline)))
90     (apply 'call-process dig-program nil buf nil cmdline)
91     buf))
92