summaryrefslogtreecommitdiff
path: root/ext/standard/streamsfuncs.c
diff options
context:
space:
mode:
authorChris Wright <daverandom@php.net>2014-02-27 13:41:25 +0000
committerChris Wright <daverandom@php.net>2014-02-27 13:41:25 +0000
commit41da7f276fb77d6a0ba3e3c62751e0c3537fbecf (patch)
treef198e1e8c19b49a56a12cb32c9ae0e9af2d9ce64 /ext/standard/streamsfuncs.c
parent5abaf7cc8792ba2eb3808de1d155197ba072cf54 (diff)
downloadphp-git-41da7f276fb77d6a0ba3e3c62751e0c3537fbecf.tar.gz
Allow crypto_method context value in stream_socket_enable_crypto()
Diffstat (limited to 'ext/standard/streamsfuncs.c')
-rw-r--r--ext/standard/streamsfuncs.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c
index b623447651..bf64282357 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 && SUCCESS == php_stream_context_get_option(stream->context, wrapper, name, &val))
+
static php_stream_context *decode_context_param(zval *contextresource TSRMLS_DC);
/* Streams based network functions */
@@ -1502,16 +1504,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_PP(val);
+ }
+
if (zsessstream) {
php_stream_from_zval(sessstream, &zsessstream);
}
@@ -1519,9 +1532,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);