From 2f174a6245027b8d3a4e568a82c240a3595e6bbb Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Thu, 9 Jul 2015 10:18:38 -0400 Subject: [PATCH] Rename DnsblSite to Site. --- harbl.cabal | 2 +- src/Network/DNS/RBL/{DnsblSite.hs => Site.hs} | 60 +++++++++---------- test/TestSuite.hs | 4 +- 3 files changed, 33 insertions(+), 33 deletions(-) rename src/Network/DNS/RBL/{DnsblSite.hs => Site.hs} (82%) diff --git a/harbl.cabal b/harbl.cabal index b86a4be..c0e782e 100644 --- a/harbl.cabal +++ b/harbl.cabal @@ -25,7 +25,7 @@ executable harbl other-modules: Network.DNS.RBL.Domain - Network.DNS.RBL.DnsblSite + Network.DNS.RBL.Site Network.DNS.RBL.IPv4Pattern Network.DNS.RBL.Pretty Network.DNS.RBL diff --git a/src/Network/DNS/RBL/DnsblSite.hs b/src/Network/DNS/RBL/Site.hs similarity index 82% rename from src/Network/DNS/RBL/DnsblSite.hs rename to src/Network/DNS/RBL/Site.hs index d23dfb1..de3cae4 100644 --- a/src/Network/DNS/RBL/DnsblSite.hs +++ b/src/Network/DNS/RBL/Site.hs @@ -1,6 +1,6 @@ --- | This module contains the 'DnsblSite' data type representing one --- blacklist with its associated return codes and weight. For example, --- in Postfix's main.cf you might have, +-- | This module contains the 'Site' data type representing one +-- blacklist with its associated return codes and weight. For +-- example, in Postfix's main.cf you might have, -- -- postscreen_dnsbl_sites = bl.mailspike.net=127.0.0.[2;10;11]*2, ... -- @@ -8,9 +8,9 @@ -- return code pattern is \"127.0.0.[2;10;11]\", and the weight is -- \"2". -- -module Network.DNS.RBL.DnsblSite ( - dnsbl_site_tests, - dnsbl_sites ) +module Network.DNS.RBL.Site ( + site_tests, + sites ) where import Data.List ( intercalate ) @@ -43,7 +43,7 @@ instance Pretty Weight where pretty_show (Weight w) = show w --- | Parse the weight multiplier at the end of a dnsbl_site. +-- | Parse the weight multiplier at the end of a site. -- -- ==== _Examples_ -- @@ -97,7 +97,7 @@ weight = try parse_weight <|> return (Weight 1) -- (DNS) name, a pattern of addresses to use for a \"hit\", and a -- weight multiplier. -- -data DnsblSite = DnsblSite UserDomain (Maybe IPv4Pattern) Weight +data Site = Site UserDomain (Maybe IPv4Pattern) Weight -- | Pretty print DNSBL sites. This is straightforward except for the @@ -110,8 +110,8 @@ data DnsblSite = DnsblSite UserDomain (Maybe IPv4Pattern) Weight -- to just choose one of these behaviors rather than pass around a -- @Maybe Weight@. We always print the multiplier, even when it's @1@. -- -instance Pretty DnsblSite where - pretty_show (DnsblSite d p w) = +instance Pretty Site where + pretty_show (Site d p w) = (pretty_show d) ++ pattern_string ++ "*" ++ (pretty_show w) where pattern_string = case p of @@ -119,40 +119,40 @@ instance Pretty DnsblSite where Just pat -> "=" ++ pretty_show pat --- | Parse a single 'DnsblSite'. +-- | Parse a single 'Site'. -- -- ==== _Examples_ -- -- >>> import Text.Parsec ( parse ) -- -- >>> let spamhaus = "zen.spamhaus.org*3" --- >>> pretty_print $ parse dnsbl_site "" spamhaus +-- >>> pretty_print $ parse site "" spamhaus -- zen.spamhaus.org*3 -- -- >>> let mailspike = "bl.mailspike.net=127.0.0.[2;10;11]*2" --- >>> pretty_print $ parse dnsbl_site "" mailspike +-- >>> pretty_print $ parse site "" mailspike -- bl.mailspike.net=127.0.0.[2;10;11]*2 -- -- If the weight is left unspecified, it defaults to \"1\" which is -- then printed: -- -- >>> let hostkarma = "hostkarma.junkemailfilter.com=127.0.0.2" --- >>> pretty_print $ parse dnsbl_site "" hostkarma +-- >>> pretty_print $ parse site "" hostkarma -- hostkarma.junkemailfilter.com=127.0.0.2*1 -- -- >>> let ubl = "ubl.unsubscore.com" --- >>> pretty_print $ parse dnsbl_site "" ubl +-- >>> pretty_print $ parse site "" ubl -- ubl.unsubscore.com*1 -- -dnsbl_site :: Parser DnsblSite -dnsbl_site = do +site :: Parser Site +site = do d <- user_domain return_codes <- optionMaybe $ char '=' >> v4pattern w <- weight - return $ DnsblSite d return_codes w + return $ Site d return_codes w --- | Parse more than one 'DnsblSite', separated by commas and/or +-- | Parse more than one 'Site', separated by commas and/or -- whitespace. -- -- ==== _Examples_ @@ -164,13 +164,13 @@ dnsbl_site = do -- >>> let spamhaus = "zen.spamhaus.org*3" -- >>> let mailspike = "bl.mailspike.net=127.0.0.[2;10;11]*2" -- >>> let bl_list = spamhaus ++ "," ++ mailspike --- >>> pretty_print $ parse dnsbl_sites "" bl_list +-- >>> pretty_print $ parse sites "" bl_list -- ["zen.spamhaus.org*3","bl.mailspike.net=127.0.0.[2;10;11]*2"] -- >>> let bl_list = spamhaus ++ " , " ++ mailspike --- >>> pretty_print $ parse dnsbl_sites "" bl_list +-- >>> pretty_print $ parse sites "" bl_list -- ["zen.spamhaus.org*3","bl.mailspike.net=127.0.0.[2;10;11]*2"] -- >>> let bl_list = spamhaus ++ " " ++ mailspike --- >>> pretty_print $ parse dnsbl_sites "" bl_list +-- >>> pretty_print $ parse sites "" bl_list -- ["zen.spamhaus.org*3","bl.mailspike.net=127.0.0.[2;10;11]*2"] -- -- Any whitespace, in fact, should work: @@ -178,31 +178,31 @@ dnsbl_site = do -- >>> let spamhaus = "zen.spamhaus.org*3" -- >>> let mailspike = "bl.mailspike.net=127.0.0.[2;10;11]*2" -- >>> let bl_list = spamhaus ++ "\n,\t \t\r" ++ mailspike --- >>> pretty_print $ parse dnsbl_sites "" bl_list +-- >>> pretty_print $ parse sites "" bl_list -- ["zen.spamhaus.org*3","bl.mailspike.net=127.0.0.[2;10;11]*2"] -- -dnsbl_sites :: Parser [DnsblSite] -dnsbl_sites = dnsbl_site `sepBy1` many1 (choice [char ',', space]) +sites :: Parser [Site] +sites = site `sepBy1` many1 (choice [char ',', space]) -- * Tests -dnsbl_site_tests :: TestTree -dnsbl_site_tests = +site_tests :: TestTree +site_tests = testGroup - "DnsblSite tests" + "Site tests" [ test_full_maincf_sites_parsed ] -- | This is a sample \"postscreen_dnsbl_sites\" from a real main.cf. --- We should be able to parse it as a list of 'DnsblSite's. +-- We should be able to parse it as a list of 'Site's. -- test_full_maincf_sites_parsed :: TestTree test_full_maincf_sites_parsed = testCase "a full main.cf list of postscreen_dnsbl_sites is parsed" $ do -- Whatever, it's a test. - let actual = pretty_show $ parse dnsbl_sites "" input + let actual = pretty_show $ parse sites "" input actual @?= expected where input = intercalate ",\n\t" [ diff --git a/test/TestSuite.hs b/test/TestSuite.hs index c6298e4..67fc01a 100644 --- a/test/TestSuite.hs +++ b/test/TestSuite.hs @@ -1,9 +1,9 @@ import Test.Tasty ( TestTree, defaultMain, testGroup ) -import Network.DNS.RBL.DnsblSite ( dnsbl_site_tests ) +import Network.DNS.RBL.Site ( site_tests ) import Network.DNS.RBL.IPv4Pattern ( ipv4pattern_tests ) tests :: TestTree -tests = testGroup "All Tests" [ dnsbl_site_tests, ipv4pattern_tests ] +tests = testGroup "All Tests" [ site_tests, ipv4pattern_tests ] main :: IO () main = defaultMain tests -- 2.44.2