src/server/daemon/config.c

changeset 579
e10457d74fe1
parent 574
76450adae540
equal deleted inserted replaced
578:eb48f716b31c 579:e10457d74fe1
191 // error 191 // error
192 log_ereport(LOG_FAILURE, "server.conf runtime"); 192 log_ereport(LOG_FAILURE, "server.conf runtime");
193 return NULL; 193 return NULL;
194 } 194 }
195 } 195 }
196 cxListDestroy(list); 196 cxListFree(list);
197 197
198 // load threadpool config 198 // load threadpool config
199 log_ereport(LOG_DEBUG, "apply config: Threadpool"); 199 log_ereport(LOG_DEBUG, "apply config: Threadpool");
200 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("Threadpool")); 200 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("Threadpool"));
201 iter = cxListIterator(list); 201 iter = cxListIterator(list);
203 if(cfg_handle_threadpool(serverconfig, elm)) { 203 if(cfg_handle_threadpool(serverconfig, elm)) {
204 log_ereport(LOG_FAILURE, "server.conf threadpool"); 204 log_ereport(LOG_FAILURE, "server.conf threadpool");
205 return NULL; 205 return NULL;
206 } 206 }
207 } 207 }
208 cxListDestroy(list); 208 cxListFree(list);
209 // check thread pool config 209 // check thread pool config
210 if(check_thread_pool_cfg() != 0) { 210 if(check_thread_pool_cfg() != 0) {
211 /* critical error */ 211 /* critical error */
212 return NULL; 212 return NULL;
213 } 213 }
226 // check event handler config 226 // check event handler config
227 if(check_event_handler_cfg() != 0) { 227 if(check_event_handler_cfg() != 0) {
228 /* critical error */ 228 /* critical error */
229 return NULL; 229 return NULL;
230 } 230 }
231 cxListDestroy(list); 231 cxListFree(list);
232 232
233 // load Listener config 233 // load Listener config
234 log_ereport(LOG_DEBUG, "apply config: Listener"); 234 log_ereport(LOG_DEBUG, "apply config: Listener");
235 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("Listener")); 235 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("Listener"));
236 iter = cxListIterator(list); 236 iter = cxListIterator(list);
237 cx_foreach(ConfigNode *, scfgobj, iter) { 237 cx_foreach(ConfigNode *, scfgobj, iter) {
238 if(cfg_handle_listener(serverconfig, scfgobj)) { 238 if(cfg_handle_listener(serverconfig, scfgobj)) {
239 return NULL; 239 return NULL;
240 } 240 }
241 } 241 }
242 cxListDestroy(list); 242 cxListFree(list);
243 243
244 // we return here, to let the webserver use the runtime info to 244 // we return here, to let the webserver use the runtime info to
245 // change the uid if needed 245 // change the uid if needed
246 return serverconfig; 246 return serverconfig;
247 } 247 }
269 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("LogFile")); 269 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("LogFile"));
270 CxIterator iter = cxListIterator(list); 270 CxIterator iter = cxListIterator(list);
271 cx_foreach(ConfigNode *, logobj, iter) { 271 cx_foreach(ConfigNode *, logobj, iter) {
272 if(!logobj) { 272 if(!logobj) {
273 // error 273 // error
274 cxListDestroy(list); 274 cxListFree(list);
275 return NULL; 275 return NULL;
276 } 276 }
277 277
278 int ret = cfg_handle_logfile(serverconfig, logobj); 278 int ret = cfg_handle_logfile(serverconfig, logobj);
279 if(ret != 0) { 279 if(ret != 0) {
280 // cannot initialize log file 280 // cannot initialize log file
281 cxListDestroy(list); 281 cxListFree(list);
282 return NULL; 282 return NULL;
283 } 283 }
284 } 284 }
285 cxListDestroy(list); 285 cxListFree(list);
286 286
287 log_ereport(LOG_DEBUG, "apply config: AccessLog"); 287 log_ereport(LOG_DEBUG, "apply config: AccessLog");
288 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("AccessLog")); 288 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("AccessLog"));
289 iter = cxListIterator(list); 289 iter = cxListIterator(list);
290 cx_foreach(ConfigNode *, scfgobj, iter) { 290 cx_foreach(ConfigNode *, scfgobj, iter) {
291 if(cfg_handle_accesslog(serverconfig, scfgobj)) { 291 if(cfg_handle_accesslog(serverconfig, scfgobj)) {
292 return NULL; 292 return NULL;
293 } 293 }
294 } 294 }
295 cxListDestroy(list); 295 cxListFree(list);
296 296
297 log_ereport(LOG_DEBUG, "apply config: AuthDB"); 297 log_ereport(LOG_DEBUG, "apply config: AuthDB");
298 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("AuthDB")); 298 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("AuthDB"));
299 iter = cxListIterator(list); 299 iter = cxListIterator(list);
300 cx_foreach(ConfigNode *, scfgobj, iter) { 300 cx_foreach(ConfigNode *, scfgobj, iter) {
301 if(cfg_handle_authdb(serverconfig, scfgobj)) { 301 if(cfg_handle_authdb(serverconfig, scfgobj)) {
302 return NULL; 302 return NULL;
303 } 303 }
304 } 304 }
305 cxListDestroy(list); 305 cxListFree(list);
306 306
307 log_ereport(LOG_DEBUG, "apply config: VirtualServer"); 307 log_ereport(LOG_DEBUG, "apply config: VirtualServer");
308 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("VirtualServer")); 308 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("VirtualServer"));
309 iter = cxListIterator(list); 309 iter = cxListIterator(list);
310 cx_foreach(ConfigNode *, scfgobj, iter) { 310 cx_foreach(ConfigNode *, scfgobj, iter) {
311 if(cfg_handle_vs(serverconfig, scfgobj)) { 311 if(cfg_handle_vs(serverconfig, scfgobj)) {
312 return NULL; 312 return NULL;
313 } 313 }
314 } 314 }
315 cxListDestroy(list); 315 cxListFree(list);
316 316
317 log_ereport(LOG_DEBUG, "apply config: ResourcePool"); 317 log_ereport(LOG_DEBUG, "apply config: ResourcePool");
318 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("ResourcePool")); 318 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("ResourcePool"));
319 iter = cxListIterator(list); 319 iter = cxListIterator(list);
320 cx_foreach(ConfigNode *, scfgobj, iter) { 320 cx_foreach(ConfigNode *, scfgobj, iter) {
321 if(cfg_handle_resourcepool(serverconfig, scfgobj)) { 321 if(cfg_handle_resourcepool(serverconfig, scfgobj)) {
322 return NULL; 322 return NULL;
323 } 323 }
324 } 324 }
325 cxListDestroy(list); 325 cxListFree(list);
326 326
327 log_ereport(LOG_DEBUG, "apply config: Dav"); 327 log_ereport(LOG_DEBUG, "apply config: Dav");
328 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("Dav")); 328 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("Dav"));
329 iter = cxListIterator(list); 329 iter = cxListIterator(list);
330 cx_foreach(ConfigNode *, scfgobj, iter) { 330 cx_foreach(ConfigNode *, scfgobj, iter) {
331 if(cfg_handle_dav(serverconfig, scfgobj)) { 331 if(cfg_handle_dav(serverconfig, scfgobj)) {
332 return NULL; 332 return NULL;
333 } 333 }
334 } 334 }
335 cxListDestroy(list); 335 cxListFree(list);
336 336
337 // set VirtualServer for all listeners 337 // set VirtualServer for all listeners
338 CxList *ls = serverconfig->listeners; 338 CxList *ls = serverconfig->listeners;
339 iter = cxListIterator(ls); 339 iter = cxListIterator(ls);
340 cx_foreach(HttpListener *, listener, iter) { 340 cx_foreach(HttpListener *, listener, iter) {
341 cxstring vsname = cx_str(listener->default_vs.vs_name); 341 cxstring vsname = cx_str(listener->default_vs.vs_name);
342 342
343 // search for VirtualServer 343 // search for VirtualServer
344 //int b = 0; 344 //int b = 0;
345 CxIterator map_iter = cxMapIteratorValues(serverconfig->host_vs); 345 CxMapIterator map_iter = cxMapIteratorValues(serverconfig->host_vs);
346 cx_foreach(VirtualServer *, vs, map_iter) { 346 cx_foreach(VirtualServer *, vs, map_iter) {
347 if(!cx_strcmp(vsname, (cxstring){vs->name.ptr, vs->name.length})) { 347 if(!cx_strcmp(vsname, (cxstring){vs->name.ptr, vs->name.length})) {
348 listener->default_vs.vs = vs; 348 listener->default_vs.vs = vs;
349 break; 349 break;
350 } 350 }
699 // TODO: check if all important configs are set 699 // TODO: check if all important configs are set
700 700
701 int ret = 0; 701 int ret = 0;
702 HttpListener *listener = http_listener_create(&lc); 702 HttpListener *listener = http_listener_create(&lc);
703 if(listener) { 703 if(listener) {
704 listener->default_vs.vs_name = cx_strdup_a(cfg->a, (cxstring){lc.vs.ptr, lc.vs.length}).ptr; 704 listener->default_vs.vs_name = cx_strdup_a(cfg->a, lc.vs).ptr;
705 cxListAdd(cfg->listeners, listener); 705 cxListAdd(cfg->listeners, listener);
706 } else { 706 } else {
707 ret = 1; 707 ret = 1;
708 } 708 }
709 709
790 if(node->type == CONFIG_NODE_DIRECTIVE) { 790 if(node->type == CONFIG_NODE_DIRECTIVE) {
791 if(CFG_NUM_PARAMS(node->args) == 1) { 791 if(CFG_NUM_PARAMS(node->args) == 1) {
792 cxListAdd(backends, node->args); 792 cxListAdd(backends, node->args);
793 } else { 793 } else {
794 log_ereport(LOG_MISCONFIG, "DavBackend must have only one value"); 794 log_ereport(LOG_MISCONFIG, "DavBackend must have only one value");
795 cxListDestroy(backends); 795 cxListFree(backends);
796 return 1; 796 return 1;
797 } 797 }
798 } else { 798 } else {
799 log_ereport(LOG_MISCONFIG, "DavBackend must be a directive"); 799 log_ereport(LOG_MISCONFIG, "DavBackend must be a directive");
800 cxListDestroy(backends); 800 cxListFree(backends);
801 return 1; 801 return 1;
802 } 802 }
803 } 803 }
804 } 804 }
805 805
839 davInit->davType = dav; 839 davInit->davType = dav;
840 davInit->davInitData = init_data; 840 davInit->davInitData = init_data;
841 841
842 cxListAdd(repository->davBackends, davInit); 842 cxListAdd(repository->davBackends, davInit);
843 } 843 }
844 cxListDestroy(backends); 844 cxListFree(backends);
845 845
846 // initialize vfs 846 // initialize vfs
847 cxstring vfs_class = serverconfig_object_directive_value(obj, cx_str("VFS")); 847 cxstring vfs_class = serverconfig_object_directive_value(obj, cx_str("VFS"));
848 if(vfs_class.length > 0) { 848 if(vfs_class.length > 0) {
849 VfsType *vfs = vfs_get_type((cxstring){vfs_class.ptr, vfs_class.length}); 849 VfsType *vfs = vfs_get_type((cxstring){vfs_class.ptr, vfs_class.length});
904 cxListAdd(tokens, &arg->name); 904 cxListAdd(tokens, &arg->name);
905 cxmutstr op = (cxmutstr){ "=", 1 }; 905 cxmutstr op = (cxmutstr){ "=", 1 };
906 cxListAdd(tokens, &op); 906 cxListAdd(tokens, &op);
907 } 907 }
908 if(cxListAdd(tokens, &arg->value)) { 908 if(cxListAdd(tokens, &arg->value)) {
909 cxListDestroy(tokens); 909 cxListFree(tokens);
910 return 1; // OOM 910 return 1; // OOM
911 } 911 }
912 arg = arg->next; 912 arg = arg->next;
913 } 913 }
914 914
917 if(!condition->expression) { 917 if(!condition->expression) {
918 ret = 1; 918 ret = 1;
919 } 919 }
920 920
921 // don't need the token list anymore 921 // don't need the token list anymore
922 cxListDestroy(tokens); 922 cxListFree(tokens);
923 923
924 return ret; 924 return ret;
925 } 925 }
926 926
927 // convert a condition 927 // convert a condition

mercurial