]> Nishi Git Mirror - tewi.git/commitdiff
add fallback option
authorNishi <nishi@nishi.boats>
Sat, 14 Sep 2024 00:51:41 +0000 (00:51 +0000)
committerNishi <nishi@nishi.boats>
Sat, 14 Sep 2024 00:51:41 +0000 (00:51 +0000)
git-svn-id: file:///raid/svn-personal/tewi/trunk@19 8739d7e6-ffea-ec47-b151-bdff447c6205

Server/config.c
Server/server.c
Server/ssl.c
Server/tw_config.h
example.conf

index 5f5f78f8734c6fe1c76db361f6e83ef0d7073d6e..1b21d737eaa9b6a4e145611915f0cbb8f260a776 100644 (file)
@@ -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);
index 9ce354290c204047dda1af91d552450162cfce8c..199fe052c41c1edded116d24ab7b32a805d45f83 100644 (file)
@@ -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;
        }
 }
 
index db4e0019f6844d5f4e2bc410a1488fb43393b693..5f4abcf9fcdd7b891eb4ac0295057edd9c7b61ef 100644 (file)
@@ -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;
        }
index 86957b344c7d3df7527fabacc350bd75a144d670..9a17e86926f4e6ab2a1713a54bb418f070d5b015 100644 (file)
@@ -14,6 +14,7 @@ struct tw_config_entry {
        int port;
        char* sslkey;
        char* sslcert;
+       char* root;
 };
 
 struct tw_config {
index 351fcf92d44c70fed1ee286d06c3eb21682f7e36..7f9b2ccf3234f72c78db781ff2f55b736e45f4c0 100644 (file)
@@ -9,5 +9,7 @@ ListenSSL 8443 8444 8445 8446 8447
 SSLKey key.pem
 SSLCertificate cert.pem
 
+DocumentRoot /var/www
+
 BeginVirtualHost nishinbsd-ssd
 EndVirtualHost