浏览代码

#IQRV #comment [CenterSetting] 支持集中配置下载

gifur 2 年之前
父节点
当前提交
ae90163795

+ 2 - 2
Module/include/CommEntityUtil.hpp

@@ -419,8 +419,8 @@ static int HexBuf2StrBuf(PBYTE hexBuf, char** strBuf, DWORD len)
 //tips: need to delete result char*
 static char* ConvertBytesToHexStr(BYTE* pBuf, int nLen)
 {
-    char* pRet = (char*)new char(nLen * 2 + 1);
-    memset(pRet, 0, nLen * 2 + 1);
+    char* pRet = (char*)new char[nLen * 2 + 1];
+    memset(pRet, '\0', nLen * 2 + 1);
     char* p = pRet;
     for (int i = 0; i < nLen; i++) {
         BYTE b = pBuf[i];

+ 29 - 58
Module/mod_CenterSetting/CenterSettingConn.cpp

@@ -118,7 +118,7 @@ CenterSettingsMicroServiceHelper::CenterSettingsMicroServiceHelper(CEntityBase*
     InitCenterSettingInfo();
 }
 
-int CenterSettingsMicroServiceHelper::GetCenterSetting()
+int CenterSettingsMicroServiceHelper::GetCenterSetting(bool byHand)
 {
     LOG_FUNCTION();
 
@@ -132,16 +132,17 @@ int CenterSettingsMicroServiceHelper::GetCenterSetting()
     req.m_terminal_no = m_terminalInfo.strTerminalID.GetData();
 
     DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("m_strFilePath:%s", m_strFilePath.GetData());
-    if (!ExistsFile(m_strFilePath)) {
-        DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("!ExistsFile(m_strFilePath)");
+    if ((byHand && !m_isFirst) || !ExistsFile(m_strFilePath)) {
+        if (byHand && !m_isFirst && ExistsFileA(m_strFilePath)) {
+            LogWarn(Severity_Low, Error_Debug, EVENT_MOD_CENTERSETTING_UPDATE_CENTER_FORCE, "尝试强制重新下载集中配置");
+        }
         req.m_version = "";
         req.m_config = "";
     } else {
         req.m_version = m_strVersion.GetData();
         req.m_config = GetLocalConfig();
     }
-    /** 有什么作用? [Gifur@202397]*/
-    if (m_isFirst) m_isFirst = false;
+
     DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("m_strVersion:%s", m_strVersion.GetData());
     req.m_update_time = GetUpdateTime();
     GetTimeoutValue(req.m_timeOut);
@@ -174,7 +175,13 @@ int CenterSettingsMicroServiceHelper::GetCenterSetting()
                 break;
         }
     }
-
+    if (byHand) {
+        if (ret1 == EXIST && m_isFirst) {
+            m_isFirst = false;
+        } else if (ret1 == SUCC && !m_isFirst) {
+            m_isFirst = true;
+        }
+    }
     return ret1;
 }
 
@@ -231,7 +238,6 @@ void CenterSettingsMicroServiceHelper::InitCenterSettingInfo()
 
     //获取集中配置路径、文件名、场所
     m_pEntity->GetFunction()->GetPath("CenterSetting", m_strFilePath);
-
     m_pEntity->GetFunction()->GetPath("RunInfo", m_strBakPath);
     m_strBakPath += SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR "CenterSetting.ini";
 }
@@ -246,8 +252,6 @@ bool CenterSettingsMicroServiceHelper::WriteToConfig(const CenterSettingResponse
         string name = it->m_name;
         string value = it->m_value;
 
-        DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("write %s:%s:%s...", module.c_str(), name.c_str(), value.c_str());
-
         if (inifile_write_str(newPath.GetData(), module.c_str(), name.c_str(), value.c_str()) == -1) {
             DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("WriteToConfig")
                 ("write %s:%s:%s fail", module.c_str(), name.c_str(), value.c_str());
@@ -390,16 +394,13 @@ int CenterSettingsMicroServiceHelper::GetCenterSettingsFromHttp(CenterSettingReq
 
     config.PreDo();
     client.Do(&config, &result);
-    DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return do");
     if (!result.ResponseOK()) {
         DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Do failed: %s", result.WhatError().c_str());
         errMsg = result.WhatError();
         return AccessServiceFail;
     }
-    DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%d", __LINE__);
     SP::Module::Restful::CommResponseJson responseStatus;
     SP::Module::Restful::GetStatusFromDebranchResponse(result.content, responseStatus);
-    DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%d", __LINE__);
     if (!responseStatus.IsOperatedOK()) {
         DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)(result.content.c_str());
         errMsg = responseStatus.WhatError().c_str();
@@ -453,52 +454,22 @@ int CenterSettingsMicroServiceHelper::GetCenterSettingsFromHttp(CenterSettingReq
 
     BYTE sm3[32] = {};
     if (strConfig.length() > 2) {
-        //if (!SM3Hash((BYTE*)(strConfig.c_str()), strConfig.length(), sm3)) {
-        //    errMsg = "计算SM3失败";
-        //    DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetCenterSettingsFromHttp")("计算SM3失败(%s)", req.m_url.c_str());
-        //    return CalcSM3Fail;
-        //} else {
-        //    int sm3len = sizeof(sm3);
-        //    DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("sm3:%s", res.m_sm3.c_str());
-        //    char* strsm3 = SP::Module::Util::ConvertBytesToHexStr(sm3, 32);
-        //    if (0 != strcmp(strsm3, res.m_sm3.c_str())) {
-        //        errMsg = "SM3校验失败";
-        //        DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetCenterSettingsFromHttp")("SM3校验失败(%s)", req.m_url.c_str());
-        //        delete[] strsm3;
-        //        return CheckSM3Fail;
-        //    }
-        //    m_strVersion = res.m_version_no.c_str();
-        //    delete[] strsm3;
-        //}
-
-        //do {
-        //    bool fErrOccur(false), fHasContent(false);
-        //    CSimpleStringA newPath = m_strBakPath + ".new";
-        //    DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("write to %s..", newPath.GetData());
-        //    for (auto it = res.m_config.cbegin(); it != res.m_config.cend(); ++it) {
-        //        DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("write %s:%s:%s...", it->m_moudle.c_str(), it->m_name.c_str(), it->m_value.c_str());
-        //        if (inifile_write_str(newPath.GetData(), it->m_moudle.c_str(), it->m_name.c_str(), it->m_value.c_str()) == -1) {
-        //            DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("WriteToConfig")
-        //                ("write %s:%s:%s fail", it->m_moudle.c_str(), it->m_name.c_str(), it->m_value.c_str());
-        //            m_strErrMsg = "集中配置写入失败";
-        //            LogWarn(Severity_Middle, Error_Unexpect, ERR_MOD_CENTERSETTING_WRITE_FAILED,
-        //                    CSimpleStringA::Format("集中配置写入失败:%s:%s:%s", it->m_moudle.c_str(), it->m_name.c_str(), it->m_value.c_str()));
-        //            fErrOccur = true;
-        //            break;
-        //        } else if (!fHasContent) {
-        //            fHasContent = true;
-        //        }
-        //    }
-
-        //    if (fHasContent && !fErrOccur) {
-        //        DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("WriteToConfig")("集中配置写入成功");
-        //        fileutil_copy_file(m_strFilePath, newPath);
-        //        fileutil_delete_file(newPath);
-        //    } else {
-        //    }
-
-        //} while (false);
-
+        if (!SM3Hash((BYTE*)(strConfig.c_str()), strConfig.length(), sm3)) {
+            errMsg = "计算SM3失败";
+            DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetCenterSettingsFromHttp")("计算SM3失败(%s)", req.m_url.c_str());
+            return CalcSM3Fail;
+        } else {
+            DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("sm3:%s", res.m_sm3.c_str());
+            char* strsm3 = SP::Module::Util::ConvertBytesToHexStr(sm3, 32);
+            if (0 != strcmp(strsm3, res.m_sm3.c_str())) {
+                errMsg = "SM3校验失败";
+                DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetCenterSettingsFromHttp")("SM3校验失败(%s)", req.m_url.c_str());
+                delete[] strsm3;
+                return CheckSM3Fail;
+            }
+            m_strVersion = res.m_version_no.c_str();
+            delete[] strsm3;
+        }
 
         if (WriteToConfig(res)) {
             m_strVersion = res.m_version_no.c_str();

+ 1 - 1
Module/mod_CenterSetting/CenterSettingConn.h

@@ -137,7 +137,7 @@ class CenterSettingsMicroServiceHelper
 public:
     CenterSettingsMicroServiceHelper(CEntityBase* pEntity);
 
-    int GetCenterSetting();
+    int GetCenterSetting(bool byHand);
     string GetLocalConfig(); //将集中配置转换成Json串
     string GetUpdateTime();  //获取集中配置更新时间,如果文件不存在则获取当前系统时间
     const char* GetErrMsg() { return m_strErrMsg.c_str(); }

+ 1 - 0
Module/mod_CenterSetting/Event.h

@@ -11,6 +11,7 @@ enum CenterSetting_UserErrorCode
     EVENT_MOD_CENTERSETTING_UPDATE_VERSION_FAILED,    	 //上传版本号失败
     EVENT_MOD_CENTERSETTING_UPDATE_VERSION_SUCC,      	 //上传版本号成功
     EVENT_MOD_CENTERSETTING_CENTER,               //总行模式
+    EVENT_MOD_CENTERSETTING_UPDATE_CENTER_FORCE,               //强制下载集中配置
     EVENT_MOD_CENTERSETTING_UPDATE_CENTER,               //集中配置发生更新(总行)  
 };
 

+ 2 - 2
Module/mod_CenterSetting/mod_centersetting.cpp

@@ -54,10 +54,10 @@ ErrorCodeEnum CCenterSettingEntity::BeginDownloadCenterSetting(bool bByHand, con
 		m_pMicroServiceHelper->UpdateUrl(url);
 	}
 
-	int rc = m_pMicroServiceHelper->GetCenterSetting();
+	int rc = m_pMicroServiceHelper->GetCenterSetting(bByHand);
 
 	if (EXIST == rc) {
-		//DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("BeginDownloadCenterSetting")(m_pMicroServiceHelper->GetErrMsg());
+
 	} else if (SUCC == rc) {
 		LogWarn(Severity_Low, Error_Succeed, EVENT_MOD_CENTERSETTING_UPDATE_CENTER,
 				CSimpleStringA::Format("下载集中配置成功:%s", m_pMicroServiceHelper->GetCurUrl().c_str()));