Support text/dns.
authorSimon Josefsson <jas@extundo.com>
Sat, 11 Sep 2004 17:17:34 +0000 (17:17 +0000)
committerSimon Josefsson <jas@extundo.com>
Sat, 11 Sep 2004 17:17:34 +0000 (17:17 +0000)
ChangeLog
GNUS-NEWS
lisp/ChangeLog
lisp/dns-mode.el [new file with mode: 0644]
lisp/mailcap.el
lisp/mm-decode.el
lisp/mm-view.el
texi/ChangeLog
texi/gnus-news.texi

index 03f4d6a..8304a47 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2004-09-11  Simon Josefsson  <jas@extundo.com>
+
+       * GNUS-NEWS: Generated.
+
 2004-09-02  Reiner Steib  <Reiner.Steib@gmx.de>
 
        * etc/.cvsignore: Remove unused.
index cad566d..f267204 100644 (file)
--- a/GNUS-NEWS
+++ b/GNUS-NEWS
@@ -78,6 +78,8 @@ customize it using the variable `nnimap-id'.
 ** Gnus now MIME decode articles even when they lack "MIME-Version"
 header.  This changes the default of `gnus-article-loose-mime'.
 
+** Gnus now view DNS master files sent as text/dns using dns-mode.
+
 \f
 * For older news, see Gnus info node "New Features".
 
index 67d66b6..b8056b6 100644 (file)
@@ -1,3 +1,15 @@
+2004-09-11  Simon Josefsson  <jas@extundo.com>
+
+       * dns-mode.el: Add.
+
+       * mm-view.el (mm-display-dns-inline): Add.
+
+       * mm-decode.el (mm-inline-media-tests): Add text/dns.
+       (mm-automatic-display): Ditto.
+
+       * mailcap.el (mailcap-mime-data): Add text/dns.
+       (mailcap-mime-extensions): Map .soa to text/dns.
+
 2004-09-10  Miles Bader  <miles@gnu.ai.mit.edu>
 
        * gnus-art.el (article-decode-mime-words, article-babel)
diff --git a/lisp/dns-mode.el b/lisp/dns-mode.el
new file mode 100644 (file)
index 0000000..d484bfb
--- /dev/null
@@ -0,0 +1,193 @@
+;;; dns-mode.el --- a mode for viewing/editing Domain Name System master files
+;; Copyright (c) 2000, 2001, 2003, 2004 Free Software Foundation, Inc.
+
+;; Author: Simon Josefsson <simon@josefsson.org>
+;; Keywords: DNS master zone file SOA
+
+;; This file is not part of GNU Emacs.
+
+;; This file is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published
+;; by the Free Software Foundation; either version 2, or (at your
+;; option) any later version.
+
+;; This file is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;; General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with This file; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;;; Commentary:
+
+;; Use M-x dns-mode RET to invoke in master files.
+;;
+;; C-c C-s  Increment SOA serial.
+;;          Understands YYYYMMDDNN, Unix time, and serial number formats,
+;;          and complains if it fail to find SOA serial.
+;;
+;; Put something similar to the following in your ~/.emacs to use this file:
+;;
+;; (load "~/path/to/dns-mode.el")
+;; (setq auto-mode-alist (cons '("\\.soa\\'" . dns-mode) auto-mode-alist))
+
+;;; References:
+
+;; RFC 1034, "DOMAIN NAMES - CONCEPTS AND FACILITIES", P. Mockapetris.
+;; RFC 1035, "DOMAIN NAMES - IMPLEMENTATION AND SPECIFICATION", P. Mockapetris.
+
+;;; Release history:
+
+;; 2004-09-11  posted on gnu.emacs.sources
+
+;;; Code:
+
+(defgroup dns-mode nil
+  "DNS master file mode configuration.")
+
+(defconst dns-mode-classes '("IN" "CS" "CH" "HS")
+  "List of strings with known DNS classes.")
+
+(defconst dns-mode-types '("A" "NS" "MD" "MF" "CNAME" "SOA" "MB" "MG" "MR"
+                          "NULL" "WKS" "PTR" "HINFO" "MINFO" "MX" "TXT"
+                          "RP" "AFSDB" "X25" "ISDN" "RT" "NSAP" "NSAP"
+                          "SIG" "KEY" "PX" "GPOS" "AAAA" "LOC" "NXT"
+                          "EID" "NIMLOC" "SRV" "ATMA" "NAPTR" "KX" "CERT"
+                          "A6" "DNAME" "SINK" "OPT" "APL" "DS" "SSHFP"
+                          "RRSIG" "NSEC" "DNSKEY" "UINFO" "UID" "GID"
+                          "UNSPEC" "TKEY" "TSIG" "IXFR" "AXFR" "MAILB"
+                          "MAILA")
+  "List of strings with known DNS types.")
+
+;; Font lock.
+
+(defvar dns-mode-control-entity-face 'font-lock-keyword-face
+  "Name of face used for control entities, e.g. $ORIGIN.")
+
+(defvar dns-mode-bad-control-entity-face 'font-lock-warning-face
+  "Name of face used for non-standard control entities, e.g. $FOO.")
+
+(defvar dns-mode-type-face 'font-lock-type-face
+  "Name of face used for DNS types, e.g., SOA.")
+
+(defvar dns-mode-class-face 'font-lock-constant-face
+  "Name of face used for DNS classes, e.g., IN.")
+
+(defcustom dns-mode-font-lock-keywords
+  `(("^$ORIGIN" 0 dns-mode-control-entity-face)
+    ("^$INCLUDE" 0 dns-mode-control-entity-face)
+    ("^$[a-z0-9A-Z]+" 0 dns-mode-bad-control-entity-face)
+    (,(regexp-opt dns-mode-classes) 0 dns-mode-class-face)
+    (,(regexp-opt dns-mode-types) 0 dns-mode-type-face))
+  "Font lock keywords used to highlight text in DNS master file mode."
+  :type 'sexp
+  :group 'dns-mode)
+
+;; Syntax table.
+
+(defvar dns-mode-syntax-table
+  (let ((table (make-syntax-table)))
+    (modify-syntax-entry ?\; "<   " table)
+    (modify-syntax-entry ?\n ">   " table)
+    table)
+  "Syntax table in use in DNS master file buffers.")
+
+;; Keymap.
+
+(defvar dns-mode-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map "\C-c\C-s" 'dns-mode-soa-increment-serial)
+    map)
+  "Keymap for DNS master file mode.")
+
+;; Menu.
+
+(defvar dns-mode-menu nil
+  "Menubar used in DNS master file mode.")
+
+(easy-menu-define dns-mode-menu dns-mode-map
+  "DNS Menu."
+  '("DNS"
+    ["Increment SOA serial" dns-mode-soa-increment-serial t]))
+
+;; Mode.
+
+;;;###autoload
+(define-derived-mode dns-mode text-mode "DNS"
+  "Major mode for viewing and editing DNS master files.
+This mode is inherited from text mode.  It add syntax
+highlighting, and some commands for handling DNS master files.
+Its keymap inherits from `text-mode' and it has the same
+variables for customizing indentation.  It has its own abbrev
+table and its own syntax table.
+
+Turning on DNS mode runs `dns-mode-hook'."
+  (set (make-local-variable 'comment-start) ";")
+  (set (make-local-variable 'comment-end) "")
+  (set (make-local-variable 'comment-start-skip) ";+ *")
+  (unless (featurep 'xemacs)
+    (set (make-local-variable 'font-lock-defaults)
+        '(dns-mode-font-lock-keywords nil nil ((?_ . "w")))))
+  (easy-menu-add-item nil nil dns-mode-menu))
+
+;; Tools.
+
+;;;###autoload
+(defun dns-mode-soa-increment-serial ()
+  "Locate SOA record and increment the serial field."
+  (interactive)
+  (save-excursion
+    (goto-char (point-min))
+    (unless (re-search-forward
+            (concat "^\\(\\(\\([^ \t]+[ \t]+\\)?[^ \t]+"
+                    "[ \t]+\\)?[^ \t]+[ \t]+\\)?SOA") nil t)
+      (error "Cannot locate SOA record"))
+    (if (re-search-forward (concat "\\<\\("
+                                  ;; year
+                                  "\\(198\\|199\\|20[0-9]\\)[0-9]"
+                                  ;; month
+                                  "\\(0[0-9]\\|10\\|11\\|12\\)"
+                                  ;; day
+                                  "\\([012][0-9]\\|30\\|31\\)"
+                                  ;; counter
+                                  "\\([0-9]\\{1,3\\}\\)"
+                                  "\\)\\>")
+                          nil t)
+       ;; YYYYMMDDIII format, one to three I's.
+       (let* ((serial (match-string 1))
+              (counterstr (match-string 5))
+              (counter (string-to-number counterstr))
+              (now (format-time-string "%Y%m%d"))
+              (nowandoldserial (concat now counterstr)))
+         (if (string< serial nowandoldserial)
+             (let ((new (format "%s00" now)))
+               (replace-match new nil nil nil 1)
+               (message "Replaced old serial %s with %s" serial new))
+           (if (string= serial nowandoldserial)
+               (let ((new (format (format "%%s%%0%dd" (length counterstr))
+                                  now (1+ counter))))
+                 (replace-match new nil nil nil 1)
+                 (message "Replaced old serial %s with %s" serial new))
+             (error "Current SOA serial is in the future"))))
+      (if (re-search-forward "\\<\\([0-9]\\{9,10\\}\\)\\>" nil t)
+         ;; Unix time
+         (let* ((serial (match-string 1))
+                (new (format-time-string "%s")))
+           (if (not (string< serial new))
+               (error "Current SOA serial is in the future")
+             (replace-match new nil nil nil 1)
+             (message "Replaced old serial %s with %s" serial new)))
+       (if (re-search-forward "\\<\\([0-9]+\\)\\>" nil t)
+           ;; Just any serial number.
+           (let* ((serial (match-string 1))
+                  (new (format "%d" (1+ (string-to-number serial)))))
+             (replace-match new nil nil nil 1)
+             (message "Replaced old serial %s with %s" serial new))
+         (error "Cannot locate serial number in SOA record"))))))
+
+(provide 'dns-mode)
+
+;;; dns-mode.el ends here
index db0ab61..cdc8205 100644 (file)
@@ -1,5 +1,5 @@
 ;;; mailcap.el --- MIME media types configuration
-;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003
+;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004
 ;;       Free Software Foundation, Inc.
 
 ;; Author: William M. Perry <wmperry@aventail.com>
      ("html"
       (viewer . mm-w3-prepare-buffer)
       (test   . (fboundp 'w3-prepare-buffer))
-      (type   . "text/html")))
+      (type   . "text/html"))
+     ("dns"
+      (viewer . dns-mode)
+      (test   . (fboundp 'dns-mode))
+      (type   . "text/dns")))
     ("video"
      ("mpeg"
       (viewer . "mpeg_play %s")
@@ -847,6 +851,7 @@ this type is returned."
     (".sit"   . "application/x-stuffit")
     (".siv"   . "application/sieve")
     (".snd"   . "audio/basic")
+    (".soa"   . "text/dns")
     (".src"   . "application/x-wais-source")
     (".tar"   . "archive/tar")
     (".tcl"   . "application/x-tcl")
index 4019132..967a92d 100644 (file)
@@ -218,6 +218,7 @@ before the external MIME handler is invoked."
        (locate-library "diff-mode")))
     ("application/emacs-lisp" mm-display-elisp-inline identity)
     ("application/x-emacs-lisp" mm-display-elisp-inline identity)
+    ("text/dns" mm-display-dns-inline identity)
     ("text/html"
      mm-inline-text-html
      (lambda (handle)
@@ -285,7 +286,7 @@ when selecting a different article."
 (defcustom mm-automatic-display
   '("text/plain" "text/enriched" "text/richtext" "text/html"
     "text/x-vcard" "image/.*" "message/delivery-status" "multipart/.*"
-    "message/rfc822" "text/x-patch" "application/pgp-signature"
+    "message/rfc822" "text/x-patch" "text/dns" "application/pgp-signature"
     "application/emacs-lisp" "application/x-emacs-lisp"
     "application/x-pkcs7-signature"
     "application/pkcs7-signature" "application/x-pkcs7-mime"
index f1ee340..0c5b6fc 100644 (file)
 (defun mm-display-elisp-inline (handle)
   (mm-display-inline-fontify handle 'emacs-lisp-mode))
 
+(defun mm-display-dns-inline (handle)
+  (mm-display-inline-fontify handle 'dns-mode))
+
 ;;      id-signedData OBJECT IDENTIFIER ::= { iso(1) member-body(2)
 ;;          us(840) rsadsi(113549) pkcs(1) pkcs7(7) 2 }
 (defvar mm-pkcs7-signed-magic
index 6b13471..9598949 100644 (file)
@@ -1,3 +1,7 @@
+2004-09-11  Simon Josefsson  <jas@extundo.com>
+
+       * gnus-news.texi: Mention text/dns.
+
 2004-09-03  Katsumi Yamaoka  <yamaoka@jpl.org>
 
        * texi2latex.el (latexi-translate-file): Support @copying and
index 2a0bee3..8dba8e5 100644 (file)
@@ -94,6 +94,8 @@ using @kbd{W e}.
 @item Gnus now MIME decode articles even when they lack "MIME-Version" header.
 This changes the default of @code{gnus-article-loose-mime}.
 
+@item Gnus now view DNS master files sent as text/dns using dns-mode.
+
 @end itemize
 
 @c gnus-news.texi ends here.