]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
added bit_set function
authorJelte Jansen <jeltejan@NLnetLabs.nl>
Tue, 16 Aug 2005 13:28:56 +0000 (13:28 +0000)
committerJelte Jansen <jeltejan@NLnetLabs.nl>
Tue, 16 Aug 2005 13:28:56 +0000 (13:28 +0000)
added last (?) str2host stuff
made frm_fp framework to know line nr (for errors and debugging)

15 files changed:
higher.c
keys.c
ldns/higher.h
ldns/keys.h
ldns/parse.h
ldns/rdata.h
ldns/resolver.h
ldns/rr.h
ldns/util.h.in
ldns/zone.h
parse.c
rdata.c
resolver.c
rr.c
zone.c

index b76caee48af1a2fd65b050af162fb17c06fb2a7d..454b8e6536b44c9e46540a85f71d2846de9be8b0 100644 (file)
--- 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 fae84150f44d8e6c839f461a77effbe21cff9cfe..12845a95c348395b0235ae6170a9d937da3a6abb 100644 (file)
--- 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();
index 359e395381dcc71597acd2a52dfbe4bc7fce23a7..35135a49781ce71d125810cc8d0803f51382cbaf 100644 (file)
@@ -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 
index be5272d27707af5814ac642e7dba79c9c2ce33a0..f20009cd25cab7cb9167acfcbf45704600f66d55 100644 (file)
@@ -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);
index b07546c5d7be57db75a8cf7308f51190a69dc9e9..7f31cd6551c88e32e85d1c137a05a7b29d1d9fa1 100644 (file)
@@ -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 */
index 956f9df1f5fae56b071d94dcf52afb7572332d9e..242efef6331185c2ce760dab5f3dcc97868a4700 100644 (file)
@@ -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 */
 
 /**
index e5398b3d5f79396f9107a1c291837c9336671811..8f5070cd8d0cb63c4ce4bede05d9a3f4ca7d1acb 100644 (file)
@@ -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
index d7d83888103b70b9af85a3a04344e29ab6760b48..4ae1b93226e3a4bd7e46a6302b1adfb2301ec8c1 100644 (file)
--- 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
index a86c340b457e025b4badae479c41155050686354..4f0a81db385852767b862effa61c8a3b7d1075a7 100644 (file)
@@ -13,6 +13,8 @@
 #ifndef _UTIL_H
 #define _UTIL_H
 
+#include <stdbool.h>
+
 #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)
index 70f8e03f37f85032c8868824a36942056ac3aecd..0abfb7b69bef49acaf64f5f0f750e8bcddae5756 100644 (file)
@@ -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 71b274df31352ea045260e59e8b42e3cba41718c..d62d421066efb1b494089f69adeab8e5962f609a 100644 (file)
--- 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 21cb96aecaccaba9f28079fc1ed6ca4568fb2b1c..1611b3af0bb8d6c5d713c4bc1c755927dc7b730a 100644 (file)
--- 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;
        }
index 324164e967d306c47c29dd90e3d091833133816d..15c954c1678d82af386a44b69e0c5ba85dcf02a7 100644 (file)
@@ -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 94df025dcbe8425febfa2900ce85494123980504..25b490f3cc759deb940349cb8000b95a9564a3f8 100644 (file)
--- 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 64626b5408847d8ffd12c03f59ce06edd40b79d9..5dc6a99f7ce5c54ff03a7d6bab8ff4d5f3c60ae7 100644 (file)
--- 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");
                }