]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
added ldns_fskipcs for FILE*
authorMiek Gieben <miekg@NLnetLabs.nl>
Wed, 13 Apr 2005 10:37:14 +0000 (10:37 +0000)
committerMiek Gieben <miekg@NLnetLabs.nl>
Wed, 13 Apr 2005 10:37:14 +0000 (10:37 +0000)
used that in resolv.conf reader, it now parses open's /etc/resolv.conf
some tweaks
default dprintf to print (for debugging)

buffer.c
ldns/buffer.h
ldns/parse.h
parse.c
resolver.c
run-test18.c
run-test19.c
util.h

index 2467d0725e1162e6cd9ef98d9ab6cdeb4496b8a3..2f8e8dc27229fa0618b2b7d88206a339a3967bfe 100644 (file)
--- a/buffer.c
+++ b/buffer.c
@@ -189,49 +189,3 @@ ldns_bgetc(ldns_buffer *buffer)
        }
        return (int)ldns_buffer_read_u8(buffer);
 }
-
-/* fast forwards the buffer, skipping the given char, setting the
- * buffer position to the location of the first different char
- * (or to the end of the buffer)
- */
-void
-ldns_bskipc(ldns_buffer *buffer, char c)
-{
-       while (c == (char) ldns_buffer_read_u8_at(buffer, ldns_buffer_position(buffer))) {
-               if (ldns_buffer_available_at(buffer, buffer->_position + sizeof(char), sizeof(char))) {
-                       buffer->_position += sizeof(char);
-               } else {
-                       return;
-               }
-       }
-}
-
-/* fast forwards the buffer, skipping all chars in the given string,
- * setting the buffer position to the first char that is not contained
- * in the string (or to the end of the buffer)
- */
-void
-ldns_bskipcs(ldns_buffer *buffer, const char *s)
-{
-       bool found;
-       char c;
-       char *d;
-       
-       while(ldns_buffer_available_at(buffer, buffer->_position, sizeof(char))) {
-               c = (char) ldns_buffer_read_u8_at(buffer,
-                                          buffer->_position);
-               found = false;
-               for (d = (char *) s; *d; d++) {
-                       if (*d == c) {
-                               found = true;
-                       }
-               }
-               if (found && buffer->_limit > buffer->_position) {
-                       buffer->_position += sizeof(char);
-               } else {
-                       return;
-               }
-       }
-}
-
-
index d1937e1a2a3da02aaa773958d4e0b792e80ed98e..38f347266d0e7a8f6bbcffe1d03388dde2b706f4 100644 (file)
@@ -420,17 +420,4 @@ void ldns_buffer_free(ldns_buffer *buffer);
  */
 void *ldns_buffer_export(ldns_buffer *buffer);
 
-/*
- * Get the next character from a buffer. Advance the position
- * pointer with 1.
- * When end of buffer is reached return EOF
- */
-int ldns_bgetc(ldns_buffer *buffer);
-
-/**
- * Skip all of the characters in the given string in the buffer, moving
- * the position to the first character that is not in *s
- */
-void ldns_bskipcs(ldns_buffer *buffer, const char *s);
-
 #endif /* _BUFFER_H_ */
index 86f628efcf3373d337766a73ecad9ef94446681d..b4c4391231622a28477cefd938bc011146d4ffda 100644 (file)
@@ -14,7 +14,7 @@
 #include <ldns/buffer.h>
 
 
-#define LDNS_PARSE_SKIP_SPACE          "\f\n\r\t\v"
+#define LDNS_PARSE_SKIP_SPACE          "\f\n\r\v"
 #define LDNS_PARSE_NORMAL              " \f\n\r\t\v"
 #define MAXLINE_LEN            512
 #define MAXKEYWORD_LEN         32
@@ -61,4 +61,28 @@ ldns_bget_keyword_data(ldns_buffer *b, const char *keyword, const char *k_del, c
  */
 char * ldns_str_remove_comment(char *str);
 
-#endif /*  _PARSE_H_ */
+/*
+ * Get the next character from a buffer. Advance the position
+ * pointer with 1.
+ * When end of buffer is reached return EOF
+ */
+int ldns_bgetc(ldns_buffer *buffer);
+
+/**
+ * Skip all of the characters in the given string in the buffer, moving
+ * the position to the first character that is not in *s
+ */
+void ldns_bskipcs(ldns_buffer *buffer, const char *s);
+
+/**
+ * Skip all of the characters in the given string in the fp, moving
+ * the position to the first character that is not in *s
+ */
+void ldns_fskipcs(FILE *fp, const char *s);
+
+
+
+
+
+
+#endif /*  _PARSE_H */
diff --git a/parse.c b/parse.c
index 12ac85ea67557202ff5e92142b4bcb5f087cbcaa..dda77f9a0526f3d1f82abe832c4eda3a384f2963 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -48,6 +48,7 @@ ldns_fget_keyword_data(FILE *f, const char *keyword, const char *k_del, char *da
 }
 
 /* walk along the file until you get a hit */
+/* number of occurences.... !! */
 ssize_t
 ldns_fget_all_keyword_data(FILE *f, const char *keyword, const char *k_del, char *data,
                const char *d_del)
@@ -101,7 +102,7 @@ ldns_fget_token(FILE *f, char *token, const char *delim, size_t limit)
                if (p < 0) {
                        /* more ) then ( - close off the string */
                        *t = '\0';
-                       return -1;
+                       return 0;
                }
 
                if (c == '\n' && p != 0) {
@@ -124,13 +125,17 @@ ldns_fget_token(FILE *f, char *token, const char *delim, size_t limit)
                }
        }
        *t = '\0';
+       if (i == 0) {
+               /* nothing read */
+               return -1;
+       }
        if (p != 0) {
                return -1;
        }
-       return 0;
+       return (ssize_t)i;
 
 tokenread:
-       /* skip something here too; ldns_fskipc(f, del) */
+       ldns_fskipcs(f, del);
        *t = '\0';
        if (p != 0) {
                return -1;
@@ -240,7 +245,6 @@ ldns_bget_token(ldns_buffer *b, char *token, const char *delim, size_t limit)
                        return -1;
                }
        }
-
        *t = '\0';
        if (i == 0) {
                /* nothing read */
@@ -285,3 +289,77 @@ ldns_str_remove_comment(char *str)
        }
        return str2;
 }
+
+/* fast forwards the buffer, skipping the given char, setting the
+ * buffer position to the location of the first different char
+ * (or to the end of the buffer)
+ */
+void
+ldns_bskipc(ldns_buffer *buffer, char c)
+{
+        while (c == (char) ldns_buffer_read_u8_at(buffer, ldns_buffer_position(buffer))) {
+                if (ldns_buffer_available_at(buffer, buffer->_position + sizeof(char), sizeof(char))) {
+                        buffer->_position += sizeof(char);
+                } else {
+                        return;
+                }
+        }
+}
+
+/* fast forwards the buffer, skipping all chars in the given string,
+ * setting the buffer position to the first char that is not contained
+ * in the string (or to the end of the buffer)
+ */
+void
+ldns_bskipcs(ldns_buffer *buffer, const char *s)
+{
+        bool found;
+        char c;
+        char *d;
+
+        while(ldns_buffer_available_at(buffer, buffer->_position, sizeof(char))) {
+                c = (char) ldns_buffer_read_u8_at(buffer,
+                                           buffer->_position);
+                found = false;
+                for (d = (char *) s; *d; d++) {
+                        if (*d == c) {
+                                found = true;
+                        }
+                }
+                if (found && buffer->_limit > buffer->_position) {
+                        buffer->_position += sizeof(char);
+                } else {
+                        return;
+                }
+        }
+}
+
+void
+ldns_fskipc(FILE *fp, char c)
+{
+
+
+}
+
+
+void
+ldns_fskipcs(FILE *fp, const char *s)
+{
+        bool found;
+        char c;
+        char *d;
+
+       while ((c = fgetc(fp)) != EOF) {
+                found = false;
+                for (d = (char *) s; *d; d++) {
+                        if (*d == c) {
+                                found = true;
+                        }
+                }
+               if (!found) {
+                       /* with getc, we've read too far */
+                       ungetc(c, fp);
+                       return;
+               }
+       }
+}
index 1fb4b8cd78cbf0a3c38ff4cce321732117c46a5a..e3d1f80d05f9d7d3f5bc2da78bd19f71f4ea074b 100644 (file)
@@ -488,13 +488,12 @@ ldns_resolver_new_frm_fp(FILE *fp)
        keyword[0] = "domain";
        keyword[1] = "nameserver";
        word = XMALLOC(char, MAXLINE_LEN);
-       expect = 0;
+       expect = RESOLV_KEYWORD;
 
        r = ldns_resolver_new();
        if (!r) {
                return NULL;
        }
-
        gtr = ldns_fget_token(fp, word, LDNS_PARSE_NORMAL, 0);
        while (gtr > 0) {
                /* do something */
@@ -512,7 +511,7 @@ ldns_resolver_new_frm_fp(FILE *fp)
                                }
                                /* no keyword recognized */
                                if (expect == 0) {
-                                       /*      dprintf("[%s] unreg keyword\n", word); */
+                                               dprintf("[%s] unreg keyword\n", word); 
                                }
                                break;
                        case RESOLV_DEFDOMAIN:
index 2a8ce693f81353ef75332ee7b7e22c6954957097..3fe05c43cc2795488a8e935458dad4ce19195f4e 100644 (file)
@@ -51,12 +51,13 @@ main()
 604800     \n\
 3600       \n\
 )";
-       soa_string2 = "miek.nl. 3600 IN SOA elektron.atoom.net. miekg.atoom.net. \
+       soa_string2 = "miek.nl. 3600 IN SOA elektron.atoom.net. miekg.atoom.net. (\
 2002120700 ; serial \n\
 21600 ; more shit\n\
 7200 ; ahh retry \n\
 604800 ; meaningless number to annoy me\n\
-3600 ; negative caching"; 
+3600 ; negative caching\n\
+)"; 
 
        rr = ldns_rr_new_frm_str(soa_string1);
        ldns_rr_print(stdout, rr);
index b90019b3447838a006d9b86a069527d5ba09b913..50367003beddf9c7e675d46f2ea606308b62b717 100644 (file)
@@ -17,32 +17,13 @@ usage(FILE *fp, char *prog) {
 int
 main()
 {
-       FILE *f;
-       char *tok;
-       size_t b;
+       ldns_resolver *r;
 
-       if (!(f = fopen("blaat", "r"))) {
-               exit(1);
+       r = ldns_resolver_new_frm_file(NULL);
+       if (!r) {
+               printf("something wrong?\n");
        }
 
-       tok = XMALLOC(char, 1024);
-
-       while ((b = ldns_get_token(f, tok, LDNS_PARSE_SKIP_SPACE)) != 0) {
-               fprintf(stdout, "%d: %s\n", (int)b, tok);
-       }
-       fclose(f);
-
-       if (!(f = fopen("Kdnssec.nl.+005+32820.private", "r"))) {
-               exit(1);
-       }
-       
-       /* ldns_get_keyword_data(f, "Algorithm", ": \t", tok, LDNS_STR);*/
-       if (ldns_get_keyword_data(f, "Private-key-format", 
-                               ":", tok, LDNS_PARSE_SKIP_SPACE) != -1) {
-               printf("found it, found it\n");
-               printf("%s\n", tok);
-       }
-
-       fclose(f);
+       ldns_resolver_print(stdout, r);
        return 0;
 }
diff --git a/util.h b/util.h
index 703d5eb00c4f110f9c6988e88cda6f8569eade22..32132b7232efdc188a49f1c1fff65ef975809e28 100644 (file)
--- a/util.h
+++ b/util.h
@@ -15,8 +15,8 @@
 
 #include <ldns/rr.h>
 
-/* #define dprintf(X,Y) printf((X), (Y))  */
-#define        dprintf(X, Y) 
+#define dprintf(X,Y) printf((X), (Y))
+/* #define     dprintf(X, Y)  */
 
 /**
  * splint static inline workaround