X-Git-Url: http://www.average.org/gitweb/?p=pdns-pipe-nmc.git;a=blobdiff_plain;f=NmcTransform.hs;h=d9a98d00459a595e05bc0850f9afd43ca8b386cf;hp=3cd37dfe314e46cbdb09918c12fb5f646bf6ef71;hb=e426dad1c624b87722fdde752258feaf92d103f2;hpb=aa91db8940672a57169b1bb400fa3c1a1e9dd335 diff --git a/NmcTransform.hs b/NmcTransform.hs index 3cd37df..d9a98d0 100644 --- a/NmcTransform.hs +++ b/NmcTransform.hs @@ -39,7 +39,7 @@ mergeIncl :: -> IO (Either String NmcDom) -- ^ result with merged import mergeIncl queryOp depth base = do let - mbase = (expandSrv . splitSubdoms . mergeSelf) base + mbase = (splitSubdoms . mergeSelf) base base' = mbase {domDelegate = Nothing, domImport = Nothing} -- print base if depth <= 0 then return $ Left "Nesting of imports is too deep" @@ -53,15 +53,15 @@ mergeIncl queryOp depth base = do 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 @@ -71,51 +71,22 @@ mergeSelf base = 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 = - let - base' = base { domService = Nothing } - in - case domService base of - Nothing -> base' - Just sl -> foldr addSrvMx base' sl - where - addSrvMx sr acc = sub1 `mergeNmcDom` acc - where - sub1 = def { domMap = Just (singleton proto sub2) - , domMx = maybemx} - sub2 = def { domMap = Just (singleton srvid sub3) } - sub3 = def { domSrv = Just [srvStr] } - proto = "_" ++ (srvProto sr) - srvid = "_" ++ (srvName sr) - srvStr = (show (srvPrio sr)) ++ "\t" - ++ (show (srvWeight sr)) ++ " " - ++ (show (srvPort sr)) ++ " " - ++ (srvHost sr) - maybemx = - if srvName sr == "smtp" - && srvProto sr == "tcp" - && srvPort sr == 25 - then Just [(show (srvPrio sr)) ++ "\t" ++ (srvHost sr)] - else Nothing - -- | 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) @@ -123,7 +94,11 @@ splitSubdoms base = 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 +propagate base sub = sub -- FIXME implement it -- | Presence of some elements require removal of some others normalizeDom :: NmcDom -> NmcDom @@ -136,7 +111,7 @@ normalizeDom dom = foldr id dom [ translateNormalizer 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 :: @@ -152,12 +127,12 @@ descendNmcDom queryOp subdom base = do 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 Nothing -> return $ Right def - Just sub -> descendNmcDom queryOp ds sub + Just sub -> descendNmcDom queryOp ds $ propagate base'' sub -- | Initial NmcDom populated with "import" only, suitable for "descend" seedNmcDom ::