X-Git-Url: http://www.average.org/gitweb/?p=pdns-pipe-nmc.git;a=blobdiff_plain;f=Config.hs;fp=Config.hs;h=070b422b0f73e7e8aaf8c96a539a97a4a563878a;hp=0000000000000000000000000000000000000000;hb=9e72c063ba8c5d23ad3061d31098ce05dcfcc3cd;hpb=adf1eff6277a0f1fb69f505285a20554a9ecabd6 diff --git a/Config.hs b/Config.hs new file mode 100644 index 0000000..070b422 --- /dev/null +++ b/Config.hs @@ -0,0 +1,27 @@ +module Config ( Config(..) + , readConfig + ) where + +import Data.ConfigFile +import Data.Either.Utils +import Data.List.Split + +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 +