mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-17 10:49:47 +00:00
Moved options handling to src/options.c
This commit is contained in:
1 parent
a8da1b3334
commit
199e0a330f
4 files changed
+86
-82
No files matched your search
+2
-1
@@ -26,7 +26,8 @@ VERSION = $(shell perl -lne \
|
||||
'print $$1 if /define\s+MONGOOSE_VERSION\s+"(\S+)"/' ../mongoose.c)
|
||||
|
||||
# The order in which files are listed is important
|
||||
SOURCES = src/internal.h src/string.c src/parse_date.c src/mongoose.c
|
||||
SOURCES = src/internal.h src/string.c src/parse_date.c src/options.c \
|
||||
src/mongoose.c
|
||||
|
||||
TINY_SOURCES = ../mongoose.c main.c
|
||||
LUA_SOURCES = $(TINY_SOURCES) sqlite3.c lsqlite3.c lua_5.2.1.c
|
||||
|
||||
@@ -1,43 +1,10 @@
|
||||
#include "internal.h"
|
||||
|
||||
static const char *config_options[] = {
|
||||
"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", NULL,
|
||||
"ssl_certificate", NULL,
|
||||
"num_threads", "50",
|
||||
"run_as_user", NULL,
|
||||
"url_rewrite_patterns", NULL,
|
||||
"hide_files_patterns", NULL,
|
||||
"request_timeout_ms", "30000",
|
||||
NULL
|
||||
};
|
||||
|
||||
// Return number of bytes left to read for this connection
|
||||
static int64_t left_to_read(const struct mg_connection *conn) {
|
||||
return conn->content_len + conn->request_len - conn->num_bytes_read;
|
||||
}
|
||||
|
||||
const char **mg_get_valid_option_names(void) {
|
||||
return config_options;
|
||||
}
|
||||
|
||||
static int call_user(int type, struct mg_connection *conn, void *p) {
|
||||
if (conn != NULL && conn->ctx != NULL) {
|
||||
conn->event.user_data = conn->ctx->user_data;
|
||||
@@ -61,28 +28,6 @@ static FILE *mg_fopen(const char *path, const char *mode) {
|
||||
#endif
|
||||
}
|
||||
|
||||
static int get_option_index(const char *name) {
|
||||
int i;
|
||||
|
||||
for (i = 0; config_options[i * 2] != NULL; i++) {
|
||||
if (strcmp(config_options[i * 2], name) == 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *mg_get_option(const struct mg_context *ctx, const char *name) {
|
||||
int i;
|
||||
if ((i = get_option_index(name)) == -1) {
|
||||
return NULL;
|
||||
} else if (ctx->config[i] == NULL) {
|
||||
return "";
|
||||
} else {
|
||||
return ctx->config[i];
|
||||
}
|
||||
}
|
||||
|
||||
static void sockaddr_to_string(char *buf, size_t len,
|
||||
const union usa *usa) {
|
||||
buf[0] = '\0';
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
#include "internal.h"
|
||||
|
||||
// This array must be in sync with enum in internal.h
|
||||
static const char *config_options[] = {
|
||||
"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", NULL,
|
||||
"ssl_certificate", NULL,
|
||||
"num_threads", "50",
|
||||
"run_as_user", NULL,
|
||||
"url_rewrite_patterns", NULL,
|
||||
"hide_files_patterns", NULL,
|
||||
"request_timeout_ms", "30000",
|
||||
NULL
|
||||
};
|
||||
|
||||
const char **mg_get_valid_option_names(void) {
|
||||
return config_options;
|
||||
}
|
||||
|
||||
static int get_option_index(const char *name) {
|
||||
int i;
|
||||
|
||||
for (i = 0; config_options[i * 2] != NULL; i++) {
|
||||
if (strcmp(config_options[i * 2], name) == 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *mg_get_option(const struct mg_context *ctx, const char *name) {
|
||||
int i;
|
||||
if ((i = get_option_index(name)) == -1) {
|
||||
return NULL;
|
||||
} else if (ctx->config[i] == NULL) {
|
||||
return "";
|
||||
} else {
|
||||
return ctx->config[i];
|
||||
}
|
||||
}
|
||||
+27
-26
@@ -751,6 +751,7 @@ static time_t parse_date_string(const char *datetime) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// This array must be in sync with enum in internal.h
|
||||
static const char *config_options[] = {
|
||||
"cgi_pattern", "**.cgi$|**.pl$|**.php$",
|
||||
"cgi_environment", NULL,
|
||||
@@ -780,15 +781,37 @@ static const char *config_options[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
const char **mg_get_valid_option_names(void) {
|
||||
return config_options;
|
||||
}
|
||||
|
||||
static int get_option_index(const char *name) {
|
||||
int i;
|
||||
|
||||
for (i = 0; config_options[i * 2] != NULL; i++) {
|
||||
if (strcmp(config_options[i * 2], name) == 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *mg_get_option(const struct mg_context *ctx, const char *name) {
|
||||
int i;
|
||||
if ((i = get_option_index(name)) == -1) {
|
||||
return NULL;
|
||||
} else if (ctx->config[i] == NULL) {
|
||||
return "";
|
||||
} else {
|
||||
return ctx->config[i];
|
||||
}
|
||||
}
|
||||
|
||||
// Return number of bytes left to read for this connection
|
||||
static int64_t left_to_read(const struct mg_connection *conn) {
|
||||
return conn->content_len + conn->request_len - conn->num_bytes_read;
|
||||
}
|
||||
|
||||
const char **mg_get_valid_option_names(void) {
|
||||
return config_options;
|
||||
}
|
||||
|
||||
static int call_user(int type, struct mg_connection *conn, void *p) {
|
||||
if (conn != NULL && conn->ctx != NULL) {
|
||||
conn->event.user_data = conn->ctx->user_data;
|
||||
@@ -812,28 +835,6 @@ static FILE *mg_fopen(const char *path, const char *mode) {
|
||||
#endif
|
||||
}
|
||||
|
||||
static int get_option_index(const char *name) {
|
||||
int i;
|
||||
|
||||
for (i = 0; config_options[i * 2] != NULL; i++) {
|
||||
if (strcmp(config_options[i * 2], name) == 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *mg_get_option(const struct mg_context *ctx, const char *name) {
|
||||
int i;
|
||||
if ((i = get_option_index(name)) == -1) {
|
||||
return NULL;
|
||||
} else if (ctx->config[i] == NULL) {
|
||||
return "";
|
||||
} else {
|
||||
return ctx->config[i];
|
||||
}
|
||||
}
|
||||
|
||||
static void sockaddr_to_string(char *buf, size_t len,
|
||||
const union usa *usa) {
|
||||
buf[0] = '\0';
|
||||
|
||||
Reference in new issue
Block a user