From: Miek Gieben Date: Mon, 12 Dec 2005 20:43:58 +0000 (+0000) Subject: API CHANGE X-Git-Tag: release-1.1.0~523 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9bcd6d1149f7b0dd8e13a24b91de5becbb94690d;p=thirdparty%2Fldns.git API CHANGE add an extra var to these function so that the previous ownername is used when current one hasn't one specified - which is valid zone file syntax --- diff --git a/examples/configure.ac b/examples/configure.ac index e917eee3..8397671b 100644 --- a/examples/configure.ac +++ b/examples/configure.ac @@ -44,15 +44,10 @@ AC_CHECK_HEADER(ldns/dns.h,, [ ], [AC_INCLUDES_DEFAULT] ) -AC_CHECK_LIB(pcap, pcap_open_offline,, [ - AC_MSG_ERROR([Can't find pcap library (needed for dpa)]) - ] -) - -AC_CHECK_HEADER(pcap.h,, [ - AC_MSG_ERROR([Can't find pcap library headers (needed for dpa)]) - ], [AC_INCLUDES_DEFAULT] -) +#AC_CHECK_LIB(pcap, pcap_open_offline,, [ +# AC_MSG_ERROR([Can't find pcap library (needed for dpa)]) +# ] +#) AC_CHECK_FUNCS(isblank) diff --git a/examples/ldns-splitzone.c b/examples/ldns-splitzone.c index 390182be..d5588e56 100644 --- a/examples/ldns-splitzone.c +++ b/examples/ldns-splitzone.c @@ -42,14 +42,15 @@ main(int argc, char **argv) int line_nr; size_t split; size_t i; - bool splitting; + int splitting; size_t file_counter; char filename[255]; progname = strdup(argv[0]); split = 0; - splitting = false; /* when true we are about to split */ + splitting = 0; /* when true we are about to split */ file_counter = 1; + lastname = NULL; while ((c = getopt(argc, argv, "n:")) != -1) { switch(c) { @@ -112,8 +113,27 @@ main(int argc, char **argv) ldns_rr_print(stdout, ldns_rr_list_rr(zrrs, i)); - lastname = ldns_rr_owner(ldns_rr_list_rr(zrrs, i)); + if (i > 0 && (i % split) == 0) { + printf("%d %d\n", i, (i & split)); + splitting = 1; + } + + if (splitting == 1 && + ldns_dname_compare(ldns_rr_owner(ldns_rr_list_rr(zrrs, i)), lastname) == 0) { + /* equal names, don't split yet */ + } else { + /* now we are ready to split */ + splitting = 2; + } + if (splitting == 2) { + /* SPLIT */ + printf("LDNS INTENT TO SPLIT !!!! \n"); + lastname = NULL; + continue; + } + + lastname = ldns_rr_owner(ldns_rr_list_rr(zrrs, i)); } /* fclose(fp); */ diff --git a/higher.c b/higher.c index 9d702c8c..bdb0e921 100644 --- a/higher.c +++ b/higher.c @@ -207,7 +207,7 @@ ldns_get_rr_list_hosts_frm_fp_l(FILE *fp, int *line_nr) } else { snprintf(rr_str, LDNS_MAX_LINELEN, "%s IN A %s", word, addr); } - rr = ldns_rr_new_frm_str(rr_str, 0, NULL); + rr = ldns_rr_new_frm_str(rr_str, 0, NULL, NULL); if (rr) { ldns_rr_list_push_rr(list, ldns_rr_clone(rr)); } @@ -338,7 +338,7 @@ ldns_update_send_simple_addr(const char *fqdn, const char *zone, snprintf(rrstr, rrstrlen, "%s IN %s %s", fqdn, strchr(ipaddr, ':') ? "AAAA" : "A", ipaddr); - up_rr = ldns_rr_new_frm_str(rrstr, ttl, NULL); + up_rr = ldns_rr_new_frm_str(rrstr, ttl, NULL, NULL); if (!up_rr) { ldns_rr_list_deep_free(up_rrlist); free(rrstr); diff --git a/ldns/rdata.h b/ldns/rdata.h index 7c14dd68..a199d1cd 100644 --- a/ldns/rdata.h +++ b/ldns/rdata.h @@ -333,16 +333,6 @@ ldns_status ldns_octet(char *word, size_t *length); */ ldns_rdf *ldns_rdf_clone(const ldns_rdf *rd); -/** - * concatenate two rdfs (of the same type!) together. Left - * is modified in this operation. - * \param[in] left the left part of the new rdf - * \param[in] right the right part of the new rdf - * \return true when it succeeds otherwise false - */ -bool ldns_rdf_cat(ldns_rdf *left, ldns_rdf *right); - - /** * compares two rdf's on their wire formats. * (To order dnames according to rfc4034, use ldns_dname_compare) diff --git a/ldns/rr.h b/ldns/rr.h index bd291471..1497e0aa 100644 --- a/ldns/rr.h +++ b/ldns/rr.h @@ -267,9 +267,11 @@ void ldns_rr_free(ldns_rr *rr); * \param[in] str the string to convert * \param[in] default_ttl pointer to a default ttl for the rr. If 0 DEF_TTL will be used * \param[in] origin when the owner is relative add this + * \param prev the previous ownername. the function overwrite this with + * the current found ownername. * \return the new rr */ -ldns_rr* ldns_rr_new_frm_str(const char *str, uint16_t default_ttl, ldns_rdf *origin); +ldns_rr* ldns_rr_new_frm_str(const char *str, uint16_t default_ttl, ldns_rdf *origin, ldns_rdf **prev); /** * creates a new rr from a file containing a string. @@ -278,9 +280,11 @@ ldns_rr* ldns_rr_new_frm_str(const char *str, uint16_t default_ttl, ldns_rdf *or * the pointer will be updated if the file contains a $TTL directive * \param[in] origin when the owner is relative add this * the pointer will be updated if the file contains a $ORIGIN directive + * \param[in] prev when the owner is whitespaces use this as the * ownername + * the pointer will be updated after the call * \return ldns_rr* */ -ldns_rr* ldns_rr_new_frm_fp(FILE *fp, uint16_t *default_ttl, ldns_rdf **origin); +ldns_rr* ldns_rr_new_frm_fp(FILE *fp, uint16_t *default_ttl, ldns_rdf **origin, ldns_rdf **prev); /** * creates a new rr from a file containing a string. @@ -290,9 +294,11 @@ ldns_rr* ldns_rr_new_frm_fp(FILE *fp, uint16_t *default_ttl, ldns_rdf **origin); * \param[in] origin when the owner is relative add this * the pointer will be updated if the file contains a $ORIGIN directive * \param[in] line_nr pointer to an integer containing the current line number (for debugging purposes) + * \param[in] prev when the owner is whitespaces use this as the * ownername + * the pointer will be updated after the call * \return ldns_rr* */ -ldns_rr* ldns_rr_new_frm_fp_l(FILE *fp, uint16_t *default_ttl, ldns_rdf **origin, int *line_nr); +ldns_rr* ldns_rr_new_frm_fp_l(FILE *fp, uint16_t *default_ttl, ldns_rdf **origin, ldns_rdf **prev, int *line_nr); /** * sets the owner in the rr structure. diff --git a/rdata.c b/rdata.c index ffac0537..41c7283d 100644 --- a/rdata.c +++ b/rdata.c @@ -193,32 +193,6 @@ ldns_rdf_clone(const ldns_rdf *r) ldns_rdf_data(r))); } -/* we modify left! */ -bool -ldns_rdf_cat(ldns_rdf *left, ldns_rdf *right) -{ - uint8_t *d; - size_t new; - - if (ldns_rdf_get_type(left) != ldns_rdf_get_type(right)) { - return false; - } - - d = ldns_rdf_data(left); - new =ldns_rdf_size(left) + ldns_rdf_size(right); - - d = LDNS_XREALLOC(d, uint8_t, new); - if (!d) { - return false; - } - - /* this -1 is ONLY TEST WITH LDNS_RDF_TYPE_DNAME XXX */ - memcpy(d + ldns_rdf_size(left) - 1, ldns_rdf_data(right), ldns_rdf_size(right)); - ldns_rdf_set_size(left, new); - ldns_rdf_set_data(left, d); - return true; -} - void ldns_rdf_deep_free(ldns_rdf *rd) { diff --git a/rr.c b/rr.c index ab16ee90..1ea8bde5 100644 --- a/rr.c +++ b/rr.c @@ -90,7 +90,7 @@ ldns_rr_free(ldns_rr *rr) * miek.nl. IN MX 10 elektron.atoom.net */ ldns_rr * -ldns_rr_new_frm_str(const char *str, uint16_t default_ttl, ldns_rdf *origin) +ldns_rr_new_frm_str(const char *str, uint16_t default_ttl, ldns_rdf *origin, ldns_rdf **prev) { ldns_rr *new; const ldns_rr_descriptor *desc; @@ -153,6 +153,7 @@ ldns_rr_new_frm_str(const char *str, uint16_t default_ttl, ldns_rdf *origin) ldns_rr_free(new); return NULL; } + if (ldns_bget_token(rr_buf, ttl, "\t\n ", 21) == -1) { LDNS_FREE(owner); LDNS_FREE(ttl); @@ -253,7 +254,11 @@ ldns_rr_new_frm_str(const char *str, uint16_t default_ttl, ldns_rdf *origin) } } else { if (strlen(owner) == 0) { - if (origin) { + /* no ownername was given, try prev, if that fails + * origin, else default to root */ + if (prev) { + ldns_rr_set_owner(new, ldns_rdf_clone(*prev)); + } else if (origin) { ldns_rr_set_owner(new, ldns_rdf_clone(origin)); } else { ldns_rr_set_owner(new, ldns_dname_new_frm_str(".")); @@ -272,7 +277,10 @@ ldns_rr_new_frm_str(const char *str, uint16_t default_ttl, ldns_rdf *origin) ldns_buffer_free(rr_buf); ldns_rr_free(new); return NULL; - } + } + } + if (prev) { + *prev = ldns_rr_owner(new); } } } @@ -355,9 +363,8 @@ ldns_rr_new_frm_str(const char *str, uint16_t default_ttl, ldns_rdf *origin) /* check if the origin should be concatenated */ if (ldns_rr_descriptor_field_type(desc, r_cnt) == LDNS_RDF_TYPE_DNAME && rd_strlen > 1 && - rd[rd_strlen - 1] != '.' && - origin) { - if (!ldns_rdf_cat(r, origin)) { + !ldns_dname_str_absolute(rd) && origin) { + if (!ldns_dname_cat(r, origin)) { /* don't know if to quit */ /* return NULL;*/ } @@ -385,13 +392,13 @@ ldns_rr_new_frm_str(const char *str, uint16_t default_ttl, ldns_rdf *origin) } ldns_rr * -ldns_rr_new_frm_fp(FILE *fp, uint16_t *ttl, ldns_rdf **origin) +ldns_rr_new_frm_fp(FILE *fp, uint16_t *ttl, ldns_rdf **origin, ldns_rdf **prev) { - return ldns_rr_new_frm_fp_l(fp, ttl, origin, NULL); + return ldns_rr_new_frm_fp_l(fp, ttl, origin, prev, NULL); } ldns_rr * -ldns_rr_new_frm_fp_l(FILE *fp, uint16_t *default_ttl, ldns_rdf **origin, int *line_nr) +ldns_rr_new_frm_fp_l(FILE *fp, uint16_t *default_ttl, ldns_rdf **origin, ldns_rdf **prev, int *line_nr) { char *line; ldns_rr *rr; @@ -430,11 +437,10 @@ ldns_rr_new_frm_fp_l(FILE *fp, uint16_t *default_ttl, ldns_rdf **origin, int *li *default_ttl = (uint16_t) atoi(keyword + 5); } } else { - if (origin) { - rr = ldns_rr_new_frm_str((const char*) line, ttl, *origin); + rr = ldns_rr_new_frm_str((const char*) line, ttl, *origin, prev); } else { - rr = ldns_rr_new_frm_str((const char*) line, ttl, NULL); + rr = ldns_rr_new_frm_str((const char*) line, ttl, NULL, prev); } } diff --git a/zone.c b/zone.c index 301dba7d..5c3c9014 100644 --- a/zone.c +++ b/zone.c @@ -162,7 +162,7 @@ ldns_zone_new_frm_fp_l(FILE *fp, ldns_rdf *origin, uint16_t ttl, ldns_rr_class c uint16_t my_ttl = ttl; ldns_rr_class my_class = c; ldns_rr *last_rr = NULL; - + ldns_rdf *my_prev = NULL; uint8_t i; newzone = ldns_zone_new(); @@ -180,7 +180,7 @@ ldns_zone_new_frm_fp_l(FILE *fp, ldns_rdf *origin, uint16_t ttl, ldns_rr_class c i = 0; do { - rr = ldns_rr_new_frm_fp_l(fp, &my_ttl, &my_origin, line_nr); + rr = ldns_rr_new_frm_fp_l(fp, &my_ttl, &my_origin, &my_prev, line_nr); i++; } while (!rr && i <= 9); @@ -214,7 +214,7 @@ ldns_zone_new_frm_fp_l(FILE *fp, ldns_rdf *origin, uint16_t ttl, ldns_rr_class c } while(!feof(fp)) { - rr = ldns_rr_new_frm_fp_l(fp, &my_ttl, &my_origin, line_nr); + rr = ldns_rr_new_frm_fp_l(fp, &my_ttl, &my_origin, &my_prev, line_nr); if (rr) { last_rr = rr; if (!ldns_zone_push_rr(newzone, rr)) {