]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/ldns/ldns/rr.h
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / ldns / ldns / rr.h
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
27 extern "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 contiguous and can be referenced instantly */
40 #define LDNS_RDATA_FIELD_DESCRIPTORS_COMMON 258
41
42
43
44 /**
45  *  The different RR classes.
46  */
47 enum 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 };
64 typedef enum ldns_enum_rr_class ldns_rr_class;
65
66 /**
67  *  Used to specify whether compression is allowed.
68  */
69 enum ldns_enum_rr_compress
70 {
71         /** compression is allowed */
72         LDNS_RR_COMPRESS,
73         LDNS_RR_NO_COMPRESS
74 };
75 typedef enum ldns_enum_rr_compress ldns_rr_compress;
76
77 /**
78  * The different RR types.
79  */
80 enum 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         /**  RFC4034, RFC3658 */
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         LDNS_RR_TYPE_TLSA = 52, /* RFC 6698 */
183
184         LDNS_RR_TYPE_HIP = 55, /* RFC 5205 */
185
186         /** draft-reid-dnsext-zs */
187         LDNS_RR_TYPE_NINFO = 56,
188         /** draft-reid-dnsext-rkey */
189         LDNS_RR_TYPE_RKEY = 57,
190         /** draft-ietf-dnsop-trust-history */
191         LDNS_RR_TYPE_TALINK = 58,
192         /** draft-barwood-dnsop-ds-publis */
193         LDNS_RR_TYPE_CDS = 59,
194
195         LDNS_RR_TYPE_SPF = 99, /* RFC 4408 */
196
197         LDNS_RR_TYPE_UINFO = 100,
198         LDNS_RR_TYPE_UID = 101,
199         LDNS_RR_TYPE_GID = 102,
200         LDNS_RR_TYPE_UNSPEC = 103,
201
202         LDNS_RR_TYPE_NID = 104, /* RFC 6742 */
203         LDNS_RR_TYPE_L32 = 105, /* RFC 6742 */
204         LDNS_RR_TYPE_L64 = 106, /* RFC 6742 */
205         LDNS_RR_TYPE_LP = 107, /* RFC 6742 */
206
207         LDNS_RR_TYPE_EUI48 = 108, /* RFC 7043 */
208         LDNS_RR_TYPE_EUI64 = 109, /* RFC 7043 */
209
210         LDNS_RR_TYPE_TKEY = 249, /* RFC 2930 */
211         LDNS_RR_TYPE_TSIG = 250,
212         LDNS_RR_TYPE_IXFR = 251,
213         LDNS_RR_TYPE_AXFR = 252,
214         /**  A request for mailbox-related records (MB, MG or MR) */
215         LDNS_RR_TYPE_MAILB = 253,
216         /**  A request for mail agent RRs (Obsolete - see MX) */
217         LDNS_RR_TYPE_MAILA = 254,
218         /**  any type (wildcard) */
219         LDNS_RR_TYPE_ANY = 255,
220         /** draft-faltstrom-uri-06 */
221         LDNS_RR_TYPE_URI = 256,
222         LDNS_RR_TYPE_CAA = 257, /* RFC 6844 */
223
224         /** DNSSEC Trust Authorities */
225         LDNS_RR_TYPE_TA = 32768,
226         /* RFC 4431, 5074, DNSSEC Lookaside Validation */
227         LDNS_RR_TYPE_DLV = 32769,
228
229         /* type codes from nsec3 experimental phase
230         LDNS_RR_TYPE_NSEC3 = 65324,
231         LDNS_RR_TYPE_NSEC3PARAMS = 65325, */
232         LDNS_RR_TYPE_FIRST = 0,
233         LDNS_RR_TYPE_LAST  = 65535,
234         LDNS_RR_TYPE_COUNT = LDNS_RR_TYPE_LAST - LDNS_RR_TYPE_FIRST + 1
235 };
236 typedef enum ldns_enum_rr_type ldns_rr_type;
237
238 /**
239  * Resource Record
240  *
241  * This is the basic DNS element that contains actual data
242  *
243  * From RFC1035:
244  * <pre>
245 3.2.1. Format
246
247 All RRs have the same top level format shown below:
248
249                                     1  1  1  1  1  1
250       0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5
251     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
252     |                                               |
253     /                                               /
254     /                      NAME                     /
255     |                                               |
256     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
257     |                      TYPE                     |
258     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
259     |                     CLASS                     |
260     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
261     |                      TTL                      |
262     |                                               |
263     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
264     |                   RDLENGTH                    |
265     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--|
266     /                     RDATA                     /
267     /                                               /
268     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
269
270 where:
271
272 NAME            an owner name, i.e., the name of the node to which this
273                 resource record pertains.
274
275 TYPE            two octets containing one of the RR TYPE codes.
276
277 CLASS           two octets containing one of the RR CLASS codes.
278
279 TTL             a 32 bit signed integer that specifies the time interval
280                 that the resource record may be cached before the source
281                 of the information should again be consulted.  Zero
282                 values are interpreted to mean that the RR can only be
283                 used for the transaction in progress, and should not be
284                 cached.  For example, SOA records are always distributed
285                 with a zero TTL to prohibit caching.  Zero values can
286                 also be used for extremely volatile data.
287
288 RDLENGTH        an unsigned 16 bit integer that specifies the length in
289                 octets of the RDATA field.
290
291 RDATA           a variable length string of octets that describes the
292                 resource.  The format of this information varies
293                 according to the TYPE and CLASS of the resource record.
294  * </pre>
295  *
296  * The actual amount and type of rdata fields depend on the RR type of the
297  * RR, and can be found by using \ref ldns_rr_descriptor functions.
298  */
299 struct ldns_struct_rr
300 {
301         /**  Owner name, uncompressed */
302         ldns_rdf        *_owner;
303         /**  Time to live  */
304         uint32_t        _ttl;
305         /**  Number of data fields */
306         size_t          _rd_count;
307         /**  the type of the RR. A, MX etc. */
308         ldns_rr_type    _rr_type;
309         /**  Class of the resource record.  */
310         ldns_rr_class   _rr_class;
311         /* everything in the rdata is in network order */
312         /**  The array of rdata's */
313         ldns_rdf         **_rdata_fields;
314         /**  question rr [it would be nicer if thous is after _rd_count]
315                  ABI change: Fix this in next major release
316          */
317         bool            _rr_question;
318 };
319 typedef struct ldns_struct_rr ldns_rr;
320
321 /**
322  * List or Set of Resource Records
323  *
324  * Contains a list of rr's <br>
325  * No official RFC-like checks are made
326  */
327 struct ldns_struct_rr_list
328 {
329         size_t _rr_count;
330         size_t _rr_capacity;
331         ldns_rr **_rrs;
332 };
333 typedef struct ldns_struct_rr_list ldns_rr_list;
334
335 /**
336  * Contains all information about resource record types.
337  *
338  * This structure contains, for all rr types, the rdata fields that are defined.
339  */
340 struct ldns_struct_rr_descriptor
341 {
342         /** Type of the RR that is described here */
343         ldns_rr_type    _type;
344         /** Textual name of the RR type.  */
345         const char *_name;
346         /** Minimum number of rdata fields in the RRs of this type.  */
347         uint8_t     _minimum;
348         /** Maximum number of rdata fields in the RRs of this type.  */
349         uint8_t     _maximum;
350         /** Wireformat specification for the rr, i.e. the types of rdata fields in their respective order. */
351         const ldns_rdf_type *_wireformat;
352         /** Special rdf types */
353         ldns_rdf_type _variable;
354         /** Specifies whether compression can be used for dnames in this RR type. */
355         ldns_rr_compress _compress;
356         /** The number of DNAMEs in the _wireformat string, for parsing. */
357         uint8_t _dname_count;
358 };
359 typedef struct ldns_struct_rr_descriptor ldns_rr_descriptor;
360
361
362 /**
363  * Create a rr type bitmap rdf providing enough space to set all 
364  * known (to ldns) rr types.
365  * \param[out] rdf the constructed rdf
366  * \return LDNS_STATUS_OK if all went well.
367  */
368 ldns_status ldns_rdf_bitmap_known_rr_types_space(ldns_rdf** rdf);
369
370 /**
371  * Create a rr type bitmap rdf with at least all known (to ldns) rr types set.
372  * \param[out] rdf the constructed rdf
373  * \return LDNS_STATUS_OK if all went well.
374  */
375 ldns_status ldns_rdf_bitmap_known_rr_types(ldns_rdf** rdf);
376
377
378 /**
379  * creates a new rr structure.
380  * \return ldns_rr *
381  */
382 ldns_rr* ldns_rr_new(void);
383
384 /**
385  * creates a new rr structure, based on the given type.
386  * alloc enough space to hold all the rdf's
387  */
388 ldns_rr* ldns_rr_new_frm_type(ldns_rr_type t);
389
390 /**
391  * frees an RR structure
392  * \param[in] *rr the RR to be freed
393  * \return void
394  */
395 void ldns_rr_free(ldns_rr *rr);
396
397 /**
398  * creates an rr from a string.
399  * The string should be a fully filled-in rr, like
400  * ownername &lt;space&gt; TTL &lt;space&gt; CLASS &lt;space&gt;
401  * TYPE &lt;space&gt; RDATA.
402  * \param[out] n the rr to return
403  * \param[in] str the string to convert
404  * \param[in] default_ttl default ttl value for the rr.
405  *            If 0 DEF_TTL will be used
406  * \param[in] origin when the owner is relative add this.
407  *      The caller must ldns_rdf_deep_free it.
408  * \param[out] prev the previous ownername. if this value is not NULL,
409  * the function overwrites this with the ownername found in this
410  * string. The caller must then ldns_rdf_deep_free it.
411  * \return a status msg describing an error or LDNS_STATUS_OK
412  */
413 ldns_status ldns_rr_new_frm_str(ldns_rr **n, const char *str,
414                                 uint32_t default_ttl, ldns_rdf *origin,
415                                 ldns_rdf **prev);
416
417 /**
418  * creates an rr for the question section from a string, i.e.
419  * without RDATA fields
420  * Origin and previous RR functionality are the same as in
421  * ldns_rr_new_frm_str()
422  * \param[out] n the rr to return
423  * \param[in] str the string to convert
424  * \param[in] origin when the owner is relative add this.
425  *      The caller must ldns_rdf_deep_free it.
426  * \param prev the previous ownername. the function overwrite this with
427  * the current found ownername. The caller must ldns_rdf_deep_free it.
428  * \return a status msg describing an error or LDNS_STATUS_OK
429  */
430 ldns_status ldns_rr_new_question_frm_str(ldns_rr **n, const char *str,
431                                 ldns_rdf *origin, ldns_rdf **prev);
432
433 /**
434  * creates a new rr from a file containing a string.
435  * \param[out] rr the new rr
436  * \param[in] fp the file pointer to use
437  * \param[in] default_ttl pointer to a default ttl for the rr. If NULL DEF_TTL will be used
438  *            the pointer will be updated if the file contains a $TTL directive
439  * \param[in] origin when the owner is relative add this
440  *            the pointer will be updated if the file contains a $ORIGIN directive
441  *            The caller must ldns_rdf_deep_free it.
442  * \param[in] prev when the owner is whitespaces use this as the * ownername
443  *            the pointer will be updated after the call
444  *            The caller must ldns_rdf_deep_free it.
445  * \return a ldns_status with an error or LDNS_STATUS_OK
446  */
447 ldns_status ldns_rr_new_frm_fp(ldns_rr **rr, FILE *fp, uint32_t *default_ttl, ldns_rdf **origin, ldns_rdf **prev);
448
449 /**
450  * creates a new rr from a file containing a string.
451  * \param[out] rr the new rr
452  * \param[in] fp the file pointer to use
453  * \param[in] default_ttl a default ttl for the rr. If NULL DEF_TTL will be used
454  *            the pointer will be updated if the file contains a $TTL directive
455  * \param[in] origin when the owner is relative add this
456  *            the pointer will be updated if the file contains a $ORIGIN directive
457  *            The caller must ldns_rdf_deep_free it.
458  * \param[in] line_nr pointer to an integer containing the current line number (for debugging purposes)
459  * \param[in] prev when the owner is whitespaces use this as the * ownername
460  *            the pointer will be updated after the call
461  *            The caller must ldns_rdf_deep_free it.
462  * \return a ldns_status with an error or LDNS_STATUS_OK
463  */
464 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);
465
466 /**
467  * sets the owner in the rr structure.
468  * \param[in] *rr rr to operate on
469  * \param[in] *owner set to this owner
470  * \return void
471  */
472 void ldns_rr_set_owner(ldns_rr *rr, ldns_rdf *owner);
473
474 /**
475  * sets the question flag in the rr structure.
476  * \param[in] *rr rr to operate on
477  * \param[in] question question flag
478  * \return void
479  */
480 void ldns_rr_set_question(ldns_rr *rr, bool question);
481
482 /**
483  * sets the ttl in the rr structure.
484  * \param[in] *rr rr to operate on
485  * \param[in] ttl set to this ttl
486  * \return void
487  */
488 void ldns_rr_set_ttl(ldns_rr *rr, uint32_t ttl);
489
490 /**
491  * sets the rd_count in the rr.
492  * \param[in] *rr rr to operate on
493  * \param[in] count set to this count
494  * \return void
495  */
496 void ldns_rr_set_rd_count(ldns_rr *rr, size_t count);
497
498 /**
499  * sets the type in the rr.
500  * \param[in] *rr rr to operate on
501  * \param[in] rr_type set to this type
502  * \return void
503  */
504 void ldns_rr_set_type(ldns_rr *rr, ldns_rr_type rr_type);
505
506 /**
507  * sets the class in the rr.
508  * \param[in] *rr rr to operate on
509  * \param[in] rr_class set to this class
510  * \return void
511  */
512 void ldns_rr_set_class(ldns_rr *rr, ldns_rr_class rr_class);
513
514 /**
515  * sets a rdf member, it will be set on the
516  * position given. The old value is returned, like pop.
517  * \param[in] *rr the rr to operate on
518  * \param[in] *f the rdf to set
519  * \param[in] position the position the set the rdf
520  * \return  the old value in the rr, NULL on failyre
521  */
522 ldns_rdf* ldns_rr_set_rdf(ldns_rr *rr, const ldns_rdf *f, size_t position);
523
524 /**
525  * sets rd_field member, it will be
526  * placed in the next available spot.
527  * \param[in] *rr rr to operate on
528  * \param[in] *f the data field member to set
529  * \return bool
530  */
531 bool ldns_rr_push_rdf(ldns_rr *rr, const ldns_rdf *f);
532
533 /**
534  * removes a rd_field member, it will be
535  * popped from the last position.
536  * \param[in] *rr rr to operate on
537  * \return rdf which was popped (null if nothing)
538  */
539 ldns_rdf* ldns_rr_pop_rdf(ldns_rr *rr);
540
541 /**
542  * returns the rdata field member counter.
543  * \param[in] *rr rr to operate on
544  * \param[in] nr the number of the rdf to return
545  * \return ldns_rdf *
546  */
547 ldns_rdf* ldns_rr_rdf(const ldns_rr *rr, size_t nr);
548
549 /**
550  * returns the owner name of an rr structure.
551  * \param[in] *rr rr to operate on
552  * \return ldns_rdf *
553  */
554 ldns_rdf* ldns_rr_owner(const ldns_rr *rr);
555
556 /**
557  * returns the question flag of an rr structure.
558  * \param[in] *rr rr to operate on
559  * \return bool true if question
560  */
561 bool ldns_rr_is_question(const ldns_rr *rr);
562
563 /**
564  * returns the ttl of an rr structure.
565  * \param[in] *rr the rr to read from
566  * \return the ttl of the rr
567  */
568 uint32_t ldns_rr_ttl(const ldns_rr *rr);
569
570 /**
571  * returns the rd_count of an rr structure.
572  * \param[in] *rr the rr to read from
573  * \return the rd count of the rr
574  */
575 size_t ldns_rr_rd_count(const ldns_rr *rr);
576
577 /**
578  * returns the type of the rr.
579  * \param[in] *rr the rr to read from
580  * \return the type of the rr
581  */
582 ldns_rr_type ldns_rr_get_type(const ldns_rr *rr);
583
584 /**
585  * returns the class of the rr.
586  * \param[in] *rr the rr to read from
587  * \return the class of the rr
588  */
589 ldns_rr_class ldns_rr_get_class(const ldns_rr *rr);
590
591 /* rr_lists */
592
593 /**
594  * returns the number of rr's in an rr_list.
595  * \param[in] rr_list  the rr_list to read from
596  * \return the number of rr's
597  */
598 size_t ldns_rr_list_rr_count(const ldns_rr_list *rr_list);
599
600 /**
601  * sets the number of rr's in an rr_list.
602  * \param[in] rr_list the rr_list to set the count on
603  * \param[in] count the number of rr in this list
604  * \return void
605  */
606 void ldns_rr_list_set_rr_count(ldns_rr_list *rr_list, size_t count);
607
608 /**
609  * set a rr on a specific index in a ldns_rr_list
610  * \param[in] rr_list the rr_list to use
611  * \param[in] r the rr to set
612  * \param[in] count index into the rr_list
613  * \return the old rr which was stored in the rr_list, or
614  * NULL is the index was too large
615  * set a specific rr */
616 ldns_rr * ldns_rr_list_set_rr(ldns_rr_list *rr_list, const ldns_rr *r, size_t count);
617
618 /**
619  * returns a specific rr of an rrlist.
620  * \param[in] rr_list the rr_list to read from
621  * \param[in] nr return this rr
622  * \return the rr at position nr
623  */
624 ldns_rr* ldns_rr_list_rr(const ldns_rr_list *rr_list, size_t nr);
625
626 /**
627  * creates a new rr_list structure.
628  * \return a new rr_list structure
629  */
630 ldns_rr_list* ldns_rr_list_new(void);
631
632 /**
633  * frees an rr_list structure.
634  * \param[in] rr_list the list to free
635  */
636 void ldns_rr_list_free(ldns_rr_list *rr_list);
637
638 /**
639  * frees an rr_list structure and all rrs contained therein.
640  * \param[in] rr_list the list to free
641  */
642 void ldns_rr_list_deep_free(ldns_rr_list *rr_list);
643
644 /**
645  * concatenates two ldns_rr_lists together. This modifies
646  * *left (to extend it and add the pointers from *right).
647  * \param[in] left the leftside
648  * \param[in] right the rightside
649  * \return a left with right concatenated to it
650  */
651 bool ldns_rr_list_cat(ldns_rr_list *left, ldns_rr_list *right);
652
653 /**
654  * concatenates two ldns_rr_lists together, but makes clones of the rr's 
655  * (instead of pointer copying).
656  * \param[in] left the leftside
657  * \param[in] right the rightside
658  * \return a new rr_list with leftside/rightside concatenated
659  */
660 ldns_rr_list* ldns_rr_list_cat_clone(ldns_rr_list *left, ldns_rr_list *right);
661
662 /**
663  * pushes an rr to an rrlist.
664  * \param[in] rr_list the rr_list to push to 
665  * \param[in] rr the rr to push 
666  * \return false on error, otherwise true
667  */
668 bool ldns_rr_list_push_rr(ldns_rr_list *rr_list, const ldns_rr *rr);
669
670 /**
671  * pushes an rr_list to an rrlist.
672  * \param[in] rr_list the rr_list to push to 
673  * \param[in] push_list the rr_list to push 
674  * \return false on error, otherwise true
675  */
676 bool ldns_rr_list_push_rr_list(ldns_rr_list *rr_list, const ldns_rr_list *push_list);
677
678 /**
679  * pops the last rr from an rrlist.
680  * \param[in] rr_list the rr_list to pop from
681  * \return NULL if nothing to pop. Otherwise the popped RR
682  */
683 ldns_rr* ldns_rr_list_pop_rr(ldns_rr_list *rr_list);
684
685 /**
686  * pops an  rr_list of size s from an rrlist.
687  * \param[in] rr_list the rr_list to pop from
688  * \param[in] size the number of rr's to pop 
689  * \return NULL if nothing to pop. Otherwise the popped rr_list
690  */
691 ldns_rr_list* ldns_rr_list_pop_rr_list(ldns_rr_list *rr_list, size_t size);
692
693 /**
694  * returns true if the given rr is one of the rrs in the
695  * list, or if it is equal to one
696  * \param[in] rr_list the rr_list to check
697  * \param[in] rr the rr to check
698  * \return true if rr_list contains rr, false otherwise
699  */
700 bool ldns_rr_list_contains_rr(const ldns_rr_list *rr_list, ldns_rr *rr); 
701
702 /**
703  * checks if an rr_list is a rrset.
704  * \param[in] rr_list the rr_list to check
705  * \return true if it is an rrset otherwise false
706  */
707 bool ldns_is_rrset(ldns_rr_list *rr_list);
708
709 /**
710  * pushes an rr to an rrset (which really are rr_list's).
711  * \param[in] *rr_list the rrset to push the rr to
712  * \param[in] *rr the rr to push
713  * \return true if the push succeeded otherwise false
714  */
715 bool ldns_rr_set_push_rr(ldns_rr_list *rr_list, ldns_rr *rr);
716
717 /**
718  * pops the last rr from an rrset. This function is there only
719  * for the symmetry.
720  * \param[in] rr_list the rr_list to pop from
721  * \return NULL if nothing to pop. Otherwise the popped RR
722  *
723  */
724 ldns_rr* ldns_rr_set_pop_rr(ldns_rr_list *rr_list);
725
726 /**
727  * pops the first rrset from the list,
728  * the list must be sorted, so that all rr's from each rrset
729  * are next to each other
730  */
731 ldns_rr_list *ldns_rr_list_pop_rrset(ldns_rr_list *rr_list);
732
733
734 /**
735  * retrieves a rrtype by looking up its name.
736  * \param[in] name a string with the name
737  * \return the type which corresponds with the name
738  */
739 ldns_rr_type ldns_get_rr_type_by_name(const char *name);
740
741 /**
742  * retrieves a class by looking up its name.
743  * \param[in] name string with the name
744  * \return the cass which corresponds with the name
745  */
746 ldns_rr_class ldns_get_rr_class_by_name(const char *name);
747
748 /**
749  * clones a rr and all its data
750  * \param[in] rr the rr to clone
751  * \return the new rr or NULL on failure
752  */
753 ldns_rr* ldns_rr_clone(const ldns_rr *rr);
754
755 /**
756  * clones an rrlist.
757  * \param[in] rrlist the rrlist to clone
758  * \return the cloned rr list
759  */
760 ldns_rr_list* ldns_rr_list_clone(const ldns_rr_list *rrlist);
761
762 /**
763  * sorts an rr_list (canonical wire format). the sorting is done inband.
764  * \param[in] unsorted the rr_list to be sorted
765  * \return void
766  */
767 void ldns_rr_list_sort(ldns_rr_list *unsorted);
768
769 /**
770  * compares two rrs. The TTL is not looked at.
771  * \param[in] rr1 the first one
772  * \param[in] rr2 the second one
773  * \return 0 if equal
774  *         -1 if rr1 comes before rr2
775  *         +1 if rr2 comes before rr1
776  */
777 int ldns_rr_compare(const ldns_rr *rr1, const ldns_rr *rr2);
778
779 /**
780  * compares two rrs, up to the rdata.
781  * \param[in] rr1 the first one
782  * \param[in] rr2 the second one
783  * \return 0 if equal
784  *         -1 if rr1 comes before rr2
785  *         +1 if rr2 comes before rr1
786  */
787 int ldns_rr_compare_no_rdata(const ldns_rr *rr1, const ldns_rr *rr2);
788
789 /**
790  * compares the wireformat of two rrs, contained in the given buffers.
791  * \param[in] rr1_buf the first one
792  * \param[in] rr2_buf the second one
793  * \return 0 if equal
794  *         -1 if rr1_buf comes before rr2_buf
795  *         +1 if rr2_buf comes before rr1_buf
796  */
797 int ldns_rr_compare_wire(ldns_buffer *rr1_buf, ldns_buffer *rr2_buf);
798
799 /**
800  * returns true of the given rr's are equal.
801  * Also returns true if one record is a DS that represents the
802  * same DNSKEY record as the other record
803  * \param[in] rr1 the first rr
804  * \param[in] rr2 the second rr
805  * \return true if equal otherwise false
806  */
807 bool ldns_rr_compare_ds(const ldns_rr *rr1, const ldns_rr *rr2);
808
809 /**
810  * compares two rr listss.
811  * \param[in] rrl1 the first one
812  * \param[in] rrl2 the second one
813  * \return 0 if equal
814  *         -1 if rrl1 comes before rrl2
815  *         +1 if rrl2 comes before rrl1
816  */
817 int ldns_rr_list_compare(const ldns_rr_list *rrl1, const ldns_rr_list *rrl2);
818
819 /** 
820  * calculates the uncompressed size of an RR.
821  * \param[in] r the rr to operate on
822  * \return size of the rr
823  */
824 size_t ldns_rr_uncompressed_size(const ldns_rr *r);
825
826 /** 
827  * converts each dname in a rr to its canonical form.
828  * \param[in] rr the rr to work on
829  * \return void
830  */
831 void ldns_rr2canonical(ldns_rr *rr);
832
833 /** 
834  * converts each dname in each rr in a rr_list to its canonical form.
835  * \param[in] rr_list the rr_list to work on
836  * \return void
837  */
838 void ldns_rr_list2canonical(ldns_rr_list *rr_list);
839
840 /** 
841  * counts the number of labels of the ownername.
842  * \param[in] rr count the labels of this rr
843  * \return the number of labels
844  */
845 uint8_t ldns_rr_label_count(ldns_rr *rr);
846
847 /**
848  * returns the resource record descriptor for the given rr type.
849  *
850  * \param[in] type the type value of the rr type
851  *\return the ldns_rr_descriptor for this type
852  */
853 const ldns_rr_descriptor *ldns_rr_descript(uint16_t type);
854
855 /**
856  * returns the minimum number of rdata fields of the rr type this descriptor describes.
857  *
858  * \param[in]  descriptor for an rr type
859  * \return the minimum number of rdata fields
860  */
861 size_t ldns_rr_descriptor_minimum(const ldns_rr_descriptor *descriptor);
862
863 /**
864  * returns the maximum number of rdata fields of the rr type this descriptor describes.
865  *
866  * \param[in]  descriptor for an rr type
867  * \return the maximum number of rdata fields
868  */
869 size_t ldns_rr_descriptor_maximum(const ldns_rr_descriptor *descriptor);
870
871 /**
872  * returns the rdf type for the given rdata field number of the rr type for the given descriptor.
873  *
874  * \param[in] descriptor for an rr type
875  * \param[in] field the field number
876  * \return the rdf type for the field
877  */
878 ldns_rdf_type ldns_rr_descriptor_field_type(const ldns_rr_descriptor *descriptor, size_t field);
879
880 /**
881  * Return the rr_list which matches the rdf at position field. Think
882  * type-covered stuff for RRSIG
883  * 
884  * \param[in] l the rr_list to look in
885  * \param[in] r the rdf to use for the comparison
886  * \param[in] pos at which position can we find the rdf
887  * 
888  * \return a new rr list with only the RRs that match 
889  *
890  */
891 ldns_rr_list *ldns_rr_list_subtype_by_rdf(ldns_rr_list *l, ldns_rdf *r, size_t pos);
892
893 /**
894  * convert an rdf of type LDNS_RDF_TYPE_TYPE to an actual
895  * LDNS_RR_TYPE. This is usefull in the case when inspecting
896  * the rrtype covered field of an RRSIG.
897  * \param[in] rd the rdf to look at
898  * \return a ldns_rr_type with equivalent LDNS_RR_TYPE
899  *
900  */
901 ldns_rr_type    ldns_rdf2rr_type(const ldns_rdf *rd);
902
903 /**
904  * Returns the type of the first element of the RR
905  * If there are no elements present, 0 is returned
906  * 
907  * \param[in] rr_list The rr list
908  * \return rr_type of the first element, or 0 if the list is empty
909  */
910 ldns_rr_type
911 ldns_rr_list_type(const ldns_rr_list *rr_list);
912
913 /**
914  * Returns the owner domain name rdf of the first element of the RR
915  * If there are no elements present, NULL is returned
916  * 
917  * \param[in] rr_list The rr list
918  * \return dname of the first element, or NULL if the list is empty
919  */
920 ldns_rdf *
921 ldns_rr_list_owner(const ldns_rr_list *rr_list);
922
923 #ifdef __cplusplus
924 }
925 #endif
926
927 #endif /* LDNS_RR_H */