2020-03-22 17:49:33 +01:00
|
|
|
#include "curl_handle.h"
|
2021-04-21 22:12:21 +02:00
|
|
|
#include "Emu/system_utils.hpp"
|
2021-08-28 16:11:53 +02:00
|
|
|
#include "util/logs.hpp"
|
2020-03-22 17:49:33 +01:00
|
|
|
|
2020-03-26 21:48:56 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
#include "Utilities/StrUtil.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-08-28 16:11:53 +02:00
|
|
|
LOG_CHANNEL(network_log, "NET");
|
|
|
|
|
|
2021-11-10 23:34:39 +01:00
|
|
|
namespace rpcs3::curl
|
|
|
|
|
{
|
|
|
|
|
|
2020-03-22 17:49:33 +01:00
|
|
|
curl_handle::curl_handle(QObject* parent) : QObject(parent)
|
|
|
|
|
{
|
2021-11-10 23:34:39 +01:00
|
|
|
reset_error_buffer();
|
|
|
|
|
|
2020-03-22 17:49:33 +01:00
|
|
|
m_curl = curl_easy_init();
|
|
|
|
|
|
2021-11-10 23:34:39 +01:00
|
|
|
CURLcode err = curl_easy_setopt(m_curl, CURLOPT_ERRORBUFFER, m_error_buffer.data());
|
|
|
|
|
if (err != CURLE_OK) network_log.error("curl_easy_setopt(CURLOPT_ERRORBUFFER): %s", curl_easy_strerror(err));
|
|
|
|
|
|
|
|
|
|
m_uses_error_buffer = err == CURLE_OK;
|
|
|
|
|
|
|
|
|
|
err = curl_easy_setopt(m_curl, CURLOPT_VERBOSE, s_curl_verbose);
|
|
|
|
|
if (err != CURLE_OK) network_log.error("curl_easy_setopt(CURLOPT_VERBOSE, %d): %s", s_curl_verbose, curl_easy_strerror(err));
|
|
|
|
|
|
2020-03-22 17:49:33 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
// This shouldn't be needed on linux
|
2021-04-21 22:12:21 +02:00
|
|
|
const std::string path_to_cert = rpcs3::utils::get_exe_dir() + "cacert.pem";
|
2020-03-26 21:48:56 +01:00
|
|
|
const std::string ansi_path = utf8_path_to_ansi_path(path_to_cert);
|
|
|
|
|
|
2021-11-10 23:34:39 +01:00
|
|
|
err = curl_easy_setopt(m_curl, CURLOPT_CAINFO, ansi_path.data());
|
2021-08-28 16:11:53 +02:00
|
|
|
if (err != CURLE_OK) network_log.error("curl_easy_setopt(CURLOPT_CAINFO, %s) error: %s", ansi_path, curl_easy_strerror(err));
|
2020-03-22 17:49:33 +01:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
curl_handle::~curl_handle()
|
|
|
|
|
{
|
|
|
|
|
curl_easy_cleanup(m_curl);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-07 23:05:18 +02:00
|
|
|
CURL* curl_handle::get_curl() const
|
2020-03-22 17:49:33 +01:00
|
|
|
{
|
|
|
|
|
return m_curl;
|
|
|
|
|
}
|
2021-11-10 23:34:39 +01:00
|
|
|
|
|
|
|
|
void curl_handle::reset_error_buffer()
|
|
|
|
|
{
|
|
|
|
|
ensure(m_error_buffer.size() == CURL_ERROR_SIZE);
|
|
|
|
|
m_error_buffer[0] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string curl_handle::get_verbose_error(CURLcode code)
|
|
|
|
|
{
|
|
|
|
|
if (m_uses_error_buffer)
|
|
|
|
|
{
|
|
|
|
|
ensure(m_error_buffer.size() == CURL_ERROR_SIZE);
|
|
|
|
|
if (m_error_buffer[0])
|
|
|
|
|
{
|
|
|
|
|
return fmt::format("Curl error (%d): %s\nDetails: %s", static_cast<int>(code), curl_easy_strerror(code), m_error_buffer.data());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fmt::format("Curl error (%d): %s", static_cast<int>(code), curl_easy_strerror(code));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|