CommEntityUtil.hpp 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098
  1. #ifndef RVC_MOD_COMM_ENTITY_UTIL_HPP_
  2. #define RVC_MOD_COMM_ENTITY_UTIL_HPP_
  3. #if defined(_MSC_VER)
  4. #include <Windows.h>
  5. #include <TlHelp32.h>
  6. #include <iphlpapi.h>
  7. #include <ws2tcpip.h>
  8. #include <Winsock2.h>
  9. #include <IPTypes.h>
  10. #include <WinInet.h>
  11. #include <ShlObj.h>
  12. #include <Pdh.h>
  13. #pragma comment(lib, "IPHLPAPI.lib")
  14. #pragma comment(lib, "Wininet.lib")
  15. #pragma comment(lib, "pdh.lib")
  16. #define streq stricmp
  17. #else
  18. #include <net/if.h>
  19. #include <sys/ioctl.h>
  20. #include <unistd.h>
  21. #include <thread>
  22. #include <chrono>
  23. #define streq strcasecmp
  24. #endif //_MSC_VER
  25. #include "path.h"
  26. #include "toolkit.h"
  27. #include <string>
  28. #include <iostream>
  29. #include <sstream>
  30. #include <map>
  31. #include "SpBase.h"
  32. #include "publicFunExport.h"
  33. #define MACSESION 6
  34. #define DIV (1024 * 1024)
  35. #define DAY_DIV (24 * 60 * 60)
  36. #define HOURS_DIV (60 * 60)
  37. #define MINUS_DIV (60)
  38. typedef unsigned long long ULLINT;
  39. typedef CAutoArray<CSimpleStringA> NetworkAddressesList;
  40. #define SLEEP(interval) std::this_thread::sleep_for(std::chrono::milliseconds(interval))
  41. namespace SP
  42. {
  43. namespace Module
  44. {
  45. namespace System
  46. {
  47. static BOOL GetSystemBootTime(CSmallDateTime& systemBootTime)
  48. {
  49. #if defined(_MSC_VER)
  50. PDH_STATUS Status;
  51. HQUERY Query = NULL;
  52. HCOUNTER hcElapsedTimeCount;
  53. BOOL fSuc = FALSE;
  54. Status = PdhOpenQuery(NULL, NULL, &Query);
  55. PDH_FMT_COUNTERVALUE counterValue;
  56. if (Status != ERROR_SUCCESS) {
  57. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("PdhOpenQuery failed with status 0x%x.", Status);
  58. goto Cleanup;
  59. }
  60. Status = PdhAddCounter(Query, "\\System\\System Up Time", NULL, &hcElapsedTimeCount);
  61. if (Status != ERROR_SUCCESS) {
  62. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("PdhAddCounter for SystemElapsedQuery failed with status 0x%x.", Status);
  63. goto Cleanup;
  64. }
  65. // 查询性能监视器数据
  66. Status = PdhCollectQueryData(Query);
  67. if (Status != ERROR_SUCCESS) {
  68. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("PdhCollectQueryData failed with 0x%x.", Status);
  69. goto Cleanup;
  70. }
  71. Status = PdhGetFormattedCounterValue(hcElapsedTimeCount, PDH_FMT_LARGE, NULL, &counterValue);
  72. if (Status == ERROR_SUCCESS) {
  73. ULONGLONG ulSinceSeconds = counterValue.largeValue;
  74. ULONG days = 0, hours = 0, minutes = 0, seconds = 0;
  75. days = ULONG(ulSinceSeconds / DAY_DIV);
  76. ulSinceSeconds %= DAY_DIV;
  77. hours = ULONG(ulSinceSeconds / HOURS_DIV);
  78. ulSinceSeconds %= HOURS_DIV;
  79. minutes = ULONG(ulSinceSeconds / MINUS_DIV);
  80. ulSinceSeconds %= MINUS_DIV;
  81. seconds = ULONG(ulSinceSeconds);
  82. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("SystemElapseTime: %u:%02u:%02u:%02u", days, hours, minutes, seconds);
  83. FILETIME ftCurTime, ftStartTime;
  84. GetSystemTimeAsFileTime(&ftCurTime);
  85. ULARGE_INTEGER uliCurTime;
  86. uliCurTime.HighPart = ftCurTime.dwHighDateTime;
  87. uliCurTime.LowPart = ftCurTime.dwLowDateTime;
  88. uliCurTime.QuadPart -= counterValue.largeValue * 1e7;
  89. ftStartTime.dwHighDateTime = uliCurTime.HighPart;
  90. ftStartTime.dwLowDateTime = uliCurTime.LowPart;
  91. SYSTEMTIME stUTC, stLocal;
  92. FileTimeToSystemTime(&ftStartTime, &stUTC);
  93. char temp[22];
  94. SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);
  95. sprintf_s(temp, 22, "%d-%02d-%02d %02d:%02d:%02d",
  96. stLocal.wYear, stLocal.wMonth, stLocal.wDay, stLocal.wHour, stLocal.wMinute, stLocal.wSecond);
  97. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("OSStartTime: %s", temp);
  98. systemBootTime.FromSystemTime(stLocal);
  99. fSuc = TRUE;
  100. }
  101. Cleanup:
  102. Status = PdhRemoveCounter(hcElapsedTimeCount);
  103. if (Query) {
  104. PdhCloseQuery(Query);
  105. }
  106. return fSuc;
  107. #else
  108. ///*TODO(80374374@3/7/2023): */
  109. return FALSE;
  110. #endif //_MSC_VER
  111. }
  112. }//system
  113. namespace Comm
  114. {
  115. /** Rely on ${OTHER_LIB_BASE_DIR}/libpublicFun and library target libpublicFun*/
  116. struct LogNotiyMessageStruct
  117. {
  118. std::string Reason;
  119. std::string ErrMsg;
  120. std::string RebootTime;
  121. LogNotiyMessageStruct(const CSimpleStringA& reason, const CSimpleStringA& errmsg, const CSimpleStringA& rebootTime)
  122. :Reason(reason.GetData()), ErrMsg(reason.GetData()), RebootTime(reason.GetData())
  123. {
  124. }
  125. LogNotiyMessageStruct(const std::string& reason, const std::string& errmsg, const std::string& rebootTime)
  126. :Reason(reason), ErrMsg(errmsg), RebootTime(rebootTime)
  127. {
  128. }
  129. LogNotiyMessageStruct(const char* reason, const char* errmsg, char* rebootTime)
  130. :Reason(reason), ErrMsg(errmsg), RebootTime(rebootTime)
  131. {
  132. }
  133. LogNotiyMessageStruct(const char* errmsg)
  134. :Reason(""), ErrMsg(errmsg), RebootTime("")
  135. {
  136. }
  137. std::string ToJsonString() const {
  138. std::map<std::string, std::string> srcData;
  139. srcData.insert(std::make_pair("reason", Reason));
  140. srcData.insert(std::make_pair("errmsg", ErrMsg));
  141. srcData.insert(std::make_pair("rebootTime", RebootTime));
  142. auto ret = generateJsonStr(srcData);
  143. if (ret.first) {
  144. return ret.second;
  145. } else {
  146. return ErrMsg;
  147. }
  148. }
  149. };
  150. struct LogCommNotiyStruct
  151. {
  152. NotifyLevelEnum eLevel;
  153. ErrorCodeEnum eSysCode;
  154. DWORD dwUserCode;
  155. LogCommNotiyStruct() :eLevel(Notify_None), eSysCode(Error_Unexpect), dwUserCode(0) {}
  156. LogCommNotiyStruct(NotifyLevelEnum level, ErrorCodeEnum errorCode, DWORD dwUserCode)
  157. :eLevel(level), eSysCode(errorCode), dwUserCode(dwUserCode) {}
  158. LogCommNotiyStruct(NotifyLevelEnum level, ErrorCodeEnum errorCode)
  159. :eLevel(level), eSysCode(errorCode), dwUserCode(0)
  160. { }
  161. virtual ~LogCommNotiyStruct() {}
  162. virtual void Notify(const LogNotiyMessageStruct& notifyMessage)
  163. {
  164. LogNotify(eLevel, eSysCode, dwUserCode, notifyMessage.ToJsonString().c_str());
  165. }
  166. };
  167. struct LogInfoNotiyStruct : public LogCommNotiyStruct
  168. {
  169. LogInfoNotiyStruct(ErrorCodeEnum errorCode, DWORD dwUserCode)
  170. :LogCommNotiyStruct(Notify_Info, errorCode, dwUserCode){}
  171. ~LogInfoNotiyStruct() {}
  172. };
  173. struct LogWarnNotiyStruct : public LogCommNotiyStruct
  174. {
  175. LogWarnNotiyStruct(ErrorCodeEnum errorCode, DWORD dwUserCode)
  176. :LogCommNotiyStruct(Notify_Warn, errorCode, dwUserCode)
  177. {
  178. }
  179. ~LogWarnNotiyStruct() {}
  180. };
  181. struct LogErrorNotiyStruct : public LogCommNotiyStruct
  182. {
  183. LogErrorNotiyStruct(ErrorCodeEnum errorCode, DWORD dwUserCode)
  184. :LogCommNotiyStruct(Notify_Error, errorCode, dwUserCode)
  185. {
  186. }
  187. ~LogErrorNotiyStruct() {}
  188. };
  189. static BOOL IsFirsRunAppAfterSystemBoot(CEntityBase* pEntity)
  190. {
  191. BOOL result(FALSE);
  192. CSystemRunInfo runInfo = { 0 };
  193. ErrorCodeEnum ec = pEntity->GetFunction()->GetSystemRunInfo(runInfo);
  194. if (ec == Error_Succeed) {
  195. CBootInfo bootInfo = { 0 };
  196. CSmallDateTime dateTime;
  197. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("systemRunInfo time: %s", (LPCTSTR)runInfo.tmStart.ToTimeString());
  198. ec = pEntity->GetFunction()->GetRebootInfo(/*runInfo.tmStart*/dateTime, bootInfo);
  199. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("bootInfor time: %s", (LPCTSTR)bootInfo.tmStart.ToTimeString());
  200. CSmallDateTime systemBootTime;
  201. const BOOL bRet = System::GetSystemBootTime(systemBootTime);
  202. if (bRet && systemBootTime > bootInfo.tmStart) {
  203. result = TRUE;
  204. }
  205. }
  206. return result;
  207. }
  208. inline
  209. CSimpleStringA GetCurrMachineType(CEntityBase* pEntity)
  210. {
  211. CSystemStaticInfo sysInfo;
  212. pEntity->GetFunction()->GetSystemStaticInfo(sysInfo);
  213. return sysInfo.strMachineType;
  214. }
  215. inline
  216. CSimpleStringA GetCurrEntityConfigPath(CEntityBase* pEntity)
  217. {
  218. CSimpleStringA strConfigDir(true);
  219. pEntity->GetFunction()->GetPath("cfg", strConfigDir);
  220. CSimpleStringA result(strConfigDir + SPLIT_SLASH_STR + pEntity->GetEntityName() + ".ini");
  221. Dbg("config path: %s", result.GetData());
  222. return result;
  223. }
  224. enum Site
  225. {
  226. CMB_UNKNOWN,
  227. CMB_LIB, /** 行内大堂*/
  228. CMB_FLB, /** 离行机器*/
  229. };
  230. #define SITE_ENUM_TYPE(MACRO) \
  231. MACRO(LIB)\
  232. MACRO(FLB)
  233. #define ENUM_MAP_CONVERT(elem) \
  234. if (streq(lpcszSiteName, "CMB."#elem) == 0) return CMB_##elem;
  235. /*!
  236. * convert cmb site name to enum type.
  237. */
  238. static Site Str2Site(LPCSTR lpcszSiteName)
  239. {
  240. if (lpcszSiteName == NULL || strlen(lpcszSiteName) == 0)
  241. return CMB_UNKNOWN;
  242. SITE_ENUM_TYPE(ENUM_MAP_CONVERT)
  243. return CMB_UNKNOWN;
  244. }
  245. #undef ENUM_MAP_CONVERT
  246. #define ENUM_MAP_CONVERT(elem) case CMB_##elem: return "CMB."#elem;
  247. static LPCSTR Site2Str(Site site)
  248. {
  249. switch (site) {
  250. SITE_ENUM_TYPE(ENUM_MAP_CONVERT)
  251. default:
  252. break;
  253. }
  254. return "Unkown";
  255. }
  256. enum What
  257. {
  258. RVC_UNKNOWN,
  259. RVC_Stand2S, /** 落地式大机*/
  260. RVC_PAD, /** PAD*/
  261. RVC_Desk2S, /** 低柜双屏*/
  262. RVC_CardStore, /** 卡库*/
  263. RVC_CardPrinter, /** 制卡机*/
  264. RVC_Stand1SPlus /** 单屏大机*/
  265. };
  266. #define MACHINE_ENUM_TYPE(MACRO) \
  267. MACRO(Stand2S)\
  268. MACRO(PAD)\
  269. MACRO(Desk2S)\
  270. MACRO(CardStore)\
  271. MACRO(CardPrinter)\
  272. MACRO(Stand1SPlus)
  273. #undef ENUM_MAP_CONVERT
  274. #define ENUM_MAP_CONVERT(elem) \
  275. if (streq(lpcszTypeName, "RVC."#elem) == 0) return RVC_##elem;
  276. /*!
  277. * convert cmb site name to enum type.
  278. */
  279. static What Str2Type(LPCSTR lpcszTypeName)
  280. {
  281. if (lpcszTypeName == NULL || strlen(lpcszTypeName) == 0)
  282. return RVC_UNKNOWN;
  283. MACHINE_ENUM_TYPE(ENUM_MAP_CONVERT)
  284. return RVC_UNKNOWN;
  285. }
  286. #undef ENUM_MAP_CONVERT
  287. #define ENUM_MAP_CONVERT(elem) case RVC_##elem: return "RVC."#elem;
  288. static LPCSTR Type2Str(What what)
  289. {
  290. switch (what) {
  291. MACHINE_ENUM_TYPE(ENUM_MAP_CONVERT)
  292. default:
  293. break;
  294. }
  295. return "Unkown";
  296. }
  297. struct TerminalMachineInfo
  298. {
  299. Site site;
  300. What type;
  301. struct {
  302. WORD minor;
  303. WORD major;
  304. } gen;
  305. };
  306. inline TerminalMachineInfo GetTerminalMachineInfo(CEntityBase* pEntity)
  307. {
  308. CSystemStaticInfo sysInfo;
  309. TerminalMachineInfo termInfo;
  310. pEntity->GetFunction()->GetSystemStaticInfo(sysInfo);
  311. termInfo.site = Str2Site(sysInfo.strSite);
  312. termInfo.type = Str2Type(sysInfo.strMachineType);
  313. termInfo.gen.major = sysInfo.MachineVersion.GetMajor();
  314. termInfo.gen.minor = sysInfo.MachineVersion.GetMinor();
  315. return termInfo;
  316. }
  317. inline ULLINT RVCGetTickCount()
  318. {
  319. #ifdef RVC_OS_WIN
  320. return GetTickCount64();
  321. #else
  322. struct timespec ts;
  323. clock_gettime(CLOCK_MONOTONIC, &ts);
  324. return (ts.tv_sec * 1000 + ts.tv_nsec / 1000000);
  325. #endif // RVC_OS_WIN
  326. }
  327. } // comm
  328. namespace Util
  329. {
  330. static int StrBuf2HexBuf(const char* strBuf, PBYTE* hexBuf)
  331. {
  332. int len = strlen(strBuf);
  333. if (len == 0 || len % 2 != 0)
  334. return 0;
  335. BYTE* buf = new BYTE[len / 2];
  336. if (buf == NULL)
  337. return 0;
  338. int j = 0;
  339. for (int i = 0; i < len;) {
  340. int tmpVal;
  341. sscanf(strBuf + i, "%2X", &tmpVal);
  342. buf[j] = tmpVal;
  343. i += 2;
  344. j++;
  345. }
  346. *hexBuf = buf;
  347. return j;
  348. }
  349. static int HexBuf2StrBuf(PBYTE hexBuf, char** strBuf, DWORD len)
  350. {
  351. char* tmpStr = *strBuf;
  352. DWORD count = 0;
  353. for (DWORD i = 0; i < len; ++i) {
  354. sprintf(tmpStr + count, "%0.2X", hexBuf[i]);
  355. count += 2;
  356. }
  357. return 0;
  358. }
  359. //tips: need to delete result char*
  360. static char* ConvertBytesToHexStr(BYTE* pBuf, int nLen)
  361. {
  362. char* pRet = (char*)new char[nLen * 2 + 1];
  363. memset(pRet, '\0', nLen * 2 + 1);
  364. char* p = pRet;
  365. for (int i = 0; i < nLen; i++) {
  366. BYTE b = pBuf[i];
  367. BYTE l = (b >> 4) & 0x0F;
  368. if (l >= 10)
  369. *p = l - 10 + 'a';
  370. else
  371. *p = l + '0';
  372. p++;
  373. BYTE r = b & 0x0F;
  374. if (r >= 10)
  375. *p = r - 10 + 'a';
  376. else
  377. *p = r + '0';
  378. p++;
  379. }
  380. return pRet;
  381. }
  382. static char HexChar2Dec(char c)
  383. {
  384. if ((c >= '0') && (c <= '9'))
  385. return c - '0';
  386. else if ((c >= 'A') && (c <= 'F'))
  387. return c - 'A' + 10;
  388. else if ((c >= 'a') && (c <= 'f'))
  389. return c - 'a' + 10;
  390. else
  391. return 0x10;
  392. }
  393. static int Hex2Int(char* s)
  394. {
  395. int ret = 0;
  396. while (*s) {
  397. int t = HexChar2Dec(*s);
  398. ret = ret * 16 + t;
  399. ++s;
  400. }
  401. return ret;
  402. }
  403. static void ConvAscii(unsigned char* Hex, char* Ascii, unsigned int len)
  404. {
  405. const unsigned char hextable[] = { "0123456789ABCDEF" };
  406. unsigned int i;
  407. for (i = 0; i < len; i++) {
  408. Ascii[2 * i] = hextable[Hex[i] >> 4];
  409. Ascii[2 * i + 1] = hextable[Hex[i] & 0xf];
  410. }
  411. Ascii[2 * len] = 0;
  412. }
  413. static void AsciiToHex(char* Ascii, unsigned char* Hex, int len)
  414. {
  415. int i;
  416. unsigned char ch;
  417. for (i = 0; i < len; i = i + 2) {
  418. ch = (Ascii[i] & 0xf);
  419. if (Ascii[i] > '9')
  420. ch += 9;
  421. Hex[i / 2] = ch << 4;
  422. ch = Ascii[i + 1] & 0xf;
  423. if (Ascii[i + 1] > '9')
  424. ch += 9;
  425. Hex[i / 2] += ch;
  426. }
  427. }
  428. static bool IsNoStr(const char* str)
  429. {
  430. int len = strlen(str);
  431. if (len == 0)
  432. return true;
  433. for (int i = 0; i < len; ++i) {
  434. if (*(str + i) != ' ')
  435. return false;
  436. }
  437. return true;
  438. }
  439. static DWORD GetDuration(const SYSTEMTIME& time1, const SYSTEMTIME& time2)
  440. {
  441. #if defined(RVC_OS_WIN)
  442. ULARGE_INTEGER fTime1;/*FILETIME*/
  443. ULARGE_INTEGER fTime2;/*FILETIME*/
  444. SystemTimeToFileTime(&time1, (FILETIME*)&fTime1);
  445. SystemTimeToFileTime(&time2, (FILETIME*)&fTime2);
  446. unsigned __int64 dft = fTime2.QuadPart - fTime1.QuadPart;
  447. return DWORD(dft / 10000);
  448. #else
  449. ///**TODO(Gifur@9/3/2021): Bug 不能这样简单的实现,考虑凌晨,切换月份甚至是年份 */
  450. DWORD s1, s2;
  451. s1 = (time1.wMinute * 60 + time1.wSecond) * 1000 + time1.wMilliseconds;
  452. s2 = (time2.wMinute * 60 + time2.wSecond) * 1000 + time2.wMilliseconds;
  453. return s2 - s1;
  454. #endif //RVC_OS_WIN
  455. }
  456. static std::string formatTime(const SYSTEMTIME& time)
  457. {
  458. char tBuf[1024] = "";
  459. sprintf(tBuf, "%04u-%02u-%02u %02u:%02u:%02u:%03u", time.wYear, time.wMonth, time.wDay, time.wHour, time.wMinute, time.wSecond, time.wMilliseconds);
  460. return tBuf;
  461. }
  462. static bool ShellExecute(const std::string& cmd, std::string& succResult, std::string& errResult)
  463. {
  464. #if defined(_MSC_VER)
  465. ///*TODO(80374374@3/7/2023): */
  466. return false;
  467. #else
  468. char buf_ps[1024];
  469. char ps[1024] = { 0 };
  470. char result[2049] = { 0 };
  471. FILE* ptr;
  472. strcpy(ps, cmd.c_str());
  473. succResult = errResult = "";
  474. if ((ptr = popen(ps, "r")) != NULL) {
  475. while (fgets(buf_ps, 1024, ptr) != NULL) {
  476. if (strlen(result) + strlen(buf_ps) > 2048)
  477. break;
  478. strcat(result, buf_ps);
  479. }
  480. pclose(ptr);
  481. const int len = strlen(result);
  482. for (int i = len - 1; i >= 0 && (result[i] == '\r' || result[i] == '\n'); --i) {
  483. result[i] = '\0';
  484. }
  485. succResult = result;
  486. return true;
  487. } else {
  488. sprintf(result, "popen %s error: %d", ps, errno);
  489. errResult = result;
  490. return false;
  491. }
  492. #endif //_MSC_VER
  493. }
  494. static CSimpleStringA generateConsumeTimeJson(const CSimpleStringA& entityName, const CSimpleStringA& startTime, int cost)
  495. {
  496. return CSimpleStringA::Format("[{\"name\":\"%s\",\"time\":\"%s\",\"cost\":%d}]", entityName.GetData(), startTime.GetData(), cost);
  497. }
  498. #if defined(_MSC_VER)
  499. static char* ConvertUtf8ToGBK(const char* strUtf8)
  500. {
  501. int len = MultiByteToWideChar(CP_UTF8, 0, strUtf8, -1, NULL, 0);
  502. WCHAR* wszGBK = new WCHAR[len + 1];
  503. memset(wszGBK, 0, len * 2 + 2);
  504. MultiByteToWideChar(CP_UTF8, 0, strUtf8, -1, wszGBK, len);
  505. len = WideCharToMultiByte(CP_ACP, 0, wszGBK, -1, NULL, 0, NULL, NULL);
  506. char* szGBK = new char[len + 1];
  507. memset(szGBK, 0, len + 1);
  508. WideCharToMultiByte(CP_ACP, 0, wszGBK, -1, szGBK, len, NULL, NULL);
  509. delete[] wszGBK;
  510. return szGBK;
  511. }
  512. static void ConvertUtf8ToGBK(std::string& str)
  513. {
  514. char* dst = ConvertUtf8ToGBK(str.c_str());
  515. str = dst;
  516. delete[] dst;
  517. }
  518. static char* ConvertGBKToUtf8(const char* gbk, int* n)
  519. {
  520. int len = MultiByteToWideChar(CP_ACP, 0, gbk, -1, NULL, 0);
  521. WCHAR* wszGBK = new WCHAR[len + 1];
  522. memset(wszGBK, 0, len * 2 + 2);
  523. MultiByteToWideChar(CP_ACP, 0, gbk, -1, wszGBK, len);
  524. len = WideCharToMultiByte(CP_UTF8, 0, wszGBK, -1, NULL, 0, NULL, NULL);
  525. char* szUtf8 = new char[len + 1];
  526. memset(szUtf8, 0, len + 1);
  527. WideCharToMultiByte(CP_UTF8, 0, wszGBK, -1, szUtf8, len, NULL, NULL);
  528. delete[] wszGBK;
  529. *n = len - 1;
  530. return szUtf8;
  531. }
  532. static void ConvertGBKToUtf8(std::string& str)
  533. {
  534. int len = 0;
  535. char* dst = ConvertGBKToUtf8(str.c_str(), &len);
  536. str = dst;
  537. delete[] dst;
  538. }
  539. #endif //_MSC_VER
  540. static std::string W2S(const std::wstring wstr)
  541. {
  542. #if defined(_MSC_VER)
  543. char* str = NULL;
  544. int n = ::WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, NULL, 0, NULL, NULL);
  545. if (n > 0) {
  546. str = new char[n + 1];
  547. if (str == NULL) {
  548. return std::string();
  549. }
  550. std::memset(str, 0, sizeof(char) * (n + 1));
  551. ::WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, &str[0], n, NULL, NULL);
  552. std::string strr(str);
  553. delete str;
  554. return strr;
  555. }
  556. #else
  557. ///*TODO(80374374@3/7/2023): */
  558. #endif //_MSC_VER
  559. return std::string();
  560. }
  561. static std::wstring S2W(const std::string str)
  562. {
  563. #if defined(_MSC_VER)
  564. wchar_t* wstr = NULL;
  565. int n = ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, NULL, 0);
  566. if (n > 0) {
  567. wstr = new wchar_t[n + 1];
  568. if (wstr == NULL) {
  569. return std::wstring();
  570. }
  571. std::memset(wstr, 0, (n + 1) * sizeof(wchar_t));
  572. ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, &wstr[0], n);
  573. std::wstring strr(wstr);
  574. delete wstr;
  575. return strr;
  576. }
  577. #else
  578. ///*TODO(80374374@3/7/2023): */
  579. #endif //_MSC_VER
  580. return std::wstring();
  581. }
  582. } //namespace Util
  583. namespace Net{
  584. struct NetworkAdapterItem
  585. {
  586. int idx;
  587. std::string friend_name;
  588. std::string adapter_name;
  589. std::string description;
  590. std::string ip;
  591. std::string mask;
  592. std::string mac;
  593. std::string gateway;
  594. std::string dhcp;
  595. bool is_physical;
  596. DWORD type;
  597. int operStatus;
  598. bool isLocal;
  599. NetworkAdapterItem() :idx(0), friend_name(""), adapter_name(""), description(""), ip(""), mask(""),
  600. mac(""), gateway(""), dhcp(""), is_physical(true), type(0), operStatus(0), isLocal(false)
  601. {
  602. }
  603. };
  604. static bool IsLocalAdapter(const std::string& name)
  605. {
  606. #if defined(_MSC_VER)
  607. if (name.length() <= 0) {
  608. return false;
  609. }
  610. std::string key("SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}");
  611. HKEY h_sub_key = NULL;
  612. LONG ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, key.c_str(), 0, KEY_READ, &h_sub_key);
  613. if (ret != 0) {
  614. return false;
  615. }
  616. std::ostringstream str;
  617. str << name << "\\Connection";
  618. HKEY h_local_key = NULL;
  619. ret = RegOpenKeyEx(h_sub_key, str.str().c_str(), 0, KEY_READ, &h_local_key);
  620. if (0 != ret) {
  621. RegCloseKey(h_sub_key);
  622. return false;
  623. }
  624. DWORD type = REG_SZ;
  625. TCHAR buf[250];
  626. DWORD buf_size = 250;
  627. ret = RegQueryValueEx(h_local_key, "PnPInstanceId", 0, &type, (BYTE*)(buf), &buf_size);
  628. RegCloseKey(h_sub_key);
  629. RegCloseKey(h_local_key);
  630. if (0 != ret) {
  631. return false;
  632. }
  633. if (0 == strnicmp(buf, "PCI", strlen("PCI")) || 0 == strnicmp(buf, "USB", strlen("USB"))) {
  634. return true;
  635. }
  636. return false;
  637. #else
  638. ///*TODO(80374374@3/7/2023): */
  639. return true;
  640. #endif //_MSC_VER
  641. }
  642. static ErrorCodeEnum GetINETMacAddresses(NetworkAddressesList& macList, NetworkAddressesList& ipList)
  643. {
  644. #if defined(RVC_OS_WIN)
  645. PIP_ADAPTER_ADDRESSES pAddresses = NULL;
  646. ULONG family = AF_INET;
  647. ULONG flags = GAA_FLAG_INCLUDE_PREFIX;
  648. ULONG outBufLen = sizeof(IP_ADAPTER_ADDRESSES);
  649. // Make an initial call to GetAdaptersAddresses to get the
  650. // size needed into the outBufLen variable
  651. if (GetAdaptersAddresses(family, flags, NULL, pAddresses, &outBufLen) == ERROR_BUFFER_OVERFLOW) {
  652. pAddresses = static_cast<PIP_ADAPTER_ADDRESSES>(HeapAlloc(GetProcessHeap(), 0, outBufLen));
  653. }
  654. if (NULL == pAddresses) {
  655. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("pAddresses = NULL");
  656. return Error_Unexpect;
  657. }
  658. DWORD dwRetVal = GetAdaptersAddresses(family, flags, NULL, pAddresses, &outBufLen);
  659. /* MACAddresses vAddress;*/
  660. if (dwRetVal != ERROR_SUCCESS) {
  661. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("dwRetVal = %d", dwRetVal);
  662. return Error_Unexpect;
  663. }
  664. PIP_ADAPTER_ADDRESSES pFirst = pAddresses;
  665. while (pAddresses) {
  666. if (pAddresses->FirstUnicastAddress->Address.lpSockaddr->sa_family == AF_INET &&
  667. pAddresses->OperStatus == IfOperStatusUp &&
  668. pAddresses->IfType != IF_TYPE_SOFTWARE_LOOPBACK) {
  669. BYTE* pa = pAddresses->PhysicalAddress;
  670. if (!pa) {
  671. pAddresses = pAddresses->Next ? pAddresses->Next : NULL;
  672. continue;
  673. }
  674. CSimpleStringA strFriendlyName(true);
  675. CSimpleStringA strDescription(true);
  676. DWORD dwNum = WideCharToMultiByte(CP_OEMCP, NULL, pAddresses->FriendlyName, -1, NULL, 0, NULL, FALSE);
  677. char* psText = new char[dwNum];
  678. if (psText != NULL) {
  679. WideCharToMultiByte(CP_OEMCP, NULL, pAddresses->FriendlyName, -1, psText, dwNum, NULL, FALSE);
  680. strFriendlyName = psText;
  681. delete[] psText;
  682. }
  683. dwNum = WideCharToMultiByte(CP_OEMCP, NULL, pAddresses->Description, -1, NULL, 0, NULL, FALSE);
  684. psText = new char[dwNum];
  685. if (psText != NULL) {
  686. WideCharToMultiByte(CP_OEMCP, NULL, pAddresses->Description, -1, psText, dwNum, NULL, FALSE);
  687. strDescription = psText;
  688. delete[] psText;
  689. }
  690. char bAddressBytes[MACSESION];
  691. int bAddressInt[MACSESION];
  692. memset(bAddressBytes, 0, MACSESION);
  693. size_t nAddressSize = pAddresses->PhysicalAddressLength;
  694. memcpy(bAddressBytes, pa, (nAddressSize < MACSESION ? nAddressSize : MACSESION));
  695. for (int i = 0; i < MACSESION; ++i) {
  696. bAddressInt[i] = bAddressBytes[i];
  697. bAddressInt[i] &= 0x000000ff; // avoid "ff" leading bytes when "char" is lager then 0x7f
  698. }
  699. CSimpleStringA tmpmac = CSimpleStringA::Format("%02x:%02x:%02x:%02x:%02x:%02x",
  700. bAddressInt[0],
  701. bAddressInt[1],
  702. bAddressInt[2],
  703. bAddressInt[3],
  704. bAddressInt[4],
  705. bAddressInt[5]);
  706. macList.Append(&tmpmac, 0, 1);
  707. sockaddr_in* sa_in = (sockaddr_in*)pAddresses->FirstUnicastAddress->Address.lpSockaddr;
  708. char buf_addr[100] = { 0 };
  709. CSimpleStringA tmpip = CSimpleStringA(inet_ntop(AF_INET, &(sa_in->sin_addr), buf_addr, 100));
  710. ipList.Append(&tmpip, 0, 1);
  711. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s, %s: OperStatus: %d, IfType = %d, ip=%s, mac=%s"
  712. , strFriendlyName.GetData(), strDescription.GetData()
  713. , pAddresses->OperStatus, pAddresses->IfType, tmpip.GetData(), tmpmac.GetData());
  714. }
  715. pAddresses = pAddresses->Next ? pAddresses->Next : NULL;
  716. }
  717. HeapFree(GetProcessHeap(), 0, pFirst);
  718. return Error_Succeed;
  719. #else
  720. std::map<std::string, std::string> inteIPs;
  721. std::map<std::string, std::string> inteMacs;
  722. char buf[512];
  723. toolkit_interface_address_t* info;
  724. int count, i;
  725. toolkit_interface_addresses(&info, &count);
  726. i = count;
  727. Dbg("Number of interfaces: %d", count);
  728. while (i--) {
  729. toolkit_interface_address_t interface = info[i];
  730. Dbg("Name: %s", interface.name);
  731. Dbg("Internal? %s", interface.is_internal ? "Yes" : "No");
  732. if (interface.address.address4.sin_family == AF_INET) {
  733. toolkit_ip4_name(&interface.address.address4, buf, sizeof(buf));
  734. Dbg("IPv4 address: %s", buf);
  735. inteIPs[interface.name] = buf;
  736. } else if (interface.address.address4.sin_family == AF_INET6) {
  737. toolkit_ip6_name(&interface.address.address6, buf, sizeof(buf));
  738. Dbg("IPv6 address: %s", buf);
  739. //inteIPs[interface.name] = buf;
  740. }
  741. }
  742. toolkit_free_interface_addresses(info, count);
  743. {
  744. int fd, interface;
  745. struct ifreq buf[16];
  746. struct ifconf ifc;
  747. char mac[32] = { 0 };
  748. if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) >= 0) {
  749. int i = 0;
  750. ifc.ifc_len = sizeof(buf);
  751. ifc.ifc_buf = (caddr_t)buf;
  752. if (!ioctl(fd, SIOCGIFCONF, (char*)&ifc)) {
  753. interface = ifc.ifc_len / sizeof(struct ifreq);
  754. Dbg("interface num is %d", interface);
  755. while (i < interface) {
  756. Dbg("Name: %s", buf[i].ifr_name);
  757. if (!(ioctl(fd, SIOCGIFHWADDR, (char*)&buf[i]))) {
  758. sprintf(mac, "%02X:%02X:%02X:%02X:%02X:%02X",
  759. (unsigned char)buf[i].ifr_hwaddr.sa_data[0],
  760. (unsigned char)buf[i].ifr_hwaddr.sa_data[1],
  761. (unsigned char)buf[i].ifr_hwaddr.sa_data[2],
  762. (unsigned char)buf[i].ifr_hwaddr.sa_data[3],
  763. (unsigned char)buf[i].ifr_hwaddr.sa_data[4],
  764. (unsigned char)buf[i].ifr_hwaddr.sa_data[5]);
  765. Dbg("HWaddr %s", mac);
  766. inteMacs[buf[i].ifr_name] = mac;
  767. }
  768. i++;
  769. }
  770. }
  771. close(fd);
  772. }
  773. }
  774. std::map<std::string, std::string>::const_iterator map_it = inteIPs.begin();
  775. while (map_it != inteIPs.end()) {
  776. CSimpleStringA tmpip(map_it->second.c_str());
  777. CSimpleStringA tmpmac(true);
  778. auto it = inteMacs.find(std::string(map_it->first));
  779. if (it != inteMacs.end()) {
  780. tmpmac = it->second.c_str();
  781. }
  782. if (tmpip.Compare("127.0.0.1") == 0 && tmpmac.Compare("00:00:00:00:00:00") == 0) {
  783. //skip
  784. } else {
  785. ipList.Append(&tmpip, 0, 1);
  786. macList.Append(&tmpmac, 0, 1);
  787. }
  788. ++map_it;
  789. }
  790. return Error_Succeed;
  791. #endif //RVC_OS_WIN
  792. }
  793. static std::vector<NetworkAdapterItem> GetNetAdapterItems()
  794. {
  795. std::vector<NetworkAdapterItem> results;
  796. #if defined(_MSC_VER)
  797. ULONG flags = GAA_FLAG_INCLUDE_PREFIX | GAA_FLAG_INCLUDE_GATEWAYS;
  798. ULONG family = AF_UNSPEC;
  799. PIP_ADAPTER_ADDRESSES address_ptr = nullptr;
  800. ULONG out_buf_len = 15000;
  801. DWORD ret_val = 0;
  802. PIP_ADAPTER_ADDRESSES cur_addr_ptr = nullptr;
  803. PIP_ADAPTER_UNICAST_ADDRESS unicast_ptr = nullptr;
  804. PIP_ADAPTER_ANYCAST_ADDRESS anycast_ptr = nullptr;
  805. PIP_ADAPTER_MULTICAST_ADDRESS multicast_ptr = nullptr;
  806. PIP_ADAPTER_DNS_SERVER_ADDRESS dns_server_ptr = nullptr;
  807. IP_ADAPTER_PREFIX* prefix_ptr = nullptr;
  808. do {
  809. address_ptr = (PIP_ADAPTER_ADDRESSES)malloc(out_buf_len);
  810. if (address_ptr == nullptr) {
  811. return results;
  812. }
  813. ret_val = GetAdaptersAddresses(family, flags, NULL, address_ptr, &out_buf_len);
  814. if (ERROR_BUFFER_OVERFLOW == ret_val) {
  815. free(address_ptr);
  816. }
  817. } while (ret_val == ERROR_BUFFER_OVERFLOW);
  818. if (NO_ERROR == ret_val) {
  819. cur_addr_ptr = address_ptr;
  820. while (cur_addr_ptr) {
  821. std::string description = Util::W2S(cur_addr_ptr->Description);
  822. bool is_local = IsLocalAdapter(cur_addr_ptr->AdapterName);
  823. std::string friend_name = Util::W2S(cur_addr_ptr->FriendlyName);
  824. NetworkAdapterItem item;
  825. item.idx = cur_addr_ptr->IfIndex;
  826. item.adapter_name = cur_addr_ptr->AdapterName;
  827. item.description = description;
  828. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)(">>>>>>>>>>>>>>> friendly name: %s", friend_name.c_str());
  829. item.friend_name = friend_name;
  830. if (is_local) {
  831. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Adapter Desc: %s", description.c_str());
  832. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Adapter Name: %s", cur_addr_ptr->AdapterName);
  833. item.isLocal = true;
  834. }
  835. if (cur_addr_ptr->PhysicalAddressLength != 0) {
  836. char sz_addr[32] = { 0 };
  837. std::stringstream str;
  838. for (int i = 0; i < (int)cur_addr_ptr->PhysicalAddressLength; i++) {
  839. if (i == ((int)cur_addr_ptr->PhysicalAddressLength - 1))
  840. sprintf_s(sz_addr, "%.2X", (int)cur_addr_ptr->PhysicalAddress[i]);
  841. else
  842. sprintf_s(sz_addr, "%.2X:", (int)cur_addr_ptr->PhysicalAddress[i]);
  843. str << sz_addr;
  844. }
  845. item.mac = str.str();
  846. }
  847. item.type = cur_addr_ptr->IfType;
  848. item.operStatus = cur_addr_ptr->OperStatus;
  849. switch (cur_addr_ptr->IfType) {
  850. case MIB_IF_TYPE_OTHER:
  851. break;
  852. case MIB_IF_TYPE_ETHERNET:
  853. break;
  854. case MIB_IF_TYPE_TOKENRING:
  855. break;
  856. case MIB_IF_TYPE_FDDI:
  857. break;
  858. case MIB_IF_TYPE_PPP:
  859. break;
  860. case MIB_IF_TYPE_LOOPBACK:
  861. break;
  862. case MIB_IF_TYPE_SLIP:
  863. break;
  864. case IF_TYPE_IEEE80211:
  865. break;
  866. case IF_TYPE_WWANPP:
  867. case IF_TYPE_WWANPP2:
  868. //WWAN devices
  869. break;
  870. default:
  871. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Unknown type %d", cur_addr_ptr->IfType);
  872. break;
  873. }
  874. unicast_ptr = cur_addr_ptr->FirstUnicastAddress;
  875. while (unicast_ptr) {
  876. char ip[120] = { 0 };
  877. if (AF_INET == unicast_ptr->Address.lpSockaddr->sa_family) {
  878. inet_ntop(PF_INET, &((sockaddr_in*)unicast_ptr->Address.lpSockaddr)->sin_addr, ip, sizeof(ip));
  879. } else if (AF_INET6 == unicast_ptr->Address.lpSockaddr->sa_family) {
  880. inet_ntop(PF_INET6, &((sockaddr_in*)unicast_ptr->Address.lpSockaddr)->sin_addr, ip, sizeof(ip));
  881. }
  882. unicast_ptr = unicast_ptr->Next;
  883. }
  884. if (cur_addr_ptr->Dhcpv4Server.lpSockaddr) {
  885. char ip[120] = { 0 };
  886. if (AF_INET == cur_addr_ptr->Dhcpv4Server.lpSockaddr->sa_family) {
  887. inet_ntop(PF_INET, &((sockaddr_in*)cur_addr_ptr->Dhcpv4Server.lpSockaddr)->sin_addr, ip, sizeof(ip));
  888. } else if (AF_INET6 == cur_addr_ptr->Dhcpv4Server.lpSockaddr->sa_family) {
  889. inet_ntop(PF_INET6, &((sockaddr_in*)cur_addr_ptr->Dhcpv4Server.lpSockaddr)->sin_addr, ip, sizeof(ip));
  890. }
  891. item.dhcp = ip;
  892. }
  893. dns_server_ptr = cur_addr_ptr->FirstDnsServerAddress;
  894. while (dns_server_ptr) {
  895. char ip[120] = { 0 };
  896. if (AF_INET == dns_server_ptr->Address.lpSockaddr->sa_family) {
  897. inet_ntop(PF_INET, &((sockaddr_in*)dns_server_ptr->Address.lpSockaddr)->sin_addr, ip, sizeof(ip));
  898. } else if (AF_INET6 == dns_server_ptr->Address.lpSockaddr->sa_family) {
  899. inet_ntop(PF_INET6, &((sockaddr_in*)dns_server_ptr->Address.lpSockaddr)->sin_addr, ip, sizeof(ip));
  900. }
  901. dns_server_ptr = dns_server_ptr->Next;
  902. }
  903. auto gateway_ptr = cur_addr_ptr->FirstGatewayAddress;
  904. while (gateway_ptr) {
  905. char ip[120] = { 0 };
  906. if (AF_INET == gateway_ptr->Address.lpSockaddr->sa_family) {
  907. inet_ntop(PF_INET, &((sockaddr_in*)gateway_ptr->Address.lpSockaddr)->sin_addr, ip, sizeof(ip));
  908. } else if (AF_INET6 == gateway_ptr->Address.lpSockaddr->sa_family) {
  909. inet_ntop(PF_INET6, &((sockaddr_in*)gateway_ptr->Address.lpSockaddr)->sin_addr, ip, sizeof(ip));
  910. }
  911. gateway_ptr = gateway_ptr->Next;
  912. }
  913. results.push_back(item);
  914. cur_addr_ptr = cur_addr_ptr->Next;
  915. }
  916. } else {
  917. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("GetAdaptersAddresses failed with error: %d", ret_val);
  918. }
  919. free(address_ptr);
  920. #else
  921. ///*TODO(80374374@3/7/2023): */
  922. #endif //_MSC_VER
  923. return results;
  924. }
  925. static BOOL CheckLANConnectStatus()
  926. {
  927. #if defined(_MSC_VER)
  928. DWORD dwFlag(0);
  929. BOOL bRet = InternetGetConnectedState(&dwFlag, 0);
  930. if ((dwFlag & INTERNET_CONNECTION_CONFIGURED) == INTERNET_CONNECTION_CONFIGURED) {
  931. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Local system has a valid connection to the Internet, but it might or might not be currently connected.");
  932. }
  933. if ((dwFlag & INTERNET_CONNECTION_LAN) == INTERNET_CONNECTION_LAN) {
  934. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Local system uses a local area network to connect to the Internet.");
  935. }
  936. if ((dwFlag & INTERNET_CONNECTION_MODEM) == INTERNET_CONNECTION_MODEM) {
  937. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Local system uses a modem to connect to the Internet.");
  938. }
  939. if ((dwFlag & INTERNET_CONNECTION_MODEM_BUSY) == INTERNET_CONNECTION_MODEM_BUSY) {
  940. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("No longer used: INTERNET_CONNECTION_MODEM_BUSY");
  941. }
  942. if ((dwFlag & INTERNET_CONNECTION_OFFLINE) == INTERNET_CONNECTION_OFFLINE) {
  943. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Local system is in offline mode.");
  944. }
  945. if ((dwFlag & INTERNET_CONNECTION_PROXY) == INTERNET_CONNECTION_PROXY) {
  946. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Local system uses a proxy server to connect to the Internet.");
  947. }
  948. if ((dwFlag & INTERNET_RAS_INSTALLED) == INTERNET_RAS_INSTALLED) {
  949. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Local system has RAS installed.");
  950. }
  951. if (bRet) {
  952. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("InternetGetConnectedState Succeed: 0x%08X", dwFlag);
  953. } else {
  954. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("InternetGetConnectedState failed: 0x%08X, GLE=%u", dwFlag, GetLastError());
  955. }
  956. return bRet;
  957. #else
  958. return FALSE;
  959. #endif //_MSC_VER
  960. }
  961. static std::string GetWWWInfoThroughDig(const std::string& wwwUrl)
  962. {
  963. std::string succStr, errStr;
  964. std::string runStr("dig ");
  965. runStr += wwwUrl;
  966. if (SP::Module::Util::ShellExecute(runStr, succStr, errStr)) {
  967. return succStr;
  968. } else {
  969. return std::string("ShellExecute(") + wwwUrl + ") failed";
  970. }
  971. }
  972. }//Net
  973. } // mod
  974. } // sp
  975. #endif //RVC_MOD_COMM_ENTITY_UTIL_HPP_