68 if(conf->levels) { |
70 if(conf->levels) { |
69 //ucx_list_free(conf->levels); |
71 //ucx_list_free(conf->levels); |
70 } |
72 } |
71 |
73 |
72 // free mempool |
74 // free mempool |
73 ucx_mempool_destroy(conf->parser.mp->pool); |
75 //ucx_mempool_destroy(conf->parser.mp->pool); |
74 free(conf); |
76 free(conf); |
75 } |
77 } |
76 |
78 |
77 |
79 |
78 |
80 |
79 int objconf_parse(void *p, ConfigLine *begin, ConfigLine *end, sstr_t line) { |
81 int objconf_parse(void *p, ConfigLine *begin, ConfigLine *end, cxmutstr line) { |
80 ObjectConfig *conf = p; |
82 ObjectConfig *conf = p; |
81 |
83 |
82 begin->type = cfg_get_line_type(line); |
84 begin->type = cfg_get_line_type(line); |
83 switch(begin->type) { |
85 switch(begin->type) { |
84 case LINE_BEGIN_TAG: { |
86 case LINE_BEGIN_TAG: { |
87 log_ereport(LOG_FAILURE, "Parse error in %s", conf->file); |
89 log_ereport(LOG_FAILURE, "Parse error in %s", conf->file); |
88 exit(-1); // TODO: better error handling |
90 exit(-1); // TODO: better error handling |
89 } |
91 } |
90 tag->begin = begin; |
92 tag->begin = begin; |
91 tag->end = end; |
93 tag->end = end; |
92 tag->type_num = cfg_get_tag_type(tag->name); |
94 tag->type_num = cfg_get_tag_type(cx_strcast(tag->name)); |
93 //printf("line {%s}\n", sstrdub(ll).ptr); |
95 //printf("line {%s}\n", cx_strdub(ll).ptr); |
94 if(objconf_on_begin_tag(conf, tag) != 0) { |
96 if(objconf_on_begin_tag(conf, tag) != 0) { |
95 fprintf(stderr, "1error\n"); |
97 fprintf(stderr, "1error\n"); |
96 exit(-1); |
98 exit(-1); |
97 } |
99 } |
98 break; |
100 break; |
99 } |
101 } |
100 case LINE_END_TAG: { |
102 case LINE_END_TAG: { |
101 sstr_t tag = cfg_get_end_tag_name(line); |
103 cxmutstr tag = cfg_get_end_tag_name(line); |
102 if(objconf_on_end_tag(conf, tag) != 0) { |
104 if(objconf_on_end_tag(conf, tag) != 0) { |
103 fprintf(stderr, "2error\n"); |
105 fprintf(stderr, "2error\n"); |
104 exit(-1); |
106 exit(-1); |
105 } |
107 } |
106 |
108 |
120 } |
122 } |
121 return 0; |
123 return 0; |
122 } |
124 } |
123 |
125 |
124 int objconf_on_begin_tag(ObjectConfig *conf, ConfigTag *tag) { |
126 int objconf_on_begin_tag(ObjectConfig *conf, ConfigTag *tag) { |
125 UcxAllocator *mp = conf->parser.mp; |
127 CxAllocator *mp = conf->parser.mp; |
126 if(tag->type_num != TAG_OBJECT) { |
128 if(tag->type_num != TAG_OBJECT) { |
127 ConfigParserLevel *l = conf->levels->data; |
129 ConfigParserLevel *l = conf->levels; |
128 if(l->tag->type_num != TAG_OBJECT) { |
130 if(l->tag->type_num != TAG_OBJECT) { |
129 tag->parent = l->tag; |
131 tag->parent = l->tag; |
130 } |
132 } |
131 } |
133 } |
132 |
134 |
135 case TAG_OBJECT: { |
137 case TAG_OBJECT: { |
136 ConfigObject *obj = OBJ_NEW_N(mp, ConfigObject); |
138 ConfigObject *obj = OBJ_NEW_N(mp, ConfigObject); |
137 obj->begin = tag->begin; |
139 obj->begin = tag->begin; |
138 obj->end = tag->end; |
140 obj->end = tag->end; |
139 |
141 |
140 obj->name = cfg_param_get(tag->param, sstr("name")); |
142 obj->name = cfg_param_get(tag->param, cx_str("name")); |
141 obj->ppath = cfg_param_get(tag->param, sstr("ppath")); |
143 obj->ppath = cfg_param_get(tag->param, cx_str("ppath")); |
142 |
144 |
143 conf->obj = obj; |
145 conf->obj = obj; |
144 conf->objects = ucx_list_append_a(mp, conf->objects, obj); |
146 //conf->objects = ucx_list_append_a(mp, conf->objects, obj); |
|
147 cxListAdd(conf->objects, obj); |
145 |
148 |
146 // create tree level object |
149 // create tree level object |
147 ConfigParserLevel *lvl = OBJ_NEW(mp, ConfigParserLevel); |
150 ConfigParserLevel *lvl = OBJ_NEW(mp, ConfigParserLevel); |
148 lvl->iftag = NULL; |
151 lvl->iftag = NULL; |
149 lvl->levelnum = 1; |
152 lvl->levelnum = 1; |
150 lvl->tag = tag; |
153 lvl->tag = tag; |
151 conf->levels = ucx_list_prepend_a(mp, conf->levels, lvl); |
154 lvl->next = NULL; |
|
155 //conf->levels = ucx_list_prepend_a(mp, conf->levels, lvl); |
|
156 CFG_LEVEL_PREPEND(&conf->levels, lvl); |
152 |
157 |
153 break; |
158 break; |
154 } |
159 } |
155 case TAG_IF: { |
160 case TAG_IF: { |
156 // create tree level object |
161 // create tree level object |
157 ConfigParserLevel *last_lvl = conf->levels->data; |
162 ConfigParserLevel *last_lvl = conf->levels; |
158 |
163 |
159 ConfigParserLevel *lvl = OBJ_NEW(mp, ConfigParserLevel); |
164 ConfigParserLevel *lvl = OBJ_NEW(mp, ConfigParserLevel); |
160 |
165 |
161 lvl->iftag = NULL; |
166 lvl->iftag = NULL; |
162 lvl->levelnum = last_lvl->levelnum + 1; |
167 lvl->levelnum = last_lvl->levelnum + 1; |
163 lvl->tag = tag; |
168 lvl->tag = tag; |
164 conf->levels = ucx_list_prepend_a(mp, conf->levels, lvl); |
169 //conf->levels = ucx_list_prepend_a(mp, conf->levels, lvl); |
|
170 CFG_LEVEL_PREPEND(&conf->levels, lvl); |
165 last_lvl->iftag = tag; |
171 last_lvl->iftag = tag; |
166 |
172 |
167 break; |
173 break; |
168 } |
174 } |
169 case TAG_ELSEIF: { |
175 case TAG_ELSEIF: { |
170 } |
176 } |
171 case TAG_ELSE: { |
177 case TAG_ELSE: { |
172 // create tree level object |
178 // create tree level object |
173 ConfigParserLevel *last_lvl = conf->levels->data; |
179 ConfigParserLevel *last_lvl = conf->levels; |
174 tag->iftag = last_lvl->iftag; |
180 tag->iftag = last_lvl->iftag; |
175 |
181 |
176 ConfigParserLevel *lvl = OBJ_NEW( |
182 ConfigParserLevel *lvl = OBJ_NEW( |
177 conf->parser.mp, |
183 conf->parser.mp, |
178 ConfigParserLevel); |
184 ConfigParserLevel); |
179 |
185 |
180 lvl->iftag = last_lvl->tag; |
186 lvl->iftag = last_lvl->tag; |
181 lvl->levelnum = last_lvl->levelnum + 1; |
187 lvl->levelnum = last_lvl->levelnum + 1; |
182 lvl->tag = tag; |
188 lvl->tag = tag; |
183 conf->levels = ucx_list_prepend(conf->levels, lvl); |
189 //conf->levels = ucx_list_prepend(conf->levels, lvl); |
|
190 CFG_LEVEL_PREPEND(&conf->levels, lvl); |
184 |
191 |
185 break; |
192 break; |
186 } |
193 } |
187 case TAG_CLIENT: { |
194 case TAG_CLIENT: { |
188 // create tree level object |
195 // create tree level object |
198 } |
205 } |
199 |
206 |
200 return 0; |
207 return 0; |
201 } |
208 } |
202 |
209 |
203 int objconf_on_end_tag(ObjectConfig *conf, sstr_t tagname) { |
210 int objconf_on_end_tag(ObjectConfig *conf, cxmutstr tagname) { |
204 int type = cfg_get_tag_type(tagname); |
211 int type = cfg_get_tag_type(cx_strcast(tagname)); |
205 if(type == -1) { |
212 if(type == -1) { |
206 log_ereport(LOG_FAILURE, "objconf: unknown tag"); |
213 log_ereport(LOG_FAILURE, "objconf: unknown tag"); |
207 return 1; |
214 return 1; |
208 } else { |
215 } else { |
209 if(type == TAG_OBJECT) { |
216 if(type == TAG_OBJECT) { |
210 conf->obj = NULL; |
217 conf->obj = NULL; |
211 } |
218 } |
212 |
219 |
213 // remove level |
220 // remove level |
|
221 /* |
214 conf->levels = ucx_list_remove_a( |
222 conf->levels = ucx_list_remove_a( |
215 conf->parser.mp, |
223 conf->parser.mp, |
216 conf->levels, |
224 conf->levels, |
217 conf->levels); |
225 conf->levels); |
|
226 */ |
|
227 conf->levels = conf->levels->next; |
218 } |
228 } |
219 |
229 |
220 return 0; |
230 return 0; |
221 } |
231 } |
222 |
232 |
223 int objconf_on_directive(ObjectConfig *conf, ConfigDirective *dir) { |
233 int objconf_on_directive(ObjectConfig *conf, ConfigDirective *dir) { |
224 ConfigParserLevel *lvl = conf->levels->data; |
234 ConfigParserLevel *lvl = conf->levels; |
225 |
235 |
226 // check if we have a condition for the directive |
236 // check if we have a condition for the directive |
227 // if the level tag is not an object tag, use it as condition |
237 // if the level tag is not an object tag, use it as condition |
228 if(lvl->tag->type_num != TAG_OBJECT) { |
238 if(lvl->tag->type_num != TAG_OBJECT) { |
229 dir->condition = lvl->tag; |
239 dir->condition = lvl->tag; |
230 } |
240 } |
231 |
241 |
232 // add directive to current object |
242 // add directive to current object |
|
243 /* |
233 conf->obj->directives[dir->type_num] = ucx_list_append_a( |
244 conf->obj->directives[dir->type_num] = ucx_list_append_a( |
234 conf->parser.mp, |
245 conf->parser.mp, |
235 conf->obj->directives[dir->type_num], |
246 conf->obj->directives[dir->type_num], |
236 dir); |
247 dir); |
237 |
248 */ |
238 return 0; |
249 |
239 } |
250 ConfigDirectiveList *dir_entry = cxMalloc(conf->parser.mp, sizeof(ConfigDirectiveList)); |
240 |
251 dir_entry->directive = dir; |
|
252 dir_entry->next = NULL; |
|
253 CFG_DIRECTIVES_ADD(&conf->obj->directives[dir->type_num], dir_entry); |
|
254 |
|
255 return 0; |
|
256 } |
|
257 |