From: Jelte Jansen Date: Tue, 16 Aug 2005 13:28:56 +0000 (+0000) Subject: added bit_set function X-Git-Tag: release-1.0.0~279 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84fdcc25fce18e5d8475850a330bef5eaf3cfeb5;p=thirdparty%2Fldns.git added bit_set function added last (?) str2host stuff made frm_fp framework to know line nr (for errors and debugging) --- diff --git a/higher.c b/higher.c index b76caee4..454b8e65 100644 --- a/higher.c +++ b/higher.c @@ -102,6 +102,12 @@ ldns_get_rr_list_name_by_addr(ldns_resolver *res, ldns_rdf *addr, ldns_rr_class /* read a line, put it in a buffer, parse the buffer */ ldns_rr_list * ldns_get_rr_list_hosts_frm_fp(FILE *fp) +{ + return ldns_get_rr_list_hosts_frm_fp_l(fp, NULL); +} + +ldns_rr_list * +ldns_get_rr_list_hosts_frm_fp_l(FILE *fp, int *line_nr) { ssize_t i, j; size_t cnt; @@ -125,9 +131,9 @@ ldns_get_rr_list_hosts_frm_fp(FILE *fp) list = ldns_rr_list_new(); rr = NULL; - for(i = ldns_fget_token(fp, line, "\n", 0); + for(i = ldns_fget_token_l(fp, line, "\n", 0, line_nr); i > 0; - i = ldns_fget_token(fp, line, "\n", 0)) + i = ldns_fget_token_l(fp, line, "\n", 0, line_nr)) { /* # is comment */ if (line[0] == '#') { diff --git a/keys.c b/keys.c index fae84150..12845a95 100644 --- a/keys.c +++ b/keys.c @@ -59,6 +59,12 @@ ldns_key_new() ldns_key * ldns_key_new_frm_fp(FILE *fp) +{ + return ldns_key_new_frm_fp_l(fp, NULL); +} + +ldns_key * +ldns_key_new_frm_fp_l(FILE *fp, int *line_nr) { ldns_key *k; char *d; @@ -81,8 +87,8 @@ ldns_key_new_frm_fp(FILE *fp) */ /* get the key format version number */ - if (ldns_fget_keyword_data(fp, "Private-key-format", ": ", d, "\n", - LDNS_MAX_LINELEN) == -1) { + if (ldns_fget_keyword_data_l(fp, "Private-key-format", ": ", d, "\n", + LDNS_MAX_LINELEN, line_nr) == -1) { /* no version information */ return NULL; } @@ -93,8 +99,8 @@ ldns_key_new_frm_fp(FILE *fp) /* get the algorithm type, our file function strip ( ) so there are * not in the return string! */ - if (ldns_fget_keyword_data(fp, "Algorithm", ": ", d, "\n", - LDNS_MAX_LINELEN) == -1) { + if (ldns_fget_keyword_data_l(fp, "Algorithm", ": ", d, "\n", + LDNS_MAX_LINELEN, line_nr) == -1) { /* no version information */ return NULL; } @@ -120,12 +126,12 @@ ldns_key_new_frm_fp(FILE *fp) case LDNS_SIGN_RSASHA1: ldns_key_set_algorithm(k, alg); - ldns_key_set_rsa_key(k, ldns_key_new_frm_fp_rsa(fp)); + ldns_key_set_rsa_key(k, ldns_key_new_frm_fp_rsa_l(fp, line_nr)); break; case LDNS_SIGN_DSA: ldns_key_set_algorithm(k, alg); - ldns_key_set_dsa_key(k, ldns_key_new_frm_fp_dsa(fp)); + ldns_key_set_dsa_key(k, ldns_key_new_frm_fp_dsa_l(fp, line_nr)); break; } @@ -140,6 +146,12 @@ ldns_key_new_frm_fp(FILE *fp) RSA * ldns_key_new_frm_fp_rsa(FILE *f) +{ + return ldns_key_new_frm_fp_rsa_l(f, NULL); +} + +RSA * +ldns_key_new_frm_fp_rsa_l(FILE *f, int *line_nr) { /* we parse * Modulus: @@ -183,7 +195,7 @@ ldns_key_new_frm_fp_rsa(FILE *f) */ /* Modules, rsa->n */ - if (ldns_fget_keyword_data(f, "Modulus", ": ", d, "\n", LDNS_MAX_LINELEN) == -1) { + if (ldns_fget_keyword_data_l(f, "Modulus", ": ", d, "\n", LDNS_MAX_LINELEN, line_nr) == -1) { goto error; } i = b64_pton((const char*)d, buf, b64_ntop_calculate_size(strlen(d))); @@ -193,7 +205,7 @@ ldns_key_new_frm_fp_rsa(FILE *f) } /* PublicExponent, rsa->e */ - if (ldns_fget_keyword_data(f, "PublicExponent", ": ", d, "\n", LDNS_MAX_LINELEN) == -1) { + if (ldns_fget_keyword_data_l(f, "PublicExponent", ": ", d, "\n", LDNS_MAX_LINELEN, line_nr) == -1) { goto error; } i = b64_pton((const char*)d, buf, b64_ntop_calculate_size(strlen(d))); @@ -203,7 +215,7 @@ ldns_key_new_frm_fp_rsa(FILE *f) } /* PrivateExponent, rsa->d */ - if (ldns_fget_keyword_data(f, "PrivateExponent", ": ", d, "\n", LDNS_MAX_LINELEN) == -1) { + if (ldns_fget_keyword_data_l(f, "PrivateExponent", ": ", d, "\n", LDNS_MAX_LINELEN, line_nr) == -1) { goto error; } i = b64_pton((const char*)d, buf, b64_ntop_calculate_size(strlen(d))); @@ -213,7 +225,7 @@ ldns_key_new_frm_fp_rsa(FILE *f) } /* Prime1, rsa->p */ - if (ldns_fget_keyword_data(f, "Prime1", ": ", d, "\n", LDNS_MAX_LINELEN) == -1) { + if (ldns_fget_keyword_data_l(f, "Prime1", ": ", d, "\n", LDNS_MAX_LINELEN, line_nr) == -1) { goto error; } i = b64_pton((const char*)d, buf, b64_ntop_calculate_size(strlen(d))); @@ -223,7 +235,7 @@ ldns_key_new_frm_fp_rsa(FILE *f) } /* Prime2, rsa->q */ - if (ldns_fget_keyword_data(f, "Prime2", ": ", d, "\n", LDNS_MAX_LINELEN) == -1) { + if (ldns_fget_keyword_data_l(f, "Prime2", ": ", d, "\n", LDNS_MAX_LINELEN, line_nr) == -1) { goto error; } i = b64_pton((const char*)d, buf, b64_ntop_calculate_size(strlen(d))); @@ -233,7 +245,7 @@ ldns_key_new_frm_fp_rsa(FILE *f) } /* Exponent1, rsa->dmp1 */ - if (ldns_fget_keyword_data(f, "Exponent1", ": ", d, "\n", LDNS_MAX_LINELEN) == -1) { + if (ldns_fget_keyword_data_l(f, "Exponent1", ": ", d, "\n", LDNS_MAX_LINELEN, line_nr) == -1) { goto error; } i = b64_pton((const char*)d, buf, b64_ntop_calculate_size(strlen(d))); @@ -243,7 +255,7 @@ ldns_key_new_frm_fp_rsa(FILE *f) } /* Exponent2, rsa->dmq1 */ - if (ldns_fget_keyword_data(f, "Exponent2", ": ", d, "\n", LDNS_MAX_LINELEN) == -1) { + if (ldns_fget_keyword_data_l(f, "Exponent2", ": ", d, "\n", LDNS_MAX_LINELEN, line_nr) == -1) { goto error; } i = b64_pton((const char*)d, buf, b64_ntop_calculate_size(strlen(d))); @@ -253,7 +265,7 @@ ldns_key_new_frm_fp_rsa(FILE *f) } /* Coefficient, rsa->iqmp */ - if (ldns_fget_keyword_data(f, "Coefficient", ": ", d, "\n", LDNS_MAX_LINELEN) == -1) { + if (ldns_fget_keyword_data_l(f, "Coefficient", ": ", d, "\n", LDNS_MAX_LINELEN, line_nr) == -1) { goto error; } i = b64_pton((const char*)d, buf, b64_ntop_calculate_size(strlen(d))); @@ -274,9 +286,17 @@ error: DSA * ldns_key_new_frm_fp_dsa(FILE *f) +{ + return ldns_key_new_frm_fp_dsa_l(f, NULL); +} + +DSA * +ldns_key_new_frm_fp_dsa_l(FILE *f, int *line_nr) { char *d; DSA *dsa; + line_nr = line_nr; + /* not impl apparently */ d = LDNS_XMALLOC(char, LDNS_MAX_LABELLEN); dsa = DSA_new(); diff --git a/ldns/higher.h b/ldns/higher.h index 359e3953..35135a49 100644 --- a/ldns/higher.h +++ b/ldns/higher.h @@ -48,6 +48,16 @@ ldns_rr_list *ldns_get_rr_list_name_by_addr(ldns_resolver *r, ldns_rdf *addr, ld */ ldns_rr_list *ldns_get_rr_list_hosts_frm_fp(FILE *fp); +/** + * wade through fp (a /etc/hosts like file) + * and return a rr_list containing all the + * defined hosts in there + * \param[in] fp the file pointer to use + * \param[in] line_nr pointer to an integer containing the current line number (for debugging purposes) + * \return ldns_rr_list * with the names + */ +ldns_rr_list *ldns_get_rr_list_hosts_frm_fp_l(FILE *fp, int *line_nr); + /** * wade through fp (a /etc/hosts like file) * and return a rr_list containing all the diff --git a/ldns/keys.h b/ldns/keys.h index be5272d2..f20009cd 100644 --- a/ldns/keys.h +++ b/ldns/keys.h @@ -116,6 +116,16 @@ ldns_key *ldns_key_new_frm_algorithm(ldns_signing_algorithm a, uint16_t size); */ ldns_key *ldns_key_new_frm_fp(FILE *fp); +/** + * creates a new priv key based on the + * contents of the file pointed by fp + * + * \param[in] fp the file pointer to use + * \param[in] line_nr pointer to an integer containing the current line number (for debugging purposes) + * \return a new ldns_key structure with the key + */ +ldns_key *ldns_key_new_frm_fp_l(FILE *fp, int *line_nr); + /** * frm_fp helper function. This function parsed the * remainder of the (RSA) priv. key file generated from bind9 @@ -123,6 +133,16 @@ ldns_key *ldns_key_new_frm_fp(FILE *fp); * \return NULL on failure otherwise a RSA structure */ RSA *ldns_key_new_frm_fp_rsa(FILE *fp); + +/** + * frm_fp helper function. This function parsed the + * remainder of the (RSA) priv. key file generated from bind9 + * \param[in] fp the file to parse + * \param[in] line_nr pointer to an integer containing the current line number (for debugging purposes) + * \return NULL on failure otherwise a RSA structure + */ +RSA *ldns_key_new_frm_fp_rsa_l(FILE *fp, int *line_nr); + /** * frm_fp helper function. This function parsed the * remainder of the (DSA) priv. key file generated from bind9 @@ -131,6 +151,15 @@ RSA *ldns_key_new_frm_fp_rsa(FILE *fp); */ DSA *ldns_key_new_frm_fp_dsa(FILE *fp); +/** + * frm_fp helper function. This function parsed the + * remainder of the (DSA) priv. key file generated from bind9 + * \param[in] fp the file to parse + * \param[in] line_nr pointer to an integer containing the current line number (for debugging purposes) + * \return NULL on failure otherwise a RSA structure + */ +DSA *ldns_key_new_frm_fp_dsa_l(FILE *fp, int *line_nr); + /* acces write functions */ void ldns_key_set_algorithm(ldns_key *k, ldns_signing_algorithm l); void ldns_key_set_rsa_key(ldns_key *k, RSA *r); diff --git a/ldns/parse.h b/ldns/parse.h index b07546c5..7f31cd65 100644 --- a/ldns/parse.h +++ b/ldns/parse.h @@ -44,12 +44,32 @@ typedef enum ldns_enum_directive ldns_directive; */ ssize_t ldns_fget_token(FILE *f, char *token, const char *delim, size_t limit); +/** + * returns a token/char from the stream F. + * This function deals with ( and ) in the stream, + * and ignores when it finds them. + * \param[in] *f the file to read from + * \param[out] *token the token is put here + * \param[in] *delim chars at which the parsing should stop + * \param[in] *limit how much to read. If 0 use builtin maximum + * \param[in] line_nr pointer to an integer containing the current line number (for debugging purposes) + * \return 0 on error of EOF of F otherwise return the length of what is read + */ +ssize_t ldns_fget_token_l(FILE *f, char *token, const char *delim, size_t limit, int *line_nr); + /* * searches for keyword and delim. Gives everything back * after the keyword + k_del until we hit d_del */ ssize_t ldns_fget_keyword_data(FILE *f, const char *keyword, const char *k_del, char *data, const char *d_del, size_t data_limit); +/* + * searches for keyword and delim. Gives everything back + * after the keyword + k_del until we hit d_del + * \param[in] line_nr pointer to an integer containing the current line number (for debugging purposes) + */ +ssize_t ldns_fget_keyword_data_l(FILE *f, const char *keyword, const char *k_del, char *data, const char *d_del, size_t data_limit, int *line_nr); + /** * returns a token/char from the buffer b. * This function deals with ( and ) in the buffer, @@ -104,4 +124,15 @@ void ldns_bskipcs(ldns_buffer *buffer, const char *s); */ void ldns_fskipcs(FILE *fp, const char *s); + +/** + * skips all of the characters in the given string in the fp, moving + * the position to the first character that is not in *s. + * \param[in] *fp file to use + * \param[in] *s characters to skip + * \param[in] line_nr pointer to an integer containing the current line number (for debugging purposes) + * \return void + */ +void ldns_fskipcs_l(FILE *fp, const char *s, int *line_nr); + #endif /* _LDNS_PARSE_H */ diff --git a/ldns/rdata.h b/ldns/rdata.h index 956f9df1..242efef6 100644 --- a/ldns/rdata.h +++ b/ldns/rdata.h @@ -185,6 +185,15 @@ ldns_rdf *ldns_rdf_new_frm_str(ldns_rdf_type type, const char *str); */ ldns_rdf *ldns_rdf_new_frm_fp(ldns_rdf_type type, FILE *fp); +/** + * creates a new rdf from a file containing a string. + * \param[in] type type to use + * \param[in] fp the file pointer to use + * \param[in] line_nr pointer to an integer containing the current line number (for debugging purposes) + * \return ldns_rdf* + */ +ldns_rdf *ldns_rdf_new_frm_fp_l(ldns_rdf_type type, FILE *fp, int *line_nr); + /* destroy functions */ /** diff --git a/ldns/resolver.h b/ldns/resolver.h index e5398b3d..8f5070cd 100644 --- a/ldns/resolver.h +++ b/ldns/resolver.h @@ -242,6 +242,15 @@ ldns_resolver* ldns_resolver_new(void); */ ldns_resolver* ldns_resolver_new_frm_fp(FILE *fp); +/** + * Create a resolver structure from a file like /etc/resolv.conf + * \param[in] fp file pointer to create new resolver from + * if NULL use /etc/resolv.conf + * \param[in] line_nr pointer to an integer containing the current line number (for debugging purposes) + * \return ldns_resolver structure + */ +ldns_resolver* ldns_resolver_new_frm_fp_l(FILE *fp, int *line_nr); + /** * configure a resolver by means of a resolv.conf file * The file may be NULL in which case there will be diff --git a/ldns/rr.h b/ldns/rr.h index d7d83888..4ae1b932 100644 --- a/ldns/rr.h +++ b/ldns/rr.h @@ -280,6 +280,16 @@ ldns_rr* ldns_rr_new_frm_str(const char *str, uint16_t default_ttl, ldns_rdf *or */ ldns_rr* ldns_rr_new_frm_fp(FILE *fp, uint16_t default_ttl, ldns_rdf *origin); +/** + * creates a new rr from a file containing a string. + * \param[in] fp the file pointer to use + * \param[in] default_ttl a default ttl for the rr. If 0 DEF_TTL will be used + * \param[in] origin when the owner is relative add this + * \param[in] line_nr pointer to an integer containing the current line number (for debugging purposes) + * \return ldns_rr* + */ +ldns_rr* ldns_rr_new_frm_fp_l(FILE *fp, uint16_t default_ttl, ldns_rdf *origin, int *line_nr); + /** * sets the owner in the rr structure. * \param[in] *rr rr to operate on diff --git a/ldns/util.h.in b/ldns/util.h.in index a86c340b..4f0a81db 100644 --- a/ldns/util.h.in +++ b/ldns/util.h.in @@ -13,6 +13,8 @@ #ifndef _UTIL_H #define _UTIL_H +#include + #define dprintf(X,Y) fprintf(stderr, (X), (Y)) /* #define dprintf(X, Y) */ @@ -149,6 +151,18 @@ int ldns_get_bit(uint8_t bits[], size_t index); */ int ldns_get_bit_r(uint8_t bits[], size_t index); +/** + * sets the specified bit in the specified byte to + * 1 if value is true, 0 if false + * The bits are counted from right to left, so bit #0 is the + * right most bit. + * + * \param[in] byte the bit to set the bit in + * \param[in] bit_nr the bit to set (0 <= n <= 7) + * \param[in] value whether to set the bit to 1 or 0 + */ +void ldns_set_bit(uint8_t *byte, int bit_nr, bool value); + /** * Returns the value of a to the power of b * (or 1 of b < 1) diff --git a/ldns/zone.h b/ldns/zone.h index 70f8e03f..0abfb7b6 100644 --- a/ldns/zone.h +++ b/ldns/zone.h @@ -96,6 +96,9 @@ bool ldns_zone_rr_is_glue(ldns_zone *z, ldns_rr *rr); ldns_zone * ldns_zone_new_frm_fp(FILE *fp, ldns_rdf *origin, uint16_t ttl, ldns_rr_class c); +ldns_zone * +ldns_zone_new_frm_fp_l(FILE *fp, ldns_rdf *origin, uint16_t ttl, ldns_rr_class c, int *line_nr); + /** * Frees the allocated memory for the zone, and the rr_list structure in it * \param[in] zone the zone to free diff --git a/parse.c b/parse.c index 71b274df..d62d4210 100644 --- a/parse.c +++ b/parse.c @@ -23,6 +23,13 @@ ldns_lookup_table ldns_directive_types[] = { ssize_t ldns_fget_keyword_data(FILE *f, const char *keyword, const char *k_del, char *data, const char *d_del, size_t data_limit) +{ + return ldns_fget_keyword_data_l(f, keyword, k_del, data, d_del, data_limit, NULL); +} + +ssize_t +ldns_fget_keyword_data_l(FILE *f, const char *keyword, const char *k_del, char *data, + const char *d_del, size_t data_limit, int *line_nr) { /* we assume: keyword|sep|data */ char *fkeyword; @@ -37,7 +44,7 @@ ldns_fget_keyword_data(FILE *f, const char *keyword, const char *k_del, char *da if (strncmp(fkeyword, keyword, LDNS_MAX_KEYWORDLEN - 1) == 0) { /* whee! */ /* printf("%s\n%s\n", "Matching keyword", fkeyword); */ - i = ldns_fget_token(f, data, d_del, data_limit); + i = ldns_fget_token_l(f, data, d_del, data_limit, line_nr); LDNS_FREE(fkeyword); return i; } else { @@ -70,6 +77,12 @@ ldns_fget_all_keyword_data(FILE *f, const char *keyword, const char *k_del, char /* add max_limit here? */ ssize_t ldns_fget_token(FILE *f, char *token, const char *delim, size_t limit) +{ + return ldns_fget_token_l(f, token, delim, limit, NULL); +} + +ssize_t +ldns_fget_token_l(FILE *f, char *token, const char *delim, size_t limit, int *line_nr) { int c; int p; /* 0 -> no parenthese seen, >0 nr of ( seen */ @@ -117,6 +130,9 @@ ldns_fget_token(FILE *f, char *token, const char *delim, size_t limit) /* comments */ com = 0; *t = ' '; + if (line_nr) { + *line_nr = *line_nr + 1; + } continue; } @@ -127,6 +143,9 @@ ldns_fget_token(FILE *f, char *token, const char *delim, size_t limit) if (c == '\n' && p != 0 && t > token) { /* in parentheses */ + if (line_nr) { + *line_nr = *line_nr + 1; + } continue; } @@ -156,7 +175,7 @@ ldns_fget_token(FILE *f, char *token, const char *delim, size_t limit) return (ssize_t)i; tokenread: - ldns_fskipcs(f, delim); + ldns_fskipcs_l(f, delim, line_nr); *t = '\0'; if (p != 0) { return -1; @@ -353,12 +372,21 @@ ldns_fskipc(FILE *fp, char c) void ldns_fskipcs(FILE *fp, const char *s) +{ + ldns_fskipcs_l(fp, s, NULL); +} + +void +ldns_fskipcs_l(FILE *fp, const char *s, int *line_nr) { bool found; char c; const char *d; while ((c = fgetc(fp)) != EOF) { + if (line_nr && c == '\n') { + *line_nr = *line_nr + 1; + } found = false; for (d = s; *d; d++) { if (*d == c) { diff --git a/rdata.c b/rdata.c index 21cb96ae..1611b3af 100644 --- a/rdata.c +++ b/rdata.c @@ -380,6 +380,12 @@ ldns_rdf_new_frm_str(ldns_rdf_type type, const char *str) ldns_rdf * ldns_rdf_new_frm_fp(ldns_rdf_type type, FILE *fp) +{ + return ldns_rdf_new_frm_fp_l(type, fp, NULL); +} + +ldns_rdf * +ldns_rdf_new_frm_fp_l(ldns_rdf_type type, FILE *fp, int *line_nr) { char *line; ldns_rdf *r; @@ -391,7 +397,7 @@ ldns_rdf_new_frm_fp(ldns_rdf_type type, FILE *fp) } /* read an entire line in from the file */ - if ((t = ldns_fget_token(fp, line, LDNS_PARSE_SKIP_SPACE, 0)) == -1) { + if ((t = ldns_fget_token_l(fp, line, LDNS_PARSE_SKIP_SPACE, 0, line_nr)) == -1) { LDNS_FREE(line); return NULL; } diff --git a/resolver.c b/resolver.c index 324164e9..15c954c1 100644 --- a/resolver.c +++ b/resolver.c @@ -470,6 +470,12 @@ ldns_resolver_new(void) ldns_resolver * ldns_resolver_new_frm_fp(FILE *fp) +{ + return ldns_resolver_new_frm_fp_l(fp, NULL); +} + +ldns_resolver * +ldns_resolver_new_frm_fp_l(FILE *fp, int *line_nr) { ldns_resolver *r; const char *keyword[2]; @@ -496,7 +502,7 @@ ldns_resolver_new_frm_fp(FILE *fp) if (!r) { return NULL; } - gtr = ldns_fget_token(fp, word, LDNS_PARSE_NORMAL, 0); + gtr = ldns_fget_token_l(fp, word, LDNS_PARSE_NORMAL, 0, line_nr); while (gtr > 0) { /* do something */ switch(expect) { @@ -550,7 +556,7 @@ ldns_resolver_new_frm_fp(FILE *fp) expect = LDNS_RESOLV_KEYWORD; break; } - gtr = ldns_fget_token(fp, word, LDNS_PARSE_NORMAL, 0); + gtr = ldns_fget_token_l(fp, word, LDNS_PARSE_NORMAL, 0, line_nr); } LDNS_FREE(word); diff --git a/rr.c b/rr.c index 94df025d..25b490f3 100644 --- a/rr.c +++ b/rr.c @@ -366,6 +366,12 @@ 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) +{ + return ldns_rr_new_frm_fp_l(fp, ttl, origin, NULL); +} + +ldns_rr * +ldns_rr_new_frm_fp_l(FILE *fp, uint16_t ttl, ldns_rdf *origin, int *line_nr) { char *line; ldns_rr *rr; @@ -375,8 +381,12 @@ ldns_rr_new_frm_fp(FILE *fp, uint16_t ttl, ldns_rdf *origin) return NULL; } + if (line_nr) { + *line_nr = *line_nr + 1; + } + /* read an entire line in from the file */ - if (ldns_fget_token(fp, line, LDNS_PARSE_SKIP_SPACE, LDNS_MAX_LINELEN) == -1) { + if (ldns_fget_token_l(fp, line, LDNS_PARSE_SKIP_SPACE, LDNS_MAX_LINELEN, line_nr) == -1) { return NULL; } @@ -898,7 +908,7 @@ ldns_rr_list_pop_rrset(ldns_rr_list *rr_list) } if (ldns_rr_list_rr_count(rr_list) > 0) { - next_rr = ldns_rr_list_rr(rr_list, 0); + next_rr = ldns_rr_list_rr(rr_list, ldns_rr_list_rr_count(rr_list) - 1); } else { next_rr = NULL; } @@ -915,7 +925,7 @@ ldns_rr_list_pop_rrset(ldns_rr_list *rr_list) ldns_rr_list_push_rr(rrset, ldns_rr_list_pop_rr(rr_list)); if (ldns_rr_list_rr_count(rr_list) > 0) { last_rr = next_rr; - next_rr = ldns_rr_list_rr(rr_list, 0); + next_rr = ldns_rr_list_rr(rr_list, ldns_rr_list_rr_count(rr_list) - 1); } else { next_rr = NULL; } @@ -923,7 +933,7 @@ ldns_rr_list_pop_rrset(ldns_rr_list *rr_list) next_rr = NULL; } } - + return rrset; } diff --git a/zone.c b/zone.c index 64626b54..5dc6a99f 100644 --- a/zone.c +++ b/zone.c @@ -80,6 +80,12 @@ ldns_zone_new(void) */ ldns_zone * ldns_zone_new_frm_fp(FILE *fp, ldns_rdf *origin, uint16_t ttl, ldns_rr_class c) +{ + return ldns_zone_new_frm_fp_l(fp, origin, ttl, c, NULL); +} + +ldns_zone * +ldns_zone_new_frm_fp_l(FILE *fp, ldns_rdf *origin, uint16_t ttl, ldns_rr_class c, int *line_nr) { ldns_zone *newzone; ldns_rr *rr; @@ -95,14 +101,13 @@ ldns_zone_new_frm_fp(FILE *fp, ldns_rdf *origin, uint16_t ttl, ldns_rr_class c) my_ttl = ttl; my_class = c; - /* read until we got a soa, all crap above is discarded * except $directives */ i = 0; do { - rr = ldns_rr_new_frm_fp(fp, my_ttl, my_origin); + rr = ldns_rr_new_frm_fp_l(fp, my_ttl, my_origin, line_nr); i++; } while (!rr && i <= 9); @@ -124,7 +129,7 @@ ldns_zone_new_frm_fp(FILE *fp, ldns_rdf *origin, uint16_t ttl, ldns_rr_class c) ldns_zone_set_soa(newzone, rr); while(!feof(fp)) { - rr = ldns_rr_new_frm_fp(fp, my_ttl, my_origin); + rr = ldns_rr_new_frm_fp_l(fp, my_ttl, my_origin, line_nr); if (rr) { last_rr = rr; if (!ldns_zone_push_rr(newzone, rr)) { @@ -137,7 +142,14 @@ ldns_zone_new_frm_fp(FILE *fp, ldns_rdf *origin, uint16_t ttl, ldns_rr_class c) my_class = ldns_rr_get_class(rr); } else { - fprintf(stderr, "Error in file, unable to read RR.\nLast rr that was parsed:\n"); + fprintf(stderr, "Error in file, unable to read RR"); + if (line_nr) { + fprintf(stderr, " at line %d.\n", *line_nr); + } else { + fprintf(stderr, "."); + } + + fprintf(stderr, "Last rr that was parsed:\n"); ldns_rr_print(stdout, last_rr); printf("\n"); }