-- (octets).
--
module Network.DNS.RBL.Domain (
- UserDomain(..),
- user_domain )
+ Domain,
+ domain )
where
import Data.Char ( toLower )
--
-- We let the 'Domain' type remain true to those RFCs, even though
-- they don't support an absolute domain name of e.g. a single dot.
--- We have one more data type 'UserDomain' which handles the possibility
--- of an absolute path.
--
data Domain =
DomainName Subdomain |
parse_empty :: Parser Domain
parse_empty = string "" >> return DomainRoot
-
-
-
--- * User domains
-
--- | This type helps clarify some murkiness in the DNS \"domain\" name
--- specification. In RFC1034, it is acknowledged that a domain name
--- input with a trailing \".\" will represent an absolute domain
--- name (i.e. with respect to the DNS root). However, the grammar in
--- RFC1035 disallows a trailing dot.
---
--- This makes some sense: within the DNS, everything knows its
--- position in the tree. The relative/absolute distinction only
--- makes sense on the client side, where a user's resolver might
--- decide to append some suffix to a relative
--- request. Unfortunately, that's where we live. So we have to deal
--- with the possibility of having a trailing dot at the end of any
--- domain name.
---
-data UserDomain =
- UserDomainRelative Domain |
- UserDomainAbsolute Domain
- deriving (Eq, Show)
-
-instance Pretty UserDomain where
- pretty_show (UserDomainRelative d) = pretty_show d
- pretty_show (UserDomainAbsolute d) = (pretty_show d) ++ "."
-
-
--- | Parse a 'UserDomain'. This is what we'll be using to read user
--- input, since it supports both relative and absolute domain names
--- (unlike the implicitly-absolute 'Domain').
---
--- ==== _Examples_
---
--- >>> import Text.Parsec ( parse, parseTest )
---
--- We can really parse the root now!
---
--- >>> parseTest user_domain "."
--- UserDomainAbsolute DomainRoot
---
--- But multiple dots aren't (only the first):
---
--- >>> pretty_print $ parse user_domain "" ".."
--- .
---
--- We can also optionally have a trailing dot at the end of a
--- non-empty name:
---
--- >>> pretty_print $ parse user_domain "" "www.example.com"
--- www.example.com
---
--- >>> pretty_print $ parse user_domain "" "www.example.com."
--- www.example.com.
---
--- A \"relative root\" can also be parsed, letting the user's
--- resolver deal with it:
---
--- >>> parseTest user_domain ""
--- UserDomainRelative DomainRoot
---
-user_domain :: Parser UserDomain
-user_domain = try absolute <|> relative
- where
- absolute :: Parser UserDomain
- absolute = do
- d <- domain
- _ <- char '.'
- return $ UserDomainAbsolute d
-
- relative :: Parser UserDomain
- relative = fmap UserDomainRelative domain