]> www.average.org Git - pdns-pipe-nmc.git/blob - Config.hs
new binary version
[pdns-pipe-nmc.git] / Config.hs
1 module Config ( Config(..)
2               , readConfig
3               ) where
4
5 import Data.ConfigFile
6 import Data.Either.Utils
7 import Data.List.Split
8
9 data Config = Config { rpcuser       :: String
10                      , rpcpassword   :: String
11                      , rpchost       :: String
12                      , rpcport       :: Int
13                      } deriving (Show)
14
15 readConfig :: String -> IO Config
16 readConfig f = do
17   cp <- return . forceEither =<< readfile emptyCP f
18   return (Config { rpcuser       = getSetting cp "rpcuser"     ""
19                  , rpcpassword   = getSetting cp "rpcpassword" ""
20                  , rpchost       = getSetting cp "rpchost"     "localhost"
21                  , rpcport       = getSetting cp "rpcport"     8336
22                  })
23     where
24       getSetting cp x dfl = case get cp "DEFAULT" x of
25                               Left  _ -> dfl
26                               Right x -> x
27