Porting to Linux

This commit is contained in:
2023-10-16 15:08:11 -04:00
parent 6fe5968ebb
commit 320b4dd714
4 changed files with 47 additions and 8 deletions

View File

@@ -23,9 +23,13 @@ THIRD_PARTY_INCLUDES_START
THIRD_PARTY_INCLUDES_END
#undef UI
#ifdef __linux__
#else
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <wincrypt.h>
#endif
#include <cstdio>
#include <string>
#include <string_view>
@@ -241,6 +245,26 @@ public:
//
/////////////////////////////////////////////////////////////////
#ifdef __linux__
inline static void strerror_helper(int status, int errnum, char errbuf[256]) {
if (status != 0) {
snprintf(errbuf, 256, "unknown errno %d", errnum);
}
}
inline static void strerror_helper(const char *result, int errnum, char errbuf[256]) {
if (result != errbuf) {
snprintf(errbuf, 256, "%s", result);
}
}
static std::string strerror_str(int errnum) {
char buf[256];
auto rval = strerror_r(errnum, buf, 256);
strerror_helper(rval, errnum, buf);
return buf;
}
#else
static std::string strerror_str(int errnum) {
char buf[256];
int status = strerror_s(buf, 256, errnum);
@@ -250,6 +274,8 @@ static std::string strerror_str(int errnum) {
}
return buf;
}
#endif
static FSocket* OpenConnection(ISocketSubsystem *subsys, const std::string& host, const std::string& port, std::string& err)
{
@@ -401,6 +427,12 @@ static SSL_CTX* SSLNewContext(int verify, const SSL_METHOD *method, BIO *tracebi
return ctx;
}
#ifdef __linux__
static std::string SSLLoadCertificateAuthorities(SSL_CTX* ctx) {
check(SSL_CTX_set_default_verify_paths(ctx) == 1);
return "";
}
#else
static std::string SSLLoadCertificateAuthorities(SSL_CTX* ctx) {
HCERTSTORE hStore = CertOpenSystemStoreW(0, L"ROOT");
@@ -427,6 +459,7 @@ static std::string SSLLoadCertificateAuthorities(SSL_CTX* ctx) {
CertCloseStore(hStore, 0);
return "";
}
#endif
static std::string SSLUseCertificateString(SSL_CTX* ctx, const char* str) {
SSLClearErrors();
@@ -747,7 +780,7 @@ void FLpxChannel::Advance()
AdvanceReadWrite();
break;
default:
checkf(false, L"EChanState is invalid");
checkf(false, TEXT("EChanState is invalid"));
break;
}