dns-patterns-0.2.1: DNS name parsing and pattern matching utilities
Safe HaskellSafe-Inferred
LanguageHaskell2010

Network.DNS

Description

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

Documentation

data Domain Source #

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.

Instances

Instances details
Eq Domain Source # 
Instance details

Defined in Network.DNS.Internal

Methods

(==) :: Domain -> Domain -> Bool #

(/=) :: Domain -> Domain -> Bool #

Ord Domain Source # 
Instance details

Defined in Network.DNS.Internal

getDomain :: Domain -> [DomainLabel] Source #

Turn a Domain into a list of its labels.

getDomain . mkDomain ~~~ id
mkDomain . getDomain ~~~ id

mkDomain :: [DomainLabel] -> Domain Source #

Turn a list of labels into a Domain.

getDomain . mkDomain ~~~ id
mkDomain . getDomain ~~~ id

data DomainLabel Source #

Domain label with case-insensitive Eq and Ord as per RFC4343.

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.

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.

foldCase :: Domain -> Domain Source #

Case-folding of a domain according to RFC4343. Note Domain will memoize a case-folded variant for Eq, Ord and pretty printing already. This function is not useful to most.

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 #

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.