161 } |
163 } |
162 |
164 |
163 HTTPObjectConfig* load_obj_conf(char *file) { |
165 HTTPObjectConfig* load_obj_conf(char *file) { |
164 printf("load_obj_conf\n"); |
166 printf("load_obj_conf\n"); |
165 |
167 |
|
168 // new conf function test |
|
169 ObjectConfig *cfg = load_object_config(file); |
|
170 if(cfg == NULL) { |
|
171 return NULL; |
|
172 } |
|
173 |
166 /* create object config */ |
174 /* create object config */ |
167 ObjectConfParser parser; |
|
168 HTTPObjectConfig *conf = calloc(sizeof(HTTPObjectConfig), 1); |
175 HTTPObjectConfig *conf = calloc(sizeof(HTTPObjectConfig), 1); |
169 conf->pool = pool_create(); |
176 conf->pool = pool_create(); |
170 parser.conf = conf; |
177 |
171 |
178 /* convert ObjectConfig to HTTPObjectConfig */ |
172 FILE *in = fopen("conf/obj.conf", "r"); |
179 |
173 if(in == NULL) { |
180 /* add objects */ |
174 fprintf(stderr, "Cannot open conf/obj.conf\n"); |
181 conf->nobj = ucx_dlist_size(cfg->objects); |
175 return NULL; |
182 conf->objects = calloc(1, sizeof(httpd_object*)); |
176 } |
183 |
177 |
184 UcxDlist *objlist = cfg->objects; |
178 char buf[512]; |
185 int i = 0; |
179 int len = 512; |
186 while(objlist != NULL) { |
180 |
187 ConfigObject *cob = objlist->data; |
181 while(!feof(in)) { |
188 |
182 fgets(buf, len, in); |
189 /* get name and ppath */ |
183 |
190 char *name = NULL; |
184 if(*buf == 0) { |
191 char *ppath = NULL; |
185 continue; |
192 if(cob->name.length > 0) { |
186 } |
193 name = sstrdub(cob->name).ptr; |
187 |
194 } |
188 char *ptr; |
195 if(cob->ppath.length > 0) { |
189 if((ptr = strrchr(buf, '\n'))) { |
196 ppath = sstrdub(cob->ppath).ptr; |
190 ptr[0] = 0; |
197 } |
191 } |
198 |
192 |
199 /* create and add object */ |
193 sstr_t line = string_trim(sstr(buf)); |
200 httpd_object *obj = object_new(name); |
194 if(line.length > 0) { |
201 obj->path = NULL; |
195 obj_conf_parse_line(&parser, line); |
202 |
196 } |
203 conf->objects[i] = obj; |
197 } |
204 |
|
205 /* add directives */ |
|
206 for(int i=0;i<6;i++) { |
|
207 UcxDlist *dirs = cob->directives[i]; |
|
208 while(dirs != NULL) { |
|
209 ConfigDirective *cfgdir = dirs->data; |
|
210 |
|
211 directive *d = malloc(sizeof(directive)); |
|
212 d->cond = NULL; |
|
213 d->param = pblock_create_pool(conf->pool, 8); |
|
214 |
|
215 /* add params */ |
|
216 UcxList *param = cfgdir->param; |
|
217 while(param != NULL) { |
|
218 ConfigParam *p = param->data; |
|
219 pblock_nvlinsert( |
|
220 p->name.ptr, |
|
221 p->name.length, |
|
222 p->value.ptr, |
|
223 p->value.length, |
|
224 d->param); |
|
225 param = param->next; |
|
226 } |
|
227 |
|
228 /* get function */ |
|
229 char *func_name = pblock_findval("fn", d->param); |
|
230 d->func = get_function(func_name); |
|
231 |
|
232 dirs = dirs->next; |
|
233 |
|
234 /* add function to dtable */ |
|
235 object_add_directive(obj, d, cfgdir->type_num); |
|
236 } |
|
237 } |
|
238 |
|
239 /* next */ |
|
240 i++; |
|
241 objlist = objlist->next; |
|
242 } |
|
243 |
|
244 |
|
245 |
198 |
246 |
199 |
247 |
200 |
248 |
201 return conf; |
249 return conf; |
202 } |
250 } |