17 #ifndef MASTODONPP_CURL_WRAPPER_HPP
18 #define MASTODONPP_CURL_WRAPPER_HPP
22 #include "curl/curl.h"
27 #include <string_view>
38 using std::string_view;
77 map<string_view, variant<string_view, vector<string_view>>>;
85 pair<string_view, variant<string_view, vector<string_view>>>;
192 return _curl_buffer_body;
206 _stream_cancelled =
true;
218 char _curl_buffer_error[CURL_ERROR_SIZE];
219 string _curl_buffer_headers;
220 string _curl_buffer_body;
221 bool _stream_cancelled;
228 size_t writer_body(
char *data,
size_t size,
size_t nmemb);
238 static inline size_t writer_body_wrapper(
char *data,
size_t sz,
239 size_t nmemb,
void *f)
241 return static_cast<CURLWrapper*>(f)->writer_body(data, sz, nmemb);
245 size_t writer_header(
char *data,
size_t size,
size_t nmemb);
248 static inline size_t writer_header_wrapper(
char *data,
size_t sz,
249 size_t nmemb,
void *f)
251 return static_cast<CURLWrapper*>(f)->writer_header(data, sz, nmemb);
261 int progress(
void *clientp, curl_off_t dltotal, curl_off_t dlnow,
262 curl_off_t ultotal, curl_off_t ulnow);
265 static inline int progress_wrapper(
void *f,
void *clientp,
266 curl_off_t dltotal, curl_off_t dlnow,
267 curl_off_t ultotal, curl_off_t ulnow)
269 return static_cast<CURLWrapper*>(f)->progress(clientp, dltotal, dlnow,
290 bool replace_parameter_in_uri(
string &uri,
const parameterpair ¶meter);
300 void add_parameters_to_uri(
string &uri,
const parametermap ¶meters);
311 void add_mime_part(curl_mime *mime,
312 string_view name, string_view data)
const;
328 curl_mime *parameters_to_curl_mime(
string &uri,
334 #endif // MASTODONPP_CURL_WRAPPER_HPP
http_method
The HTTP method.
Definition: curl_wrapper.hpp:48
void set_access_token(const string_view access_token)
Set OAuth 2.0 Bearer Access Token.
Definition: curl_wrapper.cpp:200
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:143
map< string_view, variant< string_view, vector< string_view > >> parametermap
std::map of parameters for API calls.
Definition: curl_wrapper.hpp:77
C++ wrapper for the Mastodon API.
Definition: answer.cpp:22
mutex buffer_mutex
Mutex for get_buffer a.k.a. _curl_buffer_body.
Definition: curl_wrapper.hpp:169
string & get_buffer()
Returns a reference to the buffer libcurl writes into.
Definition: curl_wrapper.hpp:190
void set_proxy(string_view proxy)
Set the proxy to use.
Definition: curl_wrapper.cpp:67
Return type for Requests.
Definition: answer.hpp:40
pair< string_view, variant< string_view, vector< string_view > >> parameterpair
A single parameter of a parametermap.
Definition: curl_wrapper.hpp:85
CURLWrapper & operator=(const CURLWrapper &other)=delete
Copy assignment operator.
Handles the details of network connections.
Definition: curl_wrapper.hpp:96
answer_type make_request(const http_method &method, string uri, const parametermap ¶meters)
Make a HTTP request.
Definition: curl_wrapper.cpp:77
virtual ~CURLWrapper() noexcept
Cleans up curl and connection.
Definition: curl_wrapper.cpp:55
void cancel_stream()
Cancel the stream.
Definition: curl_wrapper.hpp:204