--- a/src/server/daemon/conf.c Sat Jan 14 14:33:38 2012 +0100 +++ b/src/server/daemon/conf.c Sun Jan 15 17:00:16 2012 +0100 @@ -46,6 +46,8 @@ #include "vserver.h" #include "../util/pblock.h" +#include "../config/objconf.h" + VirtualServer *default_vs; void load_init_conf(char *file) { @@ -163,40 +165,86 @@ HTTPObjectConfig* load_obj_conf(char *file) { printf("load_obj_conf\n"); - /* create object config */ - ObjectConfParser parser; - HTTPObjectConfig *conf = calloc(sizeof(HTTPObjectConfig), 1); - conf->pool = pool_create(); - parser.conf = conf; - - FILE *in = fopen("conf/obj.conf", "r"); - if(in == NULL) { - fprintf(stderr, "Cannot open conf/obj.conf\n"); + // new conf function test + ObjectConfig *cfg = load_object_config(file); + if(cfg == NULL) { return NULL; } - char buf[512]; - int len = 512; + /* create object config */ + HTTPObjectConfig *conf = calloc(sizeof(HTTPObjectConfig), 1); + conf->pool = pool_create(); + + /* convert ObjectConfig to HTTPObjectConfig */ - while(!feof(in)) { - fgets(buf, len, in); + /* 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; - if(*buf == 0) { - continue; + /* 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; } - char *ptr; - if((ptr = strrchr(buf, '\n'))) { - ptr[0] = 0; + /* 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); + } } - sstr_t line = string_trim(sstr(buf)); - if(line.length > 0) { - obj_conf_parse_line(&parser, line); - } + /* next */ + i++; + objlist = objlist->next; } + + + return conf; }