diff options
Diffstat (limited to 'ext/curl/interface.c')
-rw-r--r-- | ext/curl/interface.c | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/ext/curl/interface.c b/ext/curl/interface.c index 8621c23b2b..a529ef8e73 100644 --- a/ext/curl/interface.c +++ b/ext/curl/interface.c @@ -104,7 +104,7 @@ static int php_curl_option_str(php_curl *ch, zend_long option, const char *str, CURLcode error = CURLE_OK; if (strlen(str) != len) { - php_error_docref(NULL, E_WARNING, "Curl option contains invalid characters (\\0)"); + zend_type_error("%s(): cURL option cannot contain any null-bytes", get_active_function_name()); return FAILURE; } @@ -2204,7 +2204,7 @@ PHP_FUNCTION(curl_copy_handle) } /* }}} */ -static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{ */ +static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue, bool is_array_config) /* {{{ */ { CURLcode error = CURLE_OK; zend_long lval; @@ -2381,7 +2381,7 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{ break; case CURLOPT_SAFE_UPLOAD: if (!zend_is_true(zvalue)) { - php_error_docref(NULL, E_WARNING, "Disabling safe uploads is no longer supported"); + zend_value_error("%s(): Disabling safe uploads is no longer supported", get_active_function_name()); return FAILURE; } break; @@ -2557,7 +2557,7 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{ ch->handlers->write->method = PHP_CURL_FILE; ZVAL_COPY(&ch->handlers->write->stream, zvalue); } else { - php_error_docref(NULL, E_WARNING, "The provided file handle is not writable"); + zend_value_error("%s(): The provided file handle must be writable", get_active_function_name()); return FAILURE; } break; @@ -2575,7 +2575,7 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{ ch->handlers->write_header->method = PHP_CURL_FILE; ZVAL_COPY(&ch->handlers->write_header->stream, zvalue); } else { - php_error_docref(NULL, E_WARNING, "The provided file handle is not writable"); + zend_value_error("%s(): The provided file handle must be writable", get_active_function_name()); return FAILURE; } break; @@ -2604,7 +2604,7 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{ zval_ptr_dtor(&ch->handlers->std_err); ZVAL_COPY(&ch->handlers->std_err, zvalue); } else { - php_error_docref(NULL, E_WARNING, "The provided file handle is not writable"); + zend_value_error("%s(): The provided file handle must be writable", get_active_function_name()); return FAILURE; } /* break omitted intentionally */ @@ -2674,7 +2674,8 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{ break; #endif } - php_error_docref(NULL, E_WARNING, "You must pass an array with the %s argument", name); + + zend_type_error("%s(): The %s option must have an array value", get_active_function_name(), name); return FAILURE; } @@ -2850,6 +2851,14 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{ ch->handlers->fnmatch->method = PHP_CURL_USER; break; + default: + if (is_array_config) { + zend_argument_value_error(2, "must contain only valid cURL options"); + } else { + zend_argument_value_error(2, "is not a valid cURL option"); + } + error = CURLE_UNKNOWN_OPTION; + break; } SAVE_CURL_ERROR(ch, error); @@ -2876,12 +2885,7 @@ PHP_FUNCTION(curl_setopt) ch = Z_CURL_P(zid); - if (options <= 0 && options != CURLOPT_SAFE_UPLOAD) { - php_error_docref(NULL, E_WARNING, "Invalid curl configuration option"); - RETURN_FALSE; - } - - if (_php_curl_setopt(ch, options, zvalue) == SUCCESS) { + if (_php_curl_setopt(ch, options, zvalue, 0) == SUCCESS) { RETURN_TRUE; } else { RETURN_FALSE; @@ -2906,12 +2910,12 @@ PHP_FUNCTION(curl_setopt_array) ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(arr), option, string_key, entry) { if (string_key) { - php_error_docref(NULL, E_WARNING, - "Array keys must be CURLOPT constants or equivalent integer values"); - RETURN_FALSE; + zend_argument_value_error(2, "contains an invalid cURL option"); + RETURN_THROWS(); } + ZVAL_DEREF(entry); - if (_php_curl_setopt(ch, (zend_long) option, entry) == FAILURE) { + if (_php_curl_setopt(ch, (zend_long) option, entry, 1) == FAILURE) { RETURN_FALSE; } } ZEND_HASH_FOREACH_END(); @@ -3292,8 +3296,8 @@ PHP_FUNCTION(curl_close) ch = Z_CURL_P(zid); if (ch->in_callback) { - php_error_docref(NULL, E_WARNING, "Attempt to close cURL handle from a callback"); - return; + zend_throw_error(NULL, "%s(): Attempt to close cURL handle from a callback", get_active_function_name()); + RETURN_THROWS(); } } /* }}} */ @@ -3449,8 +3453,8 @@ PHP_FUNCTION(curl_reset) ch = Z_CURL_P(zid); if (ch->in_callback) { - php_error_docref(NULL, E_WARNING, "Attempt to reset cURL handle from a callback"); - return; + zend_throw_error(NULL, "%s(): Attempt to reset cURL handle from a callback", get_active_function_name()); + RETURN_THROWS(); } curl_easy_reset(ch->cp); |