@@ -1795,7 +1795,11 @@ static void curl_free_string(void **string)
1795
1795
*/
1796
1796
static void curl_free_post (void * * post )
1797
1797
{
1798
+ #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
1799
+ curl_mime_free ((curl_mime * )* post );
1800
+ #else
1798
1801
curl_formfree ((struct HttpPost * )* post );
1802
+ #endif
1799
1803
}
1800
1804
/* }}} */
1801
1805
@@ -2715,16 +2719,28 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
2715
2719
HashTable * postfields ;
2716
2720
zend_string * string_key ;
2717
2721
zend_ulong num_key ;
2722
+ #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
2723
+ curl_mime * mime ;
2724
+ curl_mimepart * part ;
2725
+ CURLcode form_error ;
2726
+ #else
2718
2727
struct HttpPost * first = NULL ;
2719
2728
struct HttpPost * last = NULL ;
2720
2729
CURLFORMcode form_error ;
2721
-
2730
+ #endif
2722
2731
postfields = HASH_OF (zvalue );
2723
2732
if (!postfields ) {
2724
2733
php_error_docref (NULL , E_WARNING , "Couldn't get HashTable in CURLOPT_POSTFIELDS" );
2725
2734
return FAILURE ;
2726
2735
}
2727
2736
2737
+ #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
2738
+ mime = curl_mime_init (ch -> cp );
2739
+ if (mime == NULL ) {
2740
+ return FAILURE ;
2741
+ }
2742
+ #endif
2743
+
2728
2744
ZEND_HASH_FOREACH_KEY_VAL (postfields , num_key , string_key , current ) {
2729
2745
zend_string * postval , * tmp_postval ;
2730
2746
/* Pretend we have a string_key here */
@@ -2759,6 +2775,20 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
2759
2775
if (Z_TYPE_P (prop ) == IS_STRING && Z_STRLEN_P (prop ) > 0 ) {
2760
2776
filename = Z_STRVAL_P (prop );
2761
2777
}
2778
+
2779
+ #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
2780
+ part = curl_mime_addpart (mime );
2781
+ if (part == NULL ) {
2782
+ zend_string_release_ex (string_key , 0 );
2783
+ return FAILURE ;
2784
+ }
2785
+ if ((form_error = curl_mime_name (part , ZSTR_VAL (string_key ))) != CURLE_OK
2786
+ || (form_error = curl_mime_filedata (part , ZSTR_VAL (postval ))) != CURLE_OK
2787
+ || (form_error = curl_mime_filename (part , filename ? filename : ZSTR_VAL (postval ))) != CURLE_OK
2788
+ || (form_error = curl_mime_type (part , type ? type : "application/octet-stream" )) != CURLE_OK ) {
2789
+ error = form_error ;
2790
+ }
2791
+ #else
2762
2792
form_error = curl_formadd (& first , & last ,
2763
2793
CURLFORM_COPYNAME , ZSTR_VAL (string_key ),
2764
2794
CURLFORM_NAMELENGTH , ZSTR_LEN (string_key ),
@@ -2770,6 +2800,7 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
2770
2800
/* Not nice to convert between enums but we only have place for one error type */
2771
2801
error = (CURLcode )form_error ;
2772
2802
}
2803
+ #endif
2773
2804
}
2774
2805
2775
2806
zend_string_release_ex (string_key , 0 );
@@ -2778,6 +2809,18 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
2778
2809
2779
2810
postval = zval_get_tmp_string (current , & tmp_postval );
2780
2811
2812
+ #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
2813
+ part = curl_mime_addpart (mime );
2814
+ if (part == NULL ) {
2815
+ zend_tmp_string_release (tmp_postval );
2816
+ zend_string_release_ex (string_key , 0 );
2817
+ return FAILURE ;
2818
+ }
2819
+ if ((form_error = curl_mime_name (part , ZSTR_VAL (string_key ))) != CURLE_OK
2820
+ || (form_error = curl_mime_data (part , ZSTR_VAL (postval ), ZSTR_LEN (postval ))) != CURLE_OK ) {
2821
+ error = form_error ;
2822
+ }
2823
+ #else
2781
2824
/* The arguments after _NAMELENGTH and _CONTENTSLENGTH
2782
2825
* must be explicitly cast to long in curl_formadd
2783
2826
* use since curl needs a long not an int. */
@@ -2792,6 +2835,7 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
2792
2835
/* Not nice to convert between enums but we only have place for one error type */
2793
2836
error = (CURLcode )form_error ;
2794
2837
}
2838
+ #endif
2795
2839
zend_tmp_string_release (tmp_postval );
2796
2840
zend_string_release_ex (string_key , 0 );
2797
2841
} ZEND_HASH_FOREACH_END ();
@@ -2804,8 +2848,13 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
2804
2848
if ((* ch -> clone ) == 1 ) {
2805
2849
zend_llist_clean (& ch -> to_free -> post );
2806
2850
}
2851
+ #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
2852
+ zend_llist_add_element (& ch -> to_free -> post , & mime );
2853
+ error = curl_easy_setopt (ch -> cp , CURLOPT_MIMEPOST , mime );
2854
+ #else
2807
2855
zend_llist_add_element (& ch -> to_free -> post , & first );
2808
2856
error = curl_easy_setopt (ch -> cp , CURLOPT_HTTPPOST , first );
2857
+ #endif
2809
2858
} else {
2810
2859
#if LIBCURL_VERSION_NUM >= 0x071101
2811
2860
zend_string * tmp_str ;
0 commit comments