src/server/daemon/config.c

changeset 490
d218607f5a7e
parent 467
4d038bc6f86e
child 556
b036ccad4b49
equal deleted inserted replaced
489:921f83a8943f 490:d218607f5a7e
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;
227 cxListDestroy(list); 227 cxListDestroy(list);
228 228
229 // load Listener config 229 // load Listener config
230 log_ereport(LOG_DEBUG, "apply config: Listener"); 230 log_ereport(LOG_DEBUG, "apply config: Listener");
231 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("Listener")); 231 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("Listener"));
232 iter = cxListIterator(list, 0); 232 iter = cxListIterator(list);
233 cx_foreach(ConfigNode *, scfgobj, iter) { 233 cx_foreach(ConfigNode *, scfgobj, iter) {
234 if(cfg_handle_listener(serverconfig, scfgobj)) { 234 if(cfg_handle_listener(serverconfig, scfgobj)) {
235 return NULL; 235 return NULL;
236 } 236 }
237 } 237 }
261 // init logfile first 261 // init logfile first
262 CxList *list; 262 CxList *list;
263 263
264 log_ereport(LOG_DEBUG, "apply config: LogFile"); 264 log_ereport(LOG_DEBUG, "apply config: LogFile");
265 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("LogFile")); 265 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("LogFile"));
266 CxIterator iter = cxListIterator(list, 0); 266 CxIterator iter = cxListIterator(list);
267 cx_foreach(ConfigNode *, logobj, iter) { 267 cx_foreach(ConfigNode *, logobj, iter) {
268 if(!logobj) { 268 if(!logobj) {
269 // error 269 // error
270 cxListDestroy(list); 270 cxListDestroy(list);
271 return NULL; 271 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 }
391 if(cfg->next) { 391 if(cfg->next) {
392 cfg_unref(cfg->next); 392 cfg_unref(cfg->next);
393 } 393 }
394 log_ereport(LOG_VERBOSE, "destroy configuration %p", cfg); 394 log_ereport(LOG_VERBOSE, "destroy configuration %p", cfg);
395 395
396 CxIterator i = cxListIterator(cfg->listeners, 0); 396 CxIterator i = cxListIterator(cfg->listeners);
397 cx_foreach(HttpListener*, listener, i) { 397 cx_foreach(HttpListener*, listener, i) {
398 http_listener_destroy(listener); 398 http_listener_destroy(listener);
399 } 399 }
400 400
401 pool_destroy(cfg->pool); 401 pool_destroy(cfg->pool);
748 return 0; 748 return 0;
749 } 749 }
750 750
751 int cfg_handle_dav(ServerConfiguration *cfg, ConfigNode *obj) { 751 int cfg_handle_dav(ServerConfiguration *cfg, ConfigNode *obj) {
752 CxAllocator *a = pool_allocator(cfg->pool); 752 CxAllocator *a = pool_allocator(cfg->pool);
753 CxList *backends = cxPointerLinkedListCreate(a, cx_cmp_ptr); // list of ConfigParam* 753 CxList *backends = cxLinkedListCreate(a, NULL, CX_STORE_POINTERS); // list of ConfigParam*
754 int init_error; 754 int init_error;
755 755
756 // parse args 756 // parse args
757 char *uri = NULL; 757 char *uri = NULL;
758 char *ppath = NULL; 758 char *ppath = NULL;
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
1138 1138
1139 int ret = 0; 1139 int ret = 0;
1140 1140
1141 // cleanup in case of errors is done by the allocator 1141 // cleanup in case of errors is done by the allocator
1142 MimeMap *mimemap = cxMalloc(cfg->a, sizeof(MimeMap)); 1142 MimeMap *mimemap = cxMalloc(cfg->a, sizeof(MimeMap));
1143 CxMap *map = cxHashMapCreate(cfg->a, (mimecfg->ntypes * 3) / 2); 1143 CxMap *map = cxHashMapCreate(cfg->a, CX_STORE_POINTERS, (mimecfg->ntypes * 3) / 2);
1144 1144
1145 if(mimemap && map) { 1145 if(mimemap && map) {
1146 mimemap->map = map; 1146 mimemap->map = map;
1147 1147
1148 // add ext type pairs 1148 // add ext type pairs
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 }

mercurial