161 serverconfig->pool = pool; |
161 serverconfig->pool = pool; |
162 |
162 |
163 CxAllocator *allocator = pool_allocator(serverconfig->pool); |
163 CxAllocator *allocator = pool_allocator(serverconfig->pool); |
164 serverconfig->a = allocator; |
164 serverconfig->a = allocator; |
165 |
165 |
166 serverconfig->listeners = cxPointerLinkedListCreate(serverconfig->a, cx_cmp_ptr); |
166 serverconfig->listeners = cxLinkedListCreate(serverconfig->a, NULL, CX_STORE_POINTERS); |
167 serverconfig->logfiles = cxPointerLinkedListCreate(serverconfig->a, cx_cmp_ptr); |
167 serverconfig->logfiles = cxLinkedListCreate(serverconfig->a, NULL, CX_STORE_POINTERS); |
168 serverconfig->host_vs = cxHashMapCreate(serverconfig->a, 16); |
168 serverconfig->host_vs = cxHashMapCreate(serverconfig->a, CX_STORE_POINTERS, 16); |
169 serverconfig->authdbs = cxHashMapCreate(serverconfig->a, 16); |
169 serverconfig->authdbs = cxHashMapCreate(serverconfig->a, CX_STORE_POINTERS, 16); |
170 serverconfig->resources = cxHashMapCreate(serverconfig->a, 16); |
170 serverconfig->resources = cxHashMapCreate(serverconfig->a, CX_STORE_POINTERS, 16); |
171 serverconfig->dav = cxHashMapCreate(serverconfig->a, 16); |
171 serverconfig->dav = cxHashMapCreate(serverconfig->a, CX_STORE_POINTERS, 16); |
172 |
172 |
173 // STAGE 1 load_server_conf: |
173 // STAGE 1 load_server_conf: |
174 // At stage 1 we load the file and get the Runtime infos for changing |
174 // At stage 1 we load the file and get the Runtime infos for changing |
175 // the uid, which must be done before most steps. |
175 // the uid, which must be done before most steps. |
176 // Before the uid can be changed, we also need to bind listeners, |
176 // Before the uid can be changed, we also need to bind listeners, |
179 // Runtime |
179 // Runtime |
180 // Listener (dependencies: Threadpool, EventHandler) |
180 // Listener (dependencies: Threadpool, EventHandler) |
181 |
181 |
182 // load Runtime config |
182 // load Runtime config |
183 CxList *list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("Runtime")); |
183 CxList *list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("Runtime")); |
184 CxIterator iter = cxListIterator(list, 0); |
184 CxIterator iter = cxListIterator(list); |
185 cx_foreach(ConfigNode *, runtimeobj, iter) { |
185 cx_foreach(ConfigNode *, runtimeobj, iter) { |
186 if(cfg_handle_runtime(serverconfig, runtimeobj)) { |
186 if(cfg_handle_runtime(serverconfig, runtimeobj)) { |
187 // error |
187 // error |
188 log_ereport(LOG_FAILURE, "server.conf runtime"); |
188 log_ereport(LOG_FAILURE, "server.conf runtime"); |
189 return NULL; |
189 return NULL; |
192 cxListDestroy(list); |
192 cxListDestroy(list); |
193 |
193 |
194 // load threadpool config |
194 // load threadpool config |
195 log_ereport(LOG_DEBUG, "apply config: Threadpool"); |
195 log_ereport(LOG_DEBUG, "apply config: Threadpool"); |
196 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("Threadpool")); |
196 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("Threadpool")); |
197 iter = cxListIterator(list, 0); |
197 iter = cxListIterator(list); |
198 cx_foreach(ConfigNode *, elm, iter) { |
198 cx_foreach(ConfigNode *, elm, iter) { |
199 if(cfg_handle_threadpool(serverconfig, elm)) { |
199 if(cfg_handle_threadpool(serverconfig, elm)) { |
200 log_ereport(LOG_FAILURE, "server.conf threadpool"); |
200 log_ereport(LOG_FAILURE, "server.conf threadpool"); |
201 return NULL; |
201 return NULL; |
202 } |
202 } |
209 } |
209 } |
210 |
210 |
211 // load eventhandler config |
211 // load eventhandler config |
212 log_ereport(LOG_DEBUG, "apply config: EventHandler"); |
212 log_ereport(LOG_DEBUG, "apply config: EventHandler"); |
213 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("EventHandler")); |
213 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("EventHandler")); |
214 iter = cxListIterator(list, 0); |
214 iter = cxListIterator(list); |
215 cx_foreach(ConfigNode *, elm, iter) { |
215 cx_foreach(ConfigNode *, elm, iter) { |
216 if(cfg_handle_eventhandler(serverconfig, elm)) { |
216 if(cfg_handle_eventhandler(serverconfig, elm)) { |
217 // error |
217 // error |
218 log_ereport(LOG_FAILURE, "cannot create event handler"); |
218 log_ereport(LOG_FAILURE, "cannot create event handler"); |
219 return NULL; |
219 return NULL; |
280 } |
280 } |
281 cxListDestroy(list); |
281 cxListDestroy(list); |
282 |
282 |
283 log_ereport(LOG_DEBUG, "apply config: AccessLog"); |
283 log_ereport(LOG_DEBUG, "apply config: AccessLog"); |
284 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("AccessLog")); |
284 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("AccessLog")); |
285 iter = cxListIterator(list, 0); |
285 iter = cxListIterator(list); |
286 cx_foreach(ConfigNode *, scfgobj, iter) { |
286 cx_foreach(ConfigNode *, scfgobj, iter) { |
287 if(cfg_handle_accesslog(serverconfig, scfgobj)) { |
287 if(cfg_handle_accesslog(serverconfig, scfgobj)) { |
288 return NULL; |
288 return NULL; |
289 } |
289 } |
290 } |
290 } |
291 cxListDestroy(list); |
291 cxListDestroy(list); |
292 |
292 |
293 log_ereport(LOG_DEBUG, "apply config: AuthDB"); |
293 log_ereport(LOG_DEBUG, "apply config: AuthDB"); |
294 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("AuthDB")); |
294 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("AuthDB")); |
295 iter = cxListIterator(list, 0); |
295 iter = cxListIterator(list); |
296 cx_foreach(ConfigNode *, scfgobj, iter) { |
296 cx_foreach(ConfigNode *, scfgobj, iter) { |
297 if(cfg_handle_authdb(serverconfig, scfgobj)) { |
297 if(cfg_handle_authdb(serverconfig, scfgobj)) { |
298 return NULL; |
298 return NULL; |
299 } |
299 } |
300 } |
300 } |
301 cxListDestroy(list); |
301 cxListDestroy(list); |
302 |
302 |
303 log_ereport(LOG_DEBUG, "apply config: VirtualServer"); |
303 log_ereport(LOG_DEBUG, "apply config: VirtualServer"); |
304 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("VirtualServer")); |
304 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("VirtualServer")); |
305 iter = cxListIterator(list, 0); |
305 iter = cxListIterator(list); |
306 cx_foreach(ConfigNode *, scfgobj, iter) { |
306 cx_foreach(ConfigNode *, scfgobj, iter) { |
307 if(cfg_handle_vs(serverconfig, scfgobj)) { |
307 if(cfg_handle_vs(serverconfig, scfgobj)) { |
308 return NULL; |
308 return NULL; |
309 } |
309 } |
310 } |
310 } |
311 cxListDestroy(list); |
311 cxListDestroy(list); |
312 |
312 |
313 log_ereport(LOG_DEBUG, "apply config: ResourcePool"); |
313 log_ereport(LOG_DEBUG, "apply config: ResourcePool"); |
314 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("ResourcePool")); |
314 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("ResourcePool")); |
315 iter = cxListIterator(list, 0); |
315 iter = cxListIterator(list); |
316 cx_foreach(ConfigNode *, scfgobj, iter) { |
316 cx_foreach(ConfigNode *, scfgobj, iter) { |
317 if(cfg_handle_resourcepool(serverconfig, scfgobj)) { |
317 if(cfg_handle_resourcepool(serverconfig, scfgobj)) { |
318 return NULL; |
318 return NULL; |
319 } |
319 } |
320 } |
320 } |
321 cxListDestroy(list); |
321 cxListDestroy(list); |
322 |
322 |
323 log_ereport(LOG_DEBUG, "apply config: Dav"); |
323 log_ereport(LOG_DEBUG, "apply config: Dav"); |
324 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("Dav")); |
324 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("Dav")); |
325 iter = cxListIterator(list, 0); |
325 iter = cxListIterator(list); |
326 cx_foreach(ConfigNode *, scfgobj, iter) { |
326 cx_foreach(ConfigNode *, scfgobj, iter) { |
327 if(cfg_handle_dav(serverconfig, scfgobj)) { |
327 if(cfg_handle_dav(serverconfig, scfgobj)) { |
328 return NULL; |
328 return NULL; |
329 } |
329 } |
330 } |
330 } |
331 cxListDestroy(list); |
331 cxListDestroy(list); |
332 |
332 |
333 // set VirtualServer for all listeners |
333 // set VirtualServer for all listeners |
334 CxList *ls = serverconfig->listeners; |
334 CxList *ls = serverconfig->listeners; |
335 iter = cxListIterator(ls, 0); |
335 iter = cxListIterator(ls); |
336 cx_foreach(HttpListener *, listener, iter) { |
336 cx_foreach(HttpListener *, listener, iter) { |
337 cxstring vsname = cx_str(listener->default_vs.vs_name); |
337 cxstring vsname = cx_str(listener->default_vs.vs_name); |
338 |
338 |
339 // search for VirtualServer |
339 // search for VirtualServer |
340 //int b = 0; |
340 //int b = 0; |
356 old_cfg->next = new_cfg; |
356 old_cfg->next = new_cfg; |
357 cfg_ref(new_cfg); // new cfg should not be freed until old cfg is freed |
357 cfg_ref(new_cfg); // new cfg should not be freed until old cfg is freed |
358 |
358 |
359 // compare old/new listeners and set next listener, if they are using |
359 // compare old/new listeners and set next listener, if they are using |
360 // the same socket |
360 // the same socket |
361 CxIterator old_listeners = cxListIterator(old_cfg->listeners, 0); |
361 CxIterator old_listeners = cxListIterator(old_cfg->listeners); |
362 cx_foreach(HttpListener*, oldls, old_listeners) { |
362 cx_foreach(HttpListener*, oldls, old_listeners) { |
363 if(oldls->next) { |
363 if(oldls->next) { |
364 // maybe we can remove this check |
364 // maybe we can remove this check |
365 log_ereport(LOG_WARN, "migrate_server_conf: oldls->next not NULL"); |
365 log_ereport(LOG_WARN, "migrate_server_conf: oldls->next not NULL"); |
366 continue; |
366 continue; |
367 } |
367 } |
368 |
368 |
369 CxIterator new_listeners = cxListIterator(new_cfg->listeners, 0); |
369 CxIterator new_listeners = cxListIterator(new_cfg->listeners); |
370 cx_foreach(HttpListener*, newls, new_listeners) { |
370 cx_foreach(HttpListener*, newls, new_listeners) { |
371 if(http_listener_socket_eq(oldls, newls)) { |
371 if(http_listener_socket_eq(oldls, newls)) { |
372 http_listener_set_next(oldls, newls); |
372 http_listener_set_next(oldls, newls); |
373 break; |
373 break; |
374 } |
374 } |
796 |
796 |
797 int ret = 0; |
797 int ret = 0; |
798 WebdavRepository *repository = pool_malloc(cfg->pool, sizeof(WebdavRepository)); |
798 WebdavRepository *repository = pool_malloc(cfg->pool, sizeof(WebdavRepository)); |
799 repository->vfs = NULL; |
799 repository->vfs = NULL; |
800 repository->vfsInitData = NULL; |
800 repository->vfsInitData = NULL; |
801 repository->davBackends = cxPointerLinkedListCreate(a, cx_cmp_ptr); // value type: WebdavBackendInitData* |
801 repository->davBackends = cxLinkedListCreate(a, NULL, CX_STORE_POINTERS); // value type: WebdavBackendInitData* |
802 |
802 |
803 // initialize backends |
803 // initialize backends |
804 CxIterator i = cxListIterator(backends, 0); |
804 CxIterator i = cxListIterator(backends); |
805 cx_foreach(ConfigParam *, backendArg, i) { |
805 cx_foreach(ConfigParam *, backendArg, i) { |
806 // the DavBackend value should contain the dav class name |
806 // the DavBackend value should contain the dav class name |
807 |
807 |
808 WebdavType *dav = webdav_get_type((cxstring){backendArg->value.ptr, backendArg->value.length}); |
808 WebdavType *dav = webdav_get_type((cxstring){backendArg->value.ptr, backendArg->value.length}); |
809 if(!dav) { |
809 if(!dav) { |
884 // usually, one parameter is one token, however the config parser |
884 // usually, one parameter is one token, however the config parser |
885 // converts name=value pairs to one ConfigParam |
885 // converts name=value pairs to one ConfigParam |
886 |
886 |
887 // list of cxmutstr, however the expression parser will use this |
887 // list of cxmutstr, however the expression parser will use this |
888 // as list of cxstring, but that is totally fine |
888 // as list of cxstring, but that is totally fine |
889 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), cx_cmp_ptr, sizeof(cxmutstr)); |
889 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxmutstr)); |
890 ConfigParam *arg = node->args; |
890 ConfigParam *arg = node->args; |
891 while(arg) { |
891 while(arg) { |
892 if(arg->name.length > 0) { |
892 if(arg->name.length > 0) { |
893 // arg text is name=value, therefore we add 3 tokens |
893 // arg text is name=value, therefore we add 3 tokens |
894 // name, "=", value |
894 // name, "=", value |
1182 } |
1182 } |
1183 |
1183 |
1184 // TODO: malloc return checks |
1184 // TODO: malloc return checks |
1185 |
1185 |
1186 ACLData *acldata = acl_data_new(cfg->a); |
1186 ACLData *acldata = acl_data_new(cfg->a); |
1187 CxIterator iter = cxListIterator(aclfile->namedACLs, 0); |
1187 CxIterator iter = cxListIterator(aclfile->namedACLs); |
1188 cx_foreach(ACLConfig *, ac, iter) { |
1188 cx_foreach(ACLConfig *, ac, iter) { |
1189 ACLList *acl = acl_config_convert(cfg, ac); |
1189 ACLList *acl = acl_config_convert(cfg, ac); |
1190 log_ereport(LOG_VERBOSE, "add acl: %.*s", (int)ac->id.length, ac->id.ptr); |
1190 log_ereport(LOG_VERBOSE, "add acl: %.*s", (int)ac->id.length, ac->id.ptr); |
1191 cxMapPut(acldata->namedACLs, cx_hash_key(ac->id.ptr, ac->id.length), acl); |
1191 cxMapPut(acldata->namedACLs, cx_hash_key(ac->id.ptr, ac->id.length), acl); |
1192 } |
1192 } |