6 * a Net::DNS like library for C
8 * (c) NLnet Labs, 2004-2006
10 * See the file LICENSE for the license
16 * dname contains function to read and manipulate domain names.
18 * Example domain names are "www.nlnetlabs.nl." and "." (the root)
20 * If a domain name ends with a dot ("."), it is called a Fully Qualified
21 * Domain Name (FQDN). In certain places (for instance when reading a zone
22 * file), an origin (which is just another domain name) non-FQDNs will be
23 * placed after the current. For instance, if i have a zone file where the
24 * origin has been set to "nl.", and my file contains the name
25 * "www.nlnetlabs", it will result in "www.nlnetlabs.nl.". Internally, dnames are
26 * always absolute (the dot is added when it is missing and there is no origin).
29 * known as an absolute domain name, therefore the function to check this is
30 * called \ref ldns_dname_str_absolute
32 * Domain names are stored in \ref ldns_rdf structures, with the type
33 * \ref LDNS_RDF_TYPE_DNAME
35 * This module is *NOT* about the RR type called DNAME.
42 #include <ldns/common.h>
43 #include <ldns/rdata.h>
45 #define LDNS_DNAME_NORMALIZE tolower
48 * concatenates two dnames together
49 * \param[in] rd1 the leftside
50 * \param[in] rd2 the rightside
51 * \return a new rdf with leftside/rightside
53 ldns_rdf *ldns_dname_cat_clone(const ldns_rdf *rd1, const ldns_rdf *rd2);
56 * concatenates rd2 after rd1 (rd2 is copied, rd1 is modified)
57 * \param[in] rd1 the leftside
58 * \param[in] rd2 the rightside
59 * \return LDNS_STATUS_OK on success
61 ldns_status ldns_dname_cat(ldns_rdf *rd1, ldns_rdf *rd2);
64 * Returns a clone of the given dname with the labels
66 * \param[in] d the dname to reverse
67 * \return clone of the dname with the labels reversed.
69 ldns_rdf *ldns_dname_reverse(const ldns_rdf *d);
72 * Clones the given dname from the nth label on
73 * \param[in] d The dname to clone
74 * \param[in] n the label nr to clone from, if this is 0, the complete
76 * \return A newly allocated *rdf structure, containing the cloned dname,
77 * or NULL if either d was NULL, not a dname, or if n >=
81 ldns_dname_clone_from(const ldns_rdf *d, uint16_t n);
84 * chop one label off the left side of a dname. so
85 * wwww.nlnetlabs.nl, becomes nlnetlabs.nl
86 * This new name is a clone and must be freed with ldns_deep_free()
87 * \param[in] d the dname to chop
88 * \return the remaining dname
90 ldns_rdf *ldns_dname_left_chop(const ldns_rdf *d);
93 * count the number of labels inside a LDNS_RDF_DNAME type rdf.
94 * \param[in] *r the rdf
95 * \return the number of labels
97 uint8_t ldns_dname_label_count(const ldns_rdf *r);
100 * creates a new dname rdf from a string.
101 * \param[in] str string to use
102 * \return ldns_rdf* or NULL in case of an error
104 ldns_rdf *ldns_dname_new_frm_str(const char *str);
107 * Create a new dname rdf from a string
108 * \param[in] s the size of the new dname
109 * \param[in] *data pointer to the actual data
112 ldns_rdf *ldns_dname_new(uint16_t s, void *data);
115 * Create a new dname rdf from data (the data is copied)
116 * \param[in] size the size of the data
117 * \param[in] *data pointer to the actual data
120 ldns_rdf *ldns_dname_new_frm_data(uint16_t size, const void *data);
123 * Put a dname into canonical fmt - ie. lowercase it
124 * \param[in] rdf the dname to lowercase
127 void ldns_dname2canonical(const ldns_rdf *rdf);
130 * test wether the name sub falls under parent (i.e. is a subdomain
131 * of parent). This function will return false if the given dnames are
133 * \param[in] sub the name to test
134 * \param[in] parent the parent's name
135 * \return true if sub falls under parent, otherwise false
137 bool ldns_dname_is_subdomain(const ldns_rdf *sub, const ldns_rdf *parent);
140 * Compares the two dname rdf's according to the algorithm for ordering
141 * in RFC4034 Section 6.
142 * \param[in] dname1 First dname rdf to compare
143 * \param[in] dname2 Second dname rdf to compare
144 * \return -1 if dname1 comes before dname2, 1 if dname1 comes after dname2, and 0 if they are equal.
146 int ldns_dname_compare(const ldns_rdf *dname1, const ldns_rdf *dname2);
149 * Checks whether the dname matches the given wildcard
150 * \param[in] dname The dname to check
151 * \param[in] wildcard The wildcard to check with
152 * \return 1 If the wildcard matches, OR if 'wildcard' is not a wildcard and
153 * the names are *exactly* the same
154 * 0 If the wildcard does not match, or if it is not a wildcard and
155 * the names are not the same
157 int ldns_dname_match_wildcard(const ldns_rdf *dname, const ldns_rdf *wildcard);
160 * check if middle lays in the interval defined by prev and next
161 * prev <= middle < next. This is usefull for nsec checking
162 * \param[in] prev the previous dname
163 * \param[in] middle the dname to check
164 * \param[in] next the next dname
165 * return 0 on error or unknown, -1 when middle is in the interval, +1 when not
167 int ldns_dname_interval(const ldns_rdf *prev, const ldns_rdf *middle, const ldns_rdf *next);
170 * Checks whether the given dname string is absolute (i.e. ends with a '.')
171 * \param[in] *dname_str a string representing the dname
172 * \return true or false
174 bool ldns_dname_str_absolute(const char *dname_str);
177 * look inside the rdf and if it is an LDNS_RDF_TYPE_DNAME
178 * try and retrieve a specific label. The labels are numbered
179 * starting from 0 (left most).
180 * \param[in] rdf the rdf to look in
181 * \param[in] labelpos return the label with this number
182 * \return a ldns_rdf* with the label as name or NULL on error
184 ldns_rdf * ldns_dname_label(const ldns_rdf *rdf, uint8_t labelpos);
186 #endif /* LDNS_DNAME_H */