mirror of
https://github.com/RPCS3/rpcs3.git
synced 2026-07-10 01:44:41 -06:00
Add user agent to curl requests
This commit is contained in:
parent
5ee92d2e6c
commit
0735c55bfd
@ -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);
|
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())
|
if (lo())
|
||||||
{
|
{
|
||||||
version += '.';
|
fmt::append(version, ".%d", lo());
|
||||||
version += std::to_string(lo());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type() != version_type::release)
|
if (!simple && type() != version_type::release)
|
||||||
{
|
{
|
||||||
if (!postfix().empty())
|
if (!postfix().empty())
|
||||||
{
|
{
|
||||||
version += "-" + postfix();
|
fmt::append(version, "-%s", postfix());
|
||||||
}
|
}
|
||||||
|
|
||||||
version += ' ';
|
fmt::append(version, " %s", utils::to_string(type()));
|
||||||
version += utils::to_string(type());
|
|
||||||
|
|
||||||
if (type_index() > 1)
|
if (type_index() > 1)
|
||||||
{
|
{
|
||||||
version += " " + std::to_string(type_index());
|
fmt::append(version, " %d", type_index());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,10 +23,10 @@ namespace utils
|
|||||||
uint m_lo;
|
uint m_lo;
|
||||||
version_type m_type = version_type::release;
|
version_type m_type = version_type::release;
|
||||||
uint m_type_index = 1;
|
uint m_type_index = 1;
|
||||||
const char* m_postfix;
|
std::string_view m_postfix;
|
||||||
|
|
||||||
public:
|
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_hi(hi)
|
||||||
, m_mid(mid)
|
, m_mid(mid)
|
||||||
, m_lo(lo)
|
, m_lo(lo)
|
||||||
@ -56,7 +56,7 @@ namespace utils
|
|||||||
return m_type;
|
return m_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string postfix() const
|
std::string_view postfix() const
|
||||||
{
|
{
|
||||||
return m_postfix;
|
return m_postfix;
|
||||||
}
|
}
|
||||||
@ -67,7 +67,7 @@ namespace utils
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint to_hex() const;
|
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)
|
// Generic version comparison (e.g. 0.0.5 vs 1.3)
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "curl_handle.h"
|
#include "curl_handle.h"
|
||||||
#include "util/logs.hpp"
|
#include "util/logs.hpp"
|
||||||
|
#include "util/sysinfo.hpp"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include "Utilities/StrUtil.h"
|
#include "Utilities/StrUtil.h"
|
||||||
@ -15,6 +16,12 @@ curl_handle::curl_handle()
|
|||||||
{
|
{
|
||||||
m_curl = curl_easy_init();
|
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());
|
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));
|
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);
|
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));
|
if (err != CURLE_OK) network_log.error("curl_easy_setopt(CURLOPT_SSL_OPTIONS): %s", curl_easy_strerror(err));
|
||||||
#endif
|
#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_handle::~curl_handle()
|
||||||
{
|
{
|
||||||
curl_easy_cleanup(m_curl);
|
if (m_curl)
|
||||||
|
{
|
||||||
|
curl_easy_cleanup(m_curl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CURL* curl_handle::get_curl() const
|
CURL* curl_handle::get_curl() const
|
||||||
|
|||||||
@ -29,7 +29,7 @@ int curl_xferinfo_cb(void* userdata, curl_off_t /*dltotal*/, curl_off_t /*dlnow*
|
|||||||
downloader::downloader(QWidget* parent)
|
downloader::downloader(QWidget* parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_parent(parent)
|
, m_parent(parent)
|
||||||
, m_curl(new rpcs3::curl::curl_handle())
|
, m_curl(std::make_unique<rpcs3::curl::curl_handle>())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
#include "Utilities/File.h"
|
#include "Utilities/File.h"
|
||||||
#include "Emu/vfs_config.h"
|
#include "Emu/vfs_config.h"
|
||||||
#include "Utilities/Thread.h"
|
#include "Utilities/Thread.h"
|
||||||
|
#include "rpcs3_version.h"
|
||||||
|
|
||||||
#if defined(ARCH_ARM64)
|
#if defined(ARCH_ARM64)
|
||||||
#include "Emu/CPU/Backends/AArch64/AArch64Common.h"
|
#include "Emu/CPU/Backends/AArch64/AArch64Common.h"
|
||||||
@ -796,14 +797,18 @@ utils::OS_version utils::get_OS_version()
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string utils::get_OS_version_string()
|
std::string utils::get_OS_version_string(bool simple)
|
||||||
{
|
{
|
||||||
std::string output;
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
OSVERSIONINFOW osvi{};
|
OSVERSIONINFOW osvi{};
|
||||||
osvi.dwOSVersionInfoSize = sizeof(osvi);
|
osvi.dwOSVersionInfoSize = sizeof(osvi);
|
||||||
RtlGetVersion(&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';
|
const bool has_sp = osvi.szCSDVersion[0] != L'\0';
|
||||||
std::vector<char> holder;
|
std::vector<char> holder;
|
||||||
if (has_sp)
|
if (has_sp)
|
||||||
@ -815,8 +820,7 @@ std::string utils::get_OS_version_string()
|
|||||||
holder.data(), len, nullptr, nullptr);
|
holder.data(), len, nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt::append(output,
|
return fmt::format("Operating system: Windows, Major: %lu, Minor: %lu, Build: %lu, Service Pack: %s",
|
||||||
"Operating system: Windows, Major: %lu, Minor: %lu, Build: %lu, Service Pack: %s",
|
|
||||||
osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.dwBuildNumber,
|
osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.dwBuildNumber,
|
||||||
has_sp ? holder.data() : "none");
|
has_sp ? holder.data() : "none");
|
||||||
#elif defined (__APPLE__)
|
#elif defined (__APPLE__)
|
||||||
@ -824,22 +828,41 @@ std::string utils::get_OS_version_string()
|
|||||||
const int minor_version = Darwin_Version::getNSminorVersion();
|
const int minor_version = Darwin_Version::getNSminorVersion();
|
||||||
const int patch_version = Darwin_Version::getNSpatchVersion();
|
const int patch_version = Darwin_Version::getNSpatchVersion();
|
||||||
|
|
||||||
fmt::append(output, "Operating system: macOS, Version: %d.%d.%d",
|
if (simple)
|
||||||
major_version, minor_version, patch_version);
|
{
|
||||||
|
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
|
#else
|
||||||
struct utsname details = {};
|
struct utsname details = {};
|
||||||
|
|
||||||
if (!uname(&details))
|
if (!uname(&details))
|
||||||
{
|
{
|
||||||
fmt::append(output, "Operating system: POSIX, Name: %s, Release: %s, Version: %s",
|
if (simple)
|
||||||
details.sysname, details.release, details.version);
|
{
|
||||||
|
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
|
#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()
|
int utils::get_maxfiles()
|
||||||
|
|||||||
@ -89,7 +89,9 @@ namespace utils
|
|||||||
};
|
};
|
||||||
OS_version get_OS_version();
|
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();
|
int get_maxfiles();
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user