baseEx.cpp 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660
  1. #include "stdafx.h"
  2. #include "baseEx.h"
  3. #include <stdint.h>
  4. #include <iostream>
  5. #include <vector>
  6. #include <map>
  7. #include <boost/xpressive/xpressive_dynamic.hpp>
  8. #include <boost/algorithm/string.hpp>
  9. #include <boost/filesystem.hpp>
  10. #include <boost/chrono.hpp>
  11. #include <boost/interprocess/ipc/message_queue.hpp>
  12. #include <boost/interprocess/permissions.hpp>
  13. #include <boost/thread/mutex.hpp>
  14. #include <boost/thread/lock_guard.hpp>
  15. #include <boost/algorithm/hex.hpp>
  16. #include "winpr/sysinfo.h"
  17. #include "winpr/timezone.h"
  18. #include "EventCode.h"
  19. #include "exLog/log.h"
  20. #include "cJSON.h"
  21. #include "RVCComm.h"
  22. using namespace boost::interprocess;
  23. //read ini
  24. #include <boost/property_tree/ptree.hpp>
  25. #include <boost/property_tree/ini_parser.hpp>
  26. #if (defined _WIN32 || defined _WIN64)
  27. #define BOOST_INTERPROCESS_SHARED_DIR_PATH "C:\\"
  28. #else
  29. #include <sys/types.h>
  30. #include <unistd.h>
  31. #include <cstring>
  32. #include <signal.h>
  33. #endif
  34. std::string g_usercodeTranslateFile = "";
  35. std::map<std::string, std::vector<std::string>> g_networkParse;
  36. std::map<std::string, clock_t> g_networkExpiredData;
  37. std::map<std::string, ErrMsgStruct> g_UserCodeToMsgTip;
  38. boost::mutex g_networkMutex;
  39. const std::wstring WCHAR_NULL = L"";
  40. const std::wstring specialStr = L"乗俓僜刓匼哱圽塡奬媆峔嶾廫慭怽揬昞朶梊榎橽歕沑漒瀄焅燶猏玕琝甛璡痋盶癨瞈砛碶穃竆筡篭糪絓綷縗繺羂耚肻腬臶臷芢蒤薥蚛蝄蟎衆蟎裓覾譢豛赲踈躙輁郳醆鈂鉢鎈鏫閈闬隲頫颸餦馶骪鯸鮘鳿鵟鸤黒齖";
  41. #define NOR_LEN 50
  42. #define MAX_LOG_LEN 4096
  43. #define MAX_CEFLOG_LEN 5120
  44. #if (defined _WIN32 || defined _WIN64)
  45. #include <ShellAPI.h>
  46. std::string UtfToGbk(const char* utf8)
  47. {
  48. int len = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0);
  49. wchar_t* wstr = new wchar_t[len + 1];
  50. memset(wstr, 0, len + 1);
  51. MultiByteToWideChar(CP_UTF8, 0, utf8, -1, wstr, len);
  52. len = WideCharToMultiByte(CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL);
  53. char* str = new char[len + 1];
  54. memset(str, 0, len + 1);
  55. WideCharToMultiByte(CP_ACP, 0, wstr, -1, str, len, NULL, NULL);
  56. if (wstr) delete[] wstr;
  57. return str;
  58. }
  59. //GBK转化为UTF8格式
  60. std::string ConvertGBKToUtf8(std::string& strGBK)
  61. {
  62. int len = MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)strGBK.c_str(), -1, NULL, 0);
  63. wchar_t* wszUtf8 = new wchar_t[len];
  64. memset(wszUtf8, 0, len);
  65. MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)strGBK.c_str(), -1, wszUtf8, len);
  66. len = WideCharToMultiByte(CP_UTF8, 0, wszUtf8, -1, NULL, 0, NULL, NULL);
  67. char* szUtf8 = new char[len + 1];
  68. memset(szUtf8, 0, len + 1);
  69. WideCharToMultiByte(CP_UTF8, 0, wszUtf8, -1, szUtf8, len, NULL, NULL);
  70. std::string ret = szUtf8;
  71. delete[] szUtf8;
  72. delete[] wszUtf8;
  73. return ret;
  74. }
  75. #else
  76. std::string UtfToGbk(const char* utf8)
  77. {
  78. return utf8;
  79. }
  80. std::string ConvertGBKToUtf8(std::string& strGBK)
  81. {
  82. return strGBK;
  83. }
  84. #endif
  85. struct cefclientLog {
  86. LOG_LEVEL_E m_level;
  87. LOG_TYPE_E m_type;
  88. char m_logTime[NOR_LEN];
  89. char m_filename[NOR_LEN];
  90. int m_filePos;
  91. char m_cefLog[MAX_CEFLOG_LEN];
  92. 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) {
  93. m_level = t_level;
  94. m_type = t_type;
  95. strcpy_s(m_logTime, NOR_LEN, t_logTime);
  96. strcpy_s(m_filename, NOR_LEN, t_filename);
  97. m_filePos = t_filePos;
  98. strcpy_s(m_cefLog, MAX_CEFLOG_LEN, t_cefLog);
  99. }
  100. cefclientLog()
  101. :m_level(LOG_LEVEL_DEBUG), m_type(LOG_TYPE_SYSTEM), m_filePos(0)
  102. {
  103. memset(m_logTime, 0, NOR_LEN);
  104. memset(m_filename, 0, NOR_LEN);
  105. memset(m_cefLog, 0, MAX_CEFLOG_LEN);
  106. }
  107. };
  108. #define CEF_GUID "{5ED197CD-9D64-4D10-9839-2A0773B6F5D2}"
  109. bool InitFileLogger(std::string dbgPath)
  110. {
  111. auto ret = logger::init(dbgPath.c_str(), "cefLog");
  112. ConfigManager::getInstance().setLoggerInitSuccess(ret);
  113. return ret;
  114. }
  115. void DbgToFileLogger(std::string msg)
  116. {
  117. if(ConfigManager::getInstance().isLoggerInitSuccess())
  118. logger::showLog(msg);
  119. }
  120. void DbgEx(const char* str, ...)
  121. {
  122. va_list arg;
  123. va_start(arg, str);
  124. #if (defined _WIN32 || defined _WIN64)
  125. int n = _vscprintf(str, arg);
  126. char* buf = (char*)malloc(n + 1);
  127. vsprintf(buf, str, arg);
  128. auto modifyStr = CSimpleString::Format("%s", buf);
  129. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).withExtendLog(!ConfigManager::getInstance().m_withNoFileLog).setResultMsg(modifyStr.GetData())();
  130. free(buf);
  131. #else
  132. auto modifyStr = CSimpleString::Format("%s", str);
  133. vDbg(modifyStr.GetData(), arg);
  134. #endif
  135. va_end(arg);
  136. }
  137. bool SYSTEM_ON(std::string cmdLine, bool isWait)
  138. {
  139. #if (defined _WIN32 || defined _WIN64)
  140. auto waitSystem = [](const std::string cmd, const std::string par, BOOL nShow) ->DWORD
  141. {
  142. SHELLEXECUTEINFO ShExecInfo = { 0 };
  143. ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
  144. ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
  145. ShExecInfo.hwnd = NULL;
  146. ShExecInfo.lpVerb = NULL;
  147. ShExecInfo.lpFile = cmd.c_str(); //调用的程序名
  148. ShExecInfo.lpParameters = par.c_str(); //调用程序的命令行参数
  149. ShExecInfo.lpDirectory = NULL;
  150. ShExecInfo.nShow = nShow ? SW_SHOW : SW_HIDE; //窗口状态为隐藏
  151. ShExecInfo.hInstApp = NULL;
  152. if (ShellExecuteEx(&ShExecInfo) && ShExecInfo.hProcess)//如果设置了 SEE_MASK_NOCLOSEPROCESS ,并且调用成功则该值大于32,调用失败者被设置错误值
  153. {
  154. //创建进程成功
  155. WaitForSingleObject(ShExecInfo.hProcess, INFINITE); //等到该进程结束
  156. DWORD exitCode = 0;
  157. GetExitCodeProcess(ShExecInfo.hProcess, &exitCode);
  158. return exitCode;
  159. }
  160. else {
  161. std::string errMsg;
  162. auto errorCode = GetLastError();
  163. switch (errorCode)
  164. {
  165. #define CASE(code) \
  166. case code: \
  167. errMsg = #code; \
  168. break
  169. CASE(ERROR_FILE_NOT_FOUND);
  170. CASE(ERROR_PATH_NOT_FOUND);
  171. CASE(ERROR_DDE_FAIL);
  172. CASE(ERROR_NO_ASSOCIATION);
  173. CASE(ERROR_ACCESS_DENIED);
  174. CASE(ERROR_DLL_NOT_FOUND);
  175. CASE(ERROR_CANCELLED);
  176. CASE(ERROR_NOT_ENOUGH_MEMORY);
  177. CASE(ERROR_SHARING_VIOLATION);
  178. default:
  179. errMsg = "UNKNOWN";
  180. }
  181. 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());
  182. return false;
  183. }
  184. };
  185. std::string strCmd, strPar;
  186. if (isWait)
  187. {
  188. strPar = std::string("/c ") + cmdLine;
  189. strCmd = std::string("cmd ") + strPar;
  190. return waitSystem("cmd.exe", strPar, FALSE);
  191. }
  192. else {
  193. strCmd = cmdLine;
  194. unsigned int result = WinExec(strCmd.c_str(), SW_HIDE);
  195. if (result > 31)
  196. return true;
  197. else
  198. {
  199. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__).setAPI(__FUNCTION__)("SYSTEM_ON nowait with %s failed, reason:%d", result);
  200. return false;
  201. }
  202. }
  203. #else
  204. system(cmdLine.c_str());
  205. return true;
  206. #endif
  207. return false;
  208. }
  209. DWORD SaveCefclientLog(std::string magicStr)
  210. {
  211. std::string dstGuid = magicStr + "_" + CEF_GUID;
  212. try {
  213. auto removeRet = message_queue::remove(dstGuid.c_str());
  214. if (!removeRet)
  215. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("message_queue did not remove!");
  216. boost::interprocess::permissions cur;
  217. cur.set_unrestricted();
  218. message_queue mq(create_only, dstGuid.c_str(), 100, sizeof(cefclientLog), cur);
  219. ConfigManager::getInstance().setUseMagic(true);
  220. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("SaveCefclientLog thread begin");
  221. while (true)
  222. {
  223. cefclientLog t_data;
  224. #if (defined _WIN32 || defined _WIN64)
  225. unsigned int t_recvSize = 0;
  226. #else
  227. unsigned long t_recvSize = 0;
  228. #endif
  229. unsigned int t_priority = 0;
  230. mq.receive(&t_data, sizeof(cefclientLog), t_recvSize, t_priority);
  231. std::string source = std::string(t_data.m_filename) + "(" + std::to_string((ULONGLONG)t_data.m_filePos) + ")";
  232. #ifdef OUTPUT_DETAIL_LOG /*DevOps流水线编译,ST环境*/
  233. DbgWithLink(t_data.m_level, t_data.m_type).withLogProducer(ConfigManager::getInstance().getLogProducer()).setSourceType(source.c_str()).withExtendLog(true).setResultMsg(t_data.m_cefLog)();
  234. #elif defined(DEVOPS_ON_UAT)/*DevOps流水线编译,UAT环境*/
  235. DbgWithLink(t_data.m_level, t_data.m_type).withLogProducer(ConfigManager::getInstance().getLogProducer()).setSourceType(source.c_str()).withExtendLog(true).setResultMsg(t_data.m_cefLog)();
  236. #elif defined(DEVOPS_ON_PRD)/*DevOps流水线编译,PRD环境*/
  237. DbgWithLink(t_data.m_level, t_data.m_type).withLogProducer(ConfigManager::getInstance().getLogProducer()).setSourceType(source.c_str()).withExtendLog(false).setResultMsg(t_data.m_cefLog)();
  238. #else
  239. DbgWithLink(t_data.m_level, t_data.m_type).withLogProducer(ConfigManager::getInstance().getLogProducer()).setSourceType(source.c_str()).withExtendLog(false).setResultMsg(t_data.m_cefLog)();
  240. #endif // DEVOPS
  241. if (sizeof(cefclientLog) != t_recvSize)
  242. break;
  243. /*特么制品库太恶心了
  244. cefclientLog tmp;
  245. std::istringstream iss(t_data);
  246. boost::archive::binary_iarchive iarchive(iss);
  247. iarchive >> tmp;//从一个保存序列化数据的string里面反序列化,从而得到原来的对象
  248. std::string source = tmp.m_filename + "(" + std::to_string((ULONGLONG)tmp.m_filePos) + ")";
  249. DbgWithLink(tmp.m_level, tmp.m_type).setSourceType(source.c_str())(tmp.m_cefLog.c_str());
  250. */
  251. }
  252. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("SaveCefclientLog thread end");
  253. }
  254. catch (interprocess_exception& ex) {
  255. message_queue::remove(dstGuid.c_str());
  256. ConfigManager::getInstance().setUseMagic(false);
  257. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("%s run exception, for %s", dstGuid.c_str(), ex.what());
  258. return 1;
  259. }
  260. ConfigManager::getInstance().setUseMagic(false);
  261. message_queue::remove(dstGuid.c_str());
  262. return 0;
  263. }
  264. std::vector<std::string> find_files(const std::string srcPath, const std::string fileName, bool isDir)
  265. {
  266. static boost::xpressive::sregex_compiler rc;
  267. if (!rc[fileName].regex_id())
  268. {
  269. std::string str = boost::algorithm::replace_all_copy(
  270. boost::algorithm::replace_all_copy(fileName, ".", "\\."), "*", ".*");
  271. rc[fileName] = rc.compile(str);
  272. }
  273. std::vector<std::string> ret;
  274. if (!boost::filesystem::exists(srcPath) || !boost::filesystem::is_directory(srcPath))
  275. return ret;
  276. typedef boost::filesystem::recursive_directory_iterator rd_iterator;
  277. rd_iterator end;
  278. for (rd_iterator pos(srcPath); pos != end; ++pos)
  279. {
  280. if ((isDir ? boost::filesystem::is_directory(*pos) : !boost::filesystem::is_directory(*pos)) && boost::xpressive::regex_match(pos->path().filename().string(), rc[fileName]))
  281. ret.emplace_back(pos->path().string());
  282. }
  283. return ret;
  284. }
  285. bool deleteDir_byFileSystem(const std::string srcPath)
  286. {
  287. boost::system::error_code ec;
  288. return boost::filesystem::remove_all(srcPath, ec);
  289. }
  290. std::string generateTimeStr(bool isSimple)
  291. {
  292. auto tt = boost::chrono::system_clock::to_time_t(boost::chrono::system_clock::now());
  293. struct tm* ptm = localtime(&tt);
  294. char date[60] = { 0 };
  295. if (isSimple)
  296. sprintf(date, "%02d%02d%02d", (int)ptm->tm_hour, (int)ptm->tm_min, (int)ptm->tm_sec);
  297. else
  298. 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);
  299. return std::string(date);
  300. }
  301. void InitTranslateFile(std::string srcFile)
  302. {
  303. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("InitTranslateFile %s", srcFile.c_str());
  304. g_usercodeTranslateFile = srcFile;
  305. }
  306. void InitUserCodeToMsgTip(CAutoArray<CSimpleStringA>& strErrorCodeArr, CAutoArray<CSimpleStringA>& strDescriptionArr, CAutoArray<CSimpleStringA>& strRemarkArr)
  307. {
  308. g_UserCodeToMsgTip.clear();//should not be inited muli times
  309. for (int i = 0; i < strErrorCodeArr.GetCount(); i++)
  310. {
  311. std::string dstDescribe = "[" + std::string(strErrorCodeArr[i].GetData()) + "]" + std::string(strDescriptionArr[i].GetData());
  312. if (g_UserCodeToMsgTip.find(strRemarkArr[i].GetData()) != g_UserCodeToMsgTip.end())
  313. {
  314. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("InitUserCodeToMsgTip repeated usercode:%s", strRemarkArr[i].GetData());
  315. continue;
  316. }
  317. std::string curRemark = strRemarkArr[i].GetData();
  318. std::transform(curRemark.begin(), curRemark.end(), curRemark.begin(), [](unsigned char c) { return std::tolower(c); });
  319. g_UserCodeToMsgTip.insert(std::make_pair(curRemark.c_str(), ErrMsgStruct(strErrorCodeArr[i].GetData(), dstDescribe, curRemark.c_str())));
  320. }
  321. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("InitUserCodeToMsgTip size:%d", g_UserCodeToMsgTip.size());
  322. }
  323. std::pair<unsigned long, ErrMsgStruct> getErrMsgByRemark(std::string srcMsg)
  324. {
  325. const std::string headerStr = "UserError=";
  326. if (srcMsg.find(headerStr) != 0)
  327. return std::make_pair(0, ErrMsgStruct("RTA42F1", CSimpleString::Format("[RTA42F1]错误映射异常|(%s)", srcMsg.c_str()).GetData(), ""));
  328. unsigned long userCode = std::stoi(srcMsg.substr(headerStr.length()));
  329. std::string userCodeStr = CSimpleString::Format("0x%X", userCode).GetData();
  330. std::transform(userCodeStr.begin(), userCodeStr.end(), userCodeStr.begin(), [](unsigned char c) { return std::tolower(c); });
  331. if (g_UserCodeToMsgTip.size() == 0)
  332. {
  333. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA42F0").setAPI(__FUNCTION__)("[RTA42F0]微服务异常|(%s)", srcMsg.c_str());
  334. return std::make_pair(0, ErrMsgStruct("RTA42F0", CSimpleString::Format("[RTA42F0]微服务异常|(%s)", srcMsg.c_str()).GetData(), userCodeStr));
  335. }
  336. if (g_UserCodeToMsgTip.find(userCodeStr) != g_UserCodeToMsgTip.end())
  337. {
  338. ErrMsgStruct curMsg(g_UserCodeToMsgTip[userCodeStr]);
  339. return std::make_pair(userCode, curMsg);
  340. }
  341. else
  342. {
  343. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA42F1").setAPI(__FUNCTION__)("[RTA42F1]错误映射异常|(%s)", srcMsg.c_str());
  344. return std::make_pair(userCode, ErrMsgStruct("RTA42F1", CSimpleString::Format("[RTA42F1]错误映射异常|(%s)", srcMsg.c_str()).GetData(), userCodeStr));
  345. }
  346. }
  347. std::pair<unsigned long, std::string> splitStrToUserCodeAndErrMsg(std::string srcMsg)
  348. {
  349. const std::string headerStr = "UserError=";
  350. if (srcMsg.find(headerStr) != 0)
  351. return std::make_pair(0, srcMsg);
  352. unsigned long userCode = std::stoi(srcMsg.substr(headerStr.length()));
  353. std::string userCodeStr = CSimpleString::Format("0x%X", userCode).GetData();
  354. if (g_usercodeTranslateFile.length() == 0)
  355. return std::make_pair(userCode, srcMsg);
  356. try
  357. {
  358. boost::property_tree::ptree ptr, tag;
  359. boost::property_tree::ini_parser::read_ini(g_usercodeTranslateFile, ptr);
  360. tag = ptr.get_child("UserCodeToMsgTip");
  361. std::string tipMsg = tag.get<std::string>(userCodeStr);
  362. return std::make_pair(userCode, UtfToGbk(tipMsg.c_str()));
  363. }
  364. catch (std::exception &e) {
  365. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("ini_parse failed, reason:%s", e.what());
  366. }
  367. return std::make_pair(userCode, srcMsg);
  368. }
  369. std::string hexdumpToString(const char* buf, const int num)
  370. {
  371. char str[8192 * 2] = { 0 };
  372. int i = 0;
  373. char c[5] = { 0 };
  374. if (num > 100)
  375. {
  376. for (i = 0; i < 50; i++)
  377. {
  378. sprintf(c, "%02X ", (unsigned char)buf[i]);
  379. strcat(str, c);
  380. }
  381. return CSimpleStringA::Format("buffer too long to show!show pre 50 hex! CSocketClient hex buf len = %d : %s", num, str).GetData();
  382. }
  383. for (i = 0; i < num; i++)
  384. {
  385. sprintf(c, "%02X ", (unsigned char)buf[i]);
  386. strcat(str, c);
  387. }
  388. return CSimpleStringA::Format("CSocketClient hex buf len = %d : %s", num, str).GetData();
  389. }
  390. void hexdump(const char* buf, const int num) {
  391. auto hexStr = hexdumpToString(buf, num);
  392. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)(hexStr.c_str());
  393. }
  394. bool modifyBySpecialStr(std::wstring& src)
  395. {
  396. #if 0
  397. clock_t cur = clock();
  398. std::set<wchar_t> srcArr;
  399. static std::set<wchar_t> compareArr;
  400. for (auto it = src.begin(); it != src.end(); it++)
  401. srcArr.insert(*it);
  402. if (compareArr.size() == 0)
  403. {
  404. for (auto it = specialStr.begin(); it != specialStr.end(); it++)
  405. compareArr.insert(*it);
  406. }
  407. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("modifyBySpecialStr insert cost:%d", clock() - cur);
  408. cur = clock();
  409. std::set<wchar_t> result;
  410. std::set_intersection(std::begin(srcArr), std::end(srcArr), std::begin(compareArr), std::end(compareArr), std::inserter(result, std::begin(result)));
  411. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("modifyBySpecialStr intersection cost:%d", clock() - cur);
  412. cur = clock();
  413. if (result.size() == 0)
  414. return false;
  415. for (auto it = result.begin(); it != result.end(); it++)
  416. {
  417. int pos = 0;
  418. for (int pos = 0; pos < src.length();)
  419. {
  420. pos = src.find(*it, pos);
  421. if (pos < 0)
  422. break;
  423. if (pos + 1 < src.length() && src[pos + 1] == '\\')
  424. src.erase(pos + 1, 1);
  425. else
  426. pos++;
  427. }
  428. }
  429. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("modifyBySpecialStr modify cost:%d", clock() - cur);
  430. cur = clock();
  431. return true;
  432. #endif
  433. clock_t cur = clock();
  434. wchar_t specialone = L'碶';
  435. if (src.find(specialone, 0) == -1)
  436. return false;
  437. int pos = 0;
  438. for (int pos = 0; pos < src.length();)
  439. {
  440. pos = src.find(specialone, pos);
  441. if (pos < 0)
  442. break;
  443. if (pos + 1 < src.length() && src[pos + 1] == '\\')
  444. src.erase(pos + 1, 1);
  445. else
  446. pos++;
  447. }
  448. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("modifyBySpecialStr modify cost:%d", clock() - cur);
  449. return true;
  450. }
  451. #include <boost/stacktrace.hpp>
  452. #if (defined _WIN32 || defined _WIN64)
  453. long WINAPI printSEG(struct _EXCEPTION_POINTERS* ExceptionInfo)
  454. #else
  455. long printSEG()
  456. #endif
  457. {
  458. auto dumpArr = boost::stacktrace::stacktrace().as_vector();
  459. if (dumpArr.size() > 20)
  460. {
  461. for (auto i = 0; i < 10; i++)
  462. 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());
  463. for (auto i = dumpArr.size() - 10; i < dumpArr.size(); i++)
  464. 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());
  465. }
  466. else
  467. {
  468. for (auto i = 0; i < dumpArr.size(); i++)
  469. 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());
  470. }
  471. return 0;
  472. }
  473. //singal,退出函数
  474. #if (defined _WIN32 || defined _WIN64)
  475. #else
  476. #include <signal.h> // ::signal, ::raise
  477. #include <boost/stacktrace.hpp>
  478. #include "CModTools.h"
  479. #include "CWebsocketServer.h"
  480. #include <winpr/sysinfo.h>
  481. #include <winpr/timezone.h>
  482. std::string g_backtracePath = "";
  483. void seg_signal_handler(int signum)
  484. {
  485. //boost::stacktrace::safe_dump_to(g_backtracePath.c_str());
  486. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("receive signal:%d, seg_signal_handler", signum);
  487. printSEG();
  488. Chromium::CModTools::get_mutable_instance().killAllChromium();
  489. Chromium::CWebsocketServer::stopServer();
  490. signal(signum, SIG_DFL);
  491. raise(signum);
  492. }
  493. void normal_signal_handle(int signum)
  494. {
  495. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("receive signal:%d, normal_signal_handle", signum);
  496. signal(signum, SIG_DFL);
  497. raise(signum);
  498. }
  499. void set_traceback_path(std::string path)
  500. {
  501. g_backtracePath = path + "/mod_chromium/" + generateTimeStr(true) + "_chromium_backtrace.dump";
  502. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("set_traceback_path %s", g_backtracePath.c_str());
  503. }
  504. #endif
  505. void receivehexdump(const char* buf, const int num) {
  506. char str[8192 * 2] = { 0 };
  507. int i = 0;
  508. char c[5] = { 0 };
  509. if (num > 100)
  510. {
  511. for (i = 0; i < 50; i++)
  512. {
  513. sprintf(c, "%02X ", (unsigned char)buf[i]);
  514. strcat(str, c);
  515. }
  516. 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);
  517. return;
  518. }
  519. for (i = 0; i < num; i++)
  520. {
  521. sprintf(c, "%02X ", (unsigned char)buf[i]);
  522. strcat(str, c);
  523. }
  524. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("receivehexdump hex buf len = %d : %s", num, str);
  525. return;
  526. }
  527. void doWithDebugModeData(const char* strMethod, const char* buf)
  528. {
  529. boost::lock_guard<boost::mutex> lock(g_networkMutex);
  530. if(std::string(strMethod).find("Network.") == 0)
  531. {
  532. /*for example
  533. {
  534. "method": "Network.requestWillBeSent",
  535. "params": {
  536. "documentURL": "https://www.btbtt12.com/",
  537. "frameId": "8F58093A23334B311DB645BA3652E63C",
  538. "hasUserGesture": false,
  539. "initiator": {
  540. "type": "other"
  541. },
  542. "loaderId": "9F7B28B896C791554C69C5985CA92E79",
  543. "request": {
  544. "headers": {
  545. "Referer": "https://www.btbtt12.com/",
  546. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36"
  547. },
  548. "initialPriority": "Low",
  549. "method": "GET",
  550. "mixedContentType": "none",
  551. "referrerPolicy": "no-referrer-when-downgrade",
  552. "url": "https://pic.picnewsss.com/tu-2022290039/960-60.gif"
  553. },
  554. "requestId": "18476.34",
  555. "timestamp": 19338.811603,
  556. "type": "Image",
  557. "wallTime": 1666099893.800733
  558. }
  559. }
  560. */
  561. std::shared_ptr<cJSON> pJson(cJSON_Parse(buf), [](cJSON* p) {
  562. if (nullptr != p)
  563. cJSON_Delete(p);
  564. });
  565. auto paramsItem = cJSON_GetObjectItem(pJson.get(), "params");
  566. if (paramsItem == nullptr)
  567. return;
  568. auto requestIdItem = cJSON_GetObjectItem(paramsItem, "requestId");
  569. if (requestIdItem == nullptr)
  570. return;
  571. std::string requestId_str = requestIdItem->valuestring;
  572. /*
  573. ['Network.loadingFailed', 'Network.loadingFinished', 'Network.resourceChangedPriority',
  574. 'Network.requestServedFromCache', 'Network.requestWillBeSent', 'Network.requestWillBeSentExtraInfo',
  575. 'Network.responseReceived', 'Network.responseReceivedExtraInfo', 'Network.dataReceived',
  576. 'Page.frameAttached', 'Page.frameRequestedNavigation', 'Page.frameStoppedLoading',
  577. 'Page.frameClearedScheduledNavigation', 'Page.loadEventFired', 'Page.frameStartedLoading',
  578. 'Page.frameDetached', 'Page.frameScheduledNavigation', 'Page.frameNavigated', 'Page.frameResized',
  579. 'Page.domContentEventFired']
  580. */
  581. if(std::string(strMethod) == "Network.loadingFinished")
  582. {
  583. if (g_networkParse.find(requestId_str) != g_networkParse.end())
  584. g_networkParse.erase(requestId_str);
  585. if (g_networkExpiredData.find(requestId_str) != g_networkExpiredData.end())
  586. g_networkExpiredData.erase(requestId_str);
  587. if (g_networkExpiredData.size() < 30)
  588. return;
  589. for(auto it = g_networkExpiredData.begin(); it != g_networkExpiredData.end();)
  590. {
  591. if((clock() - it -> second) < 100000)
  592. {
  593. it++;
  594. continue;
  595. }
  596. if (g_networkParse.find(it->first) != g_networkParse.end())
  597. g_networkParse.erase(it->first);
  598. g_networkExpiredData.erase(it++);
  599. }
  600. }
  601. else if(std::string(strMethod) == "Network.loadingFailed"
  602. || std::string(strMethod) == "Network.webSocketFrameError"
  603. || std::string(strMethod) == "Network.requestServedFromCache")
  604. {
  605. if (g_networkParse.find(requestId_str) != g_networkParse.end())
  606. {
  607. for(auto it = g_networkParse[requestId_str].begin(); it != g_networkParse[requestId_str].end(); it++)
  608. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402402Z00001").setResultMsg(it->c_str())();
  609. g_networkParse.erase(requestId_str);
  610. }
  611. else//此时,上一轮记录已结束
  612. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402402Z00001").setResultMsg(buf)();
  613. if (g_networkExpiredData.find(requestId_str) != g_networkExpiredData.end())
  614. g_networkExpiredData.erase(requestId_str);
  615. }
  616. else
  617. {
  618. if (g_networkParse.find(requestId_str) != g_networkParse.end())
  619. g_networkParse[requestId_str].push_back(buf);
  620. else
  621. {
  622. std::vector<std::string> tmp;
  623. tmp.push_back(buf);
  624. g_networkParse[requestId_str] = tmp;
  625. g_networkExpiredData[requestId_str] = clock();
  626. }
  627. }
  628. }
  629. if (std::string(strMethod) == "Network.webSocketFrameError" ||
  630. std::string(strMethod) == "Network.loadingFailed" ||
  631. std::string(strMethod) == "Runtime.exceptionThrown")
  632. {
  633. LogWarn(Severity_Middle, Error_Debug, LOG_WARN_CHROMIUM_OPENWEBWARN, buf);
  634. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402402Z00002").setResultMsg(buf)();
  635. }
  636. }
  637. std::pair<bool, CSimpleStringA> json_deal::getStringFromCjsonObj(void* object, const char* name)
  638. {
  639. if (object == NULL)
  640. return std::make_pair(false, "");
  641. auto curNode = cJSON_GetObjectItem((cJSON*)object, name);
  642. if (curNode && curNode->type == cJSON_String) {
  643. return std::make_pair(true, curNode->valuestring);
  644. }
  645. else
  646. return std::make_pair(false, "");
  647. }
  648. std::pair<bool, int> json_deal::getIntergerFromCjsonObj(void* object, const char* name)
  649. {
  650. if (object == NULL)
  651. return std::make_pair(false, 0);
  652. auto curNode = cJSON_GetObjectItem((cJSON*)object, name);
  653. if (curNode && curNode->type == cJSON_Number) {
  654. return std::make_pair(true, curNode->valueint);
  655. }
  656. else
  657. return std::make_pair(false, 0);
  658. }
  659. std::pair<bool, double> json_deal::getDoubleFromCjsonObj(void* object, const char* name)
  660. {
  661. if (object == NULL)
  662. return std::make_pair(false, 0);
  663. auto curNode = cJSON_GetObjectItem((cJSON*)object, name);
  664. if (curNode && curNode->type == cJSON_Number) {
  665. return std::make_pair(true, curNode->valuedouble);
  666. }
  667. else
  668. return std::make_pair(false, 0);
  669. }
  670. SM2_Encrypt_Manager::SM2_Encrypt_Manager()
  671. :m_public_key_buf_len(DEFAULT_KEY_LEN),
  672. m_private_key_buf_len(DEFAULT_KEY_LEN),
  673. m_opposite_public_key_buf_len(DEFAULT_KEY_LEN)
  674. {
  675. memset(m_public_key_buf, 0, DEFAULT_KEY_LEN);
  676. memset(m_private_key_buf, 0, DEFAULT_KEY_LEN);
  677. memset(m_opposite_public_key_buf, 0, DEFAULT_KEY_LEN);
  678. GenerateSM2_key(m_public_key, m_private_key);
  679. m_state = SM2ProtocolState::WAIT_KEY_EXCHANGE;
  680. }
  681. SM2_Encrypt_Manager::~SM2_Encrypt_Manager()
  682. {
  683. }
  684. bool SM2_Encrypt_Manager::GenerateSM2_key(std::string& pub, std::string& pri)
  685. {
  686. if (!::CreateSM2KeyPair(m_public_key_buf, &m_public_key_buf_len, m_private_key_buf, &m_private_key_buf_len))
  687. return false;
  688. pub = binToHex(m_public_key_buf, m_public_key_buf_len);
  689. pri = binToHex(m_private_key_buf, m_private_key_buf_len);
  690. return true;
  691. }
  692. std::string SM2_Encrypt_Manager::binToHex(const unsigned char* data, int len)
  693. {
  694. std::string hexString;
  695. // 使用 boost::algorithm::hex 进行编码
  696. boost::algorithm::hex(data, data + len, std::back_inserter(hexString));
  697. return hexString;
  698. }
  699. void SM2_Encrypt_Manager::hexToBin(const std::string& hexStr, unsigned char* binData, int& binLen)
  700. {
  701. binLen = hexStr.size() / 2;
  702. if (binData == nullptr) {
  703. // 如果 binData 为 nullptr,仅返回计算出的 binLen,不执行实际的转换
  704. return;
  705. }
  706. // 使用 boost::algorithm::unhex 进行解码
  707. boost::algorithm::unhex(hexStr.begin(), hexStr.end(), binData);
  708. }
  709. void SM2_Encrypt_Manager::setOpposite(const std::string pub)
  710. {
  711. m_opposite_public_key = pub;
  712. hexToBin(m_opposite_public_key, m_opposite_public_key_buf, m_opposite_public_key_buf_len);
  713. }
  714. std::pair<bool, std::string> SM2_Encrypt_Manager::checkSM2Enable()
  715. {
  716. if (m_public_key.length() == 0)
  717. return std::make_pair(false, "public_key is empty");
  718. if (m_private_key.length() == 0)
  719. return std::make_pair(false, "private_key is empty");
  720. if (m_opposite_public_key.length() == 0)
  721. return std::make_pair(false, "opposite public_key is empty");
  722. return std::make_pair(true, "");
  723. }
  724. std::pair<std::string, std::string> SM2_Encrypt_Manager::EncryptMsg(std::string msg)
  725. {
  726. unsigned char sign[DEFAULT_KEY_LEN] = "";
  727. int sign_len = DEFAULT_KEY_LEN;
  728. unsigned char* dstMsg = new unsigned char[msg.length() * 2 + 97];
  729. int dstMsgLen = msg.length() * 2 + 97;
  730. std::shared_ptr<void> msgClean((void*)0, [&](void*) {
  731. if (dstMsg)
  732. {
  733. delete[]dstMsg;
  734. dstMsg = nullptr;
  735. }
  736. });
  737. if (!SM2SignWithSM3(m_private_key_buf, m_private_key_buf_len, (unsigned char*)msg.c_str(), msg.length(), sign, &sign_len))
  738. {
  739. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("SM2SignWithSM3::err, can not sign msg, sign_len:%d", sign_len);
  740. return std::make_pair("", "");
  741. }
  742. if(!EncWithSM2PubKey((unsigned char*)msg.c_str(), msg.length(), dstMsg, &dstMsgLen, m_opposite_public_key_buf, m_opposite_public_key_buf_len))
  743. {
  744. 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);
  745. return std::make_pair("", "");
  746. }
  747. return std::make_pair(binToHex(sign, sign_len), binToHex(dstMsg, dstMsgLen));
  748. }
  749. std::pair<bool, std::string> SM2_Encrypt_Manager::DecryptMsg(std::string sign, std::string msg)
  750. {
  751. 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
  752. int binMsgLen = msg.length(), outMsgLen = msg.length() * 2, signLen = sign.length();
  753. std::shared_ptr<void> msgClean((void*)0, [&](void*) {
  754. if (binMsg) {
  755. delete[] binMsg;
  756. binMsg = nullptr;
  757. }
  758. if (outMsg) {
  759. delete[] outMsg;
  760. outMsg = nullptr;
  761. }
  762. if (binSign) {
  763. delete[] binSign;
  764. binSign = nullptr;
  765. }
  766. });
  767. hexToBin(msg, binMsg, binMsgLen);
  768. hexToBin(sign, binSign, signLen);
  769. if (!DecWithSM2PriKey(binMsg, binMsgLen, outMsg, &outMsgLen, m_private_key_buf, m_private_key_buf_len))
  770. return std::make_pair(false, "DecWithSM2PriKey::err, can not dectrypt msg");
  771. if (!SM2VerifyWithSM3(m_opposite_public_key_buf, m_opposite_public_key_buf_len, outMsg, outMsgLen, binSign, signLen))
  772. return std::make_pair(false, "SM2VerifyWithSM3::err, can not verify sign");
  773. return std::make_pair(true, (char*)outMsg);
  774. }
  775. std::pair<bool, std::string> SM2_Encrypt_Manager::GenerateEncPubKey()
  776. {
  777. if(!verifySM2Manager())
  778. return std::make_pair(false, "GenerateEncPubKey::verifySM2Manager err");
  779. unsigned char encPubKey[DEFAULT_KEY_LEN] = "";
  780. int encPubKey_len = DEFAULT_KEY_LEN;
  781. 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))
  782. return std::make_pair(false, "GenerateEncPubKey::EncWithSM2PubKey err");
  783. return std::make_pair(true, binToHex(encPubKey, encPubKey_len));
  784. }
  785. bool SM2_Encrypt_Manager::verifySM2Manager()
  786. {
  787. if (m_opposite_public_key.length() == 0 || m_public_key.length() == 0 || m_private_key.length() == 0)
  788. return false;
  789. if (m_opposite_public_key_buf == NULL || m_public_key_buf == NULL || m_private_key_buf == NULL)
  790. return false;
  791. return true;
  792. }
  793. #ifdef RVC_OS_LINUX
  794. std::vector<int> getUosBrowserPIDs(int UseUOSBrowser)
  795. {
  796. std::vector<int> pids;
  797. FILE* fp = nullptr;
  798. if(UseUOSBrowser == 1)
  799. fp = popen("ps -ef | grep uosbrowser | grep -v grep | awk '{print $2}'", "r");
  800. else if(UseUOSBrowser == 2)
  801. fp = popen("ps -ef | grep browser | grep -v grep | awk '{print $2}'", "r");
  802. if (fp) {
  803. char buffer[256];
  804. while (fgets(buffer, sizeof(buffer), fp) != NULL) {
  805. pids.push_back(static_cast<pid_t>(std::atoi(buffer)));
  806. }
  807. pclose(fp);
  808. }
  809. return pids;
  810. }
  811. #endif
  812. ConfigManager& ConfigManager::getInstance() {
  813. static ConfigManager instance;
  814. return instance;
  815. }
  816. ConfigManager::ConfigManager()
  817. : 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)
  818. , m_withDebugMode(false), m_withMagic(false), m_withNoFileLog(false), m_installMode(false), m_withMedia(false), m_withSpecialTest(false), m_withConsole(false),
  819. m_withLinkLog(false), m_withUnsafeAd(false), m_noStartupPage(false), m_extension_debugOpen(false), m_extension_withTerminal(false)
  820. {
  821. void* logProducer = nullptr;
  822. std::map<std::string, void*> g_logProducerArr;
  823. bool g_useMagic = false;
  824. bool g_loggerInitSuccess = false;
  825. bool g_withSpecialTest = false;
  826. bool g_hasInitCfg = false;//can discard
  827. int g_sogouForce = 0;
  828. m_extensionPath = "";
  829. }
  830. LogManager& LogManager::getInstance() {
  831. static LogManager instance;
  832. return instance;
  833. }
  834. void LogManager::logWebSocketBuild(int64_t hdl, const std::string& url, const std::string& isSecurity) {
  835. const char* type = "ws_build";
  836. Json::Value log;
  837. log["hdl"] = Json::Int64(hdl);
  838. log["78173721_logType"] = type;
  839. m_logTotal[hdl][type].num += 1;
  840. Json::Value detail;
  841. detail["url"] = url;
  842. detail["isSecurity"] = isSecurity;
  843. log["detail"] = detail;
  844. log["timestamp"] = getCurrentTimestamp();
  845. if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
  846. log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
  847. log["threadId"] = Json::Int64(GetCurrentThreadId());
  848. writeLog(LOG_LEVEL_DEBUG, log);
  849. }
  850. void LogManager::writeLog(LOG_LEVEL_E level, const Json::Value& log) {
  851. Json::FastWriter writer;
  852. DbgWithLink(level, LOG_TYPE_SYSTEM)(writer.write(log).c_str());
  853. }
  854. std::string LogManager::getCurrentTimestamp() {
  855. /*
  856. FILETIME ft;
  857. SYSTEMTIME st;
  858. GetSystemTime(&st);
  859. SystemTimeToFileTime(&st, &ft);
  860. FILETIME utc_ft, local_ft;
  861. #ifdef _WIN32
  862. utc_ft.dwLowDateTime = (DWORD)ft.dwLowDateTime;
  863. utc_ft.dwHighDateTime = (DWORD)ft.dwHighDateTime;
  864. FileTimeToLocalFileTime(&utc_ft, &local_ft);
  865. FileTimeToSystemTime(&local_ft, &st);
  866. #else
  867. GetLocalTime(&st);
  868. #endif // _WIN32
  869. */
  870. using namespace std::chrono;
  871. auto now = system_clock::now();
  872. auto ms = duration_cast<milliseconds>(now.time_since_epoch()) % 1000;
  873. auto timer = system_clock::to_time_t(now);
  874. std::ostringstream oss;
  875. oss << std::put_time(std::localtime(&timer), "%Y-%m-%d %H:%M:%S")
  876. << '.' << std::setfill('0') << std::setw(3) << ms.count();
  877. return oss.str();
  878. }
  879. void LogManager::logWebSocketBeginSession(int64_t hdl,
  880. int64_t web_transID,
  881. int64_t inner_transID,
  882. const std::string& entity,
  883. const std::string& entityClass,
  884. int ret,
  885. const std::string& operate,
  886. const std::string& payload,
  887. int retDetail,
  888. const std::string& reason) {
  889. const char* type = "ws_beginSession";
  890. Json::Value log;
  891. log["hdl"] = Json::Int64(hdl);
  892. log["78173721_logType"] = type;
  893. m_logTotal[hdl][type].num += 1;
  894. Json::Value detail;
  895. detail["web_transID"] = web_transID;
  896. detail["inner_transID"] = inner_transID;
  897. detail["entity"] = entity;
  898. detail["class"] = entityClass;
  899. detail["ret"] = ret;
  900. detail["retDetail"] = retDetail;
  901. detail["reason"] = reason;
  902. detail["operate"] = operate;
  903. #ifdef OUTPUT_DETAIL_LOG
  904. detail["payload"] = payload;
  905. #endif
  906. log["detail"] = detail;
  907. log["timestamp"] = getCurrentTimestamp();
  908. if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
  909. log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
  910. log["threadId"] = Json::Int64(GetCurrentThreadId());
  911. writeLog(LOG_LEVEL_DEBUG, log);
  912. }
  913. void LogManager::logWebSocketClose(int64_t hdl) {
  914. const char* type = "ws_close";
  915. Json::Value log;
  916. log["hdl"] = Json::Int64(hdl);
  917. log["78173721_logType"] = type;
  918. m_logTotal[hdl][type].num += 1;
  919. log["timestamp"] = getCurrentTimestamp();
  920. if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
  921. log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
  922. log["threadId"] = Json::Int64(GetCurrentThreadId());
  923. Json::Value root(Json::objectValue);
  924. if (m_logTotal.find(hdl) != m_logTotal.end())
  925. {
  926. // 遍历 map
  927. for (const auto& pair : m_logTotal[hdl]) {
  928. std::string key = pair.first;
  929. const LogInfo& logInfo = pair.second;
  930. root[key] = logInfo.num;
  931. }
  932. log["dealed"] = root;
  933. m_logTotal.erase(hdl);
  934. }
  935. writeLog(LOG_LEVEL_INFO, log);
  936. }
  937. void LogManager::logWebSocketInfo(int64_t hdl,
  938. int64_t web_transID,
  939. int64_t sessionId,
  940. const std::string& entity,
  941. const std::string& function,
  942. int ret,
  943. const std::string& operate,
  944. int retDetail,
  945. const std::string& reason,
  946. const std::string& payload) {
  947. const char* type = "ws_info";
  948. Json::Value log;
  949. log["hdl"] = Json::Int64(hdl);
  950. log["78173721_logType"] = type;
  951. m_logTotal[hdl][type].num += 1;
  952. Json::Value detail;
  953. detail["web_transID"] = Json::Int64(web_transID);
  954. detail["sessionId"] = Json::Int64(sessionId);
  955. detail["entity"] = entity;
  956. detail["function"] = function;
  957. detail["ret"] = ret;
  958. detail["operate"] = operate;
  959. detail["retDetail"] = retDetail;
  960. detail["reason"] = reason;
  961. #ifdef OUTPUT_DETAIL_LOG
  962. detail["payload"] = payload;
  963. #endif
  964. log["detail"] = detail;
  965. log["timestamp"] = getCurrentTimestamp();
  966. if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
  967. log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
  968. log["threadId"] = Json::Int64(GetCurrentThreadId());
  969. writeLog(LOG_LEVEL_DEBUG, log);
  970. }
  971. void LogManager::logWebSocketRegister(int64_t hdl,
  972. int64_t web_transID,
  973. int64_t inner_transID,
  974. const std::string& entity,
  975. const std::string& entityClass,
  976. int ret,
  977. const std::string& operate,
  978. const std::string& payload,
  979. int retDetail,
  980. const std::string& reason) {
  981. const char* type = "ws_register";
  982. Json::Value log;
  983. log["hdl"] = Json::Int64(hdl);
  984. log["78173721_logType"] = type;
  985. m_logTotal[hdl][type].num += 1;
  986. Json::Value detail;
  987. detail["web_transID"] = Json::Int64(web_transID);
  988. detail["inner_transID"] = Json::Int64(inner_transID);
  989. detail["entity"] = entity;
  990. detail["class"] = entityClass;
  991. detail["ret"] = ret;
  992. detail["operate"] = operate;
  993. #ifdef OUTPUT_DETAIL_LOG
  994. detail["payload"] = payload;
  995. #endif
  996. detail["retDetail"] = retDetail;
  997. detail["reason"] = reason;
  998. log["detail"] = detail;
  999. log["timestamp"] = getCurrentTimestamp();
  1000. if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
  1001. log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
  1002. log["threadId"] = Json::Int64(GetCurrentThreadId());
  1003. writeLog(LOG_LEVEL_DEBUG, log);
  1004. }
  1005. void LogManager::logWebSocketRequest(int64_t hdl,
  1006. int64_t web_transID,
  1007. int64_t inner_transID,
  1008. int64_t sessionId,
  1009. const std::string& entity,
  1010. const std::string& function,
  1011. int ret,
  1012. const std::string& operate,
  1013. const std::string& payload,
  1014. int retDetail,
  1015. const std::string& reason) {
  1016. const char* type = "ws_request";
  1017. Json::Value log;
  1018. log["hdl"] = Json::Int64(hdl);
  1019. log["78173721_logType"] = type;
  1020. m_logTotal[hdl][type].num += 1;
  1021. Json::Value detail;
  1022. detail["web_transID"] = Json::Int64(web_transID);
  1023. detail["inner_transID"] = Json::Int64(inner_transID);
  1024. detail["sessionId"] = Json::Int64(sessionId);
  1025. detail["entity"] = entity;
  1026. detail["function"] = function;
  1027. detail["ret"] = ret;
  1028. detail["operate"] = operate;
  1029. detail["retDetail"] = retDetail;
  1030. detail["reason"] = reason;
  1031. #ifdef OUTPUT_DETAIL_LOG
  1032. detail["payload"] = payload;
  1033. #endif
  1034. log["detail"] = detail;
  1035. log["timestamp"] = getCurrentTimestamp();
  1036. if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
  1037. log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
  1038. log["threadId"] = Json::Int64(GetCurrentThreadId());
  1039. writeLog(LOG_LEVEL_DEBUG, log);
  1040. }
  1041. void LogManager::logWebSocketSetVar(int64_t hdl,
  1042. int64_t web_transID,
  1043. int64_t inner_transID,
  1044. const std::string& name,
  1045. const std::string& value,
  1046. int ret,
  1047. const std::string& operate,
  1048. const std::string& payload,
  1049. int retDetail,
  1050. const std::string& reason) {
  1051. const char* type = "ws_setvar";
  1052. Json::Value log;
  1053. log["hdl"] = Json::Int64(hdl);
  1054. log["78173721_logType"] = type;
  1055. m_logTotal[hdl][type].num += 1;
  1056. Json::Value detail;
  1057. detail["web_transID"] = Json::Int64(web_transID);
  1058. detail["inner_transID"] = Json::Int64(inner_transID);
  1059. detail["name"] = name;
  1060. detail["value"] = value;
  1061. detail["ret"] = ret;
  1062. detail["operate"] = operate;
  1063. detail["retDetail"] = retDetail;
  1064. detail["reason"] = reason;
  1065. #ifdef OUTPUT_DETAIL_LOG
  1066. detail["payload"] = payload;
  1067. #endif
  1068. log["detail"] = detail;
  1069. log["timestamp"] = getCurrentTimestamp();
  1070. if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
  1071. log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
  1072. log["threadId"] = Json::Int64(GetCurrentThreadId());
  1073. writeLog(LOG_LEVEL_DEBUG, log);
  1074. }
  1075. void LogManager::logWebSocketGetVar(int64_t hdl,
  1076. int64_t web_transID,
  1077. int64_t inner_transID,
  1078. const std::string& name,
  1079. int ret,
  1080. const std::string& operate,
  1081. const std::string& payload,
  1082. int retDetail,
  1083. const std::string& reason) {
  1084. const char* type = "ws_getvar";
  1085. Json::Value log;
  1086. log["hdl"] = Json::Int64(hdl);
  1087. log["78173721_logType"] = type;
  1088. m_logTotal[hdl][type].num += 1;
  1089. Json::Value detail;
  1090. detail["web_transID"] = Json::Int64(web_transID);
  1091. detail["inner_transID"] = Json::Int64(inner_transID);
  1092. detail["name"] = name;
  1093. detail["ret"] = ret;
  1094. detail["operate"] = operate;
  1095. detail["retDetail"] = retDetail;
  1096. detail["reason"] = reason;
  1097. #ifdef OUTPUT_DETAIL_LOG
  1098. detail["payload"] = payload;
  1099. #endif
  1100. log["detail"] = detail;
  1101. log["timestamp"] = getCurrentTimestamp();
  1102. if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
  1103. log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
  1104. log["threadId"] = Json::Int64(GetCurrentThreadId());
  1105. writeLog(LOG_LEVEL_DEBUG, log);
  1106. }
  1107. void LogManager::logWebSocketBroadcast(int64_t hdl,
  1108. const std::string& entity,
  1109. int ret,
  1110. const std::string& operate,
  1111. const std::string& payload,
  1112. int retDetail,
  1113. const std::string& reason) {
  1114. const char* type = "ws_broadcast";
  1115. Json::Value log;
  1116. log["hdl"] = Json::Int64(hdl);
  1117. log["78173721_logType"] = type;
  1118. m_logTotal[hdl][type].num += 1;
  1119. Json::Value detail;
  1120. detail["entity"] = entity;
  1121. detail["ret"] = ret;
  1122. detail["operate"] = operate;
  1123. detail["retDetail"] = retDetail;
  1124. detail["reason"] = reason;
  1125. #ifdef OUTPUT_DETAIL_LOG
  1126. detail["payload"] = payload;
  1127. #endif
  1128. log["detail"] = detail;
  1129. log["timestamp"] = getCurrentTimestamp();
  1130. if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
  1131. log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
  1132. log["threadId"] = Json::Int64(GetCurrentThreadId());
  1133. writeLog(LOG_LEVEL_DEBUG, log);
  1134. }
  1135. void LogManager::logVtmEndSession(int64_t hdl,
  1136. const std::string& entity,
  1137. int64_t sessionId,
  1138. int ret,
  1139. const std::string& operate,
  1140. const std::string& payload,
  1141. int retDetail,
  1142. const std::string& reason) {
  1143. const char* type = "vtm_endsession";
  1144. Json::Value log;
  1145. log["hdl"] = Json::Int64(hdl);
  1146. log["78173721_logType"] = type;
  1147. m_logTotal[hdl][type].num += 1;
  1148. Json::Value detail;
  1149. detail["entity"] = entity;
  1150. detail["sessionId"] = Json::Int64(sessionId);
  1151. detail["ret"] = ret;
  1152. detail["operate"] = operate;
  1153. detail["retDetail"] = retDetail;
  1154. detail["reason"] = reason;
  1155. #ifdef OUTPUT_DETAIL_LOG
  1156. detail["payload"] = payload;
  1157. #endif
  1158. log["detail"] = detail;
  1159. log["timestamp"] = getCurrentTimestamp();
  1160. if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
  1161. log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
  1162. log["threadId"] = Json::Int64(GetCurrentThreadId());
  1163. writeLog(LOG_LEVEL_DEBUG, log);
  1164. }
  1165. void LogManager::logVtmRequestAck(int64_t hdl,
  1166. int64_t web_transID,
  1167. int64_t inner_transID,
  1168. int64_t sessionId,
  1169. const std::string& entity,
  1170. const std::string& function,
  1171. int ret,
  1172. const std::string& operate,
  1173. const std::string& payload,
  1174. const std::string& srcByte,
  1175. int retDetail,
  1176. const std::string& reason) {
  1177. const char* type = "vtm_requestAck";
  1178. Json::Value log;
  1179. log["hdl"] = Json::Int64(hdl);
  1180. log["78173721_logType"] = type;
  1181. m_logTotal[hdl][type].num += 1;
  1182. Json::Value detail;
  1183. detail["web_transID"] = Json::Int64(web_transID);
  1184. detail["inner_transID"] = Json::Int64(inner_transID);
  1185. detail["sessionId"] = Json::Int64(sessionId);
  1186. detail["entity"] = entity;
  1187. detail["function"] = function;
  1188. detail["ret"] = ret;
  1189. detail["operate"] = operate;
  1190. #ifdef OUTPUT_DETAIL_LOG
  1191. detail["payload"] = payload;
  1192. detail["srcByte"] = srcByte;
  1193. #endif
  1194. detail["retDetail"] = retDetail;
  1195. detail["reason"] = reason;
  1196. log["detail"] = detail;
  1197. log["timestamp"] = getCurrentTimestamp();
  1198. if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
  1199. log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
  1200. log["threadId"] = Json::Int64(GetCurrentThreadId());
  1201. writeLog(LOG_LEVEL_DEBUG, log);
  1202. }
  1203. void LogManager::logVtmEvent(int64_t hdl,
  1204. int64_t inner_transID,
  1205. int64_t sessionId,
  1206. const std::string& entity,
  1207. int ret,
  1208. const std::string& operate,
  1209. const std::vector<std::pair<int, int>>& transIdAndhdl_arr,
  1210. const std::string& payload,
  1211. const std::string& srcByte,
  1212. int retDetail,
  1213. const std::string& reason) {
  1214. const char* type = "vtm_event";
  1215. Json::Value log;
  1216. log["hdl"] = Json::Int64(hdl);
  1217. log["78173721_logType"] = type;
  1218. m_logTotal[hdl][type].num += 1;
  1219. Json::Value detail;
  1220. detail["inner_transID"] = Json::Int64(inner_transID);
  1221. detail["sessionId"] = Json::Int64(sessionId);
  1222. detail["entity"] = entity;
  1223. detail["ret"] = ret;
  1224. detail["operate"] = operate;
  1225. Json::Value transIdAndhdl_json(Json::arrayValue);
  1226. for (const auto& pair : transIdAndhdl_arr) {
  1227. Json::Value pairJson(Json::objectValue);
  1228. pairJson["transId"] = Json::Int64(pair.first);
  1229. pairJson["hdl"] = Json::Int64(pair.second);
  1230. transIdAndhdl_json.append(pairJson);
  1231. }
  1232. detail["transIdAndhdl_arr"] = transIdAndhdl_json;
  1233. #ifdef OUTPUT_DETAIL_LOG
  1234. detail["payload"] = payload;
  1235. detail["srcByte"] = srcByte;
  1236. #endif
  1237. detail["retDetail"] = retDetail;
  1238. detail["reason"] = reason;
  1239. log["detail"] = detail;
  1240. log["timestamp"] = getCurrentTimestamp();
  1241. if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
  1242. log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
  1243. log["threadId"] = Json::Int64(GetCurrentThreadId());
  1244. writeLog(LOG_LEVEL_DEBUG, log);
  1245. }
  1246. void LogManager::logVtmSessionAck(int64_t hdl,
  1247. int64_t web_transID,
  1248. int64_t inner_transID,
  1249. int64_t sessionId,
  1250. const std::string& entity,
  1251. int ret,
  1252. const std::string& operate,
  1253. const std::string& payload,
  1254. const std::string& srcByte,
  1255. int retDetail,
  1256. const std::string& reason) {
  1257. const char* type = "vtm_sessionAck";
  1258. Json::Value log;
  1259. log["hdl"] = Json::Int64(hdl);
  1260. log["78173721_logType"] = type;
  1261. m_logTotal[hdl][type].num += 1;
  1262. Json::Value detail;
  1263. detail["web_transID"] = Json::Int64(web_transID);
  1264. detail["inner_transID"] = Json::Int64(inner_transID);
  1265. detail["sessionId"] = Json::Int64(sessionId);
  1266. detail["entity"] = entity;
  1267. detail["ret"] = ret;
  1268. detail["operate"] = operate;
  1269. #ifdef OUTPUT_DETAIL_LOG
  1270. detail["payload"] = payload;
  1271. detail["srcByte"] = srcByte;
  1272. #endif
  1273. detail["retDetail"] = retDetail;
  1274. detail["reason"] = reason;
  1275. log["detail"] = detail;
  1276. log["timestamp"] = getCurrentTimestamp();
  1277. if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
  1278. log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
  1279. log["threadId"] = Json::Int64(GetCurrentThreadId());
  1280. writeLog(LOG_LEVEL_DEBUG, log);
  1281. }
  1282. void LogManager::logWsLogEvent(
  1283. int64_t hdl,
  1284. int securityLevel,
  1285. int eventCode,
  1286. const std::string& message,
  1287. int ret,
  1288. const std::string& operate,
  1289. const std::string& payload,
  1290. int retDetail,
  1291. const std::string& reason
  1292. ) {
  1293. const char* type = "ws_logEvent";
  1294. Json::Value log;
  1295. log["hdl"] = Json::Int64(hdl);
  1296. log["78173721_logType"] = type;
  1297. m_logTotal[hdl][type].num += 1;
  1298. Json::Value detail;
  1299. detail["securityLevel"] = securityLevel;
  1300. detail["eventCode"] = eventCode;
  1301. detail["message"] = message;
  1302. detail["ret"] = ret;
  1303. detail["operate"] = operate;
  1304. detail["retDetail"] = retDetail;
  1305. detail["reason"] = reason;
  1306. #ifdef OUTPUT_DETAIL_LOG
  1307. detail["payload"] = payload;
  1308. #endif
  1309. log["detail"] = detail;
  1310. log["timestamp"] = getCurrentTimestamp();
  1311. if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
  1312. log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
  1313. log["threadId"] = Json::Int64(GetCurrentThreadId());
  1314. writeLog(LOG_LEVEL_DEBUG, log);
  1315. }
  1316. void LogManager::logWsLogWarn(
  1317. int64_t hdl,
  1318. int securityLevel,
  1319. int eventCode,
  1320. const std::string& message,
  1321. int ret,
  1322. const std::string& operate,
  1323. const std::string& payload,
  1324. int retDetail,
  1325. const std::string& reason
  1326. ) {
  1327. const char* type = "ws_logWarn";
  1328. Json::Value log;
  1329. log["hdl"] = Json::Int64(hdl);
  1330. log["78173721_logType"] = type;
  1331. m_logTotal[hdl][type].num += 1;
  1332. Json::Value detail;
  1333. detail["securityLevel"] = securityLevel;
  1334. detail["eventCode"] = eventCode;
  1335. detail["ret"] = ret;
  1336. detail["operate"] = operate;
  1337. detail["retDetail"] = retDetail;
  1338. detail["reason"] = reason;
  1339. #ifdef OUTPUT_DETAIL_LOG
  1340. detail["payload"] = payload;
  1341. detail["message"] = message;
  1342. #endif
  1343. log["detail"] = detail;
  1344. log["timestamp"] = getCurrentTimestamp();
  1345. if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
  1346. log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
  1347. log["threadId"] = Json::Int64(GetCurrentThreadId());
  1348. writeLog(LOG_LEVEL_DEBUG, log);
  1349. }
  1350. void LogManager::logEntityOnLog(
  1351. const std::string& entity,
  1352. int64_t usercode,
  1353. const std::string& usercodeStr,
  1354. int ret,
  1355. const std::string& operate,
  1356. int retDetail,
  1357. const std::string& reason
  1358. ) {
  1359. Json::Value log;
  1360. log["78173721_logType"] = "entity_onlog";
  1361. Json::Value detail;
  1362. detail["entity"] = entity;
  1363. detail["usercode"] = Json::Int64(usercode);
  1364. detail["usercodeStr"] = usercodeStr;
  1365. detail["ret"] = ret;
  1366. detail["operate"] = operate;
  1367. detail["retDetail"] = retDetail;
  1368. detail["reason"] = reason;
  1369. log["detail"] = detail;
  1370. log["timestamp"] = getCurrentTimestamp();
  1371. log["threadId"] = Json::Int64(GetCurrentThreadId());
  1372. writeLog(LOG_LEVEL_INFO, log);
  1373. }
  1374. void LogManager::logEntityBegin(int no_startup) {
  1375. Json::Value log;
  1376. log["78173721_logType"] = "entity_begin";
  1377. Json::Value detail;
  1378. detail["no_startup"] = no_startup;
  1379. log["detail"] = detail;
  1380. log["threadId"] = Json::Int64(GetCurrentThreadId());
  1381. log["timestamp"] = getCurrentTimestamp();
  1382. writeLog(LOG_LEVEL_INFO, log);
  1383. }
  1384. void LogManager::logEntityOpenPage(
  1385. const std::string& pageType,
  1386. int64_t pid,
  1387. int ret,
  1388. const std::string& operate,
  1389. int retDetail,
  1390. const std::string& reason
  1391. ) {
  1392. Json::Value log;
  1393. log["78173721_logType"] = "entity_openPage";
  1394. Json::Value detail;
  1395. detail["pageType"] = pageType;
  1396. detail["pid"] = Json::Int64(pid);
  1397. detail["ret"] = ret;
  1398. detail["operate"] = operate;
  1399. detail["retDetail"] = retDetail;
  1400. detail["reason"] = reason;
  1401. log["detail"] = detail;
  1402. log["threadId"] = Json::Int64(GetCurrentThreadId());
  1403. log["timestamp"] = getCurrentTimestamp();
  1404. writeLog(LOG_LEVEL_INFO, log);
  1405. }
  1406. void LogManager::logEntityStageChange(
  1407. const std::string& stage,
  1408. int ret,
  1409. const std::string& operate,
  1410. int retDetail,
  1411. const std::string& reason
  1412. ) {
  1413. Json::Value log;
  1414. log["78173721_logType"] = "entity_stageChange";
  1415. Json::Value detail;
  1416. detail["stage"] = stage;
  1417. detail["ret"] = ret;
  1418. detail["operate"] = operate;
  1419. detail["retDetail"] = retDetail;
  1420. detail["reason"] = reason;
  1421. log["detail"] = detail;
  1422. log["threadId"] = Json::Int64(GetCurrentThreadId());
  1423. log["timestamp"] = getCurrentTimestamp();
  1424. writeLog(LOG_LEVEL_INFO, log);
  1425. }
  1426. void LogManager::logEntityStatus(
  1427. const std::string& status,
  1428. int level,
  1429. int ret,
  1430. const std::string& operate,
  1431. int retDetail,
  1432. const std::string& reason
  1433. ) {
  1434. Json::Value log;
  1435. log["78173721_logType"] = "entity_status";
  1436. Json::Value detail;
  1437. detail["status"] = status;
  1438. detail["level"] = level;
  1439. detail["ret"] = ret;
  1440. detail["operate"] = operate;
  1441. detail["retDetail"] = retDetail;
  1442. detail["reason"] = reason;
  1443. log["detail"] = detail;
  1444. log["threadId"] = Json::Int64(GetCurrentThreadId());
  1445. log["timestamp"] = getCurrentTimestamp();
  1446. writeLog(LOG_LEVEL_INFO, log);
  1447. }