X-Git-Url: http://www.average.org/gitweb/?p=pdns-pipe-nmc.git;a=blobdiff_plain;f=pdns-pipe-nmc.hs;h=a933c9ca70ade2f57d3c3a46b91b80923bf41d90;hp=ba6289944877d8e464d70afbe55ab2ba6f65a8b6;hb=26b23d266b588ea4b5bc4d53cbf479f9b40d26a0;hpb=adf1eff6277a0f1fb69f505285a20554a9ecabd6 diff --git a/pdns-pipe-nmc.hs b/pdns-pipe-nmc.hs index ba62899..a933c9c 100644 --- a/pdns-pipe-nmc.hs +++ b/pdns-pipe-nmc.hs @@ -2,45 +2,23 @@ module Main where ---import Control.Applicative 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.ConfigFile -import Data.Either.Utils import Data.List.Split import Data.Aeson (encode, decode, Value(..)) import Network.HTTP.Types import Data.Conduit import Network.HTTP.Conduit -import Data.JsonRpcClient + +import JsonRpcClient +import Config import PowerDns import NmcJson confFile = "/etc/namecoin.conf" --- Config file handling - -data Config = Config { rpcuser :: String - , rpcpassword :: String - , rpchost :: String - , rpcport :: Int - } deriving (Show) - -readConfig :: String -> IO Config -readConfig f = do - cp <- return . forceEither =<< readfile emptyCP f - return (Config { rpcuser = getSetting cp "rpcuser" "" - , rpcpassword = getSetting cp "rpcpassword" "" - , rpchost = getSetting cp "rpchost" "localhost" - , rpcport = getSetting cp "rpcport" 8336 - }) - where - getSetting cp x dfl = case get cp "DEFAULT" x of - Left _ -> dfl - Right x -> x - -- HTTP/JsonRpc interface qReq :: Config -> ByteString -> ByteString -> Request m @@ -105,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 qn qt id lip rip eip -> do + ncres <- queryNmc mgr cfg (qName preq) (qType preq) (iD preq) + case ncres of + Left e -> putStrLn $ "ERROR\t" ++ e + Right dom -> putStrLn $ pdnsOut dom + PdnsRequestAXFR xfrreq -> + putStrLn ("ERROR\t No support for AXFR " ++ xfrreq) + PdnsRequestPing -> putStrLn "OK"