summaryrefslogtreecommitdiff
path: root/ext/standard/php_fopen_wrapper.c
diff options
context:
space:
mode:
authorHartmut Holzgraefe <hholzgra@php.net>2002-10-21 16:41:06 +0000
committerHartmut Holzgraefe <hholzgra@php.net>2002-10-21 16:41:06 +0000
commit8b7e9d77743ae006541a81bf4202e1c5d5311a60 (patch)
tree01ef9abc64f3bd26ecba541976d47e4a8b0ba331 /ext/standard/php_fopen_wrapper.c
parentb67b00efcdd8bd6feed6d861bdc2bd7ece0f9761 (diff)
downloadphp-git-8b7e9d77743ae006541a81bf4202e1c5d5311a60.tar.gz
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)
Diffstat (limited to 'ext/standard/php_fopen_wrapper.c')
-rw-r--r--ext/standard/php_fopen_wrapper.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/ext/standard/php_fopen_wrapper.c b/ext/standard/php_fopen_wrapper.c
index 6299e28ac1..cfaad71e0f 100644
--- a/ext/standard/php_fopen_wrapper.c
+++ b/ext/standard/php_fopen_wrapper.c
@@ -66,6 +66,59 @@ php_stream_ops php_stream_output_ops = {
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;
@@ -78,6 +131,10 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, ch
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")) {
fp = fdopen(dup(STDIN_FILENO), mode);
} else if (!strcasecmp(path, "stdout")) {