Sat, 12 Nov 2022 12:09:37 +0100
make config parser delimiters configurable
--- a/src/server/config/objconf.c Sat Nov 12 11:52:47 2022 +0100 +++ b/src/server/config/objconf.c Sat Nov 12 12:09:37 2022 +0100 @@ -75,6 +75,7 @@ ConfigParser2 parser; memset(&parser, 0, sizeof(ConfigParser2)); parser.mp = mp; + parser.delim = "()/*%"; parser.validateDirective = objectconf_validate_directive; parser.validateObjBegin = objectconf_validate_objbegin; parser.validateObjEnd = objectconf_validate_objend;
--- a/src/server/config/serverconfig.c Sat Nov 12 11:52:47 2022 +0100 +++ b/src/server/config/serverconfig.c Sat Nov 12 12:09:37 2022 +0100 @@ -49,6 +49,7 @@ memset(&parser, 0, sizeof(ConfigParser2)); parser.mp = mp; parser.allow_hierarchy = true; + parser.delim = ""; ConfigNode *root = serverconfig_load_file(&parser, file); if(!root) { cxMempoolDestroy(mp); @@ -96,17 +97,17 @@ return root; } -static int scfg_char_is_delim(char c) { - static const char *scfg_tokenizer_delim = "()/*%"; - for(int i=0;i<sizeof(scfg_tokenizer_delim)-1;i++) { - if(c == scfg_tokenizer_delim[i]) { +static int scfg_char_is_delim(ConfigParser2 *parser, char c) { + size_t len = strlen(parser->delim); + for(int i=0;i<len;i++) { + if(c == parser->delim[i]) { return 1; } } return 0; } -static CFGToken get_next_token(cxstring content, int *pos) { +static CFGToken get_next_token(ConfigParser2 *parser, cxstring content, int *pos) { CFGToken token = { {NULL, 0}, CFG_NO_TOKEN }; CFGTokenType type = CFG_TOKEN; @@ -164,7 +165,7 @@ if(token_begin < 0) { token_begin = i; } - } else if(scfg_char_is_delim(c)) { + } else if(scfg_char_is_delim(parser, c)) { if(token_begin >= 0) { token_end = i; i--; @@ -248,6 +249,10 @@ CxMempool *mp = parser->mp; CxAllocator *a = (CxAllocator*)mp->allocator; + if(!parser->delim) { + parser->delim = ""; + } + // PARSE: // first non space/comment token is directive/object name // following tokens are arguments @@ -271,7 +276,7 @@ int text_start = 0; int err = 0; - while((token = get_next_token(content, &pos)).type != CFG_NO_TOKEN) { + while((token = get_next_token(parser, content, &pos)).type != CFG_NO_TOKEN) { //printf("%s [%.*s]\n", token_type_str(token.type), (int)token.content.length, token.content.ptr); switch(token.type) {