From: Eugene Crosser Date: Sun, 30 Mar 2014 09:20:16 +0000 (+0400) Subject: move most formatting to PowerDns X-Git-Tag: 0.9.0.0~108 X-Git-Url: http://average.org/gitweb/?a=commitdiff_plain;h=0d59aa176c8ca6665f59426a436671099a393d3f;p=pdns-pipe-nmc.git move most formatting to PowerDns --- diff --git a/PowerDns.hs b/PowerDns.hs index 1c1e420..9a2a498 100644 --- a/PowerDns.hs +++ b/PowerDns.hs @@ -1,6 +1,7 @@ module PowerDns ( RRType(..) , PdnsRequest(..) , pdnsParse + , pdnsReport , pdnsOut ) where @@ -63,8 +64,16 @@ pdnsParse ver s = }) _ -> Left $ "Unparseable PDNS Request: " ++ s -pdnsOut :: Int -> RRType -> Either String NmcDom -> String -pdnsOut ver rrtype edom = +pdnsReport :: String -> String +pdnsReport err = + "LOG\tError: " ++ err ++ "\nFAIL\n" + +pdnsOut :: Int -> String -> RRType -> Either String NmcDom -> String +pdnsOut ver id rrtype edom = case edom of - Left err -> "LOG Error: " ++ err ++ "\nFAIL\n" - Right dom -> "DATA\n" ++ (show dom) ++ "\nEND\n" --FIXME + Left err -> pdnsReport err + Right dom -> pdnsAmend ver id rrtype dom "END\n" + +pdnsAmend :: Int -> String -> RRType -> NmcDom -> String -> String +pdnsAmend ver id rrtype dom accum = + "DATA\t" ++ (show dom) ++ "\n" ++ accum --FIXME diff --git a/pdns-pipe-nmc.hs b/pdns-pipe-nmc.hs index 79a17c0..50d4bd8 100644 --- a/pdns-pipe-nmc.hs +++ b/pdns-pipe-nmc.hs @@ -96,13 +96,13 @@ main = do forever $ do l <- getLine case pdnsParse ver l of - Left e -> putStrLn $ "FAIL\t" ++ e + Left e -> putStr $ pdnsReport e Right preq -> do case preq of PdnsRequestQ qname qtype id _ _ _ -> - queryNmc mgr cfg qname id >>= putStr . (pdnsOut ver qtype) + queryNmc mgr cfg qname id >>= putStr . (pdnsOut ver id qtype) PdnsRequestAXFR xfrreq -> - putStrLn ("FAIL\tNo support for AXFR " ++ xfrreq) + putStr $ pdnsReport ("No support for AXFR " ++ xfrreq) PdnsRequestPing -> putStrLn "END" -- for testing @@ -110,4 +110,4 @@ main = do ask str = do cfg <- readConfig confFile mgr <- newManager def - queryNmc mgr cfg str "test-req-id" >>= putStr . (pdnsOut 1 RRTypeANY) + queryNmc mgr cfg str "askid" >>= putStr . (pdnsOut 1 "askid" RRTypeANY)