xref: /dragonfly/contrib/ldns/ldns/rr.h (revision 36a3d1d6)
1 /*
2  * rr.h -  resource record definitions
3  *
4  * a Net::DNS like library for C
5  *
6  * (c) NLnet Labs, 2005-2006
7  *
8  * See the file LICENSE for the license
9  */
10 
11 /**
12  * \file
13  *
14  * Contains the definition of ldns_rr and functions to manipulate those.
15  */
16 
17 
18 #ifndef LDNS_RR_H
19 #define LDNS_RR_H
20 
21 #include <ldns/common.h>
22 #include <ldns/rdata.h>
23 #include <ldns/buffer.h>
24 #include <ldns/error.h>
25 
26 /** Maximum length of a dname label */
27 #define LDNS_MAX_LABELLEN     63
28 /** Maximum length of a complete dname */
29 #define LDNS_MAX_DOMAINLEN    255
30 /** Maximum number of pointers in 1 dname */
31 #define LDNS_MAX_POINTERS	65535
32 /** The bytes TTL, CLASS and length use up in an rr */
33 #define LDNS_RR_OVERHEAD	10
34 
35 /* The first fields are 'common' and can be referenced instantly */
36 #define LDNS_RDATA_FIELD_DESCRIPTORS_COMMON 51
37 
38 
39 
40 /**
41  *  The different RR classes.
42  */
43 enum ldns_enum_rr_class
44 {
45 	/** the Internet */
46 	LDNS_RR_CLASS_IN 	= 1,
47 	/** Chaos class */
48 	LDNS_RR_CLASS_CH	= 3,
49 	/** Hesiod (Dyer 87) */
50 	LDNS_RR_CLASS_HS	= 4,
51     /** None class, dynamic update */
52     LDNS_RR_CLASS_NONE      = 254,
53 	/** Any class */
54 	LDNS_RR_CLASS_ANY	= 255,
55 
56 	LDNS_RR_CLASS_FIRST     = 0,
57 	LDNS_RR_CLASS_LAST      = 65535,
58 	LDNS_RR_CLASS_COUNT     = LDNS_RR_CLASS_LAST - LDNS_RR_CLASS_FIRST + 1
59 };
60 typedef enum ldns_enum_rr_class ldns_rr_class;
61 
62 /**
63  *  Used to specify whether compression is allowed.
64  */
65 enum ldns_enum_rr_compress
66 {
67 	/** compression is allowed */
68 	LDNS_RR_COMPRESS,
69 	LDNS_RR_NO_COMPRESS
70 };
71 typedef enum ldns_enum_rr_compress ldns_rr_compress;
72 
73 /**
74  * The different RR types.
75  */
76 enum ldns_enum_rr_type
77 {
78 	/**  a host address */
79 	LDNS_RR_TYPE_A = 1,
80 	/**  an authoritative name server */
81 	LDNS_RR_TYPE_NS = 2,
82 	/**  a mail destination (Obsolete - use MX) */
83 	LDNS_RR_TYPE_MD = 3,
84 	/**  a mail forwarder (Obsolete - use MX) */
85 	LDNS_RR_TYPE_MF = 4,
86 	/**  the canonical name for an alias */
87 	LDNS_RR_TYPE_CNAME = 5,
88 	/**  marks the start of a zone of authority */
89 	LDNS_RR_TYPE_SOA = 6,
90 	/**  a mailbox domain name (EXPERIMENTAL) */
91 	LDNS_RR_TYPE_MB = 7,
92 	/**  a mail group member (EXPERIMENTAL) */
93 	LDNS_RR_TYPE_MG = 8,
94 	/**  a mail rename domain name (EXPERIMENTAL) */
95 	LDNS_RR_TYPE_MR = 9,
96 	/**  a null RR (EXPERIMENTAL) */
97 	LDNS_RR_TYPE_NULL = 10,
98 	/**  a well known service description */
99 	LDNS_RR_TYPE_WKS = 11,
100 	/**  a domain name pointer */
101 	LDNS_RR_TYPE_PTR = 12,
102 	/**  host information */
103 	LDNS_RR_TYPE_HINFO = 13,
104 	/**  mailbox or mail list information */
105 	LDNS_RR_TYPE_MINFO = 14,
106 	/**  mail exchange */
107 	LDNS_RR_TYPE_MX = 15,
108 	/**  text strings */
109 	LDNS_RR_TYPE_TXT = 16,
110 	/**  RFC1183 */
111 	LDNS_RR_TYPE_RP = 17,
112 	/**  RFC1183 */
113 	LDNS_RR_TYPE_AFSDB = 18,
114 	/**  RFC1183 */
115 	LDNS_RR_TYPE_X25 = 19,
116 	/**  RFC1183 */
117 	LDNS_RR_TYPE_ISDN = 20,
118 	/**  RFC1183 */
119 	LDNS_RR_TYPE_RT = 21,
120 	/**  RFC1706 */
121 	LDNS_RR_TYPE_NSAP = 22,
122 	/**  RFC1348 */
123 	LDNS_RR_TYPE_NSAP_PTR = 23,
124 	/**  2535typecode */
125 	LDNS_RR_TYPE_SIG = 24,
126 	/**  2535typecode */
127 	LDNS_RR_TYPE_KEY = 25,
128 	/**  RFC2163 */
129 	LDNS_RR_TYPE_PX = 26,
130 	/**  RFC1712 */
131 	LDNS_RR_TYPE_GPOS = 27,
132 	/**  ipv6 address */
133 	LDNS_RR_TYPE_AAAA = 28,
134 	/**  LOC record  RFC1876 */
135 	LDNS_RR_TYPE_LOC = 29,
136 	/**  2535typecode */
137 	LDNS_RR_TYPE_NXT = 30,
138 	/**  draft-ietf-nimrod-dns-01.txt */
139 	LDNS_RR_TYPE_EID = 31,
140 	/**  draft-ietf-nimrod-dns-01.txt */
141 	LDNS_RR_TYPE_NIMLOC = 32,
142 	/**  SRV record RFC2782 */
143 	LDNS_RR_TYPE_SRV = 33,
144 	/**  http://www.jhsoft.com/rfc/af-saa-0069.000.rtf */
145 	LDNS_RR_TYPE_ATMA = 34,
146 	/**  RFC2915 */
147 	LDNS_RR_TYPE_NAPTR = 35,
148 	/**  RFC2230 */
149 	LDNS_RR_TYPE_KX = 36,
150 	/**  RFC2538 */
151 	LDNS_RR_TYPE_CERT = 37,
152 	/**  RFC2874 */
153 	LDNS_RR_TYPE_A6 = 38,
154 	/**  RFC2672 */
155 	LDNS_RR_TYPE_DNAME = 39,
156 	/**  dnsind-kitchen-sink-02.txt */
157 	LDNS_RR_TYPE_SINK = 40,
158 	/**  Pseudo OPT record... */
159 	LDNS_RR_TYPE_OPT = 41,
160 	/**  RFC3123 */
161 	LDNS_RR_TYPE_APL = 42,
162 	/**  draft-ietf-dnsext-delegation */
163 	LDNS_RR_TYPE_DS = 43,
164 	/**  SSH Key Fingerprint */
165 	LDNS_RR_TYPE_SSHFP = 44,
166 	/**  draft-richardson-ipseckey-rr-11.txt */
167 	LDNS_RR_TYPE_IPSECKEY = 45,
168 	/**  draft-ietf-dnsext-dnssec-25 */
169 	LDNS_RR_TYPE_RRSIG = 46,
170 	LDNS_RR_TYPE_NSEC = 47,
171 	LDNS_RR_TYPE_DNSKEY = 48,
172 	LDNS_RR_TYPE_DHCID = 49,
173 
174 	LDNS_RR_TYPE_NSEC3 = 50,
175 	LDNS_RR_TYPE_NSEC3PARAMS = 51,
176 
177 	LDNS_RR_TYPE_SPF = 99,
178 
179 	LDNS_RR_TYPE_UINFO = 100,
180 	LDNS_RR_TYPE_UID = 101,
181 	LDNS_RR_TYPE_GID = 102,
182 	LDNS_RR_TYPE_UNSPEC = 103,
183 
184 	LDNS_RR_TYPE_TSIG = 250,
185 	LDNS_RR_TYPE_IXFR = 251,
186 	LDNS_RR_TYPE_AXFR = 252,
187 	/**  A request for mailbox-related records (MB, MG or MR) */
188 	LDNS_RR_TYPE_MAILB = 253,
189 	/**  A request for mail agent RRs (Obsolete - see MX) */
190 	LDNS_RR_TYPE_MAILA = 254,
191 	/**  any type (wildcard) */
192 	LDNS_RR_TYPE_ANY = 255,
193 
194 	/* RFC 4431, 5074, DNSSEC Lookaside Validation */
195 	LDNS_RR_TYPE_DLV = 32769,
196 
197 	/* type codes from nsec3 experimental phase
198 	LDNS_RR_TYPE_NSEC3 = 65324,
199 	LDNS_RR_TYPE_NSEC3PARAMS = 65325, */
200 	LDNS_RR_TYPE_FIRST = 0,
201 	LDNS_RR_TYPE_LAST  = 65535,
202 	LDNS_RR_TYPE_COUNT = LDNS_RR_TYPE_LAST - LDNS_RR_TYPE_FIRST + 1
203 };
204 typedef enum ldns_enum_rr_type ldns_rr_type;
205 
206 /**
207  * Resource Record
208  *
209  * This is the basic DNS element that contains actual data
210  *
211  * From RFC1035:
212  * <pre>
213 3.2.1. Format
214 
215 All RRs have the same top level format shown below:
216 
217                                     1  1  1  1  1  1
218       0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5
219     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
220     |                                               |
221     /                                               /
222     /                      NAME                     /
223     |                                               |
224     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
225     |                      TYPE                     |
226     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
227     |                     CLASS                     |
228     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
229     |                      TTL                      |
230     |                                               |
231     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
232     |                   RDLENGTH                    |
233     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--|
234     /                     RDATA                     /
235     /                                               /
236     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
237 
238 where:
239 
240 NAME            an owner name, i.e., the name of the node to which this
241                 resource record pertains.
242 
243 TYPE            two octets containing one of the RR TYPE codes.
244 
245 CLASS           two octets containing one of the RR CLASS codes.
246 
247 TTL             a 32 bit signed integer that specifies the time interval
248                 that the resource record may be cached before the source
249                 of the information should again be consulted.  Zero
250                 values are interpreted to mean that the RR can only be
251                 used for the transaction in progress, and should not be
252                 cached.  For example, SOA records are always distributed
253                 with a zero TTL to prohibit caching.  Zero values can
254                 also be used for extremely volatile data.
255 
256 RDLENGTH        an unsigned 16 bit integer that specifies the length in
257                 octets of the RDATA field.
258 
259 RDATA           a variable length string of octets that describes the
260                 resource.  The format of this information varies
261                 according to the TYPE and CLASS of the resource record.
262  * </pre>
263  *
264  * The actual amount and type of rdata fields depend on the RR type of the
265  * RR, and can be found by using \ref ldns_rr_descriptor functions.
266  */
267 struct ldns_struct_rr
268 {
269 	/**  Owner name, uncompressed */
270 	ldns_rdf	*_owner;
271 	/**  Time to live  */
272 	uint32_t	_ttl;
273 	/**  Number of data fields */
274 	size_t	        _rd_count;
275 	/**  the type of the RR. A, MX etc. */
276 	ldns_rr_type	_rr_type;
277 	/**  Class of the resource record.  */
278 	ldns_rr_class	_rr_class;
279 	/* everything in the rdata is in network order */
280 	/**  The array of rdata's */
281 	ldns_rdf	 **_rdata_fields;
282 	/**  question rr [it would be nicer if thous is after _rd_count]
283 		 ABI change: Fix this in next major release
284 	 */
285 	bool		_rr_question;
286 };
287 typedef struct ldns_struct_rr ldns_rr;
288 
289 /**
290  * List or Set of Resource Records
291  *
292  * Contains a list of rr's <br>
293  * No official RFC-like checks are made
294  */
295 struct ldns_struct_rr_list
296 {
297 	size_t _rr_count;
298 	size_t _rr_capacity;
299 	ldns_rr **_rrs;
300 };
301 typedef struct ldns_struct_rr_list ldns_rr_list;
302 
303 /**
304  * Contains all information about resource record types.
305  *
306  * This structure contains, for all rr types, the rdata fields that are defined.
307  */
308 struct ldns_struct_rr_descriptor
309 {
310 	/** Type of the RR that is described here */
311 	ldns_rr_type    _type;
312 	/** Textual name of the RR type.  */
313 	const char *_name;
314 	/** Minimum number of rdata fields in the RRs of this type.  */
315 	uint8_t     _minimum;
316 	/** Maximum number of rdata fields in the RRs of this type.  */
317 	uint8_t     _maximum;
318 	/** Wireformat specification for the rr, i.e. the types of rdata fields in their respective order. */
319 	const ldns_rdf_type *_wireformat;
320 	/** Special rdf types */
321 	ldns_rdf_type _variable;
322 	/** Specifies whether compression can be used for dnames in this RR type. */
323 	ldns_rr_compress _compress;
324 	/** The number of DNAMEs in the _wireformat string, for parsing. */
325 	uint8_t _dname_count;
326 };
327 typedef struct ldns_struct_rr_descriptor ldns_rr_descriptor;
328 
329 /**
330  * creates a new rr structure.
331  * \return ldns_rr *
332  */
333 ldns_rr* ldns_rr_new(void);
334 
335 /**
336  * creates a new rr structure, based on the given type.
337  * alloc enough space to hold all the rdf's
338  */
339 ldns_rr* ldns_rr_new_frm_type(ldns_rr_type t);
340 
341 /**
342  * frees an RR structure
343  * \param[in] *rr the RR to be freed
344  * \return void
345  */
346 void ldns_rr_free(ldns_rr *rr);
347 
348 /**
349  * creates an rr from a string.
350  * The string should be a fully filled-in rr, like
351  * ownername &lt;space&gt; TTL &lt;space&gt; CLASS &lt;space&gt;
352  * TYPE &lt;space&gt; RDATA.
353  * \param[out] n the rr to return
354  * \param[in] str the string to convert
355  * \param[in] default_ttl default ttl value for the rr.
356  *            If 0 DEF_TTL will be used
357  * \param[in] origin when the owner is relative add this.
358  *	The caller must ldns_rdf_deep_free it.
359  * \param[out] prev the previous ownername. if this value is not NULL,
360  * the function overwrites this with the ownername found in this
361  * string. The caller must then ldns_rdf_deep_free it.
362  * \return a status msg describing an error or LDNS_STATUS_OK
363  */
364 ldns_status ldns_rr_new_frm_str(ldns_rr **n, const char *str,
365                                 uint32_t default_ttl, ldns_rdf *origin,
366                                 ldns_rdf **prev);
367 
368 /**
369  * creates an rr for the question section from a string, i.e.
370  * without RDATA fields
371  * Origin and previous RR functionality are the same as in
372  * ldns_rr_new_frm_str()
373  * \param[out] n the rr to return
374  * \param[in] str the string to convert
375  * \param[in] origin when the owner is relative add this.
376  *	The caller must ldns_rdf_deep_free it.
377  * \param prev the previous ownername. the function overwrite this with
378  * the current found ownername. The caller must ldns_rdf_deep_free it.
379  * \return a status msg describing an error or LDNS_STATUS_OK
380  */
381 ldns_status ldns_rr_new_question_frm_str(ldns_rr **n, const char *str,
382                                 ldns_rdf *origin, ldns_rdf **prev);
383 
384 /**
385  * creates a new rr from a file containing a string.
386  * \param[out] rr the new rr
387  * \param[in] fp the file pointer to use
388  * \param[in] default_ttl pointer to a default ttl for the rr. If NULL DEF_TTL will be used
389  *            the pointer will be updated if the file contains a $TTL directive
390  * \param[in] origin when the owner is relative add this
391  * 	      the pointer will be updated if the file contains a $ORIGIN directive
392  *	      The caller must ldns_rdf_deep_free it.
393  * \param[in] prev when the owner is whitespaces use this as the * ownername
394  *            the pointer will be updated after the call
395  *	      The caller must ldns_rdf_deep_free it.
396  * \return a ldns_status with an error or LDNS_STATUS_OK
397  */
398 ldns_status ldns_rr_new_frm_fp(ldns_rr **rr, FILE *fp, uint32_t *default_ttl, ldns_rdf **origin, ldns_rdf **prev);
399 
400 /**
401  * creates a new rr from a file containing a string.
402  * \param[out] rr the new rr
403  * \param[in] fp the file pointer to use
404  * \param[in] default_ttl a default ttl for the rr. If NULL DEF_TTL will be used
405  *            the pointer will be updated if the file contains a $TTL directive
406  * \param[in] origin when the owner is relative add this
407  * 	      the pointer will be updated if the file contains a $ORIGIN directive
408  *	      The caller must ldns_rdf_deep_free it.
409  * \param[in] line_nr pointer to an integer containing the current line number (for debugging purposes)
410  * \param[in] prev when the owner is whitespaces use this as the * ownername
411  *            the pointer will be updated after the call
412  *	      The caller must ldns_rdf_deep_free it.
413  * \return a ldns_status with an error or LDNS_STATUS_OK
414  */
415 ldns_status ldns_rr_new_frm_fp_l(ldns_rr **rr, FILE *fp, uint32_t *default_ttl, ldns_rdf **origin, ldns_rdf **prev, int *line_nr);
416 
417 /**
418  * sets the owner in the rr structure.
419  * \param[in] *rr rr to operate on
420  * \param[in] *owner set to this owner
421  * \return void
422  */
423 void ldns_rr_set_owner(ldns_rr *rr, ldns_rdf *owner);
424 
425 /**
426  * sets the question flag in the rr structure.
427  * \param[in] *rr rr to operate on
428  * \param[in] question question flag
429  * \return void
430  */
431 void ldns_rr_set_question(ldns_rr *rr, bool question);
432 
433 /**
434  * sets the ttl in the rr structure.
435  * \param[in] *rr rr to operate on
436  * \param[in] ttl set to this ttl
437  * \return void
438  */
439 void ldns_rr_set_ttl(ldns_rr *rr, uint32_t ttl);
440 
441 /**
442  * sets the rd_count in the rr.
443  * \param[in] *rr rr to operate on
444  * \param[in] count set to this count
445  * \return void
446  */
447 void ldns_rr_set_rd_count(ldns_rr *rr, size_t count);
448 
449 /**
450  * sets the type in the rr.
451  * \param[in] *rr rr to operate on
452  * \param[in] rr_type set to this type
453  * \return void
454  */
455 void ldns_rr_set_type(ldns_rr *rr, ldns_rr_type rr_type);
456 
457 /**
458  * sets the class in the rr.
459  * \param[in] *rr rr to operate on
460  * \param[in] rr_class set to this class
461  * \return void
462  */
463 void ldns_rr_set_class(ldns_rr *rr, ldns_rr_class rr_class);
464 
465 /**
466  * sets a rdf member, it will be set on the
467  * position given. The old value is returned, like pop.
468  * \param[in] *rr the rr to operate on
469  * \param[in] *f the rdf to set
470  * \param[in] position the position the set the rdf
471  * \return  the old value in the rr, NULL on failyre
472  */
473 ldns_rdf* ldns_rr_set_rdf(ldns_rr *rr, const ldns_rdf *f, size_t position);
474 
475 /**
476  * sets rd_field member, it will be
477  * placed in the next available spot.
478  * \param[in] *rr rr to operate on
479  * \param[in] *f the data field member to set
480  * \return bool
481  */
482 bool ldns_rr_push_rdf(ldns_rr *rr, const ldns_rdf *f);
483 
484 /**
485  * removes a rd_field member, it will be
486  * popped from the last position.
487  * \param[in] *rr rr to operate on
488  * \return rdf which was popped (null if nothing)
489  */
490 ldns_rdf* ldns_rr_pop_rdf(ldns_rr *rr);
491 
492 /**
493  * returns the rdata field member counter.
494  * \param[in] *rr rr to operate on
495  * \param[in] nr the number of the rdf to return
496  * \return ldns_rdf *
497  */
498 ldns_rdf* ldns_rr_rdf(const ldns_rr *rr, size_t nr);
499 
500 /**
501  * returns the owner name of an rr structure.
502  * \param[in] *rr rr to operate on
503  * \return ldns_rdf *
504  */
505 ldns_rdf* ldns_rr_owner(const ldns_rr *rr);
506 
507 /**
508  * returns the question flag of an rr structure.
509  * \param[in] *rr rr to operate on
510  * \return bool true if question
511  */
512 bool ldns_rr_is_question(const ldns_rr *rr);
513 
514 /**
515  * returns the ttl of an rr structure.
516  * \param[in] *rr the rr to read from
517  * \return the ttl of the rr
518  */
519 uint32_t ldns_rr_ttl(const ldns_rr *rr);
520 
521 /**
522  * returns the rd_count of an rr structure.
523  * \param[in] *rr the rr to read from
524  * \return the rd count of the rr
525  */
526 size_t ldns_rr_rd_count(const ldns_rr *rr);
527 
528 /**
529  * returns the type of the rr.
530  * \param[in] *rr the rr to read from
531  * \return the type of the rr
532  */
533 ldns_rr_type ldns_rr_get_type(const ldns_rr *rr);
534 
535 /**
536  * returns the class of the rr.
537  * \param[in] *rr the rr to read from
538  * \return the class of the rr
539  */
540 ldns_rr_class ldns_rr_get_class(const ldns_rr *rr);
541 
542 /* rr_lists */
543 
544 /**
545  * returns the number of rr's in an rr_list.
546  * \param[in] rr_list  the rr_list to read from
547  * \return the number of rr's
548  */
549 size_t ldns_rr_list_rr_count(const ldns_rr_list *rr_list);
550 
551 /**
552  * sets the number of rr's in an rr_list.
553  * \param[in] rr_list the rr_list to set the count on
554  * \param[in] count the number of rr in this list
555  * \return void
556  */
557 void ldns_rr_list_set_rr_count(ldns_rr_list *rr_list, size_t count);
558 
559 /**
560  * set a rr on a specific index in a ldns_rr_list
561  * \param[in] rr_list the rr_list to use
562  * \param[in] r the rr to set
563  * \param[in] count index into the rr_list
564  * \return the old rr which was stored in the rr_list, or
565  * NULL is the index was too large
566  * set a specific rr */
567 ldns_rr * ldns_rr_list_set_rr(ldns_rr_list *rr_list, const ldns_rr *r, size_t count);
568 
569 /**
570  * returns a specific rr of an rrlist.
571  * \param[in] rr_list the rr_list to read from
572  * \param[in] nr return this rr
573  * \return the rr at position nr
574  */
575 ldns_rr* ldns_rr_list_rr(const ldns_rr_list *rr_list, size_t nr);
576 
577 /**
578  * creates a new rr_list structure.
579  * \return a new rr_list structure
580  */
581 ldns_rr_list* ldns_rr_list_new();
582 
583 /**
584  * frees an rr_list structure.
585  * \param[in] rr_list the list to free
586  */
587 void ldns_rr_list_free(ldns_rr_list *rr_list);
588 
589 /**
590  * frees an rr_list structure and all rrs contained therein.
591  * \param[in] rr_list the list to free
592  */
593 void ldns_rr_list_deep_free(ldns_rr_list *rr_list);
594 
595 /**
596  * concatenates two ldns_rr_lists together. This modifies
597  * *left (to extend it and add the pointers from *right).
598  * \param[in] left the leftside
599  * \param[in] right the rightside
600  * \return a left with right concatenated to it
601  */
602 bool ldns_rr_list_cat(ldns_rr_list *left, ldns_rr_list *right);
603 
604 /**
605  * concatenates two ldns_rr_lists together, but makes clones of the rr's
606  * (instead of pointer copying).
607  * \param[in] left the leftside
608  * \param[in] right the rightside
609  * \return a new rr_list with leftside/rightside concatenated
610  */
611 ldns_rr_list* ldns_rr_list_cat_clone(ldns_rr_list *left, ldns_rr_list *right);
612 
613 /**
614  * pushes an rr to an rrlist.
615  * \param[in] rr_list the rr_list to push to
616  * \param[in] rr the rr to push
617  * \return false on error, otherwise true
618  */
619 bool ldns_rr_list_push_rr(ldns_rr_list *rr_list, const ldns_rr *rr);
620 
621 /**
622  * pushes an rr_list to an rrlist.
623  * \param[in] rr_list the rr_list to push to
624  * \param[in] push_list the rr_list to push
625  * \return false on error, otherwise true
626  */
627 bool ldns_rr_list_push_rr_list(ldns_rr_list *rr_list, const ldns_rr_list *push_list);
628 
629 /**
630  * pops the last rr from an rrlist.
631  * \param[in] rr_list the rr_list to pop from
632  * \return NULL if nothing to pop. Otherwise the popped RR
633  */
634 ldns_rr* ldns_rr_list_pop_rr(ldns_rr_list *rr_list);
635 
636 /**
637  * pops an  rr_list of size s from an rrlist.
638  * \param[in] rr_list the rr_list to pop from
639  * \param[in] size the number of rr's to pop
640  * \return NULL if nothing to pop. Otherwise the popped rr_list
641  */
642 ldns_rr_list* ldns_rr_list_pop_rr_list(ldns_rr_list *rr_list, size_t size);
643 
644 /**
645  * returns true if the given rr is one of the rrs in the
646  * list, or if it is equal to one
647  * \param[in] rr_list the rr_list to check
648  * \param[in] rr the rr to check
649  * \return true if rr_list contains rr, false otherwise
650  */
651 bool ldns_rr_list_contains_rr(const ldns_rr_list *rr_list, ldns_rr *rr);
652 
653 /**
654  * checks if an rr_list is a rrset.
655  * \param[in] rr_list the rr_list to check
656  * \return true if it is an rrset otherwise false
657  */
658 bool ldns_is_rrset(ldns_rr_list *rr_list);
659 
660 /**
661  * pushes an rr to an rrset (which really are rr_list's).
662  * \param[in] *rr_list the rrset to push the rr to
663  * \param[in] *rr the rr to push
664  * \return true if the push succeeded otherwise false
665  */
666 bool ldns_rr_set_push_rr(ldns_rr_list *rr_list, ldns_rr *rr);
667 
668 /**
669  * pops the last rr from an rrset. This function is there only
670  * for the symmetry.
671  * \param[in] rr_list the rr_list to pop from
672  * \return NULL if nothing to pop. Otherwise the popped RR
673  *
674  */
675 ldns_rr* ldns_rr_set_pop_rr(ldns_rr_list *rr_list);
676 
677 /**
678  * pops the first rrset from the list,
679  * the list must be sorted, so that all rr's from each rrset
680  * are next to each other
681  */
682 ldns_rr_list *ldns_rr_list_pop_rrset(ldns_rr_list *rr_list);
683 
684 
685 /**
686  * retrieves a rrtype by looking up its name.
687  * \param[in] name a string with the name
688  * \return the type which corresponds with the name
689  */
690 ldns_rr_type ldns_get_rr_type_by_name(const char *name);
691 
692 /**
693  * retrieves a class by looking up its name.
694  * \param[in] name string with the name
695  * \return the cass which corresponds with the name
696  */
697 ldns_rr_class ldns_get_rr_class_by_name(const char *name);
698 
699 /**
700  * clones a rr and all its data
701  * \param[in] rr the rr to clone
702  * \return the new rr or NULL on failure
703  */
704 ldns_rr* ldns_rr_clone(const ldns_rr *rr);
705 
706 /**
707  * clones an rrlist.
708  * \param[in] rrlist the rrlist to clone
709  * \return the cloned rr list
710  */
711 ldns_rr_list* ldns_rr_list_clone(const ldns_rr_list *rrlist);
712 
713 /**
714  * sorts an rr_list (canonical wire format). the sorting is done inband.
715  * \param[in] unsorted the rr_list to be sorted
716  * \return void
717  */
718 void ldns_rr_list_sort(ldns_rr_list *unsorted);
719 
720 /**
721  * compares two rrs. The TTL is not looked at.
722  * \param[in] rr1 the first one
723  * \param[in] rr2 the second one
724  * \return 0 if equal
725  *         -1 if rr1 comes before rr2
726  *         +1 if rr2 comes before rr1
727  */
728 int ldns_rr_compare(const ldns_rr *rr1, const ldns_rr *rr2);
729 
730 /**
731  * compares two rrs, up to the rdata.
732  * \param[in] rr1 the first one
733  * \param[in] rr2 the second one
734  * \return 0 if equal
735  *         -1 if rr1 comes before rr2
736  *         +1 if rr2 comes before rr1
737  */
738 int ldns_rr_compare_no_rdata(const ldns_rr *rr1, const ldns_rr *rr2);
739 
740 /**
741  * compares the wireformat of two rrs, contained in the given buffers.
742  * \param[in] rr1_buf the first one
743  * \param[in] rr2_buf the second one
744  * \return 0 if equal
745  *         -1 if rr1_buf comes before rr2_buf
746  *         +1 if rr2_buf comes before rr1_buf
747  */
748 int ldns_rr_compare_wire(ldns_buffer *rr1_buf, ldns_buffer *rr2_buf);
749 
750 /**
751  * returns true of the given rr's are equal.
752  * Also returns true if one record is a DS that represents the
753  * same DNSKEY record as the other record
754  * \param[in] rr1 the first rr
755  * \param[in] rr2 the second rr
756  * \return true if equal otherwise false
757  */
758 bool ldns_rr_compare_ds(const ldns_rr *rr1, const ldns_rr *rr2);
759 
760 /**
761  * compares two rr listss.
762  * \param[in] rrl1 the first one
763  * \param[in] rrl2 the second one
764  * \return 0 if equal
765  *         -1 if rrl1 comes before rrl2
766  *         +1 if rrl2 comes before rrl1
767  */
768 int ldns_rr_list_compare(const ldns_rr_list *rrl1, const ldns_rr_list *rrl2);
769 
770 /**
771  * calculates the uncompressed size of an RR.
772  * \param[in] r the rr to operate on
773  * \return size of the rr
774  */
775 size_t ldns_rr_uncompressed_size(const ldns_rr *r);
776 
777 /**
778  * converts each dname in a rr to its canonical form.
779  * \param[in] rr the rr to work on
780  * \return void
781  */
782 void ldns_rr2canonical(ldns_rr *rr);
783 
784 /**
785  * converts each dname in each rr in a rr_list to its canonical form.
786  * \param[in] rr_list the rr_list to work on
787  * \return void
788  */
789 void ldns_rr_list2canonical(ldns_rr_list *rr_list);
790 
791 /**
792  * counts the number of labels of the ownername.
793  * \param[in] rr count the labels of this rr
794  * \return the number of labels
795  */
796 uint8_t ldns_rr_label_count(ldns_rr *rr);
797 
798 /**
799  * returns the resource record descriptor for the given rr type.
800  *
801  * \param[in] type the type value of the rr type
802  *\return the ldns_rr_descriptor for this type
803  */
804 const ldns_rr_descriptor *ldns_rr_descript(uint16_t type);
805 
806 /**
807  * returns the minimum number of rdata fields of the rr type this descriptor describes.
808  *
809  * \param[in]  descriptor for an rr type
810  * \return the minimum number of rdata fields
811  */
812 size_t ldns_rr_descriptor_minimum(const ldns_rr_descriptor *descriptor);
813 
814 /**
815  * returns the maximum number of rdata fields of the rr type this descriptor describes.
816  *
817  * \param[in]  descriptor for an rr type
818  * \return the maximum number of rdata fields
819  */
820 size_t ldns_rr_descriptor_maximum(const ldns_rr_descriptor *descriptor);
821 
822 /**
823  * returns the rdf type for the given rdata field number of the rr type for the given descriptor.
824  *
825  * \param[in] descriptor for an rr type
826  * \param[in] field the field number
827  * \return the rdf type for the field
828  */
829 ldns_rdf_type ldns_rr_descriptor_field_type(const ldns_rr_descriptor *descriptor, size_t field);
830 
831 /**
832  * Return the rr_list which matches the rdf at position field. Think
833  * type-covered stuff for RRSIG
834  *
835  * \param[in] l the rr_list to look in
836  * \param[in] r the rdf to use for the comparison
837  * \param[in] pos at which position can we find the rdf
838  *
839  * \return a new rr list with only the RRs that match
840  *
841  */
842 ldns_rr_list *ldns_rr_list_subtype_by_rdf(ldns_rr_list *l, ldns_rdf *r, size_t pos);
843 
844 /**
845  * convert an rdf of type LDNS_RDF_TYPE_TYPE to an actual
846  * LDNS_RR_TYPE. This is usefull in the case when inspecting
847  * the rrtype covered field of an RRSIG.
848  * \param[in] rd the rdf to look at
849  * \return a ldns_rr_type with equivalent LDNS_RR_TYPE
850  *
851  */
852 ldns_rr_type    ldns_rdf2rr_type(const ldns_rdf *rd);
853 
854 /**
855  * Returns the type of the first element of the RR
856  * If there are no elements present, 0 is returned
857  *
858  * \param[in] rr_list The rr list
859  * \return rr_type of the first element, or 0 if the list is empty
860  */
861 ldns_rr_type
862 ldns_rr_list_type(const ldns_rr_list *rr_list);
863 
864 /**
865  * Returns the owner domain name rdf of the first element of the RR
866  * If there are no elements present, NULL is returned
867  *
868  * \param[in] rr_list The rr list
869  * \return dname of the first element, or NULL if the list is empty
870  */
871 ldns_rdf *
872 ldns_rr_list_owner(const ldns_rr_list *rr_list);
873 
874 #endif /* LDNS_RR_H */
875