|
@@ -10,9 +10,64 @@ using std::regex;
|
|
|
#include "fileutil.h"
|
|
|
#include "iniutil.h"
|
|
|
|
|
|
+#if defined(RVC_OS_WIN)
|
|
|
+#pragma comment(lib, "crypt32.lib")
|
|
|
+#endif //RVC_OS_WIN
|
|
|
+
|
|
|
+
|
|
|
+bool CenterSettingResponse::Parse(string strData)
|
|
|
+{
|
|
|
+ Json::Value root;
|
|
|
+ Json::Reader reader;
|
|
|
+ reader.parse(strData, root, false);
|
|
|
+
|
|
|
+ bSuccess = root["success"].asBool();
|
|
|
+
|
|
|
+ if(bSuccess)
|
|
|
+ {
|
|
|
+ for(int i = 0; i < 2; ++i)
|
|
|
+ {
|
|
|
+
|
|
|
+ if(root["data"][sites[i]].isNull())
|
|
|
+ {
|
|
|
+ Dbg("%s config is NULL.", sites[i].c_str());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ configOfOneBranch.m_lastUpdateTime = root["data"][sites[i]]["lastUpdateTime"].asString();
|
|
|
+ configOfOneBranch.m_branchNo = root["data"][sites[i]]["branchNo"].asString();
|
|
|
+ if(sites[i] == "BIZ")
|
|
|
+ configOfOneBranch.m_site = "LAN";
|
|
|
+ else
|
|
|
+ configOfOneBranch.m_site = sites[i];
|
|
|
+ const string _site = configOfOneBranch.m_site;
|
|
|
+ configOfOneBranch.m_count = 0;
|
|
|
+ auto configArr = root["data"][sites[i]]["config"];
|
|
|
+ allConfigs[_site] = configOfOneBranch;
|
|
|
+ if(configArr.isArray()){
|
|
|
+ for(int j = 0; j < configArr.size(); j++)
|
|
|
+ {
|
|
|
+ allConfigs[_site].m_count++;
|
|
|
+ ConfigItem configItem;
|
|
|
+
|
|
|
+ configItem.m_cnName = configArr[j]["cnName"].asString();
|
|
|
+ configItem.m_moudle = configArr[j]["moudle"].asString();
|
|
|
+ configItem.m_name = configArr[j]["name"].asString();
|
|
|
+ configItem.m_remark = configArr[j]["remark"].asString();
|
|
|
+ configItem.m_value = configArr[j]["value"].asString();
|
|
|
+
|
|
|
+ allConfigs[_site].configSet.push_back(configItem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
CCenterSettingConn::CCenterSettingConn(CEntityBase *pEntity)
|
|
|
: SpSecureClient(pEntity)
|
|
|
{
|
|
|
+ GetConfig();
|
|
|
}
|
|
|
|
|
|
|
|
@@ -99,6 +154,15 @@ ErrorCodeEnum CCenterSettingConn::BeginPollConfig(const CSystemStaticInfo& info)
|
|
|
assert(pFunc != NULL);
|
|
|
CSimpleStringA strPath;
|
|
|
pFunc->GetPath("Cfg", strPath);
|
|
|
+
|
|
|
+ if(DeleteErrorFiles(strPath))
|
|
|
+ {
|
|
|
+ Dbg("delete error files succ.(hyc)");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Dbg("delete error files failed.(hyc)");
|
|
|
+ }
|
|
|
auto pPackage = CreateNewPackage("PollSM");
|
|
|
const int nArrayNum = pEntity->m_SyncFileInfo.size();
|
|
|
if (nArrayNum> 0)
|
|
@@ -170,10 +234,11 @@ ErrorCodeEnum CCenterSettingConn::OnEndPollConfig(const CSmartPointer<IPackage>
|
|
|
CSimpleStringA strCurStructName = CSimpleStringA::Format("PollSMA%d", nIndex);
|
|
|
|
|
|
int nRetLen = pRecvPkg->GetStructLen(strCurStructName);
|
|
|
- if (nRetLen == -1) {
|
|
|
- Dbg("Get %s pkg struct failed !", strCurStructName.GetData());
|
|
|
- break;
|
|
|
- }
|
|
|
+ if (nRetLen == -1)
|
|
|
+ {
|
|
|
+ Dbg("Get %s pkg struct failed !", strCurStructName.GetData());
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
nIndex++;
|
|
|
|
|
@@ -215,8 +280,15 @@ ErrorCodeEnum CCenterSettingConn::OnEndPollConfig(const CSmartPointer<IPackage>
|
|
|
pFunc->GetPath("Cfg", strPath);
|
|
|
CSimpleStringA strCurFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (const char*)strPath, (const char*)pRet->FileName);
|
|
|
|
|
|
+ CSimpleString strRunInfoPath;
|
|
|
+ ///**TODO(Gifur@9/16/2021): GetPath("RunCfg") implement! */
|
|
|
+ pFunc->GetPath("RunInfo", strRunInfoPath);
|
|
|
+ strRunInfoPath += SPLIT_SLASH_STR;
|
|
|
+ strRunInfoPath += "runcfg";
|
|
|
+ CSimpleStringA strNewPath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (const char*)strRunInfoPath, (const char*)pRet->FileName);
|
|
|
+
|
|
|
// 保存新配置文件
|
|
|
- CSimpleStringA strNewFile = strCurFile + ".new";
|
|
|
+ CSimpleStringA strNewFile = strNewPath + ".new";
|
|
|
auto hFile = fopen(strNewFile, "wb");
|
|
|
int nLen = fwrite(pRet->FileContent, 1, nRetLen - sizeof(PollSMA), hFile);
|
|
|
fflush(hFile);
|
|
@@ -243,7 +315,9 @@ ErrorCodeEnum CCenterSettingConn::OnEndPollConfig(const CSmartPointer<IPackage>
|
|
|
|
|
|
// 读出当前集中配置服务地址
|
|
|
memset(tmp, 0, 32);
|
|
|
- inifile_read_str_s("CenterSetting", "Server", "", tmp, 32, strCurFile);
|
|
|
+ if (10 > inifile_read_str_s("CenterSetting", "Server", "", tmp, 32, strCurFile)) {
|
|
|
+ Dbg("read center setting service addr from exist file %s fail: (%d)", strCurFile.GetData(), GetLastError());
|
|
|
+ }
|
|
|
CSimpleStringA strCurServer = tmp;
|
|
|
|
|
|
// 写入同步信息
|
|
@@ -257,24 +331,24 @@ ErrorCodeEnum CCenterSettingConn::OnEndPollConfig(const CSmartPointer<IPackage>
|
|
|
|
|
|
// 保存原配置文件
|
|
|
|
|
|
- time_t t = time(NULL);
|
|
|
- tm* t1 = localtime(&t);
|
|
|
|
|
|
- //SYSTEMTIME st = {};
|
|
|
- //GetLocalTime(&st);
|
|
|
- //CSimpleStringA strBackFile = CSimpleStringA::Format("%s.%04d%02d%02d%02d%02d", (const char*)strCurFile,
|
|
|
- // st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute);
|
|
|
- CSimpleStringA strBackFile = CSimpleStringA::Format("%s.%04d%02d%02d%02d%02d", (const char*)strCurFile,
|
|
|
- t1->tm_year + 1900, t1->tm_mon + 1, t1->tm_mday, t1->tm_hour, t1->tm_min);
|
|
|
+#if defined(RVC_OS_WIN)
|
|
|
+ SYSTEMTIME st = {};
|
|
|
+ GetLocalTime(&st);
|
|
|
+ CSimpleStringA strBackFile = CSimpleStringA::Format("%s.%04d%02d%02d%02d%02d", (const char*)strCurFile,
|
|
|
+ st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute);
|
|
|
+#else
|
|
|
+ time_t t = time(NULL);
|
|
|
+ tm* t1 = localtime(&t);
|
|
|
+ CSimpleStringA strBackFile = CSimpleStringA::Format("%s.%04d%02d%02d%02d%02d", (const char*)strCurFile,
|
|
|
+ t1->tm_year + 1900, t1->tm_mon + 1, t1->tm_mday, t1->tm_hour, t1->tm_min);
|
|
|
+#endif //RVC_OS_WIN
|
|
|
fileutil_copy_file(strBackFile, strCurFile);
|
|
|
- //CopyFileA(strCurFile, strBackFile, FALSE);
|
|
|
|
|
|
// 替换当前配置文件
|
|
|
fileutil_copy_file(strCurFile, strNewFile);
|
|
|
- //CopyFileA(strNewFile, strCurFile, FALSE);
|
|
|
fileutil_delete_file(strNewFile);
|
|
|
- //DeleteFileA(strNewFile);
|
|
|
- Dbg("Save config %s succ", (const char*)pRet->FileName);
|
|
|
+ Dbg("save config %s succ", (const char*)pRet->FileName);
|
|
|
|
|
|
// 保存同步信息
|
|
|
CCenterSettingEntity::ConfigFileInfo info;
|
|
@@ -317,3 +391,178 @@ ErrorCodeEnum CCenterSettingConn::OnEndPollConfig(const CSmartPointer<IPackage>
|
|
|
return Error_NotExist;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+bool CCenterSettingConn::DeleteErrorFiles(CSimpleStringA filePath)
|
|
|
+{
|
|
|
+ LOG_FUNCTION();
|
|
|
+ array_header_t* arr = fileutil_get_sub_files_a(filePath);
|
|
|
+ if (arr) {
|
|
|
+ for (int i = 0; i < arr->nelts; ++i) {
|
|
|
+ char* path = (char*)ARRAY_IDX(arr, i, char*);
|
|
|
+ regex reg("((DMZ)|(LAN))[^(\.ini)]");
|
|
|
+ if (regex_search(path, reg)) {
|
|
|
+ Dbg("delete: %s", path);
|
|
|
+ fileutil_delete_file(path);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ toolkit_array_free2(arr);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+bool CCenterSettingConn::InTerminalList()
|
|
|
+{
|
|
|
+ LOG_FUNCTION();
|
|
|
+ auto arrTerminalList = m_strTerminalList.Split('|');
|
|
|
+ Dbg("m_strTerminalList:%s", (const char*)m_strTerminalList);
|
|
|
+
|
|
|
+ for (int i = 0; i < arrTerminalList.GetCount(); ++i) {
|
|
|
+ if (info.strTerminalID == arrTerminalList[i]) {
|
|
|
+ Dbg("In terminalList.");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Dbg("Not in terminalList.");
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+void CCenterSettingConn::GetConfig()
|
|
|
+{
|
|
|
+ LOG_FUNCTION();
|
|
|
+
|
|
|
+ auto pFunc = m_pEntity->GetFunction();
|
|
|
+ assert(pFunc != NULL);
|
|
|
+ auto rc = pFunc->GetSystemStaticInfo(info);
|
|
|
+ assert(rc == Error_Succeed);
|
|
|
+ CSimpleStringA strCenterSetPath;
|
|
|
+ pFunc->GetPath("CenterSetting", strCenterSetPath);
|
|
|
+ m_strSite = "LAN";
|
|
|
+ if (strCenterSetPath.IsEndWith("DMZ.ini", true)) {
|
|
|
+ m_strSite = "DMZ";
|
|
|
+ }
|
|
|
+
|
|
|
+ CSmartPointer<IConfigInfo> spConfig;
|
|
|
+ ErrorCodeEnum Error = m_pEntity->GetFunction()->OpenConfig(Config_CenterSetting, spConfig);
|
|
|
+ if (Error == Error_Succeed)
|
|
|
+ {
|
|
|
+ spConfig->ReadConfigValue("Common", "GrayLaunchUrl", m_strGrayLaunchUrl);
|
|
|
+ spConfig->ReadConfigValue("Initializer", "SubBankNo", m_strCallRouteBranchNo);
|
|
|
+ spConfig->ReadConfigValue("CenterSetting", "CenterConfigUrl", m_strCenterSettingUrl);
|
|
|
+ spConfig->ReadConfigValue("CenterSetting", "LastUpdateTime", m_strLastTime);
|
|
|
+ spConfig->ReadConfigValue("CenterSetting", "Mode", m_strMode);
|
|
|
+ spConfig->ReadConfigValue("CenterSetting", "TerminalList", m_strTerminalList);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void CCenterSettingConn::WriteToConfig(const CenterSettings& configOfOneBranch)
|
|
|
+{
|
|
|
+ LOG_FUNCTION();
|
|
|
+ auto pFunc = m_pEntity->GetFunction();
|
|
|
+ assert(pFunc != NULL);
|
|
|
+ CSimpleStringA strPath;
|
|
|
+ pFunc->GetPath("Cfg", strPath);
|
|
|
+
|
|
|
+ ///**TODO(Gifur@9/16/2021): GetPath("CenterSetting") 通过此接口来获取集中配置路径地址 */
|
|
|
+ CSimpleStringA fileName = CSimpleStringA::Format("CenterSetting.%s.ini", configOfOneBranch.m_site.c_str());
|
|
|
+ Dbg("fileName:%s", fileName.GetData());
|
|
|
+ CSimpleStringA strCurFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (const char*)strPath, (const char*)fileName);
|
|
|
+
|
|
|
+ CSimpleString strRunInfoPath;
|
|
|
+ ///**TODO(Gifur@9/16/2021): GetPath("RunCfg") implement! */
|
|
|
+ pFunc->GetPath("RunInfo", strRunInfoPath);
|
|
|
+ strRunInfoPath += SPLIT_SLASH_STR;
|
|
|
+ strRunInfoPath += "runcfg";
|
|
|
+ CSimpleStringA strNewPath = strRunInfoPath + SPLIT_SLASH_STR;
|
|
|
+ CSimpleStringA strNewFile = strNewPath + fileName + ".new";
|
|
|
+
|
|
|
+ inifile_write_str(strNewFile, "CenterSetting", "LastUpdateTime", configOfOneBranch.m_lastUpdateTime.c_str());
|
|
|
+ for (int i = 0; i < configOfOneBranch.m_count; i++) {
|
|
|
+ string module = configOfOneBranch.configSet[i].m_moudle;
|
|
|
+ string name = configOfOneBranch.configSet[i].m_name;
|
|
|
+ string value = configOfOneBranch.configSet[i].m_value;
|
|
|
+ inifile_write_str(strNewFile, module.c_str(), name.c_str(), value.c_str());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 替换当前配置文件
|
|
|
+ fileutil_copy_file(strCurFile, strNewFile);
|
|
|
+ fileutil_delete_file(strNewFile);
|
|
|
+
|
|
|
+ Dbg("save config %s succ", fileName.GetData());
|
|
|
+}
|
|
|
+
|
|
|
+ErrorCodeEnum CCenterSettingConn::GetCenterSetting()
|
|
|
+{
|
|
|
+ LOG_FUNCTION();
|
|
|
+ CenterSettingReq sReq;
|
|
|
+ sReq.m_url = m_strCenterSettingUrl;
|
|
|
+ sReq.m_last_update_time = m_strLastTime;
|
|
|
+
|
|
|
+ sReq.m_terminal_no = info.strTerminalID;
|
|
|
+ CenterSettingResponse sResponse;
|
|
|
+
|
|
|
+ Dbg("sReq.m_url:%s", sReq.m_url.c_str());
|
|
|
+
|
|
|
+ bool ret = m_pHttpFunc->Post(sReq, sResponse);
|
|
|
+
|
|
|
+ if (ret && sResponse.bSuccess) {
|
|
|
+ std::string tmp(m_strSite.GetData());
|
|
|
+ if (sResponse.allConfigs[tmp].m_lastUpdateTime == sReq.m_last_update_time) {
|
|
|
+ Dbg("Centersetting.%s.ini not changed.", m_strSite.GetData());
|
|
|
+ return Error_Succeed;
|
|
|
+ }
|
|
|
+ int cnt = 0;
|
|
|
+
|
|
|
+ for (auto iter = sResponse.allConfigs.cbegin(); iter != sResponse.allConfigs.cend(); iter++) {
|
|
|
+ cnt++;
|
|
|
+ WriteToConfig(iter->second);
|
|
|
+ CSimpleStringA msg = CSimpleString::Format("Update CenterSetting.%s.ini.", m_strSite.GetData());
|
|
|
+ LogEvent(Severity_Middle, EVENT_MOD_CENTERSETTING_UPDATE, msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ return Error_Succeed;
|
|
|
+ }
|
|
|
+ return Error_Unexpect;
|
|
|
+}
|
|
|
+
|
|
|
+ErrorCodeEnum CCenterSettingConn::GrayLaunch(BOOL& grayLaunch)
|
|
|
+{
|
|
|
+ LOG_FUNCTION();
|
|
|
+
|
|
|
+ m_pHttpFunc = create_http(HTTPLogCallback);
|
|
|
+ m_bGrayLaunch = false;
|
|
|
+
|
|
|
+ if (m_strGrayLaunchUrl.GetLength() != 0) {
|
|
|
+ GrayLaunchReq gReq;
|
|
|
+ gReq.m_url = m_strGrayLaunchUrl.GetData();
|
|
|
+ Dbg("gReq.m_url: %s", gReq.m_url.c_str());
|
|
|
+ gReq.m_terminal_no = info.strTerminalID;
|
|
|
+ gReq.m_branch_no = m_strCallRouteBranchNo;
|
|
|
+ gReq.m_modular = "centersetting";
|
|
|
+ GrayLaunchResponse gResponse;
|
|
|
+
|
|
|
+ bool ret = m_pHttpFunc->Get(gReq, gResponse);
|
|
|
+ if (ret) {
|
|
|
+ m_bGrayLaunch = gResponse.m_result;
|
|
|
+ grayLaunch = m_bGrayLaunch;
|
|
|
+
|
|
|
+ return Error_Succeed;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Error_Unexpect;
|
|
|
+}
|
|
|
+
|
|
|
+void CCenterSettingConn::WriteIniFile(CSimpleStringA appName, CSimpleStringA keyName, CSimpleStringA value, CSimpleStringA newFile)
|
|
|
+{
|
|
|
+ if(-1 == inifile_write_str(newFile, appName, keyName, value)) {
|
|
|
+ LogWarn(Severity_Middle, Error_Unexpect, ERR_MOD_CENTERSETTING_WRITE_FAILED, "集中配置写入失败");
|
|
|
+ Dbg("Write config to %s fail(%d): appName=%s, keyName=%s, value=%s", newFile, GetLastError(), appName, keyName, value);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+bool CCenterSettingConn::GetMode()
|
|
|
+{
|
|
|
+ LOG_FUNCTION();
|
|
|
+ Dbg("m_strMode:%s", (const char*)m_strMode);
|
|
|
+ return (m_strMode == "1");
|
|
|
+}
|