diff -r e2093ca0ef90 -r 90805bb9fbd6 src/server/config/serverconfig.h --- a/src/server/config/serverconfig.h Sun Nov 06 16:59:39 2022 +0100 +++ b/src/server/config/serverconfig.h Sun Nov 06 17:41:39 2022 +0100 @@ -34,6 +34,8 @@ #include #include +#include + #include "conf.h" #ifdef __cplusplus @@ -46,6 +48,7 @@ typedef struct ServerConfig ServerConfig; typedef struct ConfigNode ConfigNode; typedef struct CFGToken CFGToken; +typedef struct ConfigParser2 ConfigParser2; // TODO: rename to ConfigParser after old ConfigParser is removed typedef enum ConfigNodeType ConfigNodeType; typedef enum CFGTokenType CFGTokenType; @@ -98,9 +101,50 @@ CFGTokenType type; }; +enum ConfigParserError { + CONFIG_PARSER_OOM = 0, + CONFIG_PARSER_SYNTAX_ERROR +}; + +/* + * CfgValidateNodeFunc functions are called by the parser to validate + * objects and directives. + * + * The function must return 0 if the validation was successful. If the + * functions returns a value != 0, the parser aborts. + */ +typedef int(*CfgValidateNodeFunc)(ConfigParser2 *parser, ConfigNode *node); + +struct ConfigParser2 { + CxMempool *mp; + + int error; + + /* + * called when an object is started + */ + CfgValidateNodeFunc validateObjBegin; + + /* + * called when an object is closed + */ + CfgValidateNodeFunc validateObjEnd; + + /* + * called before a directive is added + */ + CfgValidateNodeFunc validateDirective; + + /* + * true: store result in a tree + * false: flat list of directives, don't allow '{' and '}' + */ + bool allow_hierarchy; +}; + ServerConfig* serverconfig_load(const char *file); -ServerConfig* serverconfig_parse(cxstring content); +ServerConfig* serverconfig_parse(ConfigParser2 *parser, cxstring content); void serverconfig_free(ServerConfig *cfg);