Subversion Repositories Tewi

Rev

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

Rev 314 Rev 315
Line 1... Line 1...
1
/* $Id: server.c 314 2024-10-14 07:37:04Z nishi $ */
1
/* $Id: server.c 315 2024-10-14 10:01:02Z nishi $ */
2
 
2
 
3
#define SOURCE
3
#define SOURCE
4
 
4
 
5
#include "../config.h"
5
#include "../config.h"
6
 
6
 
Line 45... Line 45...
45
typedef int socklen_t;
45
typedef int socklen_t;
46
 
46
 
47
#include <tcpustd.h>
47
#include <tcpustd.h>
48
#endif
48
#endif
49
 
49
 
50
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || (defined(__WATCOMC__) && !defined(__OS2__))
50
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || (defined(__WATCOMC__) && !defined(__OS2__) && !defined(__NETWARE__))
51
#ifndef NO_GETNAMEINFO
51
#ifndef NO_GETNAMEINFO
52
#include <ws2tcpip.h>
52
#include <ws2tcpip.h>
53
#include <wspiapi.h>
53
#include <wspiapi.h>
54
#endif
54
#endif
55
#ifdef USE_WINSOCK1
55
#ifdef USE_WINSOCK1
Line 60... Line 60...
60
#include <process.h>
60
#include <process.h>
61
#include <windows.h>
61
#include <windows.h>
62
 
62
 
63
#include "strptime.h"
63
#include "strptime.h"
64
typedef int socklen_t;
64
typedef int socklen_t;
-
 
65
#elif defined(__NETWARE__)
-
 
66
#include <sys/socket.h>
-
 
67
#include <nwthread.h>
-
 
68
 
-
 
69
typedef int socklen_t;
-
 
70
#define IPPROTO_TCP 0
-
 
71
#define INADDR_ANY 0
-
 
72
#define htons(x) x
-
 
73
#include "strptime.h"
65
#else
74
#else
66
#ifdef USE_POLL
75
#ifdef USE_POLL
67
#ifdef __PPU__
76
#ifdef __PPU__
68
#include <net/poll.h>
77
#include <net/poll.h>
69
#else
78
#else
Line 134... Line 143...
134
}
143
}
135
 
144
 
136
void close_socket(int sock) {
145
void close_socket(int sock) {
137
#ifdef __OS2__
146
#ifdef __OS2__
138
	soclose(sock);
147
	soclose(sock);
-
 
148
#elif defined(__NETWARE__)
-
 
149
	shutdown(sock, 2);
139
#elif defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__)
150
#elif defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__)
140
	closesocket(sock);
151
	closesocket(sock);
141
#else
152
#else
142
	close(sock);
153
	close(sock);
143
#endif
154
#endif
144
}
155
}
145
 
156
 
146
int tw_server_init(void) {
157
int tw_server_init(void) {
147
	int i;
158
	int i;
148
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || (defined(__WATCOMC__) && !defined(__OS2__))
159
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || (defined(__WATCOMC__) && !defined(__OS2__) && !defined(__NETWARE__))
149
	WSADATA wsa;
160
	WSADATA wsa;
150
#ifdef USE_WINSOCK1
161
#ifdef USE_WINSOCK1
151
	WSAStartup(MAKEWORD(1, 1), &wsa);
162
	WSAStartup(MAKEWORD(1, 1), &wsa);
152
#else
163
#else
153
	WSAStartup(MAKEWORD(2, 0), &wsa);
164
	WSAStartup(MAKEWORD(2, 0), &wsa);
Line 519... Line 530...
519
	struct tw_tool tools;
530
	struct tw_tool tools;
520
	char* addrstr;
531
	char* addrstr;
521
#ifndef NO_GETNAMEINFO
532
#ifndef NO_GETNAMEINFO
522
	struct sockaddr* sa = (struct sockaddr*)&addr;
533
	struct sockaddr* sa = (struct sockaddr*)&addr;
523
	getnameinfo(sa, sizeof(addr), address, 512, NULL, 0, NI_NUMERICHOST);
534
	getnameinfo(sa, sizeof(addr), address, 512, NULL, 0, NI_NUMERICHOST);
-
 
535
#elif defined(__NETWARE__)
-
 
536
		address[0] = 0;
524
#else
537
#else
525
		addrstr = inet_ntoa(addr.sin_addr);
538
	addrstr = inet_ntoa(addr.sin_addr);
526
		strcpy(address, addrstr);
539
	strcpy(address, addrstr);
527
		address[strlen(addrstr)] = 0;
540
	address[strlen(addrstr)] = 0;
528
#endif
541
#endif
529
#ifdef FREE_PTR
542
#ifdef FREE_PTR
530
	free(ptr);
543
	free(ptr);
531
#endif
544
#endif
532
 
545
 
Line 629... Line 642...
629
#endif
642
#endif
630
		for(i = 0; i < config.module_count; i++) {
643
		for(i = 0; i < config.module_count; i++) {
631
#ifdef __OS2__
644
#ifdef __OS2__
632
			tw_mod_request_t mod_req = (tw_mod_request_t)tw_module_symbol(config.modules[i], "MOD_REQUEST");
645
			tw_mod_request_t mod_req = (tw_mod_request_t)tw_module_symbol(config.modules[i], "MOD_REQUEST");
633
#else
646
#else
634
			tw_mod_request_t mod_req = (tw_mod_request_t)tw_module_symbol(config.modules[i], "mod_request");
647
				tw_mod_request_t mod_req = (tw_mod_request_t)tw_module_symbol(config.modules[i], "mod_request");
635
#endif
648
#endif
636
			if(mod_req != NULL) {
649
			if(mod_req != NULL) {
637
				int ret = mod_req(&tools, &req, &res);
650
				int ret = mod_req(&tools, &req, &res);
638
				int co = ret & 0xff;
651
				int co = ret & 0xff;
639
				if(co == _TW_MODULE_PASS) {
652
				if(co == _TW_MODULE_PASS) {
Line 938... Line 951...
938
	}
951
	}
939
	SSL_free(s);
952
	SSL_free(s);
940
#endif
953
#endif
941
	close_socket(sock);
954
	close_socket(sock);
942
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__)
955
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__)
-
 
956
#ifdef __NETWARE__
-
 
957
	ExitThread(EXIT_THREAD, 0);
-
 
958
#else
943
	_endthread();
959
	_endthread();
-
 
960
#endif
944
#elif defined(__HAIKU__)
961
#elif defined(__HAIKU__)
945
		exit_thread(0);
962
		exit_thread(0);
946
#endif
963
#endif
947
#ifndef NO_RETURN_THREAD
964
#ifndef NO_RETURN_THREAD
948
	return 0;
965
	return 0;
Line 956... Line 973...
956
 
973
 
957
#if defined(__MINGW32__) || defined(__HAIKU__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__)
974
#if defined(__MINGW32__) || defined(__HAIKU__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__)
958
struct thread_entry {
975
struct thread_entry {
959
#ifdef __HAIKU__
976
#ifdef __HAIKU__
960
	thread_id thread;
977
	thread_id thread;
-
 
978
#elif defined(__NETWARE__)
-
 
979
	int thread;
961
#else
980
#else
962
	HANDLE handle;
981
	HANDLE handle;
963
#endif
982
#endif
964
	bool used;
983
	bool used;
965
};
984
};
Line 1043... Line 1062...
1043
					e->addr = claddr;
1062
					e->addr = claddr;
1044
#endif
1063
#endif
1045
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__)
1064
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__)
1046
#ifdef __OS2__
1065
#ifdef __OS2__
1047
					_beginthread(tw_server_pass, 0, 0, e);
1066
					_beginthread(tw_server_pass, 0, 0, e);
-
 
1067
#elif defined(__NETWARE__)
-
 
1068
					BeginThread(tw_server_pass, 0, 0, e);
1048
#else
1069
#else
1049
					_beginthread(tw_server_pass, 0, e);
1070
					_beginthread(tw_server_pass, 0, e);
1050
#endif
1071
#endif
1051
#elif defined(_PSP) || defined(__PPU__)
1072
#elif defined(_PSP) || defined(__PPU__)
1052
						tw_server_pass(e);
1073
						tw_server_pass(e);