mirror of
https://github.com/php/php-src.git
synced 2024-12-03 06:44:07 +08:00
Use curl_mime_*() functions if available
As of curl 7.56.0, `curl_formadd()` is deprecated in favor of
`curl_mime_*()`, so we use the latter if available.
(cherry picked from commit a83b68ba56
)
This commit is contained in:
parent
b5d2cbe027
commit
e1202733a5
@ -1844,7 +1844,11 @@ static void curl_free_string(void **string)
|
||||
*/
|
||||
static void curl_free_post(void **post)
|
||||
{
|
||||
#if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
|
||||
curl_mime_free((curl_mime *)*post);
|
||||
#else
|
||||
curl_formfree((struct HttpPost *)*post);
|
||||
#endif
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@ -2764,16 +2768,28 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
|
||||
HashTable *postfields;
|
||||
zend_string *string_key;
|
||||
zend_ulong num_key;
|
||||
#if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
|
||||
curl_mime *mime;
|
||||
curl_mimepart *part;
|
||||
CURLcode form_error;
|
||||
#else
|
||||
struct HttpPost *first = NULL;
|
||||
struct HttpPost *last = NULL;
|
||||
CURLFORMcode form_error;
|
||||
|
||||
#endif
|
||||
postfields = HASH_OF(zvalue);
|
||||
if (!postfields) {
|
||||
php_error_docref(NULL, E_WARNING, "Couldn't get HashTable in CURLOPT_POSTFIELDS");
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
#if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
|
||||
mime = curl_mime_init(ch->cp);
|
||||
if (mime == NULL) {
|
||||
return FAILURE;
|
||||
}
|
||||
#endif
|
||||
|
||||
ZEND_HASH_FOREACH_KEY_VAL(postfields, num_key, string_key, current) {
|
||||
zend_string *postval, *tmp_postval;
|
||||
/* Pretend we have a string_key here */
|
||||
@ -2808,6 +2824,20 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
|
||||
if (Z_TYPE_P(prop) == IS_STRING && Z_STRLEN_P(prop) > 0) {
|
||||
filename = Z_STRVAL_P(prop);
|
||||
}
|
||||
|
||||
#if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
|
||||
part = curl_mime_addpart(mime);
|
||||
if (part == NULL) {
|
||||
zend_string_release_ex(string_key, 0);
|
||||
return FAILURE;
|
||||
}
|
||||
if ((form_error = curl_mime_name(part, ZSTR_VAL(string_key))) != CURLE_OK
|
||||
|| (form_error = curl_mime_filedata(part, ZSTR_VAL(postval))) != CURLE_OK
|
||||
|| (form_error = curl_mime_filename(part, filename ? filename : ZSTR_VAL(postval))) != CURLE_OK
|
||||
|| (form_error = curl_mime_type(part, type ? type : "application/octet-stream")) != CURLE_OK) {
|
||||
error = form_error;
|
||||
}
|
||||
#else
|
||||
form_error = curl_formadd(&first, &last,
|
||||
CURLFORM_COPYNAME, ZSTR_VAL(string_key),
|
||||
CURLFORM_NAMELENGTH, ZSTR_LEN(string_key),
|
||||
@ -2819,6 +2849,7 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
|
||||
/* Not nice to convert between enums but we only have place for one error type */
|
||||
error = (CURLcode)form_error;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
zend_string_release_ex(string_key, 0);
|
||||
@ -2827,6 +2858,18 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
|
||||
|
||||
postval = zval_get_tmp_string(current, &tmp_postval);
|
||||
|
||||
#if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
|
||||
part = curl_mime_addpart(mime);
|
||||
if (part == NULL) {
|
||||
zend_tmp_string_release(tmp_postval);
|
||||
zend_string_release_ex(string_key, 0);
|
||||
return FAILURE;
|
||||
}
|
||||
if ((form_error = curl_mime_name(part, ZSTR_VAL(string_key))) != CURLE_OK
|
||||
|| (form_error = curl_mime_data(part, ZSTR_VAL(postval), ZSTR_LEN(postval))) != CURLE_OK) {
|
||||
error = form_error;
|
||||
}
|
||||
#else
|
||||
/* The arguments after _NAMELENGTH and _CONTENTSLENGTH
|
||||
* must be explicitly cast to long in curl_formadd
|
||||
* 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) /* {{{
|
||||
/* Not nice to convert between enums but we only have place for one error type */
|
||||
error = (CURLcode)form_error;
|
||||
}
|
||||
#endif
|
||||
zend_tmp_string_release(tmp_postval);
|
||||
zend_string_release_ex(string_key, 0);
|
||||
} ZEND_HASH_FOREACH_END();
|
||||
@ -2853,8 +2897,13 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
|
||||
if ((*ch->clone) == 1) {
|
||||
zend_llist_clean(&ch->to_free->post);
|
||||
}
|
||||
#if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
|
||||
zend_llist_add_element(&ch->to_free->post, &mime);
|
||||
error = curl_easy_setopt(ch->cp, CURLOPT_MIMEPOST, mime);
|
||||
#else
|
||||
zend_llist_add_element(&ch->to_free->post, &first);
|
||||
error = curl_easy_setopt(ch->cp, CURLOPT_HTTPPOST, first);
|
||||
#endif
|
||||
} else {
|
||||
#if LIBCURL_VERSION_NUM >= 0x071101
|
||||
zend_string *tmp_str;
|
||||
|
Loading…
Reference in New Issue
Block a user