-- | This module defines the 'Configuration' type, which is just a -- wrapper around all of the configuration options we accept on the -- command line. -- module Configuration ( Configuration(..), merge_optional ) where -- System imports. import System.Console.CmdArgs.Default ( Default(..) ) -- Harbl library imports. import Network.DNS.RBL.Weight ( Weight ) -- Local imports. import qualified OptionalConfiguration as OC ( OptionalConfiguration(..), merge_maybe, merge_monoid ) import Hosts ( Hosts(..) ) import Lists ( Lists(..) ) -- | The main configuration data type. This will be passed to most of -- the important functions once it has been created. -- data Configuration = Configuration { hosts :: Hosts, lists :: Lists, threshold :: Weight } deriving (Show) -- | A Configuration with all of its fields set to their default -- values. -- instance Default Configuration where def = Configuration { hosts = def, lists = def, threshold = def } -- | Merge a 'Configuration' with an 'OptionalConfiguration'. This is -- more or less the Monoid instance for 'OptionalConfiguration', but -- since the two types are different, we have to repeat ourselves. -- merge_optional :: Configuration -> OC.OptionalConfiguration -> Configuration merge_optional cfg opt_cfg = Configuration hs ls t where hs = OC.merge_monoid (hosts cfg) (OC.hosts opt_cfg) ls = OC.merge_monoid (lists cfg) (OC.lists opt_cfg) t = OC.merge_maybe (threshold cfg) (OC.threshold opt_cfg)