src/server/daemon/config.c

changeset 37
360b9aabe17e
parent 36
450d2d5f4735
child 38
d07810b02147
equal deleted inserted replaced
36:450d2d5f4735 37:360b9aabe17e
121 121
122 /* 122 /*
123 * convert ServerConfig to ServerConfiguration 123 * convert ServerConfig to ServerConfiguration
124 * 124 *
125 * its important to do this in the correct order: 125 * its important to do this in the correct order:
126 * LogFile (we want an open log file first to log possible errors) 126 * LogFile (open log file first to log possible errors)
127 * Runtime 127 * Runtime
128 * Threadpool 128 * Threadpool
129 * EventHandler 129 * EventHandler
130 * AuthDB 130 * AuthDB
131 * Listener (we set the VirtualServer later) 131 * Listener (we set the VirtualServer later)
157 cfg_handle_runtime(serverconfig, scfgobj); 157 cfg_handle_runtime(serverconfig, scfgobj);
158 } 158 }
159 159
160 list = ucx_map_sstr_get(serverconf->objects, sstrn("Threadpool", 10)); 160 list = ucx_map_sstr_get(serverconf->objects, sstrn("Threadpool", 10));
161 UCX_FOREACH(UcxList*, list, elm) { 161 UCX_FOREACH(UcxList*, list, elm) {
162 ServerConfigObject *scfgobj = elm->data; 162 cfg_handle_threadpool(serverconfig, elm->data);
163 // TODO: threadpool 163 }
164 // check thread pool config
165 if(check_thread_pool_cfg() != 0) {
166 /* critical error */
167 return NULL;
164 } 168 }
165 169
166 list = ucx_map_sstr_get(serverconf->objects, sstrn("EventHandler", 12)); 170 list = ucx_map_sstr_get(serverconf->objects, sstrn("EventHandler", 12));
167 UCX_FOREACH(UcxList*, list, elm) { 171 UCX_FOREACH(UcxList*, list, elm) {
168 cfg_handle_eventhandler(serverconfig, (ServerConfigObject*)elm->data); 172 cfg_handle_eventhandler(serverconfig, (ServerConfigObject*)elm->data);
173 }
174 // check event handler config
175 if(check_event_handler_cfg() != 0) {
176 /* critical error */
177 return NULL;
169 } 178 }
170 179
171 list = ucx_map_sstr_get(serverconf->objects, sstrn("AuthDB", 6)); 180 list = ucx_map_sstr_get(serverconf->objects, sstrn("AuthDB", 6));
172 UCX_FOREACH(UcxList*, list, elm) { 181 UCX_FOREACH(UcxList*, list, elm) {
173 ServerConfigObject *scfgobj = elm->data; 182 ServerConfigObject *scfgobj = elm->data;
183 list = ucx_map_sstr_get(serverconf->objects, sstrn("VirtualServer", 13)); 192 list = ucx_map_sstr_get(serverconf->objects, sstrn("VirtualServer", 13));
184 UCX_FOREACH(UcxList*, list, elm) { 193 UCX_FOREACH(UcxList*, list, elm) {
185 ServerConfigObject *scfgobj = elm->data; 194 ServerConfigObject *scfgobj = elm->data;
186 cfg_handle_vs(serverconfig, scfgobj); 195 cfg_handle_vs(serverconfig, scfgobj);
187 } 196 }
188 197
189 // check event handler config
190 if(check_event_handler_cfg() != 0) {
191 /* critical error */
192 return NULL;
193 }
194
195 // check thread pool config
196 if(check_thread_pool_cfg() != 0) {
197 /* critical error */
198 return NULL;
199 }
200 198
201 // set VirtualServer for all listeners 199 // set VirtualServer for all listeners
202 UcxList *ls = serverconfig->listeners; 200 UcxList *ls = serverconfig->listeners;
203 while(ls) { 201 while(ls) {
204 HttpListener *listener = ls->data; 202 HttpListener *listener = ls->data;
269 free(logcfg.level); 267 free(logcfg.level);
270 268
271 return ret; 269 return ret;
272 } 270 }
273 271
272 int cfg_handle_threadpool(ServerConfiguration *cfg, ServerConfigObject *obj) {
273 ThreadPoolConfig poolcfg;
274 poolcfg.min_threads = 4;
275 poolcfg.min_threads = 4;
276 poolcfg.max_threads = 8;
277 poolcfg.queue_size = 64;
278 poolcfg.stack_size = 262144;
279
280 sstr_t name = cfg_directivelist_get_str(
281 obj->directives,
282 sstr("Name"));
283 sstr_t min = cfg_directivelist_get_str(
284 obj->directives,
285 sstr("MinThreads"));
286 sstr_t max = cfg_directivelist_get_str(
287 obj->directives,
288 sstr("MaxThreads"));
289 sstr_t stack = cfg_directivelist_get_str(
290 obj->directives,
291 sstr("StackSize"));
292 sstr_t queue = cfg_directivelist_get_str(
293 obj->directives,
294 sstr("QueueSize"));
295 // TODO: Type
296
297 if(name.length == 0) {
298 // TODO: log error
299 return 1;
300 }
301
302 if(min.length != 0) {
303 min = sstrdup(min);
304 poolcfg.min_threads = atoi(min.ptr);
305 free(min.ptr);
306 }
307
308 if(max.length != 0) {
309 max = sstrdup(max);
310 poolcfg.max_threads = atoi(max.ptr);
311 free(max.ptr);
312 }
313
314 if(stack.length != 0) {
315 stack = sstrdup(stack);
316 poolcfg.stack_size = atoi(stack.ptr);
317 free(stack.ptr);
318 }
319
320 if(queue.length != 0) {
321 queue = sstrdup(queue);
322 poolcfg.queue_size = atoi(queue.ptr);
323 free(queue.ptr);
324 }
325
326 create_threadpool(name, &poolcfg);
327 }
328
274 int cfg_handle_eventhandler(ServerConfiguration *c, ServerConfigObject *obj) { 329 int cfg_handle_eventhandler(ServerConfiguration *c, ServerConfigObject *obj) {
275 EventHandlerConfig evcfg; 330 EventHandlerConfig evcfg;
276 331
277 sstr_t name = cfg_directivelist_get_str(obj->directives, sstr("Name")); 332 sstr_t name = cfg_directivelist_get_str(obj->directives, sstr("Name"));
278 sstr_t threads = cfg_directivelist_get_str( 333 sstr_t threads = cfg_directivelist_get_str(
315 obj->directives, 370 obj->directives,
316 sstr("Port")).ptr); 371 sstr("Port")).ptr);
317 lc.vs = sstrdup(cfg_directivelist_get_str( 372 lc.vs = sstrdup(cfg_directivelist_get_str(
318 obj->directives, 373 obj->directives,
319 sstr("DefaultVS"))); 374 sstr("DefaultVS")));
320 375 lc.threadpool = sstrdup(cfg_directivelist_get_str(
321 376 obj->directives,
377 sstr("Threadpool")));
378
379 // TODO: check if all important configs are set
380
322 HttpListener *listener = http_listener_create(&lc); 381 HttpListener *listener = http_listener_create(&lc);
323 listener->default_vs.vs_name = lc.vs.ptr; 382 listener->default_vs.vs_name = lc.vs.ptr;
324 cfg->listeners = ucx_list_append(cfg->listeners, listener); 383 cfg->listeners = ucx_list_append(cfg->listeners, listener);
325 384
326 return 0; 385 return 0;
327 } 386 }
328 387
329 int cfg_handle_vs(ServerConfiguration *cfg, ServerConfigObject *obj) { 388 int cfg_handle_vs(ServerConfiguration *cfg, ServerConfigObject *obj) {
330 VirtualServer *vs = vs_new(); 389 VirtualServer *vs = vs_new();

mercurial