From d198326ef6ec3031afbe7ee47b727cc52fc1198a Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Sun, 12 Jul 2020 00:25:22 +0200 Subject: Move sprop_parse to shared lib --- shared/config-parser.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 3 deletions(-) (limited to 'shared/config-parser.c') diff --git a/shared/config-parser.c b/shared/config-parser.c index ea800ad..8ea6557 100644 --- a/shared/config-parser.c +++ b/shared/config-parser.c @@ -13,6 +13,7 @@ #include "utils.h" #include "config-parser.h" #include "server-config-options.h" +#include "server-properties-options.h" #include "config.h" static bool handle_addrinfo_results(struct addrinfo *results, @@ -246,11 +247,8 @@ bool scfg_validate(struct server_config *scfg, const char **error) if (list_empty(&scfg->locals)) ERROR("missing local addresses for proxy server"); - /* FIXME: Reinstate once server.properties parsing is implemented */ - /* if (list_empty(&scfg->remotes)) ERROR("missing remote addresses for proxy server"); - */ list_for_each_entry(saddr, &scfg->locals, list) { port = saddr_port(saddr); @@ -325,6 +323,78 @@ static char *systemd_object_path(const char *service) return r; } +void sprop_parse(struct server_config *scfg, char *buf, + unsigned *lineno, const char **error) +{ + char *pos = buf; + + assert_return(scfg && buf && lineno && error); + + *lineno = 0; + + while (true) { + int key; + const char *keyname; + struct cfg_value value; + + if (!config_parse_line("server.properties", &pos, sprop_key_map, + &key, &keyname, &value, false, lineno, + error)) + break; + + switch (key) { + case SPROP_KEY_SERVER_PORT: + debug(DBG_CFG, "found remote server port in " + "server.properties"); + + if (!list_empty(&scfg->remotes)) { + error("mc server address set both in %s and " + "server.properties", scfg->filename); + break; + } + + scfg_queue_dns(scfg, &value, &scfg->remotes, false); + + break; + + case SPROP_KEY_RCON_PORT: + debug(DBG_CFG, "found rcon port in " + "server.properties"); + + if (!list_empty(&scfg->rcons)) { + error("rcon address set both in %s and " + "server.properties", scfg->filename); + break; + } + + scfg_queue_dns(scfg, &value, &scfg->rcons, false); + + break; + + case SPROP_KEY_RCON_PASSWORD: + debug(DBG_CFG, "found rcon password in " + "server.properties"); + + if (scfg->rcon_password) { + error("rcon password set both in %s and " + "server.properties (%smatching)", + scfg->filename, + streq(scfg->rcon_password, value.str) ? + "" : "not"); + break; + } + + scfg->rcon_password = xstrdup(value.str); + break; + + case SPROP_KEY_INVALID: + _fallthrough_; + default: + break; + } + } +} + bool scfg_parse(struct server_config *scfg, char *buf, bool async, unsigned *lineno, const char **error) { -- cgit v1.2.3