package domain-name
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=9ec7ae2c22772c150b84cfa3f21d9bf25fae14a796f31e20df52d86f46499d89
sha512=923acab434ebb197f44075711030fd1b7f61783e20cc6f74387ce0acf1bc5f48eb8a8a5e29d3440e7c249ab00673e250ddfdc7e53d71c5a1613f1dbb557c0ae1
doc/domain-name/Domain_name/index.html
Module Domain_nameSource
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 characters. The total length of a domain name is limited to 253 (its 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. Every t is a fully qualified domain name, its last label is the root label. The specification of domain names originates from RFC 1035.
The invariants on the length of domain names are preserved throughout the module - no t will exist which violates these.
Phantom types are used for further name restrictions, host checks for host names (`host t): only letters, digits, and hyphen allowed, hyphen not first or last character of a label, the last label must contain at least one letter. service checks for a service name (`service t): its first label is a service name: 1-15 characters, no double-hyphen, hyphen not first or last charactes, only letters, digits and hyphen allowed, and the second label is a protocol (_tcp or _udp or _sctp).
When a t is constructed (either from a string, etc.), it is a `raw t. Subsequent modifications, such as adding or removing labels, appending, of any kind of name also result in a `raw t, which needs to be checked for `host t (using host) or `service t (using service) if desired.
Constructing a t (via of_string, of_string_exn, of_strings etc.) does not require a trailing dot.
v0.5.0 - homepage
Constructor
String representation
of_string name is either t, the domain name, or an error if the provided name is not a valid domain name. A trailing dot is not requred.
of_string_exn name is t, the domain name. A trailing dot is not required.
to_string ~trailing t is String.concat ~sep:"." (to_strings t), a human-readable representation of t. If trailing is provided and true (defaults to false), the resulting string will contain a trailing dot.
Predicates and basic operations
canonical t is t', the canonical domain name, as specified in RFC 4034 (and 2535): all characters are lowercase.
host t is a `host t 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.
host_exn t is a `host t 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.
service t is `service t if t contains a service name, the following conditions have to be met: The first label is a service name (or port number); an underscore preceding 1-15 characters from the set - a-z A-Z 0-9. The service name may not contain a hyphen (-) following another hyphen; no hyphen at the beginning or end.
The second label is the protocol, one of _tcp, _udp, or _sctp. The remaining labels must form a valid hostname.
This function can be used to validate RR's of the types SRV (RFC 2782) and TLSA (RFC 7671).
service_exn t is `service t if t is a service name (see service).
is_subdomain ~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.
get_label ~rev name idx retrieves the label at index idx from name. If idx is out of bounds, an Error is returned. If rev is provided and true (defaults to false), idx is from the end instead of the beginning.
get_label_exn ~rev name idx is the label at index idx in name.
find_label ~rev name p returns the first position where p lbl is true in name, if it exists, otherwise None. If rev is provided and true (defaults to false), the name is traversed from the end instead of the beginning.
find_label_exn ~rev name p, see find_label.
Label addition and removal
prepend_label name pre is either t, the new domain name, or an error.
prepend_label_exn name pre is t, the new domain name.
drop_label ~rev ~amount t is either t, a domain name with amount (defaults to 1) labels dropped from the beginning - if rev is provided and true (defaults to false) labels are dropped from the end. drop_label (of_string_exn "foo.com") = Ok (of_string_exn "com"), drop_label ~rev:true (of_string_exn "foo.com") = Ok (of_string_exn "foo").
drop_label_exn ~rev ~amount t, see drop_label. Instead of a result, the value is returned directly.
append pre post is pre ^ "." ^ post.
Comparison
equal ~case_sensitive 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 (defaults to false).
compare t t' compares the domain names t and t' using a case insensitive string comparison. This conforms to the canonical DNS name order, as described in RFC 4034, Section 6.1.
equal_label ~case_sensitive a b is true if a and b are equal ignoring casing. If case_sensitive is provided and true (defaults to false), the casing is respected.
compare_label t t' compares the labels t and t' using a case insensitive string comparison.
Collections
The module of a service name map
The module of a service name set
String list representation
of_strings labels is either t, a domain name, or an error if the provided labels violate domain name constraints. A trailing empty label is not required.
of_strings_exn labels is t, a domain name. A trailing empty label is not required.
to_strings ~trailing t is the list of labels of t. If trailing is provided and true (defaults to false), the resulting list will contain a trailing empty label.
Pretty printer
pp ppf t pretty prints the domain name t on ppf.