|
|
@@ -1,7 +1,9 @@
|
|
|
#include "stdafx.h"
|
|
|
#include <algorithm>
|
|
|
+#include <fstream>
|
|
|
#include <winpr/file.h>
|
|
|
#include "fileutil.h"
|
|
|
+#include "RVCEventCode.h"
|
|
|
#include "VtmLoaderFSM.h"
|
|
|
#include "VtmLoader_UserCode.h"
|
|
|
#include "EventCode.h"
|
|
|
@@ -330,9 +332,9 @@ unsigned int CVtmLoaderFSM::s0_on_event(FSMEvent* pEvt)
|
|
|
case USER_EVT_QUERY_LOCAL_INFO:
|
|
|
pEvt->SetHandled();
|
|
|
{
|
|
|
- QueryLocalInfoEvent* pEvt = dynamic_cast<QueryLocalInfoEvent*>(pEvt);
|
|
|
+ QueryLocalInfoEvent* qlie = dynamic_cast<QueryLocalInfoEvent*>(pEvt);
|
|
|
QueryLocalInfoTask* pTask = new QueryLocalInfoTask(this);
|
|
|
- pTask->ctx = pEvt->ctx;
|
|
|
+ pTask->ctx = qlie->ctx;
|
|
|
GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
|
|
|
}
|
|
|
break;
|
|
|
@@ -850,6 +852,15 @@ unsigned int CVtmLoaderFSM::s4_on_event(FSMEvent* pEvt)
|
|
|
GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
|
|
|
}
|
|
|
break;
|
|
|
+ case USER_EVT_QUERY_LOCAL_INFO:
|
|
|
+ pEvt->SetHandled();
|
|
|
+ {
|
|
|
+ QueryLocalInfoEvent* qlie = dynamic_cast<QueryLocalInfoEvent*>(pEvt);
|
|
|
+ QueryLocalInfoTask* pTask = new QueryLocalInfoTask(this);
|
|
|
+ pTask->ctx = qlie->ctx;
|
|
|
+ GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
|
|
|
+ }
|
|
|
+ break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
@@ -889,6 +900,15 @@ unsigned int CVtmLoaderFSM::s5_on_event(FSMEvent* pEvt)
|
|
|
GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
|
|
|
}
|
|
|
break;
|
|
|
+ case USER_EVT_QUERY_LOCAL_INFO:
|
|
|
+ pEvt->SetHandled();
|
|
|
+ {
|
|
|
+ QueryLocalInfoEvent* qlie = dynamic_cast<QueryLocalInfoEvent*>(pEvt);
|
|
|
+ QueryLocalInfoTask* pTask = new QueryLocalInfoTask(this);
|
|
|
+ pTask->ctx = qlie->ctx;
|
|
|
+ GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
|
|
|
+ }
|
|
|
+ break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
@@ -1888,11 +1908,10 @@ int CVtmLoaderFSM::HttpConnCheck(CSimpleStringA csHttAddr, HttpAddrType eType)
|
|
|
CAutoArray<NetworkAdapterItem> netList;
|
|
|
if (SP::Module::Net::GetINETMacAddresses(netList) == Error_Succeed)
|
|
|
{
|
|
|
- string tmpDns;
|
|
|
- GetDns(tmpDns);
|
|
|
+ CSimpleStringA tmpDns = GetDns();
|
|
|
for (int i = 0; i < netList.GetCount(); i++) {
|
|
|
LogWarn(Severity_Low, Error_Unexpect, VtmLoader_BootInfoPrint, CSimpleStringA::Format("(%d)interface:%s; ip:%s; mac:%s; %s", i, netList[i].description.c_str()
|
|
|
- , netList[i].ip.c_str(), netList[i].mac.c_str(), tmpDns.c_str()).GetData());
|
|
|
+ , netList[i].ip.c_str(), netList[i].mac.c_str(), tmpDns.GetData()).GetData());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1912,37 +1931,63 @@ int CVtmLoaderFSM::HttpConnCheck(CSimpleStringA csHttAddr, HttpAddrType eType)
|
|
|
|
|
|
return -1;
|
|
|
}
|
|
|
-void CVtmLoaderFSM::GetDns(string& dns)
|
|
|
+CSimpleStringA CVtmLoaderFSM::GetDns()
|
|
|
{
|
|
|
- dns = "";
|
|
|
-#if defined(RVC_OS_LINUX)
|
|
|
-
|
|
|
- FILE* stream;
|
|
|
- char* line = NULL;
|
|
|
- size_t len = 0;
|
|
|
- ssize_t read;
|
|
|
-
|
|
|
- stream = popen("cat /etc/resolv.conf", "r");
|
|
|
- string tmpStr;
|
|
|
- while ((read = getline(&line, &len, stream)) != -1)
|
|
|
- {
|
|
|
- tmpStr = line;
|
|
|
- int pos = tmpStr.find("nameserver");
|
|
|
- if (pos != string::npos)
|
|
|
- {
|
|
|
- tmpStr = tmpStr.replace(pos, strlen("nameserver"), "dns");
|
|
|
- dns += tmpStr + ";";
|
|
|
- }
|
|
|
+ CSimpleStringA runInfoPath, csDNSKeyword, csTmpDns("");
|
|
|
+ ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("runinfo", runInfoPath);
|
|
|
+ if (eErr != Error_Succeed) {
|
|
|
+ DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("GetPath runinfo error=%d.", eErr);
|
|
|
+ return "";
|
|
|
}
|
|
|
- int rnPos = dns.find("\n");
|
|
|
- while (rnPos != string::npos)
|
|
|
+ runInfoPath = runInfoPath + SPLIT_SLASH_STR + "runcfg" + SPLIT_SLASH_STR + "dns";
|
|
|
+
|
|
|
+#if defined(RVC_OS_WIN)
|
|
|
+ CSimpleStringA csCmd;
|
|
|
+ csCmd = CSimpleStringA::Format("cmd /c ipconfig /all >%s", runInfoPath.GetData());
|
|
|
+ WinExec((LPCSTR)csCmd, SW_HIDE);
|
|
|
+ csDNSKeyword = "DNS 服务器";
|
|
|
+#else
|
|
|
+ std::string sucContent, failedContent;
|
|
|
+ CSimpleStringA strCmd;
|
|
|
+ strCmd = CSimpleStringA::Format("cat /etc/resolv.conf | grep \"nameserver\" >%s", runInfoPath.GetData());
|
|
|
+ bool ret = SP::Module::Util::ShellExecute(strCmd.GetData(), sucContent, failedContent);
|
|
|
+ csDNSKeyword = "nameserver";
|
|
|
+#endif //RVC_OS_WIN
|
|
|
+ ifstream is;
|
|
|
+ is.open(runInfoPath.GetData(), ios::binary);
|
|
|
+ if (!is.is_open())
|
|
|
{
|
|
|
- dns.replace(rnPos, 1, " ");
|
|
|
- rnPos = dns.find("\n");
|
|
|
+ DWORD dwErr = GetLastError();
|
|
|
+ DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("open %s file failed. [%d]", runInfoPath.GetData(), dwErr);
|
|
|
+ return "";
|
|
|
}
|
|
|
+
|
|
|
+ string line;
|
|
|
+ while (!is.eof()) {
|
|
|
+ getline(is, line);
|
|
|
+ //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("line:%s", line.c_str());
|
|
|
+ size_t start = line.find(csDNSKeyword.GetData());
|
|
|
+ if (start != string::npos)
|
|
|
+ {
|
|
|
+#if defined(RVC_OS_WIN)
|
|
|
+ int dnsStart = line.find(": ");
|
|
|
+ if (dnsStart != string::npos)
|
|
|
+ {
|
|
|
+ string xDns = SP::Utility::ToTrim(line.substr(dnsStart + 1, line.length() - dnsStart - 1));
|
|
|
+ csTmpDns += xDns.c_str();
|
|
|
+ csTmpDns += ";";
|
|
|
+ }
|
|
|
#else
|
|
|
+ string xDns = SP::Utility::ToTrim(line.substr(start + csDNSKeyword.GetLength() + 1, line.length() - start - csDNSKeyword.GetLength() - 1));
|
|
|
+ csTmpDns += xDns.c_str();
|
|
|
+ csTmpDns += ";";
|
|
|
#endif
|
|
|
- return;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ return csTmpDns;
|
|
|
}
|
|
|
void CVtmLoaderFSM::ToCheckIfInstalling()
|
|
|
{
|
|
|
@@ -3076,6 +3121,61 @@ void CVtmLoaderFSM::OnCentersettingUpdateTimeout(void* pData)
|
|
|
GetCenterCfgThread();
|
|
|
GetEntityBase()->GetFunction()->ResetTimer(TIMER_CENTERSETTING_UPDATE_CHECK, CENTERSETTING_UPDATE_CHECK_TIME);
|
|
|
}
|
|
|
+
|
|
|
+CSimpleStringA CVtmLoaderFSM::GetOsVersion()
|
|
|
+{
|
|
|
+#if defined(RVC_OS_WIN)
|
|
|
+ CSimpleStringA runInfoPath;
|
|
|
+ ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("runinfo", runInfoPath);
|
|
|
+ if (eErr != Error_Succeed) {
|
|
|
+ DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setResultCode(RTAERR_GETPATH_FAILED)("GetPath runinfo error=%d.", eErr);
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ runInfoPath += "\\runcfg\\osverion";
|
|
|
+ ifstream is;
|
|
|
+ is.open(runInfoPath.GetData(), ios::binary);
|
|
|
+ if (!is.is_open())
|
|
|
+ {
|
|
|
+ DWORD dwErr = GetLastError();
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("open runcfg\\osverion file failed. [%d]", dwErr);
|
|
|
+ CSimpleStringA csCmd;
|
|
|
+ csCmd = CSimpleStringA::Format("cmd /c ver >%s", runInfoPath);
|
|
|
+ WinExec((LPCSTR)csCmd, SW_HIDE);
|
|
|
+ }
|
|
|
+ is.seekg(0, std::ios::beg);
|
|
|
+ string line;
|
|
|
+ while (!is.eof()) {
|
|
|
+ getline(is, line);
|
|
|
+ int start = line.find("版本");
|
|
|
+ if (start != string::npos)
|
|
|
+ //return CSimpleStringA(line.substr(start + 5, line.length() - start - 7).c_str());
|
|
|
+ return CSimpleStringA(line.c_str());
|
|
|
+ else
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+#else
|
|
|
+ std::map<std::string, std::string> osInfo;
|
|
|
+ const char filePath[] = "/etc/os-version";
|
|
|
+ char tmp[33];
|
|
|
+ memset(tmp, 0, 33);
|
|
|
+ inifile_read_str_s("Version", "SystemName", "unknown", tmp, 32, filePath);
|
|
|
+ osInfo["SystemName"] = tmp;
|
|
|
+ memset(tmp, 0, 33);
|
|
|
+ inifile_read_str_s("Version", "ProductType", "unknown", tmp, 32, filePath);
|
|
|
+ osInfo["ProductType"] = tmp;
|
|
|
+ memset(tmp, 0, 33);
|
|
|
+ inifile_read_str_s("Version", "MajorVersion", "unknown", tmp, 32, filePath);
|
|
|
+ osInfo["MajorVersion"] = tmp;
|
|
|
+ memset(tmp, 0, 33);
|
|
|
+ inifile_read_str_s("Version", "MinorVersion", "unknown", tmp, 32, filePath);
|
|
|
+ osInfo["MinorVersion"] = tmp;
|
|
|
+ memset(tmp, 0, 33);
|
|
|
+ inifile_read_str_s("Version", "OsBuild", "unknown", tmp, 32, filePath);
|
|
|
+ osInfo["OsBuild"] = tmp;
|
|
|
+ return generateJsonStr(osInfo).second.c_str();
|
|
|
+#endif
|
|
|
+}
|
|
|
void CVtmLoaderFSM::QueryLocalInfo(SpReqAnsContext<VtmLoaderService_QueryLocalInfo_Req, VtmLoaderService_QueryLocalInfo_Ans>::Pointer ctx)
|
|
|
{
|
|
|
#ifdef RVC_OS_WIN
|
|
|
@@ -3083,5 +3183,29 @@ void CVtmLoaderFSM::QueryLocalInfo(SpReqAnsContext<VtmLoaderService_QueryLocalIn
|
|
|
#elif
|
|
|
ctx->Ans.VtmAppType = "UOS";
|
|
|
#endif
|
|
|
+ CSimpleStringA csRunPath("");
|
|
|
+ GetEntityBase()->GetFunction()->GetPath("Run", csRunPath);
|
|
|
+ ctx->Ans.AppPath = csRunPath;
|
|
|
+
|
|
|
+ CAutoArray<NetworkAdapterItem> netList;
|
|
|
+ if (SP::Module::Net::GetINETMacAddresses(netList) == Error_Succeed)
|
|
|
+ {
|
|
|
+ CSimpleStringA csMac(""), csIP("");
|
|
|
+ for (int i = 0; i < netList.GetCount(); i++) {
|
|
|
+ if (!csMac.IsNullOrEmpty()) {
|
|
|
+ csMac += ";";
|
|
|
+ }
|
|
|
+ csMac += netList[i].mac.c_str();
|
|
|
+ if (!csIP.IsNullOrEmpty()) {
|
|
|
+ csIP += ";";
|
|
|
+ }
|
|
|
+ csIP += netList[i].ip.c_str();
|
|
|
+ }
|
|
|
+ ctx->Ans.IPs = csIP;
|
|
|
+ ctx->Ans.MACs = csMac;
|
|
|
+ }
|
|
|
+ ctx->Ans.DNSs = GetDns();
|
|
|
+ ctx->Ans.OSVersion = GetOsVersion();
|
|
|
+
|
|
|
ctx->Answer(Error_Succeed);
|
|
|
}
|