]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
ready to transform ldns_resolver_new_frm_fp
authorMiek Gieben <miekg@NLnetLabs.nl>
Thu, 31 Mar 2005 13:43:50 +0000 (13:43 +0000)
committerMiek Gieben <miekg@NLnetLabs.nl>
Thu, 31 Mar 2005 13:43:50 +0000 (13:43 +0000)
ldns/parse.h
parse.c
rdata.c
run-test19.c

index e582d6abc15ab167f047eaead449f5bf20d455a2..42250e11f3d8ff2e41121b26b824d7698235de48 100644 (file)
 #include <ldns/common.h>
 
 
-#define MAXTOKEN_LEN           1024
-#define LDNS_EAT_SPACE         "\f\n\r\t\v"
+#define LDNS_PARSE_SKIP_SPACE          "\f\n\r\t\v"
+#define LDNS_PARSE_NORMAL              " \f\n\r\t\v"
 #define MAXLINE_LEN            512
 #define MAXKEYWORD_LEN         32
 
-/* what we can parse */
-enum ldns_enum_parse
-{
-       LDNS_SPACE_STR,         /* str with spaces */
-       LDNS_STR,               /* str without spaces */
-       LDNS_QUOTE_STR,         /* str with \ in it */
-       LDNS_QUOTE_SPACE_STR    /* str with \ in it and spaces */
-};
-typedef enum ldns_enum_parse ldns_parse;
-
 /* 
  * get a token/char from the stream F
  * return 0 on error of EOF of F
@@ -37,15 +27,12 @@ typedef enum ldns_enum_parse ldns_parse;
  */
 ssize_t ldns_get_token(FILE *f, char *token, const char *delim);
 
-/* 
- * get the next string and supply the type we want
- * return 0 on error, otherwise the length
- */
-ssize_t ldns_get_str(FILE *f, char *word, ldns_parse type);
-
 /* 
  * search for keyword and delim. Give everything back
- * after the delimeter(s) 
+ * after the keyword + k_del until we hit d_del
  */
+ssize_t 
+ldns_get_keyword_data(FILE *f, const char *keyword, const char *k_del, char *data, const char *d_del);
+
 
 #endif /*  _PARSE_H_ */
diff --git a/parse.c b/parse.c
index 936c968302107348cb24adb02518af6f451f3e14..4b074b8865d8c009d43e15f2ec3a169415596935 100644 (file)
--- a/parse.c
+++ b/parse.c
 #include <ldns/dns.h>
 #include "util.h"
 
-
-
-/* 
- * search for keyword and delim. Give everything back
- * after the delimeter(s) 
- */
 ssize_t
-ldns_get_keyword_data(FILE *f, char *keyword, char *del        , char *data, ldns_parse d_type)
+ldns_get_keyword_data(FILE *f, const char *keyword, const char *k_del, char *data, const char *d_del)
 {
        /* we assume: keyword|sep|data */
        char *fkeyword;
+       ssize_t i;
 
        fkeyword = XMALLOC(char, MAXKEYWORD_LEN);
+       i = 0;
 
-       ldns_get_str(f, fkeyword, LDNS_STR);
-
-       printf("%s\n", fkeyword);
-       return 0;
-}
-
+       i = ldns_get_token(f, fkeyword, k_del);
 
-ssize_t
-ldns_get_str(FILE *f, char *word, ldns_parse type)
-{
-       ssize_t i;
+       printf("[%s]\n", fkeyword);
 
-       i = 0;
-       switch (type) {
-       case LDNS_SPACE_STR:
-               i = ldns_get_token(f, word, LDNS_EAT_SPACE);
-               return i;       
-       case LDNS_STR:
-               i = ldns_get_token(f, word, NULL);
+       /* case??? */
+       if (strncmp(fkeyword, keyword, strlen(keyword)) == 0) {
+               /* whee, the match! */
+               printf("Matching keyword\n\n");
+               /* retrieve it's data */
+               i = ldns_get_token(f, data, d_del);
                return i;
-       case LDNS_QUOTE_STR:
-               i = ldns_get_token(f, word, NULL);
-               break;
-       case LDNS_QUOTE_SPACE_STR:
-               i = ldns_get_token(f, word, LDNS_EAT_SPACE);
-               break;
+       } else {
+               return -1;
        }
-       /* only reach this spot if the str was quoted */
-       /* mangle the quoted string and return what we got */
-       return i;
 }
 
+
 ssize_t
 ldns_get_token(FILE *f, char *token, const char *delim)
 {      
@@ -79,7 +60,7 @@ ldns_get_token(FILE *f, char *token, const char *delim)
        /* standard delimeters */
        if (!delim) {
                /* from isspace(3) */
-               del = " \f\n\r\t\v";
+               del = LDNS_PARSE_NORMAL;
        } else {
                del = delim;
        }
diff --git a/rdata.c b/rdata.c
index 91f94b2ce0b03c2276f9589b1a30381f6751bcad..5b6a3f9edcca54ff21dd64233fa0061c09a82ed8 100644 (file)
--- a/rdata.c
+++ b/rdata.c
@@ -426,7 +426,7 @@ ldns_rdf_new_frm_fp(ldns_rdf_type type, FILE *fp)
        }
 
        /* read an entire line in from the file */
-       if ((t = ldns_get_str(fp, line, LDNS_SPACE_STR)) == -1) {
+       if ((t = ldns_get_token(fp, line, LDNS_PARSE_SKIP_SPACE)) == -1) {
                FREE(line);
                return NULL;
        }
index fd2fd4fc58ee93c2fe52f13539711084f2b424b3..b90019b3447838a006d9b86a069527d5ba09b913 100644 (file)
@@ -27,7 +27,7 @@ main()
 
        tok = XMALLOC(char, 1024);
 
-       while ((b = ldns_get_str(f, tok, LDNS_SPACE_STR)) != 0) {
+       while ((b = ldns_get_token(f, tok, LDNS_PARSE_SKIP_SPACE)) != 0) {
                fprintf(stdout, "%d: %s\n", (int)b, tok);
        }
        fclose(f);
@@ -36,8 +36,12 @@ main()
                exit(1);
        }
        
-       ldns_get_keyword_data(f, "Algorithm", ":", tok, LDNS_STR);
-       
+       /* 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);
        return 0;