@@ -504,6 +504,11 @@ static HashTable *curl_get_gc(zend_object *object, zval **table, int *n)
504
504
zend_get_gc_buffer_add_fcc (gc_buffer , & curl -> handlers .fnmatch );
505
505
}
506
506
507
+ #if LIBCURL_VERSION_NUM >= 0x075000 /* Available since 7.80.0 */
508
+ if (ZEND_FCC_INITIALIZED (curl -> handlers .prereq )) {
509
+ zend_get_gc_buffer_add_fcc (gc_buffer , & curl -> handlers .prereq );
510
+ }
511
+ #endif
507
512
#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
508
513
if (ZEND_FCC_INITIALIZED (curl -> handlers .sshhostkey )) {
509
514
zend_get_gc_buffer_add_fcc (gc_buffer , & curl -> handlers .sshhostkey );
@@ -709,6 +714,53 @@ static size_t curl_xferinfo(void *clientp, curl_off_t dltotal, curl_off_t dlnow,
709
714
}
710
715
/* }}} */
711
716
717
+ #if LIBCURL_VERSION_NUM >= 0x075000 /* Available since 7.80.0 */
718
+ static int curl_prereqfunction (void * clientp , char * conn_primary_ip , char * conn_local_ip , int conn_primary_port , int conn_local_port )
719
+ {
720
+ php_curl * ch = (php_curl * )clientp ;
721
+ int rval = CURL_PREREQFUNC_ABORT ;
722
+
723
+ #if PHP_CURL_DEBUG
724
+ fprintf (stderr , "curl_prereqfunction() called\n" );
725
+ fprintf (stderr , "clientp = %x, conn_primary_ip = %s, conn_local_ip = %s, conn_primary_port = %d, conn_local_port = %d\n" , clientp , conn_primary_ip , conn_local_ip , conn_primary_port , conn_local_port );
726
+ #endif
727
+
728
+ zval args [5 ];
729
+ zval retval ;
730
+
731
+ GC_ADDREF (& ch -> std );
732
+ ZVAL_OBJ (& args [0 ], & ch -> std );
733
+ ZVAL_STRING (& args [1 ], conn_primary_ip );
734
+ ZVAL_STRING (& args [2 ], conn_local_ip );
735
+ ZVAL_LONG (& args [3 ], conn_primary_port );
736
+ ZVAL_LONG (& args [4 ], conn_local_port );
737
+
738
+ ch -> in_callback = true;
739
+ zend_call_known_fcc (& ch -> handlers .prereq , & retval , /* param_count */ 5 , args , /* named_params */ NULL );
740
+ ch -> in_callback = false;
741
+
742
+ if (!Z_ISUNDEF (retval )) {
743
+ _php_curl_verify_handlers (ch , /* reporterror */ true);
744
+ if (Z_TYPE (retval ) == IS_LONG ) {
745
+ zend_long retval_long = Z_LVAL (retval );
746
+ if (retval_long == CURL_PREREQFUNC_OK || retval_long == CURL_PREREQFUNC_ABORT ) {
747
+ rval = retval_long ;
748
+ } else {
749
+ zend_value_error ("The CURLOPT_PREREQFUNCTION callback must return either CURL_PREREQFUNC_OK or CURL_PREREQFUNC_ABORT" );
750
+ }
751
+ } else {
752
+ zend_type_error ("The CURLOPT_PREREQFUNCTION callback must return either CURL_PREREQFUNC_OK or CURL_PREREQFUNC_ABORT" );
753
+ }
754
+ }
755
+
756
+ zval_ptr_dtor (& args [0 ]);
757
+ zval_ptr_dtor (& args [1 ]);
758
+ zval_ptr_dtor (& args [2 ]);
759
+
760
+ return rval ;
761
+ }
762
+ #endif
763
+
712
764
#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
713
765
static int curl_ssh_hostkeyfunction (void * clientp , int keytype , const char * key , size_t keylen )
714
766
{
@@ -1037,6 +1089,9 @@ void init_curl_handle(php_curl *ch)
1037
1089
ch -> handlers .progress = empty_fcall_info_cache ;
1038
1090
ch -> handlers .xferinfo = empty_fcall_info_cache ;
1039
1091
ch -> handlers .fnmatch = empty_fcall_info_cache ;
1092
+ #if LIBCURL_VERSION_NUM >= 0x075000 /* Available since 7.80.0 */
1093
+ ch -> handlers .prereq = empty_fcall_info_cache ;
1094
+ #endif
1040
1095
#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
1041
1096
ch -> handlers .sshhostkey = empty_fcall_info_cache ;
1042
1097
#endif
@@ -1210,6 +1265,9 @@ void _php_setup_easy_copy_handlers(php_curl *ch, php_curl *source)
1210
1265
php_curl_copy_fcc_with_option (ch , CURLOPT_PROGRESSDATA , & ch -> handlers .progress , & source -> handlers .progress );
1211
1266
php_curl_copy_fcc_with_option (ch , CURLOPT_XFERINFODATA , & ch -> handlers .xferinfo , & source -> handlers .xferinfo );
1212
1267
php_curl_copy_fcc_with_option (ch , CURLOPT_FNMATCH_DATA , & ch -> handlers .fnmatch , & source -> handlers .fnmatch );
1268
+ #if LIBCURL_VERSION_NUM >= 0x075000 /* Available since 7.80.0 */
1269
+ php_curl_copy_fcc_with_option (ch , CURLOPT_PREREQDATA , & ch -> handlers .prereq , & source -> handlers .prereq );
1270
+ #endif
1213
1271
#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
1214
1272
php_curl_copy_fcc_with_option (ch , CURLOPT_SSH_HOSTKEYDATA , & ch -> handlers .sshhostkey , & source -> handlers .sshhostkey );
1215
1273
#endif
@@ -1570,6 +1628,9 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue
1570
1628
HANDLE_CURL_OPTION_CALLABLE (ch , CURLOPT_PROGRESS , handlers .progress , curl_progress );
1571
1629
HANDLE_CURL_OPTION_CALLABLE (ch , CURLOPT_XFERINFO , handlers .xferinfo , curl_xferinfo );
1572
1630
HANDLE_CURL_OPTION_CALLABLE (ch , CURLOPT_FNMATCH_ , handlers .fnmatch , curl_fnmatch );
1631
+ #if LIBCURL_VERSION_NUM >= 0x075000 /* Available since 7.80.0 */
1632
+ HANDLE_CURL_OPTION_CALLABLE (ch , CURLOPT_PREREQ , handlers .prereq , curl_prereqfunction );
1633
+ #endif
1573
1634
#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
1574
1635
HANDLE_CURL_OPTION_CALLABLE (ch , CURLOPT_SSH_HOSTKEY , handlers .sshhostkey , curl_ssh_hostkeyfunction );
1575
1636
#endif
@@ -2736,6 +2797,11 @@ static void curl_free_obj(zend_object *object)
2736
2797
if (ZEND_FCC_INITIALIZED (ch -> handlers .fnmatch )) {
2737
2798
zend_fcc_dtor (& ch -> handlers .fnmatch );
2738
2799
}
2800
+ #if LIBCURL_VERSION_NUM >= 0x075000 /* Available since 7.80.0 */
2801
+ if (ZEND_FCC_INITIALIZED (ch -> handlers .prereq )) {
2802
+ zend_fcc_dtor (& ch -> handlers .prereq );
2803
+ }
2804
+ #endif
2739
2805
#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
2740
2806
if (ZEND_FCC_INITIALIZED (ch -> handlers .sshhostkey )) {
2741
2807
zend_fcc_dtor (& ch -> handlers .sshhostkey );
@@ -2814,7 +2880,11 @@ static void _php_curl_reset_handlers(php_curl *ch)
2814
2880
if (ZEND_FCC_INITIALIZED (ch -> handlers .fnmatch )) {
2815
2881
zend_fcc_dtor (& ch -> handlers .fnmatch );
2816
2882
}
2817
-
2883
+ #if LIBCURL_VERSION_NUM >= 0x075000 /* Available since 7.80.0 */
2884
+ if (ZEND_FCC_INITIALIZED (ch -> handlers .prereq )) {
2885
+ zend_fcc_dtor (& ch -> handlers .prereq );
2886
+ }
2887
+ #endif
2818
2888
#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
2819
2889
if (ZEND_FCC_INITIALIZED (ch -> handlers .sshhostkey )) {
2820
2890
zend_fcc_dtor (& ch -> handlers .sshhostkey );
0 commit comments