X-Git-Url: http://gitweb.michael.orlitzky.com/?p=haeredes.git;a=blobdiff_plain;f=src%2FMain.hs;h=c9356bfd9318de6d96c279d0bd9dd0608fe9b332;hp=89d2cd56d1a2aeaca07420d403e2e29da1e7abfe;hb=fdf3555b3e8a1f937172baa691ca219b0e54a35f;hpb=8107db78784648b609c70f1d448764fc6c22f0ef diff --git a/src/Main.hs b/src/Main.hs index 89d2cd5..c9356bf 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -9,8 +9,9 @@ import qualified Data.ByteString.Char8 as BS ( getContents, pack, words ) -import Data.List ( (\\), intersperse ) +import Data.List ( (\\), intersperse, sort ) import Network.DNS ( + DNSError(NameError), Domain, FileOrNumericHost(RCHostName), ResolvConf(resolvInfo, resolvTimeout), @@ -52,20 +53,24 @@ report :: [Domain] -- ^ The list of @delgts@ -> LookupResult -> IO () --- If the lookup resulted in a DNS error, we just ignore the whole --- thing. -report _ _ (_, Left _) = return () - -- If the lookup succeeded but there were no results, report that the --- domain is not delegated. -report _ _ (d, Right []) = +-- domain is not delegated. Note that the behavior of the DNS library +-- changed with regard to this at some point: we used to get back +-- a "success," but with an empty list of results. Now a NameError +-- (which is not actually an error!) is returned. +report _ _ (d, Left NameError) = putStrLn $ "Domain " ++ (show d) ++ " not delegated." +-- If the lookup resulted in some other DNS error, we just ignore the +-- whole thing. +report _ _ (_, Left _) = return () + -- Otherwise, subtract our delegates from the list of results and -- report the leftovers. report delgts normalize_function (d, Right raw_hosts) = do let nrml_hosts = map normalize_function raw_hosts - let leftovers = nrml_hosts \\ delgts + -- Sort the leftovers so that we can test the expected output. + let leftovers = sort (nrml_hosts \\ delgts) unless (null leftovers) $ putStrLn $ "Domain " ++ (show d) ++