-{-
-queryNmc :: String -> String -> RRType -> String -> IO (Either String NmcDom)
-queryNmc uri fqdn qtype qid = do
- case reverse (splitOn "." fqdn) of
- "bit":dn:xs -> do
- ans <- detailledRemote Version1 [] uri "name_show" $ "d/" ++ dn
- let mdom = decode (resValue ans) :: Maybe NmcDom
- case mdom of
- Nothing -> return $ Left ("Unparseable: " ++ (show (resValue ans)))
- Just dom -> return $ Right dom
- _ ->
- return $ Left "Only \".bit\" domain is supported"
--}
--- PowerDNS ABI
-
-data RRType = RRTypeSRV | RRTypeA | RRTypeAAAA | RRTypeCNAME
- | RRTypeDNAME | RRTypeSOA | RRTypeRP | RRTypeLOC
- | RRTypeNS | RRTypeDS
- | RRTypeANY | RRTypeError String
- deriving (Show)
-
-data PdnsRequest = PdnsRequestQ
- { qName :: String
- , qType :: RRType
- , iD :: String
- , remoteIpAddress :: String
- , localIpAddress :: Maybe String
- , ednsSubnetAddress :: Maybe String
- }
- | PdnsRequestAXFR String
- | PdnsRequestPing
- deriving (Show)
-
-pdnsParse ver s =
- let
- getQt qt = case qt of
- "SRV" -> RRTypeSRV
- "A" -> RRTypeA
- "AAAA" -> RRTypeAAAA
- "CNAME" -> RRTypeCNAME
- "DNAME" -> RRTypeDNAME
- "SOA" -> RRTypeSOA
- "RP" -> RRTypeRP
- "LOC" -> RRTypeLOC
- "NS" -> RRTypeNS
- "DS" -> RRTypeDS
- "ANY" -> RRTypeANY
- _ -> RRTypeError qt
- getLIp ver xs
- | ver >= 2 = case xs of
- x:_ -> Just x
- _ -> Nothing
- | otherwise = Nothing
- getRIp ver xs
- | ver >= 3 = case xs of
- _:x:_ -> Just x
- _ -> Nothing
- | otherwise = Nothing
- in
- case words s of
- "PING":[] -> Right PdnsRequestPing
- "AXFR":x:[] -> Right (PdnsRequestAXFR x)
- "Q":qn:"IN":qt:id:rip:xs -> Right (PdnsRequestQ
- { qName = qn
- , qType = getQt qt
- , iD = id
- , remoteIpAddress = rip
- , localIpAddress = getLIp ver xs
- , ednsSubnetAddress = getRIp ver xs
- })
- _ -> Left s
-
-{-
-pdnsOut :: String -> Either String PdnsRequest -> IO ()
-pdnsOut _ (Left e) = putStrLn ("ERROR\tUnparseable request: " ++ e)
-pdnsOut uri (Right rq) = case rq of
- PdnsRequestQ qn qt id lip rip eip -> do
- dom <- queryNmc uri qn qt id
- case dom of
- Left e -> putStrLn ("ERROR\tNmc query error: " ++ e)
- Right result -> print result
- PdnsRequestAXFR xfrreq ->
- putStrLn ("ERROR\t No support for AXFR " ++ xfrreq)
- PdnsRequestPing -> putStrLn "OK"
--}
+queryNmc :: Manager -> Config -> String -> String
+ -> IO (Either String NmcDom)
+queryNmc mgr cfg qid fqdn =
+ case reverse (splitOn "." fqdn) of
+ "bit":dn:xs -> descendNmcDom queryOp xs $ seedNmcDom dn
+ _ -> return $ Left "Only \".bit\" domain is supported"
+ where
+ queryOp key = do
+ rsp <- runResourceT $ httpLbs (qReq cfg key qid) mgr
+ -- print $ qRsp rsp
+ return $ qRsp rsp