@@ -1654,6 +1654,15 @@ static void curl_free_cb_arg(void **cb_arg_p)
16541654}
16551655/* }}} */
16561656
1657+ #if LIBCURL_VERSION_NUM < 0x073800 /* 7.56.0 */
1658+ /* {{{ curl_free_buffers */
1659+ static void curl_free_buffers (void * * buffer )
1660+ {
1661+ zend_string_release ((zend_string * ) * buffer );
1662+ }
1663+ /* }}} */
1664+ #endif
1665+
16571666/* {{{ curl_free_slist */
16581667static void curl_free_slist (zval * el )
16591668{
@@ -1744,6 +1753,10 @@ void init_curl_handle(php_curl *ch)
17441753 zend_llist_init (& ch -> to_free -> post , sizeof (struct HttpPost * ), (llist_dtor_func_t )curl_free_post , 0 );
17451754 zend_llist_init (& ch -> to_free -> stream , sizeof (struct mime_data_cb_arg * ), (llist_dtor_func_t )curl_free_cb_arg , 0 );
17461755
1756+ #if LIBCURL_VERSION_NUM < 0x073800 /* 7.56.0 */
1757+ zend_llist_init (& ch -> to_free -> buffers , sizeof (zend_string * ), (llist_dtor_func_t )curl_free_buffers , 0 );
1758+ #endif
1759+
17471760 ch -> to_free -> slist = emalloc (sizeof (HashTable ));
17481761 zend_hash_init (ch -> to_free -> slist , 4 , NULL , curl_free_slist , 0 );
17491762 ZVAL_UNDEF (& ch -> postfields );
@@ -2086,6 +2099,78 @@ static inline int build_mime_structure_from_hash(php_curl *ch, zval *zpostfields
20862099 continue ;
20872100 }
20882101
2102+ if (Z_TYPE_P (current ) == IS_OBJECT && instanceof_function (Z_OBJCE_P (current ), curl_CURLStringFile_class )) {
2103+ /* new-style file upload from string */
2104+ zval * prop , rv ;
2105+ char * type = NULL , * filename = NULL ;
2106+
2107+ prop = zend_read_property (curl_CURLStringFile_class , Z_OBJ_P (current ), "postname" , sizeof ("postname" )- 1 , 0 , & rv );
2108+ if (EG (exception )) {
2109+ zend_string_release_ex (string_key , 0 );
2110+ return FAILURE ;
2111+ }
2112+ ZVAL_DEREF (prop );
2113+ ZEND_ASSERT (Z_TYPE_P (prop ) == IS_STRING );
2114+
2115+ filename = Z_STRVAL_P (prop );
2116+
2117+ prop = zend_read_property (curl_CURLStringFile_class , Z_OBJ_P (current ), "mime" , sizeof ("mime" )- 1 , 0 , & rv );
2118+ if (EG (exception )) {
2119+ zend_string_release_ex (string_key , 0 );
2120+ return FAILURE ;
2121+ }
2122+ ZVAL_DEREF (prop );
2123+ ZEND_ASSERT (Z_TYPE_P (prop ) == IS_STRING );
2124+
2125+ type = Z_STRVAL_P (prop );
2126+
2127+ prop = zend_read_property (curl_CURLStringFile_class , Z_OBJ_P (current ), "data" , sizeof ("data" )- 1 , 0 , & rv );
2128+ if (EG (exception )) {
2129+ zend_string_release_ex (string_key , 0 );
2130+ return FAILURE ;
2131+ }
2132+ ZVAL_DEREF (prop );
2133+ ZEND_ASSERT (Z_TYPE_P (prop ) == IS_STRING );
2134+
2135+ postval = Z_STR_P (prop );
2136+
2137+ #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
2138+ zval_ptr_dtor (& ch -> postfields );
2139+ ZVAL_COPY (& ch -> postfields , zpostfields );
2140+
2141+ part = curl_mime_addpart (mime );
2142+ if (part == NULL ) {
2143+ zend_string_release_ex (string_key , 0 );
2144+ return FAILURE ;
2145+ }
2146+ if ((form_error = curl_mime_name (part , ZSTR_VAL (string_key ))) != CURLE_OK
2147+ || (form_error = curl_mime_data (part , ZSTR_VAL (postval ), ZSTR_LEN (postval ))) != CURLE_OK
2148+ || (form_error = curl_mime_filename (part , filename )) != CURLE_OK
2149+ || (form_error = curl_mime_type (part , type )) != CURLE_OK ) {
2150+ error = form_error ;
2151+ }
2152+ #else
2153+ postval = zend_string_copy (postval );
2154+ zend_llist_add_element (& ch -> to_free -> buffers , & postval );
2155+
2156+ form_error = curl_formadd (& first , & last ,
2157+ CURLFORM_COPYNAME , ZSTR_VAL (string_key ),
2158+ CURLFORM_NAMELENGTH , ZSTR_LEN (string_key ),
2159+ CURLFORM_BUFFER , filename ,
2160+ CURLFORM_CONTENTTYPE , type ,
2161+ CURLFORM_BUFFERPTR , ZSTR_VAL (postval ),
2162+ CURLFORM_BUFFERLENGTH , ZSTR_LEN (postval ),
2163+ CURLFORM_END );
2164+ if (form_error != CURL_FORMADD_OK ) {
2165+ /* Not nice to convert between enums but we only have place for one error type */
2166+ error = (CURLcode )form_error ;
2167+ }
2168+ #endif
2169+
2170+ zend_string_release_ex (string_key , 0 );
2171+ continue ;
2172+ }
2173+
20892174 postval = zval_get_tmp_string (current , & tmp_postval );
20902175
20912176#if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
@@ -3330,6 +3415,11 @@ static void curl_free_obj(zend_object *object)
33303415 if (-- (* ch -> clone ) == 0 ) {
33313416 zend_llist_clean (& ch -> to_free -> post );
33323417 zend_llist_clean (& ch -> to_free -> stream );
3418+
3419+ #if LIBCURL_VERSION_NUM < 0x073800 /* 7.56.0 */
3420+ zend_llist_clean (& ch -> to_free -> buffers );
3421+ #endif
3422+
33333423 zend_hash_destroy (ch -> to_free -> slist );
33343424 efree (ch -> to_free -> slist );
33353425 efree (ch -> to_free );
0 commit comments