]> Git repositories of Nishi - tewi.git/commitdiff
icon works
authorNishi <nishi@nishi.boats>
Sat, 14 Sep 2024 13:31:16 +0000 (13:31 +0000)
committerNishi <nishi@nishi.boats>
Sat, 14 Sep 2024 13:31:16 +0000 (13:31 +0000)
git-svn-id: file:///raid/svn-personal/tewi/trunk@23 8739d7e6-ffea-ec47-b151-bdff447c6205

Server/http.c
Server/server.c
example.conf

index 6528d79841e0736f2cc565c8240a2d332419c4b2..aa39a219be91ad2bb4e4e683e167ddaf24017606 100644 (file)
@@ -59,7 +59,7 @@ int tw_http_parse(SSL* ssl, int sock, struct tw_http_request* req) {
                struct timeval tv;
                tv.tv_sec = 5;
                tv.tv_usec = 0;
-               if(!SSL_has_pending(ssl)) {
+               if(ssl == NULL || !SSL_has_pending(ssl)) {
                        int n = select(FD_SETSIZE, &fds, NULL, NULL, &tv);
                        if(n <= 0) {
                                free(header);
index 7d3755c019646325a10accdbf8c2d4af3dfca1a3..53b16173a550c6d1e118f10d9f7256f6b3d07180 100644 (file)
@@ -40,6 +40,28 @@ int sockcount = 0;
 SOCKADDR addresses[MAX_PORTS];
 int sockets[MAX_PORTS];
 
+/* https://qiita.com/gyu-don/items/5a640c6d2252a860c8cd */
+int tw_wildcard_match(const char* wildcard, const char* target) {
+       const char *pw = wildcard, *pt = target;
+
+       while(1) {
+               if(*pt == 0) {
+                       while(*pw == '*') pw++;
+                       return *pw == 0;
+               } else if(*pw == 0) {
+                       return 0;
+               } else if(*pw == '*') {
+                       return *(pw + 1) == 0 || tw_wildcard_match(pw, pt + 1) || tw_wildcard_match(pw + 1, pt);
+               } else if(*pw == '?' || (*pw == *pt)) {
+                       pw++;
+                       pt++;
+                       continue;
+               } else {
+                       return 0;
+               }
+       }
+}
+
 void close_socket(int sock) {
 #ifdef __MINGW32__
        closesocket(sock);
@@ -274,14 +296,14 @@ char* tw_get_mime(const char* ext, struct tw_config_entry* vhost_entry) {
        bool set = false;
        int i;
        for(i = 0; i < vhost_entry->mime_count; i++) {
-               if(strcmp(vhost_entry->mimes[i].ext, "all") == 0 || (ext != NULL && strcmp(vhost_entry->mimes[i].ext, ext) == 0)) {
+               if(strcmp(vhost_entry->mimes[i].ext, "all") == 0 || (ext != NULL && tw_wildcard_match(vhost_entry->mimes[i].ext, ext))) {
                        mime = vhost_entry->mimes[i].mime;
                        set = true;
                }
        }
        if(!set) {
                for(i = 0; i < config.root.mime_count; i++) {
-                       if(strcmp(config.root.mimes[i].ext, "all") == 0 || (ext != NULL && strcmp(config.root.mimes[i].ext, ext) == 0)) {
+                       if(strcmp(config.root.mimes[i].ext, "all") == 0 || (ext != NULL && tw_wildcard_match(config.root.mimes[i].ext, ext))) {
                                mime = config.root.mimes[i].mime;
                        }
                }
@@ -295,14 +317,14 @@ char* tw_get_icon(const char* mime, struct tw_config_entry* vhost_entry) {
        bool set = false;
        int i;
        for(i = 0; i < vhost_entry->icon_count; i++) {
-               if(strcmp(vhost_entry->icons[i].mime, "all") == 0 || (mime != NULL && strcmp(vhost_entry->icons[i].mime, mime) == 0)) {
+               if(strcmp(vhost_entry->icons[i].mime, "all") == 0 || (mime != NULL && tw_wildcard_match(vhost_entry->icons[i].mime, mime))) {
                        icon = vhost_entry->icons[i].icon;
                        set = true;
                }
        }
        if(!set) {
                for(i = 0; i < config.root.icon_count; i++) {
-                       if(strcmp(config.root.icons[i].mime, "all") == 0 || (mime != NULL && strcmp(config.root.icons[i].mime, mime) == 0)) {
+                       if(strcmp(config.root.icons[i].mime, "all") == 0 || (mime != NULL && tw_wildcard_match(config.root.icons[i].mime, mime))) {
                                icon = config.root.icons[i].icon;
                        }
                }
index 0d11fd1a24f8b033cd838b42d56166eda9f8651a..dabc79a8e389c46c87cda6481c4a554031ea766f 100644 (file)
@@ -3,8 +3,8 @@
 
 #LoadModule /home/nishi/SVN/tewi/trunk/Module/mod_example.so
 
-Listen 8000 8001 8002 8003 8004
-ListenSSL 8443 8444 8445 8446 8447
+Listen 80
+ListenSSL 443
 
 SSLKey key.pem
 SSLCertificate cert.pem
@@ -15,7 +15,7 @@ MIMEType .txt text/plain
 MIMEType .png image/png
 
 Icon all /icons/unknown.png
-Icon text/plain /icons/text.png
+Icon text/* /icons/text.png
 Icon misc/dir /icons/folder.png
 Icon misc/parent /icons/parent.png
 
@@ -24,6 +24,3 @@ DocumentRoot /var/www
 BeginDirectory /
        Allow all
 EndDirectory
-
-BeginVirtualHost nishinbsd-ssd
-EndVirtualHost