From: Matthijs Mekking Date: Tue, 6 Nov 2012 14:28:45 +0000 (+0000) Subject: allow for read datafiles with skip leftmost whitespace X-Git-Tag: release-1.6.17rc1~177 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8738d64350f58718abc123d00885d9b9f1d3612f;p=thirdparty%2Fldns.git allow for read datafiles with skip leftmost whitespace --- diff --git a/examples/ldns-testns.c b/examples/ldns-testns.c index eb007107..86219d60 100644 --- a/examples/ldns-testns.c +++ b/examples/ldns-testns.c @@ -492,7 +492,7 @@ main(int argc, char **argv) datafile = argv[0]; log_msg("Reading datafile %s\n", datafile); - entries = read_datafile(datafile); + entries = read_datafile(datafile, 0); #ifdef USE_WINSOCK if(WSAStartup(MAKEWORD(2,2), &wsa_data) != 0) diff --git a/examples/ldns-testpkts.c b/examples/ldns-testpkts.c index 002a6a90..be94eb2f 100644 --- a/examples/ldns-testpkts.c +++ b/examples/ldns-testpkts.c @@ -426,7 +426,7 @@ get_origin(const char* name, int lineno, ldns_rdf** origin, char* parse) /* Reads one entry from file. Returns entry or NULL on error. */ struct entry* read_entry(FILE* in, const char* name, int *lineno, uint32_t* default_ttl, - ldns_rdf** origin, ldns_rdf** prev_rr) + ldns_rdf** origin, ldns_rdf** prev_rr, int skip_whitespace) { struct entry* current = NULL; char line[MAX_LINE]; @@ -507,14 +507,17 @@ read_entry(FILE* in, const char* name, int *lineno, uint32_t* default_ttl, /* it must be a RR, parse and add to packet. */ ldns_rr* n = NULL; ldns_status status; + char* rrstr = line; + if (skip_whitespace) + rrstr = parse; if(add_section == LDNS_SECTION_QUESTION) status = ldns_rr_new_question_frm_str( - &n, line, *origin, prev_rr); - else status = ldns_rr_new_frm_str(&n, line, + &n, rrstr, *origin, prev_rr); + else status = ldns_rr_new_frm_str(&n, rrstr, *default_ttl, *origin, prev_rr); if(status != LDNS_STATUS_OK) error("%s line %d:\n\t%s: %s", name, *lineno, - ldns_get_errorstr_by_id(status), line); + ldns_get_errorstr_by_id(status), rrstr); ldns_pkt_push_rr(cur_reply->reply, add_section, n); } @@ -532,7 +535,7 @@ read_entry(FILE* in, const char* name, int *lineno, uint32_t* default_ttl, /* reads the canned reply file and returns a list of structs */ struct entry* -read_datafile(const char* name) +read_datafile(const char* name, int skip_whitespace) { struct entry* list = NULL; struct entry* last = NULL; @@ -549,7 +552,7 @@ read_datafile(const char* name) } while((current = read_entry(in, name, &lineno, &default_ttl, - &origin, &prev_rr))) + &origin, &prev_rr, skip_whitespace))) { if(last) last->next = current; diff --git a/examples/ldns-testpkts.h b/examples/ldns-testpkts.h index 59e42895..49415252 100644 --- a/examples/ldns-testpkts.h +++ b/examples/ldns-testpkts.h @@ -197,8 +197,9 @@ struct entry { /** * reads the canned reply file and returns a list of structs * does an exit on error. + * @param skip_withespace: skip leftside whitespace. */ -struct entry* read_datafile(const char* name); +struct entry* read_datafile(const char* name, int skip_whitespace); /** * Delete linked list of entries. @@ -217,10 +218,12 @@ void delete_entry(struct entry* list); * later it stores the $ORIGIN value last seen. Often &NULL or the zone * name on first call. * @param prev_rr: previous rr name for correcter parsing. &NULL on first call. + * @param skip_whitespace: skip leftside whitespace. * @return: The entry read (malloced) or NULL if no entry could be read. */ struct entry* read_entry(FILE* in, const char* name, int *lineno, - uint32_t* default_ttl, ldns_rdf** origin, ldns_rdf** prev_rr); + uint32_t* default_ttl, ldns_rdf** origin, ldns_rdf** prev_rr, + int skip_whitespace); /** * finds entry in list, or returns NULL.