📄 thttpd_patch
字号:
diff -ur thttpd-2.21b/Makefile.in thttpd-2.21b-cool/Makefile.in--- thttpd-2.21b/Makefile.in Thu Mar 29 20:36:21 2001+++ thttpd-2.21b-cool/Makefile.in Sat Sep 20 14:43:20 2003@@ -46,13 +46,15 @@ # You shouldn't need to edit anything below here. +include php_makefile+ CC = @CC@ CCOPT = @V_CCOPT@ DEFS = @DEFS@-INCLS = -I.+INCLS = -I. $(PHP_CFLAGS) CFLAGS = $(CCOPT) $(DEFS) $(INCLS)-LDFLAGS = @LDFLAGS@-LIBS = @LIBS@+LDFLAGS = @LDFLAGS@ $(PHP_LDFLAGS)+LIBS = @LIBS@ $(PHP_LIBS) NETLIBS = @V_NETLIBS@ INSTALL = @INSTALL@ @@ -62,7 +64,7 @@ @rm -f $@ $(CC) $(CFLAGS) -c $*.c -SRC = thttpd.c libhttpd.c fdwatch.c mmc.c timers.c match.c tdate_parse.c syslog.c+SRC = thttpd.c libhttpd.c fdwatch.c mmc.c timers.c match.c tdate_parse.c syslog.c php_thttpd.c OBJ = $(SRC:.c=.o) @LIBOBJS@ @@ -77,7 +79,7 @@ all: this subdirs this: $(ALL) -thttpd: $(OBJ)+thttpd: $(OBJ) libphp4.a @rm -f $@ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) $(NETLIBS) diff -ur thttpd-2.21b/config.h thttpd-2.21b-cool/config.h--- thttpd-2.21b/config.h Mon Apr 9 23:57:36 2001+++ thttpd-2.21b-cool/config.h Sat Sep 20 14:43:20 2003@@ -82,6 +82,11 @@ */ #define IDLE_READ_TIMELIMIT 60 +/* CONFIGURE: How many seconds to allow for reading the subsequent requests+** on a keep-alive connection. Should be simiar to LINGER_TIME+*/+#define IDLE_KEEPALIVE_TIMELIMIT 2+ /* CONFIGURE: How many seconds before an idle connection gets closed. */ #define IDLE_SEND_TIMELIMIT 300@@ -316,7 +321,7 @@ /* CONFIGURE: A list of index filenames to check. The files are searched ** for in this order. */-#define INDEX_NAMES "index.html", "index.htm", "Default.htm", "index.cgi"+#define INDEX_NAMES "index.php", "index.html", "index.htm", "Default.htm", "index.cgi" /* CONFIGURE: If this is defined then thttpd will automatically generate ** index pages for directories that don't have an explicit index file.diff -ur thttpd-2.21b/configure thttpd-2.21b-cool/configure--- thttpd-2.21b/configure Sat Apr 21 02:07:14 2001+++ thttpd-2.21b-cool/configure Sat Sep 20 14:43:20 2003@@ -1021,7 +1021,7 @@ fi echo "$ac_t""$CPP" 1>&6 -for ac_hdr in fcntl.h grp.h memory.h paths.h poll.h sys/poll.h sys/event.h osreldate.h+for ac_hdr in fcntl.h grp.h memory.h paths.h poll.h sys/poll.h sys/event.h osreldate.h netinet/tcp.h do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6diff -ur thttpd-2.21b/configure.in thttpd-2.21b-cool/configure.in--- thttpd-2.21b/configure.in Sat Apr 21 02:06:23 2001+++ thttpd-2.21b-cool/configure.in Sat Sep 20 14:43:20 2003@@ -64,7 +64,7 @@ AC_MSG_RESULT(no) fi -AC_CHECK_HEADERS(fcntl.h grp.h memory.h paths.h poll.h sys/poll.h sys/event.h osreldate.h)+AC_CHECK_HEADERS(fcntl.h grp.h memory.h paths.h poll.h sys/poll.h sys/event.h osreldate.h netinet/tcp.h) AC_HEADER_TIME AC_HEADER_DIRENT diff -ur thttpd-2.21b/fdwatch.c thttpd-2.21b-cool/fdwatch.c--- thttpd-2.21b/fdwatch.c Fri Apr 13 07:36:08 2001+++ thttpd-2.21b-cool/fdwatch.c Sat Sep 20 14:43:20 2003@@ -419,6 +419,7 @@ if ( pollfds == (struct pollfd*) 0 || poll_fdidx == (int*) 0 || poll_rfdidx == (int*) 0 ) return -1;+ memset(pollfds, 0, sizeof(struct pollfd) * nfiles); return 0; } @@ -460,7 +461,7 @@ ridx = 0; for ( i = 0; i < npollfds; ++i )- if ( pollfds[i].revents & ( POLLIN | POLLOUT ) )+ if ( pollfds[i].revents & ( POLLIN | POLLOUT | POLLERR | POLLHUP | POLLNVAL ) ) poll_rfdidx[ridx++] = pollfds[i].fd; return r;@@ -472,8 +473,8 @@ { switch ( fd_rw[fd] ) {- case FDW_READ: return pollfds[poll_fdidx[fd]].revents & POLLIN;- case FDW_WRITE: return pollfds[poll_fdidx[fd]].revents & POLLOUT;+ case FDW_READ: return pollfds[poll_fdidx[fd]].revents & ( POLLIN | POLLERR | POLLHUP | POLLNVAL );+ case FDW_WRITE: return pollfds[poll_fdidx[fd]].revents & ( POLLOUT | POLLERR | POLLHUP | POLLNVAL ); default: return 0; } }diff -ur thttpd-2.21b/libhttpd.c thttpd-2.21b-cool/libhttpd.c--- thttpd-2.21b/libhttpd.c Tue Apr 24 00:42:40 2001+++ thttpd-2.21b-cool/libhttpd.c Sat Sep 20 14:43:29 2003@@ -56,6 +56,10 @@ #include <unistd.h> #include <stdarg.h> +#ifdef HAVE_NETINET_TCP_H+#include <netinet/tcp.h>+#endif+ #ifdef HAVE_OSRELDATE_H #include <osreldate.h> #endif /* HAVE_OSRELDATE_H */@@ -85,6 +89,12 @@ #include "match.h" #include "tdate_parse.h" +#include "php_thttpd.h"++#ifdef __CYGWIN__+# define timezone _timezone+#endif+ #ifndef STDIN_FILENO #define STDIN_FILENO 0 #endif@@ -111,7 +121,7 @@ static int initialize_listen_socket( httpd_sockaddr* saP ); static void unlisten( httpd_server* hs ); static void add_response( httpd_conn* hc, char* str );-static void send_mime( httpd_conn* hc, int status, char* title, char* encodings, char* extraheads, char* type, int length, time_t mod );+static void send_mime( httpd_conn* hc, int status, char* title, char* encodings, char* extraheads, char* type, int length, time_t mod, const char *, size_t ); static void send_response( httpd_conn* hc, int status, char* title, char* extraheads, char* form, char* arg ); static void send_response_tail( httpd_conn* hc ); static void defang( char* str, char* dfstr, int dfsize );@@ -242,6 +252,10 @@ free( (void*) hs->cwd ); if ( hs->cgi_pattern != (char*) 0 ) free( (void*) hs->cgi_pattern );+ if ( hs->php_pattern != (char*) 0 )+ free( (void*) hs->php_pattern );+ if ( hs->phps_pattern != (char*) 0 )+ free( (void*) hs->phps_pattern ); if ( hs->charset != (char*) 0 ) free( (void*) hs->charset ); if ( hs->url_pattern != (char*) 0 )@@ -249,6 +263,7 @@ if ( hs->local_pattern != (char*) 0 ) free( (void*) hs->local_pattern ); free( (void*) hs );+ thttpd_php_shutdown(); } @@ -257,7 +272,8 @@ char* hostname, httpd_sockaddr* sa4P, httpd_sockaddr* sa6P, int port, char* cgi_pattern, char* charset, char* cwd, int no_log, FILE* logfp, int no_symlink, int vhost, int global_passwd, char* url_pattern,- char* local_pattern, int no_empty_referers )+ char* local_pattern, int no_empty_referers, char* php_pattern,+ char* phps_pattern ) { httpd_server* hs; static char ghnbuf[256];@@ -312,6 +328,8 @@ } hs->port = port;+ hs->php_pattern = strdup(php_pattern);+ hs->phps_pattern = strdup(phps_pattern); if ( cgi_pattern == (char*) 0 ) hs->cgi_pattern = (char*) 0; else@@ -329,7 +347,7 @@ while ( ( cp = strstr( hs->cgi_pattern, "|/" ) ) != (char*) 0 ) (void) strcpy( cp + 1, cp + 2 ); }- hs->charset = strdup( charset );+ hs->charset = strdup( charset ); hs->cwd = strdup( cwd ); if ( hs->cwd == (char*) 0 ) {@@ -385,6 +403,8 @@ return (httpd_server*) 0; } + thttpd_php_init();+ /* Done initializing. */ if ( hs->binding_hostname == (char*) 0 ) syslog( LOG_INFO, "%.80s starting on port %d", SERVER_SOFTWARE, hs->port );@@ -418,6 +438,11 @@ } (void) fcntl( listen_fd, F_SETFD, 1 ); +#if defined(TCP_DEFER_ACCEPT) && defined(SOL_TCP)+ on = 30; /* give clients 30s to send first data packet */+ setsockopt(listen_fd, SOL_TCP, TCP_DEFER_ACCEPT, &on, sizeof(on));+#endif+ /* Allow reuse of local addresses. */ on = 1; if ( setsockopt(@@ -582,6 +607,9 @@ /* And send it, if necessary. */ if ( hc->responselen > 0 ) {+/*+printf("**RESPONSE [%d]** len = %d\n%*.*s\n", hc->conn_fd, hc->responselen, hc->responselen, hc->responselen, hc->response); +*/ (void) write( hc->conn_fd, hc->response, hc->responselen ); hc->responselen = 0; }@@ -619,18 +647,22 @@ } } +extern time_t httpd_time_now;+extern char httpd_now_buf[];++#define SMART_STR_USE_REALLOC++#include "ext/standard/php_smart_str.h" static void-send_mime( httpd_conn* hc, int status, char* title, char* encodings, char* extraheads, char* type, int length, time_t mod )+send_mime( httpd_conn* hc, int status, char* title, char* encodings, char* extraheads, char* type, int length, time_t mod, const char *last_modified, size_t last_modified_len) {- time_t now; const char* rfc1123fmt = "%a, %d %b %Y %H:%M:%S GMT";- char nowbuf[100]; char modbuf[100];- char fixed_type[500];- char buf[1000]; int partial_content;-+ smart_str s = {0};+ int type_len;+ hc->status = status; hc->bytes_to_send = length; if ( hc->mime_flag )@@ -649,41 +681,89 @@ else partial_content = 0; - now = time( (time_t*) 0 ); if ( mod == (time_t) 0 )- mod = now;- (void) strftime( nowbuf, sizeof(nowbuf), rfc1123fmt, gmtime( &now ) );- (void) strftime( modbuf, sizeof(modbuf), rfc1123fmt, gmtime( &mod ) );- (void) my_snprintf(- fixed_type, sizeof(fixed_type), type, hc->hs->charset );- (void) my_snprintf( buf, sizeof(buf),- "%.20s %d %s\r\nServer: %s\r\nContent-Type: %s\r\nDate: %s\r\nLast-Modified: %s\r\nAccept-Ranges: bytes\r\nConnection: close\r\n",- hc->protocol, status, title, EXPOSED_SERVER_SOFTWARE, fixed_type,- nowbuf, modbuf );- add_response( hc, buf );+ mod = httpd_time_now;+ + if (last_modified == 0) {+ (void) strftime( modbuf, sizeof(modbuf), rfc1123fmt, gmtime( &mod ) );+ last_modified = modbuf;+ last_modified_len = strlen(modbuf);+ }+ + type_len = strlen(type);+ + if (hc->response) {+ s.c = hc->response;+ s.len = 0;+ s.a = hc->maxresponse;+ hc->response = 0;+ hc->maxresponse = 0;+ }+ + smart_str_appends(&s, "HTTP/1.1 ");+ smart_str_append_long(&s, status);+ smart_str_appends(&s, " HTTP\r\nServer: " EXPOSED_SERVER_SOFTWARE "\r\n"+ "Content-Type: ");+ + if (type[type_len-2] == '%' && type[type_len-1] == 's') {+ smart_str_appendl(&s, type, type_len - 2);+ smart_str_appends(&s, hc->hs->charset);+ } else {+ smart_str_appendl(&s, type, type_len);+ }++ + smart_str_appends(&s, "\r\nDate: ");+ smart_str_appends(&s, httpd_now_buf);+ smart_str_appends(&s, "\r\nLast-Modified: ");+ smart_str_appendl(&s, last_modified, last_modified_len);+ smart_str_appends(&s, "\r\nAccept-Ranges: bytes\r\n");+ if ( encodings[0] != '\0' ) {- (void) my_snprintf( buf, sizeof(buf),- "Content-Encoding: %s\r\n", encodings );- add_response( hc, buf );+ smart_str_appends(&s, "Content-Encoding: ");+ smart_str_appends(&s, encodings);+ smart_str_appends(&s, "\r\n"); } if ( partial_content ) {- (void) my_snprintf( buf, sizeof(buf),- "Content-Range: bytes %ld-%ld/%d\r\nContent-Length: %ld\r\n",- (long) hc->init_byte_loc, (long) hc->end_byte_loc, length,- (long) ( hc->end_byte_loc - hc->init_byte_loc + 1 ) );- add_response( hc, buf );++ smart_str_appends(&s, "Content-Range: bytes ");+ smart_str_append_long(&s, hc->init_byte_loc);+ smart_str_appendc(&s, '-');+ smart_str_append_long(&s, hc->end_byte_loc);+ smart_str_appendc(&s, '/');+ smart_str_append_long(&s, length);+ smart_str_appends(&s, "\r\nContent-Length: ");+ smart_str_append_long(&s, hc->end_byte_loc - hc->init_byte_loc + 1);+ smart_str_appends(&s, "\r\n");+ } else if ( length >= 0 ) {- (void) my_snprintf( buf, sizeof(buf),- "Content-Length: %d\r\n", length );- add_response( hc, buf );+ smart_str_appends(&s, "Content-Length: ");+ smart_str_append_long(&s, length);+ smart_str_appends(&s, "\r\n"); }+ else {+ hc->do_keep_alive = 0;+ } if ( extraheads[0] != '\0' )- add_response( hc, extraheads );- add_response( hc, "\r\n" );+ smart_str_appends(&s, extraheads);+ if (hc->do_keep_alive) {+ smart_str_appends(&s, "Connection: keep-alive\r\n\r\n" );+ } else {+ smart_str_appends(&s, "Connection: close\r\n\r\n" );+ }+ smart_str_0(&s);++ if (hc->response) {+ free(hc->response);+ }+ hc->response = s.c;+ hc->maxresponse = s.a;+ hc->responselen = s.len;+ } } @@ -725,7 +805,7 @@ { char defanged_arg[1000], buf[2000]; - send_mime( hc, status, title, "", extraheads, "text/html", -1, 0 );+ send_mime( hc, status, title, "", extraheads, "text/html", -1, 0, 0, 0 ); (void) my_snprintf( buf, sizeof(buf), "<HTML><HEAD><TITLE>%d %s</TITLE></HEAD>\n<BODY BGCOLOR=\"#cc9999\"><H2>%d %s</H2>\n", status, title, status, title );@@ -764,7 +844,7 @@ char* cp2; for ( cp1 = str, cp2 = dfstr;- *cp1 != '\0' && cp2 - dfstr < dfsize - 1;+ *cp1 != '\0' && cp2 - dfstr < dfsize - 5; ++cp1, ++cp2 ) { switch ( *cp1 )@@ -834,7 +914,7 @@ fp = fopen( filename, "r" ); if ( fp == (FILE*) 0 ) return 0;- send_mime( hc, status, title, "", extraheads, "text/html", -1, 0 );+ send_mime( hc, status, title, "", extraheads, "text/html", -1, 0, 0, 0 ); for (;;) { r = fread( buf, 1, sizeof(buf) - 1, fp );@@ -1336,6 +1416,9 @@ if ( hc->tildemapped ) return 1; + if ( hc->hostname[0] == '.' || strchr( hc->hostname, '/' ) != (char*) 0 )+ return 0;+ /* Figure out the host directory. */ #ifdef VHOST_DIRLEVELS httpd_realloc_str(@@ -1436,7 +1519,7 @@ restlen = strlen( path ); httpd_realloc_str( &rest, &maxrest, restlen ); (void) strcpy( rest, path );- if ( rest[restlen - 1] == '/' )+ if ( restlen > 0 && rest[restlen - 1] == '/' ) rest[--restlen] = '\0'; /* trim trailing slash */ if ( ! tildemapped ) /* Remove any leading slashes. */@@ -1603,6 +1686,70 @@ int+httpd_request_reset(httpd_conn* hc, int preserve_read_buf )+{+ if (!preserve_read_buf) {+ hc->read_idx = 0;+ hc->checked_idx = 0;+ }+ + if (hc->read_buf_is_mmap) {+ hc->read_buf_is_mmap = 0;+ munmap(hc->read_buf, hc->read_size);+ hc->read_buf = NULL;+ hc->read_size = 0;+ httpd_realloc_str( &hc->read_buf, &hc->read_size, 500 );+ }+ hc->checked_state = CHST_FIRSTWORD;+ hc->method = METHOD_UNKNOWN;+ hc->status = 0;+ hc->bytes_to_send = 0;+ hc->bytes_sent = 0;+ hc->encodedurl = "";+ hc->decodedurl[0] = '\0';+ hc->protocol = "UNKNOWN";+ hc->origfilename[0] = '\0';+ hc->expnfilename[0] = '\0';+ hc->encodings[0] = '\0';+ hc->pathinfo[0] = '\0';+ hc->query[0] = '\0';+ hc->referer = "";+ hc->useragent = "";+ hc->accept[0] = '\0';+ hc->accepte[0] = '\0';+ hc->acceptl = "";+ hc->cookie = "";+ hc->contenttype = "";+ hc->reqhost[0] = '\0';+ hc->hdrhost = "";+ hc->hostdir[0] = '\0';+ hc->authorization = "";+ hc->remoteuser[0] = '\0';+ hc->response[0] = '\0';+#ifdef TILDE_MAP_2+ hc->altdir[0] = '\0';+#endif /* TILDE_MAP_2 */+ hc->responselen = 0;+ hc->if_modified_since = (time_t) -1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -