src/server/conf.c

changeset 13
1fdbf4170ef4
parent 12
34aa8001ea53
--- 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(;i<line.length;i++) {
         if(line.ptr[i] < 33) {
@@ -335,7 +374,7 @@
             directive_type.length = i;
             if(directive_type.length <= 0) {
                 fprintf(stderr, "parse error: cannot parse directive\n");
-                return;
+                return NULL;
             }
         } else if(b == 1) {
             break;
@@ -357,7 +396,7 @@
         }
         if(!b) {
             printf("2\n");
-            return;
+            return NULL;
         }
         name.length = line.ptr + i - name.ptr - 1;
 
@@ -374,7 +413,7 @@
         }
         if(!b) {
             printf("3\n");
-            return;
+            return NULL;
         }
         value.length = line.ptr + i - value.ptr;
 
@@ -394,22 +433,25 @@
     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(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;
 }

mercurial