summaryrefslogtreecommitdiff
path: root/shared/config-parser.h
blob: d84f9fe6a0da1a0ef10159aae69ebdcc4ab64575 (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
#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,
};

struct server_config {
	char *filename;
	enum server_type type;
	char *pretty_name;
	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_result(struct server_config *scfg);

bool scfg_validate(struct server_config *scfg, const char **error);

bool scfg_async_dns_start(struct server_config *scfg);

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

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

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

#endif