aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-07-25 03:20:25 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2010-07-25 03:20:25 +0200
commit535ce1df5cb6a2bf588e1c2655cf09f49ed455db (patch)
tree20baee3aa8211e04c1ed3e1771963f1aae578705
parent451add4f23c14459734e05104ea0bc5ed4de39ee (diff)
downloadbusybox-w32-535ce1df5cb6a2bf588e1c2655cf09f49ed455db.tar.gz
busybox-w32-535ce1df5cb6a2bf588e1c2655cf09f49ed455db.tar.bz2
busybox-w32-535ce1df5cb6a2bf588e1c2655cf09f49ed455db.zip
httpd: cosmetic fixes, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/httpd.c53
1 files changed, 23 insertions, 30 deletions
diff --git a/networking/httpd.c b/networking/httpd.c
index 8ad7e88b1..12bad597a 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -5,23 +5,20 @@
5 * Copyright (C) 2002,2003 Glenn Engel <glenne@engel.org> 5 * Copyright (C) 2002,2003 Glenn Engel <glenne@engel.org>
6 * Copyright (C) 2003-2006 Vladimir Oleynik <dzo@simtreas.ru> 6 * Copyright (C) 2003-2006 Vladimir Oleynik <dzo@simtreas.ru>
7 * 7 *
8 * simplify patch stolen from libbb without using strdup
9 *
10 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 8 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
11 * 9 *
12 ***************************************************************************** 10 *****************************************************************************
13 * 11 *
14 * Typical usage: 12 * Typical usage:
15 * for non root user 13 * For non root user:
16 * httpd -p 8080 -h $HOME/public_html 14 * httpd -p 8080 -h $HOME/public_html
17 * or for daemon start from rc script with uid=0: 15 * For daemon start from rc script with uid=0:
18 * httpd -u www 16 * httpd -u www
19 * This is equivalent if www user have uid=80 to 17 * which is equivalent to (assuming user www has uid 80):
20 * httpd -p 80 -u 80 -h /www -c /etc/httpd.conf -r "Web Server Authentication" 18 * httpd -p 80 -u 80 -h $PWD -c /etc/httpd.conf -r "Web Server Authentication"
21 *
22 * 19 *
23 * When an url starts by "/cgi-bin/" it is assumed to be a cgi script. The 20 * When an url starts with "/cgi-bin/" it is assumed to be a cgi script.
24 * server changes directory to the location of the script and executes it 21 * The server changes directory to the location of the script and executes it
25 * after setting QUERY_STRING and other environment variables. 22 * after setting QUERY_STRING and other environment variables.
26 * 23 *
27 * Doc: 24 * Doc:
@@ -29,8 +26,8 @@
29 * 26 *
30 * The applet can also be invoked as an url arg decoder and html text encoder 27 * The applet can also be invoked as an url arg decoder and html text encoder
31 * as follows: 28 * as follows:
32 * foo=`httpd -d $foo` # decode "Hello%20World" as "Hello World" 29 * foo=`httpd -d $foo` # decode "Hello%20World" as "Hello World"
33 * bar=`httpd -e "<Hello World>"` # encode as "&#60Hello&#32World&#62" 30 * bar=`httpd -e "<Hello World>"` # encode as "&#60Hello&#32World&#62"
34 * Note that url encoding for arguments is not the same as html encoding for 31 * Note that url encoding for arguments is not the same as html encoding for
35 * presentation. -d decodes an url-encoded argument while -e encodes in html 32 * presentation. -d decodes an url-encoded argument while -e encodes in html
36 * for page display. 33 * for page display.
@@ -100,15 +97,14 @@
100#if ENABLE_FEATURE_HTTPD_USE_SENDFILE 97#if ENABLE_FEATURE_HTTPD_USE_SENDFILE
101# include <sys/sendfile.h> 98# include <sys/sendfile.h>
102#endif 99#endif
103
104#define DEBUG 0
105
106#define IOBUF_SIZE 8192 /* IO buffer */
107
108/* amount of buffering in a pipe */ 100/* amount of buffering in a pipe */
109#ifndef PIPE_BUF 101#ifndef PIPE_BUF
110# define PIPE_BUF 4096 102# define PIPE_BUF 4096
111#endif 103#endif
104
105#define DEBUG 0
106
107#define IOBUF_SIZE 8192
112#if PIPE_BUF >= IOBUF_SIZE 108#if PIPE_BUF >= IOBUF_SIZE
113# error "PIPE_BUF >= IOBUF_SIZE" 109# error "PIPE_BUF >= IOBUF_SIZE"
114#endif 110#endif
@@ -118,6 +114,7 @@
118static const char DEFAULT_PATH_HTTPD_CONF[] ALIGN1 = "/etc"; 114static const char DEFAULT_PATH_HTTPD_CONF[] ALIGN1 = "/etc";
119static const char HTTPD_CONF[] ALIGN1 = "httpd.conf"; 115static const char HTTPD_CONF[] ALIGN1 = "httpd.conf";
120static const char HTTP_200[] ALIGN1 = "HTTP/1.0 200 OK\r\n"; 116static const char HTTP_200[] ALIGN1 = "HTTP/1.0 200 OK\r\n";
117static const char index_html[] ALIGN1 = "index.html";
121 118
122typedef struct has_next_ptr { 119typedef struct has_next_ptr {
123 struct has_next_ptr *next; 120 struct has_next_ptr *next;
@@ -170,7 +167,6 @@ enum {
170 HTTP_PAYMENT_REQUIRED = 402, 167 HTTP_PAYMENT_REQUIRED = 402,
171 HTTP_BAD_GATEWAY = 502, 168 HTTP_BAD_GATEWAY = 502,
172 HTTP_SERVICE_UNAVAILABLE = 503, /* overload, maintenance */ 169 HTTP_SERVICE_UNAVAILABLE = 503, /* overload, maintenance */
173 HTTP_RESPONSE_SETSIZE = 0xffffffff
174#endif 170#endif
175}; 171};
176 172
@@ -231,9 +227,6 @@ static const struct {
231#endif 227#endif
232}; 228};
233 229
234static const char index_html[] ALIGN1 = "index.html";
235
236
237struct globals { 230struct globals {
238 int verbose; /* must be int (used by getopt32) */ 231 int verbose; /* must be int (used by getopt32) */
239 smallint flg_deny_all; 232 smallint flg_deny_all;
@@ -777,7 +770,7 @@ static char *encodeString(const char *string)
777 char *p = out; 770 char *p = out;
778 char ch; 771 char ch;
779 772
780 while ((ch = *string++)) { 773 while ((ch = *string++) != '\0') {
781 /* very simple check for what to encode */ 774 /* very simple check for what to encode */
782 if (isalnum(ch)) 775 if (isalnum(ch))
783 *p++ = ch; 776 *p++ = ch;
@@ -787,7 +780,7 @@ static char *encodeString(const char *string)
787 *p = '\0'; 780 *p = '\0';
788 return out; 781 return out;
789} 782}
790#endif /* FEATURE_HTTPD_ENCODE_URL_STR */ 783#endif
791 784
792/* 785/*
793 * Given a URL encoded string, convert it to plain ascii. 786 * Given a URL encoded string, convert it to plain ascii.
@@ -814,12 +807,12 @@ static unsigned hex_to_bin(unsigned char c)
814 if (v <= 5) 807 if (v <= 5)
815 return v + 10; 808 return v + 10;
816 return ~0; 809 return ~0;
817}
818/* For testing: 810/* For testing:
819void t(char c) { printf("'%c'(%u) %u\n", c, c, hex_to_bin(c)); } 811void t(char c) { printf("'%c'(%u) %u\n", c, c, hex_to_bin(c)); }
820int main() { t(0x10); t(0x20); t('0'); t('9'); t('A'); t('F'); t('a'); t('f'); 812int main() { t(0x10); t(0x20); t('0'); t('9'); t('A'); t('F'); t('a'); t('f');
821t('0'-1); t('9'+1); t('A'-1); t('F'+1); t('a'-1); t('f'+1); return 0; } 813t('0'-1); t('9'+1); t('A'-1); t('F'+1); t('a'-1); t('f'+1); return 0; }
822*/ 814*/
815}
823static char *decodeString(char *orig, int option_d) 816static char *decodeString(char *orig, int option_d)
824{ 817{
825 /* note that decoded string is always shorter than original */ 818 /* note that decoded string is always shorter than original */
@@ -1964,7 +1957,7 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
1964 if (http_major_version >= '0') { 1957 if (http_major_version >= '0') {
1965 /* Request was with "... HTTP/nXXX", and n >= 0 */ 1958 /* Request was with "... HTTP/nXXX", and n >= 0 */
1966 1959
1967 /* Read until blank line for HTTP version specified, else parse immediate */ 1960 /* Read until blank line */
1968 while (1) { 1961 while (1) {
1969 if (!get_line()) 1962 if (!get_line())
1970 break; /* EOF or error or empty line */ 1963 break; /* EOF or error or empty line */
@@ -1991,9 +1984,9 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
1991 if ((STRNCASECMP(iobuf, "Content-length:") == 0)) { 1984 if ((STRNCASECMP(iobuf, "Content-length:") == 0)) {
1992 /* extra read only for POST */ 1985 /* extra read only for POST */
1993 if (prequest != request_GET 1986 if (prequest != request_GET
1994#if ENABLE_FEATURE_HTTPD_CGI 1987# if ENABLE_FEATURE_HTTPD_CGI
1995 && prequest != request_HEAD 1988 && prequest != request_HEAD
1996#endif 1989# endif
1997 ) { 1990 ) {
1998 tptr = skip_whitespace(iobuf + sizeof("Content-length:") - 1); 1991 tptr = skip_whitespace(iobuf + sizeof("Content-length:") - 1);
1999 if (!tptr[0]) 1992 if (!tptr[0])
@@ -2183,9 +2176,9 @@ static void mini_httpd(int server_socket)
2183 /* Wait for connections... */ 2176 /* Wait for connections... */
2184 fromAddr.len = LSA_SIZEOF_SA; 2177 fromAddr.len = LSA_SIZEOF_SA;
2185 n = accept(server_socket, &fromAddr.u.sa, &fromAddr.len); 2178 n = accept(server_socket, &fromAddr.u.sa, &fromAddr.len);
2186
2187 if (n < 0) 2179 if (n < 0)
2188 continue; 2180 continue;
2181
2189 /* set the KEEPALIVE option to cull dead connections */ 2182 /* set the KEEPALIVE option to cull dead connections */
2190 setsockopt(n, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1)); 2183 setsockopt(n, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1));
2191 2184
@@ -2226,9 +2219,9 @@ static void mini_httpd_nommu(int server_socket, int argc, char **argv)
2226 /* Wait for connections... */ 2219 /* Wait for connections... */
2227 fromAddr.len = LSA_SIZEOF_SA; 2220 fromAddr.len = LSA_SIZEOF_SA;
2228 n = accept(server_socket, &fromAddr.u.sa, &fromAddr.len); 2221 n = accept(server_socket, &fromAddr.u.sa, &fromAddr.len);
2229
2230 if (n < 0) 2222 if (n < 0)
2231 continue; 2223 continue;
2224
2232 /* set the KEEPALIVE option to cull dead connections */ 2225 /* set the KEEPALIVE option to cull dead connections */
2233 setsockopt(n, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1)); 2226 setsockopt(n, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1));
2234 2227