curl: log errors

This commit is contained in:
Megamouse 2021-08-28 16:11:53 +02:00
parent 5aee8a8a81
commit 1060e93783
4 changed files with 38 additions and 14 deletions

View file

@ -584,16 +584,20 @@ int main(int argc, char** argv)
hhdr = curl_slist_append(hhdr, "Accept: application/vnd.github.v3+json"); hhdr = curl_slist_append(hhdr, "Accept: application/vnd.github.v3+json");
hhdr = curl_slist_append(hhdr, "User-Agent: curl/7.37.0"); hhdr = curl_slist_append(hhdr, "User-Agent: curl/7.37.0");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, hhdr); CURLcode err = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, hhdr);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, +[](const char* ptr, usz, usz size, void* json) -> usz if (err != CURLE_OK) fprintf(stderr, "curl_easy_setopt(CURLOPT_HTTPHEADER) error: %s", curl_easy_strerror(err));
err = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, +[](const char* ptr, usz, usz size, void* json) -> usz
{ {
static_cast<QByteArray*>(json)->append(ptr, size); static_cast<QByteArray*>(json)->append(ptr, size);
return size; return size;
}); });
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buf); if (err != CURLE_OK) fprintf(stderr, "curl_easy_setopt(CURLOPT_WRITEFUNCTION) error: %s", curl_easy_strerror(err));
err = curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buf);
if (err != CURLE_OK) fprintf(stderr, "curl_easy_setopt(CURLOPT_WRITEDATA) error: %s", curl_easy_strerror(err));
u32 page = 1; u32 page = 1;
constexpr u32 per_page = 100; constexpr u32 per_page = 100;
while (page <= 55) while (page <= 55)
@ -603,8 +607,19 @@ int main(int argc, char** argv)
if (!from.empty()) if (!from.empty())
fmt::append(url, "&sha=%s", from); fmt::append(url, "&sha=%s", from);
curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); err = curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_perform(curl); if (err != CURLE_OK)
{
fprintf(stderr, "curl_easy_setopt(CURLOPT_URL, %s) error: %s", url.c_str(), curl_easy_strerror(err));
break;
}
err = curl_easy_perform(curl);
if (err != CURLE_OK)
{
fprintf(stderr, "Curl error:\n%s", curl_easy_strerror(err));
break;
}
QJsonDocument info = QJsonDocument::fromJson(buf); QJsonDocument info = QJsonDocument::fromJson(buf);

View file

@ -1,10 +1,13 @@
#include "curl_handle.h" #include "curl_handle.h"
#include "Emu/system_utils.hpp" #include "Emu/system_utils.hpp"
#include "util/logs.hpp"
#ifdef _WIN32 #ifdef _WIN32
#include "Utilities/StrUtil.h" #include "Utilities/StrUtil.h"
#endif #endif
LOG_CHANNEL(network_log, "NET");
curl_handle::curl_handle(QObject* parent) : QObject(parent) curl_handle::curl_handle(QObject* parent) : QObject(parent)
{ {
m_curl = curl_easy_init(); m_curl = curl_easy_init();
@ -14,7 +17,8 @@ curl_handle::curl_handle(QObject* parent) : QObject(parent)
const std::string path_to_cert = rpcs3::utils::get_exe_dir() + "cacert.pem"; const std::string path_to_cert = rpcs3::utils::get_exe_dir() + "cacert.pem";
const std::string ansi_path = utf8_path_to_ansi_path(path_to_cert); const std::string ansi_path = utf8_path_to_ansi_path(path_to_cert);
curl_easy_setopt(m_curl, CURLOPT_CAINFO, ansi_path.data()); const CURLcode err = curl_easy_setopt(m_curl, CURLOPT_CAINFO, ansi_path.data());
if (err != CURLE_OK) network_log.error("curl_easy_setopt(CURLOPT_CAINFO, %s) error: %s", ansi_path, curl_easy_strerror(err));
#endif #endif
} }

View file

@ -8,7 +8,7 @@
#include "Crypto/sha256.h" #include "Crypto/sha256.h"
#include "util/logs.hpp" #include "util/logs.hpp"
LOG_CHANNEL(network_log, "NETWORK"); LOG_CHANNEL(network_log, "NET");
usz curl_write_cb_compat(char* ptr, usz /*size*/, usz nmemb, void* userdata) usz curl_write_cb_compat(char* ptr, usz /*size*/, usz nmemb, void* userdata)
{ {
@ -48,10 +48,17 @@ void downloader::start(const std::string& url, bool follow_location, bool show_p
m_curl_buf.clear(); m_curl_buf.clear();
m_curl_abort = false; m_curl_abort = false;
curl_easy_setopt(m_curl->get_curl(), CURLOPT_URL, url.c_str()); CURLcode err = curl_easy_setopt(m_curl->get_curl(), CURLOPT_URL, url.c_str());
curl_easy_setopt(m_curl->get_curl(), CURLOPT_WRITEFUNCTION, curl_write_cb_compat); if (err != CURLE_OK) network_log.error("curl_easy_setopt(CURLOPT_URL, %s) error: %s", url, curl_easy_strerror(err));
curl_easy_setopt(m_curl->get_curl(), CURLOPT_WRITEDATA, this);
curl_easy_setopt(m_curl->get_curl(), CURLOPT_FOLLOWLOCATION, follow_location ? 1 : 0); err = curl_easy_setopt(m_curl->get_curl(), CURLOPT_WRITEFUNCTION, curl_write_cb_compat);
if (err != CURLE_OK) network_log.error("curl_easy_setopt(CURLOPT_WRITEFUNCTION, curl_write_cb_compat) error: %s", curl_easy_strerror(err));
err = curl_easy_setopt(m_curl->get_curl(), CURLOPT_WRITEDATA, this);
if (err != CURLE_OK) network_log.error("curl_easy_setopt(CURLOPT_WRITEDATA) error: %s", curl_easy_strerror(err));
err = curl_easy_setopt(m_curl->get_curl(), CURLOPT_FOLLOWLOCATION, follow_location ? 1 : 0);
if (err != CURLE_OK) network_log.error("curl_easy_setopt(CURLOPT_FOLLOWLOCATION, %d) error: %s", follow_location, curl_easy_strerror(err));
m_thread = QThread::create([this] m_thread = QThread::create([this]
{ {

View file

@ -47,8 +47,6 @@ rsx_debugger::rsx_debugger(std::shared_ptr<gui_settings> gui_settings, QWidget*
QLabel l("000000000"); // hacky way to get the lineedit to resize properly QLabel l("000000000"); // hacky way to get the lineedit to resize properly
l.setFont(mono); l.setFont(mono);
QHBoxLayout* hbox_controls_addr = new QHBoxLayout();
// Controls: Breaks // Controls: Breaks
QPushButton* b_break_frame = new QPushButton(tr("Frame")); QPushButton* b_break_frame = new QPushButton(tr("Frame"));
QPushButton* b_break_text = new QPushButton(tr("Texture")); QPushButton* b_break_text = new QPushButton(tr("Texture"));