From: Nishi Date: Sat, 14 Sep 2024 00:51:41 +0000 (+0000) Subject: add fallback option X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=fb2de8c01fad08d773ead99af28c5e5657b081be;p=tewi.git add fallback option git-svn-id: file:///raid/svn-personal/tewi/trunk@19 8739d7e6-ffea-ec47-b151-bdff447c6205 --- diff --git a/Server/config.c b/Server/config.c index 5f5f78f..1b21d73 100644 --- a/Server/config.c +++ b/Server/config.c @@ -34,9 +34,11 @@ void tw_config_init(void) { for(i = 0; i < MAX_VHOSTS; i++) { config.vhosts[i].sslkey = NULL; config.vhosts[i].sslcert = NULL; + config.vhosts[i].root = NULL; } config.root.sslkey = NULL; config.root.sslcert = NULL; + config.root.root = NULL; config.vhost_count = 0; config.module_count = 0; config.extension = NULL; @@ -129,6 +131,14 @@ int tw_config_read(const char* path) { if(current->sslcert != NULL) free(current->sslcert); current->sslcert = cm_strdup(r[1]); } + } else if(cm_strcaseequ(r[0], "DocumentRoot")) { + if(r[1] == NULL) { + cm_log("Config", "Missing path at line %d", ln); + stop = 1; + } else { + if(current->root != NULL) free(current->root); + current->root = cm_strdup(r[1]); + } } else if(cm_strcaseequ(r[0], "ServerRoot")) { if(r[1] == NULL) { cm_log("Config", "Missing path at line %d", ln); diff --git a/Server/server.c b/Server/server.c index 9ce3542..199fe05 100644 --- a/Server/server.c +++ b/Server/server.c @@ -215,8 +215,8 @@ void tw_process_page(SSL* ssl, int sock, const char* status, const char* type, c while(1) { tw_write(ssl, sock, (unsigned char*)doc + incr, size < 128 ? size : 128); incr += 128; + if(size <= 128) break; size -= 128; - if(size <= 0) break; } } diff --git a/Server/ssl.c b/Server/ssl.c index db4e001..5f4abcf 100644 --- a/Server/ssl.c +++ b/Server/ssl.c @@ -25,6 +25,9 @@ int tw_ssl_cert_cb(SSL* ssl, void* arg) { SSL_use_PrivateKey_file(ssl, e->sslkey, SSL_FILETYPE_PEM); SSL_use_certificate_file(ssl, e->sslcert, SSL_FILETYPE_PEM); return 1; + } else if(config.root.sslkey != NULL && config.root.sslcert != NULL) { + SSL_use_PrivateKey_file(ssl, config.root.sslkey, SSL_FILETYPE_PEM); + SSL_use_certificate_file(ssl, config.root.sslcert, SSL_FILETYPE_PEM); } else { return 0; } diff --git a/Server/tw_config.h b/Server/tw_config.h index 86957b3..9a17e86 100644 --- a/Server/tw_config.h +++ b/Server/tw_config.h @@ -14,6 +14,7 @@ struct tw_config_entry { int port; char* sslkey; char* sslcert; + char* root; }; struct tw_config { diff --git a/example.conf b/example.conf index 351fcf9..7f9b2cc 100644 --- a/example.conf +++ b/example.conf @@ -9,5 +9,7 @@ ListenSSL 8443 8444 8445 8446 8447 SSLKey key.pem SSLCertificate cert.pem +DocumentRoot /var/www + BeginVirtualHost nishinbsd-ssd EndVirtualHost