cvs: php4 /main SAPI.c php_content_types.c rfc1867.c
| From: | Jani Taskinen | Date: | Mon, 03 Sep 2001 02:31:57 +0000 |
| Subject: | cvs: php4 /main SAPI.c php_content_types.c rfc1867.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-7169@lists.php.net to get a copy of this message | ||
sniper Sun Sep 2 22:31:57 2001 EDT
Modified files:
/php4/main SAPI.c php_content_types.c rfc1867.c
Log:
First step for chunkifying the HTTP uploads.
Index: php4/main/SAPI.c
diff -u php4/main/SAPI.c:1.114 php4/main/SAPI.c:1.115
--- php4/main/SAPI.c:1.114 Wed Aug 15 14:01:48 2001
+++ php4/main/SAPI.c Sun Sep 2 22:31:56 2001
@@ -157,10 +157,15 @@
if (oldchar) {
*(p-1) = oldchar;
}
- post_reader_func(TSRMLS_C);
+
SG(request_info).content_type_dup = content_type;
- if(PG(always_populate_raw_post_data) && sapi_module.default_post_reader) {
- sapi_module.default_post_reader(TSRMLS_C);
+
+ if(post_reader_func) {
+ post_reader_func(TSRMLS_C);
+
+ if(PG(always_populate_raw_post_data) && sapi_module.default_post_reader) {
+ sapi_module.default_post_reader(TSRMLS_C);
+ }
}
}
Index: php4/main/php_content_types.c
diff -u php4/main/php_content_types.c:1.16 php4/main/php_content_types.c:1.17
--- php4/main/php_content_types.c:1.16 Wed Aug 15 14:01:48 2001
+++ php4/main/php_content_types.c Sun Sep 2 22:31:56 2001
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_content_types.c,v 1.16 2001/08/15 18:01:48 dbeu Exp $ */
+/* $Id: php_content_types.c,v 1.17 2001/09/03 02:31:56 sniper Exp $ */
#include "php.h"
#include "SAPI.h"
@@ -27,9 +27,9 @@
/* {{{ php_post_entries[]
*/
static sapi_post_entry php_post_entries[] = {
- {
DEFAULT_POST_CONTENT_TYPE, sizeof(DEFAULT_POST_CONTENT_TYPE)-1, sapi_read_standard_form_data, php_std_post_handler
},
- {
MULTIPART_CONTENT_TYPE, sizeof(MULTIPART_CONTENT_TYPE)-1, sapi_read_standard_form_data, rfc1867_post_handler
},
- { NULL, 0, NULL }
+ { DEFAULT_POST_CONTENT_TYPE, sizeof(DEFAULT_POST_CONTENT_TYPE)-1,
sapi_read_standard_form_data, php_std_post_handler },
+ { MULTIPART_CONTENT_TYPE, sizeof(MULTIPART_CONTENT_TYPE)-1, NULL,
rfc1867_post_handler },
+ { NULL, 0, NULL, NULL }
};
/* }}} */
Index: php4/main/rfc1867.c
diff -u php4/main/rfc1867.c:1.72 php4/main/rfc1867.c:1.73
--- php4/main/rfc1867.c:1.72 Wed Aug 15 14:01:48 2001
+++ php4/main/rfc1867.c Sun Sep 2 22:31:56 2001
@@ -15,7 +15,7 @@
| Authors: Rasmus Lerdorf <rasmus@php.net> |
+----------------------------------------------------------------------+
*/
-/* $Id: rfc1867.c,v 1.72 2001/08/15 18:01:48 dbeu Exp $ */
+/* $Id: rfc1867.c,v 1.73 2001/09/03 02:31:56 sniper Exp $ */
#include <stdio.h>
#include "php.h"
@@ -100,10 +100,10 @@
/*
* Split raw mime stream up into appropriate components
*/
-static void php_mime_split(char *buf, int cnt, char *boundary, zval *array_ptr TSRMLS_DC)
+static void php_mime_split(char *buf, int cnt, char *boundary, int len, zval *array_ptr TSRMLS_DC)
{
char *ptr, *loc, *loc2, *loc3, *s, *name, *filename, *u, *temp_filename;
- int len, state = 0, Done = 0, rem, urem;
+ int state = 0, Done = 0, rem, urem;
int eolsize;
long bytes, max_file_size = 0;
char *namebuf=NULL, *filenamebuf=NULL, *lbuf=NULL,
@@ -126,7 +126,7 @@
ptr = buf;
rem = cnt;
- len = strlen(boundary);
+
while ((ptr - buf < cnt) && !Done) {
switch (state) {
case 0: /* Looking for mime boundary */
@@ -443,6 +443,22 @@
}
+/*
+ * Reads post data chunk
+ *
+ */
+static int read_post_data_chunk(char *buf TSRMLS_DC)
+{
+ int read_bytes;
+
+ read_bytes = sapi_module.read_post(buf, SAPI_POST_BLOCK_SIZE TSRMLS_CC);
+
+ SG(read_post_bytes) += read_bytes;
+
+ return read_bytes;
+}
+
+
SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler)
{
char *boundary;
@@ -454,6 +470,11 @@
return;
}
+ if (SG(request_info).content_length > SG(post_max_size)) {
+ sapi_module.sapi_error(E_COMPILE_ERROR, "POST Content-Length of %d bytes exceeds the limit
of %d bytes", SG(request_info).content_length, SG(post_max_size));
+ return;
+ }
+
boundary = strstr(content_type_dup, "boundary");
if (!boundary || !(boundary=strchr(boundary, '='))) {
sapi_module.sapi_error(E_COMPILE_ERROR, "Missing boundary in multipart/form-data POST
data");
@@ -468,11 +489,39 @@
boundary[boundary_len] = '\0';
}
+ /* <FIXME> Temporary. Should be done same time as parsing. Maybe that Apache stuff.. */
+ {
+ int allocated_bytes=SAPI_POST_BLOCK_SIZE+1, read_bytes;
+
+ SG(request_info).post_data = emalloc(allocated_bytes);
+
+ for (;;) {
+ read_bytes = read_post_data_chunk(SG(request_info).post_data+SG(read_post_bytes) TSRMLS_CC);
+
+ if(read_bytes <= 0 || read_bytes < SAPI_POST_BLOCK_SIZE) {
+ break;
+ }
+
+ if (SG(read_post_bytes) > SG(post_max_size)) {
+ php_error(E_WARNING, "Actual POST length does not match Content-Length, and exceeds %d
bytes", SG(post_max_size));
+ return;
+ }
+
+ if (SG(read_post_bytes) + SAPI_POST_BLOCK_SIZE >= allocated_bytes) {
+ allocated_bytes = SG(read_post_bytes)+SAPI_POST_BLOCK_SIZE+1;
+ SG(request_info).post_data = erealloc(SG(request_info).post_data, allocated_bytes);
+ }
+ }
+
+ SG(request_info).post_data[SG(read_post_bytes)] = 0; /* terminating NULL */
+ SG(request_info).post_data_length = SG(read_post_bytes);
+ }
+ /* </FIXME> */
+
if (SG(request_info).post_data) {
- php_mime_split(SG(request_info).post_data, SG(request_info).post_data_length, boundary, array_ptr
TSRMLS_CC);
+ php_mime_split(SG(request_info).post_data, SG(request_info).post_data_length, boundary,
boundary_len, array_ptr TSRMLS_CC);
}
}
-
/*
* Local variables: