From 12c0b896db625693fbba0c365dae4b354e67c463 Mon Sep 17 00:00:00 2001 From: tastytea Date: Wed, 21 Aug 2019 03:53:51 +0200 Subject: [PATCH] Use references for HTMLForm, where possible. HTMLForm can't be copied, so I'm returning using unique_ptr in maptoformdata() and references everywhere else. --- src/api/delete.cpp | 2 +- src/api/patch.cpp | 3 +-- src/api/post.cpp | 2 +- src/api/put.cpp | 2 +- src/http.cpp | 22 ++++++++++++---------- src/mastodon-cpp.hpp | 4 ++-- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/api/delete.cpp b/src/api/delete.cpp index 709e637..59429a6 100644 --- a/src/api/delete.cpp +++ b/src/api/delete.cpp @@ -88,5 +88,5 @@ return_call API::del(const Mastodon::API::v1 &call, return_call API::del(const std::string &call, const parameters ¶ms) { - return _http.request(http_method::DELETE, call, maptoformdata(params)); + return _http.request(http_method::DELETE, call, *maptoformdata(params)); } diff --git a/src/api/patch.cpp b/src/api/patch.cpp index 1dd0a30..82f6801 100644 --- a/src/api/patch.cpp +++ b/src/api/patch.cpp @@ -36,6 +36,5 @@ return_call API::patch(const Mastodon::API::v1 &call, break; } - return _http.request(http_method::PATCH, - strcall, maptoformdata(params)); + return _http.request(http_method::PATCH, strcall, *maptoformdata(params)); } diff --git a/src/api/post.cpp b/src/api/post.cpp index 486a07c..b4a1332 100644 --- a/src/api/post.cpp +++ b/src/api/post.cpp @@ -214,5 +214,5 @@ return_call API::post(const Mastodon::API::v1 &call) return_call API::post(const string &call, const parameters ¶ms) { - return _http.request(http_method::POST, call, maptoformdata(params)); + return _http.request(http_method::POST, call, *maptoformdata(params)); } diff --git a/src/api/put.cpp b/src/api/put.cpp index 1a6bcc6..7a3c430 100644 --- a/src/api/put.cpp +++ b/src/api/put.cpp @@ -68,5 +68,5 @@ return_call API::put(const Mastodon::API::v1 &call, return_call API::put(const string &call, const parameters ¶ms) { - return _http.request(http_method::PUT, call, maptoformdata(params)); + return _http.request(http_method::PUT, call, *maptoformdata(params)); } diff --git a/src/http.cpp b/src/http.cpp index 3a7412e..d345b86 100644 --- a/src/http.cpp +++ b/src/http.cpp @@ -106,14 +106,15 @@ API::http::~http() return_call API::http::request(const http_method &meth, const string &path) { - return request(meth, path, make_unique()); + HTMLForm form; + return request(meth, path, form); } return_call API::http::request(const http_method &meth, const string &path, - unique_ptr formdata) + HTMLForm &formdata) { string answer; - return request_common(meth, path, move(formdata), answer); + return request_common(meth, path, formdata, answer); } void API::http::request_stream(const string &path, string &stream) @@ -122,8 +123,9 @@ void API::http::request_stream(const string &path, string &stream) _streamthread = std::thread( [&, path] // path is captured by value because it may be { // deleted before we access it. + HTMLForm form; ret = request_common(http_method::GET_STREAM, path, - make_unique(), stream); + form, stream); ttdebug << "Remaining content of the stream: " << stream << '\n'; if (!ret) { @@ -137,7 +139,7 @@ void API::http::request_stream(const string &path, string &stream) return_call API::http::request_common(const http_method &meth, const string &path, - unique_ptr formdata, + HTMLForm &formdata, string &answer) { ttdebug << "Path is: " << path << '\n'; @@ -190,11 +192,11 @@ return_call API::http::request_common(const http_method &meth, request.set("Authorization", " Bearer " + _access_token); } - if (!formdata->empty()) + if (!formdata.empty()) { - ttdebug << "Size of HTMLForm is " << formdata->size() << '\n'; - formdata->prepareSubmit(request); - formdata->write(session.sendRequest(request)); + ttdebug << "Size of HTMLForm is " << formdata.size() << '\n'; + formdata.prepareSubmit(request); + formdata.write(session.sendRequest(request)); } else { @@ -246,7 +248,7 @@ return_call API::http::request_common(const http_method &meth, } else { - return request_common(meth, location, move(formdata), answer); + return request_common(meth, location, formdata, answer); } } default: diff --git a/src/mastodon-cpp.hpp b/src/mastodon-cpp.hpp index 46a0706..9ef785c 100644 --- a/src/mastodon-cpp.hpp +++ b/src/mastodon-cpp.hpp @@ -105,7 +105,7 @@ namespace Mastodon */ return_call request(const http_method &meth, const string &path, - unique_ptr formdata); + HTMLForm &formdata); /*! * @brief HTTP Request for streams. @@ -156,7 +156,7 @@ namespace Mastodon return_call request_common(const http_method &meth, const string &path, - unique_ptr formdata, + HTMLForm &formdata, string &answer); size_t callback_write(char* data, size_t size, size_t nmemb, string *oss);