]> www.average.org Git - pdns-pipe-nmc.git/blobdiff - PowerDns.hs
better error reporting
[pdns-pipe-nmc.git] / PowerDns.hs
index 0e8be9fe0d20a2522c747e5d8c845b3848aefc9f..cbc9fb5df94babc05c9f715b7e6779aa0878e276 100644 (file)
@@ -81,7 +81,7 @@ pdnsParse ver s =
       "AXFR":x:[]               -> Right (PdnsRequestAXFR (getInt x))
       "Q":qn:"IN":qt:id:rip:xs  -> case rrType qt of
                                      RRTypeError e ->
-                                       Left $ "PDNS Request: " ++ e
+                                       Left $ "PDNS Request: " ++ (show qt)
                                      rt ->
                                        Right (PdnsRequestQ
                                             { qName = qn
@@ -99,23 +99,29 @@ pdnsReport err = "LOG\tError: " ++ err ++ "\nFAIL\n"
 
 -- | Produce answer to the Q request
 pdnsOut :: Int -> Int -> String -> RRType -> Either String NmcDom -> String
-pdnsOut ver id name rrtype edom = case edom of
-  Left  err ->
-    pdnsReport $ err ++ " in a " ++ (show rrtype) ++ "query for " ++ name
-  Right dom ->
-    case rrtype of
-      RRTypeANY -> foldr (\x a -> (formatRR ver id name dom x) ++ a) "END\n"
-          [RRTypeSRV, RRTypeA, RRTypeAAAA, RRTypeCNAME, RRTypeDNAME,
-           RRTypeRP, RRTypeLOC, RRTypeNS, RRTypeDS, RRTypeMX]
-      _         -> (formatRR ver id name dom rrtype) ++ "END\n"
+pdnsOut ver id name rrtype edom =
+  let
+    rrl = case rrtype of
+      RRTypeANY -> [RRTypeSRV, RRTypeA, RRTypeAAAA, RRTypeCNAME
+                   , RRTypeDNAME, RRTypeRP, RRTypeLOC, RRTypeNS
+                   , RRTypeDS, RRTypeMX]
+      rrt       -> [rrt]
+  in
+    (formatDom ver id name rrl edom) ++ "END\n"
 
 -- | Produce answer to the AXFR request
 pdnsOutXfr :: Int -> Int -> String -> Either String NmcDom -> String
 pdnsOutXfr ver id name edom = "" -- FIXME
 
+formatDom ver id name rrl edom = case edom of
+  Left  err ->
+    pdnsReport $ err ++ " in the " ++ (show rrl) ++ " query for " ++ name
+  Right dom ->
+    foldr (\x a -> (formatRR ver id name dom x) ++ a) "" rrl
+
 formatRR ver id name dom rrtype =
   foldr (\x a -> "DATA\t" ++ v3ext ++ name ++ "\tIN\t" ++ (show rrtype)
-            ++ "\t" ++ ttl ++ "\t" ++ (show id) ++ "\t" ++ x ++ "\n" ++ a)
+              ++ "\t" ++ ttl ++ "\t" ++ (show id) ++ "\t" ++ x ++ "\n" ++ a)
         "" $ dataRR rrtype name dom
     where
       v3ext = case ver of