summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2020-07-12 00:25:22 +0200
committerDavid Härdeman <david@hardeman.nu>2020-07-12 00:25:22 +0200
commitd198326ef6ec3031afbe7ee47b727cc52fc1198a (patch)
treed6d2ec7bfeb9066d78dcb12f7b5d37890b77d32a
parentb56b003fc13a4e12f97c6cfd5dd650e928d6e016 (diff)
Move sprop_parse to shared lib
-rw-r--r--minecctl/misc-commands.c6
-rw-r--r--minecctl/server.c110
-rw-r--r--minecproxy/main.c2
-rw-r--r--minecproxy/server-config.c2
-rw-r--r--shared/config-parser.c76
-rw-r--r--shared/config-parser.h3
6 files changed, 84 insertions, 115 deletions
diff --git a/minecctl/misc-commands.c b/minecctl/misc-commands.c
index 8a54e64..1133e55 100644
--- a/minecctl/misc-commands.c
+++ b/minecctl/misc-commands.c
@@ -434,7 +434,11 @@ static bool select_free_ports(struct cfg *cfg, uint16_t *listen_port,
}
if (!used) {
- error("Found unused port, %" PRIu16, lport);
+ debug(DBG_CFG, "found unused port, "
+ "listen: %" PRIu16 ", "
+ "mc: %" PRIu16 ", "
+ "rcon: %" PRIu16,
+ lport, mport, rport);
if (listen_port && *listen_port == 0)
*listen_port = lport;
diff --git a/minecctl/server.c b/minecctl/server.c
index 3743526..8bd7b51 100644
--- a/minecctl/server.c
+++ b/minecctl/server.c
@@ -115,116 +115,6 @@ static bool read_file(int dfd, const char *filename, char *buf, size_t len,
return true;
}
-enum sprop_keys {
- SPROP_KEY_INVALID = 0,
- SPROP_KEY_SERVER_PORT,
- SPROP_KEY_RCON_PORT,
- SPROP_KEY_RCON_PASSWORD,
-};
-
-struct cfg_key_value_map sprop_key_map[] = {
- {
- .key_name = "server-port",
- .key_value = SPROP_KEY_SERVER_PORT,
- .value_type = CFG_VAL_TYPE_ADDRS,
- },
- {
- .key_name = "rcon.port",
- .key_value = SPROP_KEY_RCON_PORT,
- .value_type = CFG_VAL_TYPE_ADDRS,
- },
- {
- .key_name = "rcon.password",
- .key_value = SPROP_KEY_RCON_PASSWORD,
- .value_type = CFG_VAL_TYPE_STRING,
- }
-};
-
-static void sprop_parse(struct server_config *scfg, char *buf,
- unsigned *lineno, const char **error)
-{
- char *pos = buf;
- struct saddr *saddr, *tmp;
-
- *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:
- error("Got a server port");
-
- /* FIXME: these should use scfg_queue_dns */
- if (value.type != CFG_VAL_TYPE_ADDRS) {
- error("Got async DNS results!?");
- break;
- }
-
- if (!list_empty(&scfg->remotes)) {
- error("mc server address set both in %s and "
- "server.properties", scfg->filename);
- break;
- }
-
- list_for_each_entry_safe(saddr, tmp, &value.saddrs, list) {
- list_del(&saddr->list);
- list_add(&saddr->list, &scfg->remotes);
- }
-
- break;
-
- case SPROP_KEY_RCON_PORT:
- error("Got a rcon port");
-
- if (value.type != CFG_VAL_TYPE_ADDRS) {
- error("Got async DNS results!?");
- break;
- }
-
- if (!list_empty(&scfg->rcons)) {
- error("rcon address set both in %s and "
- "server.properties", scfg->filename);
- break;
- }
-
- list_for_each_entry_safe(saddr, tmp, &value.saddrs, list) {
- list_del(&saddr->list);
- list_add(&saddr->list, &scfg->rcons);
- }
-
- break;
-
- case SPROP_KEY_RCON_PASSWORD:
- error("Got an rcon password");
-
- 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 server_read_config(struct cfg *cfg, struct server *server,
unsigned *lineno, const char **error)
{
diff --git a/minecproxy/main.c b/minecproxy/main.c
index d8f33d0..0406976 100644
--- a/minecproxy/main.c
+++ b/minecproxy/main.c
@@ -669,7 +669,7 @@ int main(int argc, char **argv)
cfg_read();
/*
- * In the splice case we use 4 fds per proxy connection...
+ * In the splice case we use 6 fds per proxy connection...
*/
if (prlimit(0, RLIMIT_NOFILE, NULL, &old_rlimit) == 0) {
struct rlimit new_rlimit;
diff --git a/minecproxy/server-config.c b/minecproxy/server-config.c
index 575661a..7009952 100644
--- a/minecproxy/server-config.c
+++ b/minecproxy/server-config.c
@@ -55,6 +55,8 @@ static void server_cfg_read_cb(struct uring_task *task, int res)
return;
}
+ /* FIXME: open/read/parse server.properties */
+
if (!list_empty(&server->scfg.dnslookups)) {
uring_task_get(&server->task);
scfg_async_dns_start(&server->scfg);
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)
{
diff --git a/shared/config-parser.h b/shared/config-parser.h
index 129e085..da5250d 100644
--- a/shared/config-parser.h
+++ b/shared/config-parser.h
@@ -99,6 +99,9 @@ bool scfg_async_dns_start(struct server_config *scfg);
bool scfg_validate(struct server_config *scfg, const char **error);
+void sprop_parse(struct server_config *scfg, char *buf,
+ unsigned *lineno, const char **error);
+
bool scfg_parse(struct server_config *scfg, char *buf, bool async,
unsigned *lineno, const char **error);