X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FTSN%2FFeedHosts.hs;h=81f57aa53f1506d06821036e7fa8d9d81c2a52a6;hb=ac3a81eb6d0f8ca4e212752d5b390a4fc220cceb;hp=0b2056ec3ee983587b2ed74133ebfebc15fa6bdd;hpb=95e23e65db31cf51c9f207a6b447da19920ee1a1;p=dead%2Fhtsn.git diff --git a/src/TSN/FeedHosts.hs b/src/TSN/FeedHosts.hs index 0b2056e..81f57aa 100644 --- a/src/TSN/FeedHosts.hs +++ b/src/TSN/FeedHosts.hs @@ -13,16 +13,22 @@ where -- DC is needed only for the DCT.Configured instance of String. import qualified Data.Configurator as DC() -import qualified Data.Configurator.Types as DCT +import qualified Data.Configurator.Types as DCT ( + Configured, + Value( List ), + convert ) import Data.Data (Data) import System.Console.CmdArgs.Default (Default(..)) import Data.Typeable (Typeable) +-- | A (wrapper around a) list of hostnames that supply the XML feed. +-- newtype FeedHosts = FeedHosts { get_feed_hosts :: [String] } deriving (Data, Show, Typeable) + instance Default FeedHosts where -- | The default list of feed hosts. These were found by checking -- PTR records in the neighborhood of the IP address in use. There @@ -34,11 +40,18 @@ instance Default FeedHosts where instance DCT.Configured FeedHosts where + -- | This allows us to read a FeedHosts object out of a Configurator + -- config file. By default Configurator wouldn't know what to do, + -- so we have to tell it that we expect a list, and if that list + -- has strings in it, we can apply the FeedHosts constructor to + -- it. convert (DCT.List xs) = + -- mapM gives us a Maybe [String] here. fmap FeedHosts (mapM convert_string xs) where convert_string :: DCT.Value -> Maybe String convert_string = DCT.convert + -- If we read anything other than a list of values out of the file, + -- fail. convert _ = Nothing -