import Prelude hiding (lookup, readFile)
import System.Environment
+import System.Console.GetOpt
import System.IO hiding (readFile)
import System.IO.Error
import Data.Time.Clock.POSIX
-- Yet another - to use (const - expires_in) from the lookup.
nmcAge = fmap (\x -> floor ((x - 1303070400) / 600)) getPOSIXTime
--- Main entries
+-- run a PowerDNS coprocess. Negotiate ABI version and execute requests.
mainPdnsNmc = do
"AXFR" -> pdnsOutXfr 1 (-1) gen key dom
_ -> pdnsOutQ 1 (-1) gen key (rrType qt) dom
--- query by key from Namecoin
+-- run one query by key from Namecoin, print domain object and answer
mainOne gen key qt = do
cfg <- readConfig confFile
putStrLn $ ppShow dom
putStr $ pdnsOut gen key qt dom
--- using file backend for testing json domain data
+-- get data from the file, print domain object and answer
mainFile gen key qt = do
dom <- queryDom queryOpFile key
main = do
args <- getArgs
gen <- nmcAge
+ let
+ with f xs = case xs of
+ [qfqdn, qtype] -> f gen qfqdn qtype
+ _ -> error $ "usage: empty args, or \"[-f] <fqdn> {<TYPE>|ANY|AXFR}\""
+ ++ " (type in caps)"
case args of
- [] -> mainPdnsNmc
- [key, qtype] -> mainOne gen key qtype
- ["-f" ,key, qtype] -> mainFile gen key qtype
- _ -> error $ "usage: empty args, or \"[-f] <fqdn> {<TYPE>|ANY|AXFR}\" (type in caps)"
+ [] -> mainPdnsNmc
+ "-f":xs -> with mainFile xs
+ _ -> with mainOne args