3 ;;; Zone generator frontend
5 ;;; (c) 2005 Straylight/Edgeware
8 ;;;----- Licensing notice ---------------------------------------------------
10 ;;; This program is free software; you can redistribute it and/or modify
11 ;;; it under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 2 of the License, or
13 ;;; (at your option) any later version.
15 ;;; This program is distributed in the hope that it will be useful,
16 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with this program; if not, write to the Free Software Foundation,
22 ;;; Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 (defpackage #:zone.frontend
25 (:use #:common-lisp #:mdw.base #:mdw.sys-base #:optparse #:net #:zone
26 #+(or cmu clisp) #:mop
29 (in-package #:zone.frontend)
32 "Which zones to be emitted.")
33 (defvar opt-format :bind
34 "Which format to use on output.")
36 "Whether to emit stack backtraces on error.")
38 (defun directory-exists-p (name)
40 ;; Make a pathname for NAME which has the right form for a directory.
42 (let ((path (pathname name)))
43 (if (null (pathname-name path))
45 (make-pathname :directory
46 (append (or (pathname-directory path)
48 (list (pathname-name path)))
53 ;; Now check that it exists.
54 #+clisp (and (ext:probe-directory dirpath) (truename dirpath))
55 #-clisp (probe-file dirpath)))
57 (eval-when (:compile-toplevel :load-toplevel)
58 (defopthandler dir (var arg) ()
59 (let ((path (directory-exists-p arg)))
61 (not (pathname-name path)))
63 (option-parse-error "path `~A' doesn't name a directory." arg))))
64 (let ((duration-units (make-hash-table :test #'equal)))
65 (dolist (item '((("Gs") #.(* 1000 1000 1000))
66 (("Ms") #.(* 1000 1000))
70 (("yr" "year" "years" "y") #.(* 365 24 60 60))
71 (("wk" "week" "weeks" "w") #.(* 7 24 60 60))
72 (("day" "days" "dy" "d") #.(* 24 60 60))
73 (("hr" "hour" "hours" "h") #.(* 60 60))
74 (("min" "minute" "minutes" "m") 60)
75 (("s" "second" "seconds" "sec" "") 1)))
76 (dolist (name (car item))
77 (setf (gethash name duration-units) (cadr item))))
78 (defopthandler dur (var arg) ()
79 (let ((len (length arg)))
80 (multiple-value-bind (n i) (parse-integer arg :junk-allowed t)
82 (option-parse-error "invalid duration `~A': ~
83 integer expected" arg))
84 (loop (cond ((or (>= i len)
85 (not (whitespace-char-p (char arg i))))
90 (loop (cond ((or (>= i len)
91 (whitespace-char-p (char arg i)))
96 (unit (subseq arg u0 u1))
97 (scale (gethash unit duration-units)))
99 (option-parse-error "invalid duration `~A': ~
102 (setf var (* n scale)))))))))
105 :version "1.0.0" :usage "ZONEDEF..."
106 :help "Generates BIND zone files from Lisp descriptions."
107 :options (options help-options
109 (#\f "feature" (:arg "KEYWORD")
110 (list *features* 'keyword)
111 "Insert KEYWORD in *features* list.")
112 (#\s "subnet" (:arg "NET")
113 (list zone:*preferred-subnets*)
114 "Designate NET as a preferred subnet.")
115 (#\D "debug" (set opt-debug)
116 "Produce stack backtrace on error.")
118 (#\E "expire" (:arg "DURATION")
119 (dur *default-zone-expire*)
120 "Set default zone expiry period.")
121 (#\N "min-ttl" (:arg "DURATION")
122 (dur *default-zone-min-ttl*)
123 "Set default zone minimum/negative time-to-live.")
124 (#\R "refresh" (:arg "DURATION")
125 (dur *default-zone-refresh*)
126 "Set default zone refresh period.")
127 (#\T "ttl" (:arg "DURATION")
128 (dur *default-zone-ttl*)
129 "Set default zone time-to-live.")
130 (#\Y "retry" (:arg "DURATION")
131 (dur *default-zone-retry*)
132 "Set default zone retry period.")
134 (#\d "directory" (:arg "DIRECTORY")
135 (dir *zone-output-path*)
136 "Write zone and serial files to DIRECTORY.")
137 (#\F "format" (:arg "FORMAT")
142 (generic-function-methods
144 (generic-function-methods
145 #'zone:zone-write-header))
147 (method-specializers method)
148 if (typep (car specs)
151 (eql-specializer-object
153 "Format to use for output.")
154 (#\z "zone" (:arg "NAME") (list opt-zones)
155 "Write information about zone NAME.")))
158 (set-command-line-arguments)
162 (let ((*package* (make-package "ZONE.SCRATCH"
165 (progv *zone-config* (mapcar #'symbol-value *zone-config*)
166 (load f :verbose nil :print nil :if-does-not-exist :error)
167 (delete-package *package*))))
168 (zone-save opt-zones :format opt-format)
170 (with-unix-error-reporting ()
171 (unless (option-parse-try
174 (when (zerop (length rest))
175 (option-parse-error "no files to read"))
180 (with-unix-error-reporting () (run)))
183 ;;;----- That's all, folks --------------------------------------------------