File Coverage

src/ldns/rr.c
Criterion Covered Total %
statement 493 928 53.1
branch 244 568 42.9
condition n/a
subroutine n/a
pod n/a
total 737 1496 49.2


line stmt bran cond sub pod time code
1             /* rr.c
2             *
3             * access functions for ldns_rr -
4             * a Net::DNS like library for C
5             * LibDNS Team @ NLnet Labs
6             *
7             * (c) NLnet Labs, 2004-2006
8             * See the file LICENSE for the license
9             */
10             #include
11              
12             #include
13              
14             #include
15             #include
16              
17             #include
18              
19             #define LDNS_SYNTAX_DATALEN 16
20             #define LDNS_TTL_DATALEN 21
21             #define LDNS_RRLIST_INIT 8
22              
23             ldns_rr *
24 645           ldns_rr_new(void)
25             {
26             ldns_rr *rr;
27 645           rr = LDNS_MALLOC(ldns_rr);
28 645 50         if (!rr) {
29 0           return NULL;
30             }
31              
32 645           ldns_rr_set_owner(rr, NULL);
33 645           ldns_rr_set_question(rr, false);
34 645           ldns_rr_set_rd_count(rr, 0);
35 645           rr->_rdata_fields = NULL;
36 645           ldns_rr_set_class(rr, LDNS_RR_CLASS_IN);
37 645           ldns_rr_set_ttl(rr, LDNS_DEFAULT_TTL);
38 645           return rr;
39             }
40              
41             ldns_rr *
42 0           ldns_rr_new_frm_type(ldns_rr_type t)
43             {
44             ldns_rr *rr;
45             const ldns_rr_descriptor *desc;
46             size_t i;
47              
48 0           rr = LDNS_MALLOC(ldns_rr);
49 0 0         if (!rr) {
50 0           return NULL;
51             }
52              
53 0           desc = ldns_rr_descript(t);
54              
55 0           rr->_rdata_fields = LDNS_XMALLOC(ldns_rdf *, ldns_rr_descriptor_minimum(desc));
56 0 0         if(!rr->_rdata_fields) {
57 0           LDNS_FREE(rr);
58 0           return NULL;
59             }
60 0 0         for (i = 0; i < ldns_rr_descriptor_minimum(desc); i++) {
61 0           rr->_rdata_fields[i] = NULL;
62             }
63              
64 0           ldns_rr_set_owner(rr, NULL);
65 0           ldns_rr_set_question(rr, false);
66             /* set the count to minimum */
67 0           ldns_rr_set_rd_count(rr, ldns_rr_descriptor_minimum(desc));
68 0           ldns_rr_set_class(rr, LDNS_RR_CLASS_IN);
69 0           ldns_rr_set_ttl(rr, LDNS_DEFAULT_TTL);
70 0           ldns_rr_set_type(rr, t);
71 0           return rr;
72             }
73              
74             void
75 719           ldns_rr_free(ldns_rr *rr)
76             {
77             size_t i;
78 719 100         if (rr) {
79 644 50         if (ldns_rr_owner(rr)) {
80 644           ldns_rdf_deep_free(ldns_rr_owner(rr));
81             }
82 2103 100         for (i = 0; i < ldns_rr_rd_count(rr); i++) {
83 1459           ldns_rdf_deep_free(ldns_rr_rdf(rr, i));
84             }
85 644           LDNS_FREE(rr->_rdata_fields);
86 644           LDNS_FREE(rr);
87             }
88 719           }
89              
90             /* Syntactic sugar for ldns_rr_new_frm_str_internal */
91             INLINE bool
92 108           ldns_rdf_type_maybe_quoted(ldns_rdf_type rdf_type)
93             {
94 108 100         return rdf_type == LDNS_RDF_TYPE_STR ||
    50          
95             rdf_type == LDNS_RDF_TYPE_LONG_STR;
96             }
97              
98             /*
99             * trailing spaces are allowed
100             * leading spaces are not allowed
101             * allow ttl to be optional
102             * class is optional too
103             * if ttl is missing, and default_ttl is 0, use DEF_TTL
104             * allow ttl to be written as 1d3h
105             * So the RR should look like. e.g.
106             * miek.nl. 3600 IN MX 10 elektron.atoom.net
107             * or
108             * miek.nl. 1h IN MX 10 elektron.atoom.net
109             * or
110             * miek.nl. IN MX 10 elektron.atoom.net
111             */
112             static ldns_status
113 55           ldns_rr_new_frm_str_internal(ldns_rr **newrr, const char *str,
114             uint32_t default_ttl, ldns_rdf *origin,
115             ldns_rdf **prev, bool question)
116             {
117             ldns_rr *new;
118             const ldns_rr_descriptor *desc;
119             ldns_rr_type rr_type;
120 55           ldns_buffer *rr_buf = NULL;
121 55           ldns_buffer *rd_buf = NULL;
122             uint32_t ttl_val;
123 55           char *owner = NULL;
124 55           char *ttl = NULL;
125             ldns_rr_class clas_val;
126 55           char *clas = NULL;
127 55           char *type = NULL;
128 55           char *rdata = NULL;
129 55           char *rd = NULL;
130 55           char *xtok = NULL; /* For RDF types with spaces (i.e. extra tokens) */
131             size_t rd_strlen;
132             const char *delimiters;
133             ssize_t c;
134             ldns_rdf *owner_dname;
135             const char* endptr;
136 55           int was_unknown_rr_format = 0;
137 55           ldns_status status = LDNS_STATUS_OK;
138              
139             /* used for types with unknown number of rdatas */
140             bool done;
141             bool quoted;
142              
143 55           ldns_rdf *r = NULL;
144             uint16_t r_cnt;
145             uint16_t r_min;
146             uint16_t r_max;
147             size_t pre_data_pos;
148              
149             uint16_t hex_data_size;
150 55           char *hex_data_str = NULL;
151             uint16_t cur_hex_data_size;
152 55           size_t hex_pos = 0;
153 55           uint8_t *hex_data = NULL;
154              
155 55           new = ldns_rr_new();
156              
157 55           owner = LDNS_XMALLOC(char, LDNS_MAX_DOMAINLEN + 1);
158 55           ttl = LDNS_XMALLOC(char, LDNS_TTL_DATALEN);
159 55           clas = LDNS_XMALLOC(char, LDNS_SYNTAX_DATALEN);
160 55           rdata = LDNS_XMALLOC(char, LDNS_MAX_PACKETLEN + 1);
161 55           rr_buf = LDNS_MALLOC(ldns_buffer);
162 55           rd_buf = LDNS_MALLOC(ldns_buffer);
163 55           rd = LDNS_XMALLOC(char, LDNS_MAX_RDFLEN);
164 55           xtok = LDNS_XMALLOC(char, LDNS_MAX_RDFLEN);
165 55 50         if (rr_buf) {
166 55           rr_buf->_data = NULL;
167             }
168 55 50         if (rd_buf) {
169 55           rd_buf->_data = NULL;
170             }
171 55 50         if (!new || !owner || !ttl || !clas || !rdata ||
    50          
    50          
    50          
    50          
    50          
172 55 50         !rr_buf || !rd_buf || !rd || !xtok) {
    50          
    50          
173              
174             goto memerror;
175             }
176              
177 55           ldns_buffer_new_frm_data(rr_buf, (char*)str, strlen(str));
178              
179             /* split the rr in its parts -1 signals trouble */
180 55 50         if (ldns_bget_token(rr_buf, owner, "\t\n ", LDNS_MAX_DOMAINLEN) == -1){
181              
182 0           status = LDNS_STATUS_SYNTAX_ERR;
183 0           goto error;
184             }
185              
186 55 50         if (ldns_bget_token(rr_buf, ttl, "\t\n ", LDNS_TTL_DATALEN) == -1) {
187              
188 0           status = LDNS_STATUS_SYNTAX_TTL_ERR;
189 0           goto error;
190             }
191 55           ttl_val = (uint32_t) ldns_str2period(ttl, &endptr);
192              
193 55 50         if (strlen(ttl) > 0 && !isdigit((int) ttl[0])) {
    100          
194             /* ah, it's not there or something */
195 43 100         if (default_ttl == 0) {
196 27           ttl_val = LDNS_DEFAULT_TTL;
197             } else {
198 16           ttl_val = default_ttl;
199             }
200             /* we not ASSUMING the TTL is missing and that
201             * the rest of the RR is still there. That is
202             * CLASS TYPE RDATA
203             * so ttl value we read is actually the class
204             */
205 43           clas_val = ldns_get_rr_class_by_name(ttl);
206             /* class can be left out too, assume IN, current
207             * token must be type
208             */
209 58 100         if (clas_val == 0) {
210 15           clas_val = LDNS_RR_CLASS_IN;
211 15           type = LDNS_XMALLOC(char, strlen(ttl) + 1);
212 15 50         if (!type) {
213 0           goto memerror;
214             }
215 15           strncpy(type, ttl, strlen(ttl) + 1);
216             }
217             } else {
218 12 50         if (-1 == ldns_bget_token(
219             rr_buf, clas, "\t\n ", LDNS_SYNTAX_DATALEN)) {
220              
221 0           status = LDNS_STATUS_SYNTAX_CLASS_ERR;
222 0           goto error;
223             }
224 12           clas_val = ldns_get_rr_class_by_name(clas);
225             /* class can be left out too, assume IN, current
226             * token must be type
227             */
228 12 50         if (clas_val == 0) {
229 0           clas_val = LDNS_RR_CLASS_IN;
230 0           type = LDNS_XMALLOC(char, strlen(clas) + 1);
231 0 0         if (!type) {
232 0           goto memerror;
233             }
234 0           strncpy(type, clas, strlen(clas) + 1);
235             }
236             }
237             /* the rest should still be waiting for us */
238              
239 55 100         if (!type) {
240 40           type = LDNS_XMALLOC(char, LDNS_SYNTAX_DATALEN);
241 40 50         if (!type) {
242 0           goto memerror;
243             }
244 40 50         if (-1 == ldns_bget_token(
245             rr_buf, type, "\t\n ", LDNS_SYNTAX_DATALEN)) {
246              
247 0           status = LDNS_STATUS_SYNTAX_TYPE_ERR;
248 0           goto error;
249             }
250             }
251              
252 55           if (ldns_bget_token(rr_buf, rdata, "\0", LDNS_MAX_PACKETLEN) == -1) {
253             /* apparently we are done, and it's only a question RR
254             * so do not set status and go to ldnserror here
255             */
256             }
257 55           ldns_buffer_new_frm_data(rd_buf, rdata, strlen(rdata));
258              
259 55 100         if (strlen(owner) <= 1 && strncmp(owner, "@", 1) == 0) {
    50          
260 0 0         if (origin) {
261 0           ldns_rr_set_owner(new, ldns_rdf_clone(origin));
262 0 0         } else if (prev && *prev) {
    0          
263 0           ldns_rr_set_owner(new, ldns_rdf_clone(*prev));
264             } else {
265             /* default to root */
266 0           ldns_rr_set_owner(new, ldns_dname_new_frm_str("."));
267             }
268              
269             /* @ also overrides prev */
270 0 0         if (prev) {
271 0           ldns_rdf_deep_free(*prev);
272 0           *prev = ldns_rdf_clone(ldns_rr_owner(new));
273 0 0         if (!*prev) {
274 0           goto memerror;
275             }
276             }
277             } else {
278 55 100         if (strlen(owner) == 0) {
279             /* no ownername was given, try prev, if that fails
280             * origin, else default to root */
281 5 50         if (prev && *prev) {
    50          
282 5           ldns_rr_set_owner(new, ldns_rdf_clone(*prev));
283 0 0         } else if (origin) {
284 0           ldns_rr_set_owner(new, ldns_rdf_clone(origin));
285             } else {
286 0           ldns_rr_set_owner(new,
287             ldns_dname_new_frm_str("."));
288             }
289 5 50         if(!ldns_rr_owner(new)) {
290 0           goto memerror;
291             }
292             } else {
293 50           owner_dname = ldns_dname_new_frm_str(owner);
294 50 50         if (!owner_dname) {
295 0           status = LDNS_STATUS_SYNTAX_ERR;
296 0           goto error;
297             }
298              
299 50           ldns_rr_set_owner(new, owner_dname);
300 50 100         if (!ldns_dname_str_absolute(owner) && origin) {
    100          
301 11 50         if(ldns_dname_cat(ldns_rr_owner(new), origin)
302             != LDNS_STATUS_OK) {
303              
304 0           status = LDNS_STATUS_SYNTAX_ERR;
305 0           goto error;
306             }
307             }
308 50 100         if (prev) {
309 11           ldns_rdf_deep_free(*prev);
310 11           *prev = ldns_rdf_clone(ldns_rr_owner(new));
311 11 50         if (!*prev) {
312 0           goto error;
313             }
314             }
315             }
316             }
317 55           LDNS_FREE(owner);
318              
319 55           ldns_rr_set_question(new, question);
320              
321 55           ldns_rr_set_ttl(new, ttl_val);
322 55           LDNS_FREE(ttl);
323              
324 55           ldns_rr_set_class(new, clas_val);
325 55           LDNS_FREE(clas);
326              
327 55           rr_type = ldns_get_rr_type_by_name(type);
328 55           LDNS_FREE(type);
329              
330 55           desc = ldns_rr_descript((uint16_t)rr_type);
331 55           ldns_rr_set_type(new, rr_type);
332 55 50         if (desc) {
333             /* only the rdata remains */
334 55           r_max = ldns_rr_descriptor_maximum(desc);
335 55           r_min = ldns_rr_descriptor_minimum(desc);
336             } else {
337 0           r_min = 0;
338 0           r_max = 1;
339             }
340              
341 163 100         for (done = false, r_cnt = 0; !done && r_cnt < r_max; r_cnt++) {
    100          
342 108           quoted = false;
343              
344 108 100         switch (ldns_rr_descriptor_field_type(desc, r_cnt)) {
345             case LDNS_RDF_TYPE_B64 :
346             case LDNS_RDF_TYPE_HEX : /* These rdf types may con- */
347             case LDNS_RDF_TYPE_LOC : /* tain whitespace, only if */
348             case LDNS_RDF_TYPE_WKS : /* it is the last rd field. */
349             case LDNS_RDF_TYPE_IPSECKEY :
350 7 50         case LDNS_RDF_TYPE_NSEC : if (r_cnt == r_max - 1) {
351 7           delimiters = "\n";
352 7           break;
353             }
354 101           default : delimiters = "\n\t ";
355             }
356              
357 108 100         if (ldns_rdf_type_maybe_quoted(
358             ldns_rr_descriptor_field_type(
359 2 50         desc, r_cnt)) &&
360 2           ldns_buffer_remaining(rd_buf) > 0){
361              
362             /* skip spaces */
363 2 50         while (*(ldns_buffer_current(rd_buf)) == ' ') {
364 0           ldns_buffer_skip(rd_buf, 1);
365             }
366              
367 2 50         if (*(ldns_buffer_current(rd_buf)) == '\"') {
368 2           delimiters = "\"\0";
369 2           ldns_buffer_skip(rd_buf, 1);
370 2           quoted = true;
371             }
372             }
373              
374             /* because number of fields can be variable, we can't rely on
375             * _maximum() only
376             */
377              
378             /* skip spaces */
379 108 50         while (ldns_buffer_position(rd_buf) < ldns_buffer_limit(rd_buf)
380 108 50         && *(ldns_buffer_current(rd_buf)) == ' '
381 0 0         && !quoted) {
382              
383 0           ldns_buffer_skip(rd_buf, 1);
384             }
385              
386 108           pre_data_pos = ldns_buffer_position(rd_buf);
387 108 50         if (-1 == (c = ldns_bget_token(
388             rd_buf, rd, delimiters, LDNS_MAX_RDFLEN))) {
389              
390 0           done = true;
391 0           break;
392             }
393             /* hmmz, rfc3597 specifies that any type can be represented
394             * with \# method, which can contain spaces...
395             * it does specify size though...
396             */
397 108           rd_strlen = strlen(rd);
398              
399             /* unknown RR data */
400 108 50         if (strncmp(rd, "\\#", 2) == 0 && !quoted &&
    0          
    0          
401 0 0         (rd_strlen == 2 || rd[2]==' ')) {
402              
403 0           was_unknown_rr_format = 1;
404             /* go back to before \#
405             * and skip it while setting delimiters better
406             */
407 0           ldns_buffer_set_position(rd_buf, pre_data_pos);
408 0           delimiters = "\n\t ";
409 0           (void)ldns_bget_token(rd_buf, rd,
410             delimiters, LDNS_MAX_RDFLEN);
411             /* read rdata octet length */
412 0           c = ldns_bget_token(rd_buf, rd,
413             delimiters, LDNS_MAX_RDFLEN);
414 0 0         if (c == -1) {
415             /* something goes very wrong here */
416 0           status = LDNS_STATUS_SYNTAX_RDATA_ERR;
417 0           goto error;
418             }
419 0           hex_data_size = (uint16_t) atoi(rd);
420             /* copy hex chars into hex str (2 chars per byte) */
421 0           hex_data_str = LDNS_XMALLOC(char, 2*hex_data_size + 1);
422 0 0         if (!hex_data_str) {
423             /* malloc error */
424 0           goto memerror;
425             }
426 0           cur_hex_data_size = 0;
427 0 0         while(cur_hex_data_size < 2 * hex_data_size) {
428 0           c = ldns_bget_token(rd_buf, rd,
429             delimiters, LDNS_MAX_RDFLEN);
430 0 0         if (c != -1) {
431 0           rd_strlen = strlen(rd);
432             }
433 0 0         if (c == -1 ||
    0          
434 0           (size_t)cur_hex_data_size + rd_strlen >
435 0           2 * (size_t)hex_data_size) {
436              
437 0           status = LDNS_STATUS_SYNTAX_RDATA_ERR;
438 0           goto error;
439             }
440 0           strncpy(hex_data_str + cur_hex_data_size, rd,
441             rd_strlen);
442              
443 0           cur_hex_data_size += rd_strlen;
444             }
445 0           hex_data_str[cur_hex_data_size] = '\0';
446              
447             /* correct the rdf type */
448             /* if *we* know the type, interpret it as wireformat */
449 0 0         if (desc) {
450 0           hex_pos = 0;
451 0           hex_data =
452 0           LDNS_XMALLOC(uint8_t, hex_data_size+2);
453              
454 0 0         if (!hex_data) {
455 0           goto memerror;
456             }
457 0           ldns_write_uint16(hex_data, hex_data_size);
458 0           ldns_hexstring_to_data(
459             hex_data + 2, hex_data_str);
460 0           status = ldns_wire2rdf(new, hex_data,
461 0           hex_data_size + 2, &hex_pos);
462 0 0         if (status != LDNS_STATUS_OK) {
463 0           goto error;
464             }
465 0           LDNS_FREE(hex_data);
466             } else {
467 0           r = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_HEX,
468             hex_data_str);
469 0 0         if (!r) {
470 0           goto memerror;
471             }
472 0           ldns_rdf_set_type(r, LDNS_RDF_TYPE_UNKNOWN);
473 0 0         if (!ldns_rr_push_rdf(new, r)) {
474 0           goto memerror;
475             }
476             }
477 0           LDNS_FREE(hex_data_str);
478              
479 108 50         } else if(rd_strlen > 0 || quoted) {
    0          
480             /* Normal RR */
481 108           switch(ldns_rr_descriptor_field_type(desc, r_cnt)) {
482              
483             case LDNS_RDF_TYPE_HEX:
484             case LDNS_RDF_TYPE_B64:
485             /* When this is the last rdata field, then the
486             * rest should be read in (cause then these
487             * rdf types may contain spaces).
488             */
489 4 50         if (r_cnt == r_max - 1) {
490 4           c = ldns_bget_token(rd_buf, xtok,
491             "\n", LDNS_MAX_RDFLEN);
492 4 50         if (c != -1) {
493 0           (void) strncat(rd, xtok,
494             LDNS_MAX_RDFLEN -
495 0           strlen(rd) - 1);
496             }
497             }
498 4           r = ldns_rdf_new_frm_str(
499             ldns_rr_descriptor_field_type(
500             desc, r_cnt), rd);
501 4           break;
502              
503             case LDNS_RDF_TYPE_HIP:
504             /*
505             * In presentation format this RDATA type has
506             * three tokens: An algorithm byte, then a
507             * variable length HIT (in hexbytes) and then
508             * a variable length Public Key (in base64).
509             *
510             * We have just read the algorithm, so we need
511             * two more tokens: HIT and Public Key.
512             */
513             do {
514             /* Read and append HIT */
515 0 0         if (ldns_bget_token(rd_buf,
516             xtok, delimiters,
517             LDNS_MAX_RDFLEN) == -1)
518 0           break;
519              
520 0           (void) strncat(rd, " ",
521             LDNS_MAX_RDFLEN -
522 0           strlen(rd) - 1);
523 0           (void) strncat(rd, xtok,
524             LDNS_MAX_RDFLEN -
525 0           strlen(rd) - 1);
526              
527             /* Read and append Public Key*/
528 0 0         if (ldns_bget_token(rd_buf,
529             xtok, delimiters,
530             LDNS_MAX_RDFLEN) == -1)
531 0           break;
532              
533 0           (void) strncat(rd, " ",
534             LDNS_MAX_RDFLEN -
535 0           strlen(rd) - 1);
536 0           (void) strncat(rd, xtok,
537             LDNS_MAX_RDFLEN -
538 0           strlen(rd) - 1);
539             } while (false);
540              
541 0           r = ldns_rdf_new_frm_str(
542             ldns_rr_descriptor_field_type(
543             desc, r_cnt), rd);
544 0           break;
545              
546             case LDNS_RDF_TYPE_DNAME:
547 24           r = ldns_rdf_new_frm_str(
548             ldns_rr_descriptor_field_type(
549             desc, r_cnt), rd);
550              
551             /* check if the origin should be used
552             * or concatenated
553             */
554 48 50         if (r && ldns_rdf_size(r) > 1 &&
555 32 50         ldns_rdf_data(r)[0] == 1 &&
556 8           ldns_rdf_data(r)[1] == '@') {
557              
558 0           ldns_rdf_deep_free(r);
559              
560 0           r = origin ? ldns_rdf_clone(origin)
561              
562 0 0         : ( rr_type == LDNS_RR_TYPE_SOA ?
563              
564             ldns_rdf_clone(
565 0           ldns_rr_owner(new))
566              
567 0 0         : ldns_rdf_new_frm_str(
568             LDNS_RDF_TYPE_DNAME, ".")
569             );
570              
571 33 50         } else if (r && rd_strlen >= 1 && origin &&
    50          
572 9           !ldns_dname_str_absolute(rd)) {
573              
574 1           status = ldns_dname_cat(r, origin);
575 1 50         if (status != LDNS_STATUS_OK) {
576 0           goto error;
577             }
578             }
579 24           break;
580             default:
581 80           r = ldns_rdf_new_frm_str(
582             ldns_rr_descriptor_field_type(
583             desc, r_cnt), rd);
584 80           break;
585             }
586 108 50         if (!r) {
587 0           status = LDNS_STATUS_SYNTAX_RDATA_ERR;
588 0           goto error;
589             }
590 108           ldns_rr_push_rdf(new, r);
591             }
592 108 100         if (quoted) {
593 2 50         if (ldns_buffer_available(rd_buf, 1)) {
594 0           ldns_buffer_skip(rd_buf, 1);
595             } else {
596 2           done = true;
597             }
598             }
599              
600             } /* for (done = false, r_cnt = 0; !done && r_cnt < r_max; r_cnt++) */
601 55           LDNS_FREE(rd);
602 55           LDNS_FREE(xtok);
603 55           ldns_buffer_free(rd_buf);
604 55           ldns_buffer_free(rr_buf);
605 55           LDNS_FREE(rdata);
606              
607 110 50         if (!question && desc && !was_unknown_rr_format &&
    50          
608 55           ldns_rr_rd_count(new) < r_min) {
609              
610 0           ldns_rr_free(new);
611 0           return LDNS_STATUS_SYNTAX_MISSING_VALUE_ERR;
612             }
613              
614 55 50         if (newrr) {
615 55           *newrr = new;
616             } else {
617             /* Maybe the caller just wanted to see if it would parse? */
618 0           ldns_rr_free(new);
619             }
620 55           return LDNS_STATUS_OK;
621              
622             memerror:
623 0           status = LDNS_STATUS_MEM_ERR;
624             error:
625 0 0         if (rd_buf && rd_buf->_data) {
    0          
626 0           ldns_buffer_free(rd_buf);
627             } else {
628 0           LDNS_FREE(rd_buf);
629             }
630 0 0         if (rr_buf && rr_buf->_data) {
    0          
631 0           ldns_buffer_free(rr_buf);
632             } else {
633 0           LDNS_FREE(rr_buf);
634             }
635 0           LDNS_FREE(type);
636 0           LDNS_FREE(owner);
637 0           LDNS_FREE(ttl);
638 0           LDNS_FREE(clas);
639 0           LDNS_FREE(hex_data);
640 0           LDNS_FREE(hex_data_str);
641 0           LDNS_FREE(xtok);
642 0           LDNS_FREE(rd);
643 0           LDNS_FREE(rdata);
644 0           ldns_rr_free(new);
645 55           return status;
646             }
647              
648             ldns_status
649 55           ldns_rr_new_frm_str(ldns_rr **newrr, const char *str,
650             uint32_t default_ttl, ldns_rdf *origin,
651             ldns_rdf **prev)
652             {
653 55           return ldns_rr_new_frm_str_internal(newrr,
654             str,
655             default_ttl,
656             origin,
657             prev,
658             false);
659             }
660              
661             ldns_status
662 0           ldns_rr_new_question_frm_str(ldns_rr **newrr, const char *str,
663             ldns_rdf *origin, ldns_rdf **prev)
664             {
665 0           return ldns_rr_new_frm_str_internal(newrr,
666             str,
667             0,
668             origin,
669             prev,
670             true);
671             }
672              
673             /* Strip whitespace from the start and the end of . */
674             static char *
675 19           ldns_strip_ws(char *line)
676             {
677 19           char *s = line, *e;
678              
679 34 50         for (s = line; *s && isspace(*s); s++)
    100          
680             ;
681              
682 30 100         for (e = strchr(s, 0); e > s+2 && isspace(e[-1]) && e[-2] != '\\'; e--)
    100          
    50          
683             ;
684 19           *e = 0;
685              
686 19           return s;
687             }
688              
689             ldns_status
690 0           ldns_rr_new_frm_fp(ldns_rr **newrr, FILE *fp, uint32_t *ttl, ldns_rdf **origin, ldns_rdf **prev)
691             {
692 0           return ldns_rr_new_frm_fp_l(newrr, fp, ttl, origin, prev, NULL);
693             }
694              
695             ldns_status
696 19           ldns_rr_new_frm_fp_l(ldns_rr **newrr, FILE *fp, uint32_t *default_ttl, ldns_rdf **origin, ldns_rdf **prev, int *line_nr)
697             {
698             char *line;
699             const char *endptr; /* unused */
700             ldns_rr *rr;
701             uint32_t ttl;
702             ldns_rdf *tmp;
703             ldns_status s;
704             ssize_t size;
705              
706 19 50         if (default_ttl) {
707 19           ttl = *default_ttl;
708             } else {
709 0           ttl = 0;
710             }
711              
712 19           line = LDNS_XMALLOC(char, LDNS_MAX_LINELEN + 1);
713 19 50         if (!line) {
714 0           return LDNS_STATUS_MEM_ERR;
715             }
716              
717             /* read an entire line in from the file */
718 19 50         if ((size = ldns_fget_token_l(fp, line, LDNS_PARSE_SKIP_SPACE, LDNS_MAX_LINELEN, line_nr)) == -1) {
719 0           LDNS_FREE(line);
720             /* if last line was empty, we are now at feof, which is not
721             * always a parse error (happens when for instance last line
722             * was a comment)
723             */
724 0           return LDNS_STATUS_SYNTAX_ERR;
725             }
726              
727             /* we can have the situation, where we've read ok, but still got
728             * no bytes to play with, in this case size is 0
729             */
730 19 50         if (size == 0) {
731 0           LDNS_FREE(line);
732 0           return LDNS_STATUS_SYNTAX_EMPTY;
733             }
734              
735 19 100         if (strncmp(line, "$ORIGIN", 7) == 0 && isspace(line[7])) {
    50          
736 2 50         if (*origin) {
737 2           ldns_rdf_deep_free(*origin);
738 2           *origin = NULL;
739             }
740 2           tmp = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME,
741 2           ldns_strip_ws(line + 8));
742 2 50         if (!tmp) {
743             /* could not parse what next to $ORIGIN */
744 0           LDNS_FREE(line);
745 0           return LDNS_STATUS_SYNTAX_DNAME_ERR;
746             }
747 2           *origin = tmp;
748 2           s = LDNS_STATUS_SYNTAX_ORIGIN;
749 17 100         } else if (strncmp(line, "$TTL", 4) == 0 && isspace(line[4])) {
    50          
750 1 50         if (default_ttl) {
751 1           *default_ttl = ldns_str2period(
752 1           ldns_strip_ws(line + 5), &endptr);
753             }
754 1           s = LDNS_STATUS_SYNTAX_TTL;
755 16 50         } else if (strncmp(line, "$INCLUDE", 8) == 0) {
756 0           s = LDNS_STATUS_SYNTAX_INCLUDE;
757 16 50         } else if (!*ldns_strip_ws(line)) {
758 0           LDNS_FREE(line);
759 0           return LDNS_STATUS_SYNTAX_EMPTY;
760             } else {
761 16 50         if (origin && *origin) {
    50          
762 16           s = ldns_rr_new_frm_str(&rr, (const char*) line, ttl, *origin, prev);
763             } else {
764 0           s = ldns_rr_new_frm_str(&rr, (const char*) line, ttl, NULL, prev);
765             }
766             }
767 19           LDNS_FREE(line);
768 19 100         if (s == LDNS_STATUS_OK) {
769 16 50         if (newrr) {
770 16           *newrr = rr;
771             } else {
772             /* Just testing if it would parse? */
773 0           ldns_rr_free(rr);
774             }
775             }
776 19           return s;
777             }
778              
779             void
780 1290           ldns_rr_set_owner(ldns_rr *rr, ldns_rdf *owner)
781             {
782 1290           rr->_owner = owner;
783 1290           }
784              
785             void
786 1277           ldns_rr_set_question(ldns_rr *rr, bool question)
787             {
788 1277           rr->_rr_question = question;
789 1277           }
790              
791             void
792 1253           ldns_rr_set_ttl(ldns_rr *rr, uint32_t ttl)
793             {
794 1253           rr->_ttl = ttl;
795 1253           }
796              
797             void
798 2111           ldns_rr_set_rd_count(ldns_rr *rr, size_t count)
799             {
800 2111           rr->_rd_count = count;
801 2111           }
802              
803             void
804 645           ldns_rr_set_type(ldns_rr *rr, ldns_rr_type rr_type)
805             {
806 645           rr->_rr_type = rr_type;
807 645           }
808              
809             void
810 1290           ldns_rr_set_class(ldns_rr *rr, ldns_rr_class rr_class)
811             {
812 1290           rr->_rr_class = rr_class;
813 1290           }
814              
815             ldns_rdf *
816 0           ldns_rr_set_rdf(ldns_rr *rr, const ldns_rdf *f, size_t position)
817             {
818             size_t rd_count;
819             ldns_rdf *pop;
820              
821 0           rd_count = ldns_rr_rd_count(rr);
822 0 0         if (position < rd_count) {
823             /* dicard the old one */
824 0           pop = rr->_rdata_fields[position];
825 0           rr->_rdata_fields[position] = (ldns_rdf*)f;
826 0           return pop;
827             } else {
828 0           return NULL;
829             }
830             }
831              
832             bool
833 1466           ldns_rr_push_rdf(ldns_rr *rr, const ldns_rdf *f)
834             {
835             size_t rd_count;
836             ldns_rdf **rdata_fields;
837              
838 1466           rd_count = ldns_rr_rd_count(rr);
839              
840             /* grow the array */
841 1466           rdata_fields = LDNS_XREALLOC(
842             rr->_rdata_fields, ldns_rdf *, rd_count + 1);
843 1466 50         if (!rdata_fields) {
844 0           return false;
845             }
846              
847             /* add the new member */
848 1466           rr->_rdata_fields = rdata_fields;
849 1466           rr->_rdata_fields[rd_count] = (ldns_rdf*)f;
850              
851 1466           ldns_rr_set_rd_count(rr, rd_count + 1);
852 1466           return true;
853             }
854              
855             ldns_rdf *
856 0           ldns_rr_pop_rdf(ldns_rr *rr)
857             {
858             size_t rd_count;
859             ldns_rdf *pop;
860             ldns_rdf** newrd;
861              
862 0           rd_count = ldns_rr_rd_count(rr);
863              
864 0 0         if (rd_count == 0) {
865 0           return NULL;
866             }
867              
868 0           pop = rr->_rdata_fields[rd_count - 1];
869              
870             /* try to shrink the array */
871 0 0         if(rd_count > 1) {
872 0           newrd = LDNS_XREALLOC(
873             rr->_rdata_fields, ldns_rdf *, rd_count - 1);
874 0 0         if(newrd)
875 0           rr->_rdata_fields = newrd;
876             } else {
877 0           LDNS_FREE(rr->_rdata_fields);
878             }
879              
880 0           ldns_rr_set_rd_count(rr, rd_count - 1);
881 0           return pop;
882             }
883              
884             ldns_rdf *
885 3444           ldns_rr_rdf(const ldns_rr *rr, size_t nr)
886             {
887 3444 50         if (rr && nr < ldns_rr_rd_count(rr)) {
    100          
888 3441           return rr->_rdata_fields[nr];
889             } else {
890 3           return NULL;
891             }
892             }
893              
894             ldns_rdf *
895 2213           ldns_rr_owner(const ldns_rr *rr)
896             {
897 2213           return rr->_owner;
898             }
899              
900             bool
901 287           ldns_rr_is_question(const ldns_rr *rr)
902             {
903 287           return rr->_rr_question;
904             }
905              
906             uint32_t
907 334           ldns_rr_ttl(const ldns_rr *rr)
908             {
909 334           return rr->_ttl;
910             }
911              
912             size_t
913 8698           ldns_rr_rd_count(const ldns_rr *rr)
914             {
915 8698           return rr->_rd_count;
916             }
917              
918             ldns_rr_type
919 1141           ldns_rr_get_type(const ldns_rr *rr)
920             {
921 1141           return rr->_rr_type;
922             }
923              
924             ldns_rr_class
925 391           ldns_rr_get_class(const ldns_rr *rr)
926             {
927 391           return rr->_rr_class;
928             }
929              
930             /* rr_lists */
931              
932             size_t
933 2831           ldns_rr_list_rr_count(const ldns_rr_list *rr_list)
934             {
935 2831 50         if (rr_list) {
936 2831           return rr_list->_rr_count;
937             } else {
938 0           return 0;
939             }
940             }
941              
942             ldns_rr *
943 0           ldns_rr_list_set_rr(ldns_rr_list *rr_list, const ldns_rr *r, size_t count)
944             {
945             ldns_rr *old;
946              
947 0 0         if (count > ldns_rr_list_rr_count(rr_list)) {
948 0           return NULL;
949             }
950              
951 0           old = ldns_rr_list_rr(rr_list, count);
952              
953             /* overwrite old's pointer */
954 0           rr_list->_rrs[count] = (ldns_rr*)r;
955 0           return old;
956             }
957              
958             void
959 532           ldns_rr_list_set_rr_count(ldns_rr_list *rr_list, size_t count)
960             {
961             assert(count <= rr_list->_rr_capacity);
962 532           rr_list->_rr_count = count;
963 532           }
964              
965             ldns_rr *
966 855           ldns_rr_list_rr(const ldns_rr_list *rr_list, size_t nr)
967             {
968 855 50         if (nr < ldns_rr_list_rr_count(rr_list)) {
969 855           return rr_list->_rrs[nr];
970             } else {
971 0           return NULL;
972             }
973             }
974              
975             ldns_rr_list *
976 424           ldns_rr_list_new(void)
977             {
978 424           ldns_rr_list *rr_list = LDNS_MALLOC(ldns_rr_list);
979 424 50         if(!rr_list) return NULL;
980 424           rr_list->_rr_count = 0;
981 424           rr_list->_rr_capacity = 0;
982 424           rr_list->_rrs = NULL;
983 424           return rr_list;
984             }
985              
986             void
987 30           ldns_rr_list_free(ldns_rr_list *rr_list)
988             {
989 30 50         if (rr_list) {
990 30           LDNS_FREE(rr_list->_rrs);
991 30           LDNS_FREE(rr_list);
992             }
993 30           }
994              
995             void
996 394           ldns_rr_list_deep_free(ldns_rr_list *rr_list)
997             {
998             size_t i;
999              
1000 394 50         if (rr_list) {
1001 893 100         for (i=0; i < ldns_rr_list_rr_count(rr_list); i++) {
1002 499           ldns_rr_free(ldns_rr_list_rr(rr_list, i));
1003             }
1004 394           LDNS_FREE(rr_list->_rrs);
1005 394           LDNS_FREE(rr_list);
1006             }
1007 394           }
1008              
1009              
1010             /* add right to left. So we modify *left! */
1011             bool
1012 4           ldns_rr_list_cat(ldns_rr_list *left, ldns_rr_list *right)
1013             {
1014             size_t r_rr_count;
1015             size_t i;
1016              
1017 4 50         if (!left) {
1018 0           return false;
1019             }
1020              
1021 4 50         if (right) {
1022 4           r_rr_count = ldns_rr_list_rr_count(right);
1023             } else {
1024 0           r_rr_count = 0;
1025             }
1026              
1027             /* push right to left */
1028 8 100         for(i = 0; i < r_rr_count; i++) {
1029 4           ldns_rr_list_push_rr(left, ldns_rr_list_rr(right, i));
1030             }
1031 4           return true;
1032             }
1033              
1034             ldns_rr_list *
1035 6           ldns_rr_list_cat_clone(ldns_rr_list *left, ldns_rr_list *right)
1036             {
1037             size_t l_rr_count;
1038             size_t r_rr_count;
1039             size_t i;
1040             ldns_rr_list *cat;
1041              
1042 6 50         if (left) {
1043 6           l_rr_count = ldns_rr_list_rr_count(left);
1044             } else {
1045 0           return ldns_rr_list_clone(right);
1046             }
1047              
1048 6 50         if (right) {
1049 6           r_rr_count = ldns_rr_list_rr_count(right);
1050             } else {
1051 0           r_rr_count = 0;
1052             }
1053              
1054 6           cat = ldns_rr_list_new();
1055              
1056 6 50         if (!cat) {
1057 0           return NULL;
1058             }
1059              
1060             /* left */
1061 10 100         for(i = 0; i < l_rr_count; i++) {
1062 4           ldns_rr_list_push_rr(cat,
1063 4           ldns_rr_clone(ldns_rr_list_rr(left, i)));
1064             }
1065             /* right */
1066 8 100         for(i = 0; i < r_rr_count; i++) {
1067 2           ldns_rr_list_push_rr(cat,
1068 2           ldns_rr_clone(ldns_rr_list_rr(right, i)));
1069             }
1070 6           return cat;
1071             }
1072              
1073             ldns_rr_list *
1074 0           ldns_rr_list_subtype_by_rdf(ldns_rr_list *l, ldns_rdf *r, size_t pos)
1075             {
1076             size_t i;
1077             ldns_rr_list *subtyped;
1078             ldns_rdf *list_rdf;
1079              
1080 0           subtyped = ldns_rr_list_new();
1081              
1082 0 0         for(i = 0; i < ldns_rr_list_rr_count(l); i++) {
1083 0           list_rdf = ldns_rr_rdf(
1084 0           ldns_rr_list_rr(l, i),
1085             pos);
1086 0 0         if (!list_rdf) {
1087             /* pos is too large or any other error */
1088 0           ldns_rr_list_deep_free(subtyped);
1089 0           return NULL;
1090             }
1091              
1092 0 0         if (ldns_rdf_compare(list_rdf, r) == 0) {
1093             /* a match */
1094 0           ldns_rr_list_push_rr(subtyped,
1095 0           ldns_rr_clone(ldns_rr_list_rr(l, i)));
1096             }
1097             }
1098              
1099 0 0         if (ldns_rr_list_rr_count(subtyped) > 0) {
1100 0           return subtyped;
1101             } else {
1102 0           ldns_rr_list_free(subtyped);
1103 0           return NULL;
1104             }
1105             }
1106              
1107             bool
1108 528           ldns_rr_list_push_rr(ldns_rr_list *rr_list, const ldns_rr *rr)
1109             {
1110             size_t rr_count;
1111             size_t cap;
1112              
1113 528           rr_count = ldns_rr_list_rr_count(rr_list);
1114 528           cap = rr_list->_rr_capacity;
1115              
1116             /* grow the array */
1117 528 100         if(rr_count+1 > cap) {
1118             ldns_rr **rrs;
1119              
1120 206 100         if(cap == 0)
1121 177           cap = LDNS_RRLIST_INIT; /* initial list size */
1122 29           else cap *= 2;
1123 206           rrs = LDNS_XREALLOC(rr_list->_rrs, ldns_rr *, cap);
1124 206 50         if (!rrs) {
1125 0           return false;
1126             }
1127 206           rr_list->_rrs = rrs;
1128 206           rr_list->_rr_capacity = cap;
1129             }
1130              
1131             /* add the new member */
1132 528           rr_list->_rrs[rr_count] = (ldns_rr*)rr;
1133              
1134 528           ldns_rr_list_set_rr_count(rr_list, rr_count + 1);
1135 528           return true;
1136             }
1137              
1138             bool
1139 0           ldns_rr_list_push_rr_list(ldns_rr_list *rr_list, const ldns_rr_list *push_list)
1140             {
1141             size_t i;
1142              
1143 0 0         for(i = 0; i < ldns_rr_list_rr_count(push_list); i++) {
1144 0 0         if (!ldns_rr_list_push_rr(rr_list,
1145 0           ldns_rr_list_rr(push_list, i))) {
1146 0           return false;
1147             }
1148             }
1149 0           return true;
1150             }
1151              
1152             ldns_rr *
1153 6           ldns_rr_list_pop_rr(ldns_rr_list *rr_list)
1154             {
1155             size_t rr_count;
1156             size_t cap;
1157             ldns_rr *pop;
1158              
1159 6           rr_count = ldns_rr_list_rr_count(rr_list);
1160              
1161 6 100         if (rr_count == 0) {
1162 2           return NULL;
1163             }
1164              
1165 4           cap = rr_list->_rr_capacity;
1166 4           pop = ldns_rr_list_rr(rr_list, rr_count - 1);
1167              
1168             /* shrink the array */
1169 4 50         if(cap > LDNS_RRLIST_INIT && rr_count-1 <= cap/2) {
    0          
1170             ldns_rr** a;
1171 0           cap /= 2;
1172 0           a = LDNS_XREALLOC(rr_list->_rrs, ldns_rr *, cap);
1173 0 0         if(a) {
1174 0           rr_list->_rrs = a;
1175 0           rr_list->_rr_capacity = cap;
1176             }
1177             }
1178              
1179 4           ldns_rr_list_set_rr_count(rr_list, rr_count - 1);
1180              
1181 4           return pop;
1182             }
1183              
1184             ldns_rr_list *
1185 0           ldns_rr_list_pop_rr_list(ldns_rr_list *rr_list, size_t howmany)
1186             {
1187             /* pop a number of rr's and put them in a rr_list */
1188             ldns_rr_list *popped;
1189             ldns_rr *p;
1190 0           size_t i = howmany;
1191              
1192 0           popped = ldns_rr_list_new();
1193              
1194 0 0         if (!popped) {
1195 0           return NULL;
1196             }
1197              
1198              
1199 0 0         while(i > 0 &&
    0          
1200             (p = ldns_rr_list_pop_rr(rr_list)) != NULL) {
1201 0           ldns_rr_list_push_rr(popped, p);
1202 0           i--;
1203             }
1204              
1205 0 0         if (i == howmany) { /* so i <= 0 */
1206 0           ldns_rr_list_free(popped);
1207 0           return NULL;
1208             } else {
1209 0           return popped;
1210             }
1211             }
1212              
1213              
1214             bool
1215 3           ldns_rr_list_contains_rr(const ldns_rr_list *rr_list, ldns_rr *rr)
1216             {
1217             size_t i;
1218              
1219 3 50         if (!rr_list || !rr || ldns_rr_list_rr_count(rr_list) == 0) {
    50          
    100          
1220 1           return false;
1221             }
1222              
1223 3 100         for (i = 0; i < ldns_rr_list_rr_count(rr_list); i++) {
1224 2 50         if (rr == ldns_rr_list_rr(rr_list, i)) {
1225 0           return true;
1226 2 100         } else if (ldns_rr_compare(rr, ldns_rr_list_rr(rr_list, i)) == 0) {
1227 1           return true;
1228             }
1229             }
1230 1           return false;
1231             }
1232              
1233             bool
1234 3           ldns_is_rrset(ldns_rr_list *rr_list)
1235             {
1236             ldns_rr_type t;
1237             ldns_rr_class c;
1238             ldns_rdf *o;
1239             ldns_rr *tmp;
1240             size_t i;
1241              
1242 3 50         if (!rr_list || ldns_rr_list_rr_count(rr_list) == 0) {
    100          
1243 1           return false;
1244             }
1245              
1246 2           tmp = ldns_rr_list_rr(rr_list, 0);
1247              
1248 2           t = ldns_rr_get_type(tmp);
1249 2           c = ldns_rr_get_class(tmp);
1250 2           o = ldns_rr_owner(tmp);
1251              
1252             /* compare these with the rest of the rr_list, start with 1 */
1253 4 100         for (i = 1; i < ldns_rr_list_rr_count(rr_list); i++) {
1254 3           tmp = ldns_rr_list_rr(rr_list, i);
1255 3 50         if (t != ldns_rr_get_type(tmp)) {
1256 0           return false;
1257             }
1258 3 50         if (c != ldns_rr_get_class(tmp)) {
1259 0           return false;
1260             }
1261 3 100         if (ldns_rdf_compare(o, ldns_rr_owner(tmp)) != 0) {
1262 1           return false;
1263             }
1264             }
1265 1           return true;
1266             }
1267              
1268             bool
1269 0           ldns_rr_set_push_rr(ldns_rr_list *rr_list, ldns_rr *rr)
1270             {
1271             size_t rr_count;
1272             size_t i;
1273             ldns_rr *last;
1274              
1275             assert(rr != NULL);
1276              
1277 0           rr_count = ldns_rr_list_rr_count(rr_list);
1278              
1279 0 0         if (rr_count == 0) {
1280             /* nothing there, so checking it is
1281             * not needed */
1282 0           return ldns_rr_list_push_rr(rr_list, rr);
1283             } else {
1284             /* check with the final rr in the rr_list */
1285 0           last = ldns_rr_list_rr(rr_list, rr_count - 1);
1286              
1287 0 0         if (ldns_rr_get_class(last) != ldns_rr_get_class(rr)) {
1288 0           return false;
1289             }
1290 0 0         if (ldns_rr_get_type(last) != ldns_rr_get_type(rr)) {
1291 0           return false;
1292             }
1293             /* only check if not equal to RRSIG */
1294 0 0         if (ldns_rr_get_type(rr) != LDNS_RR_TYPE_RRSIG) {
1295 0 0         if (ldns_rr_ttl(last) != ldns_rr_ttl(rr)) {
1296 0           return false;
1297             }
1298             }
1299 0 0         if (ldns_rdf_compare(ldns_rr_owner(last),
1300 0           ldns_rr_owner(rr)) != 0) {
1301 0           return false;
1302             }
1303             /* ok, still alive - check if the rr already
1304             * exists - if so, dont' add it */
1305 0 0         for(i = 0; i < rr_count; i++) {
1306 0 0         if(ldns_rr_compare(
1307 0           ldns_rr_list_rr(rr_list, i), rr) == 0) {
1308 0           return false;
1309             }
1310             }
1311             /* it's safe, push it */
1312 0           return ldns_rr_list_push_rr(rr_list, rr);
1313             }
1314             }
1315              
1316             ldns_rr *
1317 0           ldns_rr_set_pop_rr(ldns_rr_list *rr_list)
1318             {
1319 0           return ldns_rr_list_pop_rr(rr_list);
1320             }
1321              
1322             ldns_rr_list *
1323 0           ldns_rr_list_pop_rrset(ldns_rr_list *rr_list)
1324             {
1325             ldns_rr_list *rrset;
1326 0           ldns_rr *last_rr = NULL;
1327             ldns_rr *next_rr;
1328              
1329 0 0         if (!rr_list) {
1330 0           return NULL;
1331             }
1332              
1333 0           rrset = ldns_rr_list_new();
1334 0 0         if (!last_rr) {
1335 0           last_rr = ldns_rr_list_pop_rr(rr_list);
1336 0 0         if (!last_rr) {
1337 0           ldns_rr_list_free(rrset);
1338 0           return NULL;
1339             } else {
1340 0           ldns_rr_list_push_rr(rrset, last_rr);
1341             }
1342             }
1343              
1344 0 0         if (ldns_rr_list_rr_count(rr_list) > 0) {
1345 0           next_rr = ldns_rr_list_rr(rr_list, ldns_rr_list_rr_count(rr_list) - 1);
1346             } else {
1347 0           next_rr = NULL;
1348             }
1349              
1350 0 0         while (next_rr) {
1351 0 0         if (
1352 0           ldns_rdf_compare(ldns_rr_owner(next_rr),
1353 0           ldns_rr_owner(last_rr)) == 0
1354 0 0         &&
1355 0           ldns_rr_get_type(next_rr) == ldns_rr_get_type(last_rr)
1356 0 0         &&
1357 0           ldns_rr_get_class(next_rr) == ldns_rr_get_class(last_rr)
1358             ) {
1359 0           ldns_rr_list_push_rr(rrset, ldns_rr_list_pop_rr(rr_list));
1360 0 0         if (ldns_rr_list_rr_count(rr_list) > 0) {
1361 0           last_rr = next_rr;
1362 0           next_rr = ldns_rr_list_rr(rr_list, ldns_rr_list_rr_count(rr_list) - 1);
1363             } else {
1364 0           next_rr = NULL;
1365             }
1366             } else {
1367 0           next_rr = NULL;
1368             }
1369             }
1370              
1371 0           return rrset;
1372             }
1373              
1374             ldns_rr *
1375 291           ldns_rr_clone(const ldns_rr *rr)
1376             {
1377             size_t i;
1378             ldns_rr *new_rr;
1379              
1380 291 100         if (!rr) {
1381 17           return NULL;
1382             }
1383              
1384 274           new_rr = ldns_rr_new();
1385 274 50         if (!new_rr) {
1386 0           return NULL;
1387             }
1388 274 50         if (ldns_rr_owner(rr)) {
1389 274           ldns_rr_set_owner(new_rr, ldns_rdf_clone(ldns_rr_owner(rr)));
1390             }
1391 274           ldns_rr_set_ttl(new_rr, ldns_rr_ttl(rr));
1392 274           ldns_rr_set_type(new_rr, ldns_rr_get_type(rr));
1393 274           ldns_rr_set_class(new_rr, ldns_rr_get_class(rr));
1394 274           ldns_rr_set_question(new_rr, ldns_rr_is_question(rr));
1395              
1396 915 100         for (i = 0; i < ldns_rr_rd_count(rr); i++) {
1397 641 50         if (ldns_rr_rdf(rr,i)) {
1398 641           ldns_rr_push_rdf(new_rr, ldns_rdf_clone(ldns_rr_rdf(rr, i)));
1399             }
1400             }
1401              
1402 274           return new_rr;
1403             }
1404              
1405             ldns_rr_list *
1406 79           ldns_rr_list_clone(const ldns_rr_list *rrlist)
1407             {
1408             size_t i;
1409             ldns_rr_list *new_list;
1410             ldns_rr *r;
1411              
1412 79 50         if (!rrlist) {
1413 0           return NULL;
1414             }
1415              
1416 79           new_list = ldns_rr_list_new();
1417 79 50         if (!new_list) {
1418 0           return NULL;
1419             }
1420 231 100         for (i = 0; i < ldns_rr_list_rr_count(rrlist); i++) {
1421 152           r = ldns_rr_clone(
1422 152           ldns_rr_list_rr(rrlist, i)
1423             );
1424 152 50         if (!r) {
1425             /* huh, failure in cloning */
1426 0           ldns_rr_list_deep_free(new_list);
1427 0           return NULL;
1428             }
1429 152           ldns_rr_list_push_rr(new_list, r);
1430             }
1431 79           return new_list;
1432             }
1433              
1434              
1435             static int
1436 0           qsort_schwartz_rr_compare(const void *a, const void *b)
1437             {
1438 0           int result = 0;
1439             ldns_rr *rr1, *rr2;
1440             ldns_buffer *rr1_buf, *rr2_buf;
1441 0           struct ldns_schwartzian_compare_struct *sa = *(struct ldns_schwartzian_compare_struct **) a;
1442 0           struct ldns_schwartzian_compare_struct *sb = *(struct ldns_schwartzian_compare_struct **) b;
1443             /* if we are doing 2wire, we need to do lowercasing on the dname (and maybe on the rdata)
1444             * this must be done for comparison only, so we need to have a temp var for both buffers,
1445             * which is only used when the transformed object value isn't there yet
1446             */
1447             ldns_rr *canonical_a, *canonical_b;
1448              
1449 0           rr1 = (ldns_rr *) sa->original_object;
1450 0           rr2 = (ldns_rr *) sb->original_object;
1451              
1452 0           result = ldns_rr_compare_no_rdata(rr1, rr2);
1453              
1454 0 0         if (result == 0) {
1455 0 0         if (!sa->transformed_object) {
1456 0           canonical_a = ldns_rr_clone(sa->original_object);
1457 0           ldns_rr2canonical(canonical_a);
1458 0           sa->transformed_object = ldns_buffer_new(ldns_rr_uncompressed_size(canonical_a));
1459 0 0         if (ldns_rr2buffer_wire(sa->transformed_object, canonical_a, LDNS_SECTION_ANY) != LDNS_STATUS_OK) {
1460 0           ldns_buffer_free((ldns_buffer *)sa->transformed_object);
1461 0           sa->transformed_object = NULL;
1462 0           ldns_rr_free(canonical_a);
1463 0           return 0;
1464             }
1465 0           ldns_rr_free(canonical_a);
1466             }
1467 0 0         if (!sb->transformed_object) {
1468 0           canonical_b = ldns_rr_clone(sb->original_object);
1469 0           ldns_rr2canonical(canonical_b);
1470 0           sb->transformed_object = ldns_buffer_new(ldns_rr_uncompressed_size(canonical_b));
1471 0 0         if (ldns_rr2buffer_wire(sb->transformed_object, canonical_b, LDNS_SECTION_ANY) != LDNS_STATUS_OK) {
1472 0           ldns_buffer_free((ldns_buffer *)sa->transformed_object);
1473 0           ldns_buffer_free((ldns_buffer *)sb->transformed_object);
1474 0           sa->transformed_object = NULL;
1475 0           sb->transformed_object = NULL;
1476 0           ldns_rr_free(canonical_b);
1477 0           return 0;
1478             }
1479 0           ldns_rr_free(canonical_b);
1480             }
1481 0           rr1_buf = (ldns_buffer *) sa->transformed_object;
1482 0           rr2_buf = (ldns_buffer *) sb->transformed_object;
1483              
1484 0           result = ldns_rr_compare_wire(rr1_buf, rr2_buf);
1485             }
1486              
1487 0           return result;
1488             }
1489              
1490             void
1491 5           ldns_rr_list_sort(ldns_rr_list *unsorted)
1492             {
1493             struct ldns_schwartzian_compare_struct **sortables;
1494             size_t item_count;
1495             size_t i;
1496              
1497 5 50         if (unsorted) {
1498 5           item_count = ldns_rr_list_rr_count(unsorted);
1499              
1500 5           sortables = LDNS_XMALLOC(struct ldns_schwartzian_compare_struct *,
1501             item_count);
1502 5 50         if(!sortables) return; /* no way to return error */
1503 10 100         for (i = 0; i < item_count; i++) {
1504 5           sortables[i] = LDNS_XMALLOC(struct ldns_schwartzian_compare_struct, 1);
1505 5 50         if(!sortables[i]) {
1506             /* free the allocated parts */
1507 0 0         while(i>0) {
1508 0           i--;
1509 0           LDNS_FREE(sortables[i]);
1510             }
1511             /* no way to return error */
1512 0           LDNS_FREE(sortables);
1513 0           return;
1514             }
1515 5           sortables[i]->original_object = ldns_rr_list_rr(unsorted, i);
1516 5           sortables[i]->transformed_object = NULL;
1517             }
1518 5           qsort(sortables,
1519             item_count,
1520             sizeof(struct ldns_schwartzian_compare_struct *),
1521             qsort_schwartz_rr_compare);
1522 10 100         for (i = 0; i < item_count; i++) {
1523 5           unsorted->_rrs[i] = sortables[i]->original_object;
1524 5 50         if (sortables[i]->transformed_object) {
1525 0           ldns_buffer_free(sortables[i]->transformed_object);
1526             }
1527 5           LDNS_FREE(sortables[i]);
1528             }
1529 5           LDNS_FREE(sortables);
1530             }
1531             }
1532              
1533             int
1534 16           ldns_rr_compare_no_rdata(const ldns_rr *rr1, const ldns_rr *rr2)
1535             {
1536             size_t rr1_len;
1537             size_t rr2_len;
1538             size_t offset;
1539              
1540             assert(rr1 != NULL);
1541             assert(rr2 != NULL);
1542              
1543 16           rr1_len = ldns_rr_uncompressed_size(rr1);
1544 16           rr2_len = ldns_rr_uncompressed_size(rr2);
1545              
1546 16 100         if (ldns_dname_compare(ldns_rr_owner(rr1), ldns_rr_owner(rr2)) < 0) {
1547 2           return -1;
1548 14 100         } else if (ldns_dname_compare(ldns_rr_owner(rr1), ldns_rr_owner(rr2)) > 0) {
1549 2           return 1;
1550             }
1551              
1552             /* should return -1 if rr1 comes before rr2, so need to do rr1 - rr2, not rr2 - rr1 */
1553 12 50         if (ldns_rr_get_class(rr1) != ldns_rr_get_class(rr2)) {
1554 0           return ldns_rr_get_class(rr1) - ldns_rr_get_class(rr2);
1555             }
1556              
1557             /* should return -1 if rr1 comes before rr2, so need to do rr1 - rr2, not rr2 - rr1 */
1558 12 100         if (ldns_rr_get_type(rr1) != ldns_rr_get_type(rr2)) {
1559 3           return ldns_rr_get_type(rr1) - ldns_rr_get_type(rr2);
1560             }
1561              
1562             /* offset is the owername length + ttl + type + class + rdlen == start of wire format rdata */
1563 9           offset = ldns_rdf_size(ldns_rr_owner(rr1)) + 4 + 2 + 2 + 2;
1564             /* if either record doesn't have any RDATA... */
1565 9 50         if (offset > rr1_len || offset > rr2_len) {
    50          
1566 0 0         if (rr1_len == rr2_len) {
1567 0           return 0;
1568             }
1569 0           return ((int) rr2_len - (int) rr1_len);
1570             }
1571              
1572 9           return 0;
1573             }
1574              
1575 9           int ldns_rr_compare_wire(ldns_buffer *rr1_buf, ldns_buffer *rr2_buf)
1576             {
1577             size_t rr1_len, rr2_len, min_len, i, offset;
1578              
1579 9           rr1_len = ldns_buffer_capacity(rr1_buf);
1580 9           rr2_len = ldns_buffer_capacity(rr2_buf);
1581              
1582             /* jump past dname (checked in earlier part)
1583             * and especially past TTL */
1584 9           offset = 0;
1585 26 50         while (offset < rr1_len && *ldns_buffer_at(rr1_buf, offset) != 0) {
    100          
1586 17           offset += *ldns_buffer_at(rr1_buf, offset) + 1;
1587             }
1588             /* jump to rdata section (PAST the rdata length field, otherwise
1589             rrs with different lengths might be sorted erroneously */
1590 9           offset += 11;
1591 9           min_len = (rr1_len < rr2_len) ? rr1_len : rr2_len;
1592             /* Compare RRs RDATA byte for byte. */
1593 307 100         for(i = offset; i < min_len; i++) {
1594 298 50         if (*ldns_buffer_at(rr1_buf,i) < *ldns_buffer_at(rr2_buf,i)) {
1595 0           return -1;
1596 298 50         } else if (*ldns_buffer_at(rr1_buf,i) > *ldns_buffer_at(rr2_buf,i)) {
1597 0           return +1;
1598             }
1599             }
1600              
1601             /* If both RDATAs are the same up to min_len, then the shorter one sorts first. */
1602 9 50         if (rr1_len < rr2_len) {
1603 0           return -1;
1604 9 50         } else if (rr1_len > rr2_len) {
1605 0           return +1;
1606             }
1607             /* The RDATAs are equal. */
1608 9           return 0;
1609              
1610             }
1611              
1612             int
1613 16           ldns_rr_compare(const ldns_rr *rr1, const ldns_rr *rr2)
1614             {
1615             int result;
1616             size_t rr1_len, rr2_len;
1617              
1618             ldns_buffer *rr1_buf;
1619             ldns_buffer *rr2_buf;
1620              
1621 16           result = ldns_rr_compare_no_rdata(rr1, rr2);
1622 16 100         if (result == 0) {
1623 9           rr1_len = ldns_rr_uncompressed_size(rr1);
1624 9           rr2_len = ldns_rr_uncompressed_size(rr2);
1625              
1626 9           rr1_buf = ldns_buffer_new(rr1_len);
1627 9           rr2_buf = ldns_buffer_new(rr2_len);
1628              
1629 9 50         if (ldns_rr2buffer_wire_canonical(rr1_buf,
1630             rr1,
1631             LDNS_SECTION_ANY)
1632             != LDNS_STATUS_OK) {
1633 0           ldns_buffer_free(rr1_buf);
1634 0           ldns_buffer_free(rr2_buf);
1635 0           return 0;
1636             }
1637 9 50         if (ldns_rr2buffer_wire_canonical(rr2_buf,
1638             rr2,
1639             LDNS_SECTION_ANY)
1640             != LDNS_STATUS_OK) {
1641 0           ldns_buffer_free(rr1_buf);
1642 0           ldns_buffer_free(rr2_buf);
1643 0           return 0;
1644             }
1645              
1646 9           result = ldns_rr_compare_wire(rr1_buf, rr2_buf);
1647              
1648 9           ldns_buffer_free(rr1_buf);
1649 9           ldns_buffer_free(rr2_buf);
1650             }
1651              
1652 16           return result;
1653             }
1654              
1655             /* convert dnskey to a ds with the given algorithm,
1656             * then compare the result with the given ds */
1657             static int
1658 6           ldns_rr_compare_ds_dnskey(ldns_rr *ds,
1659             ldns_rr *dnskey)
1660             {
1661             ldns_rr *ds_gen;
1662 6           bool result = false;
1663             ldns_hash algo;
1664              
1665 12 50         if (!dnskey || !ds ||
1666 12 50         ldns_rr_get_type(ds) != LDNS_RR_TYPE_DS ||
1667 6           ldns_rr_get_type(dnskey) != LDNS_RR_TYPE_DNSKEY) {
1668 0           return false;
1669             }
1670              
1671 6 50         if (ldns_rr_rdf(ds, 2) == NULL) {
1672 0           return false;
1673             }
1674 6           algo = ldns_rdf2native_int8(ldns_rr_rdf(ds, 2));
1675              
1676 6           ds_gen = ldns_key_rr2ds(dnskey, algo);
1677 6 50         if (ds_gen) {
1678 6           result = ldns_rr_compare(ds, ds_gen) == 0;
1679 6           ldns_rr_free(ds_gen);
1680             }
1681 6           return result;
1682             }
1683              
1684             bool
1685 8           ldns_rr_compare_ds(const ldns_rr *orr1, const ldns_rr *orr2)
1686             {
1687             bool result;
1688 8           ldns_rr *rr1 = ldns_rr_clone(orr1);
1689 8           ldns_rr *rr2 = ldns_rr_clone(orr2);
1690              
1691             /* set ttls to zero */
1692 8           ldns_rr_set_ttl(rr1, 0);
1693 8           ldns_rr_set_ttl(rr2, 0);
1694              
1695 16           if (ldns_rr_get_type(rr1) == LDNS_RR_TYPE_DS &&
1696 8           ldns_rr_get_type(rr2) == LDNS_RR_TYPE_DNSKEY) {
1697 6           result = ldns_rr_compare_ds_dnskey(rr1, rr2);
1698 2           } else if (ldns_rr_get_type(rr1) == LDNS_RR_TYPE_DNSKEY &&
1699 0           ldns_rr_get_type(rr2) == LDNS_RR_TYPE_DS) {
1700 0           result = ldns_rr_compare_ds_dnskey(rr2, rr1);
1701             } else {
1702 2           result = (ldns_rr_compare(rr1, rr2) == 0);
1703             }
1704              
1705 8           ldns_rr_free(rr1);
1706 8           ldns_rr_free(rr2);
1707              
1708 8           return result;
1709             }
1710              
1711             int
1712 0           ldns_rr_list_compare(const ldns_rr_list *rrl1, const ldns_rr_list *rrl2)
1713             {
1714 0           size_t i = 0;
1715             int rr_cmp;
1716              
1717             assert(rrl1 != NULL);
1718             assert(rrl2 != NULL);
1719              
1720 0 0         for (i = 0; i < ldns_rr_list_rr_count(rrl1) && i < ldns_rr_list_rr_count(rrl2); i++) {
    0          
1721 0           rr_cmp = ldns_rr_compare(ldns_rr_list_rr(rrl1, i), ldns_rr_list_rr(rrl2, i));
1722 0 0         if (rr_cmp != 0) {
1723 0           return rr_cmp;
1724             }
1725             }
1726              
1727 0           if (i == ldns_rr_list_rr_count(rrl1) &&
1728 0           i != ldns_rr_list_rr_count(rrl2)) {
1729 0           return 1;
1730 0           } else if (i == ldns_rr_list_rr_count(rrl2) &&
1731 0           i != ldns_rr_list_rr_count(rrl1)) {
1732 0           return -1;
1733             } else {
1734 0           return 0;
1735             }
1736             }
1737              
1738             size_t
1739 50           ldns_rr_uncompressed_size(const ldns_rr *r)
1740             {
1741             size_t rrsize;
1742             size_t i;
1743              
1744 50           rrsize = 0;
1745             /* add all the rdf sizes */
1746 208 100         for(i = 0; i < ldns_rr_rd_count(r); i++) {
1747 158           rrsize += ldns_rdf_size(ldns_rr_rdf(r, i));
1748             }
1749             /* ownername */
1750 50           rrsize += ldns_rdf_size(ldns_rr_owner(r));
1751 50           rrsize += LDNS_RR_OVERHEAD;
1752 50           return rrsize;
1753             }
1754              
1755             void
1756 7           ldns_rr2canonical(ldns_rr *rr)
1757             {
1758             uint16_t i;
1759              
1760 7 50         if (!rr) {
1761 0           return;
1762             }
1763              
1764 7           ldns_dname2canonical(ldns_rr_owner(rr));
1765              
1766             /*
1767             * lowercase the rdata dnames if the rr type is one
1768             * of the list in chapter 7 of RFC3597
1769             * Also added RRSIG, because a "Signer's Name" should be canonicalized
1770             * too. See dnssec-bis-updates-16. We can add it to this list because
1771             * the "Signer's Name" is the only dname type rdata field in a RRSIG.
1772             */
1773 7 100         switch(ldns_rr_get_type(rr)) {
1774             case LDNS_RR_TYPE_NS:
1775             case LDNS_RR_TYPE_MD:
1776             case LDNS_RR_TYPE_MF:
1777             case LDNS_RR_TYPE_CNAME:
1778             case LDNS_RR_TYPE_SOA:
1779             case LDNS_RR_TYPE_MB:
1780             case LDNS_RR_TYPE_MG:
1781             case LDNS_RR_TYPE_MR:
1782             case LDNS_RR_TYPE_PTR:
1783             case LDNS_RR_TYPE_MINFO:
1784             case LDNS_RR_TYPE_MX:
1785             case LDNS_RR_TYPE_RP:
1786             case LDNS_RR_TYPE_AFSDB:
1787             case LDNS_RR_TYPE_RT:
1788             case LDNS_RR_TYPE_SIG:
1789             case LDNS_RR_TYPE_PX:
1790             case LDNS_RR_TYPE_NXT:
1791             case LDNS_RR_TYPE_NAPTR:
1792             case LDNS_RR_TYPE_KX:
1793             case LDNS_RR_TYPE_SRV:
1794             case LDNS_RR_TYPE_DNAME:
1795             case LDNS_RR_TYPE_A6:
1796             case LDNS_RR_TYPE_RRSIG:
1797 40 100         for (i = 0; i < ldns_rr_rd_count(rr); i++) {
1798 35           ldns_dname2canonical(ldns_rr_rdf(rr, i));
1799             }
1800 5           return;
1801             default:
1802             /* do nothing */
1803 2           return;
1804             }
1805             }
1806              
1807             void
1808 0           ldns_rr_list2canonical(ldns_rr_list *rr_list)
1809             {
1810             size_t i;
1811 0 0         for (i = 0; i < ldns_rr_list_rr_count(rr_list); i++) {
1812 0           ldns_rr2canonical(ldns_rr_list_rr(rr_list, i));
1813             }
1814 0           }
1815              
1816             uint8_t
1817 0           ldns_rr_label_count(ldns_rr *rr)
1818             {
1819 0 0         if (!rr) {
1820 0           return 0;
1821             }
1822 0           return ldns_dname_label_count(
1823 0           ldns_rr_owner(rr));
1824             }
1825              
1826             /** \cond */
1827             static const ldns_rdf_type type_0_wireformat[] = { LDNS_RDF_TYPE_UNKNOWN };
1828             static const ldns_rdf_type type_a_wireformat[] = { LDNS_RDF_TYPE_A };
1829             static const ldns_rdf_type type_ns_wireformat[] = { LDNS_RDF_TYPE_DNAME };
1830             static const ldns_rdf_type type_md_wireformat[] = { LDNS_RDF_TYPE_DNAME };
1831             static const ldns_rdf_type type_mf_wireformat[] = { LDNS_RDF_TYPE_DNAME };
1832             static const ldns_rdf_type type_cname_wireformat[] = { LDNS_RDF_TYPE_DNAME };
1833             static const ldns_rdf_type type_soa_wireformat[] = {
1834             LDNS_RDF_TYPE_DNAME, LDNS_RDF_TYPE_DNAME, LDNS_RDF_TYPE_INT32,
1835             LDNS_RDF_TYPE_PERIOD, LDNS_RDF_TYPE_PERIOD, LDNS_RDF_TYPE_PERIOD,
1836             LDNS_RDF_TYPE_PERIOD
1837             };
1838             static const ldns_rdf_type type_mb_wireformat[] = { LDNS_RDF_TYPE_DNAME };
1839             static const ldns_rdf_type type_mg_wireformat[] = { LDNS_RDF_TYPE_DNAME };
1840             static const ldns_rdf_type type_mr_wireformat[] = { LDNS_RDF_TYPE_DNAME };
1841             static const ldns_rdf_type type_wks_wireformat[] = {
1842             LDNS_RDF_TYPE_A, LDNS_RDF_TYPE_WKS
1843             };
1844             static const ldns_rdf_type type_ptr_wireformat[] = { LDNS_RDF_TYPE_DNAME };
1845             static const ldns_rdf_type type_hinfo_wireformat[] = {
1846             LDNS_RDF_TYPE_STR, LDNS_RDF_TYPE_STR
1847             };
1848             static const ldns_rdf_type type_minfo_wireformat[] = {
1849             LDNS_RDF_TYPE_DNAME, LDNS_RDF_TYPE_DNAME
1850             };
1851             static const ldns_rdf_type type_mx_wireformat[] = {
1852             LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_DNAME
1853             };
1854             static const ldns_rdf_type type_rp_wireformat[] = {
1855             LDNS_RDF_TYPE_DNAME, LDNS_RDF_TYPE_DNAME
1856             };
1857             static const ldns_rdf_type type_afsdb_wireformat[] = {
1858             LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_DNAME
1859             };
1860             static const ldns_rdf_type type_x25_wireformat[] = { LDNS_RDF_TYPE_STR };
1861             static const ldns_rdf_type type_isdn_wireformat[] = {
1862             LDNS_RDF_TYPE_STR, LDNS_RDF_TYPE_STR
1863             };
1864             static const ldns_rdf_type type_rt_wireformat[] = {
1865             LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_DNAME
1866             };
1867             static const ldns_rdf_type type_nsap_wireformat[] = {
1868             LDNS_RDF_TYPE_NSAP
1869             };
1870             static const ldns_rdf_type type_nsap_ptr_wireformat[] = {
1871             LDNS_RDF_TYPE_STR
1872             };
1873             static const ldns_rdf_type type_sig_wireformat[] = {
1874             LDNS_RDF_TYPE_TYPE, LDNS_RDF_TYPE_ALG, LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_INT32,
1875             LDNS_RDF_TYPE_TIME, LDNS_RDF_TYPE_TIME, LDNS_RDF_TYPE_INT16,
1876             LDNS_RDF_TYPE_DNAME, LDNS_RDF_TYPE_B64
1877             };
1878             static const ldns_rdf_type type_key_wireformat[] = {
1879             LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_B64
1880             };
1881             static const ldns_rdf_type type_px_wireformat[] = {
1882             LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_DNAME, LDNS_RDF_TYPE_DNAME
1883             };
1884             static const ldns_rdf_type type_gpos_wireformat[] = {
1885             LDNS_RDF_TYPE_STR, LDNS_RDF_TYPE_STR, LDNS_RDF_TYPE_STR
1886             };
1887             static const ldns_rdf_type type_aaaa_wireformat[] = { LDNS_RDF_TYPE_AAAA };
1888             static const ldns_rdf_type type_loc_wireformat[] = { LDNS_RDF_TYPE_LOC };
1889             static const ldns_rdf_type type_nxt_wireformat[] = {
1890             LDNS_RDF_TYPE_DNAME, LDNS_RDF_TYPE_UNKNOWN
1891             };
1892             static const ldns_rdf_type type_eid_wireformat[] = {
1893             LDNS_RDF_TYPE_HEX
1894             };
1895             static const ldns_rdf_type type_nimloc_wireformat[] = {
1896             LDNS_RDF_TYPE_HEX
1897             };
1898             static const ldns_rdf_type type_srv_wireformat[] = {
1899             LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_DNAME
1900             };
1901             static const ldns_rdf_type type_atma_wireformat[] = {
1902             LDNS_RDF_TYPE_ATMA
1903             };
1904             static const ldns_rdf_type type_naptr_wireformat[] = {
1905             LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_STR, LDNS_RDF_TYPE_STR, LDNS_RDF_TYPE_STR, LDNS_RDF_TYPE_DNAME
1906             };
1907             static const ldns_rdf_type type_kx_wireformat[] = {
1908             LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_DNAME
1909             };
1910             static const ldns_rdf_type type_cert_wireformat[] = {
1911             LDNS_RDF_TYPE_CERT_ALG, LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_ALG, LDNS_RDF_TYPE_B64
1912             };
1913             static const ldns_rdf_type type_a6_wireformat[] = { LDNS_RDF_TYPE_UNKNOWN };
1914             static const ldns_rdf_type type_dname_wireformat[] = { LDNS_RDF_TYPE_DNAME };
1915             static const ldns_rdf_type type_sink_wireformat[] = { LDNS_RDF_TYPE_INT8,
1916             LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_B64
1917             };
1918             static const ldns_rdf_type type_apl_wireformat[] = {
1919             LDNS_RDF_TYPE_APL
1920             };
1921             static const ldns_rdf_type type_ds_wireformat[] = {
1922             LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_ALG, LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_HEX
1923             };
1924             static const ldns_rdf_type type_sshfp_wireformat[] = {
1925             LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_HEX
1926             };
1927             static const ldns_rdf_type type_ipseckey_wireformat[] = {
1928             LDNS_RDF_TYPE_IPSECKEY
1929             };
1930             static const ldns_rdf_type type_rrsig_wireformat[] = {
1931             LDNS_RDF_TYPE_TYPE, LDNS_RDF_TYPE_ALG, LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_INT32,
1932             LDNS_RDF_TYPE_TIME, LDNS_RDF_TYPE_TIME, LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_DNAME, LDNS_RDF_TYPE_B64
1933             };
1934             static const ldns_rdf_type type_nsec_wireformat[] = {
1935             LDNS_RDF_TYPE_DNAME, LDNS_RDF_TYPE_NSEC
1936             };
1937             static const ldns_rdf_type type_dhcid_wireformat[] = {
1938             LDNS_RDF_TYPE_B64
1939             };
1940             static const ldns_rdf_type type_talink_wireformat[] = {
1941             LDNS_RDF_TYPE_DNAME, LDNS_RDF_TYPE_DNAME
1942             };
1943             /*@unused@*/ static const ldns_rdf_type type_openpgpkey_wireformat[] = {
1944             LDNS_RDF_TYPE_B64
1945             };
1946             /* nsec3 is some vars, followed by same type of data of nsec */
1947             static const ldns_rdf_type type_nsec3_wireformat[] = {
1948             /* LDNS_RDF_TYPE_NSEC3_VARS, LDNS_RDF_TYPE_NSEC3_NEXT_OWNER, LDNS_RDF_TYPE_NSEC*/
1949             LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_NSEC3_SALT, LDNS_RDF_TYPE_NSEC3_NEXT_OWNER, LDNS_RDF_TYPE_NSEC
1950             };
1951              
1952             static const ldns_rdf_type type_nsec3param_wireformat[] = {
1953             /* LDNS_RDF_TYPE_NSEC3_PARAMS_VARS*/
1954             LDNS_RDF_TYPE_INT8,
1955             LDNS_RDF_TYPE_INT8,
1956             LDNS_RDF_TYPE_INT16,
1957             LDNS_RDF_TYPE_NSEC3_SALT
1958             };
1959              
1960             static const ldns_rdf_type type_dnskey_wireformat[] = {
1961             LDNS_RDF_TYPE_INT16,
1962             LDNS_RDF_TYPE_INT8,
1963             LDNS_RDF_TYPE_ALG,
1964             LDNS_RDF_TYPE_B64
1965             };
1966             static const ldns_rdf_type type_tkey_wireformat[] = {
1967             LDNS_RDF_TYPE_DNAME,
1968             LDNS_RDF_TYPE_TIME,
1969             LDNS_RDF_TYPE_TIME,
1970             LDNS_RDF_TYPE_INT16,
1971             LDNS_RDF_TYPE_INT16,
1972             LDNS_RDF_TYPE_INT16_DATA,
1973             LDNS_RDF_TYPE_INT16_DATA,
1974             };
1975             static const ldns_rdf_type type_tsig_wireformat[] = {
1976             LDNS_RDF_TYPE_DNAME,
1977             LDNS_RDF_TYPE_TSIGTIME,
1978             LDNS_RDF_TYPE_INT16,
1979             LDNS_RDF_TYPE_INT16_DATA,
1980             LDNS_RDF_TYPE_INT16,
1981             LDNS_RDF_TYPE_INT16,
1982             LDNS_RDF_TYPE_INT16_DATA
1983             };
1984             static const ldns_rdf_type type_tlsa_wireformat[] = {
1985             LDNS_RDF_TYPE_CERTIFICATE_USAGE,
1986             LDNS_RDF_TYPE_SELECTOR,
1987             LDNS_RDF_TYPE_MATCHING_TYPE,
1988             LDNS_RDF_TYPE_HEX
1989             };
1990             static const ldns_rdf_type type_hip_wireformat[] = {
1991             LDNS_RDF_TYPE_HIP
1992             };
1993             static const ldns_rdf_type type_nid_wireformat[] = {
1994             LDNS_RDF_TYPE_INT16,
1995             LDNS_RDF_TYPE_ILNP64
1996             };
1997             static const ldns_rdf_type type_l32_wireformat[] = {
1998             LDNS_RDF_TYPE_INT16,
1999             LDNS_RDF_TYPE_A
2000             };
2001             static const ldns_rdf_type type_l64_wireformat[] = {
2002             LDNS_RDF_TYPE_INT16,
2003             LDNS_RDF_TYPE_ILNP64
2004             };
2005             static const ldns_rdf_type type_lp_wireformat[] = {
2006             LDNS_RDF_TYPE_INT16,
2007             LDNS_RDF_TYPE_DNAME
2008             };
2009             static const ldns_rdf_type type_eui48_wireformat[] = {
2010             LDNS_RDF_TYPE_EUI48
2011             };
2012             static const ldns_rdf_type type_eui64_wireformat[] = {
2013             LDNS_RDF_TYPE_EUI64
2014             };
2015             #ifdef RRTYPE_URI
2016             static const ldns_rdf_type type_uri_wireformat[] = {
2017             LDNS_RDF_TYPE_INT16,
2018             LDNS_RDF_TYPE_INT16,
2019             LDNS_RDF_TYPE_LONG_STR
2020             };
2021             #endif
2022             static const ldns_rdf_type type_caa_wireformat[] = {
2023             LDNS_RDF_TYPE_INT8,
2024             LDNS_RDF_TYPE_TAG,
2025             LDNS_RDF_TYPE_LONG_STR
2026             };
2027             /** \endcond */
2028              
2029             /** \cond */
2030             /* All RR's defined in 1035 are well known and can thus
2031             * be compressed. See RFC3597. These RR's are:
2032             * CNAME HINFO MB MD MF MG MINFO MR MX NULL NS PTR SOA TXT
2033             */
2034             static ldns_rr_descriptor rdata_field_descriptors[] = {
2035             /* 0 */
2036             { 0, NULL, 0, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2037             /* 1 */
2038             {LDNS_RR_TYPE_A, "A", 1, 1, type_a_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2039             /* 2 */
2040             {LDNS_RR_TYPE_NS, "NS", 1, 1, type_ns_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 1 },
2041             /* 3 */
2042             {LDNS_RR_TYPE_MD, "MD", 1, 1, type_md_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 1 },
2043             /* 4 */
2044             {LDNS_RR_TYPE_MF, "MF", 1, 1, type_mf_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 1 },
2045             /* 5 */
2046             {LDNS_RR_TYPE_CNAME, "CNAME", 1, 1, type_cname_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 1 },
2047             /* 6 */
2048             {LDNS_RR_TYPE_SOA, "SOA", 7, 7, type_soa_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 2 },
2049             /* 7 */
2050             {LDNS_RR_TYPE_MB, "MB", 1, 1, type_mb_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 1 },
2051             /* 8 */
2052             {LDNS_RR_TYPE_MG, "MG", 1, 1, type_mg_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 1 },
2053             /* 9 */
2054             {LDNS_RR_TYPE_MR, "MR", 1, 1, type_mr_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 1 },
2055             /* 10 */
2056             {LDNS_RR_TYPE_NULL, "NULL", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2057             /* 11 */
2058             {LDNS_RR_TYPE_WKS, "WKS", 2, 2, type_wks_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2059             /* 12 */
2060             {LDNS_RR_TYPE_PTR, "PTR", 1, 1, type_ptr_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 1 },
2061             /* 13 */
2062             {LDNS_RR_TYPE_HINFO, "HINFO", 2, 2, type_hinfo_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2063             /* 14 */
2064             {LDNS_RR_TYPE_MINFO, "MINFO", 2, 2, type_minfo_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 2 },
2065             /* 15 */
2066             {LDNS_RR_TYPE_MX, "MX", 2, 2, type_mx_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 1 },
2067             /* 16 */
2068             {LDNS_RR_TYPE_TXT, "TXT", 1, 0, NULL, LDNS_RDF_TYPE_STR, LDNS_RR_NO_COMPRESS, 0 },
2069             /* 17 */
2070             {LDNS_RR_TYPE_RP, "RP", 2, 2, type_rp_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 2 },
2071             /* 18 */
2072             {LDNS_RR_TYPE_AFSDB, "AFSDB", 2, 2, type_afsdb_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
2073             /* 19 */
2074             {LDNS_RR_TYPE_X25, "X25", 1, 1, type_x25_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2075             /* 20 */
2076             {LDNS_RR_TYPE_ISDN, "ISDN", 1, 2, type_isdn_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2077             /* 21 */
2078             {LDNS_RR_TYPE_RT, "RT", 2, 2, type_rt_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
2079             /* 22 */
2080             {LDNS_RR_TYPE_NSAP, "NSAP", 1, 1, type_nsap_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2081             /* 23 */
2082             {LDNS_RR_TYPE_NSAP_PTR, "NSAP-PTR", 1, 1, type_nsap_ptr_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2083             /* 24 */
2084             {LDNS_RR_TYPE_SIG, "SIG", 9, 9, type_sig_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
2085             /* 25 */
2086             {LDNS_RR_TYPE_KEY, "KEY", 4, 4, type_key_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2087             /* 26 */
2088             {LDNS_RR_TYPE_PX, "PX", 3, 3, type_px_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 2 },
2089             /* 27 */
2090             {LDNS_RR_TYPE_GPOS, "GPOS", 3, 3, type_gpos_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2091             /* 28 */
2092             {LDNS_RR_TYPE_AAAA, "AAAA", 1, 1, type_aaaa_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2093             /* 29 */
2094             {LDNS_RR_TYPE_LOC, "LOC", 1, 1, type_loc_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2095             /* 30 */
2096             {LDNS_RR_TYPE_NXT, "NXT", 2, 2, type_nxt_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
2097             /* 31 */
2098             {LDNS_RR_TYPE_EID, "EID", 1, 1, type_eid_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2099             /* 32 */
2100             {LDNS_RR_TYPE_NIMLOC, "NIMLOC", 1, 1, type_nimloc_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2101             /* 33 */
2102             {LDNS_RR_TYPE_SRV, "SRV", 4, 4, type_srv_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
2103             /* 34 */
2104             {LDNS_RR_TYPE_ATMA, "ATMA", 1, 1, type_atma_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2105             /* 35 */
2106             {LDNS_RR_TYPE_NAPTR, "NAPTR", 6, 6, type_naptr_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
2107             /* 36 */
2108             {LDNS_RR_TYPE_KX, "KX", 2, 2, type_kx_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
2109             /* 37 */
2110             {LDNS_RR_TYPE_CERT, "CERT", 4, 4, type_cert_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2111             /* 38 */
2112             {LDNS_RR_TYPE_A6, "A6", 1, 1, type_a6_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2113             /* 39 */
2114             {LDNS_RR_TYPE_DNAME, "DNAME", 1, 1, type_dname_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
2115             /* 40 */
2116             {LDNS_RR_TYPE_SINK, "SINK", 1, 1, type_sink_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2117             /* 41 */
2118             {LDNS_RR_TYPE_OPT, "OPT", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2119             /* 42 */
2120             {LDNS_RR_TYPE_APL, "APL", 0, 0, type_apl_wireformat, LDNS_RDF_TYPE_APL, LDNS_RR_NO_COMPRESS, 0 },
2121             /* 43 */
2122             {LDNS_RR_TYPE_DS, "DS", 4, 4, type_ds_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2123             /* 44 */
2124             {LDNS_RR_TYPE_SSHFP, "SSHFP", 3, 3, type_sshfp_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2125             /* 45 */
2126             {LDNS_RR_TYPE_IPSECKEY, "IPSECKEY", 1, 1, type_ipseckey_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2127             /* 46 */
2128             {LDNS_RR_TYPE_RRSIG, "RRSIG", 9, 9, type_rrsig_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
2129             /* 47 */
2130             {LDNS_RR_TYPE_NSEC, "NSEC", 1, 2, type_nsec_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
2131             /* 48 */
2132             {LDNS_RR_TYPE_DNSKEY, "DNSKEY", 4, 4, type_dnskey_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2133             /* 49 */
2134             {LDNS_RR_TYPE_DHCID, "DHCID", 1, 1, type_dhcid_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2135             /* 50 */
2136             {LDNS_RR_TYPE_NSEC3, "NSEC3", 5, 6, type_nsec3_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2137             /* 51 */
2138             {LDNS_RR_TYPE_NSEC3PARAM, "NSEC3PARAM", 4, 4, type_nsec3param_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2139             /* 52 */
2140             {LDNS_RR_TYPE_TLSA, "TLSA", 4, 4, type_tlsa_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2141              
2142             {LDNS_RR_TYPE_NULL, "TYPE53", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2143             {LDNS_RR_TYPE_NULL, "TYPE54", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2144              
2145             /* 55
2146             * Hip ends with 0 or more Rendezvous Servers represented as dname's.
2147             * Hence the LDNS_RDF_TYPE_DNAME _variable field and the _maximum field
2148             * set to 0.
2149             */
2150             {LDNS_RR_TYPE_HIP, "HIP", 1, 1, type_hip_wireformat, LDNS_RDF_TYPE_DNAME, LDNS_RR_NO_COMPRESS, 0 },
2151              
2152             #ifdef RRTYPE_NINFO
2153             /* 56 */
2154             {LDNS_RR_TYPE_NINFO, "NINFO", 1, 0, NULL, LDNS_RDF_TYPE_STR, LDNS_RR_NO_COMPRESS, 0 },
2155             #else
2156             {LDNS_RR_TYPE_NULL, "TYPE56", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2157             #endif
2158             #ifdef RRTYPE_RKEY
2159             /* 57 */
2160             {LDNS_RR_TYPE_RKEY, "RKEY", 4, 4, type_key_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2161             #else
2162             {LDNS_RR_TYPE_NULL, "TYPE57", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2163             #endif
2164             /* 58 */
2165             {LDNS_RR_TYPE_TALINK, "TALINK", 2, 2, type_talink_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 2 },
2166              
2167             /* 59 */
2168             {LDNS_RR_TYPE_CDS, "CDS", 4, 4, type_ds_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2169             /* 60 */
2170             {LDNS_RR_TYPE_CDNSKEY, "CDNSKEY", 4, 4, type_dnskey_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2171              
2172             #ifdef RRTYPE_OPENPGPKEY
2173             /* 61 */
2174             {LDNS_RR_TYPE_OPENPGPKEY, "OPENPGPKEY", 1, 1, type_openpgpkey_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2175             #else
2176             {LDNS_RR_TYPE_NULL, "TYPE61", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2177             #endif
2178              
2179             {LDNS_RR_TYPE_NULL, "TYPE62", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2180             {LDNS_RR_TYPE_NULL, "TYPE63", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2181             {LDNS_RR_TYPE_NULL, "TYPE64", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2182             {LDNS_RR_TYPE_NULL, "TYPE65", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2183             {LDNS_RR_TYPE_NULL, "TYPE66", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2184             {LDNS_RR_TYPE_NULL, "TYPE67", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2185             {LDNS_RR_TYPE_NULL, "TYPE68", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2186             {LDNS_RR_TYPE_NULL, "TYPE69", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2187             {LDNS_RR_TYPE_NULL, "TYPE70", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2188             {LDNS_RR_TYPE_NULL, "TYPE71", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2189             {LDNS_RR_TYPE_NULL, "TYPE72", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2190             {LDNS_RR_TYPE_NULL, "TYPE73", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2191             {LDNS_RR_TYPE_NULL, "TYPE74", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2192             {LDNS_RR_TYPE_NULL, "TYPE75", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2193             {LDNS_RR_TYPE_NULL, "TYPE76", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2194             {LDNS_RR_TYPE_NULL, "TYPE77", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2195             {LDNS_RR_TYPE_NULL, "TYPE78", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2196             {LDNS_RR_TYPE_NULL, "TYPE79", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2197             {LDNS_RR_TYPE_NULL, "TYPE80", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2198             {LDNS_RR_TYPE_NULL, "TYPE81", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2199             {LDNS_RR_TYPE_NULL, "TYPE82", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2200             {LDNS_RR_TYPE_NULL, "TYPE83", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2201             {LDNS_RR_TYPE_NULL, "TYPE84", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2202             {LDNS_RR_TYPE_NULL, "TYPE85", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2203             {LDNS_RR_TYPE_NULL, "TYPE86", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2204             {LDNS_RR_TYPE_NULL, "TYPE87", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2205             {LDNS_RR_TYPE_NULL, "TYPE88", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2206             {LDNS_RR_TYPE_NULL, "TYPE89", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2207             {LDNS_RR_TYPE_NULL, "TYPE90", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2208             {LDNS_RR_TYPE_NULL, "TYPE91", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2209             {LDNS_RR_TYPE_NULL, "TYPE92", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2210             {LDNS_RR_TYPE_NULL, "TYPE93", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2211             {LDNS_RR_TYPE_NULL, "TYPE94", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2212             {LDNS_RR_TYPE_NULL, "TYPE95", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2213             {LDNS_RR_TYPE_NULL, "TYPE96", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2214             {LDNS_RR_TYPE_NULL, "TYPE97", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2215             {LDNS_RR_TYPE_NULL, "TYPE98", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2216              
2217             /* 99 */
2218             {LDNS_RR_TYPE_SPF, "SPF", 1, 0, NULL, LDNS_RDF_TYPE_STR, LDNS_RR_NO_COMPRESS, 0 },
2219              
2220             /* UINFO [IANA-Reserved] */
2221             {LDNS_RR_TYPE_NULL, "TYPE100", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2222             /* UID [IANA-Reserved] */
2223             {LDNS_RR_TYPE_NULL, "TYPE101", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2224             /* GID [IANA-Reserved] */
2225             {LDNS_RR_TYPE_NULL, "TYPE102", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2226             /* UNSPEC [IANA-Reserved] */
2227             {LDNS_RR_TYPE_NULL, "TYPE103", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2228              
2229             /* 104 */
2230             {LDNS_RR_TYPE_NID, "NID", 2, 2, type_nid_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2231             /* 105 */
2232             {LDNS_RR_TYPE_L32, "L32", 2, 2, type_l32_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2233             /* 106 */
2234             {LDNS_RR_TYPE_L64, "L64", 2, 2, type_l64_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2235             /* 107 */
2236             {LDNS_RR_TYPE_LP, "LP", 2, 2, type_lp_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
2237             /* 108 */
2238             {LDNS_RR_TYPE_EUI48, "EUI48", 1, 1, type_eui48_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2239             /* 109 */
2240             {LDNS_RR_TYPE_EUI64, "EUI64", 1, 1, type_eui64_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2241              
2242             {LDNS_RR_TYPE_NULL, "TYPE110", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2243             {LDNS_RR_TYPE_NULL, "TYPE111", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2244             {LDNS_RR_TYPE_NULL, "TYPE112", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2245             {LDNS_RR_TYPE_NULL, "TYPE113", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2246             {LDNS_RR_TYPE_NULL, "TYPE114", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2247             {LDNS_RR_TYPE_NULL, "TYPE115", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2248             {LDNS_RR_TYPE_NULL, "TYPE116", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2249             {LDNS_RR_TYPE_NULL, "TYPE117", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2250             {LDNS_RR_TYPE_NULL, "TYPE118", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2251             {LDNS_RR_TYPE_NULL, "TYPE119", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2252             {LDNS_RR_TYPE_NULL, "TYPE120", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2253             {LDNS_RR_TYPE_NULL, "TYPE121", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2254             {LDNS_RR_TYPE_NULL, "TYPE122", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2255             {LDNS_RR_TYPE_NULL, "TYPE123", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2256             {LDNS_RR_TYPE_NULL, "TYPE124", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2257             {LDNS_RR_TYPE_NULL, "TYPE125", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2258             {LDNS_RR_TYPE_NULL, "TYPE126", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2259             {LDNS_RR_TYPE_NULL, "TYPE127", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2260             {LDNS_RR_TYPE_NULL, "TYPE128", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2261             {LDNS_RR_TYPE_NULL, "TYPE129", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2262             {LDNS_RR_TYPE_NULL, "TYPE130", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2263             {LDNS_RR_TYPE_NULL, "TYPE131", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2264             {LDNS_RR_TYPE_NULL, "TYPE132", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2265             {LDNS_RR_TYPE_NULL, "TYPE133", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2266             {LDNS_RR_TYPE_NULL, "TYPE134", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2267             {LDNS_RR_TYPE_NULL, "TYPE135", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2268             {LDNS_RR_TYPE_NULL, "TYPE136", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2269             {LDNS_RR_TYPE_NULL, "TYPE137", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2270             {LDNS_RR_TYPE_NULL, "TYPE138", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2271             {LDNS_RR_TYPE_NULL, "TYPE139", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2272             {LDNS_RR_TYPE_NULL, "TYPE140", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2273             {LDNS_RR_TYPE_NULL, "TYPE141", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2274             {LDNS_RR_TYPE_NULL, "TYPE142", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2275             {LDNS_RR_TYPE_NULL, "TYPE143", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2276             {LDNS_RR_TYPE_NULL, "TYPE144", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2277             {LDNS_RR_TYPE_NULL, "TYPE145", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2278             {LDNS_RR_TYPE_NULL, "TYPE146", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2279             {LDNS_RR_TYPE_NULL, "TYPE147", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2280             {LDNS_RR_TYPE_NULL, "TYPE148", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2281             {LDNS_RR_TYPE_NULL, "TYPE149", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2282             {LDNS_RR_TYPE_NULL, "TYPE150", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2283             {LDNS_RR_TYPE_NULL, "TYPE151", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2284             {LDNS_RR_TYPE_NULL, "TYPE152", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2285             {LDNS_RR_TYPE_NULL, "TYPE153", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2286             {LDNS_RR_TYPE_NULL, "TYPE154", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2287             {LDNS_RR_TYPE_NULL, "TYPE155", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2288             {LDNS_RR_TYPE_NULL, "TYPE156", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2289             {LDNS_RR_TYPE_NULL, "TYPE157", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2290             {LDNS_RR_TYPE_NULL, "TYPE158", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2291             {LDNS_RR_TYPE_NULL, "TYPE159", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2292             {LDNS_RR_TYPE_NULL, "TYPE160", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2293             {LDNS_RR_TYPE_NULL, "TYPE161", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2294             {LDNS_RR_TYPE_NULL, "TYPE162", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2295             {LDNS_RR_TYPE_NULL, "TYPE163", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2296             {LDNS_RR_TYPE_NULL, "TYPE164", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2297             {LDNS_RR_TYPE_NULL, "TYPE165", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2298             {LDNS_RR_TYPE_NULL, "TYPE166", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2299             {LDNS_RR_TYPE_NULL, "TYPE167", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2300             {LDNS_RR_TYPE_NULL, "TYPE168", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2301             {LDNS_RR_TYPE_NULL, "TYPE169", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2302             {LDNS_RR_TYPE_NULL, "TYPE170", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2303             {LDNS_RR_TYPE_NULL, "TYPE171", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2304             {LDNS_RR_TYPE_NULL, "TYPE172", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2305             {LDNS_RR_TYPE_NULL, "TYPE173", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2306             {LDNS_RR_TYPE_NULL, "TYPE174", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2307             {LDNS_RR_TYPE_NULL, "TYPE175", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2308             {LDNS_RR_TYPE_NULL, "TYPE176", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2309             {LDNS_RR_TYPE_NULL, "TYPE177", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2310             {LDNS_RR_TYPE_NULL, "TYPE178", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2311             {LDNS_RR_TYPE_NULL, "TYPE179", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2312             {LDNS_RR_TYPE_NULL, "TYPE180", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2313             {LDNS_RR_TYPE_NULL, "TYPE181", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2314             {LDNS_RR_TYPE_NULL, "TYPE182", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2315             {LDNS_RR_TYPE_NULL, "TYPE183", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2316             {LDNS_RR_TYPE_NULL, "TYPE184", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2317             {LDNS_RR_TYPE_NULL, "TYPE185", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2318             {LDNS_RR_TYPE_NULL, "TYPE186", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2319             {LDNS_RR_TYPE_NULL, "TYPE187", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2320             {LDNS_RR_TYPE_NULL, "TYPE188", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2321             {LDNS_RR_TYPE_NULL, "TYPE189", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2322             {LDNS_RR_TYPE_NULL, "TYPE190", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2323             {LDNS_RR_TYPE_NULL, "TYPE191", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2324             {LDNS_RR_TYPE_NULL, "TYPE192", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2325             {LDNS_RR_TYPE_NULL, "TYPE193", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2326             {LDNS_RR_TYPE_NULL, "TYPE194", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2327             {LDNS_RR_TYPE_NULL, "TYPE195", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2328             {LDNS_RR_TYPE_NULL, "TYPE196", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2329             {LDNS_RR_TYPE_NULL, "TYPE197", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2330             {LDNS_RR_TYPE_NULL, "TYPE198", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2331             {LDNS_RR_TYPE_NULL, "TYPE199", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2332             {LDNS_RR_TYPE_NULL, "TYPE200", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2333             {LDNS_RR_TYPE_NULL, "TYPE201", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2334             {LDNS_RR_TYPE_NULL, "TYPE202", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2335             {LDNS_RR_TYPE_NULL, "TYPE203", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2336             {LDNS_RR_TYPE_NULL, "TYPE204", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2337             {LDNS_RR_TYPE_NULL, "TYPE205", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2338             {LDNS_RR_TYPE_NULL, "TYPE206", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2339             {LDNS_RR_TYPE_NULL, "TYPE207", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2340             {LDNS_RR_TYPE_NULL, "TYPE208", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2341             {LDNS_RR_TYPE_NULL, "TYPE209", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2342             {LDNS_RR_TYPE_NULL, "TYPE210", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2343             {LDNS_RR_TYPE_NULL, "TYPE211", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2344             {LDNS_RR_TYPE_NULL, "TYPE212", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2345             {LDNS_RR_TYPE_NULL, "TYPE213", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2346             {LDNS_RR_TYPE_NULL, "TYPE214", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2347             {LDNS_RR_TYPE_NULL, "TYPE215", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2348             {LDNS_RR_TYPE_NULL, "TYPE216", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2349             {LDNS_RR_TYPE_NULL, "TYPE217", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2350             {LDNS_RR_TYPE_NULL, "TYPE218", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2351             {LDNS_RR_TYPE_NULL, "TYPE219", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2352             {LDNS_RR_TYPE_NULL, "TYPE220", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2353             {LDNS_RR_TYPE_NULL, "TYPE221", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2354             {LDNS_RR_TYPE_NULL, "TYPE222", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2355             {LDNS_RR_TYPE_NULL, "TYPE223", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2356             {LDNS_RR_TYPE_NULL, "TYPE224", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2357             {LDNS_RR_TYPE_NULL, "TYPE225", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2358             {LDNS_RR_TYPE_NULL, "TYPE226", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2359             {LDNS_RR_TYPE_NULL, "TYPE227", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2360             {LDNS_RR_TYPE_NULL, "TYPE228", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2361             {LDNS_RR_TYPE_NULL, "TYPE229", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2362             {LDNS_RR_TYPE_NULL, "TYPE230", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2363             {LDNS_RR_TYPE_NULL, "TYPE231", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2364             {LDNS_RR_TYPE_NULL, "TYPE232", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2365             {LDNS_RR_TYPE_NULL, "TYPE233", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2366             {LDNS_RR_TYPE_NULL, "TYPE234", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2367             {LDNS_RR_TYPE_NULL, "TYPE235", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2368             {LDNS_RR_TYPE_NULL, "TYPE236", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2369             {LDNS_RR_TYPE_NULL, "TYPE237", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2370             {LDNS_RR_TYPE_NULL, "TYPE238", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2371             {LDNS_RR_TYPE_NULL, "TYPE239", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2372             {LDNS_RR_TYPE_NULL, "TYPE240", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2373             {LDNS_RR_TYPE_NULL, "TYPE241", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2374             {LDNS_RR_TYPE_NULL, "TYPE242", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2375             {LDNS_RR_TYPE_NULL, "TYPE243", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2376             {LDNS_RR_TYPE_NULL, "TYPE244", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2377             {LDNS_RR_TYPE_NULL, "TYPE245", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2378             {LDNS_RR_TYPE_NULL, "TYPE246", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2379             {LDNS_RR_TYPE_NULL, "TYPE247", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2380             {LDNS_RR_TYPE_NULL, "TYPE248", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2381              
2382             /* LDNS_RDF_TYPE_INT16_DATA takes two fields (length and data) as one.
2383             * So, unlike RFC 2930 spec, we have 7 min/max rdf's i.s.o. 8/9.
2384             */
2385             /* 249 */
2386             {LDNS_RR_TYPE_TKEY, "TKEY", 7, 7, type_tkey_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
2387             /* LDNS_RDF_TYPE_INT16_DATA takes two fields (length and data) as one.
2388             * So, unlike RFC 2930 spec, we have 7 min/max rdf's i.s.o. 8/9.
2389             */
2390             /* 250 */
2391             {LDNS_RR_TYPE_TSIG, "TSIG", 7, 7, type_tsig_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
2392              
2393             /* IXFR: A request for a transfer of an incremental zone transfer */
2394             {LDNS_RR_TYPE_NULL, "TYPE251", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2395             /* AXFR: A request for a transfer of an entire zone */
2396             {LDNS_RR_TYPE_NULL, "TYPE252", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2397             /* MAILB: A request for mailbox-related records (MB, MG or MR) */
2398             {LDNS_RR_TYPE_NULL, "TYPE253", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2399             /* MAILA: A request for mail agent RRs (Obsolete - see MX) */
2400             {LDNS_RR_TYPE_NULL, "TYPE254", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2401             /* ANY: A request for all (available) records */
2402             {LDNS_RR_TYPE_NULL, "TYPE255", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2403              
2404             #ifdef RRTYPE_URI
2405             /* 256 */
2406             {LDNS_RR_TYPE_URI, "URI", 3, 3, type_uri_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2407             #else
2408             {LDNS_RR_TYPE_NULL, "TYPE256", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2409             #endif
2410             /* 257 */
2411             {LDNS_RR_TYPE_CAA, "CAA", 3, 3, type_caa_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2412              
2413             /* split in array, no longer contiguous */
2414              
2415             #ifdef RRTYPE_TA
2416             /* 32768 */
2417             {LDNS_RR_TYPE_TA, "TA", 4, 4, type_ds_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2418             #else
2419             {LDNS_RR_TYPE_NULL, "TYPE32768", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2420             #endif
2421             /* 32769 */
2422             {LDNS_RR_TYPE_DLV, "DLV", 4, 4, type_ds_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 }
2423             };
2424             /** \endcond */
2425              
2426             /**
2427             * \def LDNS_RDATA_FIELD_DESCRIPTORS_COUNT
2428             * computes the number of rdata fields
2429             */
2430             #define LDNS_RDATA_FIELD_DESCRIPTORS_COUNT \
2431             (sizeof(rdata_field_descriptors)/sizeof(rdata_field_descriptors[0]))
2432              
2433              
2434             /*---------------------------------------------------------------------------*
2435             * The functions below return an bitmap RDF with the space required to set
2436             * or unset all known RR types. Arguably these functions are better situated
2437             * in rdata.c, however for the space calculation it is necesarry to walk
2438             * through rdata_field_descriptors which is not easily possible from anywhere
2439             * other than rr.c where it is declared static.
2440             *
2441             * Alternatively rr.c could have provided an iterator for rr_type or
2442             * rdf_descriptors, but this seemed overkill for internal use only.
2443             */
2444             static ldns_rr_descriptor* rdata_field_descriptors_end =
2445             &rdata_field_descriptors[LDNS_RDATA_FIELD_DESCRIPTORS_COUNT];
2446              
2447             /* From RFC3845:
2448             *
2449             * 2.1.2. The List of Type Bit Map(s) Field
2450             *
2451             * The RR type space is split into 256 window blocks, each representing
2452             * the low-order 8 bits of the 16-bit RR type space. Each block that
2453             * has at least one active RR type is encoded using a single octet
2454             * window number (from 0 to 255), a single octet bitmap length (from 1
2455             * to 32) indicating the number of octets used for the window block's
2456             * bitmap, and up to 32 octets (256 bits) of bitmap.
2457             *
2458             * Window blocks are present in the NSEC RR RDATA in increasing
2459             * numerical order.
2460             *
2461             * "|" denotes concatenation
2462             *
2463             * Type Bit Map(s) Field = ( Window Block # | Bitmap Length | Bitmap ) +
2464             *
2465             *
2466             *
2467             * Blocks with no types present MUST NOT be included. Trailing zero
2468             * octets in the bitmap MUST be omitted. The length of each block's
2469             * bitmap is determined by the type code with the largest numerical
2470             * value within that block, among the set of RR types present at the
2471             * NSEC RR's owner name. Trailing zero octets not specified MUST be
2472             * interpreted as zero octets.
2473             */
2474             static ldns_status
2475 0           ldns_rdf_bitmap_known_rr_types_set(ldns_rdf** rdf, int value)
2476             {
2477             uint8_t window; /* most significant octet of type */
2478             uint8_t subtype; /* least significant octet of type */
2479 0           uint16_t windows[256] /* Max subtype per window */
2480             #ifndef S_SPLINT_S
2481             = { 0 }
2482             #endif
2483             ;
2484             ldns_rr_descriptor* d; /* used to traverse rdata_field_descriptors */
2485             size_t i; /* used to traverse windows array */
2486              
2487             size_t sz; /* size needed for type bitmap rdf */
2488 0           uint8_t* data = NULL; /* rdf data */
2489             uint8_t* dptr; /* used to itraverse rdf data */
2490              
2491             assert(rdf != NULL);
2492              
2493             /* Which windows need to be in the bitmap rdf?
2494             */
2495 0 0         for (d=rdata_field_descriptors; d < rdata_field_descriptors_end; d++) {
2496 0           window = d->_type >> 8;
2497 0           subtype = d->_type & 0xff;
2498 0 0         if (windows[window] < subtype) {
2499 0           windows[window] = subtype;
2500             }
2501             }
2502              
2503             /* How much space do we need in the rdf for those windows?
2504             */
2505 0           sz = 0;
2506 0 0         for (i = 0; i < 256; i++) {
2507 0 0         if (windows[i]) {
2508 0           sz += windows[i] / 8 + 3;
2509             }
2510             }
2511 0 0         if (sz > 0) {
2512             /* Format rdf data according RFC3845 Section 2.1.2 (see above)
2513             */
2514 0           dptr = data = LDNS_XMALLOC(uint8_t, sz);
2515 0           memset(data, value, sz);
2516 0 0         if (!data) {
2517 0           return LDNS_STATUS_MEM_ERR;
2518             }
2519 0 0         for (i = 0; i < 256; i++) {
2520 0 0         if (windows[i]) {
2521 0           *dptr++ = (uint8_t)i;
2522 0           *dptr++ = (uint8_t)(windows[i] / 8 + 1);
2523 0           dptr += dptr[-1];
2524             }
2525             }
2526             }
2527             /* Allocate and return rdf structure for the data
2528             */
2529 0           *rdf = ldns_rdf_new(LDNS_RDF_TYPE_BITMAP, sz, data);
2530 0 0         if (!*rdf) {
2531 0           LDNS_FREE(data);
2532 0           return LDNS_STATUS_MEM_ERR;
2533             }
2534 0           return LDNS_STATUS_OK;
2535             }
2536              
2537             ldns_status
2538 0           ldns_rdf_bitmap_known_rr_types_space(ldns_rdf** rdf)
2539             {
2540 0           return ldns_rdf_bitmap_known_rr_types_set(rdf, 0);
2541             }
2542              
2543             ldns_status
2544 0           ldns_rdf_bitmap_known_rr_types(ldns_rdf** rdf)
2545             {
2546 0           return ldns_rdf_bitmap_known_rr_types_set(rdf, 255);
2547             }
2548             /* End of RDF bitmap functions
2549             *---------------------------------------------------------------------------*/
2550              
2551              
2552             const ldns_rr_descriptor *
2553 563           ldns_rr_descript(uint16_t type)
2554             {
2555             size_t i;
2556 563 50         if (type < LDNS_RDATA_FIELD_DESCRIPTORS_COMMON) {
2557 563           return &rdata_field_descriptors[type];
2558             } else {
2559             /* because not all array index equals type code */
2560 0 0         for (i = LDNS_RDATA_FIELD_DESCRIPTORS_COMMON;
2561             i < LDNS_RDATA_FIELD_DESCRIPTORS_COUNT;
2562 0           i++) {
2563 0 0         if (rdata_field_descriptors[i]._type == type) {
2564 0           return &rdata_field_descriptors[i];
2565             }
2566             }
2567 0           return &rdata_field_descriptors[0];
2568             }
2569             }
2570              
2571             size_t
2572 55           ldns_rr_descriptor_minimum(const ldns_rr_descriptor *descriptor)
2573             {
2574 55 50         if (descriptor) {
2575 55           return descriptor->_minimum;
2576             } else {
2577 0           return 0;
2578             }
2579             }
2580              
2581             size_t
2582 732           ldns_rr_descriptor_maximum(const ldns_rr_descriptor *descriptor)
2583             {
2584 732 50         if (descriptor) {
2585 732 100         if (descriptor->_variable != LDNS_RDF_TYPE_NONE) {
2586             /* Should really be SIZE_MAX... bad FreeBSD. */
2587 5           return UINT_MAX;
2588             } else {
2589 727           return descriptor->_maximum;
2590             }
2591             } else {
2592 0           return 0;
2593             }
2594             }
2595              
2596             ldns_rdf_type
2597 1109           ldns_rr_descriptor_field_type(const ldns_rr_descriptor *descriptor,
2598             size_t index)
2599             {
2600             assert(descriptor != NULL);
2601             assert(index < descriptor->_maximum
2602             || descriptor->_variable != LDNS_RDF_TYPE_NONE);
2603 1109 100         if (index < descriptor->_maximum) {
2604 1098           return descriptor->_wireformat[index];
2605             } else {
2606 11           return descriptor->_variable;
2607             }
2608             }
2609              
2610             ldns_rr_type
2611 90           ldns_get_rr_type_by_name(const char *name)
2612             {
2613             unsigned int i;
2614             const char *desc_name;
2615             const ldns_rr_descriptor *desc;
2616              
2617             /* TYPEXX representation */
2618 90 100         if (strlen(name) > 4 && strncasecmp(name, "TYPE", 4) == 0) {
    50          
2619 0           return atoi(name + 4);
2620             }
2621              
2622             /* Normal types */
2623 1969 100         for (i = 0; i < (unsigned int) LDNS_RDATA_FIELD_DESCRIPTORS_COUNT; i++) {
2624 1968           desc = &rdata_field_descriptors[i];
2625 1968           desc_name = desc->_name;
2626 1968 100         if(desc_name &&
    100          
2627 314 100         strlen(name) == strlen(desc_name) &&
2628 314           strncasecmp(name, desc_name, strlen(desc_name)) == 0) {
2629             /* because not all array index equals type code */
2630 89           return desc->_type;
2631             }
2632             }
2633              
2634             /* special cases for query types */
2635 1 50         if (strlen(name) == 4 && strncasecmp(name, "IXFR", 4) == 0) {
    0          
2636 0           return 251;
2637 1 50         } else if (strlen(name) == 4 && strncasecmp(name, "AXFR", 4) == 0) {
    0          
2638 0           return 252;
2639 1 50         } else if (strlen(name) == 5 && strncasecmp(name, "MAILB", 5) == 0) {
    0          
2640 0           return 253;
2641 1 50         } else if (strlen(name) == 5 && strncasecmp(name, "MAILA", 5) == 0) {
    0          
2642 0           return 254;
2643 1 50         } else if (strlen(name) == 3 && strncasecmp(name, "ANY", 3) == 0) {
    0          
2644 0           return 255;
2645             }
2646              
2647 1           return 0;
2648             }
2649              
2650             ldns_rr_class
2651 81           ldns_get_rr_class_by_name(const char *name)
2652             {
2653             ldns_lookup_table *lt;
2654              
2655             /* CLASSXX representation */
2656 81 100         if (strlen(name) > 5 && strncasecmp(name, "CLASS", 5) == 0) {
    50          
2657 0           return atoi(name + 5);
2658             }
2659              
2660             /* Normal types */
2661 81           lt = ldns_lookup_by_name(ldns_rr_classes, name);
2662              
2663 81 100         if (lt) {
2664 65           return lt->id;
2665             }
2666 16           return 0;
2667             }
2668              
2669              
2670             ldns_rr_type
2671 5           ldns_rdf2rr_type(const ldns_rdf *rd)
2672             {
2673             ldns_rr_type r;
2674              
2675 5 50         if (!rd) {
2676 0           return 0;
2677             }
2678              
2679 5 50         if (ldns_rdf_get_type(rd) != LDNS_RDF_TYPE_TYPE) {
2680 0           return 0;
2681             }
2682              
2683 5           r = (ldns_rr_type) ldns_rdf2native_int16(rd);
2684 5           return r;
2685             }
2686              
2687             ldns_rr_type
2688 0           ldns_rr_list_type(const ldns_rr_list *rr_list)
2689             {
2690 0 0         if (rr_list && ldns_rr_list_rr_count(rr_list) > 0) {
    0          
2691 0           return ldns_rr_get_type(ldns_rr_list_rr(rr_list, 0));
2692             } else {
2693 0           return 0;
2694             }
2695             }
2696              
2697             ldns_rdf *
2698 0           ldns_rr_list_owner(const ldns_rr_list *rr_list)
2699             {
2700 0 0         if (rr_list && ldns_rr_list_rr_count(rr_list) > 0) {
    0          
2701 0           return ldns_rr_owner(ldns_rr_list_rr(rr_list, 0));
2702             } else {
2703 0           return NULL;
2704             }
2705             }