Subversion Repositories Tewi

Rev

Rev 401 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 401 Rev 402
Line 1... Line 1...
1
/* $Id: server.c 401 2024-11-03 06:16:35Z nishi $ */
1
/* $Id: server.c 402 2024-11-03 10:39:59Z nishi $ */
2
 
2
 
3
#define SOURCE
3
#define SOURCE
4
 
4
 
5
#include "../config.h"
5
#include "../config.h"
6
 
6
 
Line 13... Line 13...
13
#include "tw_config.h"
13
#include "tw_config.h"
14
#include "tw_http.h"
14
#include "tw_http.h"
15
#include "tw_module.h"
15
#include "tw_module.h"
16
#include "tw_version.h"
16
#include "tw_version.h"
17
 
17
 
-
 
18
#ifdef __amiga__
-
 
19
#include <pthread.h>
-
 
20
#endif
-
 
21
 
18
#if !defined(_MSC_VER) && !defined(__BORLANDC__)
22
#if !defined(_MSC_VER) && !defined(__BORLANDC__)
19
#include <unistd.h>
23
#include <unistd.h>
20
#endif
24
#endif
21
#include <ctype.h>
25
#include <ctype.h>
22
#include <string.h>
26
#include <string.h>
Line 105... Line 109...
105
#ifndef NO_GETNAMEINFO
109
#ifndef NO_GETNAMEINFO
106
#include <netdb.h>
110
#include <netdb.h>
107
#endif
111
#endif
108
#endif
112
#endif
109
 
113
 
110
#if defined(_PSP) || defined(__ps2sdk__) || defined(__bsdi__)
114
#if defined(_PSP) || defined(__ps2sdk__) || defined(__bsdi__) || defined(__amiga__)
111
#include "strptime.h"
115
#include "strptime.h"
112
#endif
116
#endif
113
 
117
 
114
#ifdef __HAIKU__
118
#ifdef __HAIKU__
115
#include <OS.h>
119
#include <OS.h>
Line 513... Line 517...
513
};
517
};
514
 
518
 
515
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__)
519
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__)
516
#define NO_RETURN_THREAD
520
#define NO_RETURN_THREAD
517
void tw_server_pass(void* ptr) {
521
void tw_server_pass(void* ptr) {
-
 
522
#elif defined(__amiga__)
-
 
523
void* tw_server_pass(void* ptr) {
518
#elif defined(__HAIKU__)
524
#elif defined(__HAIKU__)
519
int32_t tw_server_pass(void* ptr) {
525
int32_t tw_server_pass(void* ptr) {
520
#elif defined(_PSP) || defined(__PPU__)
526
#elif defined(_PSP) || defined(__PPU__)
521
int tw_server_pass(void* ptr) {
527
int tw_server_pass(void* ptr) {
522
#endif
528
#endif
523
#if defined(__HAIKU__) || defined(__MINGW32__) || defined(_PSP) || defined(__PPU__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__)
529
#if defined(__HAIKU__) || defined(__MINGW32__) || defined(_PSP) || defined(__PPU__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__amiga__)
524
#define FREE_PTR
530
#define FREE_PTR
525
	int sock = ((struct pass_entry*)ptr)->sock;
531
	int sock = ((struct pass_entry*)ptr)->sock;
526
	bool ssl = ((struct pass_entry*)ptr)->ssl;
532
	bool ssl = ((struct pass_entry*)ptr)->ssl;
527
	int port = ((struct pass_entry*)ptr)->port;
533
	int port = ((struct pass_entry*)ptr)->port;
528
	SOCKADDR addr = ((struct pass_entry*)ptr)->addr;
534
	SOCKADDR addr = ((struct pass_entry*)ptr)->addr;
Line 619... Line 625...
619
				} else if(cm_strcaseequ(req.headers[i], "If-Modified-Since")) {
625
				} else if(cm_strcaseequ(req.headers[i], "If-Modified-Since")) {
620
					struct tm tm;
626
					struct tm tm;
621
					time_t t;
627
					time_t t;
622
					struct tm* btm;
628
					struct tm* btm;
623
					strptime(req.headers[i + 1], "%a, %d %b %Y %H:%M:%S GMT", &tm);
629
					strptime(req.headers[i + 1], "%a, %d %b %Y %H:%M:%S GMT", &tm);
624
#if defined(__MINGW32__) || defined(_PSP) || defined(__PPU__) || defined(__ps2sdk__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__USLC__) || defined(__NeXT__) || defined(__bsdi__)
630
#if defined(__MINGW32__) || defined(_PSP) || defined(__PPU__) || defined(__ps2sdk__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__USLC__) || defined(__NeXT__) || defined(__bsdi__) || defined(__amiga__)
625
					t = 0;
631
					t = 0;
626
					btm = localtime(&t);
632
					btm = localtime(&t);
627
					cmtime = mktime(&tm);
633
					cmtime = mktime(&tm);
628
					cmtime -= (btm->tm_hour * 60 + btm->tm_min) * 60;
634
					cmtime -= (btm->tm_hour * 60 + btm->tm_min) * 60;
629
#else
635
#else
Line 1053... Line 1059...
1053
#endif
1059
#endif
1054
#endif
1060
#endif
1055
		if(ret == -1) {
1061
		if(ret == -1) {
1056
#if !defined(__MINGW32__) && !defined(_MSC_VER) && !defined(__BORLANDC__) && !defined(__WATCOMC__)
1062
#if !defined(__MINGW32__) && !defined(_MSC_VER) && !defined(__BORLANDC__) && !defined(__WATCOMC__)
1057
			if(errno == EINTR) continue;
1063
			if(errno == EINTR) continue;
1058
			cm_log("Server", "Select failure: %s", strerror(errno));
1064
			cm_log("Server", "Select/poll failure: %s", strerror(errno));
1059
#endif
1065
#endif
1060
			break;
1066
			break;
1061
		} else if(ret == 0) {
1067
		} else if(ret == 0) {
1062
#ifdef SERVICE
1068
#ifdef SERVICE
1063
			if(status.dwCurrentState == SERVICE_STOP_PENDING) {
1069
			if(status.dwCurrentState == SERVICE_STOP_PENDING) {
Line 1076... Line 1082...
1076
#endif
1082
#endif
1077
				if(cond) {
1083
				if(cond) {
1078
					SOCKADDR claddr;
1084
					SOCKADDR claddr;
1079
					socklen_t clen = sizeof(claddr);
1085
					socklen_t clen = sizeof(claddr);
1080
					int sock = accept(sockets[i], (struct sockaddr*)&claddr, &clen);
1086
					int sock = accept(sockets[i], (struct sockaddr*)&claddr, &clen);
1081
#if defined(__MINGW32__) || defined(__HAIKU__) || defined(_PSP) || defined(__PPU__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__)
1087
#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
1082
					int j;
1091
					int j;
1083
					struct pass_entry* e = malloc(sizeof(*e));
1092
					struct pass_entry* e = malloc(sizeof(*e));
1084
					cm_log("Server", "New connection accepted");
1093
					cm_log("Server", "New connection accepted");
1085
					e->sock = sock;
1094
					e->sock = sock;
1086
#if defined(_MSC_VER) || defined(__BORLANDC__)
1095
#if defined(_MSC_VER) || defined(__BORLANDC__)
Line 1101... Line 1110...
1101
#else
1110
#else
1102
					_beginthread(tw_server_pass, 0, e);
1111
					_beginthread(tw_server_pass, 0, e);
1103
#endif
1112
#endif
1104
#elif defined(_PSP) || defined(__PPU__)
1113
#elif defined(_PSP) || defined(__PPU__)
1105
						tw_server_pass(e);
1114
						tw_server_pass(e);
-
 
1115
#elif defined(__amiga__)
-
 
1116
					pthread_create(&thrt, NULL, tw_server_pass, e);
1106
#elif defined(__HAIKU__)
1117
#elif defined(__HAIKU__)
1107
					for(j = 0; j < sizeof(threads) / sizeof(threads[0]); j++) {
1118
					for(j = 0; j < sizeof(threads) / sizeof(threads[0]); j++) {
1108
						if(threads[j].used) {
1119
						if(threads[j].used) {
1109
							thread_info info;
1120
							thread_info info;
1110
							bool kill = false;
1121
							bool kill = false;