aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--networking/httpd.c62
1 files changed, 32 insertions, 30 deletions
diff --git a/networking/httpd.c b/networking/httpd.c
index 9439e206c..b52526a78 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -392,7 +392,10 @@ static const struct {
392struct globals { 392struct globals {
393 int verbose; /* must be int (used by getopt32) */ 393 int verbose; /* must be int (used by getopt32) */
394 smallint flg_deny_all; 394 smallint flg_deny_all;
395 395#if ENABLE_FEATURE_HTTPD_GZIP
396 /* client can handle gzip / we are going to send gzip */
397 smallint content_gzip;
398#endif
396 unsigned rmt_ip; /* used for IP-based allow/deny rules */ 399 unsigned rmt_ip; /* used for IP-based allow/deny rules */
397 time_t last_mod; 400 time_t last_mod;
398 char *rmt_ip_str; /* for $REMOTE_ADDR and $REMOTE_PORT */ 401 char *rmt_ip_str; /* for $REMOTE_ADDR and $REMOTE_PORT */
@@ -440,14 +443,15 @@ struct globals {
440#if ENABLE_FEATURE_HTTPD_PROXY 443#if ENABLE_FEATURE_HTTPD_PROXY
441 Htaccess_Proxy *proxy; 444 Htaccess_Proxy *proxy;
442#endif 445#endif
443#if ENABLE_FEATURE_HTTPD_GZIP
444 /* client can handle gzip / we are going to send gzip */
445 smallint content_gzip;
446#endif
447}; 446};
448#define G (*ptr_to_globals) 447#define G (*ptr_to_globals)
449#define verbose (G.verbose ) 448#define verbose (G.verbose )
450#define flg_deny_all (G.flg_deny_all ) 449#define flg_deny_all (G.flg_deny_all )
450#if ENABLE_FEATURE_HTTPD_GZIP
451# define content_gzip (G.content_gzip )
452#else
453# define content_gzip 0
454#endif
451#define rmt_ip (G.rmt_ip ) 455#define rmt_ip (G.rmt_ip )
452#define bind_addr_or_port (G.bind_addr_or_port) 456#define bind_addr_or_port (G.bind_addr_or_port)
453#define g_query (G.g_query ) 457#define g_query (G.g_query )
@@ -481,11 +485,6 @@ enum {
481#define hdr_cnt (G.hdr_cnt ) 485#define hdr_cnt (G.hdr_cnt )
482#define http_error_page (G.http_error_page ) 486#define http_error_page (G.http_error_page )
483#define proxy (G.proxy ) 487#define proxy (G.proxy )
484#if ENABLE_FEATURE_HTTPD_GZIP
485# define content_gzip (G.content_gzip )
486#else
487# define content_gzip 0
488#endif
489#define INIT_G() do { \ 488#define INIT_G() do { \
490 setup_common_bufsiz(); \ 489 setup_common_bufsiz(); \
491 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ 490 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
@@ -944,7 +943,7 @@ static char *encodeString(const char *string)
944 if (isalnum(ch)) 943 if (isalnum(ch))
945 *p++ = ch; 944 *p++ = ch;
946 else 945 else
947 p += sprintf(p, "&#%d;", (unsigned char) ch); 946 p += sprintf(p, "&#%u;", (unsigned char) ch);
948 } 947 }
949 *p = '\0'; 948 *p = '\0';
950 return out; 949 return out;
@@ -1040,7 +1039,7 @@ static void log_and_exit(void)
1040 * second packet is delayed for any reason. 1039 * second packet is delayed for any reason.
1041 * responseNum - the result code to send. 1040 * responseNum - the result code to send.
1042 */ 1041 */
1043static void send_headers(int responseNum) 1042static void send_headers(unsigned responseNum)
1044{ 1043{
1045 static const char RFC1123FMT[] ALIGN1 = "%a, %d %b %Y %H:%M:%S GMT"; 1044 static const char RFC1123FMT[] ALIGN1 = "%a, %d %b %Y %H:%M:%S GMT";
1046 /* Fixed size 29-byte string. Example: Sun, 06 Nov 1994 08:49:37 GMT */ 1045 /* Fixed size 29-byte string. Example: Sun, 06 Nov 1994 08:49:37 GMT */
@@ -1052,9 +1051,9 @@ static void send_headers(int responseNum)
1052#if ENABLE_FEATURE_HTTPD_ERROR_PAGES 1051#if ENABLE_FEATURE_HTTPD_ERROR_PAGES
1053 const char *error_page = NULL; 1052 const char *error_page = NULL;
1054#endif 1053#endif
1054 unsigned len;
1055 unsigned i; 1055 unsigned i;
1056 time_t timer = time(NULL); 1056 time_t timer = time(NULL);
1057 int len;
1058 1057
1059 for (i = 0; i < ARRAY_SIZE(http_response_type); i++) { 1058 for (i = 0; i < ARRAY_SIZE(http_response_type); i++) {
1060 if (http_response_type[i] == responseNum) { 1059 if (http_response_type[i] == responseNum) {
@@ -1078,16 +1077,21 @@ static void send_headers(int responseNum)
1078 strftime(date_str, sizeof(date_str), RFC1123FMT, gmtime_r(&timer, &tm)); 1077 strftime(date_str, sizeof(date_str), RFC1123FMT, gmtime_r(&timer, &tm));
1079 /* ^^^ using gmtime_r() instead of gmtime() to not use static data */ 1078 /* ^^^ using gmtime_r() instead of gmtime() to not use static data */
1080 len = sprintf(iobuf, 1079 len = sprintf(iobuf,
1081 "HTTP/1.0 %d %s\r\n" 1080 "HTTP/1.0 %u %s\r\n"
1082 "Content-type: %s\r\n"
1083 "Date: %s\r\n" 1081 "Date: %s\r\n"
1084 "Connection: close\r\n", 1082 "Connection: close\r\n",
1085 responseNum, responseString, 1083 responseNum, responseString,
1086 /* if it's error message, then it's HTML */
1087 (responseNum == HTTP_OK ? found_mime_type : "text/html"),
1088 date_str 1084 date_str
1089 ); 1085 );
1090 1086
1087 if (responseNum != HTTP_OK || found_mime_type) {
1088 len += sprintf(iobuf + len,
1089 "Content-type: %s\r\n",
1090 /* if it's error message, then it's HTML */
1091 (responseNum != HTTP_OK ? "text/html" : found_mime_type)
1092 );
1093 }
1094
1091#if ENABLE_FEATURE_HTTPD_BASIC_AUTH 1095#if ENABLE_FEATURE_HTTPD_BASIC_AUTH
1092 if (responseNum == HTTP_UNAUTHORIZED) { 1096 if (responseNum == HTTP_UNAUTHORIZED) {
1093 len += sprintf(iobuf + len, 1097 len += sprintf(iobuf + len,
@@ -1147,9 +1151,9 @@ static void send_headers(int responseNum)
1147 "Accept-Ranges: bytes\r\n" 1151 "Accept-Ranges: bytes\r\n"
1148#endif 1152#endif
1149 "Last-Modified: %s\r\n" 1153 "Last-Modified: %s\r\n"
1150 "%s %"OFF_FMT"u\r\n", 1154 "%s-Length: %"OFF_FMT"u\r\n",
1151 date_str, 1155 date_str,
1152 content_gzip ? "Transfer-Length:" : "Content-Length:", 1156 content_gzip ? "Transfer" : "Content",
1153 file_size 1157 file_size
1154 ); 1158 );
1155 } 1159 }
@@ -1161,8 +1165,8 @@ static void send_headers(int responseNum)
1161 iobuf[len++] = '\n'; 1165 iobuf[len++] = '\n';
1162 if (infoString) { 1166 if (infoString) {
1163 len += sprintf(iobuf + len, 1167 len += sprintf(iobuf + len,
1164 "<HTML><HEAD><TITLE>%d %s</TITLE></HEAD>\n" 1168 "<HTML><HEAD><TITLE>%u %s</TITLE></HEAD>\n"
1165 "<BODY><H1>%d %s</H1>\n" 1169 "<BODY><H1>%u %s</H1>\n"
1166 "%s\n" 1170 "%s\n"
1167 "</BODY></HTML>\n", 1171 "</BODY></HTML>\n",
1168 responseNum, responseString, 1172 responseNum, responseString,
@@ -1300,9 +1304,9 @@ static NOINLINE void cgi_io_loop_and_exit(int fromCgi_rd, int toCgi_wr, int post
1300 continue; 1304 continue;
1301 } 1305 }
1302 if (DEBUG && WIFEXITED(status)) 1306 if (DEBUG && WIFEXITED(status))
1303 bb_error_msg("CGI exited, status=%d", WEXITSTATUS(status)); 1307 bb_error_msg("CGI exited, status=%u", WEXITSTATUS(status));
1304 if (DEBUG && WIFSIGNALED(status)) 1308 if (DEBUG && WIFSIGNALED(status))
1305 bb_error_msg("CGI killed, signal=%d", WTERMSIG(status)); 1309 bb_error_msg("CGI killed, signal=%u", WTERMSIG(status));
1306#endif 1310#endif
1307 break; 1311 break;
1308 } 1312 }
@@ -1533,7 +1537,7 @@ static void send_cgi_and_exit(
1533 if (G.http_accept_language) 1537 if (G.http_accept_language)
1534 setenv1("HTTP_ACCEPT_LANGUAGE", G.http_accept_language); 1538 setenv1("HTTP_ACCEPT_LANGUAGE", G.http_accept_language);
1535 if (post_len) 1539 if (post_len)
1536 putenv(xasprintf("CONTENT_LENGTH=%d", post_len)); 1540 putenv(xasprintf("CONTENT_LENGTH=%u", post_len));
1537 if (cookie) 1541 if (cookie)
1538 setenv1("HTTP_COOKIE", cookie); 1542 setenv1("HTTP_COOKIE", cookie);
1539 if (content_type) 1543 if (content_type)
@@ -1684,8 +1688,8 @@ static NOINLINE void send_file_and_exit(const char *url, int what)
1684 * (happens if you abort downloads from local httpd): */ 1688 * (happens if you abort downloads from local httpd): */
1685 signal(SIGPIPE, SIG_IGN); 1689 signal(SIGPIPE, SIG_IGN);
1686 1690
1687 /* If not found, default is "application/octet-stream" */ 1691 /* If not found, default is to not send "Content-type:" */
1688 found_mime_type = "application/octet-stream"; 1692 /*found_mime_type = NULL; - already is */
1689 suffix = strrchr(url, '.'); 1693 suffix = strrchr(url, '.');
1690 if (suffix) { 1694 if (suffix) {
1691 static const char suffixTable[] ALIGN1 = 1695 static const char suffixTable[] ALIGN1 =
@@ -2543,11 +2547,9 @@ static void mini_httpd_nommu(int server_socket, int argc, char **argv)
2543 */ 2547 */
2544 while (1) { 2548 while (1) {
2545 int n; 2549 int n;
2546 len_and_sockaddr fromAddr;
2547 2550
2548 /* Wait for connections... */ 2551 /* Wait for connections... */
2549 fromAddr.len = LSA_SIZEOF_SA; 2552 n = accept(server_socket, NULL, NULL);
2550 n = accept(server_socket, &fromAddr.u.sa, &fromAddr.len);
2551 if (n < 0) 2553 if (n < 0)
2552 continue; 2554 continue;
2553 2555
@@ -2734,7 +2736,7 @@ int httpd_main(int argc UNUSED_PARAM, char **argv)
2734 2736
2735 xfunc_error_retval = 0; 2737 xfunc_error_retval = 0;
2736 if (opt & OPT_INETD) 2738 if (opt & OPT_INETD)
2737 mini_httpd_inetd(); 2739 mini_httpd_inetd(); /* never returns */
2738#if BB_MMU 2740#if BB_MMU
2739 if (!(opt & OPT_FOREGROUND)) 2741 if (!(opt & OPT_FOREGROUND))
2740 bb_daemonize(0); /* don't change current directory */ 2742 bb_daemonize(0); /* don't change current directory */