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;
|
|
|
|
|
|
2021-11-11 14:20:11 +01:00
|
|
|
err = curl_easy_setopt(m_curl, CURLOPT_VERBOSE, g_curl_verbose);
|
|
|
|
|
if (err != CURLE_OK) network_log.error("curl_easy_setopt(CURLOPT_VERBOSE, %d): %s", g_curl_verbose, curl_easy_strerror(err));
|
2021-11-10 23:34:39 +01:00
|
|
|
|
2020-03-22 17:49:33 +01:00
|
|
|
#ifdef _WIN32
|
2023-12-06 18:52:27 +01:00
|
|
|
// Tell curl to use the native CA store for certificate verification
|
|
|
|
|
err = curl_easy_setopt(m_curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA);
|
|
|
|
|
if (err != CURLE_OK) network_log.error("curl_easy_setopt(CURLOPT_SSL_OPTIONS): %s", 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));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2022-01-11 19:42:52 +01:00
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2022-01-15 12:20:48 +01:00
|
|
|
// Functions exported from our user_settings.h in WolfSSL, implemented in RPCS3
|
|
|
|
|
extern "C"
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
FILE* wolfSSL_fopen_utf8(const char* name, const char* mode)
|
2022-01-11 19:42:52 +01:00
|
|
|
{
|
|
|
|
|
return _wfopen(utf8_to_wchar(name).c_str(), utf8_to_wchar(mode).c_str());
|
|
|
|
|
}
|
2022-01-15 12:20:48 +01:00
|
|
|
|
|
|
|
|
int wolfSSL_stat_utf8(const char* path, struct _stat* buffer)
|
|
|
|
|
{
|
|
|
|
|
return _wstat(utf8_to_wchar(path).c_str(), buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2022-01-11 19:42:52 +01:00
|
|
|
#endif
|