2023-07-10 08:36:19 +00:00
|
|
|
|
#include "pch.h"
|
|
|
|
|
|
|
|
|
|
#include "tunnel.h"
|
|
|
|
|
#include "protocol.h"
|
|
|
|
|
|
|
|
|
|
#include "globalcfg.h"
|
|
|
|
|
#include "httplib.h"
|
2023-08-15 07:34:54 +00:00
|
|
|
|
#include "misc.h"
|
2023-07-10 08:36:19 +00:00
|
|
|
|
#include "usrerr.h"
|
|
|
|
|
|
2023-07-17 10:55:01 +00:00
|
|
|
|
#include <strsafe.h>
|
2023-08-14 01:20:25 +00:00
|
|
|
|
#include <spdlog/fmt/bin_to_hex.h>
|
2023-07-17 10:55:01 +00:00
|
|
|
|
|
2023-07-10 08:36:19 +00:00
|
|
|
|
#define HTTP_JSON_CONTENT TEXT("application/json")
|
|
|
|
|
|
2023-07-14 09:29:02 +00:00
|
|
|
|
static httplib::Client *g_httpCtx = nullptr;
|
|
|
|
|
static httplib::Client *g_tunnelHttpCtx = nullptr;
|
|
|
|
|
|
|
|
|
|
int InitControlServer(const TCHAR *pUserSvrUrl) {
|
2023-07-17 10:55:01 +00:00
|
|
|
|
|
|
|
|
|
if (g_tunnelHttpCtx) {
|
|
|
|
|
delete g_tunnelHttpCtx;
|
|
|
|
|
g_tunnelHttpCtx = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-14 01:20:25 +00:00
|
|
|
|
if (UsedSCGProxy()) {
|
2023-08-02 08:41:15 +00:00
|
|
|
|
TCHAR scgProxyUrl[MAX_PATH];
|
|
|
|
|
StringCbPrintf(scgProxyUrl, MAX_PATH, TEXT("http://127.0.0.1:%d"), GetGlobalCfgInfo()->scgProxy.scgGwPort);
|
2023-08-14 01:20:25 +00:00
|
|
|
|
|
|
|
|
|
SPDLOG_DEBUG(TEXT("Control Server Used Proxy: {0} --> {1}"), pUserSvrUrl, scgProxyUrl);
|
|
|
|
|
g_tunnelHttpCtx = new httplib::Client(scgProxyUrl);
|
2023-08-02 08:41:15 +00:00
|
|
|
|
} else {
|
|
|
|
|
g_tunnelHttpCtx = new httplib::Client(pUserSvrUrl);
|
2023-08-14 01:20:25 +00:00
|
|
|
|
SPDLOG_DEBUG(TEXT("Control Server Unused Proxy: {0}"), pUserSvrUrl);
|
2023-08-02 08:41:15 +00:00
|
|
|
|
}
|
2023-07-17 10:55:01 +00:00
|
|
|
|
|
2023-07-25 01:02:16 +00:00
|
|
|
|
if (g_tunnelHttpCtx) {
|
|
|
|
|
g_tunnelHttpCtx->set_connection_timeout(0, 1000000); // 1 second
|
|
|
|
|
g_tunnelHttpCtx->set_read_timeout(5, 0); // 5 seconds
|
|
|
|
|
g_tunnelHttpCtx->set_write_timeout(5, 0); // 5 seconds
|
2023-08-21 01:22:52 +00:00
|
|
|
|
g_tunnelHttpCtx->set_keep_alive(true);
|
2023-07-25 01:02:16 +00:00
|
|
|
|
g_tunnelHttpCtx->set_post_connect_cb([](socket_t sock) {
|
2023-08-02 08:41:15 +00:00
|
|
|
|
if (UsedSCGProxy()) {
|
|
|
|
|
int ret;
|
|
|
|
|
unsigned char vmid[4];
|
2023-08-03 09:13:03 +00:00
|
|
|
|
unsigned char *p;
|
2023-08-02 08:41:15 +00:00
|
|
|
|
const unsigned int id = htonl(GetGlobalCfgInfo()->curConnVmId);
|
2023-08-03 09:13:03 +00:00
|
|
|
|
const auto svrId = static_cast<UINT8>(GetGlobalCfgInfo()->userCfg.cliConfig.scgCtrlAppId);
|
|
|
|
|
unsigned char scgProxy[] = {0x01, // VERSION
|
2023-12-20 03:13:26 +00:00
|
|
|
|
0x00, // Length 0
|
2024-01-18 08:21:31 +00:00
|
|
|
|
0x0B, // Length 1
|
2023-08-03 09:13:03 +00:00
|
|
|
|
0xF0, // ++++++ INFO[0] TYPE
|
2024-01-18 08:21:31 +00:00
|
|
|
|
0x00, // INFO[0] LENGTH 0
|
|
|
|
|
0x04, // INFO[0] LENGTH 1
|
2023-08-03 09:13:03 +00:00
|
|
|
|
0, // INFO[0] VMID[0]
|
|
|
|
|
0, // INFO[0] VMID[1]
|
|
|
|
|
0, // INFO[0] VMID[2]
|
|
|
|
|
0, // INFO[0] VMID[3]
|
|
|
|
|
0xF1, // INFO[1] TYPE
|
2023-12-20 03:13:26 +00:00
|
|
|
|
0x00, // INFO[1] LENGTH 0
|
|
|
|
|
0x01, // INFO[1] LENGTH 1
|
2023-08-03 09:13:03 +00:00
|
|
|
|
svrId}; // ------ INFO[1] SCG Service ID
|
|
|
|
|
p = scgProxy;
|
2023-08-02 08:41:15 +00:00
|
|
|
|
memcpy(vmid, &id, 4);
|
2024-01-18 08:21:31 +00:00
|
|
|
|
scgProxy[6] = vmid[0];
|
|
|
|
|
scgProxy[7] = vmid[1];
|
|
|
|
|
scgProxy[8] = vmid[2];
|
|
|
|
|
scgProxy[9] = vmid[3];
|
2023-08-02 08:41:15 +00:00
|
|
|
|
|
2023-08-14 01:20:25 +00:00
|
|
|
|
if (GetGlobalCfgInfo()->logLevel == spdlog::level::trace) {
|
|
|
|
|
std::array<unsigned char, sizeof(scgProxy)> arr;
|
|
|
|
|
std::copy(std::begin(scgProxy), std::end(scgProxy), std::begin(arr));
|
|
|
|
|
SPDLOG_DEBUG(TEXT("TCP Proxy SCG Payload: {0:Xa}"), spdlog::to_hex(arr));
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-02 08:41:15 +00:00
|
|
|
|
ret = send(sock, reinterpret_cast<const char *>(p), sizeof(scgProxy), 0);
|
|
|
|
|
|
|
|
|
|
while (ret < static_cast<int>(sizeof(scgProxy))) {
|
|
|
|
|
p += ret;
|
|
|
|
|
ret += send(sock, reinterpret_cast<const char *>(p), sizeof(scgProxy), 0);
|
|
|
|
|
}
|
2023-07-25 01:02:16 +00:00
|
|
|
|
|
2023-08-14 01:20:25 +00:00
|
|
|
|
SPDLOG_DEBUG(TEXT("Service Connected To SCG Server({1}/{2}): {0}"),
|
|
|
|
|
sock,
|
|
|
|
|
GetGlobalCfgInfo()->curConnVmId,
|
|
|
|
|
svrId);
|
2023-08-02 08:41:15 +00:00
|
|
|
|
}
|
2023-07-25 01:02:16 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-17 10:55:01 +00:00
|
|
|
|
SPDLOG_DEBUG(TEXT("Connect to Tunnel Control Service: {0}"), pUserSvrUrl);
|
|
|
|
|
|
2023-07-14 09:29:02 +00:00
|
|
|
|
return ERR_SUCCESS;
|
|
|
|
|
}
|
2023-07-10 08:36:19 +00:00
|
|
|
|
|
|
|
|
|
template<class T> int CreateProtocolRequest(T *pReqParams, TCHAR **pOutJson) {
|
|
|
|
|
std::string json;
|
|
|
|
|
|
|
|
|
|
if (!g_httpCtx && lstrlen(GetGlobalCfgInfo()->platformServerUrl) > 0) {
|
|
|
|
|
g_httpCtx = new httplib::Client(GetGlobalCfgInfo()->platformServerUrl);
|
|
|
|
|
if (g_httpCtx) {
|
|
|
|
|
g_httpCtx->set_connection_timeout(0, 300000); // 300 milliseconds
|
|
|
|
|
g_httpCtx->set_read_timeout(5, 0); // 5 seconds
|
|
|
|
|
g_httpCtx->set_write_timeout(5, 0); // 5 seconds
|
2023-08-21 01:22:52 +00:00
|
|
|
|
g_httpCtx->set_keep_alive(true);
|
|
|
|
|
g_httpCtx->enable_server_certificate_verification(false);
|
2023-07-10 08:36:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (aigc::JsonHelper::ObjectToJson(*pReqParams, json)) {
|
|
|
|
|
*pOutJson = _strdup(json.c_str());
|
|
|
|
|
return ERR_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -ERR_JSON_CREATE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T> int DecodeProtocolResponse(T *pResponse, const TCHAR *pJson) {
|
|
|
|
|
if (aigc::JsonHelper::JsonToObject(*pResponse, pJson)) {
|
|
|
|
|
return ERR_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -ERR_JSON_DECODE;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-14 09:29:02 +00:00
|
|
|
|
template<class T1, class T2>
|
|
|
|
|
int ProtolPostMessage(const TCHAR *pUrlPath,
|
|
|
|
|
ProtocolRequest<T1> *pReq,
|
|
|
|
|
ProtocolResponse<T2> *pRsp,
|
|
|
|
|
bool platformServer) {
|
|
|
|
|
int ret;
|
|
|
|
|
httplib::Result res;
|
|
|
|
|
TCHAR *pJson = nullptr;
|
2023-07-10 08:36:19 +00:00
|
|
|
|
|
|
|
|
|
if (lstrlen(GetGlobalCfgInfo()->platformServerUrl) == 0) {
|
|
|
|
|
SPDLOG_ERROR(TEXT("Platform Server URL uninitialize."));
|
|
|
|
|
return -ERR_SYSTEM_UNINITIALIZE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pReq == nullptr) {
|
2023-07-14 09:29:02 +00:00
|
|
|
|
SPDLOG_ERROR(TEXT("Input pToken params error"));
|
|
|
|
|
SPDLOG_ERROR(TEXT("Input ProtocolRequest<T1> *pReq params error"));
|
2023-07-10 08:36:19 +00:00
|
|
|
|
return -ERR_INPUT_PARAMS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pRsp == nullptr) {
|
2023-07-14 09:29:02 +00:00
|
|
|
|
SPDLOG_ERROR(TEXT("Input ProtocolResponse<T2> *pRsp params error"));
|
2023-07-10 08:36:19 +00:00
|
|
|
|
return -ERR_INPUT_PARAMS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret = CreateProtocolRequest(pReq, &pJson);
|
|
|
|
|
|
|
|
|
|
if (ret != ERR_SUCCESS) {
|
|
|
|
|
if (pJson) {
|
|
|
|
|
free(pJson);
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-14 09:29:02 +00:00
|
|
|
|
if (platformServer) {
|
2023-08-14 01:20:25 +00:00
|
|
|
|
std::string timestamp = std::to_string(time(nullptr)) + "000";
|
|
|
|
|
TCHAR hashValeu[MAX_PATH] = {0};
|
|
|
|
|
TCHAR hashBuf[1024] = {};
|
|
|
|
|
|
|
|
|
|
StringCbPrintf(hashBuf,
|
|
|
|
|
1024,
|
|
|
|
|
TEXT("%s|%s|%s|%s"),
|
|
|
|
|
GetGlobalCfgInfo()->clientId,
|
|
|
|
|
GetGlobalCfgInfo()->clientSecret,
|
|
|
|
|
timestamp.c_str(),
|
|
|
|
|
pJson);
|
|
|
|
|
|
|
|
|
|
if (lstrlen(GetGlobalCfgInfo()->clientSecret) > 0 &&
|
|
|
|
|
CalcHmacHash(HASH_SHA256,
|
|
|
|
|
reinterpret_cast<PUCHAR>(hashBuf),
|
|
|
|
|
lstrlen(hashBuf),
|
|
|
|
|
reinterpret_cast<PUCHAR>(GetGlobalCfgInfo()->clientSecret),
|
|
|
|
|
lstrlen(GetGlobalCfgInfo()->clientSecret),
|
|
|
|
|
hashValeu,
|
|
|
|
|
true) == ERR_SUCCESS) {
|
|
|
|
|
const httplib::Headers headers = {
|
|
|
|
|
{"gzs-client-id", GetGlobalCfgInfo()->clientId},
|
|
|
|
|
{"gzs-sign", hashValeu },
|
|
|
|
|
{"gzs-timestamp", timestamp },
|
|
|
|
|
};
|
|
|
|
|
res = g_httpCtx->Post(pUrlPath, headers, pJson, HTTP_JSON_CONTENT);
|
|
|
|
|
} else {
|
|
|
|
|
res = g_httpCtx->Post(pUrlPath, pJson, HTTP_JSON_CONTENT);
|
|
|
|
|
}
|
2023-07-14 09:29:02 +00:00
|
|
|
|
} else {
|
|
|
|
|
if (g_tunnelHttpCtx == nullptr) {
|
|
|
|
|
free(pJson);
|
|
|
|
|
SPDLOG_ERROR(TEXT("Server Control Service don't connected(g_tunnelHttpCtx is not initialize)."));
|
|
|
|
|
return -ERR_SYSTEM_UNINITIALIZE;
|
|
|
|
|
}
|
|
|
|
|
res = g_tunnelHttpCtx->Post(pUrlPath, pJson, HTTP_JSON_CONTENT);
|
|
|
|
|
}
|
2023-07-10 08:36:19 +00:00
|
|
|
|
|
|
|
|
|
if (res.error() != httplib::Error::Success) {
|
2023-07-14 09:29:02 +00:00
|
|
|
|
SPDLOG_ERROR(TEXT("[{0}]:Post Data {1} error: {2}"), pUrlPath, pJson, httplib::to_string(res.error()));
|
|
|
|
|
free(pJson);
|
2023-07-10 08:36:19 +00:00
|
|
|
|
return -ERR_HTTP_POST_DATA;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (res->status != 200) {
|
2023-07-14 09:29:02 +00:00
|
|
|
|
SPDLOG_ERROR(TEXT("[{0}]:Post Data {1} server return HTTP error: {2}"), pUrlPath, pJson, res->status);
|
|
|
|
|
free(pJson);
|
2023-07-10 08:36:19 +00:00
|
|
|
|
return -ERR_HTTP_SERVER_RSP;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-14 09:29:02 +00:00
|
|
|
|
SPDLOG_DEBUG(TEXT("+++++ Http Request {0}\n---- Http Response {1}"), pJson, res->body.c_str());
|
|
|
|
|
|
|
|
|
|
free(pJson);
|
|
|
|
|
|
|
|
|
|
if (lstrlen(res->body.c_str()) == 0) {
|
|
|
|
|
SPDLOG_ERROR(TEXT("Server response empty message"));
|
|
|
|
|
return -ERR_READ_FILE;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-10 08:36:19 +00:00
|
|
|
|
if (DecodeProtocolResponse(pRsp, res->body.c_str()) != ERR_SUCCESS) {
|
2023-07-14 09:29:02 +00:00
|
|
|
|
SPDLOG_ERROR(TEXT("Decode JSON {0} to ProtocolResponse<{1}> error"), res->body, typeid(T2).name());
|
2023-07-10 08:36:19 +00:00
|
|
|
|
return -ERR_JSON_DECODE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ERR_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-15 03:01:31 +00:00
|
|
|
|
#if 0
|
|
|
|
|
template<class T1> int PlatformProtolGetMessage(const TCHAR *pUrlPath, T1 *pRsp) {
|
|
|
|
|
httplib::Result res;
|
|
|
|
|
TCHAR *pJson = nullptr;
|
|
|
|
|
std::string timestamp = std::to_string(time(nullptr)) + "000";
|
|
|
|
|
TCHAR hashValeu[MAX_PATH] = {0};
|
|
|
|
|
TCHAR hashBuf[1024] = {};
|
|
|
|
|
|
|
|
|
|
if (lstrlen(GetGlobalCfgInfo()->platformServerUrl) == 0) {
|
|
|
|
|
SPDLOG_ERROR(TEXT("Platform Server URL uninitialize."));
|
|
|
|
|
return -ERR_SYSTEM_UNINITIALIZE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pRsp == nullptr) {
|
|
|
|
|
SPDLOG_ERROR(TEXT("Input ProtocolResponse<T2> *pRsp params error"));
|
|
|
|
|
return -ERR_INPUT_PARAMS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StringCbPrintf(hashBuf,
|
|
|
|
|
1024,
|
|
|
|
|
TEXT("%s|%s|%s|%s"),
|
|
|
|
|
GetGlobalCfgInfo()->clientId,
|
|
|
|
|
GetGlobalCfgInfo()->clientSecret,
|
|
|
|
|
timestamp.c_str(),
|
|
|
|
|
pJson);
|
|
|
|
|
|
|
|
|
|
if (lstrlen(GetGlobalCfgInfo()->clientSecret) > 0 &&
|
|
|
|
|
CalcHmacHash(HASH_SHA256,
|
|
|
|
|
reinterpret_cast<PUCHAR>(hashBuf),
|
|
|
|
|
lstrlen(hashBuf),
|
|
|
|
|
reinterpret_cast<PUCHAR>(GetGlobalCfgInfo()->clientSecret),
|
|
|
|
|
lstrlen(GetGlobalCfgInfo()->clientSecret),
|
|
|
|
|
hashValeu,
|
|
|
|
|
true) == ERR_SUCCESS) {
|
|
|
|
|
const httplib::Headers headers = {
|
|
|
|
|
{"gzs-client-id", GetGlobalCfgInfo()->clientId},
|
|
|
|
|
{"gzs-sign", hashValeu },
|
|
|
|
|
{"gzs-timestamp", timestamp },
|
|
|
|
|
};
|
|
|
|
|
res = g_httpCtx->Get(pUrlPath, headers);
|
|
|
|
|
} else {
|
|
|
|
|
res = g_httpCtx->Get(pUrlPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (res.error() != httplib::Error::Success) {
|
|
|
|
|
SPDLOG_ERROR(TEXT("[{0}]:Post Data {1} error: {2}"), pUrlPath, pJson, httplib::to_string(res.error()));
|
|
|
|
|
free(pJson);
|
|
|
|
|
return -ERR_HTTP_POST_DATA;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (res->status != 200) {
|
|
|
|
|
SPDLOG_ERROR(TEXT("[{0}]:Post Data {1} server return HTTP error: {2}"), pUrlPath, pJson, res->status);
|
|
|
|
|
free(pJson);
|
|
|
|
|
return -ERR_HTTP_SERVER_RSP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SPDLOG_DEBUG(TEXT("+++++ Http Request {0}\n---- Http Response {1}"), pJson, res->body.c_str());
|
|
|
|
|
|
|
|
|
|
free(pJson);
|
|
|
|
|
|
|
|
|
|
if (lstrlen(res->body.c_str()) == 0) {
|
|
|
|
|
SPDLOG_ERROR(TEXT("Server response empty message"));
|
|
|
|
|
return -ERR_READ_FILE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (DecodeProtocolResponse(pRsp, res->body.c_str()) != ERR_SUCCESS) {
|
|
|
|
|
SPDLOG_ERROR(TEXT("Decode JSON {0} to ProtocolResponse<{1}> error"), res->body, typeid(T1).name());
|
|
|
|
|
return -ERR_JSON_DECODE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ERR_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-08-23 01:05:38 +00:00
|
|
|
|
#if !USER_REAL_PLATFORM
|
2023-08-15 03:01:31 +00:00
|
|
|
|
template<class T1, class T2> int PlatformProtolPostMessage(const TCHAR *pUrlPath, T1 *pReq, T2 *pRsp) {
|
|
|
|
|
int ret;
|
|
|
|
|
httplib::Result res;
|
|
|
|
|
TCHAR *pJson = nullptr;
|
|
|
|
|
std::string timestamp = std::to_string(time(nullptr)) + "000";
|
|
|
|
|
TCHAR hashValeu[MAX_PATH] = {0};
|
|
|
|
|
TCHAR hashBuf[1024] = {};
|
|
|
|
|
|
|
|
|
|
if (lstrlen(GetGlobalCfgInfo()->platformServerUrl) == 0) {
|
|
|
|
|
SPDLOG_ERROR(TEXT("Platform Server URL uninitialize."));
|
|
|
|
|
return -ERR_SYSTEM_UNINITIALIZE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pReq == nullptr) {
|
|
|
|
|
SPDLOG_ERROR(TEXT("Input pToken params error"));
|
|
|
|
|
SPDLOG_ERROR(TEXT("Input ProtocolRequest<T1> *pReq params error"));
|
|
|
|
|
return -ERR_INPUT_PARAMS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pRsp == nullptr) {
|
|
|
|
|
SPDLOG_ERROR(TEXT("Input ProtocolResponse<T2> *pRsp params error"));
|
|
|
|
|
return -ERR_INPUT_PARAMS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret = CreateProtocolRequest(pReq, &pJson);
|
|
|
|
|
|
|
|
|
|
if (ret != ERR_SUCCESS) {
|
|
|
|
|
if (pJson) {
|
|
|
|
|
free(pJson);
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StringCbPrintf(hashBuf,
|
|
|
|
|
1024,
|
|
|
|
|
TEXT("%s|%s|%s|%s"),
|
|
|
|
|
GetGlobalCfgInfo()->clientId,
|
|
|
|
|
GetGlobalCfgInfo()->clientSecret,
|
|
|
|
|
timestamp.c_str(),
|
|
|
|
|
pJson);
|
|
|
|
|
|
|
|
|
|
if (lstrlen(GetGlobalCfgInfo()->clientSecret) > 0 &&
|
|
|
|
|
CalcHmacHash(HASH_SHA256,
|
|
|
|
|
reinterpret_cast<PUCHAR>(hashBuf),
|
|
|
|
|
lstrlen(hashBuf),
|
|
|
|
|
reinterpret_cast<PUCHAR>(GetGlobalCfgInfo()->clientSecret),
|
|
|
|
|
lstrlen(GetGlobalCfgInfo()->clientSecret),
|
|
|
|
|
hashValeu,
|
|
|
|
|
true) == ERR_SUCCESS) {
|
2023-08-21 01:22:52 +00:00
|
|
|
|
if (typeid(T1) == typeid(PlatformReqClientCfgParms)) {
|
2023-08-15 03:01:31 +00:00
|
|
|
|
const auto *p = reinterpret_cast<PlatformReqClientCfgParms *>(pReq);
|
|
|
|
|
const httplib::Headers headers = {
|
2023-08-21 01:22:52 +00:00
|
|
|
|
{"gzs-client-id", GetGlobalCfgInfo()->clientId },
|
2023-08-15 07:34:54 +00:00
|
|
|
|
{"gzs-sign", hashValeu },
|
2023-08-21 01:22:52 +00:00
|
|
|
|
{"gzs-timestamp", timestamp },
|
|
|
|
|
{"Authorization", ("Bearer " + p->token).c_str()},
|
2023-08-15 03:01:31 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
res = g_httpCtx->Post(pUrlPath, headers, pJson, HTTP_JSON_CONTENT);
|
|
|
|
|
} else {
|
|
|
|
|
const httplib::Headers headers = {
|
|
|
|
|
{"gzs-client-id", GetGlobalCfgInfo()->clientId},
|
2023-08-21 01:22:52 +00:00
|
|
|
|
{"gzs-sign", hashValeu },
|
2023-08-15 03:01:31 +00:00
|
|
|
|
{"gzs-timestamp", timestamp },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
res = g_httpCtx->Post(pUrlPath, headers, pJson, HTTP_JSON_CONTENT);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2023-08-21 01:22:52 +00:00
|
|
|
|
if (typeid(T1) == typeid(PlatformReqClientCfgParms)) {
|
2023-08-15 03:01:31 +00:00
|
|
|
|
const auto *p = reinterpret_cast<PlatformReqClientCfgParms *>(pReq);
|
|
|
|
|
const httplib::Headers headers = {
|
2023-08-21 01:22:52 +00:00
|
|
|
|
{"Authorization", ("Bearer " + p->token).c_str()},
|
2023-08-15 03:01:31 +00:00
|
|
|
|
};
|
|
|
|
|
res = g_httpCtx->Post(pUrlPath, headers, pJson, HTTP_JSON_CONTENT);
|
|
|
|
|
} else {
|
|
|
|
|
res = g_httpCtx->Post(pUrlPath, pJson, HTTP_JSON_CONTENT);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-24 01:47:01 +00:00
|
|
|
|
|
2023-08-15 03:01:31 +00:00
|
|
|
|
if (res.error() != httplib::Error::Success) {
|
2023-08-24 09:46:48 +00:00
|
|
|
|
SPDLOG_ERROR(TEXT("[{0}]:Post Data {1} error: {2}"), pUrlPath, pJson, httplib::to_string(res.error()));
|
2023-08-15 03:01:31 +00:00
|
|
|
|
free(pJson);
|
|
|
|
|
return -ERR_HTTP_POST_DATA;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-24 01:47:01 +00:00
|
|
|
|
SPDLOG_DEBUG(TEXT("+++++ Http Request {0}\n---- Http Response {1}"), pJson, res->body.c_str());
|
|
|
|
|
|
2023-08-15 03:01:31 +00:00
|
|
|
|
if (res->status != 200) {
|
|
|
|
|
SPDLOG_ERROR(TEXT("[{0}]:Post Data {1} server return HTTP error: {2}"), pUrlPath, pJson, res->status);
|
|
|
|
|
free(pJson);
|
|
|
|
|
return -ERR_HTTP_SERVER_RSP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free(pJson);
|
|
|
|
|
|
|
|
|
|
if (lstrlen(res->body.c_str()) == 0) {
|
|
|
|
|
SPDLOG_ERROR(TEXT("Server response empty message"));
|
|
|
|
|
return -ERR_READ_FILE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (DecodeProtocolResponse(pRsp, res->body.c_str()) != ERR_SUCCESS) {
|
|
|
|
|
SPDLOG_ERROR(TEXT("Decode JSON {0} to ProtocolResponse<{1}> error"), res->body, typeid(T2).name());
|
|
|
|
|
return -ERR_JSON_DECODE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ERR_SUCCESS;
|
|
|
|
|
}
|
2023-08-23 01:05:38 +00:00
|
|
|
|
#endif
|
2023-08-15 03:01:31 +00:00
|
|
|
|
|
2023-07-14 09:29:02 +00:00
|
|
|
|
template int ProtolPostMessage(const TCHAR *pUrlPath,
|
|
|
|
|
ProtocolRequest<ReqGetUserCfgParams> *pReq,
|
|
|
|
|
ProtocolResponse<RspUserSevrCfgParams> *pRsp,
|
|
|
|
|
bool platformServer);
|
|
|
|
|
|
|
|
|
|
template int ProtolPostMessage(const TCHAR *pUrlPath,
|
|
|
|
|
ProtocolRequest<ReqGetUserCfgParams> *pReq,
|
|
|
|
|
ProtocolResponse<RspUsrCliConfigParams> *pRsp,
|
|
|
|
|
bool platformServer);
|
|
|
|
|
|
2023-07-17 10:55:01 +00:00
|
|
|
|
template int ProtolPostMessage(const TCHAR *pUrlPath,
|
|
|
|
|
ProtocolRequest<ReqUserSetCliCfgParams> *pReq,
|
|
|
|
|
ProtocolResponse<RspUserSetCliCfgParams> *pRsp,
|
|
|
|
|
bool platformServer);
|
2023-07-14 09:29:02 +00:00
|
|
|
|
|
|
|
|
|
template int ProtolPostMessage(const TCHAR *pUrlPath,
|
|
|
|
|
ProtocolRequest<ReqStartTunnelParams> *pReq,
|
|
|
|
|
ProtocolResponse<ResponseStatus> *pRsp,
|
|
|
|
|
bool platformServer);
|
|
|
|
|
|
|
|
|
|
template int ProtolPostMessage(const TCHAR *pUrlPath,
|
|
|
|
|
ProtocolRequest<ReqHeartParams> *pReq,
|
|
|
|
|
ProtocolResponse<RspHeartParams> *pRsp,
|
2023-08-15 03:01:31 +00:00
|
|
|
|
bool platformServer);
|
|
|
|
|
|
|
|
|
|
#if !USER_REAL_PLATFORM
|
|
|
|
|
template int PlatformProtolPostMessage(const TCHAR *pUrlPath,
|
|
|
|
|
PlatformReqServerCfgParms *pReq,
|
|
|
|
|
PlatformRspServerCfgParams *pRsp);
|
|
|
|
|
|
|
|
|
|
template int PlatformProtolPostMessage(const TCHAR *pUrlPath,
|
|
|
|
|
PlatformReqClientCfgParms *pReq,
|
|
|
|
|
PlatformRspClientCfgParams *pRsp);
|
|
|
|
|
|
|
|
|
|
//template int PlatformProtolGetMessage(const TCHAR *pUrlPath, PlatformRspUserClientCfgParams *pRsp);
|
|
|
|
|
#endif
|