diff options
Diffstat (limited to 'shared')
-rw-r--r-- | shared/config-parser.c | 17 | ||||
-rw-r--r-- | shared/config-parser.h | 8 | ||||
-rw-r--r-- | shared/server-config-options.h | 6 |
3 files changed, 31 insertions, 0 deletions
diff --git a/shared/config-parser.c b/shared/config-parser.c index 3309b96..6b91f3f 100644 --- a/shared/config-parser.c +++ b/shared/config-parser.c @@ -216,6 +216,9 @@ bool scfg_validate(struct server_config *scfg, const char **error) switch (scfg->type) { case SERVER_TYPE_ANNOUNCE: + if (scfg->announce == SERVER_ANNOUNCE_NEVER) + ERROR("announce policy never with an announce server"); + if (scfg->announce_port == 0) ERROR("missing announce port"); @@ -365,6 +368,19 @@ bool scfg_parse(struct server_config *scfg, char *buf, bool async, ERROR("strdup failure"); break; + case SCFG_KEY_ANNOUNCE: + if (scfg->announce != SERVER_ANNOUNCE_UNDEFINED) + ERROR("announce policy defined multiple times"); + else if (streq(value.str, "always")) + scfg->announce = SERVER_ANNOUNCE_ALWAYS; + else if (streq(value.str, "never")) + scfg->announce = SERVER_ANNOUNCE_NEVER; + else if (streq(value.str, "when-running")) + scfg->announce = SERVER_ANNOUNCE_WHEN_RUNNING; + else + ERROR("unknown announce policy"); + break; + case SCFG_KEY_PORT: if (scfg->announce_port != 0) ERROR("port defined multiple times"); @@ -526,6 +542,7 @@ bool scfg_init(struct server_config *scfg, const char *filename) scfg->type = SERVER_TYPE_UNDEFINED; scfg->pretty_name = NULL; + scfg->announce = SERVER_ANNOUNCE_UNDEFINED; scfg->announce_port = 0; scfg->idle_timeout = 0; scfg->stop_method = SERVER_STOP_METHOD_UNDEFINED; diff --git a/shared/config-parser.h b/shared/config-parser.h index e1d73d2..4e3cbca 100644 --- a/shared/config-parser.h +++ b/shared/config-parser.h @@ -26,10 +26,18 @@ enum server_start_method { SERVER_START_METHOD_EXEC, }; +enum server_announce { + SERVER_ANNOUNCE_UNDEFINED, + SERVER_ANNOUNCE_ALWAYS, + SERVER_ANNOUNCE_NEVER, + SERVER_ANNOUNCE_WHEN_RUNNING, +}; + struct server_config { char *filename; enum server_type type; char *pretty_name; + enum server_announce announce; uint16_t announce_port; unsigned idle_timeout; enum server_stop_method stop_method; diff --git a/shared/server-config-options.h b/shared/server-config-options.h index 5600e52..78f9598 100644 --- a/shared/server-config-options.h +++ b/shared/server-config-options.h @@ -7,6 +7,7 @@ enum scfg_keys { SCFG_KEY_INVALID = 0, SCFG_KEY_TYPE, SCFG_KEY_NAME, + SCFG_KEY_ANNOUNCE, SCFG_KEY_PORT, SCFG_KEY_LOCAL, SCFG_KEY_REMOTE, @@ -32,6 +33,11 @@ struct cfg_key_value_map scfg_key_map[] = { .value_type = CFG_VAL_TYPE_STRING, }, { + .key_name = "announce", + .key_value = SCFG_KEY_ANNOUNCE, + .value_type = CFG_VAL_TYPE_STRING, + }, + { .key_name = "port", .key_value = SCFG_KEY_PORT, .value_type = CFG_VAL_TYPE_UINT16, |