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