From 5f3f55fad4143de8c4b2b64b912fbc3f21f20a67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=98=95?= Date: Thu, 24 Aug 2023 09:47:01 +0800 Subject: [PATCH] =?UTF-8?q?OCT=201.=20=E4=BF=AE=E5=A4=8Dhttplib=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E5=BC=82=E5=B8=B8=E8=8E=B7=E5=8F=96=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E7=A8=8B=E5=BA=8F=E9=80=80=E5=87=BA=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NetTunnelSDK/protocol/protocol.cpp | 9 ++++++--- NetTunnelSDK/tunnel/tunnel.cpp | 21 +++++++++++++-------- TestNetTunnelSDK/TestNetTunnelSDK.cpp | 3 +-- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/NetTunnelSDK/protocol/protocol.cpp b/NetTunnelSDK/protocol/protocol.cpp index b2b1149..ffdfa49 100644 --- a/NetTunnelSDK/protocol/protocol.cpp +++ b/NetTunnelSDK/protocol/protocol.cpp @@ -377,15 +377,18 @@ template int PlatformProtolPostMessage(const TCHAR *pUrlPath res = g_httpCtx->Post(pUrlPath, pJson, HTTP_JSON_CONTENT); } } - - SPDLOG_DEBUG(TEXT("+++++ Http Request {0}\n---- Http Response {1}"), pJson, res->body.c_str()); - + if (res.error() != httplib::Error::Success) { SPDLOG_ERROR(TEXT("[{0}]:Post Data {1} error: {2}"), pUrlPath, pJson, httplib::to_string(res.error())); + if(res.error() != httplib::Error::Connection) { + SPDLOG_DEBUG(TEXT("+++++ Http Request {0}\n---- Http Response {1}"), pJson, res->body.c_str()); + } free(pJson); return -ERR_HTTP_POST_DATA; } + SPDLOG_DEBUG(TEXT("+++++ Http Request {0}\n---- Http Response {1}"), pJson, res->body.c_str()); + if (res->status != 200) { SPDLOG_ERROR(TEXT("[{0}]:Post Data {1} server return HTTP error: {2}"), pUrlPath, pJson, res->status); free(pJson); diff --git a/NetTunnelSDK/tunnel/tunnel.cpp b/NetTunnelSDK/tunnel/tunnel.cpp index 8bf54b7..918a45b 100644 --- a/NetTunnelSDK/tunnel/tunnel.cpp +++ b/NetTunnelSDK/tunnel/tunnel.cpp @@ -50,17 +50,22 @@ static spdlog::level::level_enum logLevelToSpdlogLevel(LOG_LEVEL level) { static void InitTunnelSDKLog(const TCHAR *pLogFile, LOG_LEVEL level) { TCHAR buf[MAX_PATH] = {0}; + TCHAR tmpPath[MAX_PATH]; - if (pLogFile && strlen(pLogFile) > 0 && !PathIsRelative(pLogFile)) { - TCHAR tmpPath[MAX_PATH]; - StringCbCopy(tmpPath, MAX_PATH, pLogFile); - PathRemoveFileSpec(tmpPath); - MakeSureDirectoryPathExists(tmpPath); - StringCbCopy(buf, MAX_PATH, pLogFile); + if (pLogFile && strlen(pLogFile) > 0) { + if (PathIsRelative(buf)) { + StringCbPrintf(buf, MAX_PATH, TEXT("%s\\%s"), g_globalConfig.workDirectory, pLogFile); + } else { + StringCbCopy(buf, MAX_PATH, pLogFile); + } } else { StringCbPrintf(buf, MAX_PATH, TEXT("%s\\tunnelsdklog.log"), g_globalConfig.workDirectory); } + StringCbCopy(tmpPath, MAX_PATH, buf); + PathRemoveFileSpec(tmpPath); + MakeSureDirectoryPathExists(tmpPath); + g_globalConfig.enableLog = TRUE; g_globalConfig.logLevel = logLevelToSpdlogLevel(level); @@ -144,7 +149,7 @@ int TunnelSDKInitEnv(const TCHAR *pWorkDir, StringCbCat(g_globalConfig.configDirectory, MAX_PATH, "\\NetTunnel"); SPDLOG_DEBUG(TEXT("Configure directory: {0}."), g_globalConfig.configDirectory); - SPDLOG_DEBUG(TEXT("Platform Server: {}, Work Module: {}"), pSvrUrl, isWorkServer? TEXT("SERVER") : TEXT("Client")); + SPDLOG_DEBUG(TEXT("Platform Server: {}, Work Module: {}"), pSvrUrl, isWorkServer ? TEXT("SERVER") : TEXT("Client")); // 如果配置目录不存在则自动创建 if (!PathFileExists(g_globalConfig.configDirectory)) { @@ -173,7 +178,7 @@ int TunnelSDKInitEnv(const TCHAR *pWorkDir, return -ERR_ITEM_UNEXISTS; } #endif - + return ERR_SUCCESS; } diff --git a/TestNetTunnelSDK/TestNetTunnelSDK.cpp b/TestNetTunnelSDK/TestNetTunnelSDK.cpp index a8362d3..985d4b2 100644 --- a/TestNetTunnelSDK/TestNetTunnelSDK.cpp +++ b/TestNetTunnelSDK/TestNetTunnelSDK.cpp @@ -19,8 +19,7 @@ TEST_MODULE_INITIALIZE(ModuleInitialize) { Assert::AreEqual(0, TunnelSDKInitEnv(path, "http://172.21.40.194:32549", - TEXT("C:\\Users\\HuangXin\\Documents\\development\\visual_studio\\tunnel_" - "windows\\NetTunnelApp\\bin\\Debug\\utest.log"), + TEXT("./test/utest.log"), LOG_TRACE, false)); //Assert::AreEqual(0, EnableVerifySignature(TEXT("123"), TEXT("123456")));