diff options
Diffstat (limited to 'shared')
-rw-r--r-- | shared/ansi-colors.h | 12 | ||||
-rw-r--r-- | shared/config-parser.c | 38 | ||||
-rw-r--r-- | shared/config-parser.h | 5 | ||||
-rw-r--r-- | shared/meson.build | 4 | ||||
-rw-r--r-- | shared/rcon-protocol.h | 1 | ||||
-rw-r--r-- | shared/utils.h | 1 |
6 files changed, 59 insertions, 2 deletions
diff --git a/shared/ansi-colors.h b/shared/ansi-colors.h new file mode 100644 index 0000000..ba89c46 --- /dev/null +++ b/shared/ansi-colors.h @@ -0,0 +1,12 @@ +#ifndef fooansicolorshfoo +#define fooansicolorshfoo + +#define ANSI_RED "\x1B[0;31m" +#define ANSI_GREEN "\x1B[0;32m" +#define ANSI_YELLOW "\x1B[0;33m" +#define ANSI_BLUE "\x1B[0;34m" +#define ANSI_MAGENTA "\x1B[0;35m" +#define ANSI_GREY "\x1B[0;38;5;245m" +#define ANSI_NORMAL "\x1B[0m" + +#endif diff --git a/shared/config-parser.c b/shared/config-parser.c index 9f294f4..1f44db4 100644 --- a/shared/config-parser.c +++ b/shared/config-parser.c @@ -6,9 +6,12 @@ #include <unistd.h> #include <arpa/inet.h> #include <inttypes.h> +#include <sys/types.h> +#include <dirent.h> #include "utils.h" #include "config-parser.h" +#include "config.h" static void eat_whitespace_and_comments(char **pos) @@ -162,7 +165,7 @@ out: return rv; } -static bool +bool strtosockaddrs(const char *str, struct cfg_value *rvalue, bool async) { struct saddr *saddr; @@ -478,3 +481,36 @@ config_parse_header(const char *title, char **buf) return false; } + +bool +is_valid_server_config_filename(struct dirent *dent, const char *filename) +{ + const char *suffix; + + assert_return(!(dent && filename) && !(!dent && !filename), false); + + /* Maybe accept DT_LNK? */ + if (dent) { + switch (dent->d_type) { + case DT_UNKNOWN: + _fallthrough_; + case DT_REG: + break; + default: + return false; + } + filename = dent->d_name; + } + + if (empty_str(filename)) + return false; + if (filename[0] == '.') + return false; + if ((suffix = strrchr(filename, '.')) == NULL) + return false; + if (!streq(suffix, "." SERVER_CONFIG_FILE_SUFFIX)) + return false; + + return true; +} + diff --git a/shared/config-parser.h b/shared/config-parser.h index 7d99e31..7c5703e 100644 --- a/shared/config-parser.h +++ b/shared/config-parser.h @@ -5,6 +5,7 @@ #include <sys/socket.h> #include <netdb.h> #include <signal.h> +#include <dirent.h> enum cfg_value_type { CFG_VAL_TYPE_INVALID, @@ -47,6 +48,8 @@ struct cfg_value { }; }; +bool strtosockaddrs(const char *str, struct cfg_value *rvalue, bool async); + bool config_parse_line(const char *filename, char **buf, struct cfg_key_value_map *kvmap, int *rkey, const char **rkeyname, @@ -54,4 +57,6 @@ bool config_parse_line(const char *filename, char **buf, bool config_parse_header(const char *title, char **buf); +bool is_valid_server_config_filename(struct dirent *dent, const char *filename); + #endif diff --git a/shared/meson.build b/shared/meson.build index e4e4f29..ccfad4a 100644 --- a/shared/meson.build +++ b/shared/meson.build @@ -6,7 +6,9 @@ srcs_libshared = [ inc_libshared = include_directories('.') -deps_libshared = [] +deps_libshared = [ + dep_config_h, +] lib_libshared = static_library( 'shared', diff --git a/shared/rcon-protocol.h b/shared/rcon-protocol.h index 35997c4..097da1d 100644 --- a/shared/rcon-protocol.h +++ b/shared/rcon-protocol.h @@ -4,6 +4,7 @@ #include <stdbool.h> #include <stdint.h> +/* FIXME: FAIL is an id, not type, LOGIN_OK should be LOGIN_RESPONSE */ enum rcon_packet_type { RCON_PACKET_LOGIN = 3, RCON_PACKET_LOGIN_OK = 2, diff --git a/shared/utils.h b/shared/utils.h index 769d3e3..3ed1c87 100644 --- a/shared/utils.h +++ b/shared/utils.h @@ -40,6 +40,7 @@ extern unsigned debug_mask; #include "list.h" #include "debug.h" #include "external.h" +#include "ansi-colors.h" /* Length of longest DNS name = 253 + trailing dot */ #define FQDN_STR_LEN 254 |