17 #ifndef MASTODONPP_CURL_WRAPPER_HPP
18 #define MASTODONPP_CURL_WRAPPER_HPP
22 #include "curl/curl.h"
26 #include <string_view>
33 using std::string_view;
125 char *cbuf{curl_easy_escape(_connection, url.data(),
126 static_cast<int>(url.size()))};
147 char *cbuf{curl_easy_unescape(_connection, url.data(),
148 static_cast<int>(url.size()),
nullptr)};
162 string_view access_token,
164 string_view useragent);
198 return _curl_buffer_body;
212 _stream_cancelled =
true;
251 char _curl_buffer_error[CURL_ERROR_SIZE];
252 string _curl_buffer_headers;
253 string _curl_buffer_body;
254 bool _stream_cancelled;
261 size_t writer_body(
char *data,
size_t size,
size_t nmemb);
271 static inline size_t writer_body_wrapper(
char *data,
size_t sz,
272 size_t nmemb,
void *f)
274 return static_cast<CURLWrapper*>(f)->writer_body(data, sz, nmemb);
278 size_t writer_header(
char *data,
size_t size,
size_t nmemb);
281 static inline size_t writer_header_wrapper(
char *data,
size_t sz,
282 size_t nmemb,
void *f)
284 return static_cast<CURLWrapper*>(f)->writer_header(data, sz, nmemb);
294 int progress(
void *clientp, curl_off_t dltotal, curl_off_t dlnow,
295 curl_off_t ultotal, curl_off_t ulnow);
298 static inline int progress_wrapper(
void *f,
void *clientp,
299 curl_off_t dltotal, curl_off_t dlnow,
300 curl_off_t ultotal, curl_off_t ulnow)
302 return static_cast<CURLWrapper*>(f)->progress(clientp, dltotal, dlnow,
323 bool replace_parameter_in_uri(
string &uri,
const parameterpair ¶meter);
333 void add_parameters_to_uri(
string &uri,
const parametermap ¶meters);
344 void add_mime_part(curl_mime *mime,
345 string_view name, string_view data)
const;
361 curl_mime *parameters_to_curl_mime(
string &uri,
367 #endif // MASTODONPP_CURL_WRAPPER_HPP
http_method
The HTTP method.
Definition: curl_wrapper.hpp:40
CURLWrapper()
Initializes curl and sets up connection.
Definition: curl_wrapper.cpp:41
CURL * get_curl_easy_handle()
Returns pointer to the CURL easy handle.
Definition: curl_wrapper.hpp:105
map< string_view, variant< string_view, vector< string_view > >> parametermap
std::map of parameters for API calls.
Definition: types.hpp:64
string unescape_url(const string_view url) const
URL decodes the given string .
Definition: curl_wrapper.hpp:145
C++ wrapper for the Mastodon API.
Definition: api.cpp:19
mutex buffer_mutex
Mutex for get_buffer a.k.a. _curl_buffer_body.
Definition: curl_wrapper.hpp:175
string & get_buffer()
Returns a reference to the buffer libcurl writes into.
Definition: curl_wrapper.hpp:196
void set_proxy(string_view proxy)
Set the proxy to use.
Definition: curl_wrapper.cpp:216
Return type for Requests.
Definition: types.hpp:82
pair< string_view, variant< string_view, vector< string_view > >> parameterpair
A single parameter of a parametermap.
Definition: types.hpp:72
void set_cainfo(string_view path)
Set path to Certificate Authority (CA) bundle.
Definition: curl_wrapper.cpp:253
CURLWrapper & operator=(const CURLWrapper &other)=delete
Copy assignment operator.
void set_useragent(string_view useragent)
Sets the User-Agent.
Definition: curl_wrapper.cpp:263
Handles the details of network connections.
Definition: curl_wrapper.hpp:58
answer_type make_request(const http_method &method, string uri, const parametermap ¶meters)
Make a HTTP request.
Definition: curl_wrapper.cpp:67
virtual ~CURLWrapper() noexcept
Cleans up curl and connection.
Definition: curl_wrapper.cpp:55
void cancel_stream()
Cancel the stream.
Definition: curl_wrapper.hpp:210
string escape_url(const string_view url) const
URL encodes the given string.
Definition: curl_wrapper.hpp:123
void set_access_token(string_view access_token)
Set OAuth 2.0 Bearer Access Token.
Definition: curl_wrapper.cpp:227
void setup_connection_properties(string_view proxy, string_view access_token, string_view cainfo, string_view useragent)
Set some properties of the connection.
Definition: curl_wrapper.cpp:190