summaryrefslogtreecommitdiffstats
path: root/src/config.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2012-03-28 18:42:24 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2012-03-28 18:42:24 +0200
commitc8ea4868b37f53e138548b7adee756834ad7ea66 (patch)
tree6a45e32a3ab314a1699c29596c511da78faeee8a /src/config.c
parent1653c57e8167c69c11bf9aade23bdbc5207c196d (diff)
downloadfastd-c8ea4868b37f53e138548b7adee756834ad7ea66.tar
fastd-c8ea4868b37f53e138548b7adee756834ad7ea66.zip
Add single peer config options; also fix string handling in lexer
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/config.c b/src/config.c
index b53a0b9..af32975 100644
--- a/src/config.c
+++ b/src/config.c
@@ -81,17 +81,22 @@ static bool config_match(const char *opt, ...) {
return match;
}
-void fastd_read_config(fastd_context *ctx, fastd_config *conf, const char *filename, int depth) {
+void fastd_read_config(fastd_context *ctx, fastd_config *conf, const char *filename, bool peer_config, int depth) {
if (depth >= MAX_CONFIG_DEPTH)
exit_error(ctx, "maximum config include depth exceeded");
bool use_stdin = !strcmp(filename, "-");
FILE *file;
- if (use_stdin)
+ if (use_stdin) {
file = stdin;
- else
+ }
+ else {
file = fopen(filename, "r");
+ if (!file)
+ exit_error(ctx, "can't open config file `%s': %s", filename, strerror(errno));
+ }
+
yyscan_t scanner;
fastd_config_yylex_init(&scanner);
@@ -101,12 +106,18 @@ void fastd_read_config(fastd_context *ctx, fastd_config *conf, const char *filen
int token;
YYSTYPE token_val;
- do {
+
+ if (peer_config)
+ token = START_PEER_CONFIG;
+ else
+ token = START_CONFIG;
+
+ while(fastd_config_push_parse(ps, token, &token_val, ctx, conf, depth+1) == YYPUSH_MORE) {
token = fastd_config_yylex(&token_val, scanner);
if (token < 0)
exit_error(ctx, "config error: %s", token_val.str);
- } while(fastd_config_push_parse(ps, token, &token_val, ctx, conf, depth+1) == YYPUSH_MORE);
+ }
fastd_config_pstate_delete(ps);
fastd_config_yylex_destroy(scanner);
@@ -139,7 +150,13 @@ void fastd_configure(fastd_context *ctx, fastd_config *conf, int argc, char *con
while (i < argc) {
IF_OPTION_ARG("-c", "--config") {
- fastd_read_config(ctx, conf, arg, 0);
+ fastd_read_config(ctx, conf, arg, false, 0);
+ continue;
+ }
+
+ IF_OPTION_ARG("--config-peer") {
+ fastd_peer_config_new(ctx, conf);
+ fastd_read_config(ctx, conf, arg, true, 0);
continue;
}