96 lines
2.1 KiB
C++
96 lines
2.1 KiB
C++
#include "pch.h"
|
|
#include "tunnel.h"
|
|
|
|
#include <iostream>
|
|
|
|
#include "usrerr.h"
|
|
#include "logs/fmtlog.h"
|
|
|
|
typedef struct
|
|
{
|
|
PROTO_CRYPTO_TYPE proCryptoType;
|
|
char proKeyBuf[CRYPTO_MAX][256];
|
|
fmtlog::LogLevel logLevel;
|
|
} SDK_CONFIG, *PSDK_CONFIG;
|
|
|
|
static SDK_CONFIG g_globalConfig;
|
|
|
|
NETTUNNELSDK_API int TunnelSDKInitEnv()
|
|
{
|
|
memset(&g_globalConfig, 0, sizeof(SDK_CONFIG));
|
|
g_globalConfig.logLevel = fmtlog::OFF;
|
|
return ERR_SUCCESS;
|
|
}
|
|
|
|
NETTUNNELSDK_API void InitTunnelSDKLog(const char* pLogFile, LOG_LEVEL level)
|
|
{
|
|
char buf[MAX_PATH] = {0};
|
|
static fmtlog::LogLevel lv[LOG_MAX] = {fmtlog::DBG, fmtlog::INF, fmtlog::WRN, fmtlog::ERR,};
|
|
|
|
//::MessageBoxA(NULL, pLogFile, NULL, MB_OK);
|
|
if (pLogFile && strlen(pLogFile) > 0)
|
|
{
|
|
strncpy_s(buf, pLogFile, MAX_PATH);
|
|
}
|
|
else
|
|
{
|
|
GetCurrentDirectory(MAX_PATH, buf);
|
|
strcat_s(buf, "\\tunnelsdk.log");
|
|
}
|
|
|
|
fmtlog::setLogFile(buf, false);
|
|
fmtlog::setHeaderPattern("[{YmdHMSe}][{l}][{s}] ");
|
|
fmtlog::setFlushDelay(1000000);
|
|
fmtlog::setLogLevel(lv[level]);
|
|
|
|
g_globalConfig.logLevel = lv[level];
|
|
|
|
FMTLOG(lv[level], "Log({1}):{0}", buf, (int)level);
|
|
}
|
|
|
|
NETTUNNELSDK_API void TunnelLogEnable(bool enLog)
|
|
{
|
|
if (enLog)
|
|
{
|
|
fmtlog::setLogLevel(g_globalConfig.logLevel);
|
|
}
|
|
else
|
|
{
|
|
fmtlog::setLogLevel(fmtlog::OFF);
|
|
}
|
|
}
|
|
|
|
NETTUNNELSDK_API int SetProtocolEncryptType(PROTO_CRYPTO_TYPE type, const char* pProKey)
|
|
{
|
|
if (type > CRYPTO_BASE64 && type < CRYPTO_MAX)
|
|
{
|
|
if (pProKey == nullptr || strlen(pProKey) < 8)
|
|
{
|
|
return -ERR_INPUT_PARAMS;
|
|
}
|
|
}
|
|
|
|
g_globalConfig.proCryptoType = type;
|
|
strncpy_s(g_globalConfig.proKeyBuf[type], pProKey, 256);
|
|
|
|
logd("Protocol crypto type: {0} with key [{1}]", (int)type, pProKey? pProKey : "");
|
|
|
|
return ERR_SUCCESS;
|
|
}
|
|
|
|
NETTUNNELSDK_API int CreateTunnel(LPCSTR lpszMsg)
|
|
{
|
|
OutputDebugStringA(lpszMsg);
|
|
return 0;
|
|
}
|
|
|
|
NETTUNNELSDK_API const char* TestMessage()
|
|
{
|
|
return "Test Message";
|
|
}
|
|
|
|
NETTUNNELSDK_API int Add(int a, int b)
|
|
{
|
|
return a + b;
|
|
}
|