mirror of
https://github.com/lammertb/libhttp.git
synced 2026-01-03 16:02:30 +03:00
Removed support for option names
This commit is contained in:
58
main.c
58
main.c
@@ -99,18 +99,18 @@ static void show_usage_and_exit(void) {
|
||||
const char **names;
|
||||
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__);
|
||||
fprintf(stderr, "Usage:\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, "\nOPTIONS:\n");
|
||||
|
||||
names = mg_get_valid_option_names();
|
||||
for (i = 0; names[i] != NULL; i += 3) {
|
||||
fprintf(stderr, " -%s %s (default: \"%s\")\n",
|
||||
names[i], names[i + 1], names[i + 2] == NULL ? "" : names[i + 2]);
|
||||
for (i = 0; names[i] != NULL; i += 2) {
|
||||
fprintf(stderr, " -%s %s\n",
|
||||
names[i], names[i + 1] == NULL ? "<empty>" : names[i + 1]);
|
||||
}
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@@ -153,9 +153,9 @@ static void create_config_file(const char *path) {
|
||||
} else if ((fp = fopen(path, "a+")) != NULL) {
|
||||
fprintf(fp, "%s", config_file_top_comment);
|
||||
names = mg_get_valid_option_names();
|
||||
for (i = 0; names[i] != NULL; i += 3) {
|
||||
value = mg_get_option(ctx, names[i]);
|
||||
fprintf(fp, "# %s %s\n", names[i + 1], *value ? value : "<value>");
|
||||
for (i = 0; names[i * 2] != NULL; i++) {
|
||||
value = mg_get_option(ctx, names[i * 2]);
|
||||
fprintf(fp, "# %s %s\n", names[i * 2], value ? value : "<value>");
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
@@ -417,16 +417,16 @@ static void save_config(HWND hDlg, FILE *fp) {
|
||||
|
||||
fprintf(fp, "%s", config_file_top_comment);
|
||||
options = mg_get_valid_option_names();
|
||||
for (i = 0; options[i] != NULL; i += 3) {
|
||||
name = options[i + 1];
|
||||
id = ID_CONTROLS + i / 3;
|
||||
for (i = 0; options[i * 2] != NULL; i++) {
|
||||
name = options[i * 2];
|
||||
id = ID_CONTROLS + i;
|
||||
if (is_boolean_option(name)) {
|
||||
snprintf(value, sizeof(value), "%s",
|
||||
IsDlgButtonChecked(hDlg, id) ? "yes" : "no");
|
||||
} else {
|
||||
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 (strcmp(value, default_value) != 0) {
|
||||
fprintf(fp, "%s %s\n", name, value);
|
||||
@@ -457,23 +457,23 @@ static BOOL CALLBACK DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lP) {
|
||||
EnableWindow(GetDlgItem(hDlg, ID_SAVE), TRUE);
|
||||
break;
|
||||
case ID_RESET_DEFAULTS:
|
||||
for (i = 0; options[i] != NULL; i += 3) {
|
||||
name = options[i + 1];
|
||||
value = options[i + 2] == NULL ? "" : options[i + 2];
|
||||
for (i = 0; options[i * 2] != NULL; i++) {
|
||||
name = options[i * 2];
|
||||
value = options[i * 2 + 1] == NULL ? "" : options[i * 2 + 1];
|
||||
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);
|
||||
} else {
|
||||
SetWindowText(GetDlgItem(hDlg, ID_CONTROLS + i / 3), value);
|
||||
SetWindowText(GetDlgItem(hDlg, ID_CONTROLS + i), value);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
for (i = 0; options[i] != NULL; i += 3) {
|
||||
name = options[i + 1];
|
||||
for (i = 0; options[i * 2] != NULL; i++) {
|
||||
name = options[i * 2];
|
||||
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;
|
||||
BROWSEINFO bi;
|
||||
char path[PATH_MAX] = "";
|
||||
@@ -498,7 +498,7 @@ static BOOL CALLBACK DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lP) {
|
||||
}
|
||||
|
||||
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) {
|
||||
SendMessage(hDlg, WM_SETICON,(WPARAM) ICON_BIG, (LPARAM) hIcon);
|
||||
SetWindowText(hDlg, "Mongoose settings");
|
||||
SetFocus(GetDlgItem(hDlg, ID_SAVE));
|
||||
for (i = 0; options[i] != NULL; i += 3) {
|
||||
name = options[i + 1];
|
||||
for (i = 0; options[i * 2] != NULL; i++) {
|
||||
name = options[i * 2];
|
||||
value = mg_get_option(ctx, 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);
|
||||
} else {
|
||||
SetDlgItemText(hDlg, ID_CONTROLS + i / 3, value == NULL ? "" : value);
|
||||
SetDlgItemText(hDlg, ID_CONTROLS + i, value == NULL ? "" : value);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -594,8 +594,8 @@ static void show_settings_dialog() {
|
||||
p = mem + sizeof(dialog_header);
|
||||
|
||||
option_names = mg_get_valid_option_names();
|
||||
for (i = 0; option_names[i] != NULL; i += 3) {
|
||||
long_option_name = option_names[i + 1];
|
||||
for (i = 0; option_names[i * 2] != NULL; i++) {
|
||||
long_option_name = option_names[i * 2];
|
||||
style = WS_CHILD | WS_VISIBLE | WS_TABSTOP;
|
||||
x = 10 + (WIDTH / 2) * (nelems % 2);
|
||||
y = (nelems/2 + 1) * HEIGHT + 5;
|
||||
@@ -613,7 +613,7 @@ static void show_settings_dialog() {
|
||||
width -= 20;
|
||||
cl = 0x81;
|
||||
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,
|
||||
(WORD) (x + width + LABEL_WIDTH + 5),
|
||||
y, 15, 12, "...");
|
||||
@@ -623,7 +623,7 @@ static void show_settings_dialog() {
|
||||
}
|
||||
add_control(&p, dia, 0x82, ID_STATIC, WS_VISIBLE | WS_CHILD,
|
||||
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, "");
|
||||
nelems++;
|
||||
}
|
||||
|
||||
65
mongoose.c
65
mongoose.c
@@ -440,34 +440,33 @@ enum {
|
||||
};
|
||||
|
||||
static const char *config_options[] = {
|
||||
"C", "cgi_pattern", "**.cgi$|**.pl$|**.php$",
|
||||
"E", "cgi_environment", NULL,
|
||||
"G", "put_delete_auth_file", NULL,
|
||||
"I", "cgi_interpreter", NULL,
|
||||
"P", "protect_uri", NULL,
|
||||
"R", "authentication_domain", "mydomain.com",
|
||||
"S", "ssi_pattern", "**.shtml$|**.shtm$",
|
||||
"T", "throttle", NULL,
|
||||
"a", "access_log_file", NULL,
|
||||
"d", "enable_directory_listing", "yes",
|
||||
"e", "error_log_file", NULL,
|
||||
"g", "global_auth_file", NULL,
|
||||
"i", "index_files",
|
||||
"index.html,index.htm,index.cgi,index.shtml,index.php,index.lp",
|
||||
"k", "enable_keep_alive", "no",
|
||||
"l", "access_control_list", NULL,
|
||||
"m", "extra_mime_types", NULL,
|
||||
"p", "listening_ports", "8080",
|
||||
"r", "document_root", ".",
|
||||
"s", "ssl_certificate", NULL,
|
||||
"t", "num_threads", "50",
|
||||
"u", "run_as_user", NULL,
|
||||
"w", "url_rewrite_patterns", NULL,
|
||||
"x", "hide_files_patterns", NULL,
|
||||
"z", "request_timeout_ms", "30000",
|
||||
"cgi_pattern", "**.cgi$|**.pl$|**.php$",
|
||||
"cgi_environment", NULL,
|
||||
"put_delete_auth_file", NULL,
|
||||
"cgi_interpreter", NULL,
|
||||
"protect_uri", NULL,
|
||||
"authentication_domain", "mydomain.com",
|
||||
"ssi_pattern", "**.shtml$|**.shtm$",
|
||||
"throttle", NULL,
|
||||
"access_log_file", NULL,
|
||||
"enable_directory_listing", "yes",
|
||||
"error_log_file", NULL,
|
||||
"global_auth_file", NULL,
|
||||
"index_files",
|
||||
"index.html,index.htm,index.cgi,index.shtml,index.php,index.lp",
|
||||
"enable_keep_alive", "no",
|
||||
"access_control_list", NULL,
|
||||
"extra_mime_types", NULL,
|
||||
"listening_ports", "8080",
|
||||
"document_root", ".",
|
||||
"ssl_certificate", NULL,
|
||||
"num_threads", "50",
|
||||
"run_as_user", NULL,
|
||||
"url_rewrite_patterns", NULL,
|
||||
"hide_files_patterns", NULL,
|
||||
"request_timeout_ms", "30000",
|
||||
NULL
|
||||
};
|
||||
#define ENTRIES_PER_CONFIG_OPTION 3
|
||||
|
||||
struct mg_context {
|
||||
volatile int stop_flag; // Should we stop event loop
|
||||
@@ -557,10 +556,9 @@ static void mg_fclose(struct file *filep) {
|
||||
static int get_option_index(const char *name) {
|
||||
int i;
|
||||
|
||||
for (i = 0; config_options[i] != NULL; i += ENTRIES_PER_CONFIG_OPTION) {
|
||||
if (strcmp(config_options[i], name) == 0 ||
|
||||
strcmp(config_options[i + 1], name) == 0) {
|
||||
return i / ENTRIES_PER_CONFIG_OPTION;
|
||||
for (i = 0; config_options[i * 2] != NULL; i++) {
|
||||
if (strcmp(config_options[i * 2], name) == 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
@@ -5285,13 +5283,10 @@ struct mg_context *mg_start(const struct mg_callbacks *callbacks,
|
||||
}
|
||||
|
||||
// Set default value if needed
|
||||
for (i = 0; config_options[i * ENTRIES_PER_CONFIG_OPTION] != NULL; i++) {
|
||||
default_value = config_options[i * ENTRIES_PER_CONFIG_OPTION + 2];
|
||||
for (i = 0; config_options[i * 2] != NULL; i++) {
|
||||
default_value = config_options[i * 2 + 1];
|
||||
if (ctx->config[i] == NULL && default_value != NULL) {
|
||||
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') {
|
||||
# Command line options override config files settings
|
||||
write_file($config, "access_log_file access.log\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');
|
||||
unlink $config;
|
||||
kill_spawned_child();
|
||||
|
||||
Reference in New Issue
Block a user