From a6bbcc43cf436d1acaae1e0e3fcbb82bb5a6fec9 Mon Sep 17 00:00:00 2001 From: Lammert Bies Date: Wed, 28 Dec 2016 03:59:52 +0100 Subject: [PATCH] enable_directory_listing now fast --- src/httplib_config_options.c | 1 - src/httplib_handle_propfind.c | 4 +--- src/httplib_handle_request.c | 7 ++----- src/httplib_main.h | 2 +- src/httplib_send_file.c | 7 ++----- src/httplib_start.c | 6 ++++-- 6 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/httplib_config_options.c b/src/httplib_config_options.c index 60557513..30976e13 100644 --- a/src/httplib_config_options.c +++ b/src/httplib_config_options.c @@ -41,7 +41,6 @@ struct httplib_option XX_httplib_config_options[] = { { "ssi_pattern", CONFIG_TYPE_EXT_PATTERN, "**.shtml$|**.shtm$" }, { "throttle", CONFIG_TYPE_STRING, NULL }, { "access_log_file", CONFIG_TYPE_FILE, NULL }, - { "enable_directory_listing", CONFIG_TYPE_BOOLEAN, "yes" }, { "error_log_file", CONFIG_TYPE_FILE, NULL }, { "global_auth_file", CONFIG_TYPE_FILE, NULL }, { "index_files", CONFIG_TYPE_STRING, "index.xhtml,index.html,index.htm,index.cgi,index.shtml,index.php" }, diff --git a/src/httplib_handle_propfind.c b/src/httplib_handle_propfind.c index f97c4f74..2e195d3e 100644 --- a/src/httplib_handle_propfind.c +++ b/src/httplib_handle_propfind.c @@ -101,7 +101,6 @@ void XX_httplib_handle_propfind( struct httplib_connection *conn, const char *pa const char *depth; char date[64]; time_t curtime; - const char *edl; if ( conn == NULL || conn->ctx == NULL || path == NULL || filep == NULL ) return; if ( conn->ctx->cfg[DOCUMENT_ROOT] == NULL ) return; @@ -129,8 +128,7 @@ void XX_httplib_handle_propfind( struct httplib_connection *conn, const char *pa * If it is a directory, print directory entries too if Depth is not 0 */ - edl = conn->ctx->cfg[ENABLE_DIRECTORY_LISTING]; - if ( filep && filep->is_directory && edl != NULL && ! httplib_strcasecmp( edl, "yes" ) && ( depth == NULL || strcmp( depth, "0" ) != 0 ) ) { + if ( conn->ctx->enable_directory_listing && filep && filep->is_directory && ( depth == NULL || strcmp( depth, "0" ) != 0 ) ) { XX_httplib_scan_directory( conn, path, conn, &print_dav_dir_entry ); } diff --git a/src/httplib_handle_request.c b/src/httplib_handle_request.c index e3988007..6e1592b3 100644 --- a/src/httplib_handle_request.c +++ b/src/httplib_handle_request.c @@ -59,7 +59,6 @@ void XX_httplib_handle_request( struct httplib_connection *conn ) { void *callback_data; httplib_authorization_handler auth_handler; void *auth_callback_data; - const char *edl; time_t curtime; char date[64]; union { @@ -518,10 +517,8 @@ no_callback_resource: * 14.2. no substitute file */ - edl = conn->ctx->cfg[ENABLE_DIRECTORY_LISTING]; - - if ( edl != NULL && ! httplib_strcasecmp( edl, "yes" ) ) XX_httplib_handle_directory_request( conn, path ); - else XX_httplib_send_http_error( conn, 403, "%s", "Error: Directory listing denied" ); + if ( conn->ctx->enable_directory_listing ) XX_httplib_handle_directory_request( conn, path ); + else XX_httplib_send_http_error( conn, 403, "%s", "Error: Directory listing denied" ); return; } diff --git a/src/httplib_main.h b/src/httplib_main.h index 4bd0483e..07bb18bf 100644 --- a/src/httplib_main.h +++ b/src/httplib_main.h @@ -400,7 +400,6 @@ enum { SSI_EXTENSIONS, THROTTLE, ACCESS_LOG_FILE, - ENABLE_DIRECTORY_LISTING, ERROR_LOG_FILE, GLOBAL_PASSWORDS_FILE, INDEX_FILES, @@ -610,6 +609,7 @@ struct httplib_context { #ifdef USE_TIMERS struct ttimers *timers; #endif + bool enable_directory_listing; bool allow_sendfile_call; }; diff --git a/src/httplib_send_file.c b/src/httplib_send_file.c index 5b5c3dff..515a5925 100644 --- a/src/httplib_send_file.c +++ b/src/httplib_send_file.c @@ -37,17 +37,14 @@ void httplib_send_file( struct httplib_connection *conn, const char *path, const char *mime_type, const char *additional_headers ) { struct file file = STRUCT_FILE_INITIALIZER; - const char *edl; if ( XX_httplib_stat( conn, path, &file ) ) { if ( file.is_directory ) { - if ( conn == NULL ) return; + if ( conn == NULL || conn->ctx == NULL ) return; - edl = conn->ctx->cfg[ENABLE_DIRECTORY_LISTING]; - - if ( edl != NULL && ! httplib_strcasecmp( edl, "yes" ) ) XX_httplib_handle_directory_request( conn, path ); + if ( conn->ctx->enable_directory_listing ) XX_httplib_handle_directory_request( conn, path ); else XX_httplib_send_http_error( conn, 403, "%s", "Error: Directory listing denied" ); } diff --git a/src/httplib_start.c b/src/httplib_start.c index 7e404b07..ce6d4e5a 100644 --- a/src/httplib_start.c +++ b/src/httplib_start.c @@ -284,11 +284,13 @@ static bool process_options ( struct httplib_context *ctx, const struct httplib_ if ( ctx == NULL ) return false; - ctx->allow_sendfile_call = true; + ctx->allow_sendfile_call = true; + ctx->enable_directory_listing = true; while ( options != NULL && options->name != NULL ) { - if ( ! strcmp( options->name, "allow_sendfile_call" ) ) ctx->allow_sendfile_call = XX_httplib_option_value_to_bool( options->value ); + if ( ! httplib_strcasecmp( options->name, "allow_sendfile_call" ) ) ctx->allow_sendfile_call = XX_httplib_option_value_to_bool( options->value ); + else if ( ! httplib_strcasecmp( options->name, "enable_directory_listing" ) ) ctx->enable_directory_listing = XX_httplib_option_value_to_bool( options->value ); else {