diff -r 34aa8001ea53 -r 1fdbf4170ef4 src/server/conf.c --- a/src/server/conf.c Fri Dec 30 17:50:05 2011 +0100 +++ b/src/server/conf.c Sun Jan 08 15:46:47 2012 +0100 @@ -50,6 +50,42 @@ void load_init_conf(char *file) { printf("load_init_conf\n"); + if(1) { + return; + } + + pool_handle_t *pool = pool_create(); + + FILE *in = fopen("conf/obj.conf", "r"); + if(in == NULL) { + fprintf(stderr, "Cannot open conf/obj.conf\n"); + return; + } + + char buf[512]; + int len = 512; + + while(!feof(in)) { + fgets(buf, len, in); + + if(*buf == 0) { + 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); + } + } + } } void load_server_conf(char *file) { @@ -196,7 +232,10 @@ } } else { // directive - parse_directive(parser, line); + 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); } } @@ -319,7 +358,7 @@ return NULL; } -void parse_directive(ObjectConfParser *parser, sstr_t line) { +directive* parse_directive(pool_handle_t *pool, sstr_t line, sstr_t *type) { int i = 0; int b = 0; @@ -327,7 +366,7 @@ directive *directive = malloc(sizeof(directive)); directive->cond = NULL; - directive->param = pblock_create_pool(parser->conf->pool, 8); + directive->param = pblock_create_pool(pool, 8); for(;iparam); 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(directive_type, sstr("AuthTrans")) == 0) { + if(sstrcmp(type, sstr("AuthTrans")) == 0) { dt = 0; - } else if(sstrcmp(directive_type, sstr("NameTrans")) == 0) { + } else if(sstrcmp(type, sstr("NameTrans")) == 0) { dt = 1; - } else if(sstrcmp(directive_type, sstr("PathCheck")) == 0) { + } else if(sstrcmp(type, sstr("PathCheck")) == 0) { dt = 2; - } else if(sstrcmp(directive_type, sstr("ObjectType")) == 0) { + } else if(sstrcmp(type, sstr("ObjectType")) == 0) { dt = 3; - } else if(sstrcmp(directive_type, sstr("Service")) == 0) { + } else if(sstrcmp(type, sstr("Service")) == 0) { dt = 4; - } else if(sstrcmp(directive_type, sstr("AddLog")) == 0) { - //dt = 5; - return; + } else if(sstrcmp(type, sstr("AddLog")) == 0) { + dt = 5; } - - object_add_directive(parser->obj, directive, dt); + return dt; }