15 |
#include "tw_module.h" |
#include "tw_module.h" |
16 |
#include "tw_version.h" |
#include "tw_version.h" |
17 |
|
|
18 |
|
#ifdef __amiga__ |
19 |
|
#include <pthread.h> |
20 |
|
#endif |
21 |
|
|
22 |
#if !defined(_MSC_VER) && !defined(__BORLANDC__) |
#if !defined(_MSC_VER) && !defined(__BORLANDC__) |
23 |
#include <unistd.h> |
#include <unistd.h> |
24 |
#endif |
#endif |
111 |
#endif |
#endif |
112 |
#endif |
#endif |
113 |
|
|
114 |
#if defined(_PSP) || defined(__ps2sdk__) || defined(__bsdi__) |
#if defined(_PSP) || defined(__ps2sdk__) || defined(__bsdi__) || defined(__amiga__) |
115 |
#include "strptime.h" |
#include "strptime.h" |
116 |
#endif |
#endif |
117 |
|
|
347 |
incr = 0; |
incr = 0; |
348 |
while(1) { |
while(1) { |
349 |
if(f != NULL) { |
if(f != NULL) { |
350 |
char buffer[128]; |
char buffer[512]; |
351 |
fread(buffer, size < 128 ? size : 128, 1, f); |
int st; |
352 |
tw_write(ssl, sock, buffer, size < 128 ? size : 128); |
fread(buffer, size < 512 ? size : 512, 1, f); |
353 |
|
if((st = tw_write(ssl, sock, buffer, size < 512 ? size : 512)) <= 0) break; |
354 |
} else { |
} else { |
355 |
tw_write(ssl, sock, (unsigned char*)doc + incr, size < 128 ? size : 128); |
if(tw_write(ssl, sock, (unsigned char*)doc + incr, size < 512 ? size : 512) <= 0) break; |
356 |
} |
} |
357 |
incr += 128; |
incr += 512; |
358 |
if(size <= 128) break; |
if(size <= 512) break; |
359 |
size -= 128; |
size -= 512; |
360 |
} |
} |
361 |
} |
} |
362 |
|
|
519 |
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__) |
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__) |
520 |
#define NO_RETURN_THREAD |
#define NO_RETURN_THREAD |
521 |
void tw_server_pass(void* ptr) { |
void tw_server_pass(void* ptr) { |
522 |
|
#elif defined(__amiga__) |
523 |
|
void* tw_server_pass(void* ptr) { |
524 |
#elif defined(__HAIKU__) |
#elif defined(__HAIKU__) |
525 |
int32_t tw_server_pass(void* ptr) { |
int32_t tw_server_pass(void* ptr) { |
526 |
#elif defined(_PSP) || defined(__PPU__) |
#elif defined(_PSP) || defined(__PPU__) |
527 |
int tw_server_pass(void* ptr) { |
int tw_server_pass(void* ptr) { |
528 |
#endif |
#endif |
529 |
#if defined(__HAIKU__) || defined(__MINGW32__) || defined(_PSP) || defined(__PPU__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__) |
#if defined(__HAIKU__) || defined(__MINGW32__) || defined(_PSP) || defined(__PPU__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__amiga__) |
530 |
#define FREE_PTR |
#define FREE_PTR |
531 |
int sock = ((struct pass_entry*)ptr)->sock; |
int sock = ((struct pass_entry*)ptr)->sock; |
532 |
bool ssl = ((struct pass_entry*)ptr)->ssl; |
bool ssl = ((struct pass_entry*)ptr)->ssl; |
627 |
time_t t; |
time_t t; |
628 |
struct tm* btm; |
struct tm* btm; |
629 |
strptime(req.headers[i + 1], "%a, %d %b %Y %H:%M:%S GMT", &tm); |
strptime(req.headers[i + 1], "%a, %d %b %Y %H:%M:%S GMT", &tm); |
630 |
#if defined(__MINGW32__) || defined(_PSP) || defined(__PPU__) || defined(__ps2sdk__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__USLC__) || defined(__NeXT__) || defined(__bsdi__) |
#if defined(__MINGW32__) || defined(_PSP) || defined(__PPU__) || defined(__ps2sdk__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__USLC__) || defined(__NeXT__) || defined(__bsdi__) || defined(__amiga__) |
631 |
t = 0; |
t = 0; |
632 |
btm = localtime(&t); |
btm = localtime(&t); |
633 |
cmtime = mktime(&tm); |
cmtime = mktime(&tm); |
647 |
host[i] = 0; |
host[i] = 0; |
648 |
port = atoi(host + i + 1); |
port = atoi(host + i + 1); |
649 |
break; |
break; |
650 |
|
}else if(vhost[i] == '['){ |
651 |
|
for(; vhost[i] != 0 && vhost[i] != ']'; i++); |
652 |
} |
} |
653 |
} |
} |
654 |
name = host; |
name = host; |
800 |
addstring(&str, " <tr>\n"); |
addstring(&str, " <tr>\n"); |
801 |
addstring(&str, " <th></th>\n"); |
addstring(&str, " <th></th>\n"); |
802 |
addstring(&str, " <th>Filename</th>\n"); |
addstring(&str, " <th>Filename</th>\n"); |
803 |
|
addstring(&str, " <th>Last-modified</th>\n"); |
804 |
addstring(&str, " <th>MIME</th>\n"); |
addstring(&str, " <th>MIME</th>\n"); |
805 |
addstring(&str, " <th>Size</th>\n"); |
addstring(&str, " <th>Size</th>\n"); |
806 |
addstring(&str, " </tr>\n"); |
addstring(&str, " </tr>\n"); |
818 |
char* fpth = cm_strcat3(path, "/", items[i]); |
char* fpth = cm_strcat3(path, "/", items[i]); |
819 |
struct stat s; |
struct stat s; |
820 |
char size[512]; |
char size[512]; |
821 |
|
char date[512]; |
822 |
char* showmime; |
char* showmime; |
823 |
char* mime; |
char* mime; |
824 |
|
struct tm* tm; |
825 |
size[0] = 0; |
size[0] = 0; |
826 |
stat(fpth, &s); |
stat(fpth, &s); |
827 |
|
tm = localtime(&s.st_mtime); |
828 |
|
strftime(date, 512, "%a, %d %b %Y %H:%M:%S %Z", tm); |
829 |
if(phase == 0 && !S_ISDIR(s.st_mode)) { |
if(phase == 0 && !S_ISDIR(s.st_mode)) { |
830 |
free(fpth); |
free(fpth); |
831 |
continue; |
continue; |
899 |
addstring(&str, "<tr>\n"); |
addstring(&str, "<tr>\n"); |
900 |
addstring(&str, " <td><img src=\"%s\" alt=\"icon\"></td>\n", icon); |
addstring(&str, " <td><img src=\"%s\" alt=\"icon\"></td>\n", icon); |
901 |
addstring(&str, " <td><a href=\"%l\"><code>%h</code></a></td>\n", items[i], itm); |
addstring(&str, " <td><a href=\"%l\"><code>%h</code></a></td>\n", items[i], itm); |
902 |
|
addstring(&str, " <td><code> %h </code></td>\n", date); |
903 |
addstring(&str, " <td><code> %h </code></td>\n", showmime); |
addstring(&str, " <td><code> %h </code></td>\n", showmime); |
904 |
addstring(&str, " <td><code> %s </code></td>\n", size); |
addstring(&str, " <td><code> %s </code></td>\n", size); |
905 |
addstring(&str, "</tr>\n"); |
addstring(&str, "</tr>\n"); |
1028 |
fd_set fdset; |
fd_set fdset; |
1029 |
struct timeval tv; |
struct timeval tv; |
1030 |
#endif |
#endif |
1031 |
#if defined(__MINGW32__) || defined(__HAIKU__) || defined(_MSC_VER) || defined(__BORLANDC__) || (defined(__WATCOMC__) && !defined(__NETWARE__)) |
#if defined(__MINGW32__) || defined(__HAIKU__) || defined(_MSC_VER) || defined(__BORLANDC__) || (defined(__WATCOMC__) && !defined(__NETWARE__) && !defined(__DOS__)) |
1032 |
struct thread_entry threads[2048]; |
struct thread_entry threads[128]; |
1033 |
for(i = 0; i < sizeof(threads) / sizeof(threads[0]); i++) { |
for(i = 0; i < sizeof(threads) / sizeof(threads[0]); i++) { |
1034 |
threads[i].used = false; |
threads[i].used = false; |
1035 |
} |
} |
1061 |
if(ret == -1) { |
if(ret == -1) { |
1062 |
#if !defined(__MINGW32__) && !defined(_MSC_VER) && !defined(__BORLANDC__) && !defined(__WATCOMC__) |
#if !defined(__MINGW32__) && !defined(_MSC_VER) && !defined(__BORLANDC__) && !defined(__WATCOMC__) |
1063 |
if(errno == EINTR) continue; |
if(errno == EINTR) continue; |
1064 |
cm_log("Server", "Select failure: %s", strerror(errno)); |
cm_log("Server", "Select/poll failure: %s", strerror(errno)); |
1065 |
#endif |
#endif |
1066 |
break; |
break; |
1067 |
} else if(ret == 0) { |
} else if(ret == 0) { |
1084 |
SOCKADDR claddr; |
SOCKADDR claddr; |
1085 |
socklen_t clen = sizeof(claddr); |
socklen_t clen = sizeof(claddr); |
1086 |
int sock = accept(sockets[i], (struct sockaddr*)&claddr, &clen); |
int sock = accept(sockets[i], (struct sockaddr*)&claddr, &clen); |
1087 |
#if defined(__MINGW32__) || defined(__HAIKU__) || defined(_PSP) || defined(__PPU__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__) |
#if defined(__MINGW32__) || defined(__HAIKU__) || defined(_PSP) || defined(__PPU__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__amiga__) |
1088 |
|
#ifdef __amiga__ |
1089 |
|
pthread_t thrt; |
1090 |
|
#endif |
1091 |
int j; |
int j; |
1092 |
struct pass_entry* e = malloc(sizeof(*e)); |
struct pass_entry* e = malloc(sizeof(*e)); |
1093 |
cm_log("Server", "New connection accepted"); |
cm_log("Server", "New connection accepted"); |
1112 |
#endif |
#endif |
1113 |
#elif defined(_PSP) || defined(__PPU__) |
#elif defined(_PSP) || defined(__PPU__) |
1114 |
tw_server_pass(e); |
tw_server_pass(e); |
1115 |
|
#elif defined(__amiga__) |
1116 |
|
pthread_create(&thrt, NULL, tw_server_pass, e); |
1117 |
#elif defined(__HAIKU__) |
#elif defined(__HAIKU__) |
1118 |
for(j = 0; j < sizeof(threads) / sizeof(threads[0]); j++) { |
for(j = 0; j < sizeof(threads) / sizeof(threads[0]); j++) { |
1119 |
if(threads[j].used) { |
if(threads[j].used) { |