1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 #ifndef CFG_CONF_H
30 #define CFG_CONF_H
31
32 #include <stdio.h>
33 #include <stdlib.h>
34
35 #include <ucx/list.h>
36 #include <ucx/map.h>
37 #include <ucx/mempool.h>
38 #include <ucx/string.h>
39
40 #include "../util/object.h"
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46
47 #define OBJ_NEW(p, type) (type*)(p)->malloc((p)->pool,
sizeof(type))
48 #define OBJ_NEW_N(p, type) (type*)(p)->calloc((p)->pool,
1,
sizeof(type))
49
50
51 #define LINE_OTHER 0
52 #define LINE_DIRECTIVE 1
53 #define LINE_BEGIN_TAG 2
54 #define LINE_END_TAG 3
55 #define LINE_MULTI 4
56 #define LINE_NOCONTENT 5
57 #define LINE_ERROR 6
58
59
60 #define TAG_OBJECT 0
61 #define TAG_IF 1
62 #define TAG_ELSEIF 2
63 #define TAG_ELSE 3
64 #define TAG_CLIENT 4
65
66
67 #define INIT_DIRECTIVE 16
68
69 typedef struct _cfg_line {
70 sstr_t line;
71 void *object;
72 int type;
73 } ConfigLine;
74
75 typedef int (*cfg_parse_f)(
void *, ConfigLine *, ConfigLine *,
sstr_t);
76
77 typedef struct _cfg_param {
78 sstr_t name;
79 sstr_t value;
80 } ConfigParam;
81
82 typedef struct _cfg_parser {
83 UcxAllocator *mp;
84 UcxList *lines;
85 cfg_parse_f parse;
86 } ConfigParser;
87
88
89 typedef struct _conf_tag ConfigTag;
90 struct _conf_tag {
91 ConfigLine *begin;
92 ConfigLine *end;
93
94 sstr_t name;
95 UcxList *param;
96 sstr_t param_str;
97 ConfigTag *parent;
98 ConfigTag *iftag;
99 int type_num;
100 };
101
102 typedef struct _conf_directive {
103 ConfigLine *begin;
104 ConfigLine *end;
105
106 sstr_t directive_type;
107 sstr_t value;
108
109 ConfigTag *condition;
110 int type_num;
111 } ConfigDirective;
112
113
114 int cfg_parse_basic_file(ConfigParser *parser,
FILE *in);
115
116 sstr_t cfg_readln(
FILE *file);
117
118 sstr_t cfg_trim_comment(
sstr_t line);
119
120 sstr_t cfg_param(
sstr_t params,
sstr_t *name,
sstr_t *value);
121
122 sstr_t cfg_param_get(UcxList *list,
sstr_t name);
123
124 ConfigDirective* cfg_parse_directive(
sstr_t line, UcxAllocator *mp);
125
126 UcxList* cfg_param_list(
sstr_t param_str, UcxAllocator *mp);
127
128 int cfg_get_directive_type_num(
sstr_t type);
129
130 int cfg_get_basic_type(
sstr_t line);
131
132 int cfg_get_line_type(
sstr_t line);
133
134 int cfg_get_tag_type(
sstr_t tag);
135
136 sstr_t cfg_get_end_tag_name(
sstr_t line);
137
138 ConfigTag* cfg_parse_begin_tag(
sstr_t line, UcxAllocator *mp);
139
140 ConfigDirective* cfg_directivelist_get(UcxList *dirs,
sstr_t name);
141
142 sstr_t cfg_directivelist_get_str(UcxList *dirs,
sstr_t name);
143
144 sstr_t cfg_directive_pstr1(ConfigDirective *dir);
145
146 void cfg_map_destr(UcxMempool *mp, UcxMap *map);
147
148 #ifdef __cplusplus
149 }
150 #endif
151
152 #endif
153
154