src/server/config/conf.c

changeset 91
fac51f87def0
parent 83
28433f06d5ee
child 95
74a81d9e19d0
--- a/src/server/config/conf.c	Wed Jul 31 13:02:06 2013 +0200
+++ b/src/server/config/conf.c	Sun Sep 08 23:27:07 2013 +0200
@@ -32,7 +32,8 @@
 
 int cfg_parse_basic_file(ConfigParser *parser, FILE *in) {
     parser->lines = NULL;
-    parser->mp = ucx_mempool_new(512);
+    UcxMempool *mp = ucx_mempool_new(512);
+    parser->mp = ucx_mempool_allocator(mp);
 
     // one logical line over many lines
     sstr_t mline;
@@ -48,14 +49,13 @@
         
         // put the line to the list
         ConfigLine *line = OBJ_NEW(parser->mp, ConfigLine);
-        line->line = sstrdup_mp(parser->mp, l); // TODO: check for 0-len str
+        line->line = sstrdup_a(parser->mp, l); // TODO: check for 0-len str
         line->object = NULL;
         line->type = LINE_OTHER;
         if(parser->lines) {
-            parser->lines = ucx_dlist_append(parser->lines, line);
+            parser->lines = ucx_list_append_a(parser->mp, parser->lines, line);
         } else {
-            parser->lines = ucx_dlist_append(parser->lines, line);
-            cfg_dlist_destr(parser->mp, parser->lines);
+            parser->lines = ucx_list_append_a(parser->mp, parser->lines, line);
         }
 
         // check if the line contains something
@@ -67,7 +67,7 @@
             if(mline.ptr != NULL) {
                 // concate lines
                 char *ptr = ucx_mempool_malloc(
-                        parser->mp,
+                        mp,
                         mline.length + l.length + 1);
                 
                 memcpy(ptr, mline.ptr, mline.length);
@@ -83,7 +83,7 @@
             }
             if(l.ptr[l.length - 1] == '\\') {
                 if(mline.ptr == NULL) {
-                    mline = sstrdup_mp(parser->mp, l);
+                    mline = sstrdup_a(parser->mp, l);
                     start_line = line;
                 }
             } else {
@@ -277,7 +277,7 @@
  * parses a line containing a directive and returns a ConfigDirective object
  * or NULL if an error occurs
  */
-ConfigDirective* cfg_parse_directive(sstr_t line, UcxMempool *mp) {
+ConfigDirective* cfg_parse_directive(sstr_t line, UcxAllocator *mp) {
     if(line.length < 6) {
         printf("line too short\n");
         return NULL; // line too short
@@ -296,7 +296,7 @@
 
     // create directive object
     ConfigDirective *directive = OBJ_NEW(mp, ConfigDirective);
-    directive->directive_type = sstrdup_mp(mp, name);
+    directive->directive_type = sstrdup_a(mp, name);
     directive->type_num = cfg_get_directive_type_num(name);
     directive->condition = NULL; // set later by main parsing function
     //directive->param = NULL;
@@ -305,7 +305,7 @@
     param_str.ptr = name.ptr + i;
     param_str.length = line.length - i;
     param_str = sstrtrim(param_str);
-    directive->value = sstrdup_mp(mp, param_str);
+    directive->value = sstrdup_a(mp, param_str);
     
     /*
     sstr_t pname;
@@ -337,7 +337,7 @@
     return directive;
 }
 
-UcxList* cfg_param_list(sstr_t param_str, UcxMempool *mp) {
+UcxList* cfg_param_list(sstr_t param_str, UcxAllocator *mp) {
     sstr_t pname;
     sstr_t pvalue;
     UcxList *plist = NULL;
@@ -349,19 +349,18 @@
 
         // create param object
         ConfigParam *param = OBJ_NEW(mp, ConfigParam);
-        param->name = sstrdup_mp(mp, pname);
+        param->name = sstrdup_a(mp, pname);
 
         if(pvalue.length > 0) {
-            param->value = sstrdup_mp(mp, pvalue);
+            param->value = sstrdup_a(mp, pvalue);
         } else {
             param->value.ptr = NULL;
             param->value.length = 0;
         }
 
         // add param to list
-        plist = ucx_list_append(plist, param);
+        plist = ucx_list_append_a(mp, plist, param);
     }
-    cfg_list_destr(mp, plist);
     return plist;
 }
 
@@ -477,7 +476,7 @@
     return sstrtrim(name);
 }
 
-ConfigTag* cfg_parse_begin_tag(sstr_t line, UcxMempool *mp) {
+ConfigTag* cfg_parse_begin_tag(sstr_t line, UcxAllocator *mp) {
     if(line.length < 4) {
         return NULL; // this line can't contain a valid tag
     }
@@ -501,7 +500,7 @@
 
     // create tag object
     ConfigTag *tag = OBJ_NEW(mp, ConfigTag);
-    tag->name = sstrdup_mp(mp, name);
+    tag->name = sstrdup_a(mp, name);
     tag->param = NULL;
 
     // parse parameters
@@ -512,7 +511,7 @@
     if(param_str.length == 0) {
         return tag; // no parameters
     }
-    tag->param_str = sstrdup_mp(mp, param_str);
+    tag->param_str = sstrdup_a(mp, param_str);
 
     sstr_t pname;
     sstr_t pvalue;
@@ -524,16 +523,16 @@
 
         // create param object
         ConfigParam *param = OBJ_NEW(mp, ConfigParam);
-        param->name = sstrdup_mp(mp, pname);
+        param->name = sstrdup_a(mp, pname);
         if(pvalue.length > 0) {
-            param->value = sstrdup_mp(mp, pvalue);
+            param->value = sstrdup_a(mp, pvalue);
         } else {
             param->value.ptr = NULL;
             param->value.length = 0;
         }
 
         // add param to list
-        tag->param = cfg_list_append(mp, tag->param, param);
+        tag->param = ucx_list_append_a(mp, tag->param, param);
     }
 
     return tag;
@@ -546,7 +545,7 @@
  * gets a ConfigDirective with a specific name from a List of directives
  * returns a directive or NULL, if the directive cannot be found
  */
-ConfigDirective* cfg_directivelist_get(UcxDlist *dirs, sstr_t name) {
+ConfigDirective* cfg_directivelist_get(UcxList *dirs, sstr_t name) {
     while(dirs != NULL) {
         ConfigDirective *d = dirs->data;
         if(d != NULL) {
@@ -559,7 +558,7 @@
     return NULL;
 }
 
-sstr_t cfg_directivelist_get_str(UcxDlist *dirs, sstr_t name) {
+sstr_t cfg_directivelist_get_str(UcxList *dirs, sstr_t name) {
     ConfigDirective *d = cfg_directivelist_get(dirs, name);
     if(d == NULL) {
         sstr_t n;
@@ -593,24 +592,12 @@
 static void cfg_list_free(void *list) {
     ucx_list_free(list);
 }
-static void cfg_dlist_free(void *dlist) {
-    ucx_dlist_free(dlist);
-}
+
 static void cfg_map_free(void *map) {
     ucx_map_free(map);
 }
 
-void cfg_list_destr(UcxMempool *mp, UcxList *list) {
-    if(list) {
-        ucx_mempool_reg_destr(mp, list, cfg_list_free);
-    }
-}
 
-void cfg_dlist_destr(UcxMempool *mp, UcxDlist *dlist) {
-    if(dlist) {
-        ucx_mempool_reg_destr(mp, dlist, cfg_dlist_free);
-    }
-}
 
 void cfg_map_destr(UcxMempool *mp, UcxMap *map) {
     if(map) {
@@ -618,23 +605,5 @@
     }
 }
 
-UcxList* cfg_list_append(UcxMempool *mp, UcxList *list, void *data) {
-    if(list) {
-        return ucx_list_append(list, data);
-    } else {
-        UcxList *r = ucx_list_append(list, data);
-        cfg_list_destr(mp, r);
-        return r;
-    }
-}
 
-UcxDlist* cfg_dlist_append(UcxMempool *mp, UcxDlist *list, void *data) {
-    if(list) {
-        return ucx_dlist_append(list, data);
-    } else {
-        UcxDlist *r = ucx_dlist_append(list, data);
-        cfg_dlist_destr(mp, r);
-        return r;
-    }
-}
 

mercurial