forked from RPCS3/rpcs3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
curl_handle.cpp
85 lines (65 loc) · 2.06 KB
/
curl_handle.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "curl_handle.h"
#include "Emu/system_utils.hpp"
#include "util/logs.hpp"
#ifdef _WIN32
#include "Utilities/StrUtil.h"
#endif
LOG_CHANNEL(network_log, "NET");
namespace rpcs3::curl
{
curl_handle::curl_handle(QObject* parent) : QObject(parent)
{
reset_error_buffer();
m_curl = curl_easy_init();
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, g_curl_verbose);
if (err != CURLE_OK) network_log.error("curl_easy_setopt(CURLOPT_VERBOSE, %d): %s", g_curl_verbose, curl_easy_strerror(err));
#ifdef _WIN32
// This shouldn't be needed on linux
const std::string path_to_cert = rpcs3::utils::get_exe_dir() + "cacert.pem";
err = curl_easy_setopt(m_curl, CURLOPT_CAINFO, path_to_cert.data());
if (err != CURLE_OK) network_log.error("curl_easy_setopt(CURLOPT_CAINFO, %s) error: %s", path_to_cert, curl_easy_strerror(err));
#endif
}
curl_handle::~curl_handle()
{
curl_easy_cleanup(m_curl);
}
CURL* curl_handle::get_curl() const
{
return m_curl;
}
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));
}
}
#ifdef _WIN32
// Functions exported from our user_settings.h in WolfSSL, implemented in RPCS3
extern "C"
{
FILE* wolfSSL_fopen_utf8(const char* name, const char* mode)
{
return _wfopen(utf8_to_wchar(name).c_str(), utf8_to_wchar(mode).c_str());
}
int wolfSSL_stat_utf8(const char* path, struct _stat* buffer)
{
return _wstat(utf8_to_wchar(path).c_str(), buffer);
}
}
#endif