Move cvars from curlutils.cpp

Move it elsewhere so this code can be shared among tools that don't feature the ConVar class.
This commit is contained in:
Kawe Mazidjatari 2023-07-26 16:52:49 +02:00
parent 85f988dcd7
commit 31d92b439f
5 changed files with 17 additions and 14 deletions

View File

@ -239,6 +239,10 @@ ConVar* net_datablock_networkLossForSlowSpeed = nullptr;
ConVar* pylon_matchmaking_hostname = nullptr;
ConVar* pylon_host_update_interval = nullptr;
ConVar* pylon_showdebuginfo = nullptr;
ConVar* ssl_verify_peer = nullptr;
ConVar* curl_timeout = nullptr;
ConVar* curl_debug = nullptr;
//-----------------------------------------------------------------------------
// RTECH API |
ConVar* rtech_debug = nullptr;

View File

@ -225,6 +225,10 @@ extern ConVar* net_datablock_networkLossForSlowSpeed;
extern ConVar* pylon_matchmaking_hostname;
extern ConVar* pylon_host_update_interval;
extern ConVar* pylon_showdebuginfo;
extern ConVar* ssl_verify_peer;
extern ConVar* curl_timeout;
extern ConVar* curl_debug;
//-------------------------------------------------------------------------
// RTECH API |
extern ConVar* rtech_debug;

View File

@ -362,7 +362,8 @@ bool CPylon::QueryServer(const char* endpoint, const char* request,
CURLFormatUrl(finalUrl, hostName, endpoint);
curl_slist* sList = nullptr;
CURL* curl = CURLInitRequest(finalUrl.c_str(), request, outResponse, sList);
CURL* curl = CURLInitRequest(finalUrl.c_str(), request, outResponse, sList,
curl_timeout->GetInt(), ssl_verify_peer->GetBool(), curl_debug->GetBool());
if (!curl)
{
return false;

View File

@ -1,13 +1,10 @@
#ifndef TIER2_CURLUTILS_H
#define TIER2_CURLUTILS_H
extern ConVar* ssl_verify_peer;
extern ConVar* curl_timeout;
extern ConVar* curl_debug;
size_t CURLWriteStringCallback(char* contents, const size_t size, const size_t nmemb, void* userp);
CURL* CURLInitRequest(const char* remote, const char* request, string& outResponse, curl_slist*& slist);
CURL* CURLInitRequest(const char* remote, const char* request, string& outResponse, curl_slist*& slist,
const int timeOut, const bool verifyPeer, const bool debug, const void* writeFunction = CURLWriteStringCallback);
CURLcode CURLSubmitRequest(CURL* curl, curl_slist*& slist);
CURLINFO CURLRetrieveInfo(CURL* curl);

View File

@ -6,17 +6,14 @@
#include "tier1/cvar.h"
#include "tier2/curlutils.h"
ConVar* ssl_verify_peer = nullptr;
ConVar* curl_timeout = nullptr;
ConVar* curl_debug = nullptr;
size_t CURLWriteStringCallback(char* contents, const size_t size, const size_t nmemb, void* userp)
{
reinterpret_cast<string*>(userp)->append(contents, size * nmemb);
return size * nmemb;
}
CURL* CURLInitRequest(const char* remote, const char* request, string& outResponse, curl_slist*& slist)
CURL* CURLInitRequest(const char* remote, const char* request, string& outResponse, curl_slist*& slist,
const int timeOut, const bool verifyPeer, const bool debug, const void* writeFunction)
{
std::function<void(const char*)> fnError = [&](const char* errorMsg)
{
@ -42,16 +39,16 @@ CURL* CURLInitRequest(const char* remote, const char* request, string& outRespon
curl_easy_setopt(curl, CURLOPT_URL, remote);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request);
curl_easy_setopt(curl, CURLOPT_POST, 1L);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, curl_timeout->GetInt());
curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeOut);
curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CURLWriteStringCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &outResponse);
curl_easy_setopt(curl, CURLOPT_VERBOSE, curl_debug->GetBool());
curl_easy_setopt(curl, CURLOPT_VERBOSE, debug);
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
if (!ssl_verify_peer->GetBool())
if (!verifyPeer)
{
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
}