com php-src: refactor php_stream_temp_create{,_ex } and use it for the php://input stream: ext/standard/php_fopen_wrapper.c main/php_memory_st
reams.h main/streams/memory.c
| From: | Michael Wallner | Date: | Thu, 03 Jul 2014 18:40:40 +0000 |
| Subject: | com php-src: refactor php_stream_temp_create{,_ex } and use it for the php://input stream: ext/standard/php_fopen_wrapper.c main/php_memory_st reams.h main/streams/memory.c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-79229@lists.php.net to get a copy of this message | ||
Commit: 40bcd909d8948c53226accf9ceb11987b0f8e442
Author: Michael Wallner <mike@php.net> Wed, 2 Jul 2014 12:22:14 +0200
Parents: 11e401ab59b73b22dcd6ce91e250c82ca808cd4f
Branches: PHP-5.6 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=40bcd909d8948c53226accf9ceb11987b0f8e442
Log:
refactor php_stream_temp_create{,_ex} and use it for the php://input stream
Changed paths:
M ext/standard/php_fopen_wrapper.c
M main/php_memory_streams.h
M main/streams/memory.c
Diff:
diff --git a/ext/standard/php_fopen_wrapper.c b/ext/standard/php_fopen_wrapper.c
index 7e21e95..9628c0d 100644
--- a/ext/standard/php_fopen_wrapper.c
+++ b/ext/standard/php_fopen_wrapper.c
@@ -231,7 +231,7 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, const char *pa
if ((input->body = SG(request_info)..request_body)) {
php_stream_rewind(input->body);
} else {
- input->body = php_stream_temp_create(TEMP_STREAM_DEFAULT, SAPI_POST_BLOCK_SIZE);
+ input->body = php_stream_temp_create_ex(TEMP_STREAM_DEFAULT, SAPI_POST_BLOCK_SIZE,
PG(upload_tmp_dir));
SG(request_info).request_body = input->body;
}
diff --git a/main/php_memory_streams.h b/main/php_memory_streams.h
index 3c4c328..32a3dae 100644
--- a/main/php_memory_streams.h
+++ b/main/php_memory_streams.h
@@ -35,7 +35,8 @@
#define php_stream_memory_get_buffer(stream, length) _php_stream_memory_get_buffer((stream),
(length) STREAMS_CC TSRMLS_CC)
#define php_stream_temp_new() php_stream_temp_create(TEMP_STREAM_DEFAULT, PHP_STREAM_MAX_MEM)
-#define php_stream_temp_create(mode, max_memory_usage) _php_stream_temp_create((mode),
(max_memory_usage) STREAMS_CC TSRMLS_CC)
+#define php_stream_temp_create(mode, max_memory_usage) php_stream_temp_create_ex((mode),
(max_memory_usage), NULL)
+#define php_stream_temp_create_ex(mode, max_memory_usage, tmpdir)
_php_stream_temp_create_ex((mode), (max_memory_usage), (tmpdir) STREAMS_CC TSRMLS_CC)
#define php_stream_temp_create_rel(mode, max_memory_usage) _php_stream_temp_create((mode),
(max_memory_usage) STREAMS_REL_CC TSRMLS_CC)
#define php_stream_temp_open(mode, max_memory_usage, buf, length) _php_stream_temp_open((mode),
(max_memory_usage), (buf), (length) STREAMS_CC TSRMLS_CC)
@@ -45,6 +46,7 @@ PHPAPI php_stream *_php_stream_memory_open(int mode, char *buf, size_t length ST
PHPAPI char *_php_stream_memory_get_buffer(php_stream *stream, size_t *length STREAMS_DC
TSRMLS_DC);
PHPAPI php_stream *_php_stream_temp_create(int mode, size_t max_memory_usage STREAMS_DC TSRMLS_DC);
+PHPAPI php_stream *_php_stream_temp_create_ex(int mode, size_t max_memory_usage, const char *tmpdir
STREAMS_DC TSRMLS_DC);
PHPAPI php_stream *_php_stream_temp_open(int mode, size_t max_memory_usage, char *buf, size_t
length STREAMS_DC TSRMLS_DC);
END_EXTERN_C()
diff --git a/main/streams/memory.c b/main/streams/memory.c
index 854b9e2..6b3fc3f 100644
--- a/main/streams/memory.c
+++ b/main/streams/memory.c
@@ -352,6 +352,7 @@ typedef struct {
size_t smax;
int mode;
zval* meta;
+ char* tmpdir;
} php_stream_temp_data;
@@ -369,7 +370,7 @@ static size_t php_stream_temp_write(php_stream *stream, const char *buf, size_t
char *membuf = php_stream_memory_get_buffer(ts->innerstream, &memsize);
if (memsize + count >= ts->smax) {
- php_stream *file = php_stream_fopen_tmpfile();
+ php_stream *file = php_stream_fopen_temporary_file(ts->tmpdir, "php", NULL);
php_stream_write(file, membuf, memsize);
php_stream_free_enclosed(ts->innerstream, PHP_STREAM_FREE_CLOSE);
ts->innerstream = file;
@@ -420,6 +421,10 @@ static int php_stream_temp_close(php_stream *stream, int close_handle
TSRMLS_DC)
zval_ptr_dtor(&ts->meta);
}
+ if (ts->tmpdir) {
+ efree(ts->tmpdir);
+ }
+
efree(ts);
return ret;
@@ -547,8 +552,8 @@ PHPAPI php_stream_ops php_stream_temp_ops = {
/* }}} */
-/* {{{ _php_stream_temp_create */
-PHPAPI php_stream *_php_stream_temp_create(int mode, size_t max_memory_usage STREAMS_DC TSRMLS_DC)
+/* {{{ _php_stream_temp_create_ex */
+PHPAPI php_stream *_php_stream_temp_create_ex(int mode, size_t max_memory_usage, const char *tmpdir
STREAMS_DC TSRMLS_DC)
{
php_stream_temp_data *self;
php_stream *stream;
@@ -556,7 +561,9 @@ PHPAPI php_stream *_php_stream_temp_create(int mode, size_t max_memory_usage STR
self = ecalloc(1, sizeof(*self));
self->smax = max_memory_usage;
self->mode = mode;
- self->meta = NULL;
+ if (tmpdir) {
+ self->tmpdir = estrdup(tmpdir);
+ }
stream = php_stream_alloc_rel(&php_stream_temp_ops, self, 0, mode & TEMP_STREAM_READONLY ?
"rb" : "w+b");
stream->flags |= PHP_STREAM_FLAG_NO_BUFFER;
self->innerstream = php_stream_memory_create_rel(mode);