diff options
Diffstat (limited to 'ext/standard')
| -rw-r--r-- | ext/standard/php_fopen_wrapper.c | 23 | ||||
| -rw-r--r-- | ext/standard/streamsfuncs.c | 22 |
2 files changed, 28 insertions, 17 deletions
diff --git a/ext/standard/php_fopen_wrapper.c b/ext/standard/php_fopen_wrapper.c index 3deb330a8f..7e21e95d18 100644 --- a/ext/standard/php_fopen_wrapper.c +++ b/ext/standard/php_fopen_wrapper.c @@ -64,7 +64,7 @@ php_stream_ops php_stream_output_ops = { }; typedef struct php_stream_input { /* {{{ */ - php_stream **body_ptr; + php_stream *body; off_t position; } php_stream_input_t; /* }}} */ @@ -85,13 +85,13 @@ static size_t php_stream_input_read(php_stream *stream, char *buf, size_t count int read_bytes = sapi_read_post_block(buf, count TSRMLS_CC); if (read_bytes > 0) { - php_stream_seek(*input->body_ptr, 0, SEEK_END); - php_stream_write(*input->body_ptr, buf, read_bytes); + php_stream_seek(input->body, 0, SEEK_END); + php_stream_write(input->body, buf, read_bytes); } } - php_stream_seek(*input->body_ptr, input->position, SEEK_SET); - read = php_stream_read(*input->body_ptr, buf, count); + php_stream_seek(input->body, input->position, SEEK_SET); + read = php_stream_read(input->body, buf, count); if (!read || read == (size_t) -1) { stream->eof = 1; @@ -122,9 +122,9 @@ static int php_stream_input_seek(php_stream *stream, off_t offset, int whence, o { php_stream_input_t *input = stream->abstract; - if (*input->body_ptr) { - int sought = php_stream_seek(*input->body_ptr, offset, whence); - *newoffset = (*input->body_ptr)->position; + if (input->body) { + int sought = php_stream_seek(input->body, offset, whence); + *newoffset = (input->body)->position; return sought; } @@ -228,10 +228,11 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, const char *pa } input = ecalloc(1, sizeof(*input)); - if (*(input->body_ptr = &SG(request_info).request_body)) { - php_stream_rewind(*input->body_ptr); + if ((input->body = SG(request_info).request_body)) { + php_stream_rewind(input->body); } else { - *input->body_ptr = php_stream_temp_create(TEMP_STREAM_DEFAULT, SAPI_POST_BLOCK_SIZE); + input->body = php_stream_temp_create(TEMP_STREAM_DEFAULT, SAPI_POST_BLOCK_SIZE); + SG(request_info).request_body = input->body; } return php_stream_alloc(&php_stream_input_ops, input, 0, "rb"); diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index 81afb2228e..1d59a97a94 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -40,6 +40,8 @@ typedef unsigned long long php_timeout_ull; typedef unsigned __int64 php_timeout_ull; #endif +#define GET_CTX_OPT(stream, wrapper, name, val) (stream->context && NULL != (val = php_stream_context_get_option(stream->context, wrapper, name))) + static php_stream_context *decode_context_param(zval *contextresource TSRMLS_DC); /* Streams based network functions */ @@ -1444,16 +1446,27 @@ PHP_FUNCTION(stream_socket_enable_crypto) long cryptokind = 0; zval *zstream, *zsessstream = NULL; php_stream *stream, *sessstream = NULL; - zend_bool enable; + zend_bool enable, cryptokindnull; int ret; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rb|lr", &zstream, &enable, &cryptokind, &zsessstream) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rb|l!r", &zstream, &enable, &cryptokind, &cryptokindnull, &zsessstream) == FAILURE) { RETURN_FALSE; } php_stream_from_zval(stream, zstream); - if (ZEND_NUM_ARGS() >= 3) { + if (enable) { + if (ZEND_NUM_ARGS() < 3 || cryptokindnull) { + zval *val; + + if (!GET_CTX_OPT(stream, "ssl", "crypto_method", val)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "When enabling encryption you must specify the crypto type"); + RETURN_FALSE; + } + + cryptokind = Z_LVAL_P(val); + } + if (zsessstream) { php_stream_from_zval(sessstream, zsessstream); } @@ -1461,9 +1474,6 @@ PHP_FUNCTION(stream_socket_enable_crypto) if (php_stream_xport_crypto_setup(stream, cryptokind, sessstream TSRMLS_CC) < 0) { RETURN_FALSE; } - } else if (enable) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "When enabling encryption you must specify the crypto type"); - RETURN_FALSE; } ret = php_stream_xport_crypto_enable(stream, enable TSRMLS_CC); |
