summaryrefslogtreecommitdiff
path: root/shared/config-parser.h
blob: ad7e4b205c20c0c5d0e343e6e61157389c27b418 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef fooconfigparserhfoo
#define fooconfigparserhfoo

#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <signal.h>
#include <dirent.h>

enum server_type {
	SERVER_TYPE_UNDEFINED,
	SERVER_TYPE_ANNOUNCE,
	SERVER_TYPE_PROXY,
};

enum server_stop_method {
	SERVER_STOP_METHOD_UNDEFINED,
	SERVER_STOP_METHOD_RCON,
	SERVER_STOP_METHOD_SYSTEMD,
	SERVER_STOP_METHOD_EXEC,
};

enum server_start_method {
	SERVER_START_METHOD_UNDEFINED,
	SERVER_START_METHOD_SYSTEMD,
	SERVER_START_METHOD_EXEC,
};

enum server_announce {
	SERVER_ANNOUNCE_UNDEFINED,
	SERVER_ANNOUNCE_ALWAYS,
	SERVER_ANNOUNCE_NEVER,
	SERVER_ANNOUNCE_WHEN_RUNNING,
};

struct server_config {
	char *name;
	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;
	enum server_start_method start_method;
	char *stop_exec;
	char *start_exec;
	char *rcon_password;
	char *systemd_service;
	char *systemd_obj;
	struct list_head locals;
	struct list_head remotes;
	struct list_head rcons;

	struct list_head dnslookups;
	struct gaicb **gcbs;
	struct sigevent dns_sev;
};

enum cfg_value_type {
	CFG_VAL_TYPE_INVALID,
	CFG_VAL_TYPE_STRING,
	CFG_VAL_TYPE_UINT16,
	CFG_VAL_TYPE_ADDRS,
	CFG_VAL_TYPE_ASYNC_ADDRS,
	CFG_VAL_TYPE_BOOL,
};

struct dns_async {
	char name[FQDN_STR_LEN + 1];
	char port[PORT_STR_LEN + 1];
	bool pending;
	struct addrinfo req;
	struct gaicb gcb;
	struct list_head *target_list;
	struct list_head list;
};

struct cfg_key_value_map {
	const char *key_name;
	int key_value;
	enum cfg_value_type value_type;
};

struct cfg_value {
	enum cfg_value_type type;
	union {
		const char *str;
		uint16_t uint16;
		struct list_head saddrs;
		struct dns_async *dns_async;
		bool boolean;
	};
};

void scfg_async_dns_update(struct server_config *scfg);

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);

void scfg_delete(struct server_config *scfg);

bool scfg_init(struct server_config *scfg, const char *filename);

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, struct cfg_value *rvalue,
		       bool async_dns, unsigned *lineno, const char **error);

bool config_parse_header(const char *title, char **buf, unsigned *lineno);

bool config_valid_server_filename(struct dirent *dent, const char *filename);

#endif