diff --git a/build/Makefile b/build/Makefile index c2f3f4e4..e6da9481 100644 --- a/build/Makefile +++ b/build/Makefile @@ -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 diff --git a/build/src/mongoose.c b/build/src/mongoose.c index 2b9be5c6..c68b09dc 100644 --- a/build/src/mongoose.c +++ b/build/src/mongoose.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'; diff --git a/build/src/options.c b/build/src/options.c new file mode 100644 index 00000000..38a9e9ea --- /dev/null +++ b/build/src/options.c @@ -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]; + } +} diff --git a/mongoose.c b/mongoose.c index 83f986df..1a9ec6cb 100644 --- a/mongoose.c +++ b/mongoose.c @@ -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';