From: Eugene Crosser Date: Sun, 30 Mar 2014 17:41:50 +0000 (+0400) Subject: domain normalization X-Git-Tag: 0.9.0.0~105 X-Git-Url: http://average.org/gitweb/?a=commitdiff_plain;h=7350de03fb105bb8f46e96160bcb32fc75f04d61;p=pdns-pipe-nmc.git domain normalization --- diff --git a/NmcJson.hs b/NmcJson.hs index 1d8bc9c..f773366 100644 --- a/NmcJson.hs +++ b/NmcJson.hs @@ -105,22 +105,31 @@ instance FromJSON NmcRes where <*> o .: "expires_in" parseJSON _ = empty +normalizeDom :: NmcDom -> NmcDom +normalizeDom dom + | domNs dom /= Nothing = emptyNmcDom { domNs = domNs dom } + | domDelegate dom /= Nothing = emptyNmcDom -- FIXME + | domTranslate dom /= Nothing = dom { domMap = Nothing } + | otherwise = dom + descendNmc :: [String] -> NmcDom -> NmcDom -descendNmc subdom dom = case subdom of - [] -> - case domMap dom of - Nothing -> dom - Just map -> - case M.lookup "" map of -- Stupid, but "" is allowed in the map - Nothing -> dom -- Try to merge it with the root data - Just sub -> mergeNmc sub dom - d:ds -> - case domMap dom of - Nothing -> emptyNmcDom - Just map -> - case M.lookup d map of - Nothing -> emptyNmcDom - Just sub -> descendNmc ds sub +descendNmc subdom rawdom = + let dom = normalizeDom rawdom + in case subdom of + [] -> + case domMap dom of + Nothing -> dom + Just map -> + case M.lookup "" map of -- Stupid, but there are "" in the map + Nothing -> dom -- Try to merge it with the root data + Just sub -> mergeNmc sub dom -- Or maybe drop it altogether... + d:ds -> + case domMap dom of + Nothing -> emptyNmcDom + Just map -> + case M.lookup d map of + Nothing -> emptyNmcDom + Just sub -> descendNmc ds sub -- FIXME -- I hope there exists a better way to merge records! mergeNmc :: NmcDom -> NmcDom -> NmcDom