- -- ByteString constants.
- dot = BS.pack "."
- suffix = BS.pack $ "." ++ (pretty_show rbl)
-
- octets = BS.split '.' (BS.pack ip)
- reverse_ip = BS.intercalate dot (reverse octets)
- dom = reverse_ip `BS.append` suffix
-
-
-
--- | Look up the given @host@ on a single RBL, and return the number
--- of \"points\" it scores. If the host is listed, it should score the
--- weight of the given blacklist. Otherwise, it scores zero.
---
-lookup_single :: Host -> Site -> IO Int
-lookup_single host site = do
- rs <- makeResolvSeed defaultResolvConf
- withResolver rs $ \resolver -> lookup_single' resolver host site
-
-
--- | See 'lookup_single'.
---
--- The \"prime\" version of this function takes a pre-existing
--- resolver as an argument for performance reasons.
---
-lookup_single' :: Resolver -> Host -> Site -> IO Int
-lookup_single' resolver host (Site d p (Weight w)) = do
- response <- dnslookup resolver d host
- case response of
- Left _ -> return 0 -- Not listed
- Right ipv4s ->
- case p of
- -- No pattern given, but we got a hit.
- Nothing -> return w
- Just pat -> do
- let ipv4_strings = map show ipv4s
- let codes = addresses pat
- let hits = map (`elem` codes) ipv4_strings
- if or hits -- if any of the returned addresses match the pattern
- then return w
- else return 0
-
-
--- | Look up the given @host@ on all of the white/blacklists contained
--- in @sites@. Return the total \"score\" for the @host@; that is,
--- the sum of the weights for each site whose pattern the host
--- matches.
---
-lookup_simple :: Host -> [Site] -> IO Int
-lookup_simple host sites = do
- rs <- makeResolvSeed defaultResolvConf
- withResolver rs $ \resolver -> do
- results <- mapM (lookup_single' resolver host) sites
- return $ sum results