diff options
author | Wez Furlong <wez@php.net> | 2004-07-22 12:12:28 +0000 |
---|---|---|
committer | Wez Furlong <wez@php.net> | 2004-07-22 12:12:28 +0000 |
commit | 17adf438a2d3dd5c9a969557e7208058b6f5e8fb (patch) | |
tree | c3cff5ebffa937e73fbe751acb7ba9287f9e481a | |
parent | 34b00ca22a878f6c6d7fea6f86c76af2460d3e80 (diff) | |
download | php-git-17adf438a2d3dd5c9a969557e7208058b6f5e8fb.tar.gz |
Added stream_context_get_default() which returns the default context option.
You may then set options that affect streams operations for the whole script.
Added stream_socket_enable_crypto() which allows you to turn on or off a crypto
layer (eg: SSL/TLS) on stream, if supported by the underlying transport.
Registered a bunch of constants for that.
-rw-r--r-- | ext/standard/basic_functions.c | 2 | ||||
-rw-r--r-- | ext/standard/file.c | 9 | ||||
-rw-r--r-- | ext/standard/streamsfuncs.c | 53 | ||||
-rw-r--r-- | ext/standard/streamsfuncs.h | 2 |
4 files changed, 66 insertions, 0 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 7817f1e0b3..6fd7d04915 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -587,6 +587,7 @@ function_entry basic_functions[] = { PHP_FE(stream_context_set_params, NULL) PHP_FE(stream_context_set_option, NULL) PHP_FE(stream_context_get_options, NULL) + PHP_FE(stream_context_get_default, NULL) PHP_FE(stream_filter_prepend, NULL) PHP_FE(stream_filter_append, NULL) PHP_FE(stream_socket_client, second_and_third_args_force_ref) @@ -595,6 +596,7 @@ function_entry basic_functions[] = { PHP_FE(stream_socket_get_name, NULL) PHP_FE(stream_socket_recvfrom, fourth_arg_force_ref) PHP_FE(stream_socket_sendto, NULL) + PHP_FE(stream_socket_enable_crypto, NULL) PHP_FE(stream_copy_to_stream, NULL) PHP_FE(stream_get_contents, NULL) PHP_FE(fgetcsv, NULL) diff --git a/ext/standard/file.c b/ext/standard/file.c index b3af5a20c0..5fbd87de07 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -214,6 +214,15 @@ PHP_MINIT_FUNCTION(file) REGISTER_LONG_CONSTANT("STREAM_CLIENT_ASYNC_CONNECT", PHP_STREAM_CLIENT_ASYNC_CONNECT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_CLIENT_CONNECT", PHP_STREAM_CLIENT_CONNECT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("STREAM_CRYPTO_METHOD_SSLv2_CLIENT", STREAM_CRYPTO_METHOD_SSLv2_CLIENT, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("STREAM_CRYPTO_METHOD_SSLv3_CLIENT", STREAM_CRYPTO_METHOD_SSLv3_CLIENT, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("STREAM_CRYPTO_METHOD_SSLv23_CLIENT", STREAM_CRYPTO_METHOD_SSLv23_CLIENT, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("STREAM_CRYPTO_METHOD_TLS_CLIENT", STREAM_CRYPTO_METHOD_TLS_CLIENT, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("STREAM_CRYPTO_METHOD_SSLv2_SERVER", STREAM_CRYPTO_METHOD_SSLv2_SERVER, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("STREAM_CRYPTO_METHOD_SSLv3_SERVER", STREAM_CRYPTO_METHOD_SSLv3_SERVER, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("STREAM_CRYPTO_METHOD_SSLv23_SERVER", STREAM_CRYPTO_METHOD_SSLv23_SERVER, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("STREAM_CRYPTO_METHOD_TLS_SERVER", STREAM_CRYPTO_METHOD_TLS_SERVER, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("STREAM_PEEK", STREAM_PEEK, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_OOB", STREAM_OOB, CONST_CS | CONST_PERSISTENT); diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index b73fabe8d8..1e889f0b8a 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -928,6 +928,30 @@ PHP_FUNCTION(stream_context_set_params) } /* }}} */ +/* {{{ proto resource stream_context_get_default([array options]) + Get a handle on the default file/stream context and optionally set parameters */ +PHP_FUNCTION(stream_context_get_default) +{ + zval *params = NULL; + php_stream_context *context; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a", ¶ms) == FAILURE) { + RETURN_FALSE; + } + + if (FG(default_context) == NULL) { + FG(default_context) = php_stream_context_alloc(); + } + context = FG(default_context); + + if (params) { + parse_context_options(context, params); + } + + php_stream_context_to_zval(context, return_value); +} +/* }}} */ + /* {{{ proto resource stream_context_create([array options]) Create a file context and optionally set parameters */ PHP_FUNCTION(stream_context_create) @@ -1166,6 +1190,35 @@ PHP_FUNCTION(stream_set_write_buffer) } /* }}} */ +/* {{{ proto bool stream_socket_enable_crypto(resource stream, bool enable [, int cryptokind, resource sessionstream]) + Enable or disable a specific kind of crypto on the stream */ +PHP_FUNCTION(stream_socket_enable_crypto) +{ + long cryptokind; + zval *zstream, *zsessstream = NULL; + php_stream *stream, *sessstream = NULL; + zend_bool enable; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rb|lr", &zstream, &enable, &cryptokind, &zsessstream) == FAILURE) { + RETURN_FALSE; + } + + php_stream_from_zval(stream, &zstream); + + if (ZEND_NUM_ARGS() >= 3) { + if (zsessstream) { + php_stream_from_zval(sessstream, zsessstream); + } + + if (php_stream_xport_crypto_setup(stream, cryptokind, sessstream TSRMLS_CC) < 0) { + RETURN_FALSE; + } + } + + RETURN_BOOL(php_stream_xport_crypto_enable(stream, enable TSRMLS_CC) < 0 ? 0 : 1); +} +/* }}} */ + /* * Local variables: * tab-width: 4 diff --git a/ext/standard/streamsfuncs.h b/ext/standard/streamsfuncs.h index 7d4e607b43..6ec9dba491 100644 --- a/ext/standard/streamsfuncs.h +++ b/ext/standard/streamsfuncs.h @@ -47,8 +47,10 @@ PHP_FUNCTION(stream_context_create); PHP_FUNCTION(stream_context_set_params); PHP_FUNCTION(stream_context_set_option); PHP_FUNCTION(stream_context_get_options); +PHP_FUNCTION(stream_context_get_default); PHP_FUNCTION(stream_filter_prepend); PHP_FUNCTION(stream_filter_append); +PHP_FUNCTION(stream_socket_enable_crypto); /* * Local variables: |