summaryrefslogtreecommitdiff
path: root/sapi/thttpd/thttpd_patch
blob: 1a058c7aaad75b5e0ab949129488d6be32d752cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
diff -ur thttpd-2.21b-orig/Makefile.in thttpd-2.21b/Makefile.in
--- thttpd-2.21b-orig/Makefile.in	Thu Mar 29 20:36:21 2001
+++ thttpd-2.21b/Makefile.in	Mon Aug 13 23:50:27 2001
@@ -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.
 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@
 
@@ -151,6 +153,9 @@
 
 tags:
 	ctags -wtd *.c *.h
+
+php_thttpd.o: php_thttpd.c
+	$(CC) $(PHP_CFLAGS) $(CFLAGS) -c php_thttpd.c
 
 tar:
 	@name=`sed -n -e '/SERVER_SOFTWARE/!d' -e 's,.*thttpd/,thttpd-,' -e 's, .*,,p' version.h` ; \
diff -ur thttpd-2.21b-orig/config.h thttpd-2.21b/config.h
--- thttpd-2.21b-orig/config.h	Mon Apr  9 23:57:36 2001
+++ thttpd-2.21b/config.h	Mon Aug 13 23:51:00 2001
@@ -316,7 +316,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-orig/fdwatch.c thttpd-2.21b/fdwatch.c
--- thttpd-2.21b-orig/fdwatch.c	Fri Apr 13 07:36:08 2001
+++ thttpd-2.21b/fdwatch.c	Tue Aug 14 00:00:10 2001
@@ -460,7 +460,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 +472,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-orig/libhttpd.c thttpd-2.21b/libhttpd.c
--- thttpd-2.21b-orig/libhttpd.c	Tue Apr 24 00:42:40 2001
+++ thttpd-2.21b/libhttpd.c	Tue Aug 14 00:00:07 2001
@@ -85,6 +85,8 @@
 #include "match.h"
 #include "tdate_parse.h"
 
+#include "php_thttpd.h"
+
 #ifndef STDIN_FILENO
 #define STDIN_FILENO 0
 #endif
@@ -242,6 +244,8 @@
 	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->charset != (char*) 0 )
 	free( (void*) hs->charset );
     if ( hs->url_pattern != (char*) 0 )
@@ -249,6 +253,7 @@
     if ( hs->local_pattern != (char*) 0 )
 	free( (void*) hs->local_pattern );
     free( (void*) hs );
+    thttpd_php_shutdown();
     }
 
 
@@ -312,6 +317,7 @@
 	}
 
     hs->port = port;
+    hs->php_pattern = strdup("**.php");
     if ( cgi_pattern == (char*) 0 )
 	hs->cgi_pattern = (char*) 0;
     else
@@ -385,6 +391,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 );
@@ -2353,7 +2361,10 @@
     {
     make_log_entry( hc, nowP );
 
-    if ( hc->file_address != (char*) 0 )
+    if ( hc->file_address == (char*) 1 )
+    {
+	thttpd_closed_conn(hc->conn_fd);
+    } else if ( hc->file_address != (char*) 0 )
 	{
 	mmc_unmap( hc->file_address, &(hc->sb), nowP );
 	hc->file_address = (char*) 0;
@@ -3026,11 +3037,9 @@
 post_post_garbage_hack( httpd_conn* hc )
     {
     char buf[2];
-    int r;
 
-    r = recv( hc->conn_fd, buf, sizeof(buf), MSG_PEEK );
-    if ( r > 0 )
-	(void) read( hc->conn_fd, buf, r );
+	fcntl(hc->conn_fd, F_SETFL, O_NONBLOCK);
+	(void) read( hc->conn_fd, buf, 2 );
     }
 
 
@@ -3560,6 +3569,11 @@
 	 ( hc->sb.st_mode & S_IXOTH ) &&
 	 match( hc->hs->cgi_pattern, hc->expnfilename ) )
 	return cgi( hc );
+
+	if ( hc->hs->php_pattern != (char*) 0 &&
+			match( hc->hs->php_pattern, hc->expnfilename)) {
+		return thttpd_php_request( hc );
+	}
 
     /* It's not CGI.  If it's executable or there's pathinfo, someone's
     ** trying to either serve or run a non-CGI file as CGI.   Either case
Only in thttpd-2.21b: libhttpd.c~
diff -ur thttpd-2.21b-orig/libhttpd.h thttpd-2.21b/libhttpd.h
--- thttpd-2.21b-orig/libhttpd.h	Tue Apr 24 00:36:50 2001
+++ thttpd-2.21b/libhttpd.h	Mon Aug 13 23:50:27 2001
@@ -69,6 +69,7 @@
     char* server_hostname;
     int port;
     char* cgi_pattern;
+    char* php_pattern;
     char* charset;
     char* cwd;
     int listen4_fd, listen6_fd;
diff -ur thttpd-2.21b-orig/thttpd.c thttpd-2.21b/thttpd.c
--- thttpd-2.21b-orig/thttpd.c	Tue Apr 24 00:41:57 2001
+++ thttpd-2.21b/thttpd.c	Mon Aug 13 23:50:27 2001
@@ -1333,7 +1333,7 @@
 	clear_connection( c, tvP );
 	return;
 	}
-    hc->read_idx += sz;
+    if (sz > 0) hc->read_idx += sz;
 
     /* Do we have a complete request yet? */
     switch ( httpd_got_request( hc ) )
@@ -1387,6 +1387,12 @@
 	clear_connection( c, tvP );
 	return;
 	}
+	if (hc->file_address == (char *) 1) {
+		tmr_cancel( c->idle_read_timer );
+		c->idle_read_timer = (Timer*) 0;
+		c->wouldblock_delay = 0;
+		return;
+	}
     if ( c->bytes_sent >= c->bytes_to_send )
 	{
 	/* There's nothing to send. */
@@ -1500,7 +1506,7 @@
 	    {
 	    /* Yes; move the unwritten part to the front of the buffer. */
 	    int newlen = hc->responselen - sz;
-	    (void) memcpy( hc->response, &(hc->response[sz]), newlen );
+	    (void) memmove( hc->response, &(hc->response[sz]), newlen );
 	    hc->responselen = newlen;
 	    sz = 0;
 	    }
Only in thttpd-2.21b: thttpd.c~