1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660 |
- #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("RTA42F1", CSimpleString::Format("[RTA42F1]错误映射异常|(%s)", srcMsg.c_str()).GetData(), ""));
- 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 + 97];
- int dstMsgLen = msg.length() * 2 + 97;
- 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, sign_len:%d", sign_len);
- 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, m_opposite_public_key_buf_len: %d", m_opposite_public_key_buf_len);
- 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) {
- const char* type = "ws_build";
- Json::Value log;
- log["hdl"] = Json::Int64(hdl);
- log["78173721_logType"] = type;
- m_logTotal[hdl][type].num += 1;
- Json::Value detail;
- detail["url"] = url;
- detail["isSecurity"] = isSecurity;
- log["detail"] = detail;
- log["timestamp"] = getCurrentTimestamp();
- if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
- log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- writeLog(LOG_LEVEL_DEBUG, log);
- }
- void LogManager::writeLog(LOG_LEVEL_E level, const Json::Value& log) {
- Json::FastWriter writer;
- DbgWithLink(level, 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) {
- const char* type = "ws_beginSession";
- Json::Value log;
- log["hdl"] = Json::Int64(hdl);
- log["78173721_logType"] = type;
- m_logTotal[hdl][type].num += 1;
- 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();
- if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
- log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- writeLog(LOG_LEVEL_DEBUG, log);
- }
- void LogManager::logWebSocketClose(int64_t hdl) {
- const char* type = "ws_close";
- Json::Value log;
- log["hdl"] = Json::Int64(hdl);
- log["78173721_logType"] = type;
- m_logTotal[hdl][type].num += 1;
- log["timestamp"] = getCurrentTimestamp();
- if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
- log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- Json::Value root(Json::objectValue);
- if (m_logTotal.find(hdl) != m_logTotal.end())
- {
- // 遍历 map
- for (const auto& pair : m_logTotal[hdl]) {
- std::string key = pair.first;
- const LogInfo& logInfo = pair.second;
- root[key] = logInfo.num;
- }
- log["dealed"] = root;
- m_logTotal.erase(hdl);
- }
-
- writeLog(LOG_LEVEL_INFO, 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) {
- const char* type = "ws_info";
- Json::Value log;
- log["hdl"] = Json::Int64(hdl);
- log["78173721_logType"] = type;
- m_logTotal[hdl][type].num += 1;
- 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();
- if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
- log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- writeLog(LOG_LEVEL_DEBUG, 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) {
- const char* type = "ws_register";
- Json::Value log;
- log["hdl"] = Json::Int64(hdl);
- log["78173721_logType"] = type;
- m_logTotal[hdl][type].num += 1;
- 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();
- if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
- log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- writeLog(LOG_LEVEL_DEBUG, 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) {
- const char* type = "ws_request";
- Json::Value log;
- log["hdl"] = Json::Int64(hdl);
- log["78173721_logType"] = type;
- m_logTotal[hdl][type].num += 1;
- 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();
- if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
- log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- writeLog(LOG_LEVEL_DEBUG, 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) {
- const char* type = "ws_setvar";
- Json::Value log;
- log["hdl"] = Json::Int64(hdl);
- log["78173721_logType"] = type;
- m_logTotal[hdl][type].num += 1;
- 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();
- if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
- log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- writeLog(LOG_LEVEL_DEBUG, 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) {
- const char* type = "ws_getvar";
- Json::Value log;
- log["hdl"] = Json::Int64(hdl);
- log["78173721_logType"] = type;
- m_logTotal[hdl][type].num += 1;
- 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();
- if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
- log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- writeLog(LOG_LEVEL_DEBUG, 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) {
- const char* type = "ws_broadcast";
- Json::Value log;
- log["hdl"] = Json::Int64(hdl);
- log["78173721_logType"] = type;
- m_logTotal[hdl][type].num += 1;
- 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();
- if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
- log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- writeLog(LOG_LEVEL_DEBUG, 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) {
- const char* type = "vtm_endsession";
- Json::Value log;
- log["hdl"] = Json::Int64(hdl);
- log["78173721_logType"] = type;
- m_logTotal[hdl][type].num += 1;
- 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();
- if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
- log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- writeLog(LOG_LEVEL_DEBUG, 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) {
- const char* type = "vtm_requestAck";
- Json::Value log;
- log["hdl"] = Json::Int64(hdl);
- log["78173721_logType"] = type;
- m_logTotal[hdl][type].num += 1;
- 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();
- if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
- log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- writeLog(LOG_LEVEL_DEBUG, 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) {
- const char* type = "vtm_event";
- Json::Value log;
- log["hdl"] = Json::Int64(hdl);
- log["78173721_logType"] = type;
- m_logTotal[hdl][type].num += 1;
- 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();
- if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
- log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- writeLog(LOG_LEVEL_DEBUG, 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) {
- const char* type = "vtm_sessionAck";
- Json::Value log;
- log["hdl"] = Json::Int64(hdl);
- log["78173721_logType"] = type;
- m_logTotal[hdl][type].num += 1;
- 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();
- if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
- log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- writeLog(LOG_LEVEL_DEBUG, 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
- ) {
- const char* type = "ws_logEvent";
- Json::Value log;
- log["hdl"] = Json::Int64(hdl);
- log["78173721_logType"] = type;
- m_logTotal[hdl][type].num += 1;
- 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();
- if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
- log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- writeLog(LOG_LEVEL_DEBUG, 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
- ) {
- const char* type = "ws_logWarn";
- Json::Value log;
- log["hdl"] = Json::Int64(hdl);
- log["78173721_logType"] = type;
- m_logTotal[hdl][type].num += 1;
- 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();
- if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
- log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
- log["threadId"] = Json::Int64(GetCurrentThreadId());
- writeLog(LOG_LEVEL_DEBUG, 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_LEVEL_INFO, 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_LEVEL_INFO, 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_LEVEL_INFO, 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_LEVEL_INFO, 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_LEVEL_INFO, log);
- }
|