[PECL-CVS] [pecl-web_services-oauth] fix-curl-mime-deprecation: Fixes #37
[email protected] (Rasmus Lerdorf) Sat, 4 Apr 2026 21:49:13 +0000
| Newsgroups | php.pecl.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: Rasmus Lerdorf (rlerdorf)
Date: 2026-04-04T17:49:00-04:00
Commit: https://github.com/php/pecl-web_services-oauth/commit/da12553709e05dd58413dcad150fb7b60689dc00
Raw diff: https://github.com/php/pecl-web_services-oauth/commit/da12553709e05dd58413dcad150fb7b60689dc00.diff
Fixes #37
Changed paths:
M oauth.c
Diff:
diff --git a/oauth.c b/oauth.c
index a424097..e77ae17 100644
--- a/oauth.c
+++ b/oauth.c
@@ -1061,6 +1061,9 @@ long make_req_curl(php_so_object *soo, const char *url, const smart_string *payl
CURLcode cres, ctres, crres;
CURL *curl;
struct curl_slist *curl_headers = NULL;
+#if LIBCURL_VERSION_NUM >= 0x073800
+ curl_mime *mime = NULL;
+#endif
long l_code, response_code = -1;
double d_code;
zval info, *zca_info, *zca_path, *cur_val;
@@ -1106,12 +1109,13 @@ long make_req_curl(php_so_object *soo, const char *url, const smart_string *payl
}
if(soo->is_multipart) {
- struct curl_httppost *ff = NULL;
- struct curl_httppost *lf = NULL;
+#if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
+ mime = curl_mime_init(curl);
int i;
for(i=0; i < soo->multipart_files_num; i++) {
char *type, *filename, *postval;
+ curl_mimepart *part;
/* swiped from ext/curl/interface.c to help with consistency */
postval = estrdup(soo->multipart_files[i]);
@@ -1129,6 +1133,49 @@ long make_req_curl(php_so_object *soo, const char *url, const smart_string *payl
}
/* open_basedir check */
+ if(php_check_open_basedir(postval)) {
+ char *em;
+ spprintf(&em, 0, "failed to open file for multipart request: %s", postval);
+ soo_handle_error(soo, -1, em, NULL, NULL);
+ efree(em);
+ curl_mime_free(mime);
+ return 1;
+ }
+
+ part = curl_mime_addpart(mime);
+ curl_mime_name(part, soo->multipart_params[i]);
+ curl_mime_filedata(part, postval);
+ curl_mime_filename(part, filename ? filename + sizeof(";filename=") - 1 : soo->multipart_files[i]);
+ curl_mime_type(part, type ? type + sizeof(";type=") - 1 : "application/octet-stream");
+ } else {
+ part = curl_mime_addpart(mime);
+ curl_mime_name(part, soo->multipart_params[i]);
+ curl_mime_data(part, postval, CURL_ZERO_TERMINATED);
+ }
+ }
+
+ curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
+#else
+ struct curl_httppost *ff = NULL;
+ struct curl_httppost *lf = NULL;
+ int i;
+
+ for(i=0; i < soo->multipart_files_num; i++) {
+ char *type, *filename, *postval;
+
+ postval = estrdup(soo->multipart_files[i]);
+
+ if (postval[0] == '@' && soo->multipart_params[i][0] == '@') {
+ ++soo->multipart_params[i];
+ ++postval;
+
+ if((type = (char *) php_memnstr(postval, ";type=", sizeof(";type=") - 1, postval + strlen(soo->multipart_files[i]) - 1))) {
+ *type = '\0';
+ }
+ if((filename = (char *) php_memnstr(postval, ";filename=", sizeof(";filename=") - 1, postval + strlen(soo->multipart_files[i]) - 1))) {
+ *filename = '\0';
+ }
+
if(php_check_open_basedir(postval)) {
char *em;
spprintf(&em, 0, "failed to open file for multipart request: %s", postval);
@@ -1155,6 +1202,7 @@ long make_req_curl(php_so_object *soo, const char *url, const smart_string *payl
}
curl_easy_setopt(curl, CURLOPT_HTTPPOST, ff);
+#endif
} else if (payload->len) {
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, payload->c);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, payload->len);
@@ -1307,6 +1355,11 @@ long make_req_curl(php_so_object *soo, const char *url, const smart_string *payl
soo_handle_error(soo, -1, bufz, soo->lastresponse.c, NULL);
efree(bufz);
}
+#if LIBCURL_VERSION_NUM >= 0x073800
+ if (mime) {
+ curl_mime_free(mime);
+ }
+#endif
curl_easy_cleanup(curl);
return response_code;
}