summaryrefslogtreecommitdiff
path: root/networking/httpd.c
diff options
context:
space:
mode:
authorDenys Vlasenko2021-05-04 21:25:16 +0200
committerDenys Vlasenko2021-05-04 21:25:16 +0200
commit5b34a5594c6fc40b6183c50a42e3f86e4b441688 (patch)
tree937d01a38dedd1141e275c1b854b3c54954843ad /networking/httpd.c
parent1c698178858ac2b332849a2e24283e6060f9b179 (diff)
downloadbusybox-5b34a5594c6fc40b6183c50a42e3f86e4b441688.zip
busybox-5b34a5594c6fc40b6183c50a42e3f86e4b441688.tar.gz
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>
Diffstat (limited to 'networking/httpd.c')
-rw-r--r--networking/httpd.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/networking/httpd.c b/networking/httpd.c
index fc52faf..e48574e 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -679,7 +679,7 @@ enum {
SIGNALED_PARSE = 1, /* path will be "/etc" */
SUBDIR_PARSE = 2, /* path will be derived from URL */
};
-static void parse_conf(const char *path, int flag)
+static int parse_conf(const char *path, int flag)
{
/* internally used extra flag state */
enum { TRY_CURDIR_PARSE = 3 };
@@ -713,7 +713,7 @@ static void parse_conf(const char *path, int flag)
while ((f = fopen_for_read(filename)) == NULL) {
if (flag >= SUBDIR_PARSE) { /* SUBDIR or TRY_CURDIR */
/* config file not found, no changes to config */
- return;
+ return -1;
}
if (flag == FIRST_PARSE) {
/* -c CONFFILE given, but CONFFILE doesn't exist? */
@@ -971,6 +971,7 @@ static void parse_conf(const char *path, int flag)
} /* while (fgets) */
fclose(f);
+ return 0;
}
#if ENABLE_FEATURE_HTTPD_ENCODE_URL_STR
@@ -2363,12 +2364,9 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
while ((tptr = strchr(tptr + 1, '/')) != NULL) {
/* have path1/path2 */
*tptr = '\0';
-//TODO: can we avoid is_directory() test here?
- if (is_directory(urlcopy + 1, /*followlinks:*/ 1)) {
- /* may have subdir config */
- parse_conf(urlcopy + 1, SUBDIR_PARSE);
+ /* may have subdir config */
+ if (parse_conf(urlcopy + 1, SUBDIR_PARSE) == 0)
if_ip_denied_send_HTTP_FORBIDDEN_and_exit(remote_ip);
- }
*tptr = '/';
}
@@ -2420,9 +2418,9 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
else if (urlp[-1] == '/') {
/* It's a dir URL and there is no index.html
* Try cgi-bin/index.cgi */
- if (access("/cgi-bin/index.cgi"+1, X_OK) == 0) {
- cgi_type = CGI_INDEX;
- }
+ if (access("/cgi-bin/index.cgi"+1, X_OK) != 0)
+ send_headers_and_exit(HTTP_NOT_FOUND);
+ cgi_type = CGI_INDEX;
}
#endif
urlp[0] = '\0';