hholzgra Mon Oct 21 12:41:07 2002 EDT Modified files: /php4/main SAPI.c main.c php_content_types.c php_globals.h /php4/ext/standard php_fopen_wrapper.c Log: some changes to how request input data (Content-Lenght >0) is handled - webdav-specific stuff removed (should be handled using httpd.conf LIMIT or equivalents) - always_populate_raw_post_data now working on any method, not just POST (and webdav methods with allow_webdav_methods), when Content-Length is greater zero - raw input data is also available using php://input stream, this way one doesn't have to care about memory_limit - input data is now always consumed (although maybe ignored, this fixes we had withproblems with keep-alive connections @ raw POST data is now available as php://input stream (hartmut)
Index: php4/main/SAPI.c diff -u php4/main/SAPI.c:1.150 php4/main/SAPI.c:1.151 --- php4/main/SAPI.c:1.150 Sat Sep 7 21:06:29 2002 +++ php4/main/SAPI.c Mon Oct 21 12:41:06 2002 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: SAPI.c,v 1.150 2002/09/08 01:06:29 yohgaki Exp $ */ +/* $Id: SAPI.c,v 1.151 2002/10/21 16:41:06 hholzgra Exp $ */ #include <ctype.h> #include <sys/stat.h> @@ -128,7 +128,7 @@ char *content_type = estrndup(SG(request_info).content_type, content_type_length); char *p; char oldchar=0; - void (*post_reader_func)(TSRMLS_D); + void (*post_reader_func)(TSRMLS_D) = NULL; /* dedicated implementation for increased performance: @@ -159,7 +159,6 @@ return; } SG(request_info).post_entry = NULL; - post_reader_func = sapi_module.default_post_reader; } if (oldchar) { *(p-1) = oldchar; @@ -169,10 +168,10 @@ 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); - } + if(PG(always_populate_raw_post_data) && sapi_module.default_post_reader) { + sapi_module.default_post_reader(TSRMLS_C); } } @@ -282,6 +281,7 @@ SAPI_API void sapi_activate(TSRMLS_D) { void (*post_reader_func)(TSRMLS_D); + zend_llist_init(&SG(sapi_headers).headers, sizeof(sapi_header_struct), (void (*)(void *)) sapi_free_header, 0); SG(sapi_headers).send_default_content_type = 1; @@ -306,39 +306,34 @@ } SG(rfc1867_uploaded_files) = NULL; + /* handle request mehtod */ if (SG(server_context)) { - if ( SG(request_info).request_method - && (!strcmp(SG(request_info).request_method, "POST") - || (PG(allow_webdav_methods) - && (!strcmp(SG(request_info).request_method, "PROPFIND") - || !strcmp(SG(request_info).request_method, "PROPPATCH") - || !strcmp(SG(request_info).request_method, "MKCOL") - || !strcmp(SG(request_info).request_method, "PUT") - || !strcmp(SG(request_info).request_method, "MOVE") - || !strcmp(SG(request_info).request_method, "COPY") - || !strcmp(SG(request_info).request_method, "LOCK"))))) { - if (!SG(request_info).content_type) { + if ( SG(request_info).request_method) { + if(!strcmp(SG(request_info).request_method, "POST") + && (SG(request_info).content_type)) { + /* HTTP POST -> may contain form data to be read into +variables + depending on content type given + */ + sapi_read_post_data(TSRMLS_C); + } else { + /* any other method with content payload will fill + $HTTP_RAW_POST_DATA if enabled by +always_populate_raw_post_data + it is up to the webserver to decide whether to +allow a method or not + */ SG(request_info).content_type_dup = NULL; if(PG(always_populate_raw_post_data)) { - SG(request_info).post_entry = NULL; - post_reader_func = sapi_module.default_post_reader; - - 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); - } + if(sapi_module.default_post_reader) { + +sapi_module.default_post_reader(TSRMLS_C); } } else { - sapi_module.sapi_error(E_WARNING, "No content-type in POST request"); + sapi_module.sapi_error(E_WARNING, "No +content-type in %s request", SG(request_info).request_method); } - } else { - sapi_read_post_data(TSRMLS_C); } } else { SG(request_info).content_type_dup = NULL; } + + /* Cookies */ SG(request_info).cookie_data = sapi_module.read_cookies(TSRMLS_C); if (sapi_module.activate) { sapi_module.activate(TSRMLS_C); @@ -360,6 +355,14 @@ zend_llist_destroy(&SG(sapi_headers).headers); if (SG(request_info).post_data) { efree(SG(request_info).post_data); + } else if (SG(server_context)) { + if(sapi_module.read_post) { + // make sure we've consumed all request input data + char dummy[SAPI_POST_BLOCK_SIZE]; + while(sapi_module.read_post(dummy, sizeof(dummy)-1 TSRMLS_CC) +> 0) { + /* empty loop body */ + } + } } if (SG(request_info).auth_user) { efree(SG(request_info).auth_user); Index: php4/main/main.c diff -u php4/main/main.c:1.500 php4/main/main.c:1.501 --- php4/main/main.c:1.500 Mon Oct 21 09:09:28 2002 +++ php4/main/main.c Mon Oct 21 12:41:06 2002 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: main.c,v 1.500 2002/10/21 13:09:28 iliaa Exp $ */ +/* $Id: main.c,v 1.501 2002/10/21 16:41:06 hholzgra Exp $ */ /* {{{ includes */ @@ -320,7 +320,6 @@ STD_PHP_INI_BOOLEAN("allow_url_fopen", "1", PHP_INI_ALL, OnUpdateBool, allow_url_fopen, php_core_globals, core_globals) STD_PHP_INI_BOOLEAN("always_populate_raw_post_data", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, always_populate_raw_post_data, php_core_globals, core_globals) - STD_PHP_INI_BOOLEAN("allow_webdav_methods", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, allow_webdav_methods, php_core_globals, core_globals) PHP_INI_END() /* }}} */ Index: php4/main/php_content_types.c diff -u php4/main/php_content_types.c:1.21 php4/main/php_content_types.c:1.22 --- php4/main/php_content_types.c:1.21 Fri Aug 2 02:53:48 2002 +++ php4/main/php_content_types.c Mon Oct 21 12:41:06 2002 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_content_types.c,v 1.21 2002/08/02 06:53:48 hirokawa Exp $ */ +/* $Id: php_content_types.c,v 1.22 2002/10/21 16:41:06 hholzgra Exp $ */ #include "php.h" #include "SAPI.h" @@ -39,9 +39,11 @@ { char *data; - if(!SG(request_info).post_data) sapi_read_standard_form_data(TSRMLS_C); - data = estrndup(SG(request_info).post_data, SG(request_info).post_data_length); - SET_VAR_STRINGL("HTTP_RAW_POST_DATA", data, SG(request_info).post_data_length); + if(PG(always_populate_raw_post_data)) { + if(!SG(request_info).post_data) sapi_read_standard_form_data(TSRMLS_C); + data = estrndup(SG(request_info).post_data, +SG(request_info).post_data_length); + SET_VAR_STRINGL("HTTP_RAW_POST_DATA", data, +SG(request_info).post_data_length); + } } /* }}} */ Index: php4/main/php_globals.h diff -u php4/main/php_globals.h:1.83 php4/main/php_globals.h:1.84 --- php4/main/php_globals.h:1.83 Mon Oct 21 09:09:29 2002 +++ php4/main/php_globals.h Mon Oct 21 12:41:06 2002 @@ -140,7 +140,6 @@ zend_bool always_populate_raw_post_data; - zend_bool allow_webdav_methods; }; Index: php4/ext/standard/php_fopen_wrapper.c diff -u php4/ext/standard/php_fopen_wrapper.c:1.26 php4/ext/standard/php_fopen_wrapper.c:1.27 --- php4/ext/standard/php_fopen_wrapper.c:1.26 Sat Oct 5 06:35:12 2002 +++ php4/ext/standard/php_fopen_wrapper.c Mon Oct 21 12:41:06 2002 @@ -17,7 +17,7 @@ | Hartmut Holzgraefe <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ */ -/* $Id: php_fopen_wrapper.c,v 1.26 2002/10/05 10:35:12 wez Exp $ */ +/* $Id: php_fopen_wrapper.c,v 1.27 2002/10/21 16:41:06 hholzgra Exp $ */ #include <stdio.h> #include <stdlib.h> @@ -66,6 +66,59 @@ NULL /* set_option */ }; +static size_t php_stream_input_write(php_stream *stream, const char *buf, size_t +count TSRMLS_DC) +{ + return -1; +} + +static size_t php_stream_input_read(php_stream *stream, char *buf, size_t count +TSRMLS_DC) +{ + int read_bytes; + if(!stream->eof) { + if(SG(request_info).post_data) { /* data has already been read by a +post handler */ + read_bytes = SG(request_info).post_data_length - +stream->position; + if(read_bytes <= count) { + stream->eof = 1; + } else { + read_bytes = count; + } + if(read_bytes) { + memcpy(buf, SG(request_info).post_data + +stream->position, read_bytes); + } + return read_bytes; + } else { + read_bytes = sapi_module.read_post(buf, count TSRMLS_CC); + if(read_bytes <= 0){ + stream->eof = 1; + read_bytes = 0; + } + return read_bytes; + } + } +} + +static int php_stream_input_close(php_stream *stream, int close_handle TSRMLS_DC) +{ + return 0; +} + +static int php_stream_input_flush(php_stream *stream TSRMLS_DC) +{ + return -1; +} + +php_stream_ops php_stream_input_ops = { + php_stream_input_write, + php_stream_input_read, + php_stream_input_close, + php_stream_input_flush, + "Input", + NULL, /* seek */ + NULL, /* cast */ + NULL, /* stat */ + NULL /* set_option */ +}; + php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) { FILE * fp = NULL; @@ -76,6 +129,10 @@ if (!strcasecmp(path, "output")) { return php_stream_alloc(&php_stream_output_ops, NULL, 0, "wb"); + } + + if (!strcasecmp(path, "input")) { + return php_stream_alloc(&php_stream_input_ops, NULL, 0, "rb"); } if (!strcasecmp(path, "stdin")) {
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php