X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FConfiguration.hs;h=042cddbe0a5f137d9ac8eb8f207e31f76da58142;hb=HEAD;hp=a90af38435cbcd3df1fefd767f401203a4bfa169;hpb=160caf38b6e936b6541b31b3c9bbe952ba0a4b15;p=dead%2Fhtsn.git diff --git a/src/Configuration.hs b/src/Configuration.hs index a90af38..042cddb 100644 --- a/src/Configuration.hs +++ b/src/Configuration.hs @@ -13,15 +13,21 @@ import System.Log ( Priority( INFO ) ) import qualified OptionalConfiguration as OC ( OptionalConfiguration(..), merge_maybes ) -import TSN.FeedHosts (FeedHosts(..)) +import FeedHosts (FeedHosts(..)) +-- | The main configuration data type. This will be passed to most of +-- the important functions once it has been created. data Configuration = Configuration { + daemonize :: Bool, feed_hosts :: FeedHosts, log_file :: Maybe FilePath, log_level :: Priority, - password :: String, output_directory :: FilePath, + password :: String, + pidfile :: FilePath, + run_as_group :: Maybe String, + run_as_user :: Maybe String, syslog :: Bool, username :: String } deriving (Show) @@ -29,22 +35,37 @@ data Configuration = -- | A Configuration with all of its fields set to their default -- values. instance Default Configuration where - def = Configuration def def INFO def "." def def + def = Configuration { + daemonize = def, + feed_hosts = def, + log_file = def, + log_level = INFO, + output_directory = ".", + password = def, + pidfile = "/run/htsn/htsn.pid", + run_as_group = def, + run_as_user = def, + syslog = def, + username = 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 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 + (merge (daemonize cfg) (OC.daemonize opt_cfg)) all_feed_hosts (OC.merge_maybes (log_file cfg) (OC.log_file opt_cfg)) (merge (log_level cfg) (OC.log_level opt_cfg)) - (merge (password cfg) (OC.password opt_cfg)) (merge (output_directory cfg) (OC.output_directory opt_cfg)) + (merge (password cfg) (OC.password opt_cfg)) + (merge (pidfile cfg) (OC.pidfile opt_cfg)) + (OC.merge_maybes (run_as_group cfg) (OC.run_as_group opt_cfg)) + (OC.merge_maybes (run_as_user cfg) (OC.run_as_user opt_cfg)) (merge (syslog cfg) (OC.syslog opt_cfg)) (merge (username cfg) (OC.username opt_cfg)) where