19 #define LDNS_SYNTAX_DATALEN 16
20 #define LDNS_TTL_DATALEN 21
21 #define LDNS_RRLIST_INIT 8
105 ldns_rr_new_frm_str_internal(
ldns_rr **newrr,
const char *str,
106 uint32_t default_ttl,
ldns_rdf *origin,
124 const char *delimiters;
128 int was_unknown_rr_format = 0;
151 if (!
new || !owner || !ttl || !clas || !rdata || !rr_buf || !rd_buf || !rd || !b64 ) {
173 if (strlen(ttl) > 0 && !isdigit((
int) ttl[0])) {
175 if (default_ttl == 0) {
178 ttl_val = default_ttl;
197 strncpy(type, ttl, strlen(ttl) + 1);
217 strncpy(type, clas, strlen(clas) + 1);
244 if (strlen(owner) <= 1 && strncmp(owner,
"@", 1) == 0) {
247 }
else if (prev && *prev) {
265 if (strlen(owner) == 0) {
342 for (r_cnt = 0; !done && r_cnt < r_max; r_cnt++) {
359 delimiters =
"\n\t ";
364 ldns_buffer_remaining(rd_buf) > 0) {
366 while (*(ldns_buffer_current(rd_buf)) ==
' ') {
367 ldns_buffer_skip(rd_buf, 1);
370 if (*(ldns_buffer_current(rd_buf)) ==
'\"') {
372 ldns_buffer_skip(rd_buf, 1);
380 while (ldns_buffer_position(rd_buf) < ldns_buffer_limit(rd_buf) &&
381 *(ldns_buffer_current(rd_buf)) ==
' ' && !quoted
383 ldns_buffer_skip(rd_buf, 1);
386 pre_data_pos = ldns_buffer_position(rd_buf);
393 rd_strlen = strlen(rd);
396 if (strncmp(rd,
"\\#", 2) == 0 && !quoted && (rd_strlen == 2 || rd[2]==
' ')) {
397 uint16_t hex_data_size;
399 uint16_t cur_hex_data_size;
401 was_unknown_rr_format = 1;
403 ldns_buffer_set_position(rd_buf, pre_data_pos);
404 delimiters =
"\n\t ";
418 hex_data_size = (uint16_t) atoi(rd);
420 hex_data_str =
LDNS_XMALLOC(
char, 2 * hex_data_size + 1);
431 cur_hex_data_size = 0;
432 while(cur_hex_data_size < 2 * hex_data_size) {
435 rd_strlen = strlen(rd);
437 if (c == -1 || (
size_t)cur_hex_data_size + rd_strlen > 2 * (
size_t)hex_data_size) {
447 strncpy(hex_data_str + cur_hex_data_size, rd, rd_strlen);
448 cur_hex_data_size += rd_strlen;
450 hex_data_str[cur_hex_data_size] =
'\0';
456 uint8_t *hex_data =
LDNS_XMALLOC(uint8_t, hex_data_size + 2);
468 ldns_write_uint16(hex_data, hex_data_size);
471 hex_data_size+2, &hex_pos);
580 if (ldns_buffer_available(rd_buf, 1)) {
581 ldns_buffer_skip(rd_buf, 1);
597 if (!question && desc && !was_unknown_rr_format &&
ldns_rr_rd_count(
new) < r_min) {
625 uint32_t default_ttl,
ldns_rdf *origin,
628 return ldns_rr_new_frm_str_internal(newrr,
640 return ldns_rr_new_frm_str_internal(newrr,
695 if (strncmp(line,
"$ORIGIN", 7) == 0 && isspace(line[7])) {
701 while (isspace(line[offset])) {
712 }
else if (strncmp(line,
"$TTL", 4) == 0 && isspace(line[4])) {
714 while (isspace(line[offset])) {
721 }
else if (strncmp(line,
"$INCLUDE", 8) == 0) {
724 if (origin && *origin) {
785 if (position < rd_count) {
924 assert(count <= rr_list->_rr_capacity);
932 return rr_list->
_rrs[nr];
942 if(!rr_list)
return NULL;
991 for(i = 0; i < r_rr_count; i++) {
1024 for(i = 0; i < l_rr_count; i++) {
1029 for(i = 0; i < r_rr_count; i++) {
1080 if(rr_count+1 > cap) {
1090 rr_list->
_rrs = rrs;
1124 if (rr_count == 0) {
1242 if (rr_count == 0) {
1268 for(i = 0; i < rr_count; i++) {
1428 ldns_rr *canonical_a, *canonical_b;
1483 if(!sortables)
return;
1484 for (i = 0; i < item_count; i++) {
1503 for (i = 0; i < item_count; i++) {
1521 assert(rr1 !=
NULL);
1522 assert(rr2 !=
NULL);
1546 if (offset > rr1_len || offset > rr2_len) {
1547 if (rr1_len == rr2_len) {
1550 return ((
int) rr2_len - (
int) rr1_len);
1558 size_t rr1_len, rr2_len, min_len,
i, offset;
1560 rr1_len = ldns_buffer_capacity(rr1_buf);
1561 rr2_len = ldns_buffer_capacity(rr2_buf);
1566 while (offset < rr1_len && *ldns_buffer_at(rr1_buf, offset) != 0) {
1567 offset += *ldns_buffer_at(rr1_buf, offset) + 1;
1572 min_len = (rr1_len < rr2_len) ? rr1_len : rr2_len;
1574 for(i = offset; i < min_len; i++) {
1575 if (*ldns_buffer_at(rr1_buf,i) < *ldns_buffer_at(rr2_buf,i)) {
1577 }
else if (*ldns_buffer_at(rr1_buf,i) > *ldns_buffer_at(rr2_buf,i)) {
1583 if (rr1_len < rr2_len) {
1585 }
else if (rr1_len > rr2_len) {
1597 size_t rr1_len, rr2_len;
1639 ldns_rr_compare_ds_dnskey(
ldns_rr *ds,
1643 bool result =
false;
1646 if (!dnskey || !ds ||
1678 result = ldns_rr_compare_ds_dnskey(rr1, rr2);
1681 result = ldns_rr_compare_ds_dnskey(rr2, rr1);
1698 assert(rrl1 !=
NULL);
1699 assert(rrl2 !=
NULL);
1817 LDNS_RDF_TYPE_PERIOD
1953 LDNS_RDF_TYPE_INT16_DATA
2288 #define LDNS_RDATA_FIELD_DESCRIPTORS_COUNT \
2289 (sizeof(rdata_field_descriptors)/sizeof(rdata_field_descriptors[0]))
2296 return &rdata_field_descriptors[type];
2302 if (rdata_field_descriptors[i]._type == type) {
2303 return &rdata_field_descriptors[
i];
2306 return &rdata_field_descriptors[0];
2339 assert(descriptor !=
NULL);
2340 assert(index < descriptor->_maximum
2342 if (index < descriptor->_maximum) {
2353 const char *desc_name;
2357 if (strlen(name) > 4 && strncasecmp(name,
"TYPE", 4) == 0) {
2358 return atoi(name + 4);
2363 desc = &rdata_field_descriptors[
i];
2364 desc_name = desc->
_name;
2366 strlen(name) == strlen(desc_name) &&
2367 strncasecmp(name, desc_name, strlen(desc_name)) == 0) {
2374 if (strlen(name) == 4 && strncasecmp(name,
"IXFR", 4) == 0) {
2376 }
else if (strlen(name) == 4 && strncasecmp(name,
"AXFR", 4) == 0) {
2378 }
else if (strlen(name) == 5 && strncasecmp(name,
"MAILB", 5) == 0) {
2380 }
else if (strlen(name) == 5 && strncasecmp(name,
"MAILA", 5) == 0) {
2382 }
else if (strlen(name) == 3 && strncasecmp(name,
"ANY", 3) == 0) {
2395 if (strlen(name) > 5 && strncasecmp(name,
"CLASS", 5) == 0) {
2396 return atoi(name + 5);
ldns_rdf * ldns_rr_rdf(const ldns_rr *rr, size_t nr)
returns the rdata field member counter.
implementation of buffers to ease operations
mailbox or mail list information
ldns_rr_list * ldns_rr_list_new()
creates a new rr_list structure.
bool ldns_is_rrset(ldns_rr_list *rr_list)
checks if an rr_list is a rrset.
ldns_rdf * ldns_rr_set_rdf(ldns_rr *rr, const ldns_rdf *f, size_t position)
sets a rdf member, it will be set on the position given.
ldns_rr * ldns_rr_clone(const ldns_rr *rr)
clones a rr and all its data
void ldns_rdf_deep_free(ldns_rdf *rd)
frees a rdf structure and frees the data.
void ldns_rr_set_rd_count(ldns_rr *rr, size_t count)
sets the rd_count in the rr.
void ldns_rr_set_type(ldns_rr *rr, ldns_rr_type rr_type)
sets the type in the rr.
uint8_t ldns_dname_label_count(const ldns_rdf *r)
count the number of labels inside a LDNS_RDF_DNAME type rdf.
bool ldns_rr_compare_ds(const ldns_rr *orr1, const ldns_rr *orr2)
returns true of the given rr's are equal.
void ldns_rr2canonical(ldns_rr *rr)
converts each dname in a rr to its canonical form.
the canonical name for an alias
bool ldns_rr_set_push_rr(ldns_rr_list *rr_list, ldns_rr *rr)
pushes an rr to an rrset (which really are rr_list's).
ldns_rr_type ldns_rdf2rr_type(const ldns_rdf *rd)
convert an rdf of type LDNS_RDF_TYPE_TYPE to an actual LDNS_RR_TYPE.
int ldns_dname_compare(const ldns_rdf *dname1, const ldns_rdf *dname2)
Compares the two dname rdf's according to the algorithm for ordering in RFC4034 Section 6...
enum ldns_enum_rr_class ldns_rr_class
bool ldns_rr_list_push_rr(ldns_rr_list *rr_list, const ldns_rr *rr)
pushes an rr to an rrlist.
bool ldns_rr_list_contains_rr(const ldns_rr_list *rr_list, ldns_rr *rr)
returns true if the given rr is one of the rrs in the list, or if it is equal to one ...
List or Set of Resource Records.
bool ldns_rr_is_question(const ldns_rr *rr)
returns the question flag of an rr structure.
uint8_t ldns_rdf2native_int8(const ldns_rdf *rd)
returns the native uint8_t representation from the rdf.
#define LDNS_RDATA_FIELD_DESCRIPTORS_COUNT
computes the number of rdata fields
ldns_rdf_type ldns_rr_descriptor_field_type(const ldns_rr_descriptor *descriptor, size_t index)
returns the rdf type for the given rdata field number of the rr type for the given descriptor...
#define LDNS_XMALLOC(type, count)
size_t ldns_rdf_size(const ldns_rdf *rd)
returns the size of the rdf.
enum ldns_enum_hash ldns_hash
void ldns_rr_list_deep_free(ldns_rr_list *rr_list)
frees an rr_list structure and all rrs contained therein.
void ldns_buffer_free(ldns_buffer *buffer)
frees the buffer.
ldns_rr_class _rr_class
Class of the resource record.
ldns_rr_list * ldns_rr_list_subtype_by_rdf(ldns_rr_list *l, ldns_rdf *r, size_t pos)
Return the rr_list which matches the rdf at position field.
ldns_rr * ldns_rr_new_frm_type(ldns_rr_type t)
creates a new rr structure, based on the given type.
ldns_rdf * ldns_rdf_clone(const ldns_rdf *rd)
clones a rdf structure.
http://www.jhsoft.com/rfc/af-saa-0069.000.rtf
void ldns_dname2canonical(const ldns_rdf *rd)
Put a dname into canonical fmt - ie.
uint8_t _maximum
Maximum number of rdata fields in the RRs of this type.
int qsort_rr_compare(const void *a, const void *b)
size_t ldns_rr_rd_count(const ldns_rr *rr)
returns the rd_count of an rr structure.
#define LDNS_MAX_PACKETLEN
void ldns_rr_free(ldns_rr *rr)
frees an RR structure
ldns_lookup_table ldns_rr_classes[]
rr types
ssize_t ldns_bget_token(ldns_buffer *b, char *token, const char *delim, size_t limit)
returns a token/char from the buffer b.
ldns_rr_type ldns_get_rr_type_by_name(const char *name)
retrieves a rrtype by looking up its name.
int qsort_schwartz_rr_compare(const void *a, const void *b)
void ldns_rr_list_free(ldns_rr_list *rr_list)
frees an rr_list structure.
size_t ldns_rr_uncompressed_size(const ldns_rr *r)
calculates the uncompressed size of an RR.
#define LDNS_XREALLOC(ptr, type, count)
const ldns_rr_descriptor * ldns_rr_descript(uint16_t type)
returns the resource record descriptor for the given rr type.
a mailbox domain name (EXPERIMENTAL)
size_t _rd_count
Number of data fields.
ldns_status ldns_rr_new_frm_str(ldns_rr **newrr, const char *str, uint32_t default_ttl, ldns_rdf *origin, ldns_rdf **prev)
creates an rr from a string.
Including this file will include all ldns files, and define some lookup tables.
ldns_rdf * ldns_dname_new_frm_str(const char *str)
creates a new dname rdf from a string.
marks the start of a zone of authority
uint8_t * ldns_rdf_data(const ldns_rdf *rd)
returns the data of the rdf.
ldns_rr * ldns_rr_list_rr(const ldns_rr_list *rr_list, size_t nr)
returns a specific rr of an rrlist.
void ldns_rr_set_class(ldns_rr *rr, ldns_rr_class rr_class)
sets the class in the rr.
enum ldns_enum_rdf_type ldns_rdf_type
void ldns_rdf_set_type(ldns_rdf *rd, ldns_rdf_type type)
sets the size of the rdf.
ldns_rdf_type _variable
Special rdf types.
void ldns_rr_set_question(ldns_rr *rr, bool question)
#define LDNS_MAX_DOMAINLEN
Maximum length of a complete dname.
bogus section, if not interested
ldns_rr * ldns_rr_list_pop_rr(ldns_rr_list *rr_list)
pops the last rr from an rrlist.
variable length any type rdata where the length is specified by the first 2 bytes ...
uint16_t ldns_rdf2native_int16(const ldns_rdf *rd)
returns the native uint16_t representation from the rdf.
Structure to do a Schwartzian-like transformation, for instance when sorting.
ldns_rdf * ldns_rr_pop_rdf(ldns_rr *rr)
removes a rd_field member, it will be popped from the last position.
ldns_rr * ldns_rr_set_pop_rr(ldns_rr_list *rr_list)
pops the last rr from an rrset.
ldns_status ldns_rr2buffer_wire_canonical(ldns_buffer *buffer, const ldns_rr *rr, int section)
Copies the rr data to the buffer in wire format, in canonical format according to RFC3597 (every dnam...
size_t ldns_rr_descriptor_maximum(const ldns_rr_descriptor *descriptor)
returns the maximum number of rdata fields of the rr type this descriptor describes.
bool ldns_rr_list_push_rr_list(ldns_rr_list *rr_list, const ldns_rr_list *push_list)
pushes an rr_list to an rrlist.
a well known service description
ldns_rdf * ldns_rdf_new_frm_str(ldns_rdf_type type, const char *str)
creates a new rdf from a string.
ldns_status ldns_dname_cat(ldns_rdf *rd1, ldns_rdf *rd2)
concatenates rd2 after rd1 (rd2 is copied, rd1 is modified)
dnsind-kitchen-sink-02.txt
ldns_status ldns_rr2buffer_wire(ldns_buffer *buffer, const ldns_rr *rr, int section)
Copies the rr data to the buffer in wire format.
Contains all information about resource record types.
int ldns_rr_compare(const ldns_rr *rr1, const ldns_rr *rr2)
compares two rrs.
draft-ietf-dnsext-delegation
void ldns_rr_list_set_rr_count(ldns_rr_list *rr_list, size_t count)
sets the number of rr's in an rr_list.
#define LDNS_RDATA_FIELD_DESCRIPTORS_COMMON
ldns_rr_list * ldns_rr_list_clone(const ldns_rr_list *rrlist)
clones an rrlist.
ldns_rr_list * ldns_rr_list_pop_rr_list(ldns_rr_list *rr_list, size_t howmany)
pops an rr_list of size s from an rrlist.
ldns_rdf * ldns_rr_list_owner(const ldns_rr_list *rr_list)
Returns the owner domain name rdf of the first element of the RR If there are no elements present...
ssize_t ldns_fget_token_l(FILE *f, char *token, const char *delim, size_t limit, int *line_nr)
returns a token/char from the stream F.
ldns_rr_list * ldns_rr_list_cat_clone(ldns_rr_list *left, ldns_rr_list *right)
concatenates two ldns_rr_lists together, but makes clones of the rr's (instead of pointer copying)...
ldns_rdf_type ldns_rdf_get_type(const ldns_rdf *rd)
returns the type of the rdf.
void ldns_rr_set_owner(ldns_rr *rr, ldns_rdf *owner)
sets the owner in the rr structure.
ldns_rr * ldns_rr_list_set_rr(ldns_rr_list *rr_list, const ldns_rr *r, size_t count)
set a rr on a specific index in a ldns_rr_list
ldns_rr_type ldns_rr_get_type(const ldns_rr *rr)
returns the type of the rr.
ldns_rr_list * ldns_rr_list_pop_rrset(ldns_rr_list *rr_list)
pops the first rrset from the list, the list must be sorted, so that all rr's from each rrset are nex...
uint32_t ldns_str2period(const char *nptr, const char **endptr)
converts a ttl value (like 5d2h) to a long.
int ldns_rr_compare_no_rdata(const ldns_rr *rr1, const ldns_rr *rr2)
compares two rrs, up to the rdata.
draft-ietf-nimrod-dns-01.txt
nsec3 base32 string (with length byte on wire
a mail group member (EXPERIMENTAL)
void ldns_rr_set_ttl(ldns_rr *rr, uint32_t ttl)
sets the ttl in the rr structure.
enum ldns_enum_status ldns_status
a mail destination (Obsolete - use MX)
#define LDNS_MALLOC(type)
Memory management macros.
bool ldns_dname_str_absolute(const char *dname_str)
Checks whether the given dname string is absolute (i.e.
ldns_buffer * ldns_buffer_new(size_t capacity)
creates a new buffer with the specified capacity.
A general purpose lookup table.
#define LDNS_PARSE_SKIP_SPACE
ldns_status ldns_rr_new_frm_fp_l(ldns_rr **newrr, FILE *fp, uint32_t *default_ttl, ldns_rdf **origin, ldns_rdf **prev, int *line_nr)
creates a new rr from a file containing a string.
ldns_rdf * _owner
Owner name, uncompressed.
size_t ldns_rr_descriptor_minimum(const ldns_rr_descriptor *descriptor)
returns the minimum number of rdata fields of the rr type this descriptor describes.
int ldns_hexstring_to_data(uint8_t *data, const char *str)
Converts a hex string to binary data.
uint8_t _minimum
Minimum number of rdata fields in the RRs of this type.
bool ldns_rr_push_rdf(ldns_rr *rr, const ldns_rdf *f)
sets rd_field member, it will be placed in the next available spot.
a mail rename domain name (EXPERIMENTAL)
uint32_t _ttl
Time to live.
Resource record data field.
ldns_lookup_table * ldns_lookup_by_name(ldns_lookup_table *table, const char *name)
uint8_t ldns_rr_label_count(ldns_rr *rr)
counts the number of labels of the ownername.
ldns_rr_class ldns_get_rr_class_by_name(const char *name)
retrieves a class by looking up its name.
ldns_rdf * ldns_rr_owner(const ldns_rr *rr)
returns the owner name of an rr structure.
ldns_rr * ldns_rr_new(void)
creates a new rr structure.
ldns_status ldns_rr_new_question_frm_str(ldns_rr **newrr, const char *str, ldns_rdf *origin, ldns_rdf **prev)
creates an rr for the question section from a string, i.e.
size_t ldns_rr_list_rr_count(const ldns_rr_list *rr_list)
returns the number of rr's in an rr_list.
void * transformed_object
enum ldns_enum_rr_type ldns_rr_type
const char * _name
Textual name of the RR type.
an authoritative name server
ldns_rdf ** _rdata_fields
The array of rdata's.
signed char _rr_question
question rr [it would be nicer if thous is after _rd_count] ABI change: Fix this in next major releas...
void ldns_rr_list2canonical(ldns_rr_list *rr_list)
converts each dname in each rr in a rr_list to its canonical form.
int ldns_rr_list_compare(const ldns_rr_list *rrl1, const ldns_rr_list *rrl2)
compares two rr listss.
uint32_t ldns_rr_ttl(const ldns_rr *rr)
returns the ttl of an rr structure.
ldns_rr_type ldns_rr_list_type(const ldns_rr_list *rr_list)
Returns the type of the first element of the RR If there are no elements present, 0 is returned...
#define LDNS_SYNTAX_DATALEN
ldns_rr_class ldns_rr_get_class(const ldns_rr *rr)
returns the class of the rr.
draft-ietf-dnsop-trust-history
bool ldns_rr_list_cat(ldns_rr_list *left, ldns_rr_list *right)
concatenates two ldns_rr_lists together.
void ldns_buffer_new_frm_data(ldns_buffer *buffer, void *data, size_t size)
creates a buffer with the specified data.
#define LDNS_RR_OVERHEAD
The bytes TTL, CLASS and length use up in an rr.
ldns_rr_type _rr_type
the type of the RR.
void ldns_rr_list_sort(ldns_rr_list *unsorted)
sorts an rr_list (canonical wire format).
draft-ietf-nimrod-dns-01.txt
int ldns_rdf_compare(const ldns_rdf *rd1, const ldns_rdf *rd2)
compares two rdf's on their wire formats.
ldns_status ldns_rr_new_frm_fp(ldns_rr **newrr, FILE *fp, uint32_t *ttl, ldns_rdf **origin, ldns_rdf **prev)
creates a new rr from a file containing a string.
a mail forwarder (Obsolete - use MX)
ldns_status ldns_wire2rdf(ldns_rr *rr, const uint8_t *wire, size_t max, size_t *pos)
converts the data on the uint8_t bytearray (in wire format) to DNS rdata fields, and adds them to the...
int ldns_rr_compare_wire(ldns_buffer *rr1_buf, ldns_buffer *rr2_buf)
compares the wireformat of two rrs, contained in the given buffers.
ldns_rr_type _type
Type of the RR that is described here.
const ldns_rdf_type * _wireformat
Wireformat specification for the rr, i.e.
ldns_rr * ldns_key_rr2ds(const ldns_rr *key, ldns_hash h)
returns a new DS rr that represents the given key rr.