X-Git-Url: http://www.average.org/gitweb/?p=pdns-pipe-nmc.git;a=blobdiff_plain;f=NmcDom.hs;h=79402e7da1b8f185421842552195c06a8b895812;hp=3ab8c7fd40aa6213e8e47f63459a9fac296edeb1;hb=aa91db8940672a57169b1bb400fa3c1a1e9dd335;hpb=946bf9517524052ccb0cfa9ee2568c76848c49d2 diff --git a/NmcDom.hs b/NmcDom.hs index 3ab8c7f..79402e7 100644 --- a/NmcDom.hs +++ b/NmcDom.hs @@ -5,7 +5,6 @@ module NmcDom ( NmcDom(..) , NmcRRI2p(..) , NmcRRTls(..) , NmcRRDs(..) - , emptyNmcDom , mergeNmcDom ) where @@ -20,6 +19,7 @@ import Data.Map (Map, unionWith) import qualified Data.HashMap.Strict as H (lookup) import Data.Aeson import Data.Aeson.Types +import Data.Default.Class -- Variant of Aeson's `.:?` that interprets a String as a -- single-element list, so it is possible to have either @@ -157,14 +157,19 @@ data NmcDom = NmcDom { domService :: Maybe [NmcRRService] , domSrv :: Maybe [String] -- Synthetic } deriving (Show, Eq) +instance Default NmcDom where + def = NmcDom Nothing Nothing Nothing Nothing Nothing Nothing Nothing + Nothing Nothing Nothing Nothing Nothing Nothing Nothing + Nothing Nothing Nothing Nothing Nothing Nothing + instance FromJSON NmcDom where -- Wherever we expect a domain object, there may be a string -- containing IPv4 address. Interpret it as such. -- Question: shall we try to recognize IPv6 addresses too? parseJSON (String s) = return $ if isIPv4 s' - then emptyNmcDom { domIp = Just [s'] } - else emptyNmcDom + then def { domIp = Just [s'] } + else def where s' = unpack s isIPv4 x = all isNibble $ splitOn "." x @@ -227,8 +232,3 @@ instance Mergeable NmcDom where mergeNmcDom :: NmcDom -> NmcDom -> NmcDom mergeNmcDom = merge - -emptyNmcDom = NmcDom Nothing Nothing Nothing Nothing Nothing Nothing - Nothing Nothing Nothing Nothing Nothing Nothing - Nothing Nothing Nothing Nothing Nothing Nothing - Nothing Nothing