]> gitweb.michael.orlitzky.com - dead/harbl.git/blobdiff - harbl-cli/src/Configuration.hs
Add a "threshold" to the configuration.
[dead/harbl.git] / harbl-cli / src / Configuration.hs
index a6798e97f08f38803edb0116a2f5080bffae5465..c3c55f0489189ab9ef2c2d201c0b7a9d556aa8eb 100644 (file)
@@ -7,14 +7,17 @@ module Configuration (
   merge_optional )
 where
 
   merge_optional )
 where
 
-import Data.Monoid ( Monoid(..) )
+-- System imports.
 import System.Console.CmdArgs.Default ( Default(..) )
 
 import System.Console.CmdArgs.Default ( Default(..) )
 
--- From the harbl library.
+-- Harbl library imports.
 import Network.DNS.RBL.Weight ( Weight )
 
 import Network.DNS.RBL.Weight ( Weight )
 
+-- Local imports.
 import qualified OptionalConfiguration as OC (
 import qualified OptionalConfiguration as OC (
-  OptionalConfiguration(..) )
+  OptionalConfiguration(..),
+  merge_maybe,
+  merge_monoid )
 import Hosts ( Hosts(..) )
 import Lists ( Lists(..) )
 
 import Hosts ( Hosts(..) )
 import Lists ( Lists(..) )
 
@@ -25,8 +28,8 @@ import Lists ( Lists(..) )
 data Configuration =
   Configuration {
     hosts  :: Hosts,
 data Configuration =
   Configuration {
     hosts  :: Hosts,
-    lists  :: Lists }
---    threshold :: Weight }
+    lists  :: Lists,
+    threshold :: Weight }
     deriving (Show)
 
 
     deriving (Show)
 
 
@@ -35,8 +38,8 @@ data Configuration =
 --
 instance Default Configuration where
   def = Configuration { hosts = def,
 --
 instance Default Configuration where
   def = Configuration { hosts = def,
-                        lists = def }
---                        threshold = def }
+                        lists = def,
+                        threshold = def }
 
 
 -- | Merge a 'Configuration' with an 'OptionalConfiguration'. This is
 
 
 -- | Merge a 'Configuration' with an 'OptionalConfiguration'. This is
@@ -46,8 +49,8 @@ instance Default Configuration where
 merge_optional :: Configuration
                -> OC.OptionalConfiguration
                -> Configuration
 merge_optional :: Configuration
                -> OC.OptionalConfiguration
                -> Configuration
-merge_optional cfg opt_cfg =
-  Configuration all_hosts all_lists
+merge_optional cfg opt_cfg = Configuration hs ls t
   where
   where
-    all_hosts = (hosts cfg) `mappend` (OC.hosts opt_cfg)
-    all_lists = (lists cfg) `mappend` (OC.lists opt_cfg)
+    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)