Add user agent to curl requests

This commit is contained in:
Megamouse 2026-06-18 15:54:22 +02:00
parent 5ee92d2e6c
commit 0735c55bfd
6 changed files with 64 additions and 27 deletions

View File

@ -24,29 +24,27 @@ namespace utils
return (m_hi << 24) | (m_mid << 16) | (m_lo << 8) | ((uint(m_type) & 0xf) << 4) | (m_type_index & 0xf);
}
std::string version::to_string() const
std::string version::to_string(bool simple) const
{
std::string version = std::to_string(hi()) + "." + std::to_string(mid());
std::string version = fmt::format("%d.%d", hi(), mid());
if (lo())
{
version += '.';
version += std::to_string(lo());
fmt::append(version, ".%d", lo());
}
if (type() != version_type::release)
if (!simple && type() != version_type::release)
{
if (!postfix().empty())
{
version += "-" + postfix();
fmt::append(version, "-%s", postfix());
}
version += ' ';
version += utils::to_string(type());
fmt::append(version, " %s", utils::to_string(type()));
if (type_index() > 1)
{
version += " " + std::to_string(type_index());
fmt::append(version, " %d", type_index());
}
}

View File

@ -23,10 +23,10 @@ namespace utils
uint m_lo;
version_type m_type = version_type::release;
uint m_type_index = 1;
const char* m_postfix;
std::string_view m_postfix;
public:
constexpr version(uint hi, uint mid, uint lo, version_type type, uint type_index, const char* postfix)
constexpr version(uint hi, uint mid, uint lo, version_type type, uint type_index, std::string_view postfix)
: m_hi(hi)
, m_mid(mid)
, m_lo(lo)
@ -56,7 +56,7 @@ namespace utils
return m_type;
}
std::string postfix() const
std::string_view postfix() const
{
return m_postfix;
}
@ -67,7 +67,7 @@ namespace utils
}
uint to_hex() const;
std::string to_string() const;
std::string to_string(bool simple = false) const;
};
// Generic version comparison (e.g. 0.0.5 vs 1.3)

View File

@ -1,6 +1,7 @@
#include "stdafx.h"
#include "curl_handle.h"
#include "util/logs.hpp"
#include "util/sysinfo.hpp"
#ifdef _WIN32
#include "Utilities/StrUtil.h"
@ -15,6 +16,12 @@ curl_handle::curl_handle()
{
m_curl = curl_easy_init();
if (!m_curl)
{
network_log.error("curl_easy_init failed");
return;
}
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));
@ -28,11 +35,18 @@ curl_handle::curl_handle()
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));
#endif
const std::string user_agent = utils::get_user_agent();
err = curl_easy_setopt(m_curl, CURLOPT_USERAGENT, user_agent.c_str());
if (err != CURLE_OK) network_log.error("curl_easy_setopt(CURLOPT_USERAGENT): %s", curl_easy_strerror(err));
}
curl_handle::~curl_handle()
{
curl_easy_cleanup(m_curl);
if (m_curl)
{
curl_easy_cleanup(m_curl);
}
}
CURL* curl_handle::get_curl() const

View File

@ -29,7 +29,7 @@ int curl_xferinfo_cb(void* userdata, curl_off_t /*dltotal*/, curl_off_t /*dlnow*
downloader::downloader(QWidget* parent)
: QObject(parent)
, m_parent(parent)
, m_curl(new rpcs3::curl::curl_handle())
, m_curl(std::make_unique<rpcs3::curl::curl_handle>())
{
}

View File

@ -3,6 +3,7 @@
#include "Utilities/File.h"
#include "Emu/vfs_config.h"
#include "Utilities/Thread.h"
#include "rpcs3_version.h"
#if defined(ARCH_ARM64)
#include "Emu/CPU/Backends/AArch64/AArch64Common.h"
@ -796,14 +797,18 @@ utils::OS_version utils::get_OS_version()
return res;
}
std::string utils::get_OS_version_string()
std::string utils::get_OS_version_string(bool simple)
{
std::string output;
#ifdef _WIN32
OSVERSIONINFOW osvi{};
osvi.dwOSVersionInfoSize = sizeof(osvi);
RtlGetVersion(&osvi);
if (simple)
{
return fmt::format("Windows %lu.%lu.%lu", osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.dwBuildNumber);
}
const bool has_sp = osvi.szCSDVersion[0] != L'\0';
std::vector<char> holder;
if (has_sp)
@ -815,8 +820,7 @@ std::string utils::get_OS_version_string()
holder.data(), len, nullptr, nullptr);
}
fmt::append(output,
"Operating system: Windows, Major: %lu, Minor: %lu, Build: %lu, Service Pack: %s",
return fmt::format("Operating system: Windows, Major: %lu, Minor: %lu, Build: %lu, Service Pack: %s",
osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.dwBuildNumber,
has_sp ? holder.data() : "none");
#elif defined (__APPLE__)
@ -824,22 +828,41 @@ std::string utils::get_OS_version_string()
const int minor_version = Darwin_Version::getNSminorVersion();
const int patch_version = Darwin_Version::getNSpatchVersion();
fmt::append(output, "Operating system: macOS, Version: %d.%d.%d",
major_version, minor_version, patch_version);
if (simple)
{
return fmt::format("macOS %d.%d.%d", major_version, minor_version, patch_version);
}
return fmt::format("Operating system: macOS, Version: %d.%d.%d", major_version, minor_version, patch_version);
#else
struct utsname details = {};
if (!uname(&details))
{
fmt::append(output, "Operating system: POSIX, Name: %s, Release: %s, Version: %s",
details.sysname, details.release, details.version);
if (simple)
{
return fmt::format("%s %s", details.sysname, details.release);
}
return fmt::format("Operating system: POSIX, Name: %s, Release: %s, Version: %s", details.sysname, details.release, details.version);
}
else
if (simple)
{
fmt::append(output, "Operating system: POSIX, Unknown version! (Error: %d)", errno);
return "POSIX";
}
return fmt::format("Operating system: POSIX, Unknown version! (Error: %d)", errno);
#endif
return output;
}
std::string utils::get_user_agent()
{
const std::string user_agent = fmt::format("RPCS3/%s (%s; %s)",
rpcs3::get_version().to_string(true),
utils::get_OS_version_string(true),
utils::get_architecture());
return user_agent;
}
int utils::get_maxfiles()

View File

@ -89,7 +89,9 @@ namespace utils
};
OS_version get_OS_version();
std::string get_OS_version_string();
std::string get_OS_version_string(bool simple = false);
std::string get_user_agent();
int get_maxfiles();