Commit 4505b007 authored by Sergey Lyubka's avatar Sergey Lyubka

Removed support for option names

parent c485b826
...@@ -99,18 +99,18 @@ static void show_usage_and_exit(void) { ...@@ -99,18 +99,18 @@ static void show_usage_and_exit(void) {
const char **names; const char **names;
int i; int i;
fprintf(stderr, "Mongoose version %s (c) Sergey Lyubka, built %s\n", fprintf(stderr, "Mongoose version %s (c) Sergey Lyubka, built on %s\n",
mg_version(), __DATE__); mg_version(), __DATE__);
fprintf(stderr, "Usage:\n"); fprintf(stderr, "Usage:\n");
fprintf(stderr, " mongoose -A <htpasswd_file> <realm> <user> <passwd>\n"); fprintf(stderr, " mongoose -A <htpasswd_file> <realm> <user> <passwd>\n");
fprintf(stderr, " mongoose <config_file>\n"); fprintf(stderr, " mongoose [config_file]\n");
fprintf(stderr, " mongoose [-option value ...]\n"); fprintf(stderr, " mongoose [-option value ...]\n");
fprintf(stderr, "\nOPTIONS:\n"); fprintf(stderr, "\nOPTIONS:\n");
names = mg_get_valid_option_names(); names = mg_get_valid_option_names();
for (i = 0; names[i] != NULL; i += 3) { for (i = 0; names[i] != NULL; i += 2) {
fprintf(stderr, " -%s %s (default: \"%s\")\n", fprintf(stderr, " -%s %s\n",
names[i], names[i + 1], names[i + 2] == NULL ? "" : names[i + 2]); names[i], names[i + 1] == NULL ? "<empty>" : names[i + 1]);
} }
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
...@@ -153,9 +153,9 @@ static void create_config_file(const char *path) { ...@@ -153,9 +153,9 @@ static void create_config_file(const char *path) {
} else if ((fp = fopen(path, "a+")) != NULL) { } else if ((fp = fopen(path, "a+")) != NULL) {
fprintf(fp, "%s", config_file_top_comment); fprintf(fp, "%s", config_file_top_comment);
names = mg_get_valid_option_names(); names = mg_get_valid_option_names();
for (i = 0; names[i] != NULL; i += 3) { for (i = 0; names[i * 2] != NULL; i++) {
value = mg_get_option(ctx, names[i]); value = mg_get_option(ctx, names[i * 2]);
fprintf(fp, "# %s %s\n", names[i + 1], *value ? value : "<value>"); fprintf(fp, "# %s %s\n", names[i * 2], value ? value : "<value>");
} }
fclose(fp); fclose(fp);
} }
...@@ -417,16 +417,16 @@ static void save_config(HWND hDlg, FILE *fp) { ...@@ -417,16 +417,16 @@ static void save_config(HWND hDlg, FILE *fp) {
fprintf(fp, "%s", config_file_top_comment); fprintf(fp, "%s", config_file_top_comment);
options = mg_get_valid_option_names(); options = mg_get_valid_option_names();
for (i = 0; options[i] != NULL; i += 3) { for (i = 0; options[i * 2] != NULL; i++) {
name = options[i + 1]; name = options[i * 2];
id = ID_CONTROLS + i / 3; id = ID_CONTROLS + i;
if (is_boolean_option(name)) { if (is_boolean_option(name)) {
snprintf(value, sizeof(value), "%s", snprintf(value, sizeof(value), "%s",
IsDlgButtonChecked(hDlg, id) ? "yes" : "no"); IsDlgButtonChecked(hDlg, id) ? "yes" : "no");
} else { } else {
GetDlgItemText(hDlg, id, value, sizeof(value)); GetDlgItemText(hDlg, id, value, sizeof(value));
} }
default_value = options[i + 2] == NULL ? "" : options[i + 2]; default_value = options[i * 2 + 1] == NULL ? "" : options[i * 2 + 1];
// If value is the same as default, skip it // If value is the same as default, skip it
if (strcmp(value, default_value) != 0) { if (strcmp(value, default_value) != 0) {
fprintf(fp, "%s %s\n", name, value); fprintf(fp, "%s %s\n", name, value);
...@@ -457,23 +457,23 @@ static BOOL CALLBACK DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lP) { ...@@ -457,23 +457,23 @@ static BOOL CALLBACK DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lP) {
EnableWindow(GetDlgItem(hDlg, ID_SAVE), TRUE); EnableWindow(GetDlgItem(hDlg, ID_SAVE), TRUE);
break; break;
case ID_RESET_DEFAULTS: case ID_RESET_DEFAULTS:
for (i = 0; options[i] != NULL; i += 3) { for (i = 0; options[i * 2] != NULL; i++) {
name = options[i + 1]; name = options[i * 2];
value = options[i + 2] == NULL ? "" : options[i + 2]; value = options[i * 2 + 1] == NULL ? "" : options[i * 2 + 1];
if (is_boolean_option(name)) { if (is_boolean_option(name)) {
CheckDlgButton(hDlg, ID_CONTROLS + i / 3, !strcmp(value, "yes") ? CheckDlgButton(hDlg, ID_CONTROLS + i, !strcmp(value, "yes") ?
BST_CHECKED : BST_UNCHECKED); BST_CHECKED : BST_UNCHECKED);
} else { } else {
SetWindowText(GetDlgItem(hDlg, ID_CONTROLS + i / 3), value); SetWindowText(GetDlgItem(hDlg, ID_CONTROLS + i), value);
} }
} }
break; break;
} }
for (i = 0; options[i] != NULL; i += 3) { for (i = 0; options[i * 2] != NULL; i++) {
name = options[i + 1]; name = options[i * 2];
if ((is_filename_option(name) || is_directory_option(name)) && if ((is_filename_option(name) || is_directory_option(name)) &&
LOWORD(wParam) == ID_CONTROLS + i / 3 + ID_FILE_BUTTONS_DELTA) { LOWORD(wParam) == ID_CONTROLS + i + ID_FILE_BUTTONS_DELTA) {
OPENFILENAME of; OPENFILENAME of;
BROWSEINFO bi; BROWSEINFO bi;
char path[PATH_MAX] = ""; char path[PATH_MAX] = "";
...@@ -498,7 +498,7 @@ static BOOL CALLBACK DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lP) { ...@@ -498,7 +498,7 @@ static BOOL CALLBACK DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lP) {
} }
if (path[0] != '\0') { if (path[0] != '\0') {
SetWindowText(GetDlgItem(hDlg, ID_CONTROLS + i / 3), path); SetWindowText(GetDlgItem(hDlg, ID_CONTROLS + i), path);
} }
} }
} }
...@@ -510,14 +510,14 @@ static BOOL CALLBACK DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lP) { ...@@ -510,14 +510,14 @@ static BOOL CALLBACK DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lP) {
SendMessage(hDlg, WM_SETICON,(WPARAM) ICON_BIG, (LPARAM) hIcon); SendMessage(hDlg, WM_SETICON,(WPARAM) ICON_BIG, (LPARAM) hIcon);
SetWindowText(hDlg, "Mongoose settings"); SetWindowText(hDlg, "Mongoose settings");
SetFocus(GetDlgItem(hDlg, ID_SAVE)); SetFocus(GetDlgItem(hDlg, ID_SAVE));
for (i = 0; options[i] != NULL; i += 3) { for (i = 0; options[i * 2] != NULL; i++) {
name = options[i + 1]; name = options[i * 2];
value = mg_get_option(ctx, name); value = mg_get_option(ctx, name);
if (is_boolean_option(name)) { if (is_boolean_option(name)) {
CheckDlgButton(hDlg, ID_CONTROLS + i / 3, !strcmp(value, "yes") ? CheckDlgButton(hDlg, ID_CONTROLS + i, !strcmp(value, "yes") ?
BST_CHECKED : BST_UNCHECKED); BST_CHECKED : BST_UNCHECKED);
} else { } else {
SetDlgItemText(hDlg, ID_CONTROLS + i / 3, value == NULL ? "" : value); SetDlgItemText(hDlg, ID_CONTROLS + i, value == NULL ? "" : value);
} }
} }
break; break;
...@@ -594,8 +594,8 @@ static void show_settings_dialog() { ...@@ -594,8 +594,8 @@ static void show_settings_dialog() {
p = mem + sizeof(dialog_header); p = mem + sizeof(dialog_header);
option_names = mg_get_valid_option_names(); option_names = mg_get_valid_option_names();
for (i = 0; option_names[i] != NULL; i += 3) { for (i = 0; option_names[i * 2] != NULL; i++) {
long_option_name = option_names[i + 1]; long_option_name = option_names[i * 2];
style = WS_CHILD | WS_VISIBLE | WS_TABSTOP; style = WS_CHILD | WS_VISIBLE | WS_TABSTOP;
x = 10 + (WIDTH / 2) * (nelems % 2); x = 10 + (WIDTH / 2) * (nelems % 2);
y = (nelems/2 + 1) * HEIGHT + 5; y = (nelems/2 + 1) * HEIGHT + 5;
...@@ -613,7 +613,7 @@ static void show_settings_dialog() { ...@@ -613,7 +613,7 @@ static void show_settings_dialog() {
width -= 20; width -= 20;
cl = 0x81; cl = 0x81;
add_control(&p, dia, 0x80, add_control(&p, dia, 0x80,
ID_CONTROLS + (i / 3) + ID_FILE_BUTTONS_DELTA, ID_CONTROLS + i + ID_FILE_BUTTONS_DELTA,
WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
(WORD) (x + width + LABEL_WIDTH + 5), (WORD) (x + width + LABEL_WIDTH + 5),
y, 15, 12, "..."); y, 15, 12, "...");
...@@ -623,7 +623,7 @@ static void show_settings_dialog() { ...@@ -623,7 +623,7 @@ static void show_settings_dialog() {
} }
add_control(&p, dia, 0x82, ID_STATIC, WS_VISIBLE | WS_CHILD, add_control(&p, dia, 0x82, ID_STATIC, WS_VISIBLE | WS_CHILD,
x, y, LABEL_WIDTH, HEIGHT, long_option_name); x, y, LABEL_WIDTH, HEIGHT, long_option_name);
add_control(&p, dia, cl, ID_CONTROLS + (i / 3), style, add_control(&p, dia, cl, ID_CONTROLS + i, style,
(WORD) (x + LABEL_WIDTH), y, width, 12, ""); (WORD) (x + LABEL_WIDTH), y, width, 12, "");
nelems++; nelems++;
} }
......
...@@ -440,34 +440,33 @@ enum { ...@@ -440,34 +440,33 @@ enum {
}; };
static const char *config_options[] = { static const char *config_options[] = {
"C", "cgi_pattern", "**.cgi$|**.pl$|**.php$", "cgi_pattern", "**.cgi$|**.pl$|**.php$",
"E", "cgi_environment", NULL, "cgi_environment", NULL,
"G", "put_delete_auth_file", NULL, "put_delete_auth_file", NULL,
"I", "cgi_interpreter", NULL, "cgi_interpreter", NULL,
"P", "protect_uri", NULL, "protect_uri", NULL,
"R", "authentication_domain", "mydomain.com", "authentication_domain", "mydomain.com",
"S", "ssi_pattern", "**.shtml$|**.shtm$", "ssi_pattern", "**.shtml$|**.shtm$",
"T", "throttle", NULL, "throttle", NULL,
"a", "access_log_file", NULL, "access_log_file", NULL,
"d", "enable_directory_listing", "yes", "enable_directory_listing", "yes",
"e", "error_log_file", NULL, "error_log_file", NULL,
"g", "global_auth_file", NULL, "global_auth_file", NULL,
"i", "index_files", "index_files",
"index.html,index.htm,index.cgi,index.shtml,index.php,index.lp", "index.html,index.htm,index.cgi,index.shtml,index.php,index.lp",
"k", "enable_keep_alive", "no", "enable_keep_alive", "no",
"l", "access_control_list", NULL, "access_control_list", NULL,
"m", "extra_mime_types", NULL, "extra_mime_types", NULL,
"p", "listening_ports", "8080", "listening_ports", "8080",
"r", "document_root", ".", "document_root", ".",
"s", "ssl_certificate", NULL, "ssl_certificate", NULL,
"t", "num_threads", "50", "num_threads", "50",
"u", "run_as_user", NULL, "run_as_user", NULL,
"w", "url_rewrite_patterns", NULL, "url_rewrite_patterns", NULL,
"x", "hide_files_patterns", NULL, "hide_files_patterns", NULL,
"z", "request_timeout_ms", "30000", "request_timeout_ms", "30000",
NULL NULL
}; };
#define ENTRIES_PER_CONFIG_OPTION 3
struct mg_context { struct mg_context {
volatile int stop_flag; // Should we stop event loop volatile int stop_flag; // Should we stop event loop
...@@ -557,10 +556,9 @@ static void mg_fclose(struct file *filep) { ...@@ -557,10 +556,9 @@ static void mg_fclose(struct file *filep) {
static int get_option_index(const char *name) { static int get_option_index(const char *name) {
int i; int i;
for (i = 0; config_options[i] != NULL; i += ENTRIES_PER_CONFIG_OPTION) { for (i = 0; config_options[i * 2] != NULL; i++) {
if (strcmp(config_options[i], name) == 0 || if (strcmp(config_options[i * 2], name) == 0) {
strcmp(config_options[i + 1], name) == 0) { return i;
return i / ENTRIES_PER_CONFIG_OPTION;
} }
} }
return -1; return -1;
...@@ -5285,13 +5283,10 @@ struct mg_context *mg_start(const struct mg_callbacks *callbacks, ...@@ -5285,13 +5283,10 @@ struct mg_context *mg_start(const struct mg_callbacks *callbacks,
} }
// Set default value if needed // Set default value if needed
for (i = 0; config_options[i * ENTRIES_PER_CONFIG_OPTION] != NULL; i++) { for (i = 0; config_options[i * 2] != NULL; i++) {
default_value = config_options[i * ENTRIES_PER_CONFIG_OPTION + 2]; default_value = config_options[i * 2 + 1];
if (ctx->config[i] == NULL && default_value != NULL) { if (ctx->config[i] == NULL && default_value != NULL) {
ctx->config[i] = mg_strdup(default_value); ctx->config[i] = mg_strdup(default_value);
DEBUG_TRACE(("Setting default: [%s] -> [%s]",
config_options[i * ENTRIES_PER_CONFIG_OPTION + 1],
default_value));
} }
} }
......
...@@ -155,7 +155,7 @@ if (scalar(@ARGV) > 0 and $ARGV[0] eq 'unit') { ...@@ -155,7 +155,7 @@ if (scalar(@ARGV) > 0 and $ARGV[0] eq 'unit') {
# Command line options override config files settings # Command line options override config files settings
write_file($config, "access_log_file access.log\n" . write_file($config, "access_log_file access.log\n" .
"listening_ports 127.0.0.1:12345\n"); "listening_ports 127.0.0.1:12345\n");
spawn("$exe -p 127.0.0.1:$port"); spawn("$exe -listening_ports 127.0.0.1:$port");
o("GET /test/hello.txt HTTP/1.0\n\n", 'HTTP/1.1 200 OK', 'Loading config file'); o("GET /test/hello.txt HTTP/1.0\n\n", 'HTTP/1.1 200 OK', 'Loading config file');
unlink $config; unlink $config;
kill_spawned_child(); kill_spawned_child();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment