@@ -1844,7 +1844,11 @@ static void curl_free_string(void **string)
1844
1844
*/
1845
1845
static void curl_free_post (void * * post )
1846
1846
{
1847
+ #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
1848
+ curl_mime_free ((curl_mime * )* post );
1849
+ #else
1847
1850
curl_formfree ((struct HttpPost * )* post );
1851
+ #endif
1848
1852
}
1849
1853
/* }}} */
1850
1854
@@ -2764,16 +2768,28 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
2764
2768
HashTable * postfields ;
2765
2769
zend_string * string_key ;
2766
2770
zend_ulong num_key ;
2771
+ #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
2772
+ curl_mime * mime ;
2773
+ curl_mimepart * part ;
2774
+ CURLcode form_error ;
2775
+ #else
2767
2776
struct HttpPost * first = NULL ;
2768
2777
struct HttpPost * last = NULL ;
2769
2778
CURLFORMcode form_error ;
2770
-
2779
+ #endif
2771
2780
postfields = HASH_OF (zvalue );
2772
2781
if (!postfields ) {
2773
2782
php_error_docref (NULL , E_WARNING , "Couldn't get HashTable in CURLOPT_POSTFIELDS" );
2774
2783
return FAILURE ;
2775
2784
}
2776
2785
2786
+ #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
2787
+ mime = curl_mime_init (ch -> cp );
2788
+ if (mime == NULL ) {
2789
+ return FAILURE ;
2790
+ }
2791
+ #endif
2792
+
2777
2793
ZEND_HASH_FOREACH_KEY_VAL (postfields , num_key , string_key , current ) {
2778
2794
zend_string * postval , * tmp_postval ;
2779
2795
/* Pretend we have a string_key here */
@@ -2808,6 +2824,20 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
2808
2824
if (Z_TYPE_P (prop ) == IS_STRING && Z_STRLEN_P (prop ) > 0 ) {
2809
2825
filename = Z_STRVAL_P (prop );
2810
2826
}
2827
+
2828
+ #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
2829
+ part = curl_mime_addpart (mime );
2830
+ if (part == NULL ) {
2831
+ zend_string_release_ex (string_key , 0 );
2832
+ return FAILURE ;
2833
+ }
2834
+ 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
2836
+ || (form_error = curl_mime_filename (part , filename ? filename : ZSTR_VAL (postval ))) != CURLE_OK
2837
+ || (form_error = curl_mime_type (part , type ? type : "application/octet-stream" )) != CURLE_OK ) {
2838
+ error = form_error ;
2839
+ }
2840
+ #else
2811
2841
form_error = curl_formadd (& first , & last ,
2812
2842
CURLFORM_COPYNAME , ZSTR_VAL (string_key ),
2813
2843
CURLFORM_NAMELENGTH , ZSTR_LEN (string_key ),
@@ -2819,6 +2849,7 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
2819
2849
/* Not nice to convert between enums but we only have place for one error type */
2820
2850
error = (CURLcode )form_error ;
2821
2851
}
2852
+ #endif
2822
2853
}
2823
2854
2824
2855
zend_string_release_ex (string_key , 0 );
@@ -2827,6 +2858,18 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
2827
2858
2828
2859
postval = zval_get_tmp_string (current , & tmp_postval );
2829
2860
2861
+ #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
2862
+ part = curl_mime_addpart (mime );
2863
+ if (part == NULL ) {
2864
+ zend_tmp_string_release (tmp_postval );
2865
+ zend_string_release_ex (string_key , 0 );
2866
+ return FAILURE ;
2867
+ }
2868
+ if ((form_error = curl_mime_name (part , ZSTR_VAL (string_key ))) != CURLE_OK
2869
+ || (form_error = curl_mime_data (part , ZSTR_VAL (postval ), ZSTR_LEN (postval ))) != CURLE_OK ) {
2870
+ error = form_error ;
2871
+ }
2872
+ #else
2830
2873
/* The arguments after _NAMELENGTH and _CONTENTSLENGTH
2831
2874
* must be explicitly cast to long in curl_formadd
2832
2875
* use since curl needs a long not an int. */
@@ -2841,6 +2884,7 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
2841
2884
/* Not nice to convert between enums but we only have place for one error type */
2842
2885
error = (CURLcode )form_error ;
2843
2886
}
2887
+ #endif
2844
2888
zend_tmp_string_release (tmp_postval );
2845
2889
zend_string_release_ex (string_key , 0 );
2846
2890
} ZEND_HASH_FOREACH_END ();
@@ -2853,8 +2897,13 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
2853
2897
if ((* ch -> clone ) == 1 ) {
2854
2898
zend_llist_clean (& ch -> to_free -> post );
2855
2899
}
2900
+ #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
2901
+ zend_llist_add_element (& ch -> to_free -> post , & mime );
2902
+ error = curl_easy_setopt (ch -> cp , CURLOPT_MIMEPOST , mime );
2903
+ #else
2856
2904
zend_llist_add_element (& ch -> to_free -> post , & first );
2857
2905
error = curl_easy_setopt (ch -> cp , CURLOPT_HTTPPOST , first );
2906
+ #endif
2858
2907
} else {
2859
2908
#if LIBCURL_VERSION_NUM >= 0x071101
2860
2909
zend_string * tmp_str ;
0 commit comments