From: Fredrik Tolf Date: Sat, 15 May 2010 21:19:21 +0000 (+0200) Subject: COMMON-NET: Added a couple of functions for parsing/formatting DNs. X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=b466cd484e1cf6b7c7a0d2fdb791a3cf40560f46;p=lisp-utils.git COMMON-NET: Added a couple of functions for parsing/formatting DNs. --- diff --git a/dns.lisp b/dns.lisp index f768d2c..48def25 100644 --- a/dns.lisp +++ b/dns.lisp @@ -380,3 +380,34 @@ (let ((buf (make-dns-encode-state))) (encode-dns-packet buf packet) (slot-value buf 'packet-buf))) + +;;; DN format + +(defun parse-domain-name (name) + (declare (type string name)) + (let ((l '()) + (p 0)) + (loop (let ((p2 (position #\. name :start p))) + (if p2 + (if (= p2 (1- (length name))) + (return (values l t)) + (setf l (append l (list (subseq name p p2))) + p (1+ p2))) + (return (values (append l (list (subseq name p))) nil))))))) + +(defun unparse-domain-name (name) + (declare (type list name)) + (let ((buf nil)) + (dolist (label name buf) + (setf buf (if buf + (concatenate 'string buf "." label) + label))))) + +;;; Misc. + +(defmethod print-object ((q resource-query) stream) + (with-slots (name type) q + (if *print-readably* + (format stream "~A: ~A" type (unparse-domain-name name)) + (format stream "#<~S ~S ~S>" 'resource-query type (unparse-domain-name name))))) +