Commit 1fbd6fe7 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Make high-level parse functions return next character.

This avoids various unpleasant edge-cases.
parent 4852003e
...@@ -273,8 +273,8 @@ getnet(int c, unsigned char **p_r, unsigned char *plen_r, int *af_r, ...@@ -273,8 +273,8 @@ getnet(int c, unsigned char **p_r, unsigned char *plen_r, int *af_r,
return c; return c;
} }
static struct filter * static int
parse_filter(int c, gnc_t gnc, void *closure) parse_filter(int c, gnc_t gnc, void *closure, struct filter **filter_return)
{ {
char *token; char *token;
struct filter *filter; struct filter *filter;
...@@ -368,16 +368,18 @@ parse_filter(int c, gnc_t gnc, void *closure) ...@@ -368,16 +368,18 @@ parse_filter(int c, gnc_t gnc, void *closure)
filter->plen_le += 96; filter->plen_le += 96;
filter->plen_ge += 96; filter->plen_ge += 96;
} }
return filter; *filter_return = filter;
return c;
error: error:
free(filter); free(filter);
return NULL; return -2;
} }
static struct interface_conf * static int
parse_anonymous_ifconf(int c, gnc_t gnc, void *closure, parse_anonymous_ifconf(int c, gnc_t gnc, void *closure,
struct interface_conf *if_conf) struct interface_conf *if_conf,
struct interface_conf **if_conf_return)
{ {
char *token; char *token;
...@@ -468,15 +470,17 @@ parse_anonymous_ifconf(int c, gnc_t gnc, void *closure, ...@@ -468,15 +470,17 @@ parse_anonymous_ifconf(int c, gnc_t gnc, void *closure,
free(token); free(token);
} }
return if_conf; *if_conf_return = if_conf;
return c;
error: error:
free(if_conf); free(if_conf);
return NULL; return -2;
} }
static struct interface_conf * static int
parse_ifconf(int c, gnc_t gnc, void *closure) parse_ifconf(int c, gnc_t gnc, void *closure,
struct interface_conf **if_conf_return)
{ {
char *token; char *token;
struct interface_conf *if_conf; struct interface_conf *if_conf;
...@@ -495,11 +499,11 @@ parse_ifconf(int c, gnc_t gnc, void *closure) ...@@ -495,11 +499,11 @@ parse_ifconf(int c, gnc_t gnc, void *closure)
if_conf->ifname = token; if_conf->ifname = token;
return parse_anonymous_ifconf(c, gnc, closure, if_conf); return parse_anonymous_ifconf(c, gnc, closure, if_conf, if_conf_return);
error: error:
free(if_conf); free(if_conf);
return NULL; return -2;
} }
static void static void
...@@ -707,31 +711,31 @@ parse_config(gnc_t gnc, void *closure) ...@@ -707,31 +711,31 @@ parse_config(gnc_t gnc, void *closure)
if(strcmp(token, "in") == 0) { if(strcmp(token, "in") == 0) {
struct filter *filter; struct filter *filter;
filter = parse_filter(c, gnc, closure); c = parse_filter(c, gnc, closure, &filter);
if(filter == NULL) if(filter == NULL)
return -1; return -1;
add_filter(filter, &input_filters); add_filter(filter, &input_filters);
} else if(strcmp(token, "out") == 0) { } else if(strcmp(token, "out") == 0) {
struct filter *filter; struct filter *filter;
filter = parse_filter(c, gnc, closure); c = parse_filter(c, gnc, closure, &filter);
if(filter == NULL) if(filter == NULL)
return -1; return -1;
add_filter(filter, &output_filters); add_filter(filter, &output_filters);
} else if(strcmp(token, "redistribute") == 0) { } else if(strcmp(token, "redistribute") == 0) {
struct filter *filter; struct filter *filter;
filter = parse_filter(c, gnc, closure); c = parse_filter(c, gnc, closure, &filter);
if(filter == NULL) if(filter == NULL)
return -1; return -1;
add_filter(filter, &redistribute_filters); add_filter(filter, &redistribute_filters);
} else if(strcmp(token, "interface") == 0) { } else if(strcmp(token, "interface") == 0) {
struct interface_conf *if_conf; struct interface_conf *if_conf;
if_conf = parse_ifconf(c, gnc, closure); c = parse_ifconf(c, gnc, closure, &if_conf);
if(if_conf == NULL) if(if_conf == NULL)
return -1; return -1;
add_ifconf(if_conf, &interface_confs); add_ifconf(if_conf, &interface_confs);
} else if(strcmp(token, "default") == 0) { } else if(strcmp(token, "default") == 0) {
struct interface_conf *if_conf; struct interface_conf *if_conf;
if_conf = parse_anonymous_ifconf(c, gnc, closure, NULL); c = parse_anonymous_ifconf(c, gnc, closure, NULL, &if_conf);
if(if_conf == NULL) if(if_conf == NULL)
return -1; return -1;
if(default_interface_conf == NULL) if(default_interface_conf == NULL)
...@@ -742,9 +746,8 @@ parse_config(gnc_t gnc, void *closure) ...@@ -742,9 +746,8 @@ parse_config(gnc_t gnc, void *closure)
free(if_conf); free(if_conf);
} }
} else { } else {
int rc; c = parse_option(c, gnc, closure, token);
rc = parse_option(c, gnc, closure, token); if(c < -2)
if(rc < 0)
return -1; return -1;
} }
free(token); free(token);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment