diff -r a9bbd82d2dce -r d2a97bbeb57d src/server/daemon/conf.c --- a/src/server/daemon/conf.c Sun Jan 15 17:00:16 2012 +0100 +++ b/src/server/daemon/conf.c Sun Jan 15 20:30:45 2012 +0100 @@ -47,45 +47,60 @@ #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"); - pool_handle_t *pool = pool_create(); - - FILE *in = fopen("conf/init.conf", "r"); - if(in == NULL) { - fprintf(stderr, "Cannot open conf/init.conf\n"); + InitConfig *cfg = load_init_config("conf/init.conf"); + if(cfg == NULL) { return; } - char buf[512]; - buf[0] = 0; - int len = 512; + cfg_pool = pool_create(); // one pool for one Configuration + UcxDlist *dirs = cfg->directives; + while(dirs != NULL) { + ConfigDirective *dir = dirs->data; - while(!feof(in)) { - fgets(buf, len, in); + /* 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; + } - if(*buf == 0) { + /* get function */ + char *func_name = pblock_findval("fn", d->param); + d->func = get_function(func_name); + if(d->func == NULL) { + free(d); continue; } - char *ptr; - if((ptr = strrchr(buf, '\n'))) { - ptr[0] = 0; - } - - sstr_t line = string_trim(sstr(buf)); - if(line.length > 0) { - sstr_t type; - directive *d = parse_directive(pool, line, &type); - if(sstrcmp(type, sstr("Init"))) { - d->func->func(d->param, NULL, NULL); - } - } + /* execute init directive */ + d->func->func(d->param, NULL, NULL); + + dirs = dirs->next; } + + free_init_config(cfg); } void load_server_conf(char *file) { @@ -103,59 +118,7 @@ // load obj.conf default_vs->objects = load_obj_conf("conf/obj.conf"); default_vs->default_obj_name = "default"; - - // begin objset test - /* - httpd_objset *objset = default_vs->objset; - for(int i=0;ipos;i++) { - httpd_object *obj = objset->obj[i]; - printf("\n", obj->name); - for(int j=0;jnd;j++) { - dtable *dt; - switch(j) { - case NSAPIAuthTrans: { - printf(" Get AuthTrans Directives\n"); - dt = object_get_dtable(obj, NSAPIAuthTrans); - break; - } - case NSAPINameTrans: { - printf(" Get NameTrans Directives\n"); - dt = object_get_dtable(obj, NSAPINameTrans); - break; - } - case NSAPIPathCheck: { - printf(" Get PathCheck Directives\n"); - dt = object_get_dtable(obj, NSAPIPathCheck); - break; - } - case NSAPIService: { - printf(" Get Service Directives\n"); - dt = object_get_dtable(obj, NSAPIService); - break; - } - default: { - printf("j: %d\n", j); - dt = object_get_dtable(obj, j); - break; - } - } - if(dt != NULL) { - printf(" dtable[%d].length = %d\n", dt, dt->ndir); - } else { - continue; - } - for(int k=0;kndir;k++) { - directive *d = dt->directive[k]; - if(d == NULL) { - printf("d is null\n"); - } else { - printf(" Directive[%d].name = %s\n", d, d->func->name); - } - } - } - } - */ - // end objset test + } VirtualServer* conf_get_default_vs() { @@ -173,7 +136,7 @@ /* create object config */ HTTPObjectConfig *conf = calloc(sizeof(HTTPObjectConfig), 1); - conf->pool = pool_create(); + conf->pool = cfg_pool; /* convert ObjectConfig to HTTPObjectConfig */ @@ -241,263 +204,7 @@ objlist = objlist->next; } - - - - + free_object_config(cfg); return conf; } - -void obj_conf_parse_line(ObjectConfParser *parser, sstr_t line) { - //printf("{%s}[%d]\n", line.ptr, line.length); - if(line.ptr[0] == '#') { - return; - } - - if(line.length < 3) { - // to short for everything - fprintf(stderr, "obj.conf: line to short \"%s\"\n", line.ptr); - return; - } - - // TODO: ersetzen - if(line.ptr[0] == '<') { - if(line.ptr[1] == '/') { - // end tag - if(line.ptr[2] == 'O' && parser->obj != NULL) { - // end of Object - httpobjconf_add_object(parser->conf, parser->obj); - parser->obj = NULL; - return; - } - } else { - // new tag - httpd_object *obj = parse_new_object_tag(line); - parser->obj = obj; - } - } else { - // directive - sstr_t dtype; - directive *d = parse_directive(parser->conf->pool, line, &dtype); - int dt = get_directive_type_from_string(dtype); - object_add_directive(parser->obj, d, dt); - } -} - - -/* utils */ - -sstr_t string_trim(sstr_t string) { - sstr_t newstr = string; - int nsoff = 0; - int l = 1; - for(int i=0;i 32) { - l = 0; - nsoff = i; - newstr.ptr = &string.ptr[i]; - newstr.length = string.length - nsoff; - } - } else { - /* trailing whitespace */ - if(c > 32) { - newstr.length = (i - nsoff) + 1; - } - } - } - return newstr; -} - -httpd_object* parse_new_object_tag(sstr_t line) { - int i = 0; - int b = 0; - sstr_t name; - sstr_t value; - - char *obj_name = NULL; - char *obj_ppath = NULL; - - for(;i') { - break; - } - - /* get name */ - name.ptr = line.ptr + i; - for(;i') { - b = 1; - break; - } - } - if(!b) { - printf("3\n"); - return NULL; - } - value.length = line.ptr + i - value.ptr; - - if(sstrcmp(name, sstrn("name", 4)) == 0) { - obj_name = sstrdub(value).ptr; - } else if (sstrcmp(name, sstrn("ppath", 5)) == 0) { - obj_ppath = sstrdub(value).ptr; - } - - /* - printf("name: [%d]{", name.length); - fwrite(name.ptr, 1, name.length, stdout); - printf("}\n"); - printf("value: [%d]{", value.length); - fwrite(value.ptr, 1, value.length, stdout); - printf("}\n"); - */ - - char c = line.ptr[i]; - if(c == '>') { - break; - } else { - i++; - } - } - - if(obj_name != NULL || obj_ppath != NULL) { - httpd_object *o = object_new(obj_name); - o->path = obj_ppath; - return o; - } - - return NULL; -} - -directive* parse_directive(pool_handle_t *pool, sstr_t line, sstr_t *type) { - int i = 0; - int b = 0; - - sstr_t directive_type = line; - - directive *directive = malloc(sizeof(directive)); - directive->cond = NULL; - directive->param = pblock_create_pool(pool, 8); - - for(;iparam); - } - - /* get function */ - char *func_name = pblock_findval("fn", directive->param); - directive->func = get_function(func_name); - - *type = directive_type; - return directive; -} - -int get_directive_type_from_string(sstr_t type) { - /* get nsapi function type */ - int dt = -1; - if(sstrcmp(type, sstr("AuthTrans")) == 0) { - dt = 0; - } else if(sstrcmp(type, sstr("NameTrans")) == 0) { - dt = 1; - } else if(sstrcmp(type, sstr("PathCheck")) == 0) { - dt = 2; - } else if(sstrcmp(type, sstr("ObjectType")) == 0) { - dt = 3; - } else if(sstrcmp(type, sstr("Service")) == 0) { - dt = 4; - } else if(sstrcmp(type, sstr("AddLog")) == 0) { - dt = 5; - } - return dt; -}