Subversion Repositories Tewi

Rev

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

Rev 200 Rev 206
Line 1... Line 1...
1
/* $Id: main.c 200 2024-09-29 07:50:59Z nishi $ */
1
/* $Id: main.c 206 2024-10-02 02:33:40Z nishi $ */
2
 
2
 
3
#define SOURCE
3
#define SOURCE
4
 
4
 
5
#include "../config.h"
5
#include "../config.h"
6
 
6
 
Line 69... Line 69...
69
 
69
 
70
char tw_server[2048];
70
char tw_server[2048];
71
 
71
 
72
int startup(int argc, char** argv);
72
int startup(int argc, char** argv);
73
 
73
 
-
 
74
#ifdef __MINGW32__
-
 
75
char* get_registry(const char* main, const char* sub) {
-
 
76
	DWORD bufsize = 255;
-
 
77
	char* value = malloc(256);
-
 
78
	int err = RegGetValue(HKEY_LOCAL_MACHINE, main, sub, RRF_RT_ANY, NULL, (void*)value, &bufsize);
-
 
79
	if(err == ERROR_SUCCESS) {
-
 
80
		return value;
-
 
81
	} else {
-
 
82
		free(value);
-
 
83
		return NULL;
-
 
84
	}
-
 
85
}
-
 
86
#endif
-
 
87
 
74
#ifdef SERVICE
88
#ifdef SERVICE
75
SERVICE_STATUS status;
89
SERVICE_STATUS status;
76
SERVICE_STATUS_HANDLE status_handle;
90
SERVICE_STATUS_HANDLE status_handle;
77
 
91
 
78
void WINAPI servhandler(DWORD control) {
92
void WINAPI servhandler(DWORD control) {
Line 84... Line 98...
84
	}
98
	}
85
	SetServiceStatus(status_handle, &status);
99
	SetServiceStatus(status_handle, &status);
86
}
100
}
87
 
101
 
88
void WINAPI servmain(DWORD argc, LPSTR* argv) {
102
void WINAPI servmain(DWORD argc, LPSTR* argv) {
-
 
103
	char* path = get_registry("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Tewi HTTPd", "InstallDir");
-
 
104
	if(path != NULL) {
-
 
105
		char* lpath = cm_strcat(path, "/logs/tewi.log");
-
 
106
		logfile = fopen(lpath, "a");
-
 
107
		free(lpath);
-
 
108
		free(path);
-
 
109
	} else {
89
	logfile = fopen(PREFIX "/logs/tewi.log", "a");
110
		logfile = fopen(PREFIX "/logs/tewi.log", "a");
-
 
111
	}
90
	if(logfile == NULL) logfile = stderr;
112
	if(logfile == NULL) logfile = stderr;
91
	status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
113
	status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
92
	status.dwCurrentState = SERVICE_START_PENDING;
114
	status.dwCurrentState = SERVICE_START_PENDING;
93
	status.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
115
	status.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
94
	status.dwWin32ExitCode = NO_ERROR;
116
	status.dwWin32ExitCode = NO_ERROR;
Line 659... Line 681...
659
	return 0;
681
	return 0;
660
}
682
}
661
 
683
 
662
int startup(int argc, char** argv) {
684
int startup(int argc, char** argv) {
663
	int i;
685
	int i;
-
 
686
#ifdef __MINGW32__
-
 
687
	char* confpath = cm_strdup(PREFIX "/etc/tewi.conf");
-
 
688
	char* regpath = get_registry("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Tewi HTTPd", "InstallDir");
-
 
689
	if(regpath != NULL) {
-
 
690
		free(confpath);
-
 
691
		confpath = cm_strcat(regpath, "/etc/tewi.conf");
-
 
692
		free(regpath);
-
 
693
	}
-
 
694
#else
664
	const char* confpath = PREFIX "/etc/tewi.conf";
695
	const char* confpath = PREFIX "/etc/tewi.conf";
-
 
696
#endif
665
	if(argv != NULL) {
697
	if(argv != NULL) {
666
		for(i = 1; i < argc; i++) {
698
		for(i = 1; i < argc; i++) {
667
			if(argv[i][0] == '-') {
699
			if(argv[i][0] == '-') {
668
				if(strcmp(argv[i], "--verbose") == 0 || strcmp(argv[i], "-v") == 0) {
700
				if(strcmp(argv[i], "--verbose") == 0 || strcmp(argv[i], "-v") == 0) {
669
					if(!cm_do_log) {
701
					if(!cm_do_log) {