Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
There is no standardized presentation and parsing format for domain names.
In this library we assume a domain name and pattern to be specified as a text with an ASCII dot .
acting as a separator and terminator.
We do not admit arbitrary unicode codepoints, only the following subset of ASCII is acceptable per label:
[a-z], [A-Z], [0-9], '_', -
, *
Punycoding, if desired, must be taken care of the user.
In addition, we allow a backslash to be used as an escaping character for the following possible sequences:
Escape sequences The domain name and pattern language here allows for the following escape sequences
\. gives a dot inside a label, rather than a label separator \\ gives a backslash inside a label \012 gives an arbitrary octet inside a label as specified by the three octets
For example: foo\.bar.quux.
is a domain name comprised of two labels foo.bar
and quux
Synopsis
- data Domain
- getDomain :: Domain -> [DomainLabel]
- mkDomain :: [DomainLabel] -> Domain
- mkDomain' :: [Text] -> Domain
- data DomainLabel
- getDomainLabel :: DomainLabel -> ShortByteString
- getDomainLabelCF :: DomainLabel -> ShortByteString
- mkDomainLabel :: ShortByteString -> DomainLabel
- unsafeMkDomainLabel :: ShortByteString -> DomainLabel
- unsafeSingletonDomainLabel :: Word8 -> DomainLabel
- foldCase :: Domain -> Domain
- foldCase_ :: Word8 -> Word8
- foldCaseLabel :: DomainLabel -> DomainLabel
- parseAbsDomain :: Text -> Either String Domain
- parseAbsDomainRelax :: Text -> Either String Domain
- parseDomainLabel :: Text -> Either String DomainLabel
- absDomainP :: Parser Domain
- absDomainRelaxP :: Parser Domain
- domainLabelP :: Parser DomainLabel
- pprDomain_ :: Domain -> Text
- pprDomain :: Domain -> Text
- pprDomainCF :: Domain -> Text
- pprDomainLabel :: DomainLabel -> Text
- pprDomainLabelCF :: DomainLabel -> Text
Documentation
A domain parsed into labels. Each label is a ShortByteString
rather than Text
or String
because a label can contain arbitrary bytes.
However, the Ord
and Eq
instances do limited case-folding according to RFC4343.
getDomain :: Domain -> [DomainLabel] Source #
mkDomain :: [DomainLabel] -> Domain Source #
mkDomain' :: [Text] -> Domain Source #
Turn a list of text labels into a Domain
Codepoints outside ASCII are officially not supported.
data DomainLabel Source #
Instances
Eq DomainLabel Source # | |
Defined in Network.DNS.Internal (==) :: DomainLabel -> DomainLabel -> Bool # (/=) :: DomainLabel -> DomainLabel -> Bool # | |
Ord DomainLabel Source # | |
Defined in Network.DNS.Internal compare :: DomainLabel -> DomainLabel -> Ordering # (<) :: DomainLabel -> DomainLabel -> Bool # (<=) :: DomainLabel -> DomainLabel -> Bool # (>) :: DomainLabel -> DomainLabel -> Bool # (>=) :: DomainLabel -> DomainLabel -> Bool # max :: DomainLabel -> DomainLabel -> DomainLabel # min :: DomainLabel -> DomainLabel -> DomainLabel # |
getDomainLabel :: DomainLabel -> ShortByteString Source #
Get the wire-representation of a domain label.
getDomainLabelCF :: DomainLabel -> ShortByteString Source #
Get the RFC4343 case-folded wire-representation of a domain label.
mkDomainLabel :: ShortByteString -> DomainLabel Source #
Smart constructor for DomainLabel
unsafeMkDomainLabel :: ShortByteString -> DomainLabel Source #
Unsafely construct a DomainLabel
. The argument must already be case-folded according to RFC4343.
unsafeSingletonDomainLabel :: Word8 -> DomainLabel Source #
Unsafely construct a DomainLabel
from a single Word8. The argument must already be case-folded according to RFC4343.
foldCaseLabel :: DomainLabel -> DomainLabel Source #
Case-folding of a domain label according to RFC4343.
Note DomainLabel
will memoize a case-folded variant for Eq
, Ord
and pretty printing already. This function is not useful to most.
Parsing
parseAbsDomain :: Text -> Either String Domain Source #
Parse an absolute domain. Convenience wrapper for absDomainP
.
parseAbsDomainRelax :: Text -> Either String Domain Source #
Version of parseAbsDomain that also considers a domain name without a trailing dot to be absolute.
parseDomainLabel :: Text -> Either String DomainLabel Source #
Parse a singular domain label. Convenience wrapper for domainLabelP
.
absDomainP :: Parser Domain Source #
Attoparsec Parser
for absolute domains. See parseAbsDomain
for a convenience wrapper.
For a parser that also admits domain forms without a leading dot, see absDomainRelaxP
.
absDomainRelaxP :: Parser Domain Source #
Attoparsec Parser
for absolute domains. See parseAbsDomainRelax
for a convenience warpper.
This variant differs from absDomainP
in that it does not care whether the domain
name ends in a dot.
domainLabelP :: Parser DomainLabel Source #
Attoparsec Parser
for a singular domain label. See parseDomainLabel
for a convenince wrapper. Also see absDomainP
.
Pretty printing
pprDomain_ :: Domain -> Text Source #
pprDomain :: Domain -> Text Source #
Print an arbitrary domain into a presentation format.
This function nearly roundtrips with parseAbsDomain
up to escape sequence equivalence
parseAbsDomain . pprDomain ~~~ id
pprDomainCF :: Domain -> Text Source #
Print an arbitrary domain into a presentation format after case-folding according to RFC4343.
This function nearly roundtrips with parseAbsDomain
up to escape sequence equivalence and case folding.
parseAbsDomain . pprDomainCF ~~~ id
pprDomainLabel :: DomainLabel -> Text Source #
Print a singular domain label into a presentation format.
pprDomainLabelCF :: DomainLabel -> Text Source #
Print a singular domain label into a presentation format after case-folding according to RFC4343.