62 |
62 |
63 return conf; |
63 return conf; |
64 } |
64 } |
65 |
65 |
66 void free_object_config(ObjectConfig *conf) { |
66 void free_object_config(ObjectConfig *conf) { |
67 // free all objects |
|
68 UcxDlist *objects = conf->objects; |
|
69 while(objects != NULL) { |
|
70 ConfigObject *obj = objects->data; |
|
71 // free all directive lists |
|
72 for(int i=0;i<6;i++) { |
|
73 if(obj->directives[i]) { |
|
74 ucx_dlist_free(obj->directives[i]); |
|
75 } |
|
76 } |
|
77 |
|
78 objects = objects->next; |
|
79 } |
|
80 if(conf->objects) { |
|
81 ucx_dlist_free(conf->objects); |
|
82 } |
|
83 |
|
84 // free other lists |
67 // free other lists |
85 if(conf->levels) { |
68 if(conf->levels) { |
86 ucx_list_free(conf->levels); |
69 ucx_list_free(conf->levels); |
87 } |
|
88 if(conf->lines) { |
|
89 ucx_dlist_free(conf->lines); |
|
90 } |
|
91 if(conf->conditions) { |
|
92 ucx_dlist_free(conf->conditions); |
|
93 } |
70 } |
94 |
71 |
95 // free mempool |
72 // free mempool |
96 ucx_mempool_free(conf->parser.mp); |
73 ucx_mempool_free(conf->parser.mp); |
97 free(conf); |
74 free(conf); |
143 } |
120 } |
144 return 0; |
121 return 0; |
145 } |
122 } |
146 |
123 |
147 int objconf_on_begin_tag(ObjectConfig *conf, ConfigTag *tag) { |
124 int objconf_on_begin_tag(ObjectConfig *conf, ConfigTag *tag) { |
|
125 UcxMempool *mp = conf->parser.mp; |
148 if(tag->type_num != TAG_OBJECT) { |
126 if(tag->type_num != TAG_OBJECT) { |
149 ConfigParserLevel *l = conf->levels->data; |
127 ConfigParserLevel *l = conf->levels->data; |
150 if(l->tag->type_num != TAG_OBJECT) { |
128 if(l->tag->type_num != TAG_OBJECT) { |
151 tag->parent = l->tag; |
129 tag->parent = l->tag; |
152 } |
130 } |
161 |
139 |
162 obj->name = cfg_param_get(tag->param, sstr("name")); |
140 obj->name = cfg_param_get(tag->param, sstr("name")); |
163 obj->ppath = cfg_param_get(tag->param, sstr("ppath")); |
141 obj->ppath = cfg_param_get(tag->param, sstr("ppath")); |
164 |
142 |
165 conf->obj = obj; |
143 conf->obj = obj; |
166 conf->objects = ucx_dlist_append(conf->objects, obj); |
144 conf->objects = cfg_dlist_append(mp, conf->objects, obj); |
167 |
145 |
168 // create tree level object |
146 // create tree level object |
169 ConfigParserLevel *lvl = OBJ_NEW(conf->parser.mp, ConfigParserLevel); |
147 ConfigParserLevel *lvl = OBJ_NEW(conf->parser.mp, ConfigParserLevel); |
170 lvl->iftag = NULL; |
148 lvl->iftag = NULL; |
171 lvl->levelnum = 1; |
149 lvl->levelnum = 1; |
249 if(lvl->tag->type_num != TAG_OBJECT) { |
227 if(lvl->tag->type_num != TAG_OBJECT) { |
250 dir->condition = lvl->tag; |
228 dir->condition = lvl->tag; |
251 } |
229 } |
252 |
230 |
253 // add directive to current object |
231 // add directive to current object |
254 conf->obj->directives[dir->type_num] = ucx_dlist_append( |
232 conf->obj->directives[dir->type_num] = cfg_dlist_append( |
|
233 conf->parser.mp, |
255 conf->obj->directives[dir->type_num], |
234 conf->obj->directives[dir->type_num], |
256 dir); |
235 dir); |
257 |
236 |
258 return 0; |
237 return 0; |
259 } |
238 } |