From d87571766ee4f056d92f6347128c3caf98c57aec Mon Sep 17 00:00:00 2001 From: Le Philousophe Date: Thu, 21 Sep 2023 20:32:33 +0200 Subject: [PATCH] BACKENDS: NETWORKING: Use Path for cURL requests --- backends/networking/curl/curlrequest.cpp | 2 +- backends/networking/curl/curlrequest.h | 5 +++-- backends/networking/curl/networkreadstream.cpp | 10 +++++----- backends/networking/curl/networkreadstream.h | 7 ++++--- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/backends/networking/curl/curlrequest.cpp b/backends/networking/curl/curlrequest.cpp index b9f42ab0e07..7c847aee827 100644 --- a/backends/networking/curl/curlrequest.cpp +++ b/backends/networking/curl/curlrequest.cpp @@ -112,7 +112,7 @@ void CurlRequest::addFormField(const Common::String &name, const Common::String _formFields[name] = value; } -void CurlRequest::addFormFile(const Common::String &name, const Common::String &filename) { +void CurlRequest::addFormFile(const Common::String &name, const Common::Path &filename) { if (_bytesBuffer) warning("CurlRequest: added POST form files would be ignored, because there is buffer present"); diff --git a/backends/networking/curl/curlrequest.h b/backends/networking/curl/curlrequest.h index aed00332616..577871d9400 100644 --- a/backends/networking/curl/curlrequest.h +++ b/backends/networking/curl/curlrequest.h @@ -23,6 +23,7 @@ #define BACKENDS_NETWORKING_CURL_CURLREQUEST_H #include "backends/networking/curl/request.h" +#include "common/path.h" #include "common/str.h" #include "common/array.h" #include "common/hashmap.h" @@ -44,7 +45,7 @@ protected: curl_slist *_headersList; Common::String _postFields; Common::HashMap _formFields; - Common::HashMap _formFiles; + Common::HashMap _formFiles; byte *_bytesBuffer; uint32 _bytesBufferSize; bool _uploading; //using PUT method @@ -75,7 +76,7 @@ public: virtual void addFormField(const Common::String &name, const Common::String &value); /** Adds a form/multipart file (field name, file name). */ - virtual void addFormFile(const Common::String &name, const Common::String &filename); + virtual void addFormFile(const Common::String &name, const Common::Path &filename); /** Sets bytes buffer. */ virtual void setBuffer(byte *buffer, uint32 size); diff --git a/backends/networking/curl/networkreadstream.cpp b/backends/networking/curl/networkreadstream.cpp index 0f7ed8e33ba..1315d4addb6 100644 --- a/backends/networking/curl/networkreadstream.cpp +++ b/backends/networking/curl/networkreadstream.cpp @@ -158,7 +158,7 @@ void NetworkReadStream::setupBufferContents(const byte *buffer, uint32 bufferSiz ConnMan.registerEasyHandle(_easy); } -void NetworkReadStream::setupFormMultipart(const Common::HashMap &formFields, const Common::HashMap &formFiles) { +void NetworkReadStream::setupFormMultipart(const Common::HashMap &formFields, const Common::HashMap &formFiles) { // set POST multipart upload form fields/files struct curl_httppost *formpost = nullptr; struct curl_httppost *lastptr = nullptr; @@ -176,12 +176,12 @@ void NetworkReadStream::setupFormMultipart(const Common::HashMap_key.c_str()); } - for (Common::HashMap::iterator i = formFiles.begin(); i != formFiles.end(); ++i) { + for (Common::HashMap::iterator i = formFiles.begin(); i != formFiles.end(); ++i) { CURLFORMcode code = curl_formadd( &formpost, &lastptr, CURLFORM_COPYNAME, i->_key.c_str(), - CURLFORM_FILE, i->_value.c_str(), + CURLFORM_FILE, i->_value.toString(Common::Path::kNativeSeparator).c_str(), CURLFORM_END ); @@ -199,7 +199,7 @@ NetworkReadStream::NetworkReadStream(const char *url, curl_slist *headersList, c setupBufferContents((const byte *)postFields.c_str(), postFields.size(), uploading, usingPatch, false); } -NetworkReadStream::NetworkReadStream(const char *url, curl_slist *headersList, const Common::HashMap &formFields, const Common::HashMap &formFiles, bool keepAlive, long keepAliveIdle, long keepAliveInterval): +NetworkReadStream::NetworkReadStream(const char *url, curl_slist *headersList, const Common::HashMap &formFields, const Common::HashMap &formFiles, bool keepAlive, long keepAliveIdle, long keepAliveInterval): _backingStream(DisposeAfterUse::YES), _keepAlive(keepAlive), _keepAliveIdle(keepAliveIdle), _keepAliveInterval(keepAliveInterval), _errorBuffer(nullptr), _errorCode(CURLE_OK) { initCurl(url, headersList); setupFormMultipart(formFields, formFiles); @@ -220,7 +220,7 @@ bool NetworkReadStream::reuse(const char *url, curl_slist *headersList, const Co return true; } -bool NetworkReadStream::reuse(const char *url, curl_slist *headersList, const Common::HashMap &formFields, const Common::HashMap &formFiles) { +bool NetworkReadStream::reuse(const char *url, curl_slist *headersList, const Common::HashMap &formFields, const Common::HashMap &formFiles) { if (!reuseCurl(url, headersList)) return false; diff --git a/backends/networking/curl/networkreadstream.h b/backends/networking/curl/networkreadstream.h index 2625a13fcbf..3e1d9fb39e5 100644 --- a/backends/networking/curl/networkreadstream.h +++ b/backends/networking/curl/networkreadstream.h @@ -23,6 +23,7 @@ #define BACKENDS_NETWORKING_CURL_NETWORKREADSTREAM_H #include "common/memstream.h" +#include "common/path.h" #include "common/stream.h" #include "common/str.h" #include "common/hashmap.h" @@ -52,7 +53,7 @@ class NetworkReadStream : public Common::ReadStream { void initCurl(const char *url, curl_slist *headersList); bool reuseCurl(const char *url, curl_slist *headersList); void setupBufferContents(const byte *buffer, uint32 bufferSize, bool uploading, bool usingPatch, bool post); - void setupFormMultipart(const Common::HashMap &formFields, const Common::HashMap &formFiles); + void setupFormMultipart(const Common::HashMap &formFields, const Common::HashMap &formFiles); /** * Fills the passed buffer with _sendingContentsBuffer contents. @@ -81,7 +82,7 @@ public: NetworkReadStream( const char *url, curl_slist *headersList, const Common::HashMap &formFields, - const Common::HashMap &formFiles, + const Common::HashMap &formFiles, bool keepAlive = false, long keepAliveIdle = 120, long keepAliveInterval = 60); /** Send , using POST by default. */ NetworkReadStream(const char *url, curl_slist *headersList, const byte *buffer, uint32 bufferSize, bool uploading = false, bool usingPatch = false, bool post = true, bool keepAlive = false, long keepAliveIdle = 120, long keepAliveInterval = 60); @@ -93,7 +94,7 @@ public: bool reuse( const char *url, curl_slist *headersList, const Common::HashMap &formFields, - const Common::HashMap &formFiles); + const Common::HashMap &formFiles); /** Send , using POST by default. */ bool reuse(const char *url, curl_slist *headersList, const byte *buffer, uint32 bufferSize, bool uploading = false, bool usingPatch = false, bool post = true);