summaryrefslogtreecommitdiff
path: root/ext/standard/streamsfuncs.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/standard/streamsfuncs.c')
-rw-r--r--ext/standard/streamsfuncs.c84
1 files changed, 45 insertions, 39 deletions
diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c
index 0bc475498f..f56f52930c 100644
--- a/ext/standard/streamsfuncs.c
+++ b/ext/standard/streamsfuncs.c
@@ -868,13 +868,13 @@ static void user_space_stream_notifier_dtor(php_stream_notifier *notifier)
}
}
-static int parse_context_options(php_stream_context *context, zval *options)
+static int parse_context_options(php_stream_context *context, HashTable *options)
{
zval *wval, *oval;
zend_string *wkey, *okey;
int ret = SUCCESS;
- ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(options), wkey, wval) {
+ ZEND_HASH_FOREACH_STR_KEY_VAL(options, wkey, wval) {
ZVAL_DEREF(wval);
if (wkey && Z_TYPE_P(wval) == IS_ARRAY) {
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(wval), okey, oval) {
@@ -891,12 +891,12 @@ static int parse_context_options(php_stream_context *context, zval *options)
return ret;
}
-static int parse_context_params(php_stream_context *context, zval *params)
+static int parse_context_params(php_stream_context *context, HashTable *params)
{
int ret = SUCCESS;
zval *tmp;
- if (NULL != (tmp = zend_hash_str_find(Z_ARRVAL_P(params), "notification", sizeof("notification")-1))) {
+ if (NULL != (tmp = zend_hash_str_find(params, "notification", sizeof("notification")-1))) {
if (context->notifier) {
php_stream_notification_free(context->notifier);
@@ -908,9 +908,9 @@ static int parse_context_params(php_stream_context *context, zval *params)
ZVAL_COPY(&context->notifier->ptr, tmp);
context->notifier->dtor = user_space_stream_notifier_dtor;
}
- if (NULL != (tmp = zend_hash_str_find(Z_ARRVAL_P(params), "options", sizeof("options")-1))) {
+ if (NULL != (tmp = zend_hash_str_find(params, "options", sizeof("options")-1))) {
if (Z_TYPE_P(tmp) == IS_ARRAY) {
- return parse_context_options(context, tmp);
+ return parse_context_options(context, Z_ARRVAL_P(tmp));
} else {
zend_type_error("Invalid stream/context parameter");
return FAILURE;
@@ -975,41 +975,45 @@ PHP_FUNCTION(stream_context_set_option)
{
zval *zcontext = NULL;
php_stream_context *context;
+ zend_string *wrappername;
+ HashTable *options;
+ char *optionname = NULL;
+ size_t optionname_len;
+ zval *zvalue = NULL;
- if (ZEND_NUM_ARGS() == 2) {
- zval *options;
+ ZEND_PARSE_PARAMETERS_START(2, 4)
+ Z_PARAM_RESOURCE(zcontext)
+ Z_PARAM_STR_OR_ARRAY_HT(wrappername, options)
+ Z_PARAM_OPTIONAL
+ Z_PARAM_STRING_OR_NULL(optionname, optionname_len)
+ Z_PARAM_ZVAL(zvalue)
+ ZEND_PARSE_PARAMETERS_END();
+
+ /* figure out where the context is coming from exactly */
+ if (!(context = decode_context_param(zcontext))) {
+ zend_argument_type_error(1, "must be a valid stream/context");
+ RETURN_THROWS();
+ }
- ZEND_PARSE_PARAMETERS_START(2, 2)
- Z_PARAM_RESOURCE(zcontext)
- Z_PARAM_ARRAY(options)
- ZEND_PARSE_PARAMETERS_END();
+ if (options) {
+ if (optionname) {
+ zend_argument_value_error(3, "must be null when argument #2 ($wrapper_or_options) is an array");
+ RETURN_THROWS();
+ }
- /* figure out where the context is coming from exactly */
- if (!(context = decode_context_param(zcontext))) {
- zend_argument_type_error(1, "must be a valid stream/context");
+ if (zvalue) {
+ zend_argument_value_error(4, "cannot be provided when argument #2 ($wrapper_or_options) is an array");
RETURN_THROWS();
}
RETURN_BOOL(parse_context_options(context, options) == SUCCESS);
} else {
- zval *zvalue;
- char *wrappername, *optionname;
- size_t wrapperlen, optionlen;
-
- ZEND_PARSE_PARAMETERS_START(4, 4)
- Z_PARAM_RESOURCE(zcontext)
- Z_PARAM_STRING(wrappername, wrapperlen)
- Z_PARAM_STRING(optionname, optionlen)
- Z_PARAM_ZVAL(zvalue)
- ZEND_PARSE_PARAMETERS_END();
-
- /* figure out where the context is coming from exactly */
- if (!(context = decode_context_param(zcontext))) {
- zend_argument_type_error(1, "must be a valid stream/context");
+ if (!optionname) {
+ zend_argument_value_error(3, "cannot be null when argument #2 ($wrapper_or_options) is a string");
RETURN_THROWS();
}
- RETURN_BOOL(php_stream_context_set_option(context, wrappername, optionname, zvalue) == SUCCESS);
+ RETURN_BOOL(php_stream_context_set_option(context, ZSTR_VAL(wrappername), optionname, zvalue) == SUCCESS);
}
}
/* }}} */
@@ -1017,12 +1021,13 @@ PHP_FUNCTION(stream_context_set_option)
/* {{{ Set parameters for a file context */
PHP_FUNCTION(stream_context_set_params)
{
- zval *params, *zcontext;
+ HashTable *params;
+ zval *zcontext;
php_stream_context *context;
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_RESOURCE(zcontext)
- Z_PARAM_ARRAY(params)
+ Z_PARAM_ARRAY_HT(params)
ZEND_PARSE_PARAMETERS_END();
context = decode_context_param(zcontext);
@@ -1064,12 +1069,12 @@ PHP_FUNCTION(stream_context_get_params)
/* {{{ Get a handle on the default file/stream context and optionally set parameters */
PHP_FUNCTION(stream_context_get_default)
{
- zval *params = NULL;
+ HashTable *params = NULL;
php_stream_context *context;
ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
- Z_PARAM_ARRAY(params)
+ Z_PARAM_ARRAY_HT(params)
ZEND_PARSE_PARAMETERS_END();
if (FG(default_context) == NULL) {
@@ -1090,11 +1095,11 @@ PHP_FUNCTION(stream_context_get_default)
/* {{{ Set default file/stream context, returns the context as a resource */
PHP_FUNCTION(stream_context_set_default)
{
- zval *options = NULL;
+ HashTable *options;
php_stream_context *context;
ZEND_PARSE_PARAMETERS_START(1, 1)
- Z_PARAM_ARRAY(options)
+ Z_PARAM_ARRAY_HT(options)
ZEND_PARSE_PARAMETERS_END();
if (FG(default_context) == NULL) {
@@ -1113,13 +1118,14 @@ PHP_FUNCTION(stream_context_set_default)
/* {{{ Create a file context and optionally set parameters */
PHP_FUNCTION(stream_context_create)
{
- zval *options = NULL, *params = NULL;
+ HashTable *options = NULL;
+ HashTable *params = NULL;
php_stream_context *context;
ZEND_PARSE_PARAMETERS_START(0, 2)
Z_PARAM_OPTIONAL
- Z_PARAM_ARRAY_OR_NULL(options)
- Z_PARAM_ARRAY_OR_NULL(params)
+ Z_PARAM_ARRAY_HT_OR_NULL(options)
+ Z_PARAM_ARRAY_HT_OR_NULL(params)
ZEND_PARSE_PARAMETERS_END();
context = php_stream_context_alloc();