Subversion Repositories Tewi

Rev

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

Rev 62 Rev 70
Line 1... Line 1...
1
/* $Id: main.c 62 2024-09-18 20:02:26Z nishi $ */
1
/* $Id: main.c 70 2024-09-19 09:23:45Z nishi $ */
2
 
2
 
3
#define SOURCE
3
#define SOURCE
4
 
4
 
5
#include "../config.h"
5
#include "../config.h"
6
 
6
 
Line 34... Line 34...
34
 
34
 
35
#ifdef SERVICE
35
#ifdef SERVICE
36
SERVICE_STATUS status;
36
SERVICE_STATUS status;
37
SERVICE_STATUS_HANDLE status_handle;
37
SERVICE_STATUS_HANDLE status_handle;
38
 
38
 
39
void WINAPI servhandler(DWORD control){
39
void WINAPI servhandler(DWORD control) {
40
	switch(control){
40
	switch(control) {
41
		case SERVICE_CONTROL_STOP:
41
	case SERVICE_CONTROL_STOP:
42
		case SERVICE_CONTROL_SHUTDOWN:
42
	case SERVICE_CONTROL_SHUTDOWN:
43
			status.dwCurrentState = SERVICE_STOP_PENDING;
43
		status.dwCurrentState = SERVICE_STOP_PENDING;
44
			break;
44
		break;
45
	}
45
	}
46
	SetServiceStatus(status_handle, &status);
46
	SetServiceStatus(status_handle, &status);
47
}
47
}
48
 
48
 
49
void WINAPI servmain(DWORD argc, LPSTR* argv){
49
void WINAPI servmain(DWORD argc, LPSTR* argv) {
50
	logfile = fopen(PREFIX "/logs/tewi.log", "a");
50
	logfile = fopen(PREFIX "/logs/tewi.log", "a");
51
	if(logfile == NULL) logfile = stderr;
51
	if(logfile == NULL) logfile = stderr;
52
	status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
52
	status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
53
	status.dwCurrentState = SERVICE_START_PENDING;
53
	status.dwCurrentState = SERVICE_START_PENDING;
54
	status.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
54
	status.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
Line 58... Line 58...
58
	status.dwWaitHint = 0;
58
	status.dwWaitHint = 0;
59
	status_handle = RegisterServiceCtrlHandler("Tewi HTTPd", servhandler);
59
	status_handle = RegisterServiceCtrlHandler("Tewi HTTPd", servhandler);
60
	if(status_handle == NULL) return;
60
	if(status_handle == NULL) return;
61
	if(SetServiceStatus(status_handle, &status) == 0) return;
61
	if(SetServiceStatus(status_handle, &status) == 0) return;
62
	int st = startup(argc, argv);
62
	int st = startup(argc, argv);
63
	if(st != -1){
63
	if(st != -1) {
64
		status.dwWin32ExitCode = NO_ERROR;
64
		status.dwWin32ExitCode = NO_ERROR;
65
		status.dwServiceSpecificExitCode = st;
65
		status.dwServiceSpecificExitCode = st;
66
		status.dwCurrentState = SERVICE_STOPPED;
66
		status.dwCurrentState = SERVICE_STOPPED;
67
		SetServiceStatus(status_handle, &status);
67
		SetServiceStatus(status_handle, &status);
68
		return;
68
		return;
Line 85... Line 85...
85
	if(st != -1) return st;
85
	if(st != -1) return st;
86
	tw_server_loop();
86
	tw_server_loop();
87
#endif
87
#endif
88
}
88
}
89
 
89
 
90
int startup(int argc, char** argv){
90
int startup(int argc, char** argv) {
91
	int i;
91
	int i;
92
	const char* confpath = PREFIX "/etc/tewi.conf";
92
	const char* confpath = PREFIX "/etc/tewi.conf";
93
	if(argv != NULL){
93
	if(argv != NULL) {
94
		for(i = 1; i < argc; i++) {
94
		for(i = 1; i < argc; i++) {
95
			if(argv[i][0] == '-') {
95
			if(argv[i][0] == '-') {
96
				if(strcmp(argv[i], "--verbose") == 0 || strcmp(argv[i], "-v") == 0) {
96
				if(strcmp(argv[i], "--verbose") == 0 || strcmp(argv[i], "-v") == 0) {
97
					if(!cm_do_log) {
97
					if(!cm_do_log) {
98
						cm_do_log = true;
98
						cm_do_log = true;
99
	#ifndef NO_SSL
99
#ifndef NO_SSL
100
						cm_log("", "This is Tewi HTTPd, version %s, using %s", tw_get_version(), OPENSSL_VERSION_TEXT);
100
						cm_log("", "This is Tewi HTTPd, version %s, using %s", tw_get_version(), OPENSSL_VERSION_TEXT);
101
	#else
101
#else
102
						cm_log("", "This is Tewi HTTPd, version %s", tw_get_version());
102
						cm_log("", "This is Tewi HTTPd, version %s", tw_get_version());
103
	#endif
103
#endif
104
					} else {
104
					} else {
105
						cm_do_log = true;
105
						cm_do_log = true;
106
					}
106
					}
107
				} else if(strcmp(argv[i], "--config") == 0 || strcmp(argv[i], "-C") == 0) {
107
				} else if(strcmp(argv[i], "--config") == 0 || strcmp(argv[i], "-C") == 0) {
108
					i++;
108
					i++;