Skip to content

Commit

Permalink
Support for curl_strerror and curl_multi_strerror
Browse files Browse the repository at this point in the history
Add the support for both curl_strerror and curl_multi_strerror.
Those function will return a string describing the error code
passed in the argument errornum
  • Loading branch information
adoy committed Dec 23, 2012
1 parent 64595a5 commit 4b4f3db
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 2 deletions.
38 changes: 37 additions & 1 deletion ext/curl/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,16 @@ ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_close, 0)
ZEND_ARG_INFO(0, mh)
ZEND_END_ARG_INFO()

#if LIBCURL_VERSION_NUM >= 0x070c00 /* Available since 7.12.0 */
ZEND_BEGIN_ARG_INFO(arginfo_curl_strerror, 0)
ZEND_ARG_INFO(0, errornum)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_strerror, 0)
ZEND_ARG_INFO(0, errornum)
ZEND_END_ARG_INFO()
#endif

ZEND_BEGIN_ARG_INFO(arginfo_curl_share_init, 0)
ZEND_END_ARG_INFO()

Expand Down Expand Up @@ -401,6 +411,10 @@ const zend_function_entry curl_functions[] = {
PHP_FE(curl_error, arginfo_curl_error)
PHP_FE(curl_errno, arginfo_curl_errno)
PHP_FE(curl_close, arginfo_curl_close)
#if LIBCURL_VERSION_NUM >= 0x070c00 /* 7.12.0 */
PHP_FE(curl_strerror, arginfo_curl_strerror)
PHP_FE(curl_multi_strerror, arginfo_curl_multi_strerror)
#endif
#if LIBCURL_VERSION_NUM >= 0x070c01 /* 7.12.1 */
PHP_FE(curl_reset, arginfo_curl_reset)
#endif
Expand Down Expand Up @@ -3256,6 +3270,28 @@ static void _php_curl_close(zend_rsrc_list_entry *rsrc TSRMLS_DC)
}
/* }}} */

#if LIBCURL_VERSION_NUM >= 0x070c00 /* Available since 7.12.0 */
/* {{{ proto bool curl_strerror(int code)
return string describing error code */
PHP_FUNCTION(curl_strerror)
{
long code;
const char *str;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &code) == FAILURE) {
return;
}

str = curl_easy_strerror(code);
if (str) {
RETURN_STRING(str, 1);
} else {
RETURN_NULL();
}
}
/* }}} */
#endif

#if LIBCURL_VERSION_NUM >= 0x070c01 /* 7.12.1 */
/* {{{ _php_curl_reset_handlers()
Reset all handlers of a given php_curl */
Expand All @@ -3280,7 +3316,7 @@ static void _php_curl_reset_handlers(php_curl *ch)
ch->handlers->read->stream = NULL;
}
ch->handlers->read->fp = NULL;
ch->handlers->read->fd = NULL;
ch->handlers->read->fd = 0;
ch->handlers->read->method = PHP_CURL_DIRECT;

if (ch->handlers->std_err) {
Expand Down
23 changes: 22 additions & 1 deletion ext/curl/multi.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,28 @@ void _php_curl_multi_close(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */
}
/* }}} */

#if LIBCURL_VERSION_NUM >= 0x070c00 /* Available since 7.12.0 */
/* {{{ proto bool curl_multi_strerror(int code)
return string describing error code */
PHP_FUNCTION(curl_multi_strerror)
{
long code;
const char *str;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &code) == FAILURE) {
return;
}

str = curl_multi_strerror(code);
if (str) {
RETURN_STRING(str, 1);
} else {
RETURN_NULL();
}
}
/* }}} */
#endif

#if LIBCURL_VERSION_NUM >= 0x070f04 /* 7.15.4 */
static int _php_curl_multi_setopt(php_curlm *mh, long option, zval **zvalue, zval *return_value TSRMLS_DC) /* {{{ */
{
Expand Down Expand Up @@ -389,7 +411,6 @@ static int _php_curl_multi_setopt(php_curlm *mh, long option, zval **zvalue, zva
}
/* }}} */


/* {{{ proto int curl_multi_setopt(resource mh, int option, mixed value)
Set an option for the curl multi handle */
PHP_FUNCTION(curl_multi_setopt)
Expand Down
5 changes: 5 additions & 0 deletions ext/curl/php_curl.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ PHP_FUNCTION(curl_share_close);
PHP_FUNCTION(curl_share_init);
PHP_FUNCTION(curl_share_setopt);

#if LIBCURL_VERSION_NUM >= 0x070c00 /* 7.12.0 */
PHP_FUNCTION(curl_strerror);
PHP_FUNCTION(curl_multi_strerror);
#endif

#if LIBCURL_VERSION_NUM >= 0x070c01 /* 7.12.1 */
PHP_FUNCTION(curl_reset);
#endif
Expand Down
20 changes: 20 additions & 0 deletions ext/curl/tests/curl_multi_strerror_001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
curl_multi_strerror basic test
--SKIPIF--
if (!extension_loaded("curl")) {
exit("skip curl extension not loaded");
}
$curl_version = curl_version();
if ($curl_version['version_number'] < 0x070c00) {
exit("skip: test works only with curl >= 7.12.0");
}
--FILE--
<?php

var_dump(curl_multi_strerror(CURLM_OK));
var_dump(curl_multi_strerror(CURLM_BAD_HANDLE));

?>
--EXPECTF--
string(8) "No error"
string(20) "Invalid multi handle"
22 changes: 22 additions & 0 deletions ext/curl/tests/curl_strerror_001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
curl_strerror basic test
--SKIPIF--
if (!extension_loaded("curl")) {
exit("skip curl extension not loaded");
}
$curl_version = curl_version();
if ($curl_version['version_number'] < 0x070c00) {
exit("skip: test works only with curl >= 7.12.0");
}
--FILE--
<?php

var_dump(curl_strerror(CURLE_OK));
var_dump(curl_strerror(CURLE_UNSUPPORTED_PROTOCOL));
var_dump(curl_strerror(-1));

?>
--EXPECTF--
string(8) "No error"
string(20) "Unsupported protocol"
string(13) "Unknown error"

0 comments on commit 4b4f3db

Please sign in to comment.