X-Git-Url: http://www.average.org/gitweb/?p=pdns-pipe-nmc.git;a=blobdiff_plain;f=pdns-pipe-nmc.hs;h=ee5bd3771a900dd880f2add5c7dcacff6a100ae9;hp=f61d7baecf5ae61faa20d39adeb62a0e208e7699;hb=bae658dcd2084b5f5be71987c6eba23f4106818a;hpb=e8fbbca8429c42f84bab9e1ab14bb1ff52c5e4cd diff --git a/pdns-pipe-nmc.hs b/pdns-pipe-nmc.hs index f61d7ba..ee5bd37 100644 --- a/pdns-pipe-nmc.hs +++ b/pdns-pipe-nmc.hs @@ -49,9 +49,9 @@ qRsp rsp = -- NMC interface -queryNmc :: Manager -> Config -> String -> RRType -> String +queryNmc :: Manager -> Config -> String -> String -> IO (Either String NmcDom) -queryNmc mgr cfg fqdn qtype qid = do +queryNmc mgr cfg fqdn qid = do case reverse (splitOn "." fqdn) of "bit":dn:xs -> do rsp <- runResourceT $ @@ -83,18 +83,17 @@ main = do putStrLn $ "OK\tDnsNmc ready to serve, protocol v." ++ (show ver) mgr <- newManager def - - print $ qReq cfg "d/nosuchdomain" "query-nmc" - rsp <- runResourceT $ httpLbs (qReq cfg "d/nosuchdomain" "query-nmc") mgr - print $ (statusCode . responseStatus) rsp - putStrLn "===== complete response is:" - print rsp - let rbody = responseBody rsp - putStrLn "===== response body is:" - print rbody - let result = parseJsonRpc rbody :: Either JsonRpcError NmcRes - putStrLn "===== parsed response is:" - print result --- print $ parseJsonRpc (responseBody rsp) - - --forever $ getLine >>= (pdnsOut uri) . (pdnsParse ver) + forever $ do + l <- getLine + case pdnsParse ver l of + Left e -> putStrLn $ "ERROR\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 + PdnsRequestAXFR xfrreq -> + putStrLn ("ERROR\tNo support for AXFR " ++ xfrreq) + PdnsRequestPing -> putStrLn "OK"