From: Miek Gieben Date: Thu, 31 Mar 2005 13:43:50 +0000 (+0000) Subject: ready to transform ldns_resolver_new_frm_fp X-Git-Tag: release-0.50~179 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=09ae4f23cd534d03f8d7048cf738ca784cfc8068;p=thirdparty%2Fldns.git ready to transform ldns_resolver_new_frm_fp --- diff --git a/ldns/parse.h b/ldns/parse.h index e582d6ab..42250e11 100644 --- a/ldns/parse.h +++ b/ldns/parse.h @@ -13,21 +13,11 @@ #include -#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 936c9683..4b074b88 100644 --- a/parse.c +++ b/parse.c @@ -20,52 +20,33 @@ #include #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 91f94b2c..5b6a3f9e 100644 --- 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; } diff --git a/run-test19.c b/run-test19.c index fd2fd4fc..b90019b3 100644 --- a/run-test19.c +++ b/run-test19.c @@ -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;