17 #ifndef MASTODONPP_CURL_WRAPPER_HPP
18 #define MASTODONPP_CURL_WRAPPER_HPP
22 #include "curl/curl.h"
27 #include <string_view>
37 using std::string_view;
69 using parametermap = map<string_view, variant<string_view, vector<string_view>>>;
188 return _curl_buffer_body;
193 char _curl_buffer_error[CURL_ERROR_SIZE];
194 string _curl_buffer_headers;
195 string _curl_buffer_body;
196 bool _stream_cancelled;
203 size_t writer_body(
char *data,
size_t size,
size_t nmemb);
213 static inline size_t writer_body_wrapper(
char *data,
size_t sz,
214 size_t nmemb,
void *f)
216 return static_cast<CURLWrapper*>(f)->writer_body(data, sz, nmemb);
220 size_t writer_header(
char *data,
size_t size,
size_t nmemb);
223 static inline size_t writer_header_wrapper(
char *data,
size_t sz,
224 size_t nmemb,
void *f)
226 return static_cast<CURLWrapper*>(f)->writer_header(data, sz, nmemb);
236 int progress(
void *clientp, curl_off_t dltotal, curl_off_t dlnow,
237 curl_off_t ultotal, curl_off_t ulnow);
240 static inline int progress_wrapper(
void *f,
void *clientp,
241 curl_off_t dltotal, curl_off_t dlnow,
242 curl_off_t ultotal, curl_off_t ulnow)
244 return static_cast<CURLWrapper*>(f)->progress(clientp, dltotal, dlnow,
263 void add_parameters_to_uri(
string &uri,
const parametermap ¶meters);
268 #endif // MASTODONPP_CURL_WRAPPER_HPP
http_method
The HTTP method.
Definition: curl_wrapper.hpp:46
CURLWrapper()
Initializes curl and sets up connection.
Definition: curl_wrapper.cpp:42
CURL * get_curl_easy_handle()
Returns pointer to the CURL easy handle.
Definition: curl_wrapper.hpp:127
map< string_view, variant< string_view, vector< string_view > >> parametermap
std::map of parameters for API calls.
Definition: curl_wrapper.hpp:69
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:165
string & get_buffer()
Returns a reference to the buffer libcurl writes into.
Definition: curl_wrapper.hpp:186
void set_proxy(string_view proxy)
Set the proxy to use.
Definition: curl_wrapper.cpp:68
Return type for Requests.
Definition: answer.hpp:40
CURLWrapper & operator=(const CURLWrapper &other)=delete
Copy assignment operator.
Handles the details of network connections.
Definition: curl_wrapper.hpp:80
answer_type make_request(const http_method &method, string uri, const parametermap ¶meters)
Make a HTTP request.
Definition: curl_wrapper.cpp:83
virtual ~CURLWrapper() noexcept
Cleans up curl and connection.
Definition: curl_wrapper.cpp:56
void cancel_stream()
Cancel the stream.
Definition: curl_wrapper.cpp:78