From 80ae5c930e028d0fd5ec1afb76cf10327ab6bd0e Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Tue, 4 Nov 2014 09:33:09 -0500 Subject: [PATCH] Normalize results to prevent false positives in Main. --- src/Main.hs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/Main.hs b/src/Main.hs index 70fa2f5..3e8d8c0 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -9,7 +9,7 @@ import qualified Data.ByteString.Char8 as BS ( getContents, pack, words ) -import Data.List ((\\)) +import Data.List ( (\\) ) import Data.String.Utils (join) import Network.DNS ( Domain, @@ -35,30 +35,37 @@ import Timeout (Timeout(..)) -- | Given a list of delegates, report results for this --- LookupResult. +-- 'LookupResult'. -- -- If there's an empty list in the second component, there were no -- query results, so we report that the domain was not delegated. If -- there were some results and there are leftovers (after removing -- the delegates), we report those as well. -- +-- Before processing, all names are normalized using the supplied +-- function @normalize_function@. Ideally this should be the same +-- function applied to the user-input names. +-- report :: [Domain] -- ^ The list of @delgts@ + -> (Domain -> Domain) -- ^ Domain name normalization function, + -- @normalize_function@. -> LookupResult -> IO () -- If the lookup resulted in a DNS error, we just ignore the whole -- thing. -report _ (_, Left _) = return () +report _ _ (_, Left _) = return () -- If the lookup succeeded but there were no results, report that the -- domain is not delegated. -report _ (d, Right []) = +report _ _ (d, Right []) = putStrLn $ "Domain " ++ (show d) ++ " not delegated." -- Otherwise, subtract our delegates from the list of results and -- report the leftovers. -report delgts (d, Right hosts) = do - let leftovers = hosts \\ delgts +report delgts normalize_function (d, Right raw_hosts) = do + let nrml_hosts = map normalize_function raw_hosts + let leftovers = nrml_hosts \\ delgts unless (null leftovers) $ putStrLn $ "Domain " ++ (show d) ++ @@ -106,7 +113,8 @@ main = do -- Set the timeout from the command line. The resolvTimeout field is -- in microseconds, so we multiply by one million. - let rc = rc' { resolvTimeout = 1000 * 1000 * seconds (timeout cfg) } + let a_million = 1000 * 1000 + let rc = rc' { resolvTimeout = a_million * seconds (timeout cfg) } rs <- makeResolvSeed rc let lookup_function = case cfg of @@ -124,6 +132,6 @@ main = do results <- parallelInterleaved actions -- Output the results. - _ <- mapM (report nrml_delegates) results + _ <- mapM (report nrml_delegates normalize_function) results stopGlobalPool -- 2.43.2