From ab87c7bf4977fe6b89e8e6d1a45c300e341d366a Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Fri, 15 Jun 2007 15:07:07 +0100 Subject: [PATCH] zone: Allow control over output file names. Organization: Straylight/Edgeware From: Mark Wooding Output file names are now constructed by a dedicated function, using Lisp pathname functions rather than format. There's also a default *zone-output-path* to control where the files get put. This suggests a reordering of the code, specifically to move make-serial-number below the new zone-file-name. --- zone.lisp | 72 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/zone.lisp b/zone.lisp index d3b2c4e..6b11880 100644 --- a/zone.lisp +++ b/zone.lisp @@ -33,6 +33,7 @@ (defpackage #:zone #:*default-zone-retry* #:*default-zone-expire* #:*default-zone-min-ttl* #:*default-zone-ttl* #:*default-mx-priority* #:*default-zone-admin* + #:*zone-output-path* #:zone-find #:zone-parse #:zone-write #:zone-create #:defzone #:defrevzone #:zone-save #:defzoneparse #:zone-parse-host @@ -180,35 +181,6 @@ (defvar *default-zone-ttl* (* 8 60 60) (defvar *default-mx-priority* 50 "Default MX priority.") -;;;-------------------------------------------------------------------------- -;;; Serial numbering. - -(defun make-zone-serial (name) - "Given a zone NAME, come up with a new serial number. This will (very - carefully) update a file ZONE.serial in the current directory." - (let* ((file (format nil "~(~A~).serial" name)) - (last (with-open-file (in file - :direction :input - :if-does-not-exist nil) - (if in (read in) - (list 0 0 0 0)))) - (now (multiple-value-bind - (sec min hr dy mon yr dow dstp tz) - (get-decoded-time) - (declare (ignore sec min hr dow dstp tz)) - (list dy mon yr))) - (seq (cond ((not (equal now (cdr last))) 0) - ((< (car last) 99) (1+ (car last))) - (t (error "Run out of sequence numbers for ~A" name))))) - (safely-writing (out file) - (format out - ";; Serial number file for zone ~A~%~ - ;; (LAST-SEQ DAY MONTH YEAR)~%~ - ~S~%" - name - (cons seq now))) - (from-mixed-base '(100 100 100) (reverse (cons seq now))))) - ;;;-------------------------------------------------------------------------- ;;; Zone variables and structures. @@ -238,9 +210,18 @@ (defstruct (zone-subdomain (:conc-name zs-)) ttl records) +(defvar *zone-output-path* *default-pathname-defaults* + "Pathname defaults to merge into output files.") + ;;;-------------------------------------------------------------------------- ;;; Zone infrastructure. +(defun zone-file-name (zone type) + "Choose a file name for a given ZONE and TYPE." + (merge-pathnames (make-pathname :name (string-downcase zone) + :type (string-downcase type)) + *zone-output-path*)) + (defun zone-process-records (rec ttl func) "Sort out the list of records in REC, calling FUNC for each one. TTL is the default time-to-live for records which don't specify one." @@ -407,6 +388,35 @@ (defun zone-cidr-delegation (data name ttl list) :data (join-strings #\. (list tail tdom))) list))))))) +;;;-------------------------------------------------------------------------- +;;; Serial numbering. + +(defun make-zone-serial (name) + "Given a zone NAME, come up with a new serial number. This will (very + carefully) update a file ZONE.serial in the current directory." + (let* ((file (zone-file-name name :serial)) + (last (with-open-file (in file + :direction :input + :if-does-not-exist nil) + (if in (read in) + (list 0 0 0 0)))) + (now (multiple-value-bind + (sec min hr dy mon yr dow dstp tz) + (get-decoded-time) + (declare (ignore sec min hr dow dstp tz)) + (list dy mon yr))) + (seq (cond ((not (equal now (cdr last))) 0) + ((< (car last) 99) (1+ (car last))) + (t (error "Run out of sequence numbers for ~A" name))))) + (safely-writing (out file) + (format out + ";; Serial number file for zone ~A~%~ + ;; (LAST-SEQ DAY MONTH YEAR)~%~ + ~S~%" + name + (cons seq now))) + (from-mixed-base '(100 100 100) (reverse (cons seq now))))) + ;;;-------------------------------------------------------------------------- ;;; Zone form parsing. @@ -774,9 +784,7 @@ (defun zone-save (zones) (unless zz (error "Unknown zone `~A'." z)) (let ((stream (safely-open-output-stream safe - (format nil - "~(~A~).zone" - z)))) + (zone-file-name z :zone)))) (zone-write zz stream)))))) ;;;----- That's all, folks -------------------------------------------------- -- [mdw]