# HG changeset patch # User Olaf Wintermann # Date 1326719212 -3600 # Node ID 73aacbf6e492f3826d23c71d09d2733f647fc40e # Parent d2a97bbeb57d1c2da272006996403fd320ef134f Added server.conf parser diff -r d2a97bbeb57d -r 73aacbf6e492 Makefile --- a/Makefile Sun Jan 15 20:30:45 2012 +0100 +++ b/Makefile Mon Jan 16 14:06:52 2012 +0100 @@ -53,7 +53,7 @@ cp work/bin/webservd.bin $(WS_INSTALL_DIR)bin/webservd rm work/bin/webservd.bin @echo "copy includes" - cp src/server/nsapi.h $(WS_INSTALL_DIR)include/nsapi.h + cp src/server/public/nsapi.h $(WS_INSTALL_DIR)include/nsapi.h @echo "copy scripts" sed s:%%WS_INSTALL_DIR%%:$(WS_INSTALL_DIR):g templates/bin/startserv.template > $(WS_INSTALL_DIR)bin/startserv chmod +x $(WS_INSTALL_DIR)bin/startserv diff -r d2a97bbeb57d -r 73aacbf6e492 src/server/config/conf.c --- a/src/server/config/conf.c Sun Jan 15 20:30:45 2012 +0100 +++ b/src/server/config/conf.c Mon Jan 16 14:06:52 2012 +0100 @@ -433,10 +433,10 @@ int i; for(i=1;i +#include +#include + +#include "serverconf.h" + +ServerConfig *load_server_config(char *file) { + FILE *in = fopen(file, "r"); + if(in == NULL) { + return NULL; + } + + ServerConfig *conf = malloc(sizeof(ServerConfig)); + conf->parser.parse = serverconf_parse; + conf->file = file; + conf->objects = ucx_map_new(8); + + conf->obj = NULL; + + int r = cfg_parse_basic_file((ConfigParser*)conf, in); + if(r != 0) { + // TODO: free + return NULL; + } + + return conf; +} + +void free_server_config(ServerConfig *conf) { + // TODO +} + +int serverconf_parse(void *p, ConfigLine *begin, ConfigLine *end, sstr_t line){ + ServerConfig *conf = p; + + begin->type = cfg_get_line_type(line); + switch(begin->type) { + case LINE_BEGIN_TAG: { + ConfigTag *tag = cfg_parse_begin_tag(line, conf->parser.mp); + + // create server config object + ServerConfigObject *obj = OBJ_NEW( + conf->parser.mp, + ServerConfigObject); + obj->type = tag->name; + obj->begin = begin; + obj->end = end; + obj->directives = NULL; + + // add object to server config + UcxList *list = ucx_map_sstr_get(conf->objects, obj->type); + list = ucx_list_append(list, obj); + ucx_map_sstr_put(conf->objects, obj->type, list); + conf->obj = obj; + + break; + } + case LINE_END_TAG: { + sstr_t tag = cfg_get_end_tag_name(line); + if(sstrcmp(tag, conf->obj->type) != 0) { + fprintf(stderr, "syntax error: wrong close tag\n"); + exit(-1); + } + conf->obj = NULL; + + break; + } + case LINE_DIRECTIVE: { + if(conf->obj == NULL) { + fprintf(stderr, "syntax error: directive outside of object\n"); + exit(-1); + } + + ConfigDirective *d = cfg_parse_directive(line, conf->parser.mp); + d->begin = begin; + d->end = end; + + //printf("%s.%s\n", conf->obj->type.ptr, d->directive_type.ptr); + conf->obj->directives = ucx_dlist_append(conf->obj->directives, d); + } + } + return 0; +} diff -r d2a97bbeb57d -r 73aacbf6e492 src/server/config/serverconf.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/server/config/serverconf.h Mon Jan 16 14:06:52 2012 +0100 @@ -0,0 +1,66 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SERVERCONF_H +#define SERVERCONF_H + +#include "conf.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct _server_conf_obj { + ConfigLine *begin; + ConfigLine *end; + + sstr_t type; + UcxDlist *directives; +} ServerConfigObject; + +typedef struct _server_conf { + ConfigParser parser; + char *file; + UcxMap *objects; // contains UcxList of ServerConfigObject + // parser temp vars + ServerConfigObject *obj; +} ServerConfig; + +ServerConfig *load_server_config(char *file); + +void free_server_config(ServerConfig *conf); + +int serverconf_parse(void *p, ConfigLine *begin, ConfigLine *end, sstr_t line); + + +#ifdef __cplusplus +} +#endif + +#endif /* SERVERCONF_H */ + diff -r d2a97bbeb57d -r 73aacbf6e492 src/server/daemon/conf.c --- a/src/server/daemon/conf.c Sun Jan 15 20:30:45 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,210 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2011 Olaf Wintermann. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "../public/nsapi.h" - -#include -#include - -#include -#include -#include -#include -#include - -#include "../ucx/string.h" - -#include "httplistener.h" -#include "conf.h" -#include "func.h" - -#include "vserver.h" -#include "../util/pblock.h" - -#include "../config/objconf.h" -#include "../config/initconf.h" - -VirtualServer *default_vs; - -pool_handle_t *cfg_pool; - -// TODO: Funktion für ConfigDirective -> directive -// TODO: Funktion für UcxList parameter list -> pblock -// TODO: ConfigurationManager -// TODO: server.conf - -void load_init_conf(char *file) { - printf("load_init_conf\n"); - - InitConfig *cfg = load_init_config("conf/init.conf"); - if(cfg == NULL) { - return; - } - - cfg_pool = pool_create(); // one pool for one Configuration - UcxDlist *dirs = cfg->directives; - while(dirs != NULL) { - ConfigDirective *dir = dirs->data; - - /* create NSAPI directive */ - directive *d = malloc(sizeof(directive)); - d->param = pblock_create_pool(cfg_pool, 8); - UcxList *param = dir->param; - while(param != NULL) { - ConfigParam *p = param->data; - pblock_nvlinsert( - p->name.ptr, - p->name.length, - p->value.ptr, - p->value.length, - d->param); - param = param->next; - } - - /* get function */ - char *func_name = pblock_findval("fn", d->param); - d->func = get_function(func_name); - if(d->func == NULL) { - free(d); - continue; - } - - /* execute init directive */ - d->func->func(d->param, NULL, NULL); - - dirs = dirs->next; - } - - free_init_config(cfg); -} - -void load_server_conf(char *file) { - printf("load_server_conf\n"); - - ListenerConfig *conf = malloc(sizeof(ListenerConfig)); - conf->port = 9090; - conf->nacceptors = 1; - conf->name = "default"; - - http_listener_new(conf); - - // virtual server - default_vs = vs_new(); - // load obj.conf - default_vs->objects = load_obj_conf("conf/obj.conf"); - default_vs->default_obj_name = "default"; - -} - -VirtualServer* conf_get_default_vs() { - return default_vs; -} - -HTTPObjectConfig* load_obj_conf(char *file) { - printf("load_obj_conf\n"); - - // new conf function test - ObjectConfig *cfg = load_object_config(file); - if(cfg == NULL) { - return NULL; - } - - /* create object config */ - HTTPObjectConfig *conf = calloc(sizeof(HTTPObjectConfig), 1); - conf->pool = cfg_pool; - - /* convert ObjectConfig to HTTPObjectConfig */ - - /* add objects */ - conf->nobj = ucx_dlist_size(cfg->objects); - conf->objects = calloc(1, sizeof(httpd_object*)); - - UcxDlist *objlist = cfg->objects; - int i = 0; - while(objlist != NULL) { - ConfigObject *cob = objlist->data; - - /* get name and ppath */ - char *name = NULL; - char *ppath = NULL; - if(cob->name.length > 0) { - name = sstrdub(cob->name).ptr; - } - if(cob->ppath.length > 0) { - ppath = sstrdub(cob->ppath).ptr; - } - - /* create and add object */ - httpd_object *obj = object_new(name); - obj->path = NULL; - - conf->objects[i] = obj; - - /* add directives */ - for(int i=0;i<6;i++) { - UcxDlist *dirs = cob->directives[i]; - while(dirs != NULL) { - ConfigDirective *cfgdir = dirs->data; - - directive *d = malloc(sizeof(directive)); - d->cond = NULL; - d->param = pblock_create_pool(conf->pool, 8); - - /* add params */ - UcxList *param = cfgdir->param; - while(param != NULL) { - ConfigParam *p = param->data; - pblock_nvlinsert( - p->name.ptr, - p->name.length, - p->value.ptr, - p->value.length, - d->param); - param = param->next; - } - - /* get function */ - char *func_name = pblock_findval("fn", d->param); - d->func = get_function(func_name); - - dirs = dirs->next; - - /* add function to dtable */ - object_add_directive(obj, d, cfgdir->type_num); - } - } - - /* next */ - i++; - objlist = objlist->next; - } - - free_object_config(cfg); - - return conf; -} diff -r d2a97bbeb57d -r 73aacbf6e492 src/server/daemon/conf.h --- a/src/server/daemon/conf.h Sun Jan 15 20:30:45 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2011 Olaf Wintermann. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef CONF_H -#define CONF_H - -#include "../util/object.h" - -#include "../ucx/string.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - HTTPObjectConfig *conf; - httpd_object *obj; -} ObjectConfParser; - -void load_init_conf(char *file); - -void load_server_conf(char *file); - -VirtualServer* conf_get_default_vs(); - - -HTTPObjectConfig* load_obj_conf(char *file); - -void obj_conf_parse_line(ObjectConfParser *parser, sstr_t line); - - -/* utils */ -sstr_t string_trim(sstr_t string); - -httpd_object* parse_new_object_tag(sstr_t line); - -directive* parse_directive(pool_handle_t *pool, sstr_t line, sstr_t *type); - -int get_directive_type_from_string(sstr_t dt); - - -#ifdef __cplusplus -} -#endif - -#endif /* CONF_H */ - diff -r d2a97bbeb57d -r 73aacbf6e492 src/server/daemon/config.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/server/daemon/config.c Mon Jan 16 14:06:52 2012 +0100 @@ -0,0 +1,274 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "../public/nsapi.h" + +#include +#include + +#include +#include +#include +#include +#include + +#include "../ucx/string.h" + +#include "httplistener.h" +#include "config.h" +#include "func.h" + +#include "vserver.h" +#include "../util/pblock.h" + +VirtualServer *default_vs; + +pool_handle_t *cfg_pool; + +// TODO: Funktion für ConfigDirective -> directive +// TODO: Funktion für UcxList parameter list -> pblock +// TODO: ConfigurationManager +// TODO: server.conf + +UcxMap *server_conf_handlers; // type: ServerConfigHandler* + +void load_init_conf(char *file) { + printf("load_init_conf\n"); + + InitConfig *cfg = load_init_config("conf/init.conf"); + if(cfg == NULL) { + return; + } + + cfg_pool = pool_create(); // one pool for one Configuration + UcxDlist *dirs = cfg->directives; + while(dirs != NULL) { + ConfigDirective *dir = dirs->data; + + /* create NSAPI directive */ + directive *d = malloc(sizeof(directive)); + d->param = pblock_create_pool(cfg_pool, 8); + UcxList *param = dir->param; + while(param != NULL) { + ConfigParam *p = param->data; + pblock_nvlinsert( + p->name.ptr, + p->name.length, + p->value.ptr, + p->value.length, + d->param); + param = param->next; + } + + /* get function */ + char *func_name = pblock_findval("fn", d->param); + d->func = get_function(func_name); + if(d->func == NULL) { + free(d); + continue; + } + + /* execute init directive */ + d->func->func(d->param, NULL, NULL); + + dirs = dirs->next; + } + + free_init_config(cfg); +} + +void load_server_conf(char *file) { + printf("load_server_conf\n"); + + init_default_server_conf_handlers(); + + ServerConfig *serverconf = load_server_config("conf/server.conf"); + if(serverconf == NULL) { + fprintf(stderr, "Cannot load server.conf\n"); + } + ServerConfiguration *serverconfig = malloc(sizeof(ServerConfiguration)); + // TODO: init serverconfig stuff + + /* convert ServerConfig to ServerConfiguration */ + for(int i=0;iobjects->size;i++) { + UcxMapElement *elm = &serverconf->objects->map[i]; + while(elm != NULL) { + UcxList *list = elm->data; + while(list != NULL) { + ServerConfigObject *scfgobj = list->data; + + /* get handler */ + ServerConfigHandler *handler = ucx_map_sstr_get( + server_conf_handlers, + scfgobj->type); + if(handler != NULL) { + /* process the directives */ + UcxDlist *dirs = scfgobj->directives; + while(dirs != NULL) { + handler->process_directive( + handler, + serverconfig, + dirs->data); + + dirs = dirs->next; + } + } + + list = list->next; + } + + elm = elm->next; + } + } + + + ListenerConfig *conf = malloc(sizeof(ListenerConfig)); + conf->port = 9090; + conf->nacceptors = 1; + conf->name = "default"; + + http_listener_new(conf); + + // virtual server + default_vs = vs_new(); + // load obj.conf + default_vs->objects = load_obj_conf("conf/obj.conf"); + default_vs->default_obj_name = "default"; + +} + +void init_default_server_conf_handlers() { + /* create handler map */ + server_conf_handlers = ucx_map_new(8); + + /* create and add default handlers */ + + ServerConfigHandler *runtime = malloc(sizeof(ServerConfigHandler)); + runtime->init = NULL; + runtime->process_directive = handle_runtime_directive; + + ucx_map_cstr_put(server_conf_handlers, "Runtime", runtime); +} + +int handle_runtime_directive( + ServerConfigHandler *h, + ServerConfiguration *conf, + ConfigDirective *dir) +{ + + + return 0; +} + +VirtualServer* conf_get_default_vs() { + return default_vs; +} + +HTTPObjectConfig* load_obj_conf(char *file) { + printf("load_obj_conf\n"); + + // new conf function test + ObjectConfig *cfg = load_object_config(file); + if(cfg == NULL) { + return NULL; + } + + /* create object config */ + HTTPObjectConfig *conf = calloc(sizeof(HTTPObjectConfig), 1); + conf->pool = cfg_pool; + + /* convert ObjectConfig to HTTPObjectConfig */ + + /* add objects */ + conf->nobj = ucx_dlist_size(cfg->objects); + conf->objects = calloc(1, sizeof(httpd_object*)); + + UcxDlist *objlist = cfg->objects; + int i = 0; + while(objlist != NULL) { + ConfigObject *cob = objlist->data; + + /* get name and ppath */ + char *name = NULL; + char *ppath = NULL; + if(cob->name.length > 0) { + name = sstrdub(cob->name).ptr; + } + if(cob->ppath.length > 0) { + ppath = sstrdub(cob->ppath).ptr; + } + + /* create and add object */ + httpd_object *obj = object_new(name); + obj->path = NULL; + + conf->objects[i] = obj; + + /* add directives */ + for(int i=0;i<6;i++) { + UcxDlist *dirs = cob->directives[i]; + while(dirs != NULL) { + ConfigDirective *cfgdir = dirs->data; + + directive *d = malloc(sizeof(directive)); + d->cond = NULL; + d->param = pblock_create_pool(conf->pool, 8); + + /* add params */ + UcxList *param = cfgdir->param; + while(param != NULL) { + ConfigParam *p = param->data; + pblock_nvlinsert( + p->name.ptr, + p->name.length, + p->value.ptr, + p->value.length, + d->param); + param = param->next; + } + + /* get function */ + char *func_name = pblock_findval("fn", d->param); + d->func = get_function(func_name); + + dirs = dirs->next; + + /* add function to dtable */ + object_add_directive(obj, d, cfgdir->type_num); + } + } + + /* next */ + i++; + objlist = objlist->next; + } + + free_object_config(cfg); + + return conf; +} diff -r d2a97bbeb57d -r 73aacbf6e492 src/server/daemon/config.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/server/daemon/config.h Mon Jan 16 14:06:52 2012 +0100 @@ -0,0 +1,107 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef CONF_H +#define CONF_H + +#include "../util/object.h" + +#include "../config/objconf.h" +#include "../config/initconf.h" +#include "../config/serverconf.h" + +#include "../ucx/list.h" +#include "../ucx/dlist.h" +#include "../ucx/map.h" +#include "../ucx/mempool.h" +#include "../ucx/string.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct _server_configuration { + pool_handle_t *pool; + UcxMap *host_vs; // map of all vservers. key is the host name + UcxList *listeners; // list of all listeners + UcxList *logfiles; + UcxMap *authdbs; + sstr_t tmp; + sstr_t user; +} ServerConfiguration; + +/* + * Handles an object in the server.conf + * An object looks like ... directives ... + * The parser executes the handlers process_directive function for each + * directive in the object + */ +typedef struct _server_conf_handler ServerConfigHandler; + +typedef void(*cfg_handler_init_f)(ServerConfigHandler*, ServerConfiguration*); +typedef int(*cfg_process_directive_f)( + ServerConfigHandler*, + ServerConfiguration*, + ConfigDirective*); + +struct _server_conf_handler { + cfg_handler_init_f init; + cfg_process_directive_f process_directive; +}; + +void load_init_conf(char *file); + +void load_server_conf(char *file); + +void init_default_server_conf_handlers(); + +int handle_runtime_directive( + ServerConfigHandler *h, + ServerConfiguration *conf, + ConfigDirective *dir); +int handle_listener_directive( + ServerConfigHandler *h, + ServerConfiguration *conf, + ConfigDirective *dir); +int handle_vserver_directive( + ServerConfigHandler *h, + ServerConfiguration *conf, + ConfigDirective *dir); + +VirtualServer* conf_get_default_vs(); + +HTTPObjectConfig* load_obj_conf(char *file); + + + +#ifdef __cplusplus +} +#endif + +#endif /* CONF_H */ + diff -r d2a97bbeb57d -r 73aacbf6e492 src/server/daemon/configmanager.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/server/daemon/configmanager.c Mon Jan 16 14:06:52 2012 +0100 @@ -0,0 +1,40 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +#include "../public/nsapi.h" + +#include "configmanager.h" + + + +void init_configuration_manager() { + +} diff -r d2a97bbeb57d -r 73aacbf6e492 src/server/daemon/configmanager.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/server/daemon/configmanager.h Mon Jan 16 14:06:52 2012 +0100 @@ -0,0 +1,55 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef CONFIGMANAGER_H +#define CONFIGMANAGER_H + +#include "config.h" + +#include "vserver.h" + +#include "../ucx/list.h" +#include "../ucx/dlist.h" +#include "../ucx/map.h" +#include "../ucx/mempool.h" +#include "../ucx/string.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +void init_configuration_manager(); + + +#ifdef __cplusplus +} +#endif + +#endif /* CONFIGMANAGER_H */ + diff -r d2a97bbeb57d -r 73aacbf6e492 src/server/daemon/httprequest.c --- a/src/server/daemon/httprequest.c Sun Jan 15 20:30:45 2012 +0100 +++ b/src/server/daemon/httprequest.c Mon Jan 16 14:06:52 2012 +0100 @@ -36,7 +36,7 @@ #include "../util/io.h" #include "../util/util.h" #include "httprequest.h" -#include "conf.h" +#include "config.h" #include "vserver.h" HTTPRequest *http_request_new() { diff -r d2a97bbeb57d -r 73aacbf6e492 src/server/daemon/objs.mk --- a/src/server/daemon/objs.mk Sun Jan 15 20:30:45 2012 +0100 +++ b/src/server/daemon/objs.mk Mon Jan 16 14:06:52 2012 +0100 @@ -30,7 +30,7 @@ DMN_OBJPRE = $(OBJ_DIR)$(DMN_SRC_DIR) -DAEMONOBJ = conf.o +DAEMONOBJ = config.o DAEMONOBJ += func.o DAEMONOBJ += httplistener.o DAEMONOBJ += httpparser.o @@ -43,6 +43,7 @@ DAEMONOBJ += vserver.o DAEMONOBJ += webserver.o DAEMONOBJ += ws-fn.o +DAEMONOBJ += configmanager.o DAEMONOBJS = $(DAEMONOBJ:%=$(DMN_OBJPRE)%) DAEMONSOURCE = $(DAEMONOBJ:%.o=daemon/%.c) diff -r d2a97bbeb57d -r 73aacbf6e492 src/server/daemon/webserver.c --- a/src/server/daemon/webserver.c Sun Jan 15 20:30:45 2012 +0100 +++ b/src/server/daemon/webserver.c Mon Jan 16 14:06:52 2012 +0100 @@ -34,7 +34,7 @@ #include "../util/systhr.h" #include "func.h" -#include "conf.h" +#include "config.h" #include "httplistener.h" #include "webserver.h" diff -r d2a97bbeb57d -r 73aacbf6e492 templates/conf/init.conf --- a/templates/conf/init.conf Sun Jan 15 20:30:45 2012 +0100 +++ b/templates/conf/init.conf Mon Jan 16 14:06:52 2012 +0100 @@ -0,0 +1,6 @@ +# +# init.conf +# + +Init fn="init-test" + diff -r d2a97bbeb57d -r 73aacbf6e492 templates/conf/server.conf --- a/templates/conf/server.conf Sun Jan 15 20:30:45 2012 +0100 +++ b/templates/conf/server.conf Mon Jan 16 14:06:52 2012 +0100 @@ -1,18 +1,43 @@ -Listener { - name = default - ip = x4 - port = 80 - ssl = false -} +# +# server.conf +# + + + Temp /tmp/webserver-rw6pgl8b/ + User webservd + + + + File logs/errors + Level INFO + + + + Name keyfile + Type keyfile + -VirtualServer { - name = x4 -} + + Name http-listener-1 + Port 9090 + DefaultVS x4 + + + + Name http-listener-2 + Port 9091 + DefaultVS x4 + -name1 = value1 -name2 = value2 + + Name x4 + Host x4 + Listener http-listener-1 + Listener http-listener-2 + ObjectFile obj.conf + ACLFile acl.conf + DAVFile dav.conf + DocRoot docs/ + -AuthDB { - name = ldap -}