Ejemplo n.º 1
0
struct replay_scenario* 
replay_scenario_read(FILE* in, const char* name, int* lineno)
{
	char line[MAX_LINE_LEN];
	char *parse;
	struct replay_scenario* scen = NULL;
	uint32_t ttl = 3600;
	ldns_rdf* or = NULL;
	ldns_rdf* prev = NULL;
	line[MAX_LINE_LEN-1]=0;

	while(fgets(line, MAX_LINE_LEN-1, in)) {
		parse=line;
		(*lineno)++;
		while(isspace((int)*parse))
			parse++;
		if(!*parse) 
			continue; /* empty line */
		if(parse_keyword(&parse, ";"))
			continue; /* comment */
		if(parse_keyword(&parse, "SCENARIO_BEGIN")) {
			scen = make_scenario(parse);
			if(!scen)
				fatal_exit("%d: could not make scen", *lineno);
			continue;
		} 
		if(!scen)
			fatal_exit("%d: expected SCENARIO", *lineno);
		if(parse_keyword(&parse, "RANGE_BEGIN")) {
			struct replay_range* newr = replay_range_read(parse, 
				in, name, lineno, line, &ttl, &or, &prev);
			if(!newr)
				fatal_exit("%d: bad range", *lineno);
			newr->next_range = scen->range_list;
			scen->range_list = newr;
		} else if(parse_keyword(&parse, "STEP")) {
			struct replay_moment* mom = replay_moment_read(parse, 
				in, name, lineno, &ttl, &or, &prev);
			if(!mom)
				fatal_exit("%d: bad moment", *lineno);
			if(scen->mom_last && 
				scen->mom_last->time_step >= mom->time_step)
				fatal_exit("%d: time goes backwards", *lineno);
			if(scen->mom_last)
				scen->mom_last->mom_next = mom;
			else	scen->mom_first = mom;
			scen->mom_last = mom;
		} else if(parse_keyword(&parse, "SCENARIO_END")) {
			struct replay_moment *p = scen->mom_first;
			int num = 0;
			while(p) {
				num++;
				p = p->mom_next;
			}
			log_info("Scenario has %d steps", num);
			ldns_rdf_deep_free(or);
			ldns_rdf_deep_free(prev);
			return scen;
		}
	}
	ldns_rdf_deep_free(or);
	ldns_rdf_deep_free(prev);
	replay_scenario_delete(scen);
	return NULL;
}
Ejemplo n.º 2
0
struct replay_scenario* 
replay_scenario_read(FILE* in, const char* name, int* lineno)
{
	char line[MAX_LINE_LEN];
	char *parse;
	struct replay_scenario* scen = NULL;
	struct sldns_file_parse_state pstate;
	line[MAX_LINE_LEN-1]=0;
	memset(&pstate, 0, sizeof(pstate));
	pstate.default_ttl = 3600;
	pstate.lineno = *lineno;

	while(fgets(line, MAX_LINE_LEN-1, in)) {
		parse=line;
		pstate.lineno++;
		(*lineno)++;
		while(isspace((unsigned char)*parse))
			parse++;
		if(!*parse) 
			continue; /* empty line */
		if(parse_keyword(&parse, ";"))
			continue; /* comment */
		if(parse_keyword(&parse, "SCENARIO_BEGIN")) {
			scen = make_scenario(parse);
			if(!scen)
				fatal_exit("%d: could not make scen", *lineno);
			continue;
		} 
		if(!scen)
			fatal_exit("%d: expected SCENARIO", *lineno);
		if(parse_keyword(&parse, "RANGE_BEGIN")) {
			struct replay_range* newr = replay_range_read(parse, 
				in, name, &pstate, line);
			if(!newr)
				fatal_exit("%d: bad range", pstate.lineno);
			*lineno = pstate.lineno;
			newr->next_range = scen->range_list;
			scen->range_list = newr;
		} else if(parse_keyword(&parse, "STEP")) {
			struct replay_moment* mom = replay_moment_read(parse, 
				in, name, &pstate);
			if(!mom)
				fatal_exit("%d: bad moment", pstate.lineno);
			*lineno = pstate.lineno;
			if(scen->mom_last && 
				scen->mom_last->time_step >= mom->time_step)
				fatal_exit("%d: time goes backwards", *lineno);
			if(scen->mom_last)
				scen->mom_last->mom_next = mom;
			else	scen->mom_first = mom;
			scen->mom_last = mom;
		} else if(parse_keyword(&parse, "SCENARIO_END")) {
			struct replay_moment *p = scen->mom_first;
			int num = 0;
			while(p) {
				num++;
				p = p->mom_next;
			}
			log_info("Scenario has %d steps", num);
			return scen;
		}
	}
	replay_scenario_delete(scen);
	return NULL;
}