diff options
Diffstat (limited to 'src/instance.cpp')
-rw-r--r-- | src/instance.cpp | 67 |
1 files changed, 1 insertions, 66 deletions
diff --git a/src/instance.cpp b/src/instance.cpp index 3f6ab1b..6b3443d 100644 --- a/src/instance.cpp +++ b/src/instance.cpp @@ -15,7 +15,6 @@ */ #include "instance.hpp" -#include "exceptions.hpp" #include <utility> @@ -24,73 +23,9 @@ namespace mastodonpp using std::move; -bool curl_initialized{false}; - Instance::Instance(string instance, string access_token) : _instance{move(instance)} , _access_token{move(access_token)} - , _curl_buffer_error{} -{ - if (!curl_initialized) - { - curl_global_init(CURL_GLOBAL_ALL); // NOLINT(hicpp-signed-bitwise) - curl_initialized = true; - } - _connection = curl_easy_init(); - setup_curl(); -} -Instance::~Instance() -{ - curl_easy_cleanup(_connection); - - if (curl_initialized) - { - curl_global_cleanup(); - curl_initialized = false; - } -} - -int Instance::writer(char *data, size_t size, size_t nmemb, string *writerData) -{ - if(writerData == nullptr) - { - return 0; - } - - writerData->append(data, size*nmemb); - - return static_cast<int>(size * nmemb); -} - -void Instance::setup_curl() -{ - if (_connection == nullptr) - { - throw CURLException{CURLE_FAILED_INIT, "Failed to initialize curl."}; - } - - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) - CURLcode code{curl_easy_setopt(_connection, CURLOPT_ERRORBUFFER, - _curl_buffer_error)}; - if (code != CURLE_OK) - { - throw CURLException{code, "Failed to set error buffer."}; - } - - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) - code = curl_easy_setopt(_connection, CURLOPT_WRITEFUNCTION, writer); - if (code != CURLE_OK) - { - throw CURLException{code, "Failed to set writer", _curl_buffer_error}; - } - - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) - code = curl_easy_setopt(_connection, CURLOPT_WRITEDATA, &_curl_buffer); - if (code != CURLE_OK) - { - throw CURLException{code, "Failed to set write data", - _curl_buffer_error}; - } -} +{} } // namespace mastodonpp |