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;
129 char *cbuf{curl_easy_escape(_connection, url.data(),
130 static_cast<int>(url.size()))};
131 const string sbuf{cbuf};
151 char *cbuf{curl_easy_unescape(_connection, url.data(),
152 static_cast<int>(url.size()),
nullptr)};
153 const string sbuf{cbuf};
166 string_view access_token,
168 string_view useragent);
202 return _curl_buffer_body;
216 _stream_cancelled =
true;
229 virtual void set_proxy(string_view proxy);
255 char _curl_buffer_error[CURL_ERROR_SIZE];
256 string _curl_buffer_headers;
257 string _curl_buffer_body;
258 bool _stream_cancelled;
272 size_t writer_body(
char *data,
size_t size,
size_t nmemb);
282 static inline size_t writer_body_wrapper(
char *data,
size_t sz,
283 size_t nmemb,
void *f)
285 return static_cast<CURLWrapper*>(f)->writer_body(data, sz, nmemb);
289 size_t writer_header(
char *data,
size_t size,
size_t nmemb);
292 static inline size_t writer_header_wrapper(
char *data,
size_t sz,
293 size_t nmemb,
void *f)
295 return static_cast<CURLWrapper*>(f)->writer_header(data, sz, nmemb);
305 int progress(
void *clientp, curl_off_t dltotal, curl_off_t dlnow,
306 curl_off_t ultotal, curl_off_t ulnow);
309 static inline int progress_wrapper(
void *f,
void *clientp,
310 curl_off_t dltotal, curl_off_t dlnow,
311 curl_off_t ultotal, curl_off_t ulnow)
313 return static_cast<CURLWrapper*>(f)->progress(clientp, dltotal, dlnow,
334 static bool replace_parameter_in_uri(
string &uri,
345 static void add_parameters_to_uri(
string &uri,
357 static void add_mime_part(curl_mime *mime,
358 string_view name, string_view data);
374 curl_mime *parameters_to_curl_mime(
string &uri,
380 #endif // MASTODONPP_CURL_WRAPPER_HPP
http_method
The HTTP method.
Definition: curl_wrapper.hpp:40
mutex _buffer_mutex
Mutex for get_buffer a.k.a. _curl_buffer_body.
Definition: curl_wrapper.hpp:179
CURLWrapper()
Initializes curl and sets up connection.
Definition: curl_wrapper.cpp:57
CURL * get_curl_easy_handle()
Returns pointer to the CURL easy handle.
Definition: curl_wrapper.hpp:109
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:149
C++ wrapper for the Mastodon API.
Definition: api.cpp:19
string & get_buffer()
Returns a reference to the buffer libcurl writes into.
Definition: curl_wrapper.hpp:200
virtual void set_proxy(string_view proxy)
Set the proxy to use.
Definition: curl_wrapper.cpp:234
Return type for Requests.
Definition: types.hpp:79
pair< string_view, variant< string_view, vector< string_view > >> parameterpair
A single parameter of a parametermap.
Definition: types.hpp:72
virtual void set_cainfo(string_view path)
Set path to Certificate Authority (CA) bundle.
Definition: curl_wrapper.cpp:271
CURLWrapper & operator=(const CURLWrapper &other)=delete
Copy assignment operator.
virtual void set_useragent(string_view useragent)
Sets the User-Agent.
Definition: curl_wrapper.cpp:281
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:85
virtual ~CURLWrapper() noexcept
Cleans up curl and connection.
Definition: curl_wrapper.cpp:73
void cancel_stream()
Cancel the stream.
Definition: curl_wrapper.hpp:214
string escape_url(const string_view url) const
URL encodes the given string.
Definition: curl_wrapper.hpp:127
void set_access_token(string_view access_token)
Set OAuth 2.0 Bearer Access Token.
Definition: curl_wrapper.cpp:245
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:208