src/server/config/conf.h

changeset 415
d938228c382e
parent 95
74a81d9e19d0
child 505
d41fc7f37aed
--- a/src/server/config/conf.h	Wed Nov 02 19:19:01 2022 +0100
+++ b/src/server/config/conf.h	Sun Nov 06 15:53:32 2022 +0100
@@ -32,10 +32,13 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-#include <ucx/list.h>
-#include <ucx/map.h>
-#include <ucx/mempool.h>
-#include <ucx/string.h>
+#include <cx/linked_list.h>
+#include <cx/hash_map.h>
+#include <cx/mempool.h>
+#include <cx/basic_mempool.h>
+#include <cx/string.h>
+#include <cx/utils.h>
+#include <cx/compare.h>
 
 #include "../util/object.h"
 
@@ -44,8 +47,8 @@
 #endif
    
 // mempool malloc macro
-#define OBJ_NEW(p, type) (type*)(p)->malloc((p)->pool, sizeof(type))
-#define OBJ_NEW_N(p, type) (type*)(p)->calloc((p)->pool, 1, sizeof(type))
+#define OBJ_NEW(p, type) (type*)cxMalloc(p, sizeof(type))
+#define OBJ_NEW_N(p, type) (type*)cxCalloc(p, 1, sizeof(type))
 
 // line types
 #define LINE_OTHER      0
@@ -65,85 +68,111 @@
 
     
 #define INIT_DIRECTIVE  16    
+    
+#define CFG_LINE_ADD(list_begin, list_end, elm) \
+    cx_linked_list_add((void**)list_begin, (void**)list_end, offsetof(ConfigLineList, prev), offsetof(ConfigLineList, next), elm)
+    
+#define CFG_PARAM_ADD(list_begin, list_end, elm) \
+    cx_linked_list_add((void**)list_begin, (void**)list_end, -1, offsetof(ConfigParam, next), elm)
 
+#define CFG_DIRECTIVES_ADD(list, dir) \
+    cx_linked_list_add((void**)list, NULL, -1, offsetof(ConfigDirectiveList, next), dir)
+    
+#define CFG_NUM_PARAMS(param) cx_linked_list_size(param, offsetof(ConfigParam, next))
+    
 typedef struct _cfg_line {
-    sstr_t line;    // raw line string
+    cxmutstr line;    // raw line string
     void   *object; // pointer to data struct
     int    type;    // type, see line types
 } ConfigLine;
 
-typedef int (*cfg_parse_f)(void *, ConfigLine *, ConfigLine *, sstr_t);
+typedef int (*cfg_parse_f)(void *, ConfigLine *, ConfigLine *, cxmutstr);
 
-typedef struct _cfg_param {
-    sstr_t     name;
-    sstr_t     value;
-} ConfigParam;
+typedef struct _cfg_param ConfigParam;
+struct _cfg_param {
+    cxmutstr     name;
+    cxmutstr     value;
+    ConfigParam  *next;
+};
+
+typedef struct ConfigLineList ConfigLineList;
+struct ConfigLineList {
+    ConfigLine *line;
+    ConfigLineList *prev;
+    ConfigLineList *next;
+};
 
 typedef struct _cfg_parser {
-    UcxAllocator  *mp;
-    UcxList       *lines;
-    cfg_parse_f   parse;
+    CxAllocator    *mp;
+    ConfigLineList *lines_begin;
+    ConfigLineList *lines_end;
+    cfg_parse_f    parse;
 } ConfigParser;
 
 
 typedef struct _conf_tag ConfigTag;
 struct _conf_tag {
-    ConfigLine *begin;
-    ConfigLine *end;
+    ConfigLine      *begin;
+    ConfigLine      *end;
 
-    sstr_t     name;
-    UcxList    *param;
-    sstr_t     param_str;
-    ConfigTag  *parent;
-    ConfigTag  *iftag; // only used by <ElseIf> and <Else>
-    int        type_num;
+    cxmutstr        name;
+    ConfigParam     *param;
+    cxmutstr        param_str;
+    ConfigTag       *parent;
+    ConfigTag       *iftag; // only used by <ElseIf> and <Else>
+    int             type_num;
 };
 
 typedef struct _conf_directive {
     ConfigLine *begin;
     ConfigLine *end;
 
-    sstr_t     directive_type;
-    sstr_t     value;
+    cxmutstr     directive_type;
+    cxmutstr     value;
     //UcxList    *param;
     ConfigTag  *condition;
     int        type_num;
 } ConfigDirective;
 
+typedef struct ConfigDirectiveList ConfigDirectiveList;
+struct ConfigDirectiveList {
+    ConfigDirective *directive;
+    ConfigDirectiveList *next;
+};
 
 int cfg_parse_basic_file(ConfigParser *parser, FILE *in);
 
-sstr_t cfg_readln(FILE *file);
+cxmutstr cfg_readln(FILE *file);
 
-sstr_t cfg_trim_comment(sstr_t line);
+cxmutstr cfg_trim_comment(cxmutstr line);
 
-sstr_t cfg_param(sstr_t params, sstr_t *name, sstr_t *value);
+cxmutstr cfg_param(cxmutstr params, cxmutstr *name, cxmutstr *value);
 
-sstr_t cfg_param_get(UcxList *list, sstr_t name);
+cxmutstr cfg_param_get(ConfigParam *list, cxstring name);
 
-ConfigDirective* cfg_parse_directive(sstr_t line, UcxAllocator *mp);
+ConfigDirective* cfg_parse_directive(cxmutstr line, CxAllocator *mp);
 
-UcxList* cfg_param_list(sstr_t param_str, UcxAllocator *mp);
+ConfigParam* cfg_param_list(cxmutstr param_str, CxAllocator *mp);
 
-int cfg_get_directive_type_num(sstr_t type);
+int cfg_get_directive_type_num(cxstring type);
 
-int cfg_get_basic_type(sstr_t line);
+int cfg_get_basic_type(cxmutstr line);
 
-int cfg_get_line_type(sstr_t line);
+int cfg_get_line_type(cxmutstr line);
 
-int cfg_get_tag_type(sstr_t tag);
+int cfg_get_tag_type(cxstring tag);
 
-sstr_t cfg_get_end_tag_name(sstr_t line);
+cxmutstr cfg_get_end_tag_name(cxmutstr line);
 
-ConfigTag* cfg_parse_begin_tag(sstr_t line, UcxAllocator *mp);
+ConfigTag* cfg_parse_begin_tag(cxmutstr line, CxAllocator *mp);
 
-ConfigDirective* cfg_directivelist_get(UcxList *dirs, sstr_t name);
+//ConfigDirective* cfg_directivelist_get(UcxList *dirs, cxmutstr name);
 
-sstr_t cfg_directivelist_get_str(UcxList *dirs, sstr_t name);
+//cxmutstr cfg_directivelist_get_str(UcxList *dirs, cxmutstr name);
 
-sstr_t cfg_directive_pstr1(ConfigDirective *dir);
+cxmutstr cfg_directive_pstr1(ConfigDirective *dir);
 
-void cfg_map_destr(UcxMempool *mp, UcxMap *map);
+
 
 #ifdef	__cplusplus
 }

mercurial