diff -r 63d9051fe35c -r b122f34ddc80 src/server/daemon/config.c --- a/src/server/daemon/config.c Wed Oct 28 17:59:34 2015 +0100 +++ b/src/server/daemon/config.c Sat Oct 31 15:01:07 2015 +0100 @@ -53,6 +53,7 @@ #include "../util/pblock.h" #include "../util/util.h" #include "../util/atomic.h" +#include "ucx/buffer.h" pool_handle_t *cfg_pool; @@ -575,6 +576,29 @@ obj->directives, sstr("Threadpool"))); + sstr_t ssl = cfg_directivelist_get_str(obj->directives, S("SSL")); + if(util_getboolean_s(ssl, WS_FALSE)) { + sstr_t cert = cfg_directivelist_get_str(obj->directives, S("Cert")); + sstr_t privkey = cfg_directivelist_get_str(obj->directives, S("PrivateKey")); + sstr_t chain = cfg_directivelist_get_str(obj->directives, S("Chain")); + WSBool config_ok = WS_TRUE; + // TODO: log error + if(!cert.ptr) { + config_ok = WS_FALSE; + } + if(!privkey.ptr) { + config_ok = WS_FALSE; + } + if(config_ok) { + lc.certfile = cert; + lc.privkeyfile = privkey; + lc.chainfile = chain; + lc.ssl = WS_TRUE; + } + } else { + lc.ssl = WS_FALSE; + } + // TODO: check if all important configs are set HttpListener *listener = http_listener_create(&lc); @@ -955,3 +979,40 @@ return 0; } + + +sstr_t cfg_load_file(sstr_t file) { + sstr_t r; + r.ptr = NULL; + r.length = 0; + + if(!file.ptr) { + return r; + } + + sstr_t f = sstrdup(file); + FILE *in = fopen(f.ptr, "r"); + if(!in) { + return r; + } + + UcxBuffer *buf = ucx_buffer_new(NULL, 4096, UCX_BUFFER_AUTOEXTEND); + if(!buf) { + fclose(in); + return r; + } + + if(ucx_stream_hcopy(in, buf, (read_func)fread, (write_func)ucx_buffer_write) == 0) { + fclose(in); + ucx_buffer_free(buf); + return r; + } + + r.ptr = buf->space; + r.length = buf->pos; + + free(buf); + fclose(in); + + return r; +}