Add Instance::set_cainfo().

This commit is contained in:
tastytea 2020-01-12 13:37:53 +01:00
parent cd31af94a6
commit 97eb269865
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
4 changed files with 48 additions and 0 deletions

View File

@ -255,6 +255,14 @@ protected:
*/
void set_access_token(const string_view access_token);
/*!
* @brief Set path to Certificate Authority (CA) bundle.
*
* @since 0.2.1
*/
void set_cainfo(string_view path);
private:
CURL *_connection;
char _curl_buffer_error[CURL_ERROR_SIZE];

View File

@ -166,6 +166,32 @@ public:
*/
vector<string> get_post_formats();
/*!
* @brief Set path to Certificate Authority (CA) bundle.
*
* Sets also the CA info for all Connection%s that are initialized with
* this Instance afterwards.
*
* @since 0.2.1
*/
void set_cainfo(string_view path)
{
_cainfo = path;
CURLWrapper::set_cainfo(path);
}
/*!
* @brief Returns the cainfo path that was previously set.
*
* This is used when initializing a Connection.
*
* @since 0.2.1
*/
string_view get_cainfo()
{
return _cainfo;
}
private:
const string _hostname;
const string _baseuri;
@ -173,6 +199,7 @@ private:
uint64_t _max_chars;
string _proxy;
vector<string> _post_formats;
string _cainfo;
};
} // namespace mastodonpp

View File

@ -35,6 +35,10 @@ Connection::Connection(Instance &instance)
{
CURLWrapper::set_access_token(_instance.get_access_token());
}
if (!_instance.get_cainfo().empty())
{
CURLWrapper::set_cainfo(_instance.get_cainfo());
}
}
string Connection::endpoint_to_uri(const endpoint_variant &endpoint) const

View File

@ -223,6 +223,15 @@ void CURLWrapper::set_access_token(const string_view access_token)
debuglog << "Set authorization token.\n";
}
void CURLWrapper::set_cainfo(string_view path)
{
CURLcode code{curl_easy_setopt(_connection, CURLOPT_CAINFO, path.data())};
if (code != CURLE_OK)
{
throw CURLException{code, "Could not set CA info.", _curl_buffer_error};
}
}
size_t CURLWrapper::writer_body(char *data, size_t size, size_t nmemb)
{
if(data == nullptr)