X-Git-Url: http://www.average.org/gitweb/?p=pdns-pipe-nmc.git;a=blobdiff_plain;f=NmcDom.hs;h=1ccf836b9049b8bfe15aebbefda18d67bea4f233;hp=90c7966064afe24cfba4321d405aed70f0535de6;hb=890c9222bd6d44ff1d499fc3124c53e36d5fe61d;hpb=c3a4cdbe13176c6b6327c7bac775d0bc6be2819c diff --git a/NmcDom.hs b/NmcDom.hs index 90c7966..1ccf836 100644 --- a/NmcDom.hs +++ b/NmcDom.hs @@ -4,7 +4,7 @@ module NmcDom ( NmcDom(..) , NmcRRService(..) , NmcRRI2p(..) , NmcRRTls(..) - , emptyNmcDom + , NmcRRDs(..) , mergeNmcDom ) where @@ -19,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 @@ -80,16 +81,16 @@ instance Mergeable NmcRRService where merge _ b = b data NmcRRI2p = NmcRRI2p - { i2pDestination :: String - , i2pName :: String - , i2pB32 :: String + { i2pDestination :: Maybe String + , i2pName :: Maybe String + , i2pB32 :: Maybe String } deriving (Show, Eq) instance FromJSON NmcRRI2p where parseJSON (Object o) = NmcRRI2p - <$> o .: "destination" - <*> o .: "name" - <*> o .: "b32" + <$> o .:? "destination" + <*> o .:? "name" + <*> o .:? "b32" parseJSON _ = empty instance Mergeable NmcRRI2p where @@ -153,16 +154,23 @@ data NmcDom = NmcDom { domService :: Maybe [NmcRRService] (Map String [NmcRRTls])) , domDs :: Maybe [NmcRRDs] , domMx :: Maybe [String] -- Synthetic + , domSrv :: Maybe [String] -- Synthetic + , domTlsa :: 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 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 @@ -189,6 +197,8 @@ instance FromJSON NmcDom where <*> o .:? "tls" <*> o .:? "ds" <*> return Nothing -- domMx not parsed + <*> return Nothing -- domSrv not parsed + <*> return Nothing -- domTlsa not parsed parseJSON _ = empty instance Mergeable NmcDom where @@ -211,6 +221,8 @@ instance Mergeable NmcDom where , domTls = mergelm domTls , domDs = mergelm domDs , domMx = mergelm domMx + , domSrv = mergelm domSrv + , domTlsa = mergelm domTlsa } where mergelm x = merge (x sub) (x dom) @@ -223,8 +235,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