@@ -1852,6 +1852,14 @@ static void curl_free_post(void **post)
1852
1852
}
1853
1853
/* }}} */
1854
1854
1855
+ /* {{{ curl_free_stream
1856
+ */
1857
+ static void curl_free_stream (void * * post )
1858
+ {
1859
+ php_stream_close ((php_stream * )* post );
1860
+ }
1861
+ /* }}} */
1862
+
1855
1863
/* {{{ curl_free_slist
1856
1864
*/
1857
1865
static void curl_free_slist (zval * el )
@@ -1943,6 +1951,7 @@ php_curl *alloc_curl_handle()
1943
1951
1944
1952
zend_llist_init (& ch -> to_free -> str , sizeof (char * ), (llist_dtor_func_t )curl_free_string , 0 );
1945
1953
zend_llist_init (& ch -> to_free -> post , sizeof (struct HttpPost * ), (llist_dtor_func_t )curl_free_post , 0 );
1954
+ zend_llist_init (& ch -> to_free -> stream , sizeof (php_stream * ), (llist_dtor_func_t )curl_free_stream , 0 );
1946
1955
1947
1956
ch -> to_free -> slist = emalloc (sizeof (HashTable ));
1948
1957
zend_hash_init (ch -> to_free -> slist , 4 , NULL , curl_free_slist , 0 );
@@ -2170,6 +2179,32 @@ PHP_FUNCTION(curl_copy_handle)
2170
2179
}
2171
2180
/* }}} */
2172
2181
2182
+ #if LIBCURL_VERSION_NUM >= 0x073800
2183
+ static size_t read_cb (char * buffer , size_t size , size_t nitems , void * arg ) /* {{{ */
2184
+ {
2185
+ php_stream * stream = (php_stream * ) arg ;
2186
+ size_t numread = php_stream_read (stream , buffer , nitems * size );
2187
+
2188
+ if (numread == (size_t )-1 ) {
2189
+ return CURL_READFUNC_ABORT ;
2190
+ }
2191
+ return numread ;
2192
+ }
2193
+ /* }}} */
2194
+
2195
+ static int seek_cb (void * arg , curl_off_t offset , int origin ) /* {{{ */
2196
+ {
2197
+ php_stream * stream = (php_stream * ) arg ;
2198
+ int res = php_stream_seek (stream , offset , origin );
2199
+
2200
+ if (res ) {
2201
+ return CURL_SEEKFUNC_CANTSEEK ;
2202
+ }
2203
+ return CURL_SEEKFUNC_OK ;
2204
+ }
2205
+ /* }}} */
2206
+ #endif
2207
+
2173
2208
static int _php_curl_setopt (php_curl * ch , zend_long option , zval * zvalue ) /* {{{ */
2174
2209
{
2175
2210
CURLcode error = CURLE_OK ;
@@ -2805,6 +2840,9 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
2805
2840
/* new-style file upload */
2806
2841
zval * prop , rv ;
2807
2842
char * type = NULL , * filename = NULL ;
2843
+ #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
2844
+ php_stream * stream ;
2845
+ #endif
2808
2846
2809
2847
prop = zend_read_property (curl_CURLFile_class , current , "name" , sizeof ("name" )- 1 , 0 , & rv );
2810
2848
if (Z_TYPE_P (prop ) != IS_STRING ) {
@@ -2826,17 +2864,24 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
2826
2864
}
2827
2865
2828
2866
#if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
2867
+ if (!(stream = php_stream_open_wrapper (ZSTR_VAL (postval ), "rb" , IGNORE_PATH , NULL ))) {
2868
+ zend_string_release_ex (string_key , 0 );
2869
+ return FAILURE ;
2870
+ }
2829
2871
part = curl_mime_addpart (mime );
2830
2872
if (part == NULL ) {
2873
+ php_stream_close (stream );
2831
2874
zend_string_release_ex (string_key , 0 );
2832
2875
return FAILURE ;
2833
2876
}
2834
2877
if ((form_error = curl_mime_name (part , ZSTR_VAL (string_key ))) != CURLE_OK
2835
- || (form_error = curl_mime_filedata (part , ZSTR_VAL ( postval ) )) != CURLE_OK
2878
+ || (form_error = curl_mime_data_cb (part , -1 , read_cb , seek_cb , NULL , stream )) != CURLE_OK
2836
2879
|| (form_error = curl_mime_filename (part , filename ? filename : ZSTR_VAL (postval ))) != CURLE_OK
2837
2880
|| (form_error = curl_mime_type (part , type ? type : "application/octet-stream" )) != CURLE_OK ) {
2881
+ php_stream_close (stream );
2838
2882
error = form_error ;
2839
2883
}
2884
+ zend_llist_add_element (& ch -> to_free -> stream , & stream );
2840
2885
#else
2841
2886
form_error = curl_formadd (& first , & last ,
2842
2887
CURLFORM_COPYNAME , ZSTR_VAL (string_key ),
@@ -3566,6 +3611,7 @@ static void _php_curl_close_ex(php_curl *ch)
3566
3611
if (-- (* ch -> clone ) == 0 ) {
3567
3612
zend_llist_clean (& ch -> to_free -> str );
3568
3613
zend_llist_clean (& ch -> to_free -> post );
3614
+ zend_llist_clean (& ch -> to_free -> stream );
3569
3615
zend_hash_destroy (ch -> to_free -> slist );
3570
3616
efree (ch -> to_free -> slist );
3571
3617
efree (ch -> to_free );
0 commit comments