1 -- | This module defines the 'Configuration' type, which is just a
2 -- wrapper around all of the configuration options we accept on the
10 import System.Console.CmdArgs.Default ( Default( def ) )
12 import MxList ( MxList( get_mxs ) )
13 import qualified OptionalConfiguration as OC (
14 OptionalConfiguration(..),
17 -- | The main configuration data type. This will be passed to most of
18 -- the important functions once it has been created.
22 database :: Maybe String,
23 domain_query :: String,
25 forward_query :: String,
27 password :: Maybe String,
29 username :: Maybe String }
33 -- | A Configuration with all of its fields set to their default
36 instance Default Configuration where
39 domain_query = def_domain_query,
41 forward_query = def_forward_query,
47 def_domain_query = "SELECT domain " ++
49 "WHERE domain <> 'ALL' " ++
52 def_forward_query = "SELECT address,goto " ++
56 -- | Merge a 'Configuration' with an 'OptionalConfiguration'. This is
57 -- more or less the Monoid instance for 'OptionalConfiguration', but
58 -- since the two types are different, we have to repeat ourselves.
60 merge_optional :: Configuration
61 -> OC.OptionalConfiguration
63 merge_optional cfg opt_cfg =
65 (OC.merge_maybes (database cfg) (OC.database opt_cfg))
66 (merge (domain_query cfg) (OC.domain_query opt_cfg))
68 (merge (forward_query cfg) (OC.forward_query opt_cfg))
69 (OC.merge_maybes (host cfg) (OC.host opt_cfg))
70 (OC.merge_maybes (password cfg) (OC.password opt_cfg))
71 (OC.merge_maybes (port cfg) (OC.port opt_cfg))
72 (OC.merge_maybes (username cfg) (OC.username opt_cfg))
74 -- | If the thing on the right is Just something, return that
75 -- something, otherwise return the thing on the left.
76 merge :: a -> Maybe a -> a
80 -- If there are any optional usernames, use only those.
81 all_excluded_mx = if (null (get_mxs (OC.exclude_mx opt_cfg)))
83 else (OC.exclude_mx opt_cfg)