123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590 |
- #include "stdafx.h"
- #include "baseEx.h"
- #include <stdint.h>
- #include <iostream>
- #include <vector>
- #include <map>
- #include <boost/xpressive/xpressive_dynamic.hpp>
- #include <boost/algorithm/string.hpp>
- #include <boost/filesystem.hpp>
- #include <boost/chrono.hpp>
- #include <boost/interprocess/ipc/message_queue.hpp>
- #include <boost/interprocess/permissions.hpp>
- #include <boost/thread/mutex.hpp>
- #include <boost/thread/lock_guard.hpp>
- #include <boost/algorithm/hex.hpp>
- #include "winpr/sysinfo.h"
- #include "winpr/timezone.h"
- #include "EventCode.h"
- #include "exLog/log.h"
- #include "cJSON.h"
- #include "RVCComm.h"
- using namespace boost::interprocess;
- //read ini
- #include <boost/property_tree/ptree.hpp>
- #include <boost/property_tree/ini_parser.hpp>
- #if (defined _WIN32 || defined _WIN64)
- #define BOOST_INTERPROCESS_SHARED_DIR_PATH "C:\\"
- #else
- #include <sys/types.h>
- #include <unistd.h>
- #include <cstring>
- #include <signal.h>
- #endif
- std::string g_usercodeTranslateFile = "";
- std::map<std::string, std::vector<std::string>> g_networkParse;
- std::map<std::string, clock_t> g_networkExpiredData;
- std::map<std::string, ErrMsgStruct> g_UserCodeToMsgTip;
- boost::mutex g_networkMutex;
- const std::wstring WCHAR_NULL = L"";
- const std::wstring specialStr = L"乗俓僜刓匼哱圽塡奬媆峔嶾廫慭怽揬昞朶梊榎橽歕沑漒瀄焅燶猏玕琝甛璡痋盶癨瞈砛碶穃竆筡篭糪絓綷縗繺羂耚肻腬臶臷芢蒤薥蚛蝄蟎衆蟎裓覾譢豛赲踈躙輁郳醆鈂鉢鎈鏫閈闬隲頫颸餦馶骪鯸鮘鳿鵟鸤黒齖";
- #define NOR_LEN 50
- #define MAX_LOG_LEN 4096
- #define MAX_CEFLOG_LEN 5120
- #if (defined _WIN32 || defined _WIN64)
- #include <ShellAPI.h>
- std::string UtfToGbk(const char* utf8)
- {
- int len = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0);
- wchar_t* wstr = new wchar_t[len + 1];
- memset(wstr, 0, len + 1);
- MultiByteToWideChar(CP_UTF8, 0, utf8, -1, wstr, len);
- len = WideCharToMultiByte(CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL);
- char* str = new char[len + 1];
- memset(str, 0, len + 1);
- WideCharToMultiByte(CP_ACP, 0, wstr, -1, str, len, NULL, NULL);
- if (wstr) delete[] wstr;
- return str;
- }
- //GBK转化为UTF8格式
- std::string ConvertGBKToUtf8(std::string& strGBK)
- {
- int len = MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)strGBK.c_str(), -1, NULL, 0);
- wchar_t* wszUtf8 = new wchar_t[len];
- memset(wszUtf8, 0, len);
- MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)strGBK.c_str(), -1, wszUtf8, len);
- len = WideCharToMultiByte(CP_UTF8, 0, wszUtf8, -1, NULL, 0, NULL, NULL);
- char* szUtf8 = new char[len + 1];
- memset(szUtf8, 0, len + 1);
- WideCharToMultiByte(CP_UTF8, 0, wszUtf8, -1, szUtf8, len, NULL, NULL);
- std::string ret = szUtf8;
- delete[] szUtf8;
- delete[] wszUtf8;
- return ret;
- }
- #else
- std::string UtfToGbk(const char* utf8)
- {
- return utf8;
- }
- std::string ConvertGBKToUtf8(std::string& strGBK)
- {
- return strGBK;
- }
- #endif
- struct cefclientLog {
- LOG_LEVEL_E m_level;
- LOG_TYPE_E m_type;
- char m_logTime[NOR_LEN];
- char m_filename[NOR_LEN];
- int m_filePos;
- char m_cefLog[MAX_CEFLOG_LEN];
- cefclientLog(LOG_LEVEL_E t_level, LOG_TYPE_E t_type, const char* t_logTime, const char* t_filename, int t_filePos, const char* t_cefLog) {
- m_level = t_level;
- m_type = t_type;
- strcpy_s(m_logTime, NOR_LEN, t_logTime);
- strcpy_s(m_filename, NOR_LEN, t_filename);
- m_filePos = t_filePos;
- strcpy_s(m_cefLog, MAX_CEFLOG_LEN, t_cefLog);
- }
- cefclientLog()
- :m_level(LOG_LEVEL_DEBUG), m_type(LOG_TYPE_SYSTEM), m_filePos(0)
- {
- memset(m_logTime, 0, NOR_LEN);
- memset(m_filename, 0, NOR_LEN);
- memset(m_cefLog, 0, MAX_CEFLOG_LEN);
- }
- };
- #define CEF_GUID "{5ED197CD-9D64-4D10-9839-2A0773B6F5D2}"
- bool InitFileLogger(std::string dbgPath)
- {
- auto ret = logger::init(dbgPath.c_str(), "cefLog");
- ConfigManager::getInstance().setLoggerInitSuccess(ret);
- return ret;
- }
- void DbgToFileLogger(std::string msg)
- {
- if(ConfigManager::getInstance().isLoggerInitSuccess())
- logger::showLog(msg);
- }
- void DbgEx(const char* str, ...)
- {
- va_list arg;
- va_start(arg, str);
- #if (defined _WIN32 || defined _WIN64)
- int n = _vscprintf(str, arg);
- char* buf = (char*)malloc(n + 1);
- vsprintf(buf, str, arg);
- auto modifyStr = CSimpleString::Format("%s", buf);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).withExtendLog(!ConfigManager::getInstance().m_withNoFileLog).setResultMsg(modifyStr.GetData())();
- free(buf);
- #else
- auto modifyStr = CSimpleString::Format("%s", str);
- vDbg(modifyStr.GetData(), arg);
- #endif
- va_end(arg);
- }
- bool SYSTEM_ON(std::string cmdLine, bool isWait)
- {
- #if (defined _WIN32 || defined _WIN64)
- auto waitSystem = [](const std::string cmd, const std::string par, BOOL nShow) ->DWORD
- {
- SHELLEXECUTEINFO ShExecInfo = { 0 };
- ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
- ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
- ShExecInfo.hwnd = NULL;
- ShExecInfo.lpVerb = NULL;
- ShExecInfo.lpFile = cmd.c_str(); //调用的程序名
- ShExecInfo.lpParameters = par.c_str(); //调用程序的命令行参数
- ShExecInfo.lpDirectory = NULL;
- ShExecInfo.nShow = nShow ? SW_SHOW : SW_HIDE; //窗口状态为隐藏
- ShExecInfo.hInstApp = NULL;
- if (ShellExecuteEx(&ShExecInfo) && ShExecInfo.hProcess)//如果设置了 SEE_MASK_NOCLOSEPROCESS ,并且调用成功则该值大于32,调用失败者被设置错误值
- {
- //创建进程成功
- WaitForSingleObject(ShExecInfo.hProcess, INFINITE); //等到该进程结束
- DWORD exitCode = 0;
- GetExitCodeProcess(ShExecInfo.hProcess, &exitCode);
- return exitCode;
- }
- else {
- std::string errMsg;
- auto errorCode = GetLastError();
- switch (errorCode)
- {
- #define CASE(code) \
- case code: \
- errMsg = #code; \
- break
- CASE(ERROR_FILE_NOT_FOUND);
- CASE(ERROR_PATH_NOT_FOUND);
- CASE(ERROR_DDE_FAIL);
- CASE(ERROR_NO_ASSOCIATION);
- CASE(ERROR_ACCESS_DENIED);
- CASE(ERROR_DLL_NOT_FOUND);
- CASE(ERROR_CANCELLED);
- CASE(ERROR_NOT_ENOUGH_MEMORY);
- CASE(ERROR_SHARING_VIOLATION);
- default:
- errMsg = "UNKNOWN";
- }
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("SYSTEM_ON wait with %s failed, reason:%d-%s", par.c_str(), errorCode, errMsg.c_str());
- return false;
- }
-
-
- };
- std::string strCmd, strPar;
- if (isWait)
- {
- strPar = std::string("/c ") + cmdLine;
- strCmd = std::string("cmd ") + strPar;
- return waitSystem("cmd.exe", strPar, FALSE);
- }
- else {
- strCmd = cmdLine;
- unsigned int result = WinExec(strCmd.c_str(), SW_HIDE);
- if (result > 31)
- return true;
- else
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__).setAPI(__FUNCTION__)("SYSTEM_ON nowait with %s failed, reason:%d", result);
- return false;
- }
- }
- #else
- system(cmdLine.c_str());
- return true;
- #endif
- return false;
- }
- DWORD SaveCefclientLog(std::string magicStr)
- {
- std::string dstGuid = magicStr + "_" + CEF_GUID;
- try {
- auto removeRet = message_queue::remove(dstGuid.c_str());
- if (!removeRet)
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("message_queue did not remove!");
- boost::interprocess::permissions cur;
- cur.set_unrestricted();
- message_queue mq(create_only, dstGuid.c_str(), 100, sizeof(cefclientLog), cur);
- ConfigManager::getInstance().setUseMagic(true);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("SaveCefclientLog thread begin");
- while (true)
- {
- cefclientLog t_data;
- #if (defined _WIN32 || defined _WIN64)
- unsigned int t_recvSize = 0;
- #else
- unsigned long t_recvSize = 0;
- #endif
- unsigned int t_priority = 0;
- mq.receive(&t_data, sizeof(cefclientLog), t_recvSize, t_priority);
- std::string source = std::string(t_data.m_filename) + "(" + std::to_string((ULONGLONG)t_data.m_filePos) + ")";
- #ifdef OUTPUT_DETAIL_LOG /*DevOps流水线编译,ST环境*/
- DbgWithLink(t_data.m_level, t_data.m_type).withLogProducer(ConfigManager::getInstance().getLogProducer()).setSourceType(source.c_str()).withExtendLog(true).setResultMsg(t_data.m_cefLog)();
- #elif defined(DEVOPS_ON_UAT)/*DevOps流水线编译,UAT环境*/
- DbgWithLink(t_data.m_level, t_data.m_type).withLogProducer(ConfigManager::getInstance().getLogProducer()).setSourceType(source.c_str()).withExtendLog(true).setResultMsg(t_data.m_cefLog)();
- #elif defined(DEVOPS_ON_PRD)/*DevOps流水线编译,PRD环境*/
- DbgWithLink(t_data.m_level, t_data.m_type).withLogProducer(ConfigManager::getInstance().getLogProducer()).setSourceType(source.c_str()).withExtendLog(false).setResultMsg(t_data.m_cefLog)();
- #else
- DbgWithLink(t_data.m_level, t_data.m_type).withLogProducer(ConfigManager::getInstance().getLogProducer()).setSourceType(source.c_str()).withExtendLog(false).setResultMsg(t_data.m_cefLog)();
- #endif // DEVOPS
- if (sizeof(cefclientLog) != t_recvSize)
- break;
- /*特么制品库太恶心了
- cefclientLog tmp;
- std::istringstream iss(t_data);
- boost::archive::binary_iarchive iarchive(iss);
- iarchive >> tmp;//从一个保存序列化数据的string里面反序列化,从而得到原来的对象
- std::string source = tmp.m_filename + "(" + std::to_string((ULONGLONG)tmp.m_filePos) + ")";
- DbgWithLink(tmp.m_level, tmp.m_type).setSourceType(source.c_str())(tmp.m_cefLog.c_str());
- */
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("SaveCefclientLog thread end");
- }
- catch (interprocess_exception& ex) {
- message_queue::remove(dstGuid.c_str());
- ConfigManager::getInstance().setUseMagic(false);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("%s run exception, for %s", dstGuid.c_str(), ex.what());
- return 1;
- }
- ConfigManager::getInstance().setUseMagic(false);
- message_queue::remove(dstGuid.c_str());
- return 0;
- }
- std::vector<std::string> find_files(const std::string srcPath, const std::string fileName, bool isDir)
- {
- static boost::xpressive::sregex_compiler rc;
- if (!rc[fileName].regex_id())
- {
- std::string str = boost::algorithm::replace_all_copy(
- boost::algorithm::replace_all_copy(fileName, ".", "\\."), "*", ".*");
- rc[fileName] = rc.compile(str);
- }
- std::vector<std::string> ret;
- if (!boost::filesystem::exists(srcPath) || !boost::filesystem::is_directory(srcPath))
- return ret;
- typedef boost::filesystem::recursive_directory_iterator rd_iterator;
- rd_iterator end;
- for (rd_iterator pos(srcPath); pos != end; ++pos)
- {
- if ((isDir ? boost::filesystem::is_directory(*pos) : !boost::filesystem::is_directory(*pos)) && boost::xpressive::regex_match(pos->path().filename().string(), rc[fileName]))
- ret.emplace_back(pos->path().string());
- }
- return ret;
- }
- bool deleteDir_byFileSystem(const std::string srcPath)
- {
- boost::system::error_code ec;
- return boost::filesystem::remove_all(srcPath, ec);
- }
- std::string generateTimeStr(bool isSimple)
- {
- auto tt = boost::chrono::system_clock::to_time_t(boost::chrono::system_clock::now());
- struct tm* ptm = localtime(&tt);
- char date[60] = { 0 };
- if (isSimple)
- sprintf(date, "%02d%02d%02d", (int)ptm->tm_hour, (int)ptm->tm_min, (int)ptm->tm_sec);
- else
- sprintf(date, "%d-%02d-%02d-%02d:%02d:%02d", (int)ptm->tm_year + 1900, (int)ptm->tm_mon + 1, (int)ptm->tm_mday, (int)ptm->tm_hour, (int)ptm->tm_min, (int)ptm->tm_sec);
- return std::string(date);
- }
- void InitTranslateFile(std::string srcFile)
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("InitTranslateFile %s", srcFile.c_str());
- g_usercodeTranslateFile = srcFile;
- }
- void InitUserCodeToMsgTip(CAutoArray<CSimpleStringA>& strErrorCodeArr, CAutoArray<CSimpleStringA>& strDescriptionArr, CAutoArray<CSimpleStringA>& strRemarkArr)
- {
- g_UserCodeToMsgTip.clear();//should not be inited muli times
- for (int i = 0; i < strErrorCodeArr.GetCount(); i++)
- {
- std::string dstDescribe = "[" + std::string(strErrorCodeArr[i].GetData()) + "]" + std::string(strDescriptionArr[i].GetData());
- if (g_UserCodeToMsgTip.find(strRemarkArr[i].GetData()) != g_UserCodeToMsgTip.end())
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("InitUserCodeToMsgTip repeated usercode:%s", strRemarkArr[i].GetData());
- continue;
- }
- std::string curRemark = strRemarkArr[i].GetData();
- std::transform(curRemark.begin(), curRemark.end(), curRemark.begin(), [](unsigned char c) { return std::tolower(c); });
- g_UserCodeToMsgTip.insert(std::make_pair(curRemark.c_str(), ErrMsgStruct(strErrorCodeArr[i].GetData(), dstDescribe, curRemark.c_str())));
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("InitUserCodeToMsgTip size:%d", g_UserCodeToMsgTip.size());
- }
- std::pair<unsigned long, ErrMsgStruct> getErrMsgByRemark(std::string srcMsg)
- {
- const std::string headerStr = "UserError=";
- if (srcMsg.find(headerStr) != 0)
- return std::make_pair(0, ErrMsgStruct("", srcMsg, ""));
- unsigned long userCode = std::stoi(srcMsg.substr(headerStr.length()));
- std::string userCodeStr = CSimpleString::Format("0x%X", userCode).GetData();
- std::transform(userCodeStr.begin(), userCodeStr.end(), userCodeStr.begin(), [](unsigned char c) { return std::tolower(c); });
- if (g_UserCodeToMsgTip.size() == 0)
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA42F0").setAPI(__FUNCTION__)("[RTA42F0]微服务异常|(%s)", srcMsg.c_str());
- return std::make_pair(0, ErrMsgStruct("RTA42F0", CSimpleString::Format("[RTA42F0]微服务异常|(%s)", srcMsg.c_str()).GetData(), userCodeStr));
- }
- if (g_UserCodeToMsgTip.find(userCodeStr) != g_UserCodeToMsgTip.end())
- {
- ErrMsgStruct curMsg(g_UserCodeToMsgTip[userCodeStr]);
- return std::make_pair(userCode, curMsg);
- }
- else
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA42F1").setAPI(__FUNCTION__)("[RTA42F1]错误映射异常|(%s)", srcMsg.c_str());
- return std::make_pair(userCode, ErrMsgStruct("RTA42F1", CSimpleString::Format("[RTA42F1]错误映射异常|(%s)", srcMsg.c_str()).GetData(), userCodeStr));
- }
- }
- std::pair<unsigned long, std::string> splitStrToUserCodeAndErrMsg(std::string srcMsg)
- {
- const std::string headerStr = "UserError=";
- if (srcMsg.find(headerStr) != 0)
- return std::make_pair(0, srcMsg);
- unsigned long userCode = std::stoi(srcMsg.substr(headerStr.length()));
- std::string userCodeStr = CSimpleString::Format("0x%X", userCode).GetData();
- if (g_usercodeTranslateFile.length() == 0)
- return std::make_pair(userCode, srcMsg);
- try
- {
- boost::property_tree::ptree ptr, tag;
- boost::property_tree::ini_parser::read_ini(g_usercodeTranslateFile, ptr);
- tag = ptr.get_child("UserCodeToMsgTip");
- std::string tipMsg = tag.get<std::string>(userCodeStr);
- return std::make_pair(userCode, UtfToGbk(tipMsg.c_str()));
- }
- catch (std::exception &e) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("ini_parse failed, reason:%s", e.what());
- }
-
- return std::make_pair(userCode, srcMsg);
- }
- std::string hexdumpToString(const char* buf, const int num)
- {
- char str[8192 * 2] = { 0 };
- int i = 0;
- char c[5] = { 0 };
- if (num > 100)
- {
- for (i = 0; i < 50; i++)
- {
- sprintf(c, "%02X ", (unsigned char)buf[i]);
- strcat(str, c);
- }
- return CSimpleStringA::Format("buffer too long to show!show pre 50 hex! CSocketClient hex buf len = %d : %s", num, str).GetData();
- }
- for (i = 0; i < num; i++)
- {
- sprintf(c, "%02X ", (unsigned char)buf[i]);
- strcat(str, c);
- }
- return CSimpleStringA::Format("CSocketClient hex buf len = %d : %s", num, str).GetData();
- }
- void hexdump(const char* buf, const int num) {
- auto hexStr = hexdumpToString(buf, num);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)(hexStr.c_str());
- }
- bool modifyBySpecialStr(std::wstring& src)
- {
- #if 0
- clock_t cur = clock();
- std::set<wchar_t> srcArr;
- static std::set<wchar_t> compareArr;
- for (auto it = src.begin(); it != src.end(); it++)
- srcArr.insert(*it);
- if (compareArr.size() == 0)
- {
- for (auto it = specialStr.begin(); it != specialStr.end(); it++)
- compareArr.insert(*it);
- }
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("modifyBySpecialStr insert cost:%d", clock() - cur);
- cur = clock();
- std::set<wchar_t> result;
- std::set_intersection(std::begin(srcArr), std::end(srcArr), std::begin(compareArr), std::end(compareArr), std::inserter(result, std::begin(result)));
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("modifyBySpecialStr intersection cost:%d", clock() - cur);
- cur = clock();
- if (result.size() == 0)
- return false;
- for (auto it = result.begin(); it != result.end(); it++)
- {
- int pos = 0;
- for (int pos = 0; pos < src.length();)
- {
- pos = src.find(*it, pos);
- if (pos < 0)
- break;
- if (pos + 1 < src.length() && src[pos + 1] == '\\')
- src.erase(pos + 1, 1);
- else
- pos++;
- }
- }
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("modifyBySpecialStr modify cost:%d", clock() - cur);
- cur = clock();
- return true;
- #endif
- clock_t cur = clock();
- wchar_t specialone = L'碶';
- if (src.find(specialone, 0) == -1)
- return false;
- int pos = 0;
- for (int pos = 0; pos < src.length();)
- {
- pos = src.find(specialone, pos);
- if (pos < 0)
- break;
- if (pos + 1 < src.length() && src[pos + 1] == '\\')
- src.erase(pos + 1, 1);
- else
- pos++;
- }
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("modifyBySpecialStr modify cost:%d", clock() - cur);
- return true;
- }
- #include <boost/stacktrace.hpp>
- #if (defined _WIN32 || defined _WIN64)
- long WINAPI printSEG(struct _EXCEPTION_POINTERS* ExceptionInfo)
- #else
- long printSEG()
- #endif
- {
- auto dumpArr = boost::stacktrace::stacktrace().as_vector();
- if (dumpArr.size() > 20)
- {
- for (auto i = 0; i < 10; i++)
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("Pre SEG[%d]%X---%s(%s-%d)", i, dumpArr[i].address(), dumpArr[i].name().c_str(), dumpArr[i].source_file().c_str(), dumpArr[i].source_line());
- for (auto i = dumpArr.size() - 10; i < dumpArr.size(); i++)
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("Post SEG[%d]%X---%s(%s-%d)", i, dumpArr[i].address(), dumpArr[i].name().c_str(), dumpArr[i].source_file().c_str(), dumpArr[i].source_line());
- }
- else
- {
- for (auto i = 0; i < dumpArr.size(); i++)
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("SEG[%d]%X---%s(%s-%d)", i, dumpArr[i].address(), dumpArr[i].name().c_str(), dumpArr[i].source_file().c_str(), dumpArr[i].source_line());
- }
- return 0;
- }
- //singal,退出函数
- #if (defined _WIN32 || defined _WIN64)
- #else
- #include <signal.h> // ::signal, ::raise
- #include <boost/stacktrace.hpp>
- #include "CModTools.h"
- #include "CWebsocketServer.h"
- #include <winpr/sysinfo.h>
- #include <winpr/timezone.h>
- std::string g_backtracePath = "";
- void seg_signal_handler(int signum)
- {
- //boost::stacktrace::safe_dump_to(g_backtracePath.c_str());
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("receive signal:%d, seg_signal_handler", signum);
-
- printSEG();
- Chromium::CModTools::get_mutable_instance().killAllChromium();
- Chromium::CWebsocketServer::stopServer();
- signal(signum, SIG_DFL);
- raise(signum);
- }
- void normal_signal_handle(int signum)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("receive signal:%d, normal_signal_handle", signum);
- signal(signum, SIG_DFL);
- raise(signum);
- }
- void set_traceback_path(std::string path)
- {
- g_backtracePath = path + "/mod_chromium/" + generateTimeStr(true) + "_chromium_backtrace.dump";
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("set_traceback_path %s", g_backtracePath.c_str());
- }
- #endif
- void receivehexdump(const char* buf, const int num) {
- char str[8192 * 2] = { 0 };
- int i = 0;
- char c[5] = { 0 };
- if (num > 100)
- {
- for (i = 0; i < 50; i++)
- {
- sprintf(c, "%02X ", (unsigned char)buf[i]);
- strcat(str, c);
- }
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("buffer too long to show!show pre 50 hex! receivehexdump hex buf len = %d : %s", num, str);
- return;
- }
- for (i = 0; i < num; i++)
- {
- sprintf(c, "%02X ", (unsigned char)buf[i]);
- strcat(str, c);
- }
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("receivehexdump hex buf len = %d : %s", num, str);
- return;
- }
- void doWithDebugModeData(const char* strMethod, const char* buf)
- {
- boost::lock_guard<boost::mutex> lock(g_networkMutex);
- if(std::string(strMethod).find("Network.") == 0)
- {
- /*for example
- {
- "method": "Network.requestWillBeSent",
- "params": {
- "documentURL": "https://www.btbtt12.com/",
- "frameId": "8F58093A23334B311DB645BA3652E63C",
- "hasUserGesture": false,
- "initiator": {
- "type": "other"
- },
- "loaderId": "9F7B28B896C791554C69C5985CA92E79",
- "request": {
- "headers": {
- "Referer": "https://www.btbtt12.com/",
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36"
- },
- "initialPriority": "Low",
- "method": "GET",
- "mixedContentType": "none",
- "referrerPolicy": "no-referrer-when-downgrade",
- "url": "https://pic.picnewsss.com/tu-2022290039/960-60.gif"
- },
- "requestId": "18476.34",
- "timestamp": 19338.811603,
- "type": "Image",
- "wallTime": 1666099893.800733
- }
- }
- */
- std::shared_ptr<cJSON> pJson(cJSON_Parse(buf), [](cJSON* p) {
- if (nullptr != p)
- cJSON_Delete(p);
- });
- auto paramsItem = cJSON_GetObjectItem(pJson.get(), "params");
- if (paramsItem == nullptr)
- return;
- auto requestIdItem = cJSON_GetObjectItem(paramsItem, "requestId");
- if (requestIdItem == nullptr)
- return;
- std::string requestId_str = requestIdItem->valuestring;
- /*
- ['Network.loadingFailed', 'Network.loadingFinished', 'Network.resourceChangedPriority',
- 'Network.requestServedFromCache', 'Network.requestWillBeSent', 'Network.requestWillBeSentExtraInfo',
- 'Network.responseReceived', 'Network.responseReceivedExtraInfo', 'Network.dataReceived',
- 'Page.frameAttached', 'Page.frameRequestedNavigation', 'Page.frameStoppedLoading',
- 'Page.frameClearedScheduledNavigation', 'Page.loadEventFired', 'Page.frameStartedLoading',
- 'Page.frameDetached', 'Page.frameScheduledNavigation', 'Page.frameNavigated', 'Page.frameResized',
- 'Page.domContentEventFired']
-
- */
- if(std::string(strMethod) == "Network.loadingFinished")
- {
- if (g_networkParse.find(requestId_str) != g_networkParse.end())
- g_networkParse.erase(requestId_str);
- if (g_networkExpiredData.find(requestId_str) != g_networkExpiredData.end())
- g_networkExpiredData.erase(requestId_str);
- if (g_networkExpiredData.size() < 30)
- return;
- for(auto it = g_networkExpiredData.begin(); it != g_networkExpiredData.end();)
- {
- if((clock() - it -> second) < 100000)
- {
- it++;
- continue;
- }
- if (g_networkParse.find(it->first) != g_networkParse.end())
- g_networkParse.erase(it->first);
- g_networkExpiredData.erase(it++);
- }
- }
- else if(std::string(strMethod) == "Network.loadingFailed"
- || std::string(strMethod) == "Network.webSocketFrameError"
- || std::string(strMethod) == "Network.requestServedFromCache")
- {
- if (g_networkParse.find(requestId_str) != g_networkParse.end())
- {
- for(auto it = g_networkParse[requestId_str].begin(); it != g_networkParse[requestId_str].end(); it++)
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402402Z00001").setResultMsg(it->c_str())();
- g_networkParse.erase(requestId_str);
- }
- else//此时,上一轮记录已结束
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402402Z00001").setResultMsg(buf)();
- if (g_networkExpiredData.find(requestId_str) != g_networkExpiredData.end())
- g_networkExpiredData.erase(requestId_str);
- }
- else
- {
- if (g_networkParse.find(requestId_str) != g_networkParse.end())
- g_networkParse[requestId_str].push_back(buf);
- else
- {
- std::vector<std::string> tmp;
- tmp.push_back(buf);
- g_networkParse[requestId_str] = tmp;
- g_networkExpiredData[requestId_str] = clock();
- }
- }
- }
- if (std::string(strMethod) == "Network.webSocketFrameError" ||
- std::string(strMethod) == "Network.loadingFailed" ||
- std::string(strMethod) == "Runtime.exceptionThrown")
- {
- LogWarn(Severity_Middle, Error_Debug, LOG_WARN_CHROMIUM_OPENWEBWARN, buf);
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402402Z00002").setResultMsg(buf)();
- }
-
- }
- std::pair<bool, CSimpleStringA> json_deal::getStringFromCjsonObj(void* object, const char* name)
- {
- if (object == NULL)
- return std::make_pair(false, "");
- auto curNode = cJSON_GetObjectItem((cJSON*)object, name);
- if (curNode && curNode->type == cJSON_String) {
- return std::make_pair(true, curNode->valuestring);
- }
- else
- return std::make_pair(false, "");
- }
- std::pair<bool, int> json_deal::getIntergerFromCjsonObj(void* object, const char* name)
- {
- if (object == NULL)
- return std::make_pair(false, 0);
- auto curNode = cJSON_GetObjectItem((cJSON*)object, name);
- if (curNode && curNode->type == cJSON_Number) {
- return std::make_pair(true, curNode->valueint);
- }
- else
- return std::make_pair(false, 0);
- }
- std::pair<bool, double> json_deal::getDoubleFromCjsonObj(void* object, const char* name)
- {
- if (object == NULL)
- return std::make_pair(false, 0);
- auto curNode = cJSON_GetObjectItem((cJSON*)object, name);
- if (curNode && curNode->type == cJSON_Number) {
- return std::make_pair(true, curNode->valuedouble);
- }
- else
- return std::make_pair(false, 0);
- }
- SM2_Encrypt_Manager::SM2_Encrypt_Manager()
- :m_public_key_buf_len(DEFAULT_KEY_LEN),
- m_private_key_buf_len(DEFAULT_KEY_LEN),
- m_opposite_public_key_buf_len(DEFAULT_KEY_LEN)
- {
- memset(m_public_key_buf, 0, DEFAULT_KEY_LEN);
- memset(m_private_key_buf, 0, DEFAULT_KEY_LEN);
- memset(m_opposite_public_key_buf, 0, DEFAULT_KEY_LEN);
- GenerateSM2_key(m_public_key, m_private_key);
- m_state = SM2ProtocolState::WAIT_KEY_EXCHANGE;
- }
- SM2_Encrypt_Manager::~SM2_Encrypt_Manager()
- {
- }
- bool SM2_Encrypt_Manager::GenerateSM2_key(std::string& pub, std::string& pri)
- {
- if (!::CreateSM2KeyPair(m_public_key_buf, &m_public_key_buf_len, m_private_key_buf, &m_private_key_buf_len))
- return false;
- pub = binToHex(m_public_key_buf, m_public_key_buf_len);
- pri = binToHex(m_private_key_buf, m_private_key_buf_len);
- return true;
- }
- std::string SM2_Encrypt_Manager::binToHex(const unsigned char* data, int len)
- {
- std::string hexString;
- // 使用 boost::algorithm::hex 进行编码
- boost::algorithm::hex(data, data + len, std::back_inserter(hexString));
- return hexString;
- }
- void SM2_Encrypt_Manager::hexToBin(const std::string& hexStr, unsigned char* binData, int& binLen)
- {
- binLen = hexStr.size() / 2;
- if (binData == nullptr) {
- // 如果 binData 为 nullptr,仅返回计算出的 binLen,不执行实际的转换
- return;
- }
- // 使用 boost::algorithm::unhex 进行解码
- boost::algorithm::unhex(hexStr.begin(), hexStr.end(), binData);
- }
- void SM2_Encrypt_Manager::setOpposite(const std::string pub)
- {
- m_opposite_public_key = pub;
- hexToBin(m_opposite_public_key, m_opposite_public_key_buf, m_opposite_public_key_buf_len);
- }
- std::pair<bool, std::string> SM2_Encrypt_Manager::checkSM2Enable()
- {
- if (m_public_key.length() == 0)
- return std::make_pair(false, "public_key is empty");
- if (m_private_key.length() == 0)
- return std::make_pair(false, "private_key is empty");
- if (m_opposite_public_key.length() == 0)
- return std::make_pair(false, "opposite public_key is empty");
- return std::make_pair(true, "");
- }
- std::pair<std::string, std::string> SM2_Encrypt_Manager::EncryptMsg(std::string msg)
- {
- unsigned char sign[DEFAULT_KEY_LEN] = "";
- int sign_len = DEFAULT_KEY_LEN;
- unsigned char* dstMsg = new unsigned char[msg.length() * 2];
- int dstMsgLen = msg.length() * 2;
- std::shared_ptr<void> msgClean((void*)0, [&](void*) {
- if (dstMsg)
- {
- delete[]dstMsg;
- dstMsg = nullptr;
- }
-
- });
- if (!SM2SignWithSM3(m_private_key_buf, m_private_key_buf_len, (unsigned char*)msg.c_str(), msg.length(), sign, &sign_len))
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("SM2SignWithSM3::err, can not sign msg");
- return std::make_pair("", "");
- }
- if(!EncWithSM2PubKey((unsigned char*)msg.c_str(), msg.length(), dstMsg, &dstMsgLen, m_opposite_public_key_buf, m_opposite_public_key_buf_len))
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("EncWithSM2PubKey::err, can not encrypt msg");
- return std::make_pair("", "");
- }
- return std::make_pair(binToHex(sign, sign_len), binToHex(dstMsg, dstMsgLen));
- }
- std::pair<bool, std::string> SM2_Encrypt_Manager::DecryptMsg(std::string sign, std::string msg)
- {
- unsigned char* binMsg = new unsigned char[msg.length()], *outMsg = new unsigned char[msg.length() * 2], *binSign = new unsigned char[sign.length()];//normally, it is half length of msg
- int binMsgLen = msg.length(), outMsgLen = msg.length() * 2, signLen = sign.length();
- std::shared_ptr<void> msgClean((void*)0, [&](void*) {
- if (binMsg) {
- delete[] binMsg;
- binMsg = nullptr;
- }
- if (outMsg) {
- delete[] outMsg;
- outMsg = nullptr;
- }
- if (binSign) {
- delete[] binSign;
- binSign = nullptr;
- }
- });
- hexToBin(msg, binMsg, binMsgLen);
- hexToBin(sign, binSign, signLen);
- if (!DecWithSM2PriKey(binMsg, binMsgLen, outMsg, &outMsgLen, m_private_key_buf, m_private_key_buf_len))
- return std::make_pair(false, "DecWithSM2PriKey::err, can not dectrypt msg");
- if (!SM2VerifyWithSM3(m_opposite_public_key_buf, m_opposite_public_key_buf_len, outMsg, outMsgLen, binSign, signLen))
- return std::make_pair(false, "SM2VerifyWithSM3::err, can not verify sign");
- return std::make_pair(true, (char*)outMsg);
- }
- std::pair<bool, std::string> SM2_Encrypt_Manager::GenerateEncPubKey()
- {
- if(!verifySM2Manager())
- return std::make_pair(false, "GenerateEncPubKey::verifySM2Manager err");
- unsigned char encPubKey[DEFAULT_KEY_LEN] = "";
- int encPubKey_len = DEFAULT_KEY_LEN;
- if(!EncWithSM2PubKey(m_public_key_buf, m_public_key_buf_len, encPubKey, &encPubKey_len, m_opposite_public_key_buf, m_opposite_public_key_buf_len))
- return std::make_pair(false, "GenerateEncPubKey::EncWithSM2PubKey err");
- return std::make_pair(true, binToHex(encPubKey, encPubKey_len));
- }
- bool SM2_Encrypt_Manager::verifySM2Manager()
- {
- if (m_opposite_public_key.length() == 0 || m_public_key.length() == 0 || m_private_key.length() == 0)
- return false;
- if (m_opposite_public_key_buf == NULL || m_public_key_buf == NULL || m_private_key_buf == NULL)
- return false;
- return true;
- }
- #ifdef RVC_OS_LINUX
- std::vector<int> getUosBrowserPIDs(int UseUOSBrowser)
- {
- std::vector<int> pids;
- FILE* fp = nullptr;
- if(UseUOSBrowser == 1)
- fp = popen("ps -ef | grep uosbrowser | grep -v grep | awk '{print $2}'", "r");
- else if(UseUOSBrowser == 2)
- fp = popen("ps -ef | grep browser | grep -v grep | awk '{print $2}'", "r");
- if (fp) {
- char buffer[256];
- while (fgets(buffer, sizeof(buffer), fp) != NULL) {
- pids.push_back(static_cast<pid_t>(std::atoi(buffer)));
- }
- pclose(fp);
- }
- return pids;
- }
- #endif
- ConfigManager& ConfigManager::getInstance() {
- static ConfigManager instance;
- return instance;
- }
- ConfigManager::ConfigManager()
- : m_iTcpBridgePort(4504), m_strCustomMainUrl(""), m_strCustomAdUrl(""), m_runAd(false), m_runMain(false), m_runExtend(false), m_runLogin(false), m_withBrowser(false), m_withMin(false), m_withClose(false)
- , m_withDebugMode(false), m_withMagic(false), m_withNoFileLog(false), m_installMode(false), m_withMedia(false), m_withSpecialTest(false), m_withConsole(false),
- m_withLinkLog(false), m_withUnsafeAd(false), m_noStartupPage(false), m_extension_debugOpen(false), m_extension_withTerminal(false)
- {
- void* logProducer = nullptr;
- std::map<std::string, void*> g_logProducerArr;
- bool g_useMagic = false;
- bool g_loggerInitSuccess = false;
- bool g_withSpecialTest = false;
- bool g_hasInitCfg = false;//can discard
- int g_sogouForce = 0;
- m_extensionPath = "";
- }
- LogManager& LogManager::getInstance() {
- static LogManager instance;
- return instance;
- }
- void LogManager::logWebSocketBuild(int64_t hdl, const std::string& url, const std::string& isSecurity) {
- Json::Value log;
- log["hdl"] = hdl;
- log["78173721_logType"] = "ws_build";
- Json::Value detail;
- detail["url"] = url;
- detail["isSecurity"] = isSecurity;
- log["detail"] = detail;
- log["timestamp"] = getCurrentTimestamp();
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- writeLog(log);
- }
- void LogManager::writeLog(const Json::Value& log) {
- Json::FastWriter writer;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)(writer.write(log).c_str());
- }
- std::string LogManager::getCurrentTimestamp() {
- /*
- FILETIME ft;
- SYSTEMTIME st;
- GetSystemTime(&st);
- SystemTimeToFileTime(&st, &ft);
- FILETIME utc_ft, local_ft;
- #ifdef _WIN32
- utc_ft.dwLowDateTime = (DWORD)ft.dwLowDateTime;
- utc_ft.dwHighDateTime = (DWORD)ft.dwHighDateTime;
- FileTimeToLocalFileTime(&utc_ft, &local_ft);
- FileTimeToSystemTime(&local_ft, &st);
- #else
- GetLocalTime(&st);
- #endif // _WIN32
- */
- using namespace std::chrono;
- auto now = system_clock::now();
- auto ms = duration_cast<milliseconds>(now.time_since_epoch()) % 1000;
- auto timer = system_clock::to_time_t(now);
- std::ostringstream oss;
- oss << std::put_time(std::localtime(&timer), "%Y-%m-%d %H:%M:%S")
- << '.' << std::setfill('0') << std::setw(3) << ms.count();
- return oss.str();
- }
- void LogManager::logWebSocketBeginSession(int64_t hdl,
- int64_t web_transID,
- int64_t inner_transID,
- const std::string& entity,
- const std::string& entityClass,
- int ret,
- const std::string& operate,
- const std::string& payload,
- int retDetail,
- const std::string& reason) {
- Json::Value log;
- log["hdl"] = hdl;
- log["78173721_logType"] = "ws_beginSession";
- Json::Value detail;
- detail["web_transID"] = web_transID;
- detail["inner_transID"] = inner_transID;
- detail["entity"] = entity;
- detail["class"] = entityClass;
- detail["ret"] = ret;
- detail["retDetail"] = retDetail;
- detail["reason"] = reason;
- detail["operate"] = operate;
- #ifdef OUTPUT_DETAIL_LOG
- detail["payload"] = payload;
- #endif
- log["detail"] = detail;
- log["timestamp"] = getCurrentTimestamp();
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- writeLog(log);
- }
- void LogManager::logWebSocketClose(int64_t hdl) {
- Json::Value log;
- log["hdl"] = hdl;
- log["78173721_logType"] = "ws_close";
- log["timestamp"] = getCurrentTimestamp();
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- writeLog(log);
- }
- void LogManager::logWebSocketInfo(int64_t hdl,
- int64_t web_transID,
- int64_t sessionId,
- const std::string& entity,
- const std::string& function,
- int ret,
- const std::string& operate,
- int retDetail,
- const std::string& reason,
- const std::string& payload) {
- Json::Value log;
- log["hdl"] = Json::Int64(hdl);
- log["78173721_logType"] = "ws_info";
- Json::Value detail;
- detail["web_transID"] = Json::Int64(web_transID);
- detail["sessionId"] = Json::Int64(sessionId);
- detail["entity"] = entity;
- detail["function"] = function;
- detail["ret"] = ret;
- detail["operate"] = operate;
- detail["retDetail"] = retDetail;
- detail["reason"] = reason;
- #ifdef OUTPUT_DETAIL_LOG
- detail["payload"] = payload;
- #endif
- log["detail"] = detail;
- log["timestamp"] = getCurrentTimestamp();
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- writeLog(log);
- }
- void LogManager::logWebSocketRegister(int64_t hdl,
- int64_t web_transID,
- int64_t inner_transID,
- const std::string& entity,
- const std::string& entityClass,
- int ret,
- const std::string& operate,
- const std::string& payload,
- int retDetail,
- const std::string& reason) {
- Json::Value log;
- log["hdl"] = Json::Int64(hdl);
- log["78173721_logType"] = "ws_register";
- Json::Value detail;
- detail["web_transID"] = Json::Int64(web_transID);
- detail["inner_transID"] = Json::Int64(inner_transID);
- detail["entity"] = entity;
- detail["class"] = entityClass;
- detail["ret"] = ret;
- detail["operate"] = operate;
- #ifdef OUTPUT_DETAIL_LOG
- detail["payload"] = payload;
- #endif
- detail["retDetail"] = retDetail;
- detail["reason"] = reason;
- log["detail"] = detail;
- log["timestamp"] = getCurrentTimestamp();
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- writeLog(log);
- }
- void LogManager::logWebSocketRequest(int64_t hdl,
- int64_t web_transID,
- int64_t inner_transID,
- int64_t sessionId,
- const std::string& entity,
- const std::string& function,
- int ret,
- const std::string& operate,
- const std::string& payload,
- int retDetail,
- const std::string& reason) {
- Json::Value log;
- log["hdl"] = Json::Int64(hdl);
- log["78173721_logType"] = "ws_request";
- Json::Value detail;
- detail["web_transID"] = Json::Int64(web_transID);
- detail["inner_transID"] = Json::Int64(inner_transID);
- detail["sessionId"] = Json::Int64(sessionId);
- detail["entity"] = entity;
- detail["function"] = function;
- detail["ret"] = ret;
- detail["operate"] = operate;
- detail["retDetail"] = retDetail;
- detail["reason"] = reason;
- #ifdef OUTPUT_DETAIL_LOG
- detail["payload"] = payload;
- #endif
- log["detail"] = detail;
- log["timestamp"] = getCurrentTimestamp();
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- writeLog(log);
- }
- void LogManager::logWebSocketSetVar(int64_t hdl,
- int64_t web_transID,
- int64_t inner_transID,
- const std::string& name,
- const std::string& value,
- int ret,
- const std::string& operate,
- const std::string& payload,
- int retDetail,
- const std::string& reason) {
- Json::Value log;
- log["hdl"] = Json::Int64(hdl);
- log["78173721_logType"] = "ws_setvar";
- Json::Value detail;
- detail["web_transID"] = Json::Int64(web_transID);
- detail["inner_transID"] = Json::Int64(inner_transID);
- detail["name"] = name;
- detail["value"] = value;
- detail["ret"] = ret;
- detail["operate"] = operate;
- detail["retDetail"] = retDetail;
- detail["reason"] = reason;
- #ifdef OUTPUT_DETAIL_LOG
- detail["payload"] = payload;
- #endif
- log["detail"] = detail;
- log["timestamp"] = getCurrentTimestamp();
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- writeLog(log);
- }
- void LogManager::logWebSocketGetVar(int64_t hdl,
- int64_t web_transID,
- int64_t inner_transID,
- const std::string& name,
- int ret,
- const std::string& operate,
- const std::string& payload,
- int retDetail,
- const std::string& reason) {
- Json::Value log;
- log["hdl"] = Json::Int64(hdl);
- log["78173721_logType"] = "ws_getvar";
- Json::Value detail;
- detail["web_transID"] = Json::Int64(web_transID);
- detail["inner_transID"] = Json::Int64(inner_transID);
- detail["name"] = name;
- detail["ret"] = ret;
- detail["operate"] = operate;
- detail["retDetail"] = retDetail;
- detail["reason"] = reason;
- #ifdef OUTPUT_DETAIL_LOG
- detail["payload"] = payload;
- #endif
- log["detail"] = detail;
- log["timestamp"] = getCurrentTimestamp();
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- writeLog(log);
- }
- void LogManager::logWebSocketBroadcast(int64_t hdl,
- const std::string& entity,
- int ret,
- const std::string& operate,
- const std::string& payload,
- int retDetail,
- const std::string& reason) {
- Json::Value log;
- log["hdl"] = Json::Int64(hdl);
- log["78173721_logType"] = "ws_broadcast";
- Json::Value detail;
- detail["entity"] = entity;
- detail["ret"] = ret;
- detail["operate"] = operate;
- detail["retDetail"] = retDetail;
- detail["reason"] = reason;
- #ifdef OUTPUT_DETAIL_LOG
- detail["payload"] = payload;
- #endif
- log["detail"] = detail;
- log["timestamp"] = getCurrentTimestamp();
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- writeLog(log);
- }
- void LogManager::logVtmEndSession(int64_t hdl,
- const std::string& entity,
- int64_t sessionId,
- int ret,
- const std::string& operate,
- const std::string& payload,
- int retDetail,
- const std::string& reason) {
- Json::Value log;
- log["hdl"] = Json::Int64(hdl);
- log["78173721_logType"] = "vtm_endsession";
- Json::Value detail;
- detail["entity"] = entity;
- detail["sessionId"] = Json::Int64(sessionId);
- detail["ret"] = ret;
- detail["operate"] = operate;
- detail["retDetail"] = retDetail;
- detail["reason"] = reason;
- #ifdef OUTPUT_DETAIL_LOG
- detail["payload"] = payload;
- #endif
- log["detail"] = detail;
- log["timestamp"] = getCurrentTimestamp();
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- writeLog(log);
- }
- void LogManager::logVtmRequestAck(int64_t hdl,
- int64_t web_transID,
- int64_t inner_transID,
- int64_t sessionId,
- const std::string& entity,
- const std::string& function,
- int ret,
- const std::string& operate,
- const std::string& payload,
- const std::string& srcByte,
- int retDetail,
- const std::string& reason) {
- Json::Value log;
- log["hdl"] = Json::Int64(hdl);
- log["78173721_logType"] = "vtm_requestAck";
- Json::Value detail;
- detail["web_transID"] = Json::Int64(web_transID);
- detail["inner_transID"] = Json::Int64(inner_transID);
- detail["sessionId"] = Json::Int64(sessionId);
- detail["entity"] = entity;
- detail["function"] = function;
- detail["ret"] = ret;
- detail["operate"] = operate;
- #ifdef OUTPUT_DETAIL_LOG
- detail["payload"] = payload;
- detail["srcByte"] = srcByte;
- #endif
- detail["retDetail"] = retDetail;
- detail["reason"] = reason;
- log["detail"] = detail;
- log["timestamp"] = getCurrentTimestamp();
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- writeLog(log);
- }
- void LogManager::logVtmEvent(int64_t hdl,
- int64_t inner_transID,
- int64_t sessionId,
- const std::string& entity,
- int ret,
- const std::string& operate,
- const std::vector<std::pair<int, int>>& transIdAndhdl_arr,
- const std::string& payload,
- const std::string& srcByte,
- int retDetail,
- const std::string& reason) {
- Json::Value log;
- log["hdl"] = Json::Int64(hdl);
- log["78173721_logType"] = "vtm_event";
- Json::Value detail;
- detail["inner_transID"] = Json::Int64(inner_transID);
- detail["sessionId"] = Json::Int64(sessionId);
- detail["entity"] = entity;
- detail["ret"] = ret;
- detail["operate"] = operate;
- Json::Value transIdAndhdl_json(Json::arrayValue);
- for (const auto& pair : transIdAndhdl_arr) {
- Json::Value pairJson(Json::objectValue);
- pairJson["transId"] = Json::Int64(pair.first);
- pairJson["hdl"] = Json::Int64(pair.second);
- transIdAndhdl_json.append(pairJson);
- }
- detail["transIdAndhdl_arr"] = transIdAndhdl_json;
- #ifdef OUTPUT_DETAIL_LOG
- detail["payload"] = payload;
- detail["srcByte"] = srcByte;
- #endif
- detail["retDetail"] = retDetail;
- detail["reason"] = reason;
- log["detail"] = detail;
- log["timestamp"] = getCurrentTimestamp();
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- writeLog(log);
- }
- void LogManager::logVtmSessionAck(int64_t hdl,
- int64_t web_transID,
- int64_t inner_transID,
- int64_t sessionId,
- const std::string& entity,
- int ret,
- const std::string& operate,
- const std::string& payload,
- const std::string& srcByte,
- int retDetail,
- const std::string& reason) {
- Json::Value log;
- log["hdl"] = Json::Int64(hdl);
- log["78173721_logType"] = "vtm_sessionAck";
- Json::Value detail;
- detail["web_transID"] = Json::Int64(web_transID);
- detail["inner_transID"] = Json::Int64(inner_transID);
- detail["sessionId"] = Json::Int64(sessionId);
- detail["entity"] = entity;
- detail["ret"] = ret;
- detail["operate"] = operate;
- #ifdef OUTPUT_DETAIL_LOG
- detail["payload"] = payload;
- detail["srcByte"] = srcByte;
- #endif
- detail["retDetail"] = retDetail;
- detail["reason"] = reason;
- log["detail"] = detail;
- log["timestamp"] = getCurrentTimestamp();
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- writeLog(log);
- }
- void LogManager::logWsLogEvent(
- int64_t hdl,
- int securityLevel,
- int eventCode,
- const std::string& message,
- int ret,
- const std::string& operate,
- const std::string& payload,
- int retDetail,
- const std::string& reason
- ) {
- Json::Value log;
- log["hdl"] = Json::Int64(hdl);
- log["78173721_logType"] = "ws_logEvent";
- Json::Value detail;
- detail["securityLevel"] = securityLevel;
- detail["eventCode"] = eventCode;
- detail["message"] = message;
- detail["ret"] = ret;
- detail["operate"] = operate;
- detail["retDetail"] = retDetail;
- detail["reason"] = reason;
- #ifdef OUTPUT_DETAIL_LOG
- detail["payload"] = payload;
- #endif
- log["detail"] = detail;
- log["timestamp"] = getCurrentTimestamp();
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- writeLog(log);
- }
- void LogManager::logWsLogWarn(
- int64_t hdl,
- int securityLevel,
- int eventCode,
- const std::string& message,
- int ret,
- const std::string& operate,
- const std::string& payload,
- int retDetail,
- const std::string& reason
- ) {
- Json::Value log;
- log["hdl"] = Json::Int64(hdl);
- log["78173721_logType"] = "ws_logWarn";
- Json::Value detail;
- detail["securityLevel"] = securityLevel;
- detail["eventCode"] = eventCode;
-
- detail["ret"] = ret;
- detail["operate"] = operate;
- detail["retDetail"] = retDetail;
- detail["reason"] = reason;
- #ifdef OUTPUT_DETAIL_LOG
- detail["payload"] = payload;
- detail["message"] = message;
- #endif
- log["detail"] = detail;
- log["timestamp"] = getCurrentTimestamp();
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- writeLog(log);
- }
- void LogManager::logEntityOnLog(
- const std::string& entity,
- int64_t usercode,
- const std::string& usercodeStr,
- int ret,
- const std::string& operate,
- int retDetail,
- const std::string& reason
- ) {
- Json::Value log;
- log["78173721_logType"] = "entity_onlog";
- Json::Value detail;
- detail["entity"] = entity;
- detail["usercode"] = Json::Int64(usercode);
- detail["usercodeStr"] = usercodeStr;
- detail["ret"] = ret;
- detail["operate"] = operate;
- detail["retDetail"] = retDetail;
- detail["reason"] = reason;
- log["detail"] = detail;
- log["timestamp"] = getCurrentTimestamp();
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- writeLog(log);
- }
- void LogManager::logEntityBegin(int no_startup) {
- Json::Value log;
- log["78173721_logType"] = "entity_begin";
- Json::Value detail;
- detail["no_startup"] = no_startup;
- log["detail"] = detail;
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- log["timestamp"] = getCurrentTimestamp();
- writeLog(log);
- }
- void LogManager::logEntityOpenPage(
- const std::string& pageType,
- int64_t pid,
- int ret,
- const std::string& operate,
- int retDetail,
- const std::string& reason
- ) {
- Json::Value log;
- log["78173721_logType"] = "entity_openPage";
- Json::Value detail;
- detail["pageType"] = pageType;
- detail["pid"] = Json::Int64(pid);
- detail["ret"] = ret;
- detail["operate"] = operate;
- detail["retDetail"] = retDetail;
- detail["reason"] = reason;
- log["detail"] = detail;
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- log["timestamp"] = getCurrentTimestamp();
- writeLog(log);
- }
- void LogManager::logEntityStageChange(
- const std::string& stage,
- int ret,
- const std::string& operate,
- int retDetail,
- const std::string& reason
- ) {
- Json::Value log;
- log["78173721_logType"] = "entity_stageChange";
- Json::Value detail;
- detail["stage"] = stage;
- detail["ret"] = ret;
- detail["operate"] = operate;
- detail["retDetail"] = retDetail;
- detail["reason"] = reason;
- log["detail"] = detail;
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- log["timestamp"] = getCurrentTimestamp();
- writeLog(log);
- }
- void LogManager::logEntityStatus(
- const std::string& status,
- int level,
- int ret,
- const std::string& operate,
- int retDetail,
- const std::string& reason
- ) {
- Json::Value log;
- log["78173721_logType"] = "entity_status";
- Json::Value detail;
- detail["status"] = status;
- detail["level"] = level;
- detail["ret"] = ret;
- detail["operate"] = operate;
- detail["retDetail"] = retDetail;
- detail["reason"] = reason;
- log["detail"] = detail;
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- log["timestamp"] = getCurrentTimestamp();
- writeLog(log);
- }
|