src/server/daemon/config.c

changeset 106
b122f34ddc80
parent 99
b9a6af0ae41a
child 115
51d9a15eac98
equal deleted inserted replaced
105:63d9051fe35c 106:b122f34ddc80
51 51
52 #include "vserver.h" 52 #include "vserver.h"
53 #include "../util/pblock.h" 53 #include "../util/pblock.h"
54 #include "../util/util.h" 54 #include "../util/util.h"
55 #include "../util/atomic.h" 55 #include "../util/atomic.h"
56 #include "ucx/buffer.h"
56 57
57 pool_handle_t *cfg_pool; 58 pool_handle_t *cfg_pool;
58 59
59 // TODO: Funktion für ConfigDirective -> directive 60 // TODO: Funktion für ConfigDirective -> directive
60 // TODO: Funktion für UcxList parameter list -> pblock 61 // TODO: Funktion für UcxList parameter list -> pblock
573 sstr("DefaultVS"))); 574 sstr("DefaultVS")));
574 lc.threadpool = sstrdup(cfg_directivelist_get_str( 575 lc.threadpool = sstrdup(cfg_directivelist_get_str(
575 obj->directives, 576 obj->directives,
576 sstr("Threadpool"))); 577 sstr("Threadpool")));
577 578
579 sstr_t ssl = cfg_directivelist_get_str(obj->directives, S("SSL"));
580 if(util_getboolean_s(ssl, WS_FALSE)) {
581 sstr_t cert = cfg_directivelist_get_str(obj->directives, S("Cert"));
582 sstr_t privkey = cfg_directivelist_get_str(obj->directives, S("PrivateKey"));
583 sstr_t chain = cfg_directivelist_get_str(obj->directives, S("Chain"));
584 WSBool config_ok = WS_TRUE;
585 // TODO: log error
586 if(!cert.ptr) {
587 config_ok = WS_FALSE;
588 }
589 if(!privkey.ptr) {
590 config_ok = WS_FALSE;
591 }
592 if(config_ok) {
593 lc.certfile = cert;
594 lc.privkeyfile = privkey;
595 lc.chainfile = chain;
596 lc.ssl = WS_TRUE;
597 }
598 } else {
599 lc.ssl = WS_FALSE;
600 }
601
578 // TODO: check if all important configs are set 602 // TODO: check if all important configs are set
579 603
580 HttpListener *listener = http_listener_create(&lc); 604 HttpListener *listener = http_listener_create(&lc);
581 listener->default_vs.vs_name = lc.vs.ptr; 605 listener->default_vs.vs_name = lc.vs.ptr;
582 cfg->listeners = ucx_list_append(cfg->listeners, listener); 606 cfg->listeners = ucx_list_append(cfg->listeners, listener);
953 keyfile_unref(old_data); 977 keyfile_unref(old_data);
954 } 978 }
955 979
956 return 0; 980 return 0;
957 } 981 }
982
983
984 sstr_t cfg_load_file(sstr_t file) {
985 sstr_t r;
986 r.ptr = NULL;
987 r.length = 0;
988
989 if(!file.ptr) {
990 return r;
991 }
992
993 sstr_t f = sstrdup(file);
994 FILE *in = fopen(f.ptr, "r");
995 if(!in) {
996 return r;
997 }
998
999 UcxBuffer *buf = ucx_buffer_new(NULL, 4096, UCX_BUFFER_AUTOEXTEND);
1000 if(!buf) {
1001 fclose(in);
1002 return r;
1003 }
1004
1005 if(ucx_stream_hcopy(in, buf, (read_func)fread, (write_func)ucx_buffer_write) == 0) {
1006 fclose(in);
1007 ucx_buffer_free(buf);
1008 return r;
1009 }
1010
1011 r.ptr = buf->space;
1012 r.length = buf->pos;
1013
1014 free(buf);
1015 fclose(in);
1016
1017 return r;
1018 }

mercurial