diff -r b7dcc9c4f270 -r f1d29785ad2d src/server/daemon/config.c --- a/src/server/daemon/config.c Mon Nov 07 17:59:44 2022 +0100 +++ b/src/server/daemon/config.c Mon Nov 07 22:30:12 2022 +0100 @@ -75,7 +75,6 @@ log_ereport(LOG_FAILURE, "Cannot load init.conf"); return 1; } - CxAllocator *mp = cfg->mp; init_pool = pool_create(); ConfigNode *dir = cfg->root->children_begin; @@ -838,78 +837,82 @@ return ret; } -static int convert_objconf(ServerConfiguration *scfg, ObjectConfig *cfg, HTTPObjectConfig *conf, cxmutstr file) { +static int convert_objconf(ServerConfiguration *scfg, ObjectConfig2 *cfg, HTTPObjectConfig *conf, cxmutstr file) { pool_handle_t *pool = conf->pool; - CxList *objlist = cfg->objects; - CxIterator iter = cxListIterator(objlist, 0); int i = 0; - cx_foreach(ConfigObject*, cob, iter) { + for(ConfigNode *objnode=cfg->root->children_begin;objnode;objnode=objnode->next) { + if(objnode->type != CONFIG_NODE_OBJECT) { + continue; + } + // get name and ppath + cxmutstr cfg_name = cfg_param_get(objnode->args, cx_str("name")); + cxmutstr cfg_ppath = cfg_param_get(objnode->args, cx_str("ppath")); + char *name = NULL; char *ppath = NULL; - if(cob->name.length > 0) { - name = cx_strdup_pool(pool, cob->name).ptr; + + if(cfg_name.length > 0) { + name = cx_strdup_pool(pool, cfg_name).ptr; if(!name) return -1; } - if(cob->ppath.length > 0) { - ppath = cx_strdup_pool(pool, cob->ppath).ptr; + if(cfg_ppath.length > 0) { + ppath = cx_strdup_pool(pool, cfg_ppath).ptr; if(!ppath) return -1; } - + // create and add object httpd_object *obj = object_new(pool, name); if(!obj) return -1; obj->path = NULL; - + conf->objects[i] = obj; - + + // TODO: this doesn't work with If/Else... nodes + // and needs to be rewritten // add directives - for(int j=0;jdirectives[j]; - while(dirs != NULL) { - ConfigDirective *cfgdir = dirs->directive; - - directive *d = pool_malloc(pool, sizeof(directive)); - if(!d) return -1; - if(cfgdir->condition) { - cxmutstr expr = cfgdir->condition->param_str; - d->cond = condition_from_str(pool, expr.ptr, expr.length); - } else { - d->cond = NULL; - } - d->param = pblock_create_pool(pool, 8); + for(ConfigNode *dir=objnode->children_begin;dir;dir=dir->next) { + if(dir->type != CONFIG_NODE_DIRECTIVE) { + continue; + } + + directive *d = pool_malloc(pool, sizeof(directive)); + if(!d) return -1; + d->param = pblock_create_pool(pool, 8); - // add params - ConfigParam *param = cfg_param_list(cfgdir->value, scfg->a); - while(param != NULL) { - pblock_nvlinsert( - param->name.ptr, - param->name.length, - param->value.ptr, - param->value.length, - d->param); - param = param->next; - } + // add params + ConfigParam *param = dir->args; + while(param != NULL) { + pblock_nvlinsert( + param->name.ptr, + param->name.length, + param->value.ptr, + param->value.length, + d->param); + param = param->next; + } - // get function - char *func_name = pblock_findval("fn", d->param); - if(!func_name) { - log_ereport(LOG_MISCONFIG, "%s: Missing fn parameter", file.ptr); - return -1; - } - d->func = get_function(func_name); - if(!d->func) { - log_ereport(LOG_MISCONFIG, "func %s not found", func_name); - return -1; - } + // get function + char *func_name = pblock_findval("fn", d->param); + if(!func_name) { + log_ereport(LOG_MISCONFIG, "%s: Missing fn parameter", file.ptr); + return -1; + } + d->func = get_function(func_name); + if(!d->func) { + log_ereport(LOG_MISCONFIG, "func %s not found", func_name); + return -1; + } - dirs = dirs->next; - - // add function to dtable - object_add_directive(obj, d, cfgdir->type_num); + // add function to dtable + int dir_type = cfg_get_directive_type_num(cx_strcast(dir->name)); + if(dir_type < 0) { + log_ereport(LOG_MISCONFIG, "unknown directive type %s", dir->name); } + object_add_directive(obj, d, dir_type); } + // next i++; @@ -932,7 +935,7 @@ conf->pool = pool; // load obj config file - ObjectConfig *cfg = load_object_config(file.ptr); + ObjectConfig2 *cfg = objectconf_load(file.ptr); if(!cfg) { return NULL; } @@ -940,7 +943,7 @@ // convert ObjectConfig to HTTPObjectConfig // add objects - conf->nobj = cfg->objects->size; + conf->nobj = serverconfig_children_count(cfg->root, CONFIG_NODE_OBJECT); conf->objects = pool_calloc(pool, conf->nobj, sizeof(httpd_object*)); if(conf->objects) { ret = convert_objconf(scfg, cfg, conf, file); @@ -948,7 +951,7 @@ ret = -1; } - free_object_config(cfg); + objectconf_free(cfg); return !ret ? conf : NULL; }