Skip to content

Commit 4b4f3db

Browse files
committed
Support for curl_strerror and curl_multi_strerror
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
1 parent 64595a5 commit 4b4f3db

File tree

5 files changed

+106
-2
lines changed

5 files changed

+106
-2
lines changed

ext/curl/interface.c

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,16 @@ ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_close, 0)
374374
ZEND_ARG_INFO(0, mh)
375375
ZEND_END_ARG_INFO()
376376

377+
#if LIBCURL_VERSION_NUM >= 0x070c00 /* Available since 7.12.0 */
378+
ZEND_BEGIN_ARG_INFO(arginfo_curl_strerror, 0)
379+
ZEND_ARG_INFO(0, errornum)
380+
ZEND_END_ARG_INFO()
381+
382+
ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_strerror, 0)
383+
ZEND_ARG_INFO(0, errornum)
384+
ZEND_END_ARG_INFO()
385+
#endif
386+
377387
ZEND_BEGIN_ARG_INFO(arginfo_curl_share_init, 0)
378388
ZEND_END_ARG_INFO()
379389

@@ -401,6 +411,10 @@ const zend_function_entry curl_functions[] = {
401411
PHP_FE(curl_error, arginfo_curl_error)
402412
PHP_FE(curl_errno, arginfo_curl_errno)
403413
PHP_FE(curl_close, arginfo_curl_close)
414+
#if LIBCURL_VERSION_NUM >= 0x070c00 /* 7.12.0 */
415+
PHP_FE(curl_strerror, arginfo_curl_strerror)
416+
PHP_FE(curl_multi_strerror, arginfo_curl_multi_strerror)
417+
#endif
404418
#if LIBCURL_VERSION_NUM >= 0x070c01 /* 7.12.1 */
405419
PHP_FE(curl_reset, arginfo_curl_reset)
406420
#endif
@@ -3256,6 +3270,28 @@ static void _php_curl_close(zend_rsrc_list_entry *rsrc TSRMLS_DC)
32563270
}
32573271
/* }}} */
32583272

3273+
#if LIBCURL_VERSION_NUM >= 0x070c00 /* Available since 7.12.0 */
3274+
/* {{{ proto bool curl_strerror(int code)
3275+
return string describing error code */
3276+
PHP_FUNCTION(curl_strerror)
3277+
{
3278+
long code;
3279+
const char *str;
3280+
3281+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &code) == FAILURE) {
3282+
return;
3283+
}
3284+
3285+
str = curl_easy_strerror(code);
3286+
if (str) {
3287+
RETURN_STRING(str, 1);
3288+
} else {
3289+
RETURN_NULL();
3290+
}
3291+
}
3292+
/* }}} */
3293+
#endif
3294+
32593295
#if LIBCURL_VERSION_NUM >= 0x070c01 /* 7.12.1 */
32603296
/* {{{ _php_curl_reset_handlers()
32613297
Reset all handlers of a given php_curl */
@@ -3280,7 +3316,7 @@ static void _php_curl_reset_handlers(php_curl *ch)
32803316
ch->handlers->read->stream = NULL;
32813317
}
32823318
ch->handlers->read->fp = NULL;
3283-
ch->handlers->read->fd = NULL;
3319+
ch->handlers->read->fd = 0;
32843320
ch->handlers->read->method = PHP_CURL_DIRECT;
32853321

32863322
if (ch->handlers->std_err) {

ext/curl/multi.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,28 @@ void _php_curl_multi_close(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */
359359
}
360360
/* }}} */
361361

362+
#if LIBCURL_VERSION_NUM >= 0x070c00 /* Available since 7.12.0 */
363+
/* {{{ proto bool curl_multi_strerror(int code)
364+
return string describing error code */
365+
PHP_FUNCTION(curl_multi_strerror)
366+
{
367+
long code;
368+
const char *str;
369+
370+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &code) == FAILURE) {
371+
return;
372+
}
373+
374+
str = curl_multi_strerror(code);
375+
if (str) {
376+
RETURN_STRING(str, 1);
377+
} else {
378+
RETURN_NULL();
379+
}
380+
}
381+
/* }}} */
382+
#endif
383+
362384
#if LIBCURL_VERSION_NUM >= 0x070f04 /* 7.15.4 */
363385
static int _php_curl_multi_setopt(php_curlm *mh, long option, zval **zvalue, zval *return_value TSRMLS_DC) /* {{{ */
364386
{
@@ -389,7 +411,6 @@ static int _php_curl_multi_setopt(php_curlm *mh, long option, zval **zvalue, zva
389411
}
390412
/* }}} */
391413

392-
393414
/* {{{ proto int curl_multi_setopt(resource mh, int option, mixed value)
394415
Set an option for the curl multi handle */
395416
PHP_FUNCTION(curl_multi_setopt)

ext/curl/php_curl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ PHP_FUNCTION(curl_share_close);
8484
PHP_FUNCTION(curl_share_init);
8585
PHP_FUNCTION(curl_share_setopt);
8686

87+
#if LIBCURL_VERSION_NUM >= 0x070c00 /* 7.12.0 */
88+
PHP_FUNCTION(curl_strerror);
89+
PHP_FUNCTION(curl_multi_strerror);
90+
#endif
91+
8792
#if LIBCURL_VERSION_NUM >= 0x070c01 /* 7.12.1 */
8893
PHP_FUNCTION(curl_reset);
8994
#endif
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
curl_multi_strerror basic test
3+
--SKIPIF--
4+
if (!extension_loaded("curl")) {
5+
exit("skip curl extension not loaded");
6+
}
7+
$curl_version = curl_version();
8+
if ($curl_version['version_number'] < 0x070c00) {
9+
exit("skip: test works only with curl >= 7.12.0");
10+
}
11+
--FILE--
12+
<?php
13+
14+
var_dump(curl_multi_strerror(CURLM_OK));
15+
var_dump(curl_multi_strerror(CURLM_BAD_HANDLE));
16+
17+
?>
18+
--EXPECTF--
19+
string(8) "No error"
20+
string(20) "Invalid multi handle"

ext/curl/tests/curl_strerror_001.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
curl_strerror basic test
3+
--SKIPIF--
4+
if (!extension_loaded("curl")) {
5+
exit("skip curl extension not loaded");
6+
}
7+
$curl_version = curl_version();
8+
if ($curl_version['version_number'] < 0x070c00) {
9+
exit("skip: test works only with curl >= 7.12.0");
10+
}
11+
--FILE--
12+
<?php
13+
14+
var_dump(curl_strerror(CURLE_OK));
15+
var_dump(curl_strerror(CURLE_UNSUPPORTED_PROTOCOL));
16+
var_dump(curl_strerror(-1));
17+
18+
?>
19+
--EXPECTF--
20+
string(8) "No error"
21+
string(20) "Unsupported protocol"
22+
string(13) "Unknown error"

0 commit comments

Comments
 (0)