diff -r 90805bb9fbd6 -r b7dcc9c4f270 src/server/config/serverconfig.h --- a/src/server/config/serverconfig.h Sun Nov 06 17:41:39 2022 +0100 +++ b/src/server/config/serverconfig.h Mon Nov 07 17:59:44 2022 +0100 @@ -56,7 +56,7 @@ struct ServerConfig { CxMempool *mp; ConfigNode *root; - cxmutstr tab; + cxstring tab; }; enum ConfigNodeType { @@ -103,6 +103,7 @@ enum ConfigParserError { CONFIG_PARSER_OOM = 0, + CONFIG_PARSER_IO_ERROR, CONFIG_PARSER_SYNTAX_ERROR }; @@ -118,7 +119,12 @@ struct ConfigParser2 { CxMempool *mp; - int error; + enum ConfigParserError error; + + /* + * errno in case of IO errors (parser.error == CONFIG_PARSER_IO_ERROR) + */ + int io_errno; /* * called when an object is started @@ -144,7 +150,9 @@ ServerConfig* serverconfig_load(const char *file); -ServerConfig* serverconfig_parse(ConfigParser2 *parser, cxstring content); +ConfigNode* serverconfig_load_file(ConfigParser2 *parser, const char *file); + +ConfigNode* serverconfig_parse(ConfigParser2 *parser, cxstring content); void serverconfig_free(ServerConfig *cfg); @@ -152,9 +160,42 @@ CxList* serverconfig_get_node_list(ConfigNode *parent, ConfigNodeType type, cxstring name); -cxstring serverconfig_directive_value(ConfigNode *obj, cxstring name); +/* + * Searches in the specified object for the directive with the name + * directive_name and returns the value + * + * Directives only have a value, if they have one argument + */ +cxstring serverconfig_object_directive_value(ConfigNode *obj, cxstring directive_name); + +/* + * Returns the directive parameter value that has the specified name + */ +cxstring serverconfig_directive_get_arg(ConfigNode *directive, cxstring param_name); + -cxmutstr serverconfig_arg_name_value(CxAllocator *a, cxstring str, cxstring *name); +/* + * Checks if the directive name matches any string in the names array. + * If it matches a name, the function returns 0 and stores the index of the + * matched name in nameindex + * If it doesn't match a name, the function returns 1 + */ +int serverconfig_validate_directive_name( + ConfigNode *directive, + const char *names[], + size_t numnames, + size_t *nameindex); + +/* + * Checks if all directive parameters have a name + * If every parameter has a name, the function returns 0 + * otherwise it returns 1 + * + * If a parameter doesn't contain a name, err is set to this parameter + * + * config file syntax: paramname="value" + */ +int serverconfig_check_param_names(ConfigNode *directive, ConfigParam **err); #ifdef __cplusplus }