|
@@ -15,12 +15,43 @@ using std::regex;
|
|
|
#include "json/json.h"
|
|
|
|
|
|
#include "mod_centersetting.h"
|
|
|
+#include "SpUtility.h"
|
|
|
+#include "RVCComm.h"
|
|
|
|
|
|
|
|
|
#if defined(RVC_OS_WIN)
|
|
|
#pragma comment(lib, "crypt32.lib")
|
|
|
#endif //RVC_OS_WIN
|
|
|
|
|
|
+#define WITH_CPPRESTSDK
|
|
|
+
|
|
|
+#ifdef WITH_CPPRESTSDK
|
|
|
+#include "CommEntityRestful.hpp"
|
|
|
+#include "microservices/api_terminal_center_config.h"
|
|
|
+
|
|
|
+struct ModuleConfigItemJson : public MicroServices::API::TerminalV3::ModuleConfigItem
|
|
|
+{
|
|
|
+ JSONCONVERT2OBJECT_MEMEBER_REGISTER(strModule, strName, strValue)
|
|
|
+ JSONCONVERT2OBJECT_MEMEBER_RENAME_REGISTER("moudle", "name", "value")
|
|
|
+};
|
|
|
+
|
|
|
+struct CenterSettingConfigJson
|
|
|
+{
|
|
|
+ bool isUpdate;
|
|
|
+ bool isReset;
|
|
|
+ std::string SM3;
|
|
|
+ std::string versionNo;
|
|
|
+ std::vector<ModuleConfigItemJson> configs;
|
|
|
+ std::string strConfig;
|
|
|
+ JSONCONVERT2OBJECT_MEMEBER_REGISTER(isUpdate, isReset, SM3, versionNo, strConfig)
|
|
|
+ JSONCONVERT2OBJECT_MEMEBER_RENAME_REGISTER("is_update", "is_reset", "sm3", "version_no", "config")
|
|
|
+};
|
|
|
+
|
|
|
+#else
|
|
|
+#define SAFE_DELETE_HTTPCLIENT(obj) \
|
|
|
+ do{if(obj != NULL) { obj->Destory(); obj = NULL; }}while(false)
|
|
|
+#endif
|
|
|
+
|
|
|
void convert(string& str)
|
|
|
{
|
|
|
//将单斜杠转为双斜杠
|
|
@@ -56,15 +87,39 @@ void transferblank(string& str)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+void HttpsLogCallBackTest(const char* logtxt)
|
|
|
+{
|
|
|
+ Dbg("http dbg: %s", logtxt);
|
|
|
+}
|
|
|
+
|
|
|
bool CenterSettingResponse::Parse(string strData)
|
|
|
{
|
|
|
+ LOG_FUNCTION();
|
|
|
+
|
|
|
Json::Value root;
|
|
|
Json::Reader reader;
|
|
|
Json::Value arrConfig;
|
|
|
- reader.parse(strData, root, false);
|
|
|
|
|
|
- m_success = root["success"].asBool();
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Parse:[%d]", strData.length());
|
|
|
+
|
|
|
+ if (!reader.parse(strData, root, false)) {
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("parse json string failed: ");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
+ struct CommResponseJson : public MicroServices::API::CommResponse
|
|
|
+ {
|
|
|
+ JSONCONVERT2OBJECT_MEMEBER_REGISTER(success, errorCode, returnCode, errorMsg, message)
|
|
|
+ JSONCONVERT2OBJECT_MEMEBER_RENAME_REGISTER("success", "code", "return_code", "error_msg", "message")
|
|
|
+ } reponseStatus;
|
|
|
+
|
|
|
+ if (!Json2Object(reponseStatus, root)) {
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Json2Object failed");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ m_success = reponseStatus.success;
|
|
|
if (m_success) {
|
|
|
m_message = root["message"].asString();
|
|
|
m_is_update = root["data"]["is_update"].asBool();
|
|
@@ -72,7 +127,7 @@ bool CenterSettingResponse::Parse(string strData)
|
|
|
m_version_no = root["data"]["version_no"].asString();
|
|
|
transferblank(m_version_no);
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("m_version_no:%s", m_version_no.c_str());
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("m_is_reset:%d", m_is_reset);
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("m_is_reset:%d", m_is_reset ? 1 : 0);
|
|
|
m_sm3 = root["data"]["sm3"].asString();
|
|
|
m_strConfig = root["data"]["config"].asString();
|
|
|
|
|
@@ -128,6 +183,120 @@ int CenterSettingsMicroServiceHelper::GetCenterSetting()
|
|
|
return AllAddressNull;
|
|
|
}
|
|
|
|
|
|
+#ifdef WITH_CPPRESTSDK
|
|
|
+
|
|
|
+ int res = UNknown;
|
|
|
+
|
|
|
+ struct GetCenterSettingsReqJson
|
|
|
+ {
|
|
|
+ GetCenterSettingsReqJson() :terminalNo(""), strVersion(""), lastUpdateTime("") {}
|
|
|
+ std::string terminalNo;
|
|
|
+ std::string strVersion;
|
|
|
+ std::string lastUpdateTime;
|
|
|
+ std::vector<ModuleConfigItemJson> configs;
|
|
|
+ JSONCONVERT2OBJECT_MEMEBER_REGISTER(terminalNo, strVersion, configs, lastUpdateTime)
|
|
|
+ JSONCONVERT2OBJECT_MEMEBER_RENAME_REGISTER("terminal_no", "version", "config", "update_time")
|
|
|
+ } getCenterSettingsReqJson;
|
|
|
+
|
|
|
+ HttpClientResponseResult result;
|
|
|
+
|
|
|
+
|
|
|
+ getCenterSettingsReqJson.terminalNo = m_terminalInfo.strTerminalID;
|
|
|
+ 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)");
|
|
|
+ } else {
|
|
|
+ getCenterSettingsReqJson.strVersion = m_strVersion.GetData();
|
|
|
+ ///**TODO(Gifur@9/7/2023): */
|
|
|
+ getCenterSettingsReqJson.configs;
|
|
|
+ }
|
|
|
+ getCenterSettingsReqJson.lastUpdateTime = GetUpdateTime();
|
|
|
+
|
|
|
+ HttpClientRequestConfig config(HttpRequestMethod::POST);
|
|
|
+ if (!m_strUrl.IsNullOrEmpty()) {
|
|
|
+ config.SetUri(m_strUrl.GetData());
|
|
|
+ config.AppendQuery("update_time", getCenterSettingsReqJson.lastUpdateTime);
|
|
|
+ config.AppendQuery("terminal_no", getCenterSettingsReqJson.terminalNo);
|
|
|
+ config.AppendQuery("version", getCenterSettingsReqJson.strVersion);
|
|
|
+ }
|
|
|
+ SP::Module::Restful::FulfillRequestJsonBody(&config, getCenterSettingsReqJson);
|
|
|
+ int timout(0);
|
|
|
+ GetTimeoutValue(timout);
|
|
|
+ if(timout > 0) config.SetTimeout(timout);
|
|
|
+
|
|
|
+ /** 有什么作用? [Gifur@202397]*/
|
|
|
+ if (m_isFirst) m_isFirst = false;
|
|
|
+
|
|
|
+ RestfulClient client = RestfulClient::getInstance();
|
|
|
+ config.PreDo();
|
|
|
+ client.Do(&config, &result);
|
|
|
+ if (result.ResponseOK()) {
|
|
|
+ SP::Module::Restful::CommResponseJson responseStatus;
|
|
|
+ SP::Module::Restful::GetStatusFromDebranchResponse(result.content, responseStatus);
|
|
|
+ if (!responseStatus.IsOperatedOK()) {
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)(result.content.c_str());
|
|
|
+ DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)(responseStatus.WhatError().c_str());
|
|
|
+ } else {
|
|
|
+ CenterSettingConfigJson getCenterSettingsAns;
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%s", result.content.substr(0, 1000).c_str());
|
|
|
+ if (!SP::Module::Restful::ExtractDataFromDebranchResponse(result.content, getCenterSettingsAns)) {
|
|
|
+ DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("parse json data node failed: ");
|
|
|
+ } else {
|
|
|
+ if (!getCenterSettingsAns.isUpdate) {
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetCenterSetting")("Centersetting not changed.");
|
|
|
+ m_strErrMsg = "集中配置已是最新版本";
|
|
|
+ res = EXIST;
|
|
|
+ } else {
|
|
|
+
|
|
|
+ SP::Utility::replaceInPlace(getCenterSettingsAns.strConfig, "\\\"", "\"");
|
|
|
+ if (!Json2Object(getCenterSettingsAns.configs, getCenterSettingsAns.strConfig)) {
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("parse config content failed!");
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ do {
|
|
|
+ bool fErrOccur(false), fHasContent(false);
|
|
|
+ CSimpleStringA newPath = m_strBakPath + ".new";
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("write to %s..", newPath);
|
|
|
+ for (auto it = getCenterSettingsAns.configs.cbegin(); it != getCenterSettingsAns.configs.cend(); ++it) {
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("write %s:%s:%s...", it->strModule.c_str(), it->strName.c_str(), it->strValue.c_str());
|
|
|
+ if (inifile_write_str(newPath.GetData(), it->strModule.c_str(), it->strName.c_str(), it->strValue.c_str()) == -1) {
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("WriteToConfig")
|
|
|
+ ("write %s:%s:%s fail", it->strModule.c_str(), it->strName.c_str(), it->strValue.c_str());
|
|
|
+ m_strErrMsg = "集中配置写入失败";
|
|
|
+ LogWarn(Severity_Middle, Error_Unexpect, ERR_MOD_CENTERSETTING_WRITE_FAILED,
|
|
|
+ CSimpleStringA::Format("集中配置写入失败:%s:%s:%s", it->strModule.c_str(), it->strName.c_str(), it->strValue.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);
|
|
|
+ res = SUCC;
|
|
|
+ } else {
|
|
|
+ res = UNknown;
|
|
|
+ }
|
|
|
+
|
|
|
+ } while (false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ m_strErrMsg = result.WhatError();
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Do failed: %s", m_strErrMsg.c_str());
|
|
|
+ res = AccessServiceFail;
|
|
|
+ }
|
|
|
+
|
|
|
+ return res;
|
|
|
+
|
|
|
+#else
|
|
|
+
|
|
|
CenterSettingReq req;
|
|
|
CenterSettingResponse res;
|
|
|
req.m_terminal_no = m_terminalInfo.strTerminalID.GetData();
|
|
@@ -143,7 +312,6 @@ int CenterSettingsMicroServiceHelper::GetCenterSetting()
|
|
|
}
|
|
|
|
|
|
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);
|
|
@@ -156,15 +324,20 @@ int CenterSettingsMicroServiceHelper::GetCenterSetting()
|
|
|
m_strCurUrl = req.m_url;
|
|
|
req.m_url += "?update_time=" + req.m_update_time + "&terminal_no=" + req.m_terminal_no + "&version=" + req.m_version;
|
|
|
ret1 = OnRequest(req, res, m_strErrMsg);
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("ret111:%d", ret1);
|
|
|
}
|
|
|
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%d", __LINE__);
|
|
|
+
|
|
|
if (SUCC != ret1) {
|
|
|
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("ret1 is not succ: %d", ret1);
|
|
|
+
|
|
|
if (m_strUrl.IsNullOrEmpty())
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetCenterSetting")("集中配置文件中地址为空,使用默认地址");
|
|
|
|
|
|
if (m_urlsFromShell.size() <= 0) {
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetCenterSetting")("shell.ini中找不到集中配置地址");
|
|
|
+ DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setAPI("GetCenterSetting")("shell.ini 中找不到集中配置地址");
|
|
|
return ret1;
|
|
|
}
|
|
|
|
|
@@ -174,33 +347,43 @@ int CenterSettingsMicroServiceHelper::GetCenterSetting()
|
|
|
req.m_url += "?update_time=" + req.m_update_time + "&terminal_no=" + req.m_terminal_no + "&version=" + req.m_version;
|
|
|
string err_str;
|
|
|
ret2 = OnRequest(req, res, err_str);
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("ret2:%d", ret2);
|
|
|
if (ret2 == SUCC)
|
|
|
break;
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
if (SUCC == ret1 || SUCC == ret2) {
|
|
|
+
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%d", __LINE__);
|
|
|
+
|
|
|
if (!res.m_is_update) {
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetCenterSetting")("Centersetting not changed.");
|
|
|
m_strErrMsg = "集中配置已是最新版本";
|
|
|
return EXIST;
|
|
|
}
|
|
|
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%d", __LINE__);
|
|
|
+
|
|
|
if (WriteToConfig(res)) {
|
|
|
m_strVersion = res.m_version_no.c_str();
|
|
|
DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("WriteToConfig m_strVersion:%s", m_strVersion.GetData());
|
|
|
m_pEntity->GetFunction()->OpenConfig(Config_CenterSetting, m_pCenterConfig, true);
|
|
|
m_pRunConfig->WriteConfigValue("CenterSetting", "version", m_strVersion);
|
|
|
UpdateVersion();
|
|
|
- if (res.m_is_reset)
|
|
|
+ if (res.m_is_reset) {
|
|
|
LogEvent(Severity_Middle, EVENT_MOD_CENTERSETTING_CRITICAL_UPDATE, "Update centersetting with critical items.");
|
|
|
-
|
|
|
+ }
|
|
|
return SUCC;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%d", __LINE__);
|
|
|
+
|
|
|
return ret1;
|
|
|
+
|
|
|
+#endif //WITH_CPPRESTSDK
|
|
|
}
|
|
|
|
|
|
void CenterSettingsMicroServiceHelper::InitCenterSettingInfo()
|
|
@@ -213,23 +396,41 @@ void CenterSettingsMicroServiceHelper::InitCenterSettingInfo()
|
|
|
|
|
|
//从集中配置和shell.ini获取url
|
|
|
m_pCenterConfig->ReadConfigValue("CenterSetting", "CenterConfigUrlNew", m_strUrl);
|
|
|
- if (m_strUrl.IsNullOrEmpty())
|
|
|
+ if (m_strUrl.IsNullOrEmpty()) {
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("InitCenterSettingInfo")("集中配置中的服务链接为空,使用默认链接");
|
|
|
+ } else {
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("CenterConfigUrlNew:%s", m_strUrl.GetData());
|
|
|
+ }
|
|
|
|
|
|
CSimpleStringA strMicroServiceURLSection = "MicroServiceURL";
|
|
|
|
|
|
- strMicroServiceURLSection = "MicroServiceURL";
|
|
|
+#if 0 /** 配置后置后没这堆玩意,至少现在的配置中没有 [Gifur@202397]*/
|
|
|
+
|
|
|
+#ifdef DEVOPS_ON_ST /*DevOps流水线编译,ST环境*/
|
|
|
+ strMicroServiceURLSection = "MicroServiceURL-ST";
|
|
|
+#elif defined(DEVOPS_ON_UAT)/*DevOps流水线编译,UAT环境*/
|
|
|
+ strMicroServiceURLSection = "MicroServiceURL-UAT";
|
|
|
+#elif defined(DEVOPS_ON_PRD)/*DevOps流水线编译,PRD环境*/
|
|
|
+ //strMicroServiceURLSection = "MicroServiceURL-PRD";
|
|
|
+#elif defined(DEVOPS_ON_DEV)/*DevOps流水线编译,Dev环境*/
|
|
|
+ strMicroServiceURLSection = "MicroServiceURL-Dev";
|
|
|
+#else/*本地编译等非DevOps环境编译的版本*/
|
|
|
+ strMicroServiceURLSection = "MicroServiceURL-Dev";
|
|
|
+#endif
|
|
|
|
|
|
+#endif
|
|
|
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("InitCenterSettingInfo")("获取集中配置服务地址 Section name:%s", strMicroServiceURLSection.GetData());
|
|
|
|
|
|
shellConfig->ReadAllKeys(strMicroServiceURLSection, m_arrKeys);
|
|
|
|
|
|
CSimpleStringA strUrl;
|
|
|
- for(int i = 0; i < m_arrKeys.GetCount() && m_arrKeys[i].IsStartWith("CenterConfigUrl", true); i++){
|
|
|
+ for (int i = 0; i < m_arrKeys.GetCount() && m_arrKeys[i].IsStartWith("CenterConfigUrl", true); i++) {
|
|
|
shellConfig->ReadConfigValue(strMicroServiceURLSection, m_arrKeys[i].GetData(), strUrl);
|
|
|
- if (!strUrl.IsNullOrEmpty())
|
|
|
+ if (!strUrl.IsNullOrEmpty()) {
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("add CenterURL:%s", strUrl.GetData());
|
|
|
m_urlsFromShell.push_back(strUrl);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//获取集中配置路径、文件名、场所
|
|
@@ -241,15 +442,19 @@ void CenterSettingsMicroServiceHelper::InitCenterSettingInfo()
|
|
|
|
|
|
bool CenterSettingsMicroServiceHelper::WriteToConfig(CenterSettingResponse& sResponse)
|
|
|
{
|
|
|
+ LOG_FUNCTION();
|
|
|
|
|
|
CSimpleStringA newPath = m_strBakPath + ".new";
|
|
|
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("config size: %d", sResponse.m_config.size());
|
|
|
for (int i = 0; i < sResponse.m_config.size(); i++) {
|
|
|
auto item = sResponse.m_config[i];
|
|
|
string module = item.m_moudle;
|
|
|
string name = item.m_name;
|
|
|
string value = item.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());
|
|
@@ -350,6 +555,7 @@ string CenterSettingsMicroServiceHelper::GetUpdateTime()
|
|
|
{
|
|
|
CSimpleStringA strUpdateTime;
|
|
|
|
|
|
+ /** 配置后置后本地没有这个实体文件,都被框架放到运行时了,所以需要处理这个逻辑 [Gifur@202397]*/
|
|
|
if (ExistsFile(m_strFilePath.GetData())) {
|
|
|
SYSTEMTIME st = GetModifyTime(m_strFilePath.GetData());
|
|
|
strUpdateTime = CSimpleStringA::Format("%d-%02d-%02d-%02d:%02d:%02d",
|
|
@@ -375,48 +581,64 @@ void CenterSettingsMicroServiceHelper::GetTimeoutValue(int& timeout)
|
|
|
|
|
|
int CenterSettingsMicroServiceHelper::OnRequest(CenterSettingReq& req, CenterSettingResponse& res, string& errMsg)
|
|
|
{
|
|
|
+ LOG_FUNCTION();
|
|
|
+
|
|
|
//req.m_url = "http://99.12.23.16:8081/api/terminal/center/config/v3?update_time=2022-08-08%2010:24:40&terminal_no=7555985008&version=";
|
|
|
- bool ret = m_pHttpFunc->Post(req, res);
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%s", req.m_url.c_str());
|
|
|
|
|
|
+ IHttpFunc* client;
|
|
|
+ client = create_http(HttpsLogCallBackTest);
|
|
|
+
|
|
|
+ bool ret = client->Post(req, res);
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("ret %d, succ: %d, update: %d", ret ? 1 : 0, res.m_success ? 1 : 0, res.m_is_update ? 1 : 0);
|
|
|
if (ret && res.m_success) {
|
|
|
- if (!res.m_is_update)
|
|
|
+ if (!res.m_is_update) {
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("no need to update.");
|
|
|
+ client->Destory();
|
|
|
return SUCC;
|
|
|
-
|
|
|
+ }
|
|
|
#if defined(_MSC_VER)
|
|
|
SP::Module::Util::ConvertGBKToUtf8(res.m_strConfig);
|
|
|
-#endif //_MSC_VER
|
|
|
string strConfig = res.m_strConfig;
|
|
|
+#else
|
|
|
+ string strConfig = SP::Utility::GBK2UTF8(res.m_strConfig);
|
|
|
+#endif //_MSC_VER
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("config:%d", strConfig.length());
|
|
|
|
|
|
BYTE sm3[32] = {};
|
|
|
if (strConfig.length() > 2) {
|
|
|
- if (!SM3Hash((BYTE*)(strConfig.c_str()), strlen(strConfig.c_str()), sm3)) {
|
|
|
+ if (!SM3Hash((BYTE*)(strConfig.c_str()), strConfig.length(), sm3)) {
|
|
|
errMsg = "计算SM3失败";
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("OnRequest")
|
|
|
- (CSimpleStringA::Format("计算SM3失败(%s)", req.m_url.c_str()));
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("OnRequest")("计算SM3失败(%s)", req.m_url.c_str());
|
|
|
+ client->Destory();
|
|
|
return CalcSM3Fail;
|
|
|
} else {
|
|
|
int sm3len = sizeof(sm3);
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("smlen:%d", sm3len);
|
|
|
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("OnRequest")
|
|
|
- (CSimpleStringA::Format("SM3校验失败(%s)", req.m_url.c_str()));
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("OnRequest")("SM3校验失败(%s)", req.m_url.c_str());
|
|
|
delete[] strsm3;
|
|
|
+ client->Destory();
|
|
|
return CheckSM3Fail;
|
|
|
}
|
|
|
m_strVersion = res.m_version_no.c_str();
|
|
|
delete[] strsm3;
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%d", __LINE__);
|
|
|
+ client->Destory();
|
|
|
+
|
|
|
return SUCC;
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
+ client->Destory();
|
|
|
errMsg = res.m_errMsg;
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("OnRequest")
|
|
|
- (CSimpleStringA::Format("访问失败:%s", res.m_errMsg.c_str()));
|
|
|
-
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("OnRequest")("访问失败:%s", res.m_errMsg.c_str());
|
|
|
if (res.m_sysCode == 28 || res.m_sysCode == 7)
|
|
|
return AccessServiceFail;
|
|
|
-
|
|
|
return MANUAL;
|
|
|
}
|
|
|
+ client->Destory();
|
|
|
+ return UNknown;
|
|
|
}
|