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

Network.DNS.Pattern

Description

Patterns can be simple absolute domain names, where labels are replaceable with a single glob * or a globstar **. A single glob will match any label in its place, where globstar will greedily match as many labels as possible towards the left.

Admits the escape sequences from domain names. See DNS.

Note: Currently a globstar is only supported on the left-most label.

Examples of valid patterns are:

   *.foo.bar.
   **.foo.bar.
   foo.*.bar.
   foo.bar.*.
Synopsis

Pattern language

data LabelPattern Source #

A pattern for a singular label.

Constructors

DomLiteral DomainLabel

Represents an exact label that must be matched.

DomGlob

Represents a single asterisk glob matching any arbitrary domain at a given level.

DomGlobStar

Represents a double asterisk matching any arbitrary subdomain at a given level.

matchesPattern :: Domain -> DomainPattern -> Bool Source #

Test whether a given domain matches a DomainPattern

patternWorksInside :: DomainPattern -> Domain -> Bool Source #

Given a pattern and a DNS zone specified by a domain name, test whether or not the pattern is applicable beneath that zone.

  foo.*.bar.  applicable inside zone          quux.bar.
  foo.bar.    applicable inside zone          bar.
  bar.        applicable inside zone          bar.
  foo.bar.    not applicable inside zone      quux.

labelMatchesPattern :: DomainLabel -> LabelPattern -> Bool Source #

Test whether a single label matches a label pattern

Parsing

parsePattern :: Text -> Either String DomainPattern Source #

Parse a domain pattern. Convenience wrapper for 'patternP.

patternP :: Parser DomainPattern Source #

Attoparsec Parser for domain patterns. See parsePattern for a convenince wrapper.

Pretty printing

pprPattern :: DomainPattern -> Text Source #

Print domain pattern.

This function nearly roundtrips with parsePattern up to escape sequence equivalence.

parsePattern . pprPattern ~~~ id

pprPatternCF :: DomainPattern -> Text Source #

Print domain pattern after into presentation format after case-folding according to RFC4343.

This function nearly roundtrips with parsePattern up to escape sequence equivalence and case folding.

parsePattern . pprPatternCF ~~~ id

pprLabelPattern :: LabelPattern -> Text Source #

Print a singular domain label pattern into a presentation format.

pprLabelPatternCF :: LabelPattern -> Text Source #

Print a singular domain label pattern into a presentation format after case-folding according to RFC4343.