@@ -456,6 +456,9 @@ PHP_MINIT_FUNCTION(curl)
456
456
REGISTER_CURL_CONSTANT (CURLOPT_VERBOSE );
457
457
REGISTER_CURL_CONSTANT (CURLOPT_WRITEFUNCTION );
458
458
REGISTER_CURL_CONSTANT (CURLOPT_WRITEHEADER );
459
+ #if LIBCURL_VERSION_NUM >= 0x072000
460
+ REGISTER_CURL_CONSTANT (CURLOPT_XFERINFOFUNCTION );
461
+ #endif
459
462
460
463
/* */
461
464
REGISTER_CURL_CONSTANT (CURLE_ABORTED_BY_CALLBACK );
@@ -1287,11 +1290,15 @@ static HashTable *curl_get_gc(zend_object *object, zval **table, int *n)
1287
1290
zend_get_gc_buffer_add_zval (gc_buffer , & curl -> handlers .progress -> func_name );
1288
1291
}
1289
1292
1290
- #if LIBCURL_VERSION_NUM >= 0x071500
1293
+ #if LIBCURL_VERSION_NUM >= 0x072000
1294
+ if (curl -> handlers .xferinfo ) {
1295
+ zend_get_gc_buffer_add_zval (gc_buffer , & curl -> handlers .xferinfo -> func_name );
1296
+ }
1297
+ #endif
1298
+
1291
1299
if (curl -> handlers .fnmatch ) {
1292
1300
zend_get_gc_buffer_add_zval (gc_buffer , & curl -> handlers .fnmatch -> func_name );
1293
1301
}
1294
- #endif
1295
1302
1296
1303
zend_get_gc_buffer_add_zval (gc_buffer , & curl -> handlers .std_err );
1297
1304
zend_get_gc_buffer_add_zval (gc_buffer , & curl -> private_data );
@@ -1496,6 +1503,56 @@ static size_t curl_progress(void *clientp, double dltotal, double dlnow, double
1496
1503
}
1497
1504
/* }}} */
1498
1505
1506
+ #if LIBCURL_VERSION_NUM >= 0x072000
1507
+ /* {{{ curl_xferinfo */
1508
+ static size_t curl_xferinfo (void * clientp , curl_off_t dltotal , curl_off_t dlnow , curl_off_t ultotal , curl_off_t ulnow )
1509
+ {
1510
+ php_curl * ch = (php_curl * )clientp ;
1511
+ php_curl_callback * t = ch -> handlers .xferinfo ;
1512
+ size_t rval = 0 ;
1513
+
1514
+ #if PHP_CURL_DEBUG
1515
+ fprintf (stderr , "curl_xferinfo() called\n" );
1516
+ fprintf (stderr , "clientp = %x, dltotal = %ld, dlnow = %ld, ultotal = %ld, ulnow = %ld\n" , clientp , dltotal , dlnow , ultotal , ulnow );
1517
+ #endif
1518
+
1519
+ zval argv [5 ];
1520
+ zval retval ;
1521
+ zend_result error ;
1522
+ zend_fcall_info fci ;
1523
+
1524
+ GC_ADDREF (& ch -> std );
1525
+ ZVAL_OBJ (& argv [0 ], & ch -> std );
1526
+ ZVAL_LONG (& argv [1 ], dltotal );
1527
+ ZVAL_LONG (& argv [2 ], dlnow );
1528
+ ZVAL_LONG (& argv [3 ], ultotal );
1529
+ ZVAL_LONG (& argv [4 ], ulnow );
1530
+
1531
+ fci .size = sizeof (fci );
1532
+ ZVAL_COPY_VALUE (& fci .function_name , & t -> func_name );
1533
+ fci .object = NULL ;
1534
+ fci .retval = & retval ;
1535
+ fci .param_count = 5 ;
1536
+ fci .params = argv ;
1537
+ fci .named_params = NULL ;
1538
+
1539
+ ch -> in_callback = 1 ;
1540
+ error = zend_call_function (& fci , & t -> fci_cache );
1541
+ ch -> in_callback = 0 ;
1542
+ if (error == FAILURE ) {
1543
+ php_error_docref (NULL , E_WARNING , "Cannot call the CURLOPT_XFERINFOFUNCTION" );
1544
+ } else if (!Z_ISUNDEF (retval )) {
1545
+ _php_curl_verify_handlers (ch , /* reporterror */ true);
1546
+ if (0 != zval_get_long (& retval )) {
1547
+ rval = 1 ;
1548
+ }
1549
+ }
1550
+ zval_ptr_dtor (& argv [0 ]);
1551
+ return rval ;
1552
+ }
1553
+ /* }}} */
1554
+ #endif
1555
+
1499
1556
/* {{{ curl_read */
1500
1557
static size_t curl_read (char * data , size_t size , size_t nmemb , void * ctx )
1501
1558
{
@@ -1753,6 +1810,9 @@ void init_curl_handle(php_curl *ch)
1753
1810
ch -> handlers .write_header = ecalloc (1 , sizeof (php_curl_write ));
1754
1811
ch -> handlers .read = ecalloc (1 , sizeof (php_curl_read ));
1755
1812
ch -> handlers .progress = NULL ;
1813
+ #if LIBCURL_VERSION_NUM >= 0x072000
1814
+ ch -> handlers .xferinfo = NULL ;
1815
+ #endif
1756
1816
ch -> handlers .fnmatch = NULL ;
1757
1817
ch -> clone = emalloc (sizeof (uint32_t ));
1758
1818
* ch -> clone = 1 ;
@@ -1925,6 +1985,16 @@ void _php_setup_easy_copy_handlers(php_curl *ch, php_curl *source)
1925
1985
curl_easy_setopt (ch -> cp , CURLOPT_PROGRESSDATA , (void * ) ch );
1926
1986
}
1927
1987
1988
+ #if LIBCURL_VERSION_NUM >= 0x072000
1989
+ if (source -> handlers .xferinfo ) {
1990
+ ch -> handlers .xferinfo = ecalloc (1 , sizeof (php_curl_callback ));
1991
+ if (!Z_ISUNDEF (source -> handlers .xferinfo -> func_name )) {
1992
+ ZVAL_COPY (& ch -> handlers .xferinfo -> func_name , & source -> handlers .xferinfo -> func_name );
1993
+ }
1994
+ curl_easy_setopt (ch -> cp , CURLOPT_XFERINFODATA , (void * ) ch );
1995
+ }
1996
+ #endif
1997
+
1928
1998
if (source -> handlers .fnmatch ) {
1929
1999
ch -> handlers .fnmatch = ecalloc (1 , sizeof (php_curl_callback ));
1930
2000
if (!Z_ISUNDEF (source -> handlers .fnmatch -> func_name )) {
@@ -2884,6 +2954,20 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue
2884
2954
ch -> handlers .write -> method = PHP_CURL_USER ;
2885
2955
break ;
2886
2956
2957
+ #if LIBCURL_VERSION_NUM >= 0x072000
2958
+ case CURLOPT_XFERINFOFUNCTION :
2959
+ curl_easy_setopt (ch -> cp , CURLOPT_XFERINFOFUNCTION , curl_xferinfo );
2960
+ curl_easy_setopt (ch -> cp , CURLOPT_XFERINFODATA , ch );
2961
+ if (ch -> handlers .xferinfo == NULL ) {
2962
+ ch -> handlers .xferinfo = ecalloc (1 , sizeof (php_curl_callback ));
2963
+ } else if (!Z_ISUNDEF (ch -> handlers .xferinfo -> func_name )) {
2964
+ zval_ptr_dtor (& ch -> handlers .xferinfo -> func_name );
2965
+ ch -> handlers .xferinfo -> fci_cache = empty_fcall_info_cache ;
2966
+ }
2967
+ ZVAL_COPY (& ch -> handlers .xferinfo -> func_name , zvalue );
2968
+ break ;
2969
+ #endif
2970
+
2887
2971
/* Curl off_t options */
2888
2972
case CURLOPT_MAX_RECV_SPEED_LARGE :
2889
2973
case CURLOPT_MAX_SEND_SPEED_LARGE :
@@ -3521,6 +3605,13 @@ static void curl_free_obj(zend_object *object)
3521
3605
efree (ch -> handlers .progress );
3522
3606
}
3523
3607
3608
+ #if LIBCURL_VERSION_NUM >= 0x072000
3609
+ if (ch -> handlers .xferinfo ) {
3610
+ zval_ptr_dtor (& ch -> handlers .xferinfo -> func_name );
3611
+ efree (ch -> handlers .xferinfo );
3612
+ }
3613
+ #endif
3614
+
3524
3615
if (ch -> handlers .fnmatch ) {
3525
3616
zval_ptr_dtor (& ch -> handlers .fnmatch -> func_name );
3526
3617
efree (ch -> handlers .fnmatch );
@@ -3593,12 +3684,19 @@ static void _php_curl_reset_handlers(php_curl *ch)
3593
3684
ch -> handlers .progress = NULL ;
3594
3685
}
3595
3686
3687
+ #if LIBCURL_VERSION_NUM >= 0x072000
3688
+ if (ch -> handlers .xferinfo ) {
3689
+ zval_ptr_dtor (& ch -> handlers .xferinfo -> func_name );
3690
+ efree (ch -> handlers .xferinfo );
3691
+ ch -> handlers .xferinfo = NULL ;
3692
+ }
3693
+ #endif
3694
+
3596
3695
if (ch -> handlers .fnmatch ) {
3597
3696
zval_ptr_dtor (& ch -> handlers .fnmatch -> func_name );
3598
3697
efree (ch -> handlers .fnmatch );
3599
3698
ch -> handlers .fnmatch = NULL ;
3600
3699
}
3601
-
3602
3700
}
3603
3701
/* }}} */
3604
3702
0 commit comments