aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2021-05-04 21:25:16 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2021-05-04 21:25:16 +0200
commit5b34a5594c6fc40b6183c50a42e3f86e4b441688 (patch)
tree937d01a38dedd1141e275c1b854b3c54954843ad
parent1c698178858ac2b332849a2e24283e6060f9b179 (diff)
downloadbusybox-w32-5b34a5594c6fc40b6183c50a42e3f86e4b441688.tar.gz
busybox-w32-5b34a5594c6fc40b6183c50a42e3f86e4b441688.tar.bz2
busybox-w32-5b34a5594c6fc40b6183c50a42e3f86e4b441688.zip
httpd: avoid extra stat() calls for "GET /dirname/" case
function old new delta parse_conf 1325 1332 +7 handle_incoming_and_exit 2173 2161 -12 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 7/-12) Total: -5 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/httpd.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/networking/httpd.c b/networking/httpd.c
index fc52fafea..e48574e4f 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -679,7 +679,7 @@ enum {
679 SIGNALED_PARSE = 1, /* path will be "/etc" */ 679 SIGNALED_PARSE = 1, /* path will be "/etc" */
680 SUBDIR_PARSE = 2, /* path will be derived from URL */ 680 SUBDIR_PARSE = 2, /* path will be derived from URL */
681}; 681};
682static void parse_conf(const char *path, int flag) 682static int parse_conf(const char *path, int flag)
683{ 683{
684 /* internally used extra flag state */ 684 /* internally used extra flag state */
685 enum { TRY_CURDIR_PARSE = 3 }; 685 enum { TRY_CURDIR_PARSE = 3 };
@@ -713,7 +713,7 @@ static void parse_conf(const char *path, int flag)
713 while ((f = fopen_for_read(filename)) == NULL) { 713 while ((f = fopen_for_read(filename)) == NULL) {
714 if (flag >= SUBDIR_PARSE) { /* SUBDIR or TRY_CURDIR */ 714 if (flag >= SUBDIR_PARSE) { /* SUBDIR or TRY_CURDIR */
715 /* config file not found, no changes to config */ 715 /* config file not found, no changes to config */
716 return; 716 return -1;
717 } 717 }
718 if (flag == FIRST_PARSE) { 718 if (flag == FIRST_PARSE) {
719 /* -c CONFFILE given, but CONFFILE doesn't exist? */ 719 /* -c CONFFILE given, but CONFFILE doesn't exist? */
@@ -971,6 +971,7 @@ static void parse_conf(const char *path, int flag)
971 } /* while (fgets) */ 971 } /* while (fgets) */
972 972
973 fclose(f); 973 fclose(f);
974 return 0;
974} 975}
975 976
976#if ENABLE_FEATURE_HTTPD_ENCODE_URL_STR 977#if ENABLE_FEATURE_HTTPD_ENCODE_URL_STR
@@ -2363,12 +2364,9 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
2363 while ((tptr = strchr(tptr + 1, '/')) != NULL) { 2364 while ((tptr = strchr(tptr + 1, '/')) != NULL) {
2364 /* have path1/path2 */ 2365 /* have path1/path2 */
2365 *tptr = '\0'; 2366 *tptr = '\0';
2366//TODO: can we avoid is_directory() test here? 2367 /* may have subdir config */
2367 if (is_directory(urlcopy + 1, /*followlinks:*/ 1)) { 2368 if (parse_conf(urlcopy + 1, SUBDIR_PARSE) == 0)
2368 /* may have subdir config */
2369 parse_conf(urlcopy + 1, SUBDIR_PARSE);
2370 if_ip_denied_send_HTTP_FORBIDDEN_and_exit(remote_ip); 2369 if_ip_denied_send_HTTP_FORBIDDEN_and_exit(remote_ip);
2371 }
2372 *tptr = '/'; 2370 *tptr = '/';
2373 } 2371 }
2374 2372
@@ -2420,9 +2418,9 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
2420 else if (urlp[-1] == '/') { 2418 else if (urlp[-1] == '/') {
2421 /* It's a dir URL and there is no index.html 2419 /* It's a dir URL and there is no index.html
2422 * Try cgi-bin/index.cgi */ 2420 * Try cgi-bin/index.cgi */
2423 if (access("/cgi-bin/index.cgi"+1, X_OK) == 0) { 2421 if (access("/cgi-bin/index.cgi"+1, X_OK) != 0)
2424 cgi_type = CGI_INDEX; 2422 send_headers_and_exit(HTTP_NOT_FOUND);
2425 } 2423 cgi_type = CGI_INDEX;
2426 } 2424 }
2427#endif 2425#endif
2428 urlp[0] = '\0'; 2426 urlp[0] = '\0';