|
@@ -21,7 +21,12 @@
|
|
|
*/
|
|
|
|
|
|
#if defined(_WIN32)
|
|
|
+#ifndef _CRT_SECURE_NO_WARNINGS
|
|
|
#define _CRT_SECURE_NO_WARNINGS /* Disable deprecation warning in VS2005 */
|
|
|
+#endif
|
|
|
+#ifndef _CRT_SECURE_NO_DEPRECATE
|
|
|
+#define _CRT_SECURE_NO_DEPRECATE
|
|
|
+#endif
|
|
|
#else
|
|
|
#define _XOPEN_SOURCE 600 /* For PATH_MAX on linux */
|
|
|
#endif
|
|
@@ -48,6 +53,7 @@
|
|
|
#ifndef _WIN32_WINNT
|
|
|
#define _WIN32_WINNT 0x0501 /* Target Windows XP or higher */
|
|
|
#endif
|
|
|
+#undef UNICODE
|
|
|
#include <windows.h>
|
|
|
#include <winsvc.h>
|
|
|
#include <shlobj.h>
|
|
@@ -59,6 +65,11 @@ extern char *_getcwd(char *buf, size_t size);
|
|
|
#endif
|
|
|
static int guard = 0; /* test if any dialog is already open */
|
|
|
|
|
|
+#if defined (_MSC_VER)
|
|
|
+#define strdup _strdup
|
|
|
+/* or #pragma warning (disable : 4996 ) */
|
|
|
+#endif
|
|
|
+
|
|
|
#ifndef PATH_MAX
|
|
|
#define PATH_MAX MAX_PATH
|
|
|
#endif
|
|
@@ -84,12 +95,17 @@ static int guard = 0; /* test if any dialog is already open */
|
|
|
#define MAX_OPTIONS 50
|
|
|
#define MAX_CONF_FILE_LINE_SIZE (8 * 1024)
|
|
|
|
|
|
-static int exit_flag = 0; /* Main loop should exit */
|
|
|
-static char server_base_name[40]; /* Set by init_server_name() */
|
|
|
-static char *server_name; /* Set by init_server_name() */
|
|
|
-static char *icon_name; /* Set by init_server_name() */
|
|
|
-static char config_file[PATH_MAX] = ""; /* Set by process_command_line_arguments() */
|
|
|
-static struct mg_context *ctx; /* Set by start_civetweb() */
|
|
|
+struct tuser_data {
|
|
|
+ char * first_message;
|
|
|
+};
|
|
|
+
|
|
|
+static int g_exit_flag = 0; /* Main loop should exit */
|
|
|
+static char g_server_base_name[40]; /* Set by init_server_name() */
|
|
|
+static char *g_server_name; /* Set by init_server_name() */
|
|
|
+static char *g_icon_name; /* Set by init_server_name() */
|
|
|
+static char g_config_file[PATH_MAX] = ""; /* Set by process_command_line_arguments() */
|
|
|
+static struct mg_context *g_ctx; /* Set by start_civetweb() */
|
|
|
+static struct tuser_data g_user_data; /* Passed to mg_start() by start_civetweb() */
|
|
|
|
|
|
#if !defined(CONFIG_FILE)
|
|
|
#define CONFIG_FILE "civetweb.conf"
|
|
@@ -118,7 +134,7 @@ static struct mg_option main_config_options[] = {
|
|
|
|
|
|
static void WINCDECL signal_handler(int sig_num)
|
|
|
{
|
|
|
- exit_flag = sig_num;
|
|
|
+ g_exit_flag = sig_num;
|
|
|
}
|
|
|
|
|
|
static void die(const char *fmt, ...)
|
|
@@ -210,7 +226,7 @@ static const char *get_url_to_first_open_port(const struct mg_context *ctx)
|
|
|
return url;
|
|
|
}
|
|
|
|
|
|
-static void create_config_file(const char *path)
|
|
|
+static void create_config_file(const struct mg_context *ctx, const char *path)
|
|
|
{
|
|
|
const struct mg_option *options;
|
|
|
const char *value;
|
|
@@ -408,26 +424,25 @@ static void process_command_line_arguments(char *argv[], char **options)
|
|
|
|
|
|
/* Should we use a config file ? */
|
|
|
if (argv[1] != NULL && argv[1][0] != '-') {
|
|
|
- snprintf(config_file, sizeof(config_file), "%s", argv[1]);
|
|
|
+ snprintf(g_config_file, sizeof(g_config_file)-1, "%s", argv[1]);
|
|
|
cmd_line_opts_start = 2;
|
|
|
} else if ((p = strrchr(argv[0], DIRSEP)) == NULL) {
|
|
|
/* No command line flags specified. Look where binary lives */
|
|
|
- snprintf(config_file, sizeof(config_file)-1, "%s", CONFIG_FILE);
|
|
|
- config_file[sizeof(config_file)-1] = 0;
|
|
|
+ snprintf(g_config_file, sizeof(g_config_file)-1, "%s", CONFIG_FILE);
|
|
|
} else {
|
|
|
- snprintf(config_file, sizeof(config_file)-1, "%.*s%c%s",
|
|
|
+ snprintf(g_config_file, sizeof(g_config_file)-1, "%.*s%c%s",
|
|
|
(int) (p - argv[0]), argv[0], DIRSEP, CONFIG_FILE);
|
|
|
- config_file[sizeof(config_file)-1] = 0;
|
|
|
}
|
|
|
+ g_config_file[sizeof(g_config_file)-1] = 0;
|
|
|
|
|
|
#ifdef CONFIG_FILE2
|
|
|
- fp = fopen(config_file, "r");
|
|
|
+ fp = fopen(g_config_file, "r");
|
|
|
|
|
|
/* try alternate config file */
|
|
|
if (fp == NULL) {
|
|
|
fp = fopen(CONFIG_FILE2, "r");
|
|
|
if (fp != NULL) {
|
|
|
- strcpy(config_file, CONFIG_FILE2);
|
|
|
+ strcpy(g_config_file, CONFIG_FILE2);
|
|
|
}
|
|
|
}
|
|
|
if (fp != NULL) {
|
|
@@ -436,7 +451,7 @@ static void process_command_line_arguments(char *argv[], char **options)
|
|
|
#endif
|
|
|
|
|
|
/* read all configurations from a config file */
|
|
|
- (void)read_config_file(config_file, options);
|
|
|
+ (void)read_config_file(g_config_file, options);
|
|
|
|
|
|
/* If we're under MacOS and started by launchd, then the second
|
|
|
argument is process serial number, -psn_.....
|
|
@@ -460,28 +475,35 @@ static void init_server_name(int argc, const char *argv[])
|
|
|
{
|
|
|
int i;
|
|
|
assert(sizeof(main_config_options)/sizeof(main_config_options[0]) == NUM_MAIN_OPTIONS+1);
|
|
|
- assert((strlen(mg_version())+12)<sizeof(server_base_name));
|
|
|
- snprintf(server_base_name, sizeof(server_base_name), "Civetweb V%s",
|
|
|
+ assert((strlen(mg_version())+12)<sizeof(g_server_base_name));
|
|
|
+ snprintf(g_server_base_name, sizeof(g_server_base_name), "Civetweb V%s",
|
|
|
mg_version());
|
|
|
|
|
|
- server_name = server_base_name;
|
|
|
+ g_server_name = g_server_base_name;
|
|
|
for (i=0; i<argc-1; i++) {
|
|
|
if ((argv[i][0]=='-') && (0==strcmp(argv[i]+1, main_config_options[OPTION_TITLE].name))) {
|
|
|
- server_name = (char*)(argv[i+1]);
|
|
|
+ g_server_name = (char*)(argv[i+1]);
|
|
|
}
|
|
|
}
|
|
|
- icon_name = NULL;
|
|
|
+ g_icon_name = NULL;
|
|
|
for (i=0; i<argc-1; i++) {
|
|
|
if ((argv[i][0]=='-') && (0==strcmp(argv[i]+1, main_config_options[OPTION_ICON].name))) {
|
|
|
- icon_name = (char*)(argv[i+1]);
|
|
|
+ g_icon_name = (char*)(argv[i+1]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
static int log_message(const struct mg_connection *conn, const char *message)
|
|
|
{
|
|
|
- (void) conn;
|
|
|
+ const struct mg_context * ctx = mg_get_context(conn);
|
|
|
+ struct tuser_data * ud = (struct tuser_data *) mg_get_user_data(ctx);
|
|
|
+
|
|
|
printf("%s\n", message);
|
|
|
+
|
|
|
+ if (ud->first_message == NULL) {
|
|
|
+ ud->first_message = strdup(message);
|
|
|
+ }
|
|
|
+
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
@@ -514,6 +536,7 @@ static void verify_existence(char **options, const char *option_name,
|
|
|
len = MultiByteToWideChar(CP_UTF8, 0, path, -1, wbuf, (int) sizeof(wbuf)/sizeof(wbuf[0])-1);
|
|
|
wcstombs(mbbuf, wbuf, sizeof(mbbuf)-1);
|
|
|
path = mbbuf;
|
|
|
+ (void)len;
|
|
|
}
|
|
|
#endif
|
|
|
|
|
@@ -639,19 +662,29 @@ static void start_civetweb(int argc, char *argv[])
|
|
|
signal(SIGTERM, signal_handler);
|
|
|
signal(SIGINT, signal_handler);
|
|
|
|
|
|
+ /* Initialize user data */
|
|
|
+ memset(&g_user_data, 0, sizeof(g_user_data));
|
|
|
+
|
|
|
/* Start Civetweb */
|
|
|
memset(&callbacks, 0, sizeof(callbacks));
|
|
|
callbacks.log_message = &log_message;
|
|
|
- ctx = mg_start(&callbacks, NULL, (const char **) options);
|
|
|
+ g_ctx = mg_start(&callbacks, &g_user_data, (const char **) options);
|
|
|
for (i = 0; options[i] != NULL; i++) {
|
|
|
free(options[i]);
|
|
|
}
|
|
|
|
|
|
- if (ctx == NULL) {
|
|
|
- die("%s", "Failed to start Civetweb.");
|
|
|
+ if (g_ctx == NULL) {
|
|
|
+ die("Failed to start Civetweb:\n%s", (g_user_data.first_message == NULL) ? "unknown reason" : g_user_data.first_message);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+void stop_civetweb(void)
|
|
|
+{
|
|
|
+ mg_stop(g_ctx);
|
|
|
+ free(g_user_data.first_message);
|
|
|
+ g_user_data.first_message = NULL;
|
|
|
+}
|
|
|
+
|
|
|
#ifdef _WIN32
|
|
|
enum {
|
|
|
ID_ICON = 100, ID_QUIT, ID_SETTINGS, ID_SEPARATOR, ID_INSTALL_SERVICE,
|
|
@@ -690,13 +723,13 @@ static void WINAPI ServiceMain(void)
|
|
|
ss.dwCurrentState = SERVICE_RUNNING;
|
|
|
ss.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
|
|
|
|
|
|
- hStatus = RegisterServiceCtrlHandler(server_name, ControlHandler);
|
|
|
+ hStatus = RegisterServiceCtrlHandler(g_server_name, ControlHandler);
|
|
|
SetServiceStatus(hStatus, &ss);
|
|
|
|
|
|
while (ss.dwCurrentState == SERVICE_RUNNING) {
|
|
|
Sleep(1000);
|
|
|
}
|
|
|
- mg_stop(ctx);
|
|
|
+ stop_civetweb();
|
|
|
|
|
|
ss.dwCurrentState = SERVICE_STOPPED;
|
|
|
ss.dwWin32ExitCode = (DWORD) -1;
|
|
@@ -747,7 +780,7 @@ static void save_config(HWND hDlg, FILE *fp)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-static BOOL CALLBACK SettingsDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lP)
|
|
|
+static BOOL CALLBACK SettingsDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
|
|
|
{
|
|
|
FILE *fp;
|
|
|
int i, j;
|
|
@@ -755,6 +788,7 @@ static BOOL CALLBACK SettingsDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM
|
|
|
const struct mg_option *default_options = mg_get_valid_options();
|
|
|
char *file_options[MAX_OPTIONS*2+1] = {0};
|
|
|
char *title;
|
|
|
+ (void)lParam;
|
|
|
|
|
|
switch (msg) {
|
|
|
case WM_CLOSE:
|
|
@@ -766,10 +800,10 @@ static BOOL CALLBACK SettingsDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM
|
|
|
|
|
|
case ID_SAVE:
|
|
|
EnableWindow(GetDlgItem(hDlg, ID_SAVE), FALSE);
|
|
|
- if ((fp = fopen(config_file, "w+")) != NULL) {
|
|
|
+ if ((fp = fopen(g_config_file, "w+")) != NULL) {
|
|
|
save_config(hDlg, fp);
|
|
|
fclose(fp);
|
|
|
- mg_stop(ctx);
|
|
|
+ stop_civetweb();
|
|
|
start_civetweb(__argc, __argv);
|
|
|
}
|
|
|
EnableWindow(GetDlgItem(hDlg, ID_SAVE), TRUE);
|
|
@@ -789,7 +823,7 @@ static BOOL CALLBACK SettingsDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM
|
|
|
break;
|
|
|
|
|
|
case ID_RESET_FILE:
|
|
|
- read_config_file(config_file, file_options);
|
|
|
+ read_config_file(g_config_file, file_options);
|
|
|
for (i = 0; default_options[i].name != NULL; i++) {
|
|
|
name = default_options[i].name;
|
|
|
value = default_options[i].default_value;
|
|
@@ -816,7 +850,7 @@ static BOOL CALLBACK SettingsDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM
|
|
|
case ID_RESET_ACTIVE:
|
|
|
for (i = 0; default_options[i].name != NULL; i++) {
|
|
|
name = default_options[i].name;
|
|
|
- value = mg_get_option(ctx, name);
|
|
|
+ value = mg_get_option(g_ctx, name);
|
|
|
if (default_options[i].type == CONFIG_TYPE_BOOLEAN) {
|
|
|
CheckDlgButton(hDlg, ID_CONTROLS + i, !strcmp(value, "yes") ?
|
|
|
BST_CHECKED : BST_UNCHECKED);
|
|
@@ -840,7 +874,7 @@ static BOOL CALLBACK SettingsDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM
|
|
|
of.hwndOwner = (HWND) hDlg;
|
|
|
of.lpstrFile = path;
|
|
|
of.nMaxFile = sizeof(path);
|
|
|
- of.lpstrInitialDir = mg_get_option(ctx, "document_root");
|
|
|
+ of.lpstrInitialDir = mg_get_option(g_ctx, "document_root");
|
|
|
of.Flags = OFN_CREATEPROMPT | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
|
|
|
|
|
|
memset(&bi, 0, sizeof(bi));
|
|
@@ -864,9 +898,9 @@ static BOOL CALLBACK SettingsDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM
|
|
|
case WM_INITDIALOG:
|
|
|
SendMessage(hDlg, WM_SETICON, (WPARAM) ICON_SMALL, (LPARAM) hIcon);
|
|
|
SendMessage(hDlg, WM_SETICON, (WPARAM) ICON_BIG, (LPARAM) hIcon);
|
|
|
- title = malloc(strlen(server_name)+16);
|
|
|
+ title = malloc(strlen(g_server_name)+16);
|
|
|
if (title) {
|
|
|
- strcpy(title, server_name);
|
|
|
+ strcpy(title, g_server_name);
|
|
|
strcat(title, " settings");
|
|
|
SetWindowText(hDlg, title);
|
|
|
free(title);
|
|
@@ -966,7 +1000,6 @@ static int get_password(const char * user, const char * realm, char * passwd, un
|
|
|
#define WIDTH 280
|
|
|
#define LABEL_WIDTH 90
|
|
|
|
|
|
- HWND hDlg = NULL;
|
|
|
unsigned char mem[4096], *p;
|
|
|
DLGTEMPLATE *dia = (DLGTEMPLATE *) mem;
|
|
|
int ok, y;
|
|
@@ -1031,7 +1064,7 @@ static int get_password(const char * user, const char * realm, char * passwd, un
|
|
|
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,
|
|
|
140, y, 55, 12, "Cancel");
|
|
|
|
|
|
- assert((int)p - (int)mem < sizeof(mem));
|
|
|
+ assert((int)p - (int)mem < (int)sizeof(mem));
|
|
|
|
|
|
dia->cy = y + (WORD)(HEIGHT * 1.5);
|
|
|
|
|
@@ -1204,7 +1237,7 @@ static void show_settings_dialog()
|
|
|
(WORD) (x + LABEL_WIDTH), y, width, 12, "");
|
|
|
nelems++;
|
|
|
|
|
|
- assert((int)p - (int)mem < sizeof(mem));
|
|
|
+ assert(((int)p - (int)mem) < (int)sizeof(mem));
|
|
|
}
|
|
|
|
|
|
y = (WORD) (((nelems + 1) / 2 + 1) * HEIGHT + 5);
|
|
@@ -1225,9 +1258,9 @@ static void show_settings_dialog()
|
|
|
WIDTH - 280, y, 65, 12, "Reload active");
|
|
|
add_control(&p, dia, 0x82, ID_STATIC,
|
|
|
WS_CHILD | WS_VISIBLE | WS_DISABLED,
|
|
|
- 5, y, 100, 12, server_base_name);
|
|
|
+ 5, y, 100, 12, g_server_base_name);
|
|
|
|
|
|
- assert((int)p - (int)mem < sizeof(mem));
|
|
|
+ assert(((int)p - (int)mem) < (int)sizeof(mem));
|
|
|
|
|
|
dia->cy = ((nelems + 1) / 2 + 1) * HEIGHT + 30;
|
|
|
DialogBoxIndirectParam(NULL, dia, NULL, SettingsDlgProc, (LPARAM) NULL);
|
|
@@ -1252,7 +1285,7 @@ static void change_password_file()
|
|
|
int y, nelems;
|
|
|
unsigned char mem[4096], *p;
|
|
|
DLGTEMPLATE *dia = (DLGTEMPLATE *) mem;
|
|
|
- const char * domain = mg_get_option(ctx, "authentication_domain");
|
|
|
+ const char * domain = mg_get_option(g_ctx, "authentication_domain");
|
|
|
|
|
|
static struct {
|
|
|
DLGTEMPLATE template; /* 18 bytes */
|
|
@@ -1278,7 +1311,7 @@ static void change_password_file()
|
|
|
of.hwndOwner = (HWND) hDlg;
|
|
|
of.lpstrFile = path;
|
|
|
of.nMaxFile = sizeof(path);
|
|
|
- of.lpstrInitialDir = mg_get_option(ctx, "document_root");
|
|
|
+ of.lpstrInitialDir = mg_get_option(g_ctx, "document_root");
|
|
|
of.Flags = OFN_CREATEPROMPT | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
|
|
|
|
|
|
if (IDOK != GetSaveFileName(&of)) {
|
|
@@ -1329,7 +1362,7 @@ static void change_password_file()
|
|
|
140, y, 100, 12, u);
|
|
|
|
|
|
nelems++;
|
|
|
- assert((int)p - (int)mem < sizeof(mem));
|
|
|
+ assert(((int)p - (int)mem) < (int)sizeof(mem));
|
|
|
}
|
|
|
fclose(f);
|
|
|
|
|
@@ -1351,12 +1384,12 @@ static void change_password_file()
|
|
|
y += HEIGHT;
|
|
|
add_control(&p, dia, 0x82, ID_STATIC,
|
|
|
WS_CHILD | WS_VISIBLE | WS_DISABLED,
|
|
|
- 5, y, 100, 12, server_base_name);
|
|
|
+ 5, y, 100, 12, g_server_base_name);
|
|
|
|
|
|
- assert((int)p - (int)mem < sizeof(mem));
|
|
|
+ assert(((int)p - (int)mem) < (int)sizeof(mem));
|
|
|
|
|
|
dia->cy = y + 20;
|
|
|
- } while ((IDOK == DialogBoxIndirectParam(NULL, dia, NULL, PasswordDlgProc, (LPARAM) path)) && (!exit_flag));
|
|
|
+ } while ((IDOK == DialogBoxIndirectParam(NULL, dia, NULL, PasswordDlgProc, (LPARAM) path)) && (!g_exit_flag));
|
|
|
|
|
|
guard--;
|
|
|
|
|
@@ -1369,7 +1402,7 @@ static int manage_service(int action)
|
|
|
{
|
|
|
static const char *service_name = "Civetweb"; /* TODO: check using server_name instead of service_name */
|
|
|
SC_HANDLE hSCM = NULL, hService = NULL;
|
|
|
- SERVICE_DESCRIPTION descr = {server_name};
|
|
|
+ SERVICE_DESCRIPTION descr = {g_server_name};
|
|
|
char path[PATH_MAX + 20] = "";/* Path to executable plus magic argument */
|
|
|
int success = 1;
|
|
|
|
|
@@ -1412,14 +1445,15 @@ static int manage_service(int action)
|
|
|
static LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam,
|
|
|
LPARAM lParam)
|
|
|
{
|
|
|
- static SERVICE_TABLE_ENTRY service_table[2] = {0};
|
|
|
+ static SERVICE_TABLE_ENTRY service_table[2];
|
|
|
int service_installed;
|
|
|
char buf[200], *service_argv[] = {__argv[0], NULL};
|
|
|
POINT pt;
|
|
|
HMENU hMenu;
|
|
|
static UINT s_uTaskbarRestart; /* for taskbar creation */
|
|
|
|
|
|
- service_table[0].lpServiceName = server_name;
|
|
|
+ memset(service_table, 0, sizeof(service_table));
|
|
|
+ service_table[0].lpServiceName = g_server_name;
|
|
|
service_table[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTION)ServiceMain;
|
|
|
|
|
|
switch (msg) {
|
|
@@ -1437,9 +1471,9 @@ static LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam,
|
|
|
case WM_COMMAND:
|
|
|
switch (LOWORD(wParam)) {
|
|
|
case ID_QUIT:
|
|
|
- mg_stop(ctx);
|
|
|
+ stop_civetweb();
|
|
|
Shell_NotifyIcon(NIM_DELETE, &TrayIcon);
|
|
|
- exit_flag = 1;
|
|
|
+ g_exit_flag = 1;
|
|
|
PostQuitMessage(0);
|
|
|
return 0;
|
|
|
case ID_SETTINGS:
|
|
@@ -1453,8 +1487,8 @@ static LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam,
|
|
|
manage_service(LOWORD(wParam));
|
|
|
break;
|
|
|
case ID_CONNECT:
|
|
|
- printf("[%s]\n", get_url_to_first_open_port(ctx));
|
|
|
- ShellExecute(NULL, "open", get_url_to_first_open_port(ctx),
|
|
|
+ printf("[%s]\n", get_url_to_first_open_port(g_ctx));
|
|
|
+ ShellExecute(NULL, "open", get_url_to_first_open_port(g_ctx),
|
|
|
NULL, NULL, SW_SHOW);
|
|
|
break;
|
|
|
}
|
|
@@ -1465,7 +1499,7 @@ static LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam,
|
|
|
case WM_LBUTTONUP:
|
|
|
case WM_LBUTTONDBLCLK:
|
|
|
hMenu = CreatePopupMenu();
|
|
|
- AppendMenu(hMenu, MF_STRING | MF_GRAYED, ID_SEPARATOR, server_name);
|
|
|
+ AppendMenu(hMenu, MF_STRING | MF_GRAYED, ID_SEPARATOR, g_server_name);
|
|
|
AppendMenu(hMenu, MF_SEPARATOR, ID_SEPARATOR, "");
|
|
|
service_installed = manage_service(0);
|
|
|
snprintf(buf, sizeof(buf)-1, "NT service: %s installed",
|
|
@@ -1491,9 +1525,9 @@ static LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam,
|
|
|
}
|
|
|
break;
|
|
|
case WM_CLOSE:
|
|
|
- mg_stop(ctx);
|
|
|
+ stop_civetweb();
|
|
|
Shell_NotifyIcon(NIM_DELETE, &TrayIcon);
|
|
|
- exit_flag = 1;
|
|
|
+ g_exit_flag = 1;
|
|
|
PostQuitMessage(0);
|
|
|
return 0;/* We've just sent our own quit message, with proper hwnd. */
|
|
|
default:
|
|
@@ -1528,7 +1562,7 @@ static int MakeConsole() {
|
|
|
}
|
|
|
|
|
|
if (ok) {
|
|
|
- SetConsoleTitle(server_name);
|
|
|
+ SetConsoleTitle(g_server_name);
|
|
|
}
|
|
|
|
|
|
return ok;
|
|
@@ -1540,19 +1574,24 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR cmdline, int show)
|
|
|
HWND hWnd;
|
|
|
MSG msg;
|
|
|
|
|
|
- init_server_name(__argc, __argv);
|
|
|
+ (void)hInst;
|
|
|
+ (void)hPrev;
|
|
|
+ (void)cmdline;
|
|
|
+ (void)show;
|
|
|
+
|
|
|
+ init_server_name((int)__argc, (const char **)__argv);
|
|
|
memset(&cls, 0, sizeof(cls));
|
|
|
cls.lpfnWndProc = (WNDPROC) WindowProc;
|
|
|
cls.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
|
|
- cls.lpszClassName = server_base_name;
|
|
|
+ cls.lpszClassName = g_server_base_name;
|
|
|
|
|
|
RegisterClass(&cls);
|
|
|
- hWnd = CreateWindow(cls.lpszClassName, server_name, WS_OVERLAPPEDWINDOW,
|
|
|
+ hWnd = CreateWindow(cls.lpszClassName, g_server_name, WS_OVERLAPPEDWINDOW,
|
|
|
0, 0, 0, 0, NULL, NULL, NULL, NULL);
|
|
|
ShowWindow(hWnd, SW_HIDE);
|
|
|
|
|
|
- if (icon_name) {
|
|
|
- hIcon = LoadImage(NULL, icon_name, IMAGE_ICON, 16, 16, LR_LOADFROMFILE);
|
|
|
+ if (g_icon_name) {
|
|
|
+ hIcon = LoadImage(NULL, g_icon_name, IMAGE_ICON, 16, 16, LR_LOADFROMFILE);
|
|
|
} else {
|
|
|
hIcon = LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(ID_ICON), IMAGE_ICON, 16, 16, 0);
|
|
|
}
|
|
@@ -1562,7 +1601,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR cmdline, int show)
|
|
|
TrayIcon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
|
|
|
TrayIcon.hIcon = hIcon;
|
|
|
TrayIcon.hWnd = hWnd;
|
|
|
- snprintf(TrayIcon.szTip, sizeof(TrayIcon.szTip), "%s", server_name);
|
|
|
+ snprintf(TrayIcon.szTip, sizeof(TrayIcon.szTip), "%s", g_server_name);
|
|
|
TrayIcon.uCallbackMessage = WM_USER;
|
|
|
Shell_NotifyIcon(NIM_ADD, &TrayIcon);
|
|
|
|
|
@@ -1595,12 +1634,12 @@ NSObject<NSApplicationDelegate>
|
|
|
- (void) openBrowser {
|
|
|
[[NSWorkspace sharedWorkspace]
|
|
|
openURL:[NSURL URLWithString:
|
|
|
-[NSString stringWithUTF8String:get_url_to_first_open_port(ctx)]]];
|
|
|
+[NSString stringWithUTF8String:get_url_to_first_open_port(g_ctx)]]];
|
|
|
}
|
|
|
- (void) editConfig {
|
|
|
- create_config_file(config_file);
|
|
|
+ create_config_file(g_ctx, g_config_file);
|
|
|
[[NSWorkspace sharedWorkspace]
|
|
|
-openFile:[NSString stringWithUTF8String:config_file]
|
|
|
+openFile:[NSString stringWithUTF8String:g_config_file]
|
|
|
withApplication:@"TextEdit"];
|
|
|
}
|
|
|
- (void)shutDown {
|
|
@@ -1631,7 +1670,7 @@ int main(int argc, char *argv[])
|
|
|
/* Add version menu item */
|
|
|
[menu addItem:[[[NSMenuItem alloc]
|
|
|
/*initWithTitle:[NSString stringWithFormat:@"%s", server_name]*/
|
|
|
- initWithTitle:[NSString stringWithUTF8String:server_name]
|
|
|
+ initWithTitle:[NSString stringWithUTF8String:g_server_name]
|
|
|
action:@selector(noexist) keyEquivalent:@""] autorelease]];
|
|
|
|
|
|
/* Add configuration menu item */
|
|
@@ -1663,7 +1702,7 @@ int main(int argc, char *argv[])
|
|
|
[NSApp activateIgnoringOtherApps:YES];
|
|
|
[NSApp run];
|
|
|
|
|
|
- mg_stop(ctx);
|
|
|
+ stop_civetweb(g_ctx);
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
}
|
|
@@ -1673,15 +1712,15 @@ int main(int argc, char *argv[])
|
|
|
init_server_name(argc, (const char **)argv);
|
|
|
start_civetweb(argc, argv);
|
|
|
printf("%s started on port(s) %s with web root [%s]\n",
|
|
|
- server_name, mg_get_option(ctx, "listening_ports"),
|
|
|
- mg_get_option(ctx, "document_root"));
|
|
|
- while (exit_flag == 0) {
|
|
|
+ g_server_name, mg_get_option(g_ctx, "listening_ports"),
|
|
|
+ mg_get_option(g_ctx, "document_root"));
|
|
|
+ while (g_exit_flag == 0) {
|
|
|
sleep(1);
|
|
|
}
|
|
|
printf("Exiting on signal %d, waiting for all threads to finish...",
|
|
|
- exit_flag);
|
|
|
+ g_exit_flag);
|
|
|
fflush(stdout);
|
|
|
- mg_stop(ctx);
|
|
|
+ stop_civetweb();
|
|
|
printf("%s", " done.\n");
|
|
|
|
|
|
return EXIT_SUCCESS;
|