From faeeedcae8529a2f0132c25cf14feba5572afd84 Mon Sep 17 00:00:00 2001 From: Nishi Date: Sat, 14 Sep 2024 13:31:16 +0000 Subject: [PATCH] icon works git-svn-id: file:///raid/svn-personal/tewi/trunk@23 8739d7e6-ffea-ec47-b151-bdff447c6205 --- Server/http.c | 2 +- Server/server.c | 30 ++++++++++++++++++++++++++---- example.conf | 9 +++------ 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/Server/http.c b/Server/http.c index 6528d79..aa39a21 100644 --- a/Server/http.c +++ b/Server/http.c @@ -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); diff --git a/Server/server.c b/Server/server.c index 7d3755c..53b1617 100644 --- a/Server/server.c +++ b/Server/server.c @@ -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; } } diff --git a/example.conf b/example.conf index 0d11fd1..dabc79a 100644 --- a/example.conf +++ b/example.conf @@ -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 -- 2.43.0