]> Nishi Git Mirror - tewi.git/commitdiff
can show readme on index now
authorNishi <nishi@nishi.boats>
Mon, 16 Sep 2024 12:52:47 +0000 (12:52 +0000)
committerNishi <nishi@nishi.boats>
Mon, 16 Sep 2024 12:52:47 +0000 (12:52 +0000)
git-svn-id: file:///raid/svn-personal/tewi/trunk@33 8739d7e6-ffea-ec47-b151-bdff447c6205

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

index a87b1debea11bf4534801f9e8793ed2e021dcaa9..95592fd6baf259e58bd5be946384a0c7d61a46c5 100644 (file)
@@ -83,6 +83,7 @@ void tw_config_init(void) {
        config.root.dir_count = 0;
        config.root.icon_count = 0;
        config.root.index_count = 0;
+       config.root.readme_count = 0;
        config.vhost_count = 0;
        config.module_count = 0;
        config.extension = NULL;
@@ -183,6 +184,7 @@ int tw_config_read(const char* path) {
                                                                current->mime_count = 0;
                                                                current->icon_count = 0;
                                                                current->index_count = 0;
+                                                               current->readme_count = 0;
                                                                int i;
                                                                current->name = cm_strdup(vhost);
                                                                current->port = -1;
@@ -288,6 +290,10 @@ int tw_config_read(const char* path) {
                                                for(i = 1; r[i] != NULL; i++) {
                                                        current->indexes[current->index_count++] = cm_strdup(r[i]);
                                                }
+                                       } else if(cm_strcaseequ(r[0], "Readme")) {
+                                               for(i = 1; r[i] != NULL; i++) {
+                                                       current->readmes[current->readme_count++] = cm_strdup(r[i]);
+                                               }
                                        } else {
                                                if(r[0] != NULL) {
                                                        cm_log("Config", "Unknown directive `%s' at line %d", r[0], ln);
index 2ae66d78081360a0dfc8da1ecb3b7e86a99083c6..ed6ee5b3915c4d21141c1707514416e9c671aed9 100644 (file)
@@ -512,10 +512,14 @@ void tw_server_pass(int sock, bool ssl, int port, SOCKADDR addr) {
                                                        addstring(&str, "                               <th>MIME</th>\n");
                                                        addstring(&str, "                               <th>Size</th>\n");
                                                        addstring(&str, "                       </tr>\n");
+                                                       int readme = -1;
+                                                       char** readmes = vhost_entry->readme_count == 0 ? config.root.readmes : vhost_entry->readmes;
+                                                       int readme_count = vhost_entry->readme_count == 0 ? config.root.readme_count : vhost_entry->readme_count;
                                                        if(items != NULL) {
                                                                int phase = 0;
                                                        doit:
                                                                for(i = 0; items[i] != NULL; i++) {
+                                                                       int j;
                                                                        char* fpth = cm_strcat3(path, "/", items[i]);
                                                                        struct stat s;
                                                                        char size[512];
@@ -528,6 +532,18 @@ void tw_server_pass(int sock, bool ssl, int port, SOCKADDR addr) {
                                                                                free(fpth);
                                                                                continue;
                                                                        }
+                                                                       if(readme == -1) {
+                                                                               for(j = 0; j < readme_count; j++) {
+                                                                                       if(strcmp(items[i], readmes[j]) == 0) {
+                                                                                               readme = j;
+                                                                                               break;
+                                                                                       }
+                                                                               }
+                                                                               if(readme != -1) {
+                                                                                       free(fpth);
+                                                                                       continue;
+                                                                               }
+                                                                       }
                                                                        if(s.st_size < 1024ULL) {
                                                                                sprintf(size, "%d", (int)s.st_size);
                                                                        } else if(s.st_size < 1024ULL * 1024) {
@@ -543,7 +559,6 @@ void tw_server_pass(int sock, bool ssl, int port, SOCKADDR addr) {
                                                                        free(fpth);
 
                                                                        char* ext = NULL;
-                                                                       int j;
                                                                        for(j = strlen(items[i]) - 1; j >= 0; j--) {
                                                                                if(items[i][j] == '.') {
                                                                                        ext = cm_strdup(items[i] + j);
@@ -594,6 +609,20 @@ void tw_server_pass(int sock, bool ssl, int port, SOCKADDR addr) {
                                                                free(items);
                                                        }
                                                        addstring(&str, "               </table>\n");
+                                                       if(readme != -1) {
+                                                               addstring(&str, "<hr>\n");
+                                                               char* fpth = cm_strcat3(path, "/", readmes[readme]);
+                                                               struct stat s;
+                                                               stat(fpth, &s);
+                                                               FILE* fr = fopen(fpth, "r");
+                                                               if(fr != NULL) {
+                                                                       char* rmbuf = malloc(s.st_size + 1);
+                                                                       rmbuf[s.st_size] = 0;
+                                                                       fread(rmbuf, s.st_size, 1, fr);
+                                                                       addstring(&str, "<pre><code>%h</code></pre>\n", rmbuf);
+                                                                       fclose(fr);
+                                                               }
+                                                       }
                                                        addstring(&str, "               <hr>\n");
                                                        addstring(&str, "               <address>%s Server at %s Port %d</address>\n", tw_server, name, port);
                                                        addstring(&str, "       </body>\n");
index 98bf244b715f53c1e89d414b123d3ee6e54a85a4..4975d0ef1dcdb0f258fefde0a8a56fd7826dc82b 100644 (file)
@@ -28,6 +28,7 @@
 #define MAX_MIME 1024
 #define MAX_ICON 1024
 #define MAX_INDEX 1024
+#define MAX_README 8
 
 enum TW_DIR_TYPE {
        TW_DIR_ALLOW = 0,
@@ -64,6 +65,8 @@ struct tw_config_entry {
        int icon_count;
        char* indexes[MAX_INDEX];
        int index_count;
+       char* readmes[MAX_README];
+       int readme_count;
 };
 
 struct tw_config {
index b68d0012d7ed91576d36945bac6948f631a5872c..8c753e8f5a6c43895dc41ef3cbdff84399247a1c 100644 (file)
@@ -4,7 +4,7 @@
 
 #include "tw_version.h"
 
-const char* tw_version = "0.00";
+const char* tw_version = "1.00";
 
 const char* tw_platform =
 #if defined(PLATFORM)
index 1a19160b89c94b89f307dc07631d073f9a2e1fcd..e64da91e13a47062c377d0c6b9b02f2be89c015e 100644 (file)
@@ -3,8 +3,8 @@
 
 #LoadModule /home/nishi/SVN/tewi/trunk/Module/mod_example.so
 
-Listen 8080
-#ListenSSL 443
+Listen 80
+ListenSSL 443
 
 SSLKey key.pem
 SSLCertificate cert.pem
@@ -22,6 +22,8 @@ Icon misc/parent /icons/parent.png
 
 DirectoryIndex index.html
 
+Readme README
+
 DocumentRoot /var/www
 
 BeginDirectory /