Library
Module
Module type
Parameter
Class
Class type
The type of a domain name, a sequence of labels separated by dots. Each label may contain any bytes. The length of each label may not exceed 63 charactes. The total length of a domain name is limited to 253 (byte representation is 255), but other protocols (such as SMTP) may apply even smaller limits. A domain name label is case preserving, comparison is done in a case insensitive manner.
The invariants on the length of domain names are preserved throughout the module - no t
will exist which violates these.
The specification of domain names originates from RFC 1035.
val root : t
root
is the root domain ("."), the empty label.
of_string ~hostname name
is either t
, the domain name, or an error if the provided name
is not a valid domain name. If hostname
is provided and true
(the default), the contents is additionally checked for being a valid hostname using is_hostname
.
val of_string_exn : ?hostname:bool -> string -> t
of_string_exn ~hostname name
is t
, the domain name. If hostname
is provided and true
(the default), the contents is additionally checked for being a valid hostname using is_hostname
.
val to_string : t -> string
to_string t
is String.concat ~sep:"." (to_strings t)
, a human-readable representation of t
.
canonical t
is t'
, the canonical domain name, as specified in RFC 4034 (and 2535): all characters are lowercase.
val is_hostname : t -> bool
is_hostname t
is true
if t
is a hostname: the contents of the domain name is limited: each label may start with a digit or letter, followed by digits, letters, or hyphens.
val is_service : t -> bool
is_service t
is true
if t
is a service label: the first label is a service name (containing of letters, digits, hyphens) prefixed with "_". The service name may not contain a hyphen following another hyphen, no hypen at the beginning or end, and must contain at least one letter. The total length must be between 1 and at most 15 characters. The second label is the protocol, prefixed by "_" (at the moment, tcp, udp, or sctp), and the remaining must be a host name.
sub ~subdomain ~domain
is true
if subdomain
contains any labels prepended to domain
: foo.bar.com
is a subdomain of bar.com
and of com
, sub ~subdomain:x ~domain:root
is true for all x
.
Label addition and removal
prepend ~hostname name pre
is either t
, the new domain name, or an error. If hostname
is provided and true
(the default), the resulting domain name is checked for being a valid host name using is_hostname
.
prepend_exn ~hostname name pre
is t
, the new domain name.
drop_labels ~back ~amount t
is either t
, a domain name with amount
(defaults to 1) labels dropped from the beginning (unless back
is provided and true
, defaults to false
). drop_labels
applied to foo.com
is com
.
drop_labels_exn ~back ~amount t
is either t
, a domain name with amount
(defaults to 1) labels dropped from the beginning (unless back
is provided and true
, defaults to false
). drop_labels
applied to foo.com
is com
.
equal ~case t t'
is true
if all labels of t
and t'
are equal. If case_sensitive
is provided and true
, the cases of the labels are respected (default: false
).
compare t t'
compares the domain names t
and t'
using a case insensitive string comparison.
compare_sub t t'
compares the labels t
and t'
using a case insensitive string comparison.
module Map : sig ... end
The module of a domain name map
of_strings ~hostname labels
is either t
, a domain name, or an error if the provided labels
violate domain name constraints. If hostname
is provided and true
(the default), the labels are additionally checked for being a valid hostname using is_hostname
.
val of_strings_exn : ?hostname:bool -> string list -> t
of_strings_exn ~hostname labels
is t
, a domain name.
val to_strings : t -> string list
to_strings t
is the list of labels of t
.