@@ -1654,6 +1654,15 @@ static void curl_free_cb_arg(void **cb_arg_p)
1654
1654
}
1655
1655
/* }}} */
1656
1656
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
+
1657
1666
/* {{{ curl_free_slist */
1658
1667
static void curl_free_slist (zval * el )
1659
1668
{
@@ -1744,6 +1753,10 @@ void init_curl_handle(php_curl *ch)
1744
1753
zend_llist_init (& ch -> to_free -> post , sizeof (struct HttpPost * ), (llist_dtor_func_t )curl_free_post , 0 );
1745
1754
zend_llist_init (& ch -> to_free -> stream , sizeof (struct mime_data_cb_arg * ), (llist_dtor_func_t )curl_free_cb_arg , 0 );
1746
1755
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
+
1747
1760
ch -> to_free -> slist = emalloc (sizeof (HashTable ));
1748
1761
zend_hash_init (ch -> to_free -> slist , 4 , NULL , curl_free_slist , 0 );
1749
1762
ZVAL_UNDEF (& ch -> postfields );
@@ -2086,6 +2099,78 @@ static inline int build_mime_structure_from_hash(php_curl *ch, zval *zpostfields
2086
2099
continue ;
2087
2100
}
2088
2101
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
+
2089
2174
postval = zval_get_tmp_string (current , & tmp_postval );
2090
2175
2091
2176
#if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
@@ -3330,6 +3415,11 @@ static void curl_free_obj(zend_object *object)
3330
3415
if (-- (* ch -> clone ) == 0 ) {
3331
3416
zend_llist_clean (& ch -> to_free -> post );
3332
3417
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
+
3333
3423
zend_hash_destroy (ch -> to_free -> slist );
3334
3424
efree (ch -> to_free -> slist );
3335
3425
efree (ch -> to_free );
0 commit comments