-> IO (Either String NmcDom) -- ^ result with merged import
mergeIncl queryOp depth base = do
let
- mbase = (expandSrv . splitSubdoms . mergeSelf) base
+ mbase = ({-expandSrv .-} splitSubdoms . mergeSelf) base
base' = mbase {domDelegate = Nothing, domImport = Nothing}
-- print base
if depth <= 0 then return $ Left "Nesting of imports is too deep"
sub <- queryNmcDom queryOp key
case sub of
Left err -> return $ Left err
- Right sub' -> mergeIncl queryOp (depth - 1) $ sub' `mergeNmcDom` acc
+ Right sub' -> mergeIncl queryOp (depth - 1) $ sub' `merge` acc
-- | If there is an element in the map with key "", merge the contents
-- and remove this element. Do this recursively.
mergeSelf :: NmcDom -> NmcDom
mergeSelf base =
let
- map = domMap base
- base' = base {domMap = removeSelf map}
+ map = domSubmap base
+ base' = base {domSubmap = removeSelf map}
removeSelf Nothing = Nothing
removeSelf (Just map) = if size map' == 0 then Nothing else Just map'
where map' = delete "" map
Just map' ->
case lookup "" map' of
Nothing -> base'
- Just sub -> (mergeSelf sub) `mergeNmcDom` base'
+ Just sub -> (mergeSelf sub) `merge` base'
-- recursion depth limited by the size of the record
-
+{-
-- | replace Service with Srv down in the Map
expandSrv :: NmcDom -> NmcDom
expandSrv base =
Nothing -> base'
Just sl -> foldr addSrvMx base' sl
where
- addSrvMx sr acc = sub1 `mergeNmcDom` acc
+ addSrvMx sr acc = sub1 `merge` acc
where
- sub1 = def { domMap = Just (singleton proto sub2)
+ sub1 = def { domSubmap = Just (singleton proto sub2)
, domMx = maybemx}
- sub2 = def { domMap = Just (singleton srvid sub3) }
+ sub2 = def { domSubmap = Just (singleton srvid sub3) }
sub3 = def { domSrv = Just [srvStr] }
proto = "_" ++ (srvProto sr)
srvid = "_" ++ (srvName sr)
&& srvPort sr == 25
then Just [(show (srvPrio sr)) ++ "\t" ++ (srvHost sr)]
else Nothing
-{-
--- | replace Tls with Tlsa down in the Map
--- This function is almost, but not quite, entirely unlike expandSrv.
-expandTls :: NmcDom -> NmcDom
-expandTls base =
- let
- base' = base { domTls = Nothing }
- in
- case domTls base of
- Nothing -> base'
- Just sl -> foldr addTlsa base' sl
- where
- addTlsa sr acc = sub1 `mergeNmcDom` acc
- where
- sub1 = def { domMap = Just (singleton proto sub2) }
- sub2 = def { domMap = Just (singleton port sub3) }
- sub3 = def { domTlsa = Just [tlsStr] }
- proto = "_" ++ (tlsProto sr)
- port = "_" ++ (tlsName sr)
- tlsStr = (show (tlsPrio sr)) ++ "\t"
- ++ (show (tlsWeight sr)) ++ " "
- ++ (show (tlsPort sr)) ++ " "
- ++ (tlsHost sr)
-}
-
-- | Convert map elements of the form "subN...sub2.sub1.dom.bit"
-- into nested map and merge it
splitSubdoms :: NmcDom -> NmcDom
splitSubdoms base =
let
- base' = base { domMap = Nothing }
+ base' = base { domSubmap = Nothing }
in
- case domMap base of
+ case domSubmap base of
Nothing -> base'
- Just sdmap -> (def { domMap = Just sdmap' }) `mergeNmcDom` base'
+ Just sdmap -> (def { domSubmap = Just sdmap' }) `merge` base'
where
sdmap' = foldrWithKey stow empty sdmap
- stow fqdn sdom acc = insertWith mergeNmcDom fqdn' sdom' acc
+ stow fqdn sdom acc = insertWith merge fqdn' sdom' acc
where
(fqdn', sdom') =
nest (filter (/= "") (splitOnDots fqdn), sdom)
nest ([], v) = (fqdn, v) -- can split result be empty?
nest ([k], v) = (k, v)
nest (k:ks, v) =
- nest (ks, def { domMap = Just (singleton k v) })
+ nest (ks, def { domSubmap = Just (singleton k v) })
-- | transfer some elements of `base` into `sub`, notably TLSA
propagate :: NmcDom -> NmcDom -> NmcDom
Just ns -> def { domNs = domNs dom, domEmail = domEmail dom }
translateNormalizer dom = case domTranslate dom of
Nothing -> dom
- Just tr -> dom { domMap = Nothing }
+ Just tr -> dom { domSubmap = Nothing }
-- | Merge imports and Selfs and follow the maps tree to get dom
descendNmcDom ::
case base' of
Left err -> return base'
Right base'' ->
- case domMap base'' of
+ case domSubmap base'' of
Nothing -> return $ Right def
Just map ->
case lookup d map of