diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-11-10 23:28:57 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-11-10 23:28:57 +0000 |
commit | 6c5e5a0e85af5016600d70a06db8563e17ad3814 (patch) | |
tree | 6993fbce9c9a260aa2611b1bacfda9ad83671b6b | |
parent | 067e3f031a2107c69d287d89b9543fbfe5c0a571 (diff) | |
download | busybox-w32-6c5e5a0e85af5016600d70a06db8563e17ad3814.tar.gz busybox-w32-6c5e5a0e85af5016600d70a06db8563e17ad3814.tar.bz2 busybox-w32-6c5e5a0e85af5016600d70a06db8563e17ad3814.zip |
httpd: cosmetic fixes (the bug which was being hunted down
turned out to be nonexistent :)
-rw-r--r-- | networking/httpd.c | 96 |
1 files changed, 45 insertions, 51 deletions
diff --git a/networking/httpd.c b/networking/httpd.c index 3b12df673..a64fcb138 100644 --- a/networking/httpd.c +++ b/networking/httpd.c | |||
@@ -951,7 +951,7 @@ static int sendHeaders(HttpResponseNum responseNum) | |||
951 | ****************************************************************************/ | 951 | ****************************************************************************/ |
952 | static int getLine(void) | 952 | static int getLine(void) |
953 | { | 953 | { |
954 | int count = 0; | 954 | int count = 0; |
955 | char *buf = config->buf; | 955 | char *buf = config->buf; |
956 | 956 | ||
957 | while (read(a_c_r, buf + count, 1) == 1) { | 957 | while (read(a_c_r, buf + count, 1) == 1) { |
@@ -960,7 +960,7 @@ static int getLine(void) | |||
960 | buf[count] = 0; | 960 | buf[count] = 0; |
961 | return count; | 961 | return count; |
962 | } | 962 | } |
963 | if (count < (MAX_MEMORY_BUFF-1)) /* check owerflow */ | 963 | if (count < (MAX_MEMORY_BUFF-1)) /* check overflow */ |
964 | count++; | 964 | count++; |
965 | } | 965 | } |
966 | if (count) return count; | 966 | if (count) return count; |
@@ -991,8 +991,8 @@ static int getLine(void) | |||
991 | * | 991 | * |
992 | ****************************************************************************/ | 992 | ****************************************************************************/ |
993 | static int sendCgi(const char *url, | 993 | static int sendCgi(const char *url, |
994 | const char *request, int bodyLen, const char *cookie, | 994 | const char *request, int bodyLen, const char *cookie, |
995 | const char *content_type) | 995 | const char *content_type) |
996 | { | 996 | { |
997 | int fromCgi[2]; /* pipe for reading data from CGI */ | 997 | int fromCgi[2]; /* pipe for reading data from CGI */ |
998 | int toCgi[2]; /* pipe for sending data to CGI */ | 998 | int toCgi[2]; /* pipe for sending data to CGI */ |
@@ -1265,7 +1265,7 @@ static int sendCgi(const char *url, | |||
1265 | * | 1265 | * |
1266 | > $Function: sendFile() | 1266 | > $Function: sendFile() |
1267 | * | 1267 | * |
1268 | * $Description: Send a file response to an HTTP request | 1268 | * $Description: Send a file response to a HTTP request |
1269 | * | 1269 | * |
1270 | * $Parameter: | 1270 | * $Parameter: |
1271 | * (const char *) url . . The URL requested. | 1271 | * (const char *) url . . The URL requested. |
@@ -1455,8 +1455,8 @@ set_remoteuser_var: | |||
1455 | 1455 | ||
1456 | static void handle_sigalrm(int sig) | 1456 | static void handle_sigalrm(int sig) |
1457 | { | 1457 | { |
1458 | sendHeaders(HTTP_REQUEST_TIMEOUT); | 1458 | sendHeaders(HTTP_REQUEST_TIMEOUT); |
1459 | config->alarm_signaled = sig; | 1459 | config->alarm_signaled = sig; |
1460 | } | 1460 | } |
1461 | 1461 | ||
1462 | /**************************************************************************** | 1462 | /**************************************************************************** |
@@ -1487,7 +1487,7 @@ static void handleIncoming(void) | |||
1487 | struct sigaction sa; | 1487 | struct sigaction sa; |
1488 | 1488 | ||
1489 | #if ENABLE_FEATURE_HTTPD_BASIC_AUTH | 1489 | #if ENABLE_FEATURE_HTTPD_BASIC_AUTH |
1490 | int credentials = -1; /* if not requred this is Ok */ | 1490 | int credentials = -1; /* if not required this is Ok */ |
1491 | #endif | 1491 | #endif |
1492 | 1492 | ||
1493 | sa.sa_handler = handle_sigalrm; | 1493 | sa.sa_handler = handle_sigalrm; |
@@ -1530,7 +1530,7 @@ BAD_REQUEST: | |||
1530 | /* Garbled request/URL */ | 1530 | /* Garbled request/URL */ |
1531 | goto BAD_REQUEST; | 1531 | goto BAD_REQUEST; |
1532 | } | 1532 | } |
1533 | url = alloca(strlen(buf) + 12); /* + sizeof("/index.html\0") */ | 1533 | url = alloca(strlen(buf) + sizeof("/index.html")); |
1534 | if (url == NULL) { | 1534 | if (url == NULL) { |
1535 | sendHeaders(HTTP_INTERNAL_SERVER_ERROR); | 1535 | sendHeaders(HTTP_INTERNAL_SERVER_ERROR); |
1536 | break; | 1536 | break; |
@@ -1707,21 +1707,18 @@ FORBIDDEN: /* protect listing /cgi-bin */ | |||
1707 | /* unset if non inetd looped */ | 1707 | /* unset if non inetd looped */ |
1708 | config->ContentLength = -1; | 1708 | config->ContentLength = -1; |
1709 | #endif | 1709 | #endif |
1710 | |||
1711 | #if ENABLE_FEATURE_HTTPD_CGI | 1710 | #if ENABLE_FEATURE_HTTPD_CGI |
1712 | } | 1711 | } |
1713 | } | 1712 | } |
1714 | #endif | 1713 | #endif |
1715 | |||
1716 | } while (0); | 1714 | } while (0); |
1717 | 1715 | ||
1718 | |||
1719 | #if ENABLE_FEATURE_HTTPD_WITHOUT_INETD | 1716 | #if ENABLE_FEATURE_HTTPD_WITHOUT_INETD |
1720 | /* from inetd don't looping: freeing, closing automatic from exit always */ | 1717 | /* from inetd don't looping: freeing, closing automatic from exit always */ |
1721 | # if DEBUG | 1718 | # if DEBUG |
1722 | fprintf(stderr, "closing socket\n"); | 1719 | fprintf(stderr, "closing socket\n"); |
1723 | # endif | 1720 | # endif |
1724 | # ifdef CONFIG_FEATURE_HTTPD_CGI | 1721 | # if ENABLE_FEATURE_HTTPD_CGI |
1725 | free(cookie); | 1722 | free(cookie); |
1726 | free(content_type); | 1723 | free(content_type); |
1727 | free(config->referer); | 1724 | free(config->referer); |
@@ -1773,57 +1770,54 @@ static int miniHttpd(int server) | |||
1773 | 1770 | ||
1774 | /* copy the ports we are watching to the readfd set */ | 1771 | /* copy the ports we are watching to the readfd set */ |
1775 | while (1) { | 1772 | while (1) { |
1776 | readfd = portfd; | 1773 | int on, s; |
1774 | socklen_t fromAddrLen; | ||
1775 | struct sockaddr_in fromAddr; | ||
1777 | 1776 | ||
1778 | /* Now wait INDEFINITELY on the set of sockets! */ | 1777 | /* Now wait INDEFINITELY on the set of sockets! */ |
1779 | if (select(server + 1, &readfd, 0, 0, 0) > 0) { | 1778 | readfd = portfd; |
1780 | if (FD_ISSET(server, &readfd)) { | 1779 | if (select(server + 1, &readfd, 0, 0, 0) <= 0) |
1781 | int on; | 1780 | continue; |
1782 | struct sockaddr_in fromAddr; | 1781 | if (!FD_ISSET(server, &readfd)) |
1783 | 1782 | continue; | |
1784 | socklen_t fromAddrLen = sizeof(fromAddr); | 1783 | fromAddrLen = sizeof(fromAddr); |
1785 | int s = accept(server, | 1784 | s = accept(server, (struct sockaddr *)&fromAddr, &fromAddrLen); |
1786 | (struct sockaddr *)&fromAddr, &fromAddrLen); | 1785 | if (s < 0) |
1786 | continue; | ||
1787 | 1787 | ||
1788 | if (s < 0) { | 1788 | config->accepted_socket = s; |
1789 | continue; | 1789 | config->rmt_ip = ntohl(fromAddr.sin_addr.s_addr); |
1790 | } | ||
1791 | config->accepted_socket = s; | ||
1792 | config->rmt_ip = ntohl(fromAddr.sin_addr.s_addr); | ||
1793 | #if ENABLE_FEATURE_HTTPD_CGI || DEBUG | 1790 | #if ENABLE_FEATURE_HTTPD_CGI || DEBUG |
1794 | sprintf(config->rmt_ip_str, "%u.%u.%u.%u", | 1791 | sprintf(config->rmt_ip_str, "%u.%u.%u.%u", |
1795 | (unsigned char)(config->rmt_ip >> 24), | 1792 | (unsigned char)(config->rmt_ip >> 24), |
1796 | (unsigned char)(config->rmt_ip >> 16), | 1793 | (unsigned char)(config->rmt_ip >> 16), |
1797 | (unsigned char)(config->rmt_ip >> 8), | 1794 | (unsigned char)(config->rmt_ip >> 8), |
1798 | config->rmt_ip & 0xff); | 1795 | config->rmt_ip & 0xff); |
1799 | config->port = ntohs(fromAddr.sin_port); | 1796 | config->port = ntohs(fromAddr.sin_port); |
1800 | #if DEBUG | 1797 | #if DEBUG |
1801 | bb_error_msg("connection from IP=%s, port %u", | 1798 | bb_error_msg("connection from IP=%s, port %u", |
1802 | config->rmt_ip_str, config->port); | 1799 | config->rmt_ip_str, config->port); |
1803 | #endif | 1800 | #endif |
1804 | #endif /* CONFIG_FEATURE_HTTPD_CGI */ | 1801 | #endif /* CONFIG_FEATURE_HTTPD_CGI */ |
1805 | 1802 | ||
1806 | /* set the KEEPALIVE option to cull dead connections */ | 1803 | /* set the KEEPALIVE option to cull dead connections */ |
1807 | on = 1; | 1804 | on = 1; |
1808 | setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on)); | 1805 | setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on)); |
1809 | |||
1810 | #if !DEBUG | 1806 | #if !DEBUG |
1811 | if (fork() == 0) | 1807 | if (fork() == 0) |
1812 | #endif | 1808 | #endif |
1813 | { | 1809 | { |
1814 | /* This is the spawned thread */ | 1810 | /* This is the spawned thread */ |
1815 | #if ENABLE_FEATURE_HTTPD_RELOAD_CONFIG_SIGHUP | 1811 | #if ENABLE_FEATURE_HTTPD_RELOAD_CONFIG_SIGHUP |
1816 | /* protect reload config, may be confuse checking */ | 1812 | /* protect reload config, may be confuse checking */ |
1817 | signal(SIGHUP, SIG_IGN); | 1813 | signal(SIGHUP, SIG_IGN); |
1818 | #endif | 1814 | #endif |
1819 | handleIncoming(); | 1815 | handleIncoming(); |
1820 | #if !DEBUG | 1816 | #if !DEBUG |
1821 | exit(0); | 1817 | exit(0); |
1822 | #endif | 1818 | #endif |
1823 | } | ||
1824 | close(s); | ||
1825 | } | ||
1826 | } | 1819 | } |
1820 | close(s); | ||
1827 | } // while (1) | 1821 | } // while (1) |
1828 | return 0; | 1822 | return 0; |
1829 | } | 1823 | } |
@@ -1967,7 +1961,7 @@ int httpd_main(int argc, char *argv[]) | |||
1967 | xchdir(home_httpd); | 1961 | xchdir(home_httpd); |
1968 | #if ENABLE_FEATURE_HTTPD_WITHOUT_INETD | 1962 | #if ENABLE_FEATURE_HTTPD_WITHOUT_INETD |
1969 | config->server_socket = openServer(); | 1963 | config->server_socket = openServer(); |
1970 | # ifdef CONFIG_FEATURE_HTTPD_SETUID | 1964 | # if ENABLE_FEATURE_HTTPD_SETUID |
1971 | /* drop privileges */ | 1965 | /* drop privileges */ |
1972 | if (opt & OPT_SETUID) { | 1966 | if (opt & OPT_SETUID) { |
1973 | if (ugid.gid != (gid_t)-1) { | 1967 | if (ugid.gid != (gid_t)-1) { |
@@ -1990,7 +1984,7 @@ int httpd_main(int argc, char *argv[]) | |||
1990 | clearenv(); | 1984 | clearenv(); |
1991 | if (p) | 1985 | if (p) |
1992 | setenv("PATH", p, 1); | 1986 | setenv("PATH", p, 1); |
1993 | # ifdef CONFIG_FEATURE_HTTPD_WITHOUT_INETD | 1987 | # if ENABLE_FEATURE_HTTPD_WITHOUT_INETD |
1994 | addEnvPort("SERVER"); | 1988 | addEnvPort("SERVER"); |
1995 | # endif | 1989 | # endif |
1996 | } | 1990 | } |