diff -r 90805bb9fbd6 -r b7dcc9c4f270 src/server/daemon/config.c --- a/src/server/daemon/config.c Sun Nov 06 17:41:39 2022 +0100 +++ b/src/server/daemon/config.c Mon Nov 07 17:59:44 2022 +0100 @@ -70,22 +70,32 @@ int load_init_conf(char *file) { log_ereport(LOG_VERBOSE, "load_init_conf"); - InitConfig *cfg = load_init_config(file); + InitConfig *cfg = initconfig_load(file); if(cfg == NULL) { log_ereport(LOG_FAILURE, "Cannot load init.conf"); return 1; } - CxAllocator *mp = cfg->parser.mp; - - init_pool = pool_create(); // one pool for one Configuration - ConfigDirectiveList *dirs = cfg->directives; - while(dirs != NULL) { - ConfigDirective *dir = dirs->directive; - - /* create NSAPI directive */ - directive *d = malloc(sizeof(directive)); + CxAllocator *mp = cfg->mp; + init_pool = pool_create(); + + ConfigNode *dir = cfg->root->children_begin; + while(dir) { + if(dir->type != CONFIG_NODE_DIRECTIVE) { + // dir is just space/comment + dir = dir->next; + continue; + } + + // create NSAPI directive + + // The parser checks the directive name and makes sure it is "Init" + // if more than one init directive type is introduced, the parser + // must be extended and also dir->name must be checked here + + directive *d = pool_malloc(init_pool, sizeof(directive)); d->param = pblock_create_pool(init_pool, 8); - ConfigParam *param = cfg_param_list(dir->value, mp); + + ConfigParam *param = dir->args; while(param != NULL) { pblock_nvlinsert( param->name.ptr, @@ -96,39 +106,33 @@ param = param->next; } - - /* get function */ + + // get function + // the parser makes sure that an "fn" parameter always exists char *func_name = pblock_findval("fn", d->param); d->func = get_function(func_name); if(d->func == NULL) { - pblock_free(d->param); - free(d); - //dirs = dirs->next; log_ereport( LOG_MISCONFIG, "Cannot find Init function %s", func_name); return 1; } - - /* execute init directive */ + + // execute init directive int ret = d->func->func(d->param, NULL, NULL); if(ret != REQ_PROCEED && ret != REQ_NOACTION) { log_ereport( LOG_FAILURE, "Error running Init function %s", func_name); - pblock_free(d->param); - free(d); return 1; } - pblock_free(d->param); - free(d); - dirs = dirs->next; + dir = dir->next; } - free_init_config(cfg); + initconfig_free(cfg); return 0; } @@ -356,11 +360,11 @@ } int cfg_handle_runtime(ServerConfiguration *cfg, ConfigNode *obj) { - cxstring user = serverconfig_directive_value(obj, cx_str("User")); + cxstring user = serverconfig_object_directive_value(obj, cx_str("User")); if(user.ptr) { cfg->user = cx_strdup_a(cfg->a, user); } - cxstring tmp = serverconfig_directive_value(obj, cx_str("Temp")); + cxstring tmp = serverconfig_object_directive_value(obj, cx_str("Temp")); if(tmp.ptr) { cfg->tmp = cx_strdup_a(cfg->a, tmp); } else { @@ -370,7 +374,7 @@ } // mime file - cxstring mf = serverconfig_directive_value(obj, cx_str("MimeFile")); + cxstring mf = serverconfig_object_directive_value(obj, cx_str("MimeFile")); cxstring base = cx_str("config/"); cxmutstr file = cx_strcat(2, base, mf); @@ -383,8 +387,8 @@ } int cfg_handle_logfile(ServerConfiguration *cfg, ConfigNode *obj) { - cxstring file = serverconfig_directive_value(obj, cx_str("File")); - cxstring lvl = serverconfig_directive_value(obj, cx_str("Level")); + cxstring file = serverconfig_object_directive_value(obj, cx_str("File")); + cxstring lvl = serverconfig_object_directive_value(obj, cx_str("Level")); int err = 0; if(file.ptr == NULL) { @@ -419,11 +423,11 @@ poolcfg.queue_size = 64; poolcfg.stack_size = 262144; - cxstring name = serverconfig_directive_value(obj, cx_str("Name")); - cxstring min = serverconfig_directive_value(obj, cx_str("MinThreads")); - cxstring max = serverconfig_directive_value(obj, cx_str("MaxThreads")); - cxstring stack = serverconfig_directive_value(obj, cx_str("StackSize")); - cxstring queue = serverconfig_directive_value(obj, cx_str("QueueSize")); + cxstring name = serverconfig_object_directive_value(obj, cx_str("Name")); + cxstring min = serverconfig_object_directive_value(obj, cx_str("MinThreads")); + cxstring max = serverconfig_object_directive_value(obj, cx_str("MaxThreads")); + cxstring stack = serverconfig_object_directive_value(obj, cx_str("StackSize")); + cxstring queue = serverconfig_object_directive_value(obj, cx_str("QueueSize")); // TODO: Type if(name.length == 0) { @@ -478,9 +482,9 @@ int cfg_handle_eventhandler(ServerConfiguration *c, ConfigNode *obj) { EventHandlerConfig evcfg; - cxstring name = serverconfig_directive_value(obj, cx_str("Name")); - cxstring threads = serverconfig_directive_value(obj, cx_str("Threads")); - cxstring isdefault = serverconfig_directive_value(obj, cx_str("Default")); + cxstring name = serverconfig_object_directive_value(obj, cx_str("Name")); + cxstring threads = serverconfig_object_directive_value(obj, cx_str("Threads")); + cxstring isdefault = serverconfig_object_directive_value(obj, cx_str("Default")); evcfg.name = name; @@ -502,8 +506,8 @@ } int cfg_handle_resourcepool(ServerConfiguration *cfg, ConfigNode *obj) { - cxstring name = serverconfig_directive_value(obj, cx_str("Name")); - cxstring type = serverconfig_directive_value(obj, cx_str("Type")); + cxstring name = serverconfig_object_directive_value(obj, cx_str("Name")); + cxstring type = serverconfig_object_directive_value(obj, cx_str("Type")); int ret = 0; if(resourcepool_new(cfg, type, name, obj)) { @@ -516,7 +520,7 @@ int cfg_handle_accesslog(ServerConfiguration *cfg, ConfigNode *obj) { // TODO: use a name to identify the log file - cxstring file = serverconfig_directive_value(obj, cx_str("File")); + cxstring file = serverconfig_object_directive_value(obj, cx_str("File")); if(file.ptr == NULL) { return 0; } @@ -544,19 +548,19 @@ } int cfg_handle_authdb(ServerConfiguration *cfg, ConfigNode *obj) { - cxstring name = serverconfig_directive_value(obj, cx_str("Name")); - cxstring type = serverconfig_directive_value(obj, cx_str("Type")); + cxstring name = serverconfig_object_directive_value(obj, cx_str("Name")); + cxstring type = serverconfig_object_directive_value(obj, cx_str("Type")); AuthDB *authdb = NULL; if(!cx_strcmp(type, cx_str("ldap"))) { LDAPConfig conf; - cxstring host = serverconfig_directive_value(obj, cx_str("Host")); - cxstring port = serverconfig_directive_value( obj, cx_str("Port")); - cxstring basedn = serverconfig_directive_value(obj, cx_str("BaseDN")); - cxstring binddn = serverconfig_directive_value(obj, cx_str("BindDN")); - cxstring basepw = serverconfig_directive_value(obj, cx_str("BindPW")); + cxstring host = serverconfig_object_directive_value(obj, cx_str("Host")); + cxstring port = serverconfig_object_directive_value( obj, cx_str("Port")); + cxstring basedn = serverconfig_object_directive_value(obj, cx_str("BaseDN")); + cxstring binddn = serverconfig_object_directive_value(obj, cx_str("BindDN")); + cxstring basepw = serverconfig_object_directive_value(obj, cx_str("BindPW")); conf.hostname = cx_strdup_a(cfg->a, host).ptr; conf.port = atoi(port.ptr); @@ -567,7 +571,7 @@ authdb = create_ldap_authdb(cfg, name.ptr, &conf); } else if(!cx_strcmp(type, cx_str("keyfile"))) { // we only need the file parameter - cxstring file = serverconfig_directive_value(obj, cx_str("File")); + cxstring file = serverconfig_object_directive_value(obj, cx_str("File")); if(file.length == 0) { log_ereport( LOG_MISCONFIG, @@ -595,11 +599,11 @@ lc.port = 8080; lc.nacceptors = 1; - cxstring name = serverconfig_directive_value(obj, cx_str("Name")); - cxstring port = serverconfig_directive_value(obj, cx_str("Port")); - cxstring vs = serverconfig_directive_value(obj, cx_str("DefaultVS")); - cxstring thrp = serverconfig_directive_value(obj, cx_str("Threadpool")); - cxstring blck = serverconfig_directive_value(obj, cx_str("BlockingIO")); + cxstring name = serverconfig_object_directive_value(obj, cx_str("Name")); + cxstring port = serverconfig_object_directive_value(obj, cx_str("Port")); + cxstring vs = serverconfig_object_directive_value(obj, cx_str("DefaultVS")); + cxstring thrp = serverconfig_object_directive_value(obj, cx_str("Threadpool")); + cxstring blck = serverconfig_object_directive_value(obj, cx_str("BlockingIO")); // TODO: use cx_strdup_pool? int64_t port_value; @@ -619,12 +623,12 @@ lc.blockingio = util_getboolean_s(blck, WS_FALSE); - cxstring ssl = serverconfig_directive_value(obj, cx_str("SSL")); + cxstring ssl = serverconfig_object_directive_value(obj, cx_str("SSL")); if(util_getboolean_s(ssl, WS_FALSE)) { - cxstring cert = serverconfig_directive_value(obj, cx_str("Cert")); - cxstring privkey = serverconfig_directive_value(obj, cx_str("Key")); - cxstring chain = serverconfig_directive_value(obj, cx_str("CertChain")); - cxstring disableprot = serverconfig_directive_value(obj, cx_str("SSLDisableProtocol")); + cxstring cert = serverconfig_object_directive_value(obj, cx_str("Cert")); + cxstring privkey = serverconfig_object_directive_value(obj, cx_str("Key")); + cxstring chain = serverconfig_object_directive_value(obj, cx_str("CertChain")); + cxstring disableprot = serverconfig_object_directive_value(obj, cx_str("SSLDisableProtocol")); WSBool config_ok = WS_TRUE; // TODO: log error @@ -670,12 +674,12 @@ int cfg_handle_vs(ServerConfiguration *cfg, ConfigNode *obj) { VirtualServer *vs = vs_new(); - vs->name = cx_strdup_a(cfg->a, serverconfig_directive_value(obj, cx_str("Name"))); - vs->host = cx_strdup_a(cfg->a, serverconfig_directive_value(obj, cx_str("Host"))); - vs->document_root = cx_strdup_a(cfg->a, serverconfig_directive_value(obj, cx_str("DocRoot"))); + vs->name = cx_strdup_a(cfg->a, serverconfig_object_directive_value(obj, cx_str("Name"))); + vs->host = cx_strdup_a(cfg->a, serverconfig_object_directive_value(obj, cx_str("Host"))); + vs->document_root = cx_strdup_a(cfg->a, serverconfig_object_directive_value(obj, cx_str("DocRoot"))); - cxstring objfile = serverconfig_directive_value(obj, cx_str("ObjectFile")); - cxstring aclfile = serverconfig_directive_value(obj, cx_str("ACLFile")); + cxstring objfile = serverconfig_object_directive_value(obj, cx_str("ObjectFile")); + cxstring aclfile = serverconfig_object_directive_value(obj, cx_str("ACLFile")); // load the object config file cxstring base = cx_str("config/"); @@ -797,7 +801,7 @@ cxListDestroy(backends); // initialize vfs - cxstring vfs_class = serverconfig_directive_value(obj, cx_str("VFS")); + cxstring vfs_class = serverconfig_object_directive_value(obj, cx_str("VFS")); if(vfs_class.length > 0) { VfsType *vfs = vfs_get_type((cxstring){vfs_class.ptr, vfs_class.length}); if(vfs) { @@ -812,7 +816,7 @@ } } - cxstring object = serverconfig_directive_value(obj, cx_str("Object")); + cxstring object = serverconfig_object_directive_value(obj, cx_str("Object")); if(object.length > 0) { repository->object = cx_strdup_a(a, object); if(repository->object.length != object.length) {