summaryrefslogtreecommitdiff
path: root/minecproxy
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2020-07-12 22:30:22 +0200
committerDavid Härdeman <david@hardeman.nu>2020-07-12 22:30:22 +0200
commitbbdd4abc9f787f057848a5b97656509b877793e0 (patch)
treef1daee6b9302e444ddd17a6d3986a407b35b4806 /minecproxy
parent5c91d6294929b86105f16b96de5596a93be3ea68 (diff)
Move more static strings to config.h
Diffstat (limited to 'minecproxy')
-rw-r--r--minecproxy/main.c87
-rw-r--r--minecproxy/minecproxy-config-options.h77
-rw-r--r--minecproxy/server-config.c2
3 files changed, 86 insertions, 80 deletions
diff --git a/minecproxy/main.c b/minecproxy/main.c
index 7e17369..92065cc 100644
--- a/minecproxy/main.c
+++ b/minecproxy/main.c
@@ -29,6 +29,7 @@
#include "idle.h"
#include "ptimer.h"
#include "config.h"
+#include "minecproxy-config-options.h"
/* Global */
struct cfg *cfg = NULL;
@@ -196,78 +197,6 @@ static void cfg_free(struct uring_task *task)
/* The cfg struct is free:d in main() */
}
-enum mcfg_keys {
- MCFG_KEY_INVALID = 0,
- MCFG_KEY_IGMP,
- MCFG_KEY_IGMP_IFACE,
- MCFG_KEY_ANNOUNCE_INTERVAL,
- MCFG_KEY_PROXY_CONN_INTERVAL,
- MCFG_KEY_PROXY_CONN_ATTEMPTS,
- MCFG_KEY_SOCKET_DEFER,
- MCFG_KEY_SOCKET_FREEBIND,
- MCFG_KEY_SOCKET_KEEPALIVE,
- MCFG_KEY_SOCKET_IPTOS,
- MCFG_KEY_SOCKET_NODELAY,
-};
-
-struct cfg_key_value_map mcfg_key_map[] = {
- {
- .key_name = "igmp",
- .key_value = MCFG_KEY_IGMP,
- .value_type = CFG_VAL_TYPE_BOOL,
- },
- {
- .key_name = "igmp_iface",
- .key_value = MCFG_KEY_IGMP_IFACE,
- .value_type = CFG_VAL_TYPE_STRING,
- },
- {
- .key_name = "announce_interval",
- .key_value = MCFG_KEY_ANNOUNCE_INTERVAL,
- .value_type = CFG_VAL_TYPE_UINT16,
- },
- {
- .key_name = "proxy_connection_interval",
- .key_value = MCFG_KEY_PROXY_CONN_INTERVAL,
- .value_type = CFG_VAL_TYPE_UINT16,
- },
- {
- .key_name = "proxy_connection_attempts",
- .key_value = MCFG_KEY_PROXY_CONN_ATTEMPTS,
- .value_type = CFG_VAL_TYPE_UINT16,
- },
- {
- .key_name = "socket_defer",
- .key_value = MCFG_KEY_SOCKET_DEFER,
- .value_type = CFG_VAL_TYPE_BOOL,
- },
- {
- .key_name = "socket_freebind",
- .key_value = MCFG_KEY_SOCKET_FREEBIND,
- .value_type = CFG_VAL_TYPE_BOOL,
- },
- {
- .key_name = "socket_keepalive",
- .key_value = MCFG_KEY_SOCKET_KEEPALIVE,
- .value_type = CFG_VAL_TYPE_BOOL,
- },
- {
- .key_name = "socket_iptos",
- .key_value = MCFG_KEY_SOCKET_IPTOS,
- .value_type = CFG_VAL_TYPE_BOOL,
- },
- {
- .key_name = "socket_nodelay",
- .key_value = MCFG_KEY_SOCKET_NODELAY,
- .value_type = CFG_VAL_TYPE_BOOL,
- },
- {
- .key_name = NULL,
- .key_value = MCFG_KEY_INVALID,
- .value_type = CFG_VAL_TYPE_INVALID,
- }
-};
-
static void cfg_read()
{
char buf[4096];
@@ -280,7 +209,7 @@ static void cfg_read()
assert_return(cfg);
- fd = openat(dirfd(cfg->cfg_dir), DEFAULT_MAIN_CFG_FILE,
+ fd = openat(dirfd(cfg->cfg_dir), MINECPROXY_CFG_FILE,
O_RDONLY | O_CLOEXEC | O_NOCTTY);
if (fd < 0)
return;
@@ -291,7 +220,7 @@ static void cfg_read()
fd = -1;
debug(DBG_CFG, "opened main config file %s/%s", cfg->cfg_real_path,
- DEFAULT_MAIN_CFG_FILE);
+ MINECPROXY_CFG_FILE);
for (off = 0; off < sizeof(buf); off += r) {
r = fread(buf + off, 1, sizeof(buf) - off, cfgfile);
@@ -301,14 +230,14 @@ static void cfg_read()
if (off >= sizeof(buf) - 1)
die("main config file %s/%s too large", cfg->cfg_real_path,
- DEFAULT_MAIN_CFG_FILE);
+ MINECPROXY_CFG_FILE);
buf[off] = '\0';
pos = buf;
- if (!config_parse_header("mcproxy", &pos, &lineno))
+ if (!config_parse_header(MINECPROXY_CFG_HEADER, &pos, &lineno))
die("main config file %s/%s missing/invalid header",
- cfg->cfg_real_path, DEFAULT_MAIN_CFG_FILE);
+ cfg->cfg_real_path, MINECPROXY_CFG_FILE);
while (true) {
int key;
@@ -316,14 +245,14 @@ static void cfg_read()
struct cfg_value value;
const char *error;
- if (!config_parse_line(DEFAULT_MAIN_CFG_FILE, &pos,
+ if (!config_parse_line(MINECPROXY_CFG_FILE, &pos,
mcfg_key_map, &key, &keyname,
&value, false, &lineno, &error))
break;
if (key == MCFG_KEY_INVALID)
die("main config file %s/%s invalid: line %u: %s",
- cfg->cfg_real_path, DEFAULT_MAIN_CFG_FILE, lineno,
+ cfg->cfg_real_path, MINECPROXY_CFG_FILE, lineno,
error);
debug(DBG_CFG, "main cfg: key %s", keyname);
diff --git a/minecproxy/minecproxy-config-options.h b/minecproxy/minecproxy-config-options.h
new file mode 100644
index 0000000..5107f27
--- /dev/null
+++ b/minecproxy/minecproxy-config-options.h
@@ -0,0 +1,77 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef foominecproxyconfigoptionshfoo
+#define foominecproxyconfigoptionshfoo
+
+enum mcfg_keys {
+ MCFG_KEY_INVALID = 0,
+ MCFG_KEY_IGMP,
+ MCFG_KEY_IGMP_IFACE,
+ MCFG_KEY_ANNOUNCE_INTERVAL,
+ MCFG_KEY_PROXY_CONN_INTERVAL,
+ MCFG_KEY_PROXY_CONN_ATTEMPTS,
+ MCFG_KEY_SOCKET_DEFER,
+ MCFG_KEY_SOCKET_FREEBIND,
+ MCFG_KEY_SOCKET_KEEPALIVE,
+ MCFG_KEY_SOCKET_IPTOS,
+ MCFG_KEY_SOCKET_NODELAY,
+};
+
+struct cfg_key_value_map mcfg_key_map[] = {
+ {
+ .key_name = "igmp",
+ .key_value = MCFG_KEY_IGMP,
+ .value_type = CFG_VAL_TYPE_BOOL,
+ },
+ {
+ .key_name = "igmp_iface",
+ .key_value = MCFG_KEY_IGMP_IFACE,
+ .value_type = CFG_VAL_TYPE_STRING,
+ },
+ {
+ .key_name = "announce_interval",
+ .key_value = MCFG_KEY_ANNOUNCE_INTERVAL,
+ .value_type = CFG_VAL_TYPE_UINT16,
+ },
+ {
+ .key_name = "proxy_connection_interval",
+ .key_value = MCFG_KEY_PROXY_CONN_INTERVAL,
+ .value_type = CFG_VAL_TYPE_UINT16,
+ },
+ {
+ .key_name = "proxy_connection_attempts",
+ .key_value = MCFG_KEY_PROXY_CONN_ATTEMPTS,
+ .value_type = CFG_VAL_TYPE_UINT16,
+ },
+ {
+ .key_name = "socket_defer",
+ .key_value = MCFG_KEY_SOCKET_DEFER,
+ .value_type = CFG_VAL_TYPE_BOOL,
+ },
+ {
+ .key_name = "socket_freebind",
+ .key_value = MCFG_KEY_SOCKET_FREEBIND,
+ .value_type = CFG_VAL_TYPE_BOOL,
+ },
+ {
+ .key_name = "socket_keepalive",
+ .key_value = MCFG_KEY_SOCKET_KEEPALIVE,
+ .value_type = CFG_VAL_TYPE_BOOL,
+ },
+ {
+ .key_name = "socket_iptos",
+ .key_value = MCFG_KEY_SOCKET_IPTOS,
+ .value_type = CFG_VAL_TYPE_BOOL,
+ },
+ {
+ .key_name = "socket_nodelay",
+ .key_value = MCFG_KEY_SOCKET_NODELAY,
+ .value_type = CFG_VAL_TYPE_BOOL,
+ },
+ {
+ .key_name = NULL,
+ .key_value = MCFG_KEY_INVALID,
+ .value_type = CFG_VAL_TYPE_INVALID,
+ }
+};
+
+#endif
diff --git a/minecproxy/server-config.c b/minecproxy/server-config.c
index baf47fb..4e77716 100644
--- a/minecproxy/server-config.c
+++ b/minecproxy/server-config.c
@@ -111,7 +111,7 @@ static void server_cfg_read_cb(struct uring_task *task, int res)
return;
}
- sprop = xstrcat(server->scfg.name, "/server.properties", NULL);
+ sprop = xstrcat(server->scfg.name, "/" MC_SERVER_PROPERTIES, NULL);
if (!sprop) {
error("%s: xstrcat %m", server->scfg.name);
server_delete(server);