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