X-Git-Url: http://www.average.org/gitweb/?p=pdns-pipe-nmc.git;a=blobdiff_plain;f=pdns-pipe-nmc.hs;h=b010bac1cfd9ebfa0472eec64c3e68ca2c1317fe;hp=a3fc8c7c5b2a5a414388c4f4ede60d1f6c94e1a5;hb=b0c8a2dae29482014bcb8794a18c0aef24abe683;hpb=b2f5f20509c12bb94783f7035042aed1e0d99c58 diff --git a/pdns-pipe-nmc.hs b/pdns-pipe-nmc.hs index a3fc8c7..b010bac 100644 --- a/pdns-pipe-nmc.hs +++ b/pdns-pipe-nmc.hs @@ -5,7 +5,7 @@ module Main where import Control.Monad import qualified Data.ByteString.Char8 as C (pack, unpack) import qualified Data.ByteString.Lazy.Char8 as L (pack, unpack) -import Data.ByteString.Lazy as BS hiding (reverse, putStrLn) +import Data.ByteString.Lazy as BS hiding (reverse, putStr, putStrLn) import Data.List.Split import Data.Aeson (encode, decode, Value(..)) import Network.HTTP.Types @@ -55,6 +55,8 @@ qRsp rsp = -- NMC interface +descend subdom dom = dom + queryNmc :: Manager -> Config -> String -> String -> IO (Either String NmcDom) queryNmc mgr cfg fqdn qid = do @@ -62,7 +64,9 @@ queryNmc mgr cfg fqdn qid = do "bit":dn:xs -> do rsp <- runResourceT $ httpLbs (qReq cfg (L.pack ("d/" ++ dn)) (L.pack qid)) mgr - return $ qRsp rsp + return $ case qRsp rsp of + Left err -> Left err + Right dom -> Right $ descend xs dom _ -> return $ Left "Only \".bit\" domain is supported" @@ -92,24 +96,18 @@ main = do forever $ do l <- getLine case pdnsParse ver l of - Left e -> putStrLn $ "ERROR\t" ++ e + Left e -> putStrLn $ "FAIL\t" ++ e Right preq -> do case preq of - PdnsRequestQ qname qtype id _ _ _ -> do - ncres <- queryNmc mgr cfg qname id - case ncres of - Left e -> putStrLn $ "ERROR\t" ++ e - Right dom -> putStrLn $ pdnsOut qtype dom + PdnsRequestQ qname qtype id _ _ _ -> + queryNmc mgr cfg qname id >>= putStr . (pdnsOut ver qtype) PdnsRequestAXFR xfrreq -> - putStrLn ("ERROR\tNo support for AXFR " ++ xfrreq) - PdnsRequestPing -> putStrLn "OK" + putStrLn ("FAIL\tNo support for AXFR " ++ xfrreq) + PdnsRequestPing -> putStrLn "END" -- for testing ask str = do cfg <- readConfig confFile mgr <- newManager def - ncres <- queryNmc mgr cfg str "test-req-id" - case ncres of - Left e -> putStrLn $ "ERROR\t" ++ e - Right dom -> putStrLn $ pdnsOut RRTypeANY dom + queryNmc mgr cfg str "test-req-id" >>= putStr . (pdnsOut 1 RRTypeANY)