@@ -506,6 +506,11 @@ static HashTable *curl_get_gc(zend_object *object, zval **table, int *n)
506
506
zend_get_gc_buffer_add_fcc (gc_buffer , & curl -> handlers .fnmatch );
507
507
}
508
508
509
+ #if LIBCURL_VERSION_NUM >= 0x075000 /* Available since 7.80.0 */
510
+ if (ZEND_FCC_INITIALIZED (curl -> handlers .prereq )) {
511
+ zend_get_gc_buffer_add_fcc (gc_buffer , & curl -> handlers .prereq );
512
+ }
513
+ #endif
509
514
#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
510
515
if (ZEND_FCC_INITIALIZED (curl -> handlers .sshhostkey )) {
511
516
zend_get_gc_buffer_add_fcc (gc_buffer , & curl -> handlers .sshhostkey );
@@ -711,6 +716,53 @@ static size_t curl_xferinfo(void *clientp, curl_off_t dltotal, curl_off_t dlnow,
711
716
}
712
717
/* }}} */
713
718
719
+ #if LIBCURL_VERSION_NUM >= 0x075000 /* Available since 7.80.0 */
720
+ static int curl_prereqfunction (void * clientp , char * conn_primary_ip , char * conn_local_ip , int conn_primary_port , int conn_local_port )
721
+ {
722
+ php_curl * ch = (php_curl * )clientp ;
723
+ int rval = CURL_PREREQFUNC_ABORT ;
724
+
725
+ #if PHP_CURL_DEBUG
726
+ fprintf (stderr , "curl_prereqfunction() called\n" );
727
+ 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 );
728
+ #endif
729
+
730
+ zval args [5 ];
731
+ zval retval ;
732
+
733
+ GC_ADDREF (& ch -> std );
734
+ ZVAL_OBJ (& args [0 ], & ch -> std );
735
+ ZVAL_STRING (& args [1 ], conn_primary_ip );
736
+ ZVAL_STRING (& args [2 ], conn_local_ip );
737
+ ZVAL_LONG (& args [3 ], conn_primary_port );
738
+ ZVAL_LONG (& args [4 ], conn_local_port );
739
+
740
+ ch -> in_callback = true;
741
+ zend_call_known_fcc (& ch -> handlers .prereq , & retval , /* param_count */ 5 , args , /* named_params */ NULL );
742
+ ch -> in_callback = false;
743
+
744
+ if (!Z_ISUNDEF (retval )) {
745
+ _php_curl_verify_handlers (ch , /* reporterror */ true);
746
+ if (Z_TYPE (retval ) == IS_LONG ) {
747
+ zend_long retval_long = Z_LVAL (retval );
748
+ if (retval_long == CURL_PREREQFUNC_OK || retval_long == CURL_PREREQFUNC_ABORT ) {
749
+ rval = retval_long ;
750
+ } else {
751
+ zend_throw_error (NULL , "The CURLOPT_PREREQFUNCTION callback must return either CURL_PREREQFUNC_OK or CURL_PREREQFUNC_ABORT" );
752
+ }
753
+ } else {
754
+ zend_throw_error (NULL , "The CURLOPT_PREREQFUNCTION callback must return either CURL_PREREQFUNC_OK or CURL_PREREQFUNC_ABORT" );
755
+ }
756
+ }
757
+
758
+ zval_ptr_dtor (& args [0 ]);
759
+ zval_ptr_dtor (& args [1 ]);
760
+ zval_ptr_dtor (& args [2 ]);
761
+
762
+ return rval ;
763
+ }
764
+ #endif
765
+
714
766
#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
715
767
static int curl_ssh_hostkeyfunction (void * clientp , int keytype , const char * key , size_t keylen )
716
768
{
@@ -1039,6 +1091,9 @@ void init_curl_handle(php_curl *ch)
1039
1091
ch -> handlers .progress = empty_fcall_info_cache ;
1040
1092
ch -> handlers .xferinfo = empty_fcall_info_cache ;
1041
1093
ch -> handlers .fnmatch = empty_fcall_info_cache ;
1094
+ #if LIBCURL_VERSION_NUM >= 0x075000 /* Available since 7.80.0 */
1095
+ ch -> handlers .prereq = empty_fcall_info_cache ;
1096
+ #endif
1042
1097
#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
1043
1098
ch -> handlers .sshhostkey = empty_fcall_info_cache ;
1044
1099
#endif
@@ -1212,6 +1267,9 @@ void _php_setup_easy_copy_handlers(php_curl *ch, php_curl *source)
1212
1267
php_curl_copy_fcc_with_option (ch , CURLOPT_PROGRESSDATA , & ch -> handlers .progress , & source -> handlers .progress );
1213
1268
php_curl_copy_fcc_with_option (ch , CURLOPT_XFERINFODATA , & ch -> handlers .xferinfo , & source -> handlers .xferinfo );
1214
1269
php_curl_copy_fcc_with_option (ch , CURLOPT_FNMATCH_DATA , & ch -> handlers .fnmatch , & source -> handlers .fnmatch );
1270
+ #if LIBCURL_VERSION_NUM >= 0x075000 /* Available since 7.80.0 */
1271
+ php_curl_copy_fcc_with_option (ch , CURLOPT_PREREQDATA , & ch -> handlers .prereq , & source -> handlers .prereq );
1272
+ #endif
1215
1273
#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
1216
1274
php_curl_copy_fcc_with_option (ch , CURLOPT_SSH_HOSTKEYDATA , & ch -> handlers .sshhostkey , & source -> handlers .sshhostkey );
1217
1275
#endif
@@ -1568,6 +1626,9 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue
1568
1626
HANDLE_CURL_OPTION_CALLABLE (ch , CURLOPT_PROGRESS , handlers .progress , curl_progress );
1569
1627
HANDLE_CURL_OPTION_CALLABLE (ch , CURLOPT_XFERINFO , handlers .xferinfo , curl_xferinfo );
1570
1628
HANDLE_CURL_OPTION_CALLABLE (ch , CURLOPT_FNMATCH_ , handlers .fnmatch , curl_fnmatch );
1629
+ #if LIBCURL_VERSION_NUM >= 0x075000 /* Available since 7.80.0 */
1630
+ HANDLE_CURL_OPTION_CALLABLE (ch , CURLOPT_PREREQ , handlers .prereq , curl_prereqfunction );
1631
+ #endif
1571
1632
#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
1572
1633
HANDLE_CURL_OPTION_CALLABLE (ch , CURLOPT_SSH_HOSTKEY , handlers .sshhostkey , curl_ssh_hostkeyfunction );
1573
1634
#endif
@@ -2727,6 +2788,11 @@ static void curl_free_obj(zend_object *object)
2727
2788
if (ZEND_FCC_INITIALIZED (ch -> handlers .fnmatch )) {
2728
2789
zend_fcc_dtor (& ch -> handlers .fnmatch );
2729
2790
}
2791
+ #if LIBCURL_VERSION_NUM >= 0x075000 /* Available since 7.80.0 */
2792
+ if (ZEND_FCC_INITIALIZED (ch -> handlers .prereq )) {
2793
+ zend_fcc_dtor (& ch -> handlers .prereq );
2794
+ }
2795
+ #endif
2730
2796
#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
2731
2797
if (ZEND_FCC_INITIALIZED (ch -> handlers .sshhostkey )) {
2732
2798
zend_fcc_dtor (& ch -> handlers .sshhostkey );
@@ -2805,7 +2871,11 @@ static void _php_curl_reset_handlers(php_curl *ch)
2805
2871
if (ZEND_FCC_INITIALIZED (ch -> handlers .fnmatch )) {
2806
2872
zend_fcc_dtor (& ch -> handlers .fnmatch );
2807
2873
}
2808
-
2874
+ #if LIBCURL_VERSION_NUM >= 0x075000 /* Available since 7.80.0 */
2875
+ if (ZEND_FCC_INITIALIZED (ch -> handlers .prereq )) {
2876
+ zend_fcc_dtor (& ch -> handlers .prereq );
2877
+ }
2878
+ #endif
2809
2879
#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
2810
2880
if (ZEND_FCC_INITIALIZED (ch -> handlers .sshhostkey )) {
2811
2881
zend_fcc_dtor (& ch -> handlers .sshhostkey );
0 commit comments