@@ -2115,12 +2115,75 @@ void _php_setup_easy_copy_handlers(php_curl *ch, php_curl *source)
21152115}
21162116
21172117#if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
2118- static size_t read_cb (char * buffer , size_t size , size_t nitems , void * arg );
2119- static int seek_cb (void * arg , curl_off_t offset , int origin );
2120- static void free_cb (void * arg );
2118+ static size_t read_cb (char * buffer , size_t size , size_t nitems , void * arg ) /* {{{ */
2119+ {
2120+ struct mime_data_cb_arg * cb_arg = (struct mime_data_cb_arg * ) arg ;
2121+ ssize_t numread ;
2122+
2123+ ZEND_ASSERT (!cb_arg -> ch );
2124+
2125+ if (cb_arg -> stream == NULL ) {
2126+ if (!(cb_arg -> stream = php_stream_open_wrapper (ZSTR_VAL (cb_arg -> filename ), "rb" , IGNORE_PATH , NULL ))) {
2127+ return CURL_READFUNC_ABORT ;
2128+ }
2129+ }
2130+ numread = php_stream_read (cb_arg -> stream , buffer , nitems * size );
2131+ if (numread < 0 ) {
2132+ php_stream_close (cb_arg -> stream );
2133+ cb_arg -> stream = NULL ;
2134+ }
2135+ return (numread >= 0 ) ? numread : CURL_READFUNC_ABORT ;
2136+ }
2137+ /* }}} */
2138+
2139+ static int seek_cb (void * arg , curl_off_t offset , int origin ) /* {{{ */
2140+ {
2141+ struct mime_data_cb_arg * cb_arg = (struct mime_data_cb_arg * ) arg ;
2142+ int res ;
2143+
2144+ ZEND_ASSERT (!cb_arg -> ch );
2145+
2146+ if (cb_arg -> stream == NULL ) {
2147+ if (!(cb_arg -> stream = php_stream_open_wrapper (ZSTR_VAL (cb_arg -> filename ), "rb" , IGNORE_PATH , NULL ))) {
2148+ return CURL_SEEKFUNC_CANTSEEK ;
2149+ }
2150+ }
2151+ res = php_stream_seek (cb_arg -> stream , offset , origin );
2152+ return !res ? CURL_SEEKFUNC_OK : CURL_SEEKFUNC_CANTSEEK ;
2153+ }
2154+ /* }}} */
2155+
2156+ static void free_cb (void * arg ) /* {{{ */
2157+ {
2158+ struct mime_data_cb_arg * cb_arg = (struct mime_data_cb_arg * ) arg ;
2159+
2160+ ZEND_ASSERT (!cb_arg -> ch );
2161+
2162+ if (cb_arg -> stream != NULL ) {
2163+ php_stream_close (cb_arg -> stream );
2164+ cb_arg -> stream = NULL ;
2165+ }
2166+ }
2167+ /* }}} */
2168+
2169+ static zval * get_postfields_of_handle (php_curl * ch ) /* {{{ */
2170+ {
2171+ struct mime_data_cb_arg * cb_arg , * * cb_arg_p ;
2172+
2173+ cb_arg_p = zend_llist_get_last (& ch -> to_free -> stream );
2174+ while (cb_arg_p ) {
2175+ cb_arg = * cb_arg_p ;
2176+ if (cb_arg -> ch == ch ) {
2177+ return & cb_arg -> postfields ;
2178+ }
2179+ cb_arg_p = zend_llist_get_prev (& ch -> to_free -> stream );
2180+ }
2181+ return NULL ;
2182+ }
2183+ /* }}} */
21212184#endif
21222185
2123- static int build_mime_structure_from_hash (php_curl * ch , zval * zpostfields )
2186+ static int build_mime_structure_from_hash (php_curl * ch , zval * zpostfields ) /* }}} */
21242187{
21252188 CURLcode error = CURLE_OK ;
21262189 zval * current ;
@@ -2284,23 +2347,7 @@ static int build_mime_structure_from_hash(php_curl *ch, zval *zpostfields)
22842347 SAVE_CURL_ERROR (ch , error );
22852348 return error == CURLE_OK ? SUCCESS : FAILURE ;
22862349}
2287-
2288- #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
2289- static HashTable * get_postfields_of_handle (php_curl * ch )
2290- {
2291- struct mime_data_cb_arg * cb_arg , * * cb_arg_p ;
2292-
2293- cb_arg_p = zend_llist_get_last (& ch -> to_free -> stream );
2294- while (cb_arg_p ) {
2295- cb_arg = * cb_arg_p ;
2296- if (cb_arg -> ch == ch ) {
2297- return & cb_arg -> postfields ;
2298- }
2299- cb_arg_p = zend_llist_get_prev (& ch -> to_free -> stream );
2300- }
2301- return NULL ;
2302- }
2303- #endif
2350+ /* }}} */
23042351
23052352/* {{{ proto resource curl_copy_handle(resource ch)
23062353 Copy a cURL handle along with all of it's preferences */
@@ -2348,59 +2395,6 @@ PHP_FUNCTION(curl_copy_handle)
23482395}
23492396/* }}} */
23502397
2351- #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
2352- static size_t read_cb (char * buffer , size_t size , size_t nitems , void * arg ) /* {{{ */
2353- {
2354- struct mime_data_cb_arg * cb_arg = (struct mime_data_cb_arg * ) arg ;
2355- ssize_t numread ;
2356-
2357- ZEND_ASSERT (!cb_arg -> ch );
2358-
2359- if (cb_arg -> stream == NULL ) {
2360- if (!(cb_arg -> stream = php_stream_open_wrapper (ZSTR_VAL (cb_arg -> filename ), "rb" , IGNORE_PATH , NULL ))) {
2361- return CURL_READFUNC_ABORT ;
2362- }
2363- }
2364- numread = php_stream_read (cb_arg -> stream , buffer , nitems * size );
2365- if (numread < 0 ) {
2366- php_stream_close (cb_arg -> stream );
2367- cb_arg -> stream = NULL ;
2368- }
2369- return (numread >= 0 ) ? numread : CURL_READFUNC_ABORT ;
2370- }
2371- /* }}} */
2372-
2373- static int seek_cb (void * arg , curl_off_t offset , int origin ) /* {{{ */
2374- {
2375- struct mime_data_cb_arg * cb_arg = (struct mime_data_cb_arg * ) arg ;
2376- int res ;
2377-
2378- ZEND_ASSERT (!cb_arg -> ch );
2379-
2380- if (cb_arg -> stream == NULL ) {
2381- if (!(cb_arg -> stream = php_stream_open_wrapper (ZSTR_VAL (cb_arg -> filename ), "rb" , IGNORE_PATH , NULL ))) {
2382- return CURL_SEEKFUNC_CANTSEEK ;
2383- }
2384- }
2385- res = php_stream_seek (cb_arg -> stream , offset , origin );
2386- return !res ? CURL_SEEKFUNC_OK : CURL_SEEKFUNC_CANTSEEK ;
2387- }
2388- /* }}} */
2389-
2390- static void free_cb (void * arg ) /* {{{ */
2391- {
2392- struct mime_data_cb_arg * cb_arg = (struct mime_data_cb_arg * ) arg ;
2393-
2394- ZEND_ASSERT (!cb_arg -> ch );
2395-
2396- if (cb_arg -> stream != NULL ) {
2397- php_stream_close (cb_arg -> stream );
2398- cb_arg -> stream = NULL ;
2399- }
2400- }
2401- /* }}} */
2402- #endif
2403-
24042398static int _php_curl_setopt (php_curl * ch , zend_long option , zval * zvalue ) /* {{{ */
24052399{
24062400 CURLcode error = CURLE_OK ;
0 commit comments