#ifndef fooconfigparserhfoo #define fooconfigparserhfoo #include #include #include #include #include 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; }; 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, }; typedef void (*notification_cb_t)(struct server_config *scfg, bool done); struct dns_async { char name[FQDN_STR_LEN + 1]; char port[PORT_STR_LEN + 1]; struct addrinfo req; struct gaicb gcb; struct sigevent sev; void (*cb)(struct dns_async *); notification_cb_t notification_cb; void *priv; 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; }; }; bool scfg_parse(struct server_config *scfg, char *buf, notification_cb_t notification_cb); 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); bool config_parse_header(const char *title, char **buf); bool is_valid_server_config_filename(struct dirent *dent, const char *filename); #endif