@@ -506,6 +506,11 @@ static HashTable *curl_get_gc(zend_object *object, zval **table, int *n)
506506 zend_get_gc_buffer_add_fcc (gc_buffer , & curl -> handlers .fnmatch );
507507 }
508508
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
509514#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
510515 if (ZEND_FCC_INITIALIZED (curl -> handlers .sshhostkey )) {
511516 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,
711716}
712717/* }}} */
713718
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+
714766#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
715767static int curl_ssh_hostkeyfunction (void * clientp , int keytype , const char * key , size_t keylen )
716768{
@@ -1039,6 +1091,9 @@ void init_curl_handle(php_curl *ch)
10391091 ch -> handlers .progress = empty_fcall_info_cache ;
10401092 ch -> handlers .xferinfo = empty_fcall_info_cache ;
10411093 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
10421097#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
10431098 ch -> handlers .sshhostkey = empty_fcall_info_cache ;
10441099#endif
@@ -1213,7 +1268,7 @@ void _php_setup_easy_copy_handlers(php_curl *ch, php_curl *source)
12131268 php_curl_copy_fcc_with_option (ch , CURLOPT_XFERINFODATA , & ch -> handlers .xferinfo , & source -> handlers .xferinfo );
12141269 php_curl_copy_fcc_with_option (ch , CURLOPT_FNMATCH_DATA , & ch -> handlers .fnmatch , & source -> handlers .fnmatch );
12151270#if LIBCURL_VERSION_NUM >= 0x075000 /* Available since 7.80.0 */
1216- php_curl_copy_fcc_with_option (ch , CURLOPT_PREREQFUNCTION , & ch -> handlers .prereq , & source -> handlers .prereq );
1271+ php_curl_copy_fcc_with_option (ch , CURLOPT_PREREQDATA , & ch -> handlers .prereq , & source -> handlers .prereq );
12171272#endif
12181273#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
12191274 php_curl_copy_fcc_with_option (ch , CURLOPT_SSH_HOSTKEYDATA , & ch -> handlers .sshhostkey , & source -> handlers .sshhostkey );
@@ -1571,6 +1626,9 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue
15711626 HANDLE_CURL_OPTION_CALLABLE (ch , CURLOPT_PROGRESS , handlers .progress , curl_progress );
15721627 HANDLE_CURL_OPTION_CALLABLE (ch , CURLOPT_XFERINFO , handlers .xferinfo , curl_xferinfo );
15731628 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
15741632#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
15751633 HANDLE_CURL_OPTION_CALLABLE (ch , CURLOPT_SSH_HOSTKEY , handlers .sshhostkey , curl_ssh_hostkeyfunction );
15761634#endif
@@ -2730,6 +2788,11 @@ static void curl_free_obj(zend_object *object)
27302788 if (ZEND_FCC_INITIALIZED (ch -> handlers .fnmatch )) {
27312789 zend_fcc_dtor (& ch -> handlers .fnmatch );
27322790 }
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
27332796#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
27342797 if (ZEND_FCC_INITIALIZED (ch -> handlers .sshhostkey )) {
27352798 zend_fcc_dtor (& ch -> handlers .sshhostkey );
@@ -2808,7 +2871,11 @@ static void _php_curl_reset_handlers(php_curl *ch)
28082871 if (ZEND_FCC_INITIALIZED (ch -> handlers .fnmatch )) {
28092872 zend_fcc_dtor (& ch -> handlers .fnmatch );
28102873 }
2811-
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
28122879#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
28132880 if (ZEND_FCC_INITIALIZED (ch -> handlers .sshhostkey )) {
28142881 zend_fcc_dtor (& ch -> handlers .sshhostkey );
0 commit comments