mod_centersetting.cpp 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048
  1. #include "stdafx.h"
  2. #include "SpBase.h"
  3. #include "Event.h"
  4. #include "mod_centersetting.h"
  5. #include "publicFunExport.h"
  6. #include "array.h"
  7. #include "fileutil.h"
  8. #include "iniutil.h"
  9. #include "array.h"
  10. #include "EventCode.h"
  11. #include "SpIni.h"
  12. #include <regex.h>
  13. #include <regex>
  14. using namespace std;
  15. #define DOWNLOAD_CENTERSETTINGS_TIMER_ID 1
  16. #define DOWNLOAD_CENTERSETTINGS_TIMER_INTERVAL (5 * 60 * 1000)
  17. CServerSessionBase *CCenterSettingEntity::OnNewSession(const char* /*pszRemoteEntityName*/, const char * /*pszClass*/)
  18. {
  19. return new CCenterSettingService(this);
  20. }
  21. void CCenterSettingEntity::OnPreStart(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext)
  22. {
  23. ErrorCodeEnum result(Error_Succeed);
  24. CSimpleStringA strtermState;
  25. GetFunction()->GetSysVar("TerminalStage", strtermState);
  26. if ('Z' != strtermState[0]) {
  27. CSimpleStringA strFilePath;
  28. GetFunction()->GetPath("CenterSetting", strFilePath);
  29. if (!ExistsFileA(strFilePath)) {
  30. std::map<std::string, std::string> srcData;
  31. srcData.insert(std::make_pair("reason", "empty"));
  32. srcData.insert(std::make_pair("errmsg", "集中配置文件不存在,请先下载集中配置再重启应用!"));
  33. srcData.insert(std::make_pair("rebootTime", ""));
  34. auto ret = generateJsonStr(srcData);
  35. if (ret.first) {
  36. LogNotify(Notify_Error, Error_InvalidState, EVENT_CENTERSETTING_NOTIFY_LACK_OF_CENTER_CONFIG, ret.second.c_str());
  37. }
  38. }
  39. }
  40. pTransactionContext->SendAnswer(result);
  41. }
  42. void CCenterSettingEntity::OnStarted()
  43. {
  44. CSimpleStringA strtermState;
  45. GetFunction()->GetSysVar("TerminalStage", strtermState);
  46. if (strtermState.IsStartWith("Z=")) {
  47. Dbg("in config mode, do nothing about centersetting sync");
  48. return;
  49. }
  50. CSimpleStringA strPath;
  51. GetFunction()->GetPath("Cfg", strPath);
  52. auto arr = fileutil_get_sub_files(strPath);
  53. if (arr != NULL)
  54. {
  55. for (int i = 0; i < arr->nelts; ++i)
  56. {
  57. ConfigFileInfo info = {};
  58. char *pszFile = ARRAY_IDX(arr, i, char*);
  59. CSimpleStringA strSite;
  60. if (TryExtractSiteFromFileName(pszFile, info.strFileName, strSite))
  61. {
  62. char szTmp[80];
  63. inifile_read_str_s("Main", "SyncHash", "", szTmp, 80, pszFile);
  64. info.strFileHash = szTmp;
  65. inifile_read_str_s("Main", "SyncTime", "", szTmp, 80, pszFile);
  66. DWORD nValue;
  67. sscanf(szTmp, "0x%X", &nValue);
  68. info.dwSyncTime = nValue;
  69. m_SyncFileInfo[(const char*)strSite] = info;
  70. }
  71. }
  72. toolkit_array_free2(arr);
  73. }
  74. CSimpleStringA strFilePath;
  75. GetFunction()->GetPath("CenterSetting", strFilePath);
  76. CSimpleStringA strNoUsed;
  77. TryExtractSiteFromFileName(strFilePath, strNoUsed, m_strCurSiteExtName);
  78. // 缓存当前RVCWeb版本
  79. char szVersion[64] = {};
  80. inifile_read_str_s("IEBrowser", "RvcWebVersion", "", szVersion, 64, strFilePath);
  81. m_strRvcWebVersion = szVersion;
  82. // 立刻同步配置
  83. GetFunction()->PostEntityTaskFIFO(new DownloadCenterSettingsTask(this));
  84. //订阅首页状态
  85. GetFunction()->RegistSysVarEvent("UIState", this);
  86. // 启动轮询定时器 5min
  87. GetFunction()->SetTimer(DOWNLOAD_CENTERSETTINGS_TIMER_ID, this, DOWNLOAD_CENTERSETTINGS_TIMER_INTERVAL);
  88. }
  89. void CCenterSettingEntity::OnTimeout(DWORD dwTimerID)
  90. {
  91. BeginDownloadCenterSetting();
  92. }
  93. void CCenterSettingEntity::OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  94. {
  95. SecureClientRelease();
  96. GetFunction()->KillTimer(DOWNLOAD_CENTERSETTINGS_TIMER_ID);
  97. pTransactionContext->SendAnswer(Error_Succeed);
  98. }
  99. ErrorCodeEnum CCenterSettingEntity::BeginDownloadCenterSetting(LPCTSTR serverIP, int port)
  100. {
  101. LOG_FUNCTION();
  102. //TODO
  103. m_pConnection = new CCenterSettingConn(this);
  104. if (!GetServerIP())
  105. {
  106. Dbg("Centersetting may be lost.");
  107. //return Error_Unexpect;
  108. }
  109. if (serverIP != NULL && strlen(serverIP) > 0 && port > 0) {
  110. if (!SecureClientConnect(ConnectServerType::PARAM, serverIP, port)) {
  111. return Error_NetBroken;
  112. }
  113. }
  114. else {
  115. if (!SecureClientConnect(ConnectServerType::DEFAULT)) {
  116. return Error_NetBroken;
  117. }
  118. }
  119. if (m_bGrayLaunch) {
  120. ErrorCodeEnum rc = m_pConnection->GetCenterSetting(); //新模式
  121. if (rc != Error_Succeed)
  122. LogWarn(Severity_Middle, rc, ERR_MOD_CENTERSETTING_CONNECT_FAILED, "Get centersetting failed.");
  123. else
  124. LogWarn(Severity_Middle, Error_Succeed, EVENT_MOD_CENTERSETTING_CONNECT_SUCC, "Get centersetting succ.");
  125. ReturnAndClearDownloadContext(rc);
  126. return rc;
  127. }
  128. m_nConnectFailCount = 0;
  129. LOG_ASSERT(IsServerConnectedNow());
  130. CSystemStaticInfo info;
  131. auto rc = GetFunction()->GetSystemStaticInfo(info);
  132. assert(rc == Error_Succeed);
  133. rc = m_pConnection->BeginPollConfig(info);
  134. return rc;
  135. }
  136. ErrorCodeEnum CCenterSettingEntity::EndDownloadCenterSetting(ErrorCodeEnum rc)
  137. {
  138. // 备份地址只使用短连接,用于应急切换,使用后立即释放,仍尝试使用新地址
  139. //if (m_bUseBackupNow) // xkm@20160803: 改为短连接
  140. SecureClientRelease();
  141. //if (rc == Error_Succeed)
  142. // LogEvent(Severity_Middle, EVENT_MOD_CENTERSETTING_DOWNOK, "集中配置同步成功");
  143. ReturnAndClearDownloadContext(rc);
  144. return rc;
  145. }
  146. ErrorCodeEnum CCenterSettingEntity::DownloadCenterSetting(
  147. SpReqAnsContext<CenterSettingService_Download_Req, CenterSettingService_Download_Ans>::Pointer sp)
  148. {
  149. if (IsDownloadPending())
  150. {
  151. Dbg("last download call not complet");
  152. sp->Answer(Error_Duplication);
  153. return Error_Duplication;
  154. }
  155. m_spDownloadCall = sp;
  156. ErrorCodeEnum error = (sp != NULL ? BeginDownloadCenterSetting(sp->Req.strAddr, sp->Req.nPort) : BeginDownloadCenterSetting());
  157. if (error == Error_NetBroken) {
  158. m_spDownloadCall = nullptr;
  159. if (sp != NULL) {
  160. sp->Answer(Error_Unexpect);
  161. }
  162. return error;
  163. }
  164. return Error_Succeed;
  165. }
  166. void CCenterSettingEntity::OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext)
  167. {
  168. CSmartPointer<IConfigInfo> pConfig;
  169. GetFunction()->OpenConfig(Config_Run, pConfig);
  170. CSimpleStringA strServer;
  171. int nPort(0);
  172. pConfig->ReadConfigValue("Test", "ServerIP", strServer);
  173. pConfig->ReadConfigValueInt("Test", "Port", nPort);
  174. if (strServer.IsNullOrEmpty() || nPort <= 0) {
  175. Dbg("Invalid Param from RunCfg");
  176. pTransactionContext->SendAnswer(Error_Param);
  177. return;
  178. }
  179. ErrorCodeEnum error = BeginDownloadCenterSetting(strServer, nPort);
  180. pTransactionContext->SendAnswer(error);
  181. }
  182. void CCenterSettingEntity::EditWebUrl(SpReqAnsContext<CenterSettingService_EditWebUrl_Req, CenterSettingService_EditWebUrl_Ans>::Pointer ctx)
  183. {
  184. ErrorCodeEnum result(Error_Unexpect);
  185. ctx->Ans.result = 0;
  186. ctx->Ans.msg = "";
  187. switch (ctx->Req.operation) {
  188. case 1: //new
  189. {
  190. CSmartPointer<IConfigInfo> pConfig;
  191. GetFunction()->OpenConfig(Config_Cache, pConfig);
  192. int count(0);
  193. bool newCreate = true;
  194. pConfig->ReadConfigValueInt("CustomWebUrl", "Count", count);
  195. int newIndex(count + 1);
  196. for (int i = 1; i <= count; ++i) {
  197. CustomWebUrlConfig item;
  198. CSimpleStringA strSection = CSimpleStringA::Format("CustomWebUrl%d", i);
  199. pConfig->ReadConfigValue(strSection, "FultureUrl", item.strFutureUrl);
  200. pConfig->ReadConfigValue(strSection, "AdUrl", item.strAdUrl);
  201. pConfig->ReadConfigValue(strSection, "Remark", item.strRemark);
  202. pConfig->ReadConfigValueInt(strSection, "Env", item.useEnv);
  203. pConfig->ReadConfigValueInt(strSection, "Status", item.curStatus);
  204. if (!item.IsValid()) {
  205. newIndex = i;
  206. newCreate = false;
  207. break;
  208. }
  209. }
  210. CSimpleStringA strNewSection = CSimpleStringA::Format("CustomWebUrl%d", newIndex);
  211. pConfig->WriteConfigValue(strNewSection, "FultureUrl", ctx->Req.futureUrl);
  212. pConfig->WriteConfigValue(strNewSection, "AdUrl", ctx->Req.adUrl);
  213. CSimpleStringA strRemark(ctx->Req.remark);
  214. if (strRemark.IsNullOrEmpty()) {
  215. if (ctx->Req.env == 1) strRemark = "DEV:";
  216. else if(ctx->Req.env == 2) strRemark = "ST:";
  217. if (ctx->Req.env == 3) strRemark = "UAT:";
  218. strRemark += ctx->Req.futureUrl;
  219. }
  220. pConfig->WriteConfigValue(strNewSection, "Remark", strRemark);
  221. pConfig->WriteConfigValueInt(strNewSection, "Env", ctx->Req.env);
  222. pConfig->WriteConfigValueInt(strNewSection, "Status", WEBURL_STATUS_PROVIDE);
  223. if (ctx->Req.setDefault) {
  224. pConfig->WriteConfigValueInt("CustomWebUrl", "Current", newIndex);
  225. }
  226. if (newCreate) {
  227. pConfig->WriteConfigValueInt("CustomWebUrl", "Count", newIndex);
  228. }
  229. ctx->Ans.addition = newIndex;
  230. result = Error_Succeed;
  231. }
  232. break;
  233. case 2: //delete
  234. {
  235. if (ctx->Req.index >= WEBURL_ITEM_INDEX_CENTERSETTING) {
  236. result = Error_NoPrivilege;
  237. } else {
  238. CSmartPointer<IConfigInfo> pConfig;
  239. GetFunction()->OpenConfig(Config_Cache, pConfig);
  240. int oldStatus(0);
  241. CSimpleStringA strSection = CSimpleStringA::Format("CustomWebUrl%d", ctx->Req.index);
  242. pConfig->ReadConfigValueInt(strSection, "Status", oldStatus);
  243. pConfig->WriteConfigValueInt(strSection, "Status", WEBURL_STATUS_DEPRECATE);
  244. int currentUsing(0);
  245. pConfig->ReadConfigValueInt("CustomWebUrl", "Current", currentUsing);
  246. if (ctx->Req.index == currentUsing) {
  247. pConfig->WriteConfigValueInt("CustomWebUrl", "Current", 0);
  248. }
  249. result = Error_Succeed;
  250. }
  251. }
  252. break;
  253. case 3: //update
  254. {
  255. if (ctx->Req.index >= WEBURL_ITEM_INDEX_CENTERSETTING) { //如果当前是集中配置文件
  256. CSmartPointer<IConfigInfo> pConfig;
  257. GetFunction()->OpenConfig(Config_Cache, pConfig);
  258. int currentUsing(0);
  259. pConfig->ReadConfigValueInt("CustomWebUrl", "Current", currentUsing);
  260. if (currentUsing != 0 && ctx->Req.setDefault) {
  261. pConfig->WriteConfigValueInt("CustomWebUrl", "Current", 0);
  262. result = Error_Succeed;
  263. } else {
  264. result = Error_NoPrivilege;
  265. }
  266. break;
  267. }
  268. CSmartPointer<IConfigInfo> pConfig;
  269. GetFunction()->OpenConfig(Config_Cache, pConfig);
  270. CSimpleStringA strExistedSection = CSimpleStringA::Format("CustomWebUrl%d", ctx->Req.index);
  271. pConfig->WriteConfigValue(strExistedSection, "FultureUrl", ctx->Req.futureUrl);
  272. pConfig->WriteConfigValue(strExistedSection, "AdUrl", ctx->Req.adUrl);
  273. CSimpleStringA strRemark(ctx->Req.remark);
  274. if (strRemark.IsNullOrEmpty()) {
  275. if (ctx->Req.env == 1) strRemark = "DEV:";
  276. else if (ctx->Req.env == 2) strRemark = "ST:";
  277. if (ctx->Req.env == 3) strRemark = "UAT:";
  278. strRemark += ctx->Req.futureUrl;
  279. }
  280. pConfig->WriteConfigValue(strExistedSection, "Remark", strRemark);
  281. pConfig->WriteConfigValueInt(strExistedSection, "Env", ctx->Req.env);
  282. pConfig->WriteConfigValueInt(strExistedSection, "Status", WEBURL_STATUS_PROVIDE);
  283. if (ctx->Req.setDefault) {
  284. pConfig->WriteConfigValueInt("CustomWebUrl", "Current", ctx->Req.index);
  285. }
  286. ctx->Ans.addition = ctx->Req.index;
  287. result = Error_Succeed;
  288. }
  289. break;
  290. default:
  291. result = Error_NotSupport;
  292. break;
  293. }
  294. ctx->Answer(result);
  295. return;
  296. }
  297. void CCenterSettingEntity::GetWebUrlList(SpReqAnsContext<CenterSettingService_GetWebUrlList_Req, CenterSettingService_GetWebUrlList_Ans>::Pointer ctx)
  298. {
  299. ErrorCodeEnum result(Error_Succeed);
  300. CSmartPointer<IConfigInfo> pConfig;
  301. GetFunction()->OpenConfig(Config_Cache, pConfig);
  302. int cnt(0), curIndex(0), realCnt(0);
  303. bool hasDefaultFromCustom(false);
  304. pConfig->ReadConfigValueInt("CustomWebUrl", "Count", cnt);
  305. int currentUsing(0);
  306. pConfig->ReadConfigValueInt("CustomWebUrl", "Current", currentUsing);
  307. CAutoArray< CustomWebUrlConfig> configs(cnt);
  308. Dbg("custom count: %d", cnt);
  309. for (int i = 1; i <= cnt; ++i) {
  310. CustomWebUrlConfig& item = configs[i - 1];
  311. item.configFrom = WEBURL_CONFIG_CUSTOM;
  312. item.index = i;
  313. CSimpleStringA strSection = CSimpleStringA::Format("CustomWebUrl%d", i);
  314. pConfig->ReadConfigValue(strSection, "FultureUrl", item.strFutureUrl);
  315. pConfig->ReadConfigValue(strSection, "AdUrl", item.strAdUrl);
  316. pConfig->ReadConfigValue(strSection, "Remark", item.strRemark);
  317. pConfig->ReadConfigValueInt(strSection, "Env", item.useEnv);
  318. pConfig->ReadConfigValueInt(strSection, "Status", item.curStatus);
  319. if (item.IsValid()) {
  320. realCnt++;
  321. if (currentUsing == i) {
  322. hasDefaultFromCustom = true;
  323. item.curStatus = WEBURL_STATUS_DEFAULT;
  324. } else {
  325. item.curStatus = WEBURL_STATUS_PROVIDE;
  326. }
  327. }
  328. }
  329. CustomWebUrlConfig defaultOne;
  330. ErrorCodeEnum resultFromFetch = GetWebUrlInfoFromCenterSettings(defaultOne);
  331. if (resultFromFetch == Error_Succeed) {
  332. Dbg("add centersettings config");
  333. realCnt += 1;
  334. if (!hasDefaultFromCustom) {
  335. defaultOne.curStatus = WEBURL_STATUS_DEFAULT;
  336. }
  337. }
  338. Dbg("total count: %d", realCnt);
  339. ctx->Ans.index.Init(realCnt);
  340. ctx->Ans.futureUrl.Init(realCnt);
  341. ctx->Ans.adUrl.Init(realCnt);
  342. ctx->Ans.remark.Init(realCnt);
  343. ctx->Ans.env.Init(realCnt);
  344. ctx->Ans.type.Init(realCnt);
  345. ctx->Ans.status.Init(realCnt);
  346. if (resultFromFetch == Error_Succeed) {
  347. ctx->Ans.index[curIndex] = WEBURL_ITEM_INDEX_CENTERSETTING;
  348. ctx->Ans.futureUrl[curIndex] = defaultOne.strFutureUrl;
  349. ctx->Ans.adUrl[curIndex] = defaultOne.strAdUrl;
  350. ctx->Ans.remark[curIndex] = defaultOne.strRemark;
  351. ctx->Ans.env[curIndex] = defaultOne.useEnv;
  352. ctx->Ans.type[curIndex] = defaultOne.configFrom;
  353. ctx->Ans.status[curIndex] = defaultOne.curStatus;
  354. curIndex++;
  355. }
  356. for (int i = 0; i < configs.GetCount(); ++i) {
  357. CustomWebUrlConfig& item = configs[i];
  358. if (item.IsValid()) {
  359. ctx->Ans.index[curIndex] = item.index;
  360. ctx->Ans.futureUrl[curIndex] = item.strFutureUrl;
  361. ctx->Ans.adUrl[curIndex] = item.strAdUrl;
  362. ctx->Ans.remark[curIndex] = item.strRemark;
  363. ctx->Ans.env[curIndex] = item.useEnv;
  364. ctx->Ans.type[curIndex] = item.configFrom;
  365. ctx->Ans.status[curIndex] = item.curStatus;
  366. curIndex++;
  367. }
  368. }
  369. ctx->Answer(result);
  370. }
  371. void CCenterSettingEntity::GetActiveCustomUrl(
  372. SpReqAnsContext<CenterSettingService_GetActiveCustomUrl_Req, CenterSettingService_GetActiveCustomUrl_Ans>::Pointer ctx)
  373. {
  374. ErrorCodeEnum result(Error_Succeed);
  375. CSmartPointer<IConfigInfo> pConfig;
  376. GetFunction()->OpenConfig(Config_Cache, pConfig);
  377. int cnt(0), currentUsing(0);
  378. pConfig->ReadConfigValueInt("CustomWebUrl", "Count", cnt);
  379. pConfig->ReadConfigValueInt("CustomWebUrl", "Current", currentUsing);
  380. if (cnt == 0 || currentUsing == 0) {
  381. result = Error_NotConfig;
  382. } else {
  383. CSimpleStringA strSection = CSimpleStringA::Format("CustomWebUrl%d", currentUsing);
  384. pConfig->ReadConfigValue(strSection, "FultureUrl", ctx->Ans.fultureUrl);
  385. pConfig->ReadConfigValue(strSection, "AdUrl", ctx->Ans.adUrl);
  386. if (!ctx->Ans.fultureUrl.IsNullOrEmpty()) {
  387. result = Error_Succeed;
  388. } else {
  389. result = Error_CheckSum;
  390. }
  391. }
  392. ctx->Answer(result);
  393. return;
  394. }
  395. void CCenterSettingEntity::EditTerminalBackupInfo(SpReqAnsContext<CenterSettingService_EditTerminalBackupInfo_Req, CenterSettingService_EditTerminalBackupInfo_Ans>::Pointer ctx)
  396. {
  397. ErrorCodeEnum result(Error_Succeed);
  398. CSimpleStringA errMsg(true);
  399. ErrorCodeEnum tmpResult(Error_Succeed);
  400. switch (ctx->Req.operation) {
  401. case 1: //new
  402. {
  403. CSmartPointer<IConfigInfo> pConfig;
  404. GetFunction()->OpenConfig(Config_Cache, pConfig);
  405. int count(0);
  406. bool newCreate = true;
  407. pConfig->ReadConfigValueInt("TerminalBackup", "Count", count);
  408. int newIndex(count + 1);
  409. for (int i = 1; i <= count; ++i) {
  410. CustomWebUrlConfig item;
  411. CSimpleStringA strSection = CSimpleStringA::Format("TerminalBackup%d", i);
  412. pConfig->ReadConfigValue(strSection, "TerminalNo", item.strFutureUrl);
  413. pConfig->ReadConfigValue(strSection, "ServerIP", item.strAdUrl);
  414. pConfig->ReadConfigValue(strSection, "Remark", item.strRemark);
  415. pConfig->ReadConfigValueInt(strSection, "Env", item.useEnv);
  416. pConfig->ReadConfigValueInt(strSection, "Status", item.curStatus);
  417. if (!item.IsValid()) {
  418. newIndex = i;
  419. newCreate = false;
  420. break;
  421. }
  422. }
  423. CSimpleStringA strNewSection = CSimpleStringA::Format("TerminalBackup%d", newIndex);
  424. pConfig->WriteConfigValue(strNewSection, "TerminalNo", ctx->Req.terminalNo);
  425. pConfig->WriteConfigValue(strNewSection, "ServerIP", ctx->Req.branchIP);
  426. CSimpleStringA strRemark(ctx->Req.remark);
  427. if (strRemark.IsNullOrEmpty()) {
  428. if (ctx->Req.env == 1) strRemark = "DEV:";
  429. else if (ctx->Req.env == 2) strRemark = "ST:";
  430. if (ctx->Req.env == 3) strRemark = "UAT:";
  431. strRemark += ctx->Req.terminalNo;
  432. }
  433. pConfig->WriteConfigValue(strNewSection, "Remark", strRemark);
  434. pConfig->WriteConfigValueInt(strNewSection, "Env", ctx->Req.env);
  435. pConfig->WriteConfigValueInt(strNewSection, "Status", WEBURL_STATUS_PROVIDE);
  436. if (ctx->Req.setDefault) {
  437. tmpResult = UpdateTerminalInfoAtChange(ctx->Req.terminalNo);
  438. if (!(tmpResult == Error_Succeed || tmpResult == Error_AlreadyExist)) {
  439. pConfig->WriteConfigValueInt(strNewSection, "Status", WEBURL_STATUS_DEPRECATE);
  440. errMsg = CSimpleStringA::Format("更新终端号信息失败!");
  441. break;
  442. }
  443. }
  444. if (newCreate) {
  445. pConfig->WriteConfigValueInt("TerminalBackup", "Count", newIndex);
  446. }
  447. ctx->Ans.addition = (int)ConfirmCenterSettingsFileAndUpdateIfNecessary(ctx->Req.branchIP);
  448. result = Error_Succeed;
  449. }
  450. break;
  451. case 2: //delete
  452. {
  453. CSmartPointer<IConfigInfo> pConfig;
  454. GetFunction()->OpenConfig(Config_Cache, pConfig);
  455. CSimpleStringA strSection = CSimpleStringA::Format("TerminalBackup%d", ctx->Req.index);
  456. int oldStatus(0);
  457. pConfig->ReadConfigValueInt(strSection, "Status", oldStatus);
  458. pConfig->WriteConfigValueInt(strSection, "Status", WEBURL_STATUS_DEPRECATE);
  459. }
  460. break;
  461. case 3: //update
  462. {
  463. CSmartPointer<IConfigInfo> pConfig;
  464. GetFunction()->OpenConfig(Config_Cache, pConfig);
  465. CSimpleStringA strExistedSection = CSimpleStringA::Format("TerminalBackup%d", ctx->Req.index);
  466. if (ctx->Req.setDefault) {
  467. tmpResult = UpdateTerminalInfoAtChange(ctx->Req.terminalNo);
  468. if (!(tmpResult == Error_Succeed || tmpResult == Error_AlreadyExist)) {
  469. errMsg = CSimpleStringA::Format("更新终端号信息失败!");
  470. break;
  471. }
  472. }
  473. pConfig->WriteConfigValue(strExistedSection, "TerminalNo", ctx->Req.terminalNo);
  474. pConfig->WriteConfigValue(strExistedSection, "ServerIP", ctx->Req.branchIP);
  475. CSimpleStringA strRemark(ctx->Req.remark);
  476. if (strRemark.IsNullOrEmpty()) {
  477. if (ctx->Req.env == 1) strRemark = "DEV:";
  478. else if (ctx->Req.env == 2) strRemark = "ST:";
  479. if (ctx->Req.env == 3) strRemark = "UAT:";
  480. strRemark += ctx->Req.terminalNo;
  481. }
  482. pConfig->WriteConfigValue(strExistedSection, "Remark", strRemark);
  483. pConfig->WriteConfigValueInt(strExistedSection, "Env", ctx->Req.env);
  484. pConfig->WriteConfigValueInt(strExistedSection, "Status", WEBURL_STATUS_PROVIDE);
  485. ctx->Ans.addition = (int)ConfirmCenterSettingsFileAndUpdateIfNecessary(ctx->Req.branchIP);
  486. result = Error_Succeed;
  487. }
  488. break;
  489. default:
  490. result = Error_NotSupport;
  491. break;
  492. }
  493. ctx->Ans.result = tmpResult;
  494. ctx->Ans.msg = errMsg;
  495. ctx->Answer(result);
  496. return;
  497. }
  498. void CCenterSettingEntity::GetTerminalBackupInfoList(SpReqAnsContext<CenterSettingService_GetTerminalBackupInfoList_Req, CenterSettingService_GetTerminalBackupInfoList_Ans>::Pointer ctx)
  499. {
  500. ErrorCodeEnum result(Error_Succeed);
  501. CSmartPointer<IConfigInfo> pConfig;
  502. GetFunction()->OpenConfig(Config_Cache, pConfig);
  503. int cnt(0), curIndex(0), realCnt(0);
  504. bool hasDefaultFromCustom(false);
  505. pConfig->ReadConfigValueInt("TerminalBackup", "Count", cnt);
  506. CAutoArray< CustomWebUrlConfig> configs(cnt);
  507. Dbg("custom count: %d", cnt);
  508. for (int i = 1; i <= cnt; ++i) {
  509. CustomWebUrlConfig& item = configs[i - 1];
  510. item.configFrom = WEBURL_CONFIG_CUSTOM;
  511. item.index = i;
  512. CSimpleStringA strSection = CSimpleStringA::Format("TerminalBackup%d", i);
  513. pConfig->ReadConfigValue(strSection, "TerminalNo", item.strFutureUrl);
  514. pConfig->ReadConfigValue(strSection, "ServerIP", item.strAdUrl);
  515. pConfig->ReadConfigValue(strSection, "Remark", item.strRemark);
  516. pConfig->ReadConfigValueInt(strSection, "Env", item.useEnv);
  517. pConfig->ReadConfigValueInt(strSection, "Status", item.curStatus);
  518. if (item.IsValid()) {
  519. realCnt++;
  520. DWORD dwMask(0);
  521. if (IsParamCurrentUsed(item.strFutureUrl, item.strAdUrl, dwMask)) {
  522. hasDefaultFromCustom = true;
  523. item.curStatus = WEBURL_STATUS_DEFAULT;
  524. } else {
  525. item.curStatus = WEBURL_STATUS_PROVIDE;
  526. }
  527. }
  528. }
  529. ErrorCodeEnum resultFromFetch(Error_NotInit);
  530. CustomWebUrlConfig defaultOne;
  531. if (!hasDefaultFromCustom) {
  532. resultFromFetch = GetParamCurrentUseing(defaultOne);
  533. if (resultFromFetch == Error_Succeed) {
  534. Dbg("add root config");
  535. realCnt += 1;
  536. defaultOne.curStatus = WEBURL_STATUS_DEFAULT;
  537. }
  538. }
  539. Dbg("total count: %d", realCnt);
  540. ctx->Ans.index.Init(realCnt);
  541. ctx->Ans.terminalNo.Init(realCnt);
  542. ctx->Ans.branchIP.Init(realCnt);
  543. ctx->Ans.remark.Init(realCnt);
  544. ctx->Ans.env.Init(realCnt);
  545. ctx->Ans.status.Init(realCnt);
  546. if (resultFromFetch == Error_Succeed) {
  547. ctx->Ans.index[curIndex] = defaultOne.index;
  548. ctx->Ans.terminalNo[curIndex] = defaultOne.strFutureUrl;
  549. ctx->Ans.branchIP[curIndex] = defaultOne.strAdUrl;
  550. ctx->Ans.remark[curIndex] = defaultOne.strRemark;
  551. ctx->Ans.env[curIndex] = defaultOne.useEnv;
  552. ctx->Ans.status[curIndex] = defaultOne.curStatus;
  553. Dbg("index: %d", ctx->Ans.index[curIndex]);
  554. Dbg("terminalNo: %s", ctx->Ans.terminalNo[curIndex].GetData());
  555. Dbg("branchIP: %s", ctx->Ans.branchIP[curIndex].GetData());
  556. Dbg("remark: %s", ctx->Ans.remark[curIndex].GetData());
  557. Dbg("env: %d", ctx->Ans.env[curIndex]);
  558. Dbg("status: %d", ctx->Ans.status[curIndex]);
  559. curIndex++;
  560. }
  561. for (int i = 0; i < configs.GetCount(); ++i) {
  562. CustomWebUrlConfig& item = configs[i];
  563. if (item.IsValid()) {
  564. ctx->Ans.index[curIndex] = item.index;
  565. ctx->Ans.terminalNo[curIndex] = item.strFutureUrl;
  566. ctx->Ans.branchIP[curIndex] = item.strAdUrl;
  567. ctx->Ans.remark[curIndex] = item.strRemark;
  568. ctx->Ans.env[curIndex] = item.useEnv;
  569. ctx->Ans.status[curIndex] = item.curStatus;
  570. curIndex++;
  571. }
  572. }
  573. ctx->Answer(result);
  574. }
  575. void CCenterSettingEntity::DownloadCenterFiles(SpReqAnsContext<CenterSettingService_DownloadCenterFiles_Req, CenterSettingService_DownloadCenterFiles_Ans>::Pointer ctx)
  576. {
  577. if (IsDownloadPending()) {
  578. Dbg("%s: last download call not complet", __FUNCTION__);
  579. ctx->Answer(Error_Duplication);
  580. return;
  581. }
  582. if (ctx->Req.strAddr == NULL || strlen(ctx->Req.strAddr) == 0 || ctx->Req.nPort <= 0) {
  583. ctx->Answer(Error_Param);
  584. return;
  585. }
  586. m_spDownloadCallEx = ctx;
  587. SecureClientRelease();
  588. m_pConnection = new CCenterSettingConn(this);
  589. if (!m_pConnection->Connect(ctx->Req.strAddr, ctx->Req.nPort, 3)) {
  590. SecureClientRelease();
  591. ReturnAndClearDownloadContext(Error_NetBroken);
  592. } else {
  593. Dbg("custom download from server %s:%d", ctx->Req.strAddr.GetData(), ctx->Req.nPort, 3);
  594. if (ctx->Req.deleteIfExist) {
  595. Dbg("Remove CenterSettings file!");
  596. RemoveAllCenterSettingFiles();
  597. }
  598. CSystemStaticInfo info;
  599. GetFunction()->GetSystemStaticInfo(info);
  600. if (!ctx->Req.additional1.IsNullOrEmpty()) {
  601. Dbg("Render TeminalNo from %s to %s", info.strTerminalID.GetData(), ctx->Req.additional1.GetData());
  602. info.strTerminalID = ctx->Req.additional1;
  603. }
  604. /** 该接口永远返回成功,所以没有做判断 [Gifur@2021127]*/
  605. ErrorCodeEnum ret = m_pConnection->BeginPollConfig(info);
  606. }
  607. }
  608. ErrorCodeEnum CCenterSettingEntity::GetSyncInfo(unsigned int& dwSyncTime, CSimpleStringA& strSyncHash, CSimpleStringA& strSyncFile)
  609. {
  610. if (m_SyncFileInfo.find((const char*)m_strCurSiteExtName) != m_SyncFileInfo.end())
  611. {
  612. auto info = m_SyncFileInfo[(const char*)m_strCurSiteExtName];
  613. dwSyncTime = info.dwSyncTime;
  614. strSyncFile = info.strFileName;
  615. strSyncHash = info.strFileHash;
  616. return Error_Succeed;
  617. }
  618. return Error_NotExist;
  619. }
  620. bool CCenterSettingEntity::ParseIPAddress(const char *str, CSimpleStringA &ip, int &port)
  621. {
  622. if (str)
  623. {
  624. char tmp1[32] = {};
  625. char tmp2[16] = {};
  626. sscanf(str, "%s %s", tmp1, tmp2);
  627. if (tmp1[0] != 0 && tmp2[0] != 0)
  628. {
  629. ip = tmp1;
  630. port = atoi(tmp2);
  631. return true;
  632. }
  633. }
  634. return false;
  635. }
  636. bool CCenterSettingEntity::TryExtractSiteFromFileName(
  637. const char *pszPath, CSimpleStringA &strFileName, CSimpleStringA &strSite)
  638. {
  639. const regex re("(CenterSetting\.(.+)\.ini$)");
  640. cmatch result;
  641. if (!regex_search(pszPath, result, re))
  642. return false;
  643. strFileName = result[1].str().c_str();
  644. strSite = result[2].str().c_str();
  645. return true;
  646. }
  647. ErrorCodeEnum CCenterSettingEntity::GetWebUrlInfoFromCenterSettings(CustomWebUrlConfig& config)
  648. {
  649. CSmartPointer<IConfigInfo> spCerConfig;
  650. ErrorCodeEnum err = GetFunction()->OpenConfig(Config_CenterSetting, spCerConfig);
  651. SpIniMappingTable table;
  652. CSimpleStringA entityName("Chromium");
  653. // clean cache every time
  654. table.AddEntryString(entityName, "UserMgrUrlFulture", config.strFutureUrl, "");
  655. table.AddEntryString(entityName, "UserMgrAd", config.strAdUrl, "");
  656. err = table.Load(spCerConfig);
  657. if (err == Error_Succeed) {
  658. config.configFrom = WEBURL_CONFIG_CENTESETTING;
  659. config.curStatus = WEBURL_STATUS_PROVIDE;
  660. config.useEnv = WEBURL_ENV_ALL;
  661. config.strRemark = "Default Config From CenterSettings";
  662. }
  663. if (config.strFutureUrl.IsNullOrEmpty()) {
  664. err = Error_NotConfig;
  665. }
  666. return err;
  667. }
  668. bool CCenterSettingEntity::SecureClientConnect(ConnectServerType type, LPCTSTR serverIP, int port)
  669. {
  670. LOG_FUNCTION();
  671. Dbg("connect type:%d, %s::%d", type, serverIP, port);
  672. if (type == ConnectServerType::DEFAULT && IsServerConnectedNow())
  673. return true;
  674. SecureClientRelease();
  675. m_bUseBackupNow = (type == ConnectServerType::BACKUP);
  676. m_pConnection = new CCenterSettingConn(this);
  677. //TerminalList中或Mode=1的终端走新模式,否则走旧模式
  678. if (m_pConnection->InTerminalList() || m_pConnection->GetMode()) {
  679. ErrorCodeEnum rc = m_pConnection->GrayLaunch(m_bGrayLaunch);
  680. if (Error_Succeed != rc) {
  681. LogWarn(Severity_Middle, rc, ERR_MOD_CENTERSETTING_GRAY_CONNECT_FAILED, "Get grayLaunch failed.");
  682. return false;
  683. } else if(m_bGrayLaunch) {
  684. LogWarn(Severity_Middle, Error_Succeed, EVENT_MOD_CENTERSETTING_GRAY_CONNECT_SUCC, "Get grayLaunch succ.");
  685. return true;
  686. }
  687. }
  688. if (m_bUseBackupNow)
  689. {
  690. CSmartPointer<IConfigInfo> pConfig;
  691. auto rc = GetFunction()->OpenConfig(Config_CenterSetting, pConfig);
  692. assert(rc == Error_Succeed);
  693. CSimpleStringA strLastServer;
  694. rc = pConfig->ReadConfigValue("Main", "LastServer", strLastServer);
  695. if (rc != Error_Succeed || strLastServer.IsNullOrEmpty())
  696. {
  697. Dbg("read last server from center setting fail");
  698. return false;
  699. }
  700. CSimpleStringA strIP;
  701. int nPort(0);
  702. if (!ParseIPAddress(strLastServer, strIP, nPort))
  703. {
  704. Dbg("parse last server [%s] fail", (const char*)strLastServer);
  705. return false;
  706. }
  707. return m_pConnection->Connect(strIP, nPort, 3);
  708. } else if(type == ConnectServerType::PARAM)
  709. {
  710. Dbg("custom download from server %s:%d", serverIP, port);
  711. return m_pConnection->Connect(serverIP, port, 3);
  712. }
  713. return m_pConnection->ConnectFromCentralSetting();
  714. }
  715. void CCenterSettingEntity::SecureClientRelease()
  716. {
  717. if (m_pConnection !=NULL)
  718. {
  719. if (m_pConnection->IsConnectionOK())
  720. m_pConnection->Close();
  721. m_pConnection->DecRefCount();
  722. m_pConnection = NULL;
  723. }
  724. m_bGrayLaunch = FALSE;
  725. }
  726. void CCenterSettingEntity::OnSysVarEvent(const char* pszKey,
  727. const char* pszValue, const char* pszOldValue, const char* pszEntityName)
  728. {
  729. if ((_strnicmp(pszKey, "UIState", strlen("UIState")) == 0)) {
  730. if (_strnicmp(pszValue, "M", strlen("M")) == 0) {
  731. Dbg("enter main page");
  732. CSimpleStringA strCurFile;
  733. GetFunction()->GetPath("CenterSetting", strCurFile);
  734. CSimpleStringA strBackFile = CSimpleStringA::Format("%s.backup", strCurFile.GetData());
  735. if (!fileutil_copy_file(strBackFile, strCurFile)) {
  736. Dbg("Copy curFile to backFile failed: %d", GetLastError());
  737. }
  738. GetFunction()->UnregistSysVarEvent("UIState");
  739. } else {
  740. Dbg("not main page[%s]", pszValue);
  741. }
  742. }
  743. }
  744. bool CCenterSettingEntity::GetServerIP()
  745. {
  746. LOG_FUNCTION();
  747. CSmartPointer<IConfigInfo> pConfig;
  748. auto rc = GetFunction()->OpenConfig(Config_CenterSetting, pConfig);
  749. assert(rc == Error_Succeed);
  750. CSimpleStringA strServer;
  751. rc = pConfig->ReadConfigValue("CenterSetting", "Server", strServer);
  752. if (rc != Error_Succeed || strServer.IsNullOrEmpty()) {
  753. Dbg("read strServer from center setting fail.");
  754. Dbg("use backup center setting...");
  755. CSimpleStringA strBackFile, strCurFile;
  756. GetFunction()->GetPath("CenterSetting", strCurFile);
  757. strBackFile = CSimpleStringA::Format("%s.backup", strCurFile.GetData());
  758. if(-1 == fileutil_copy_file(strCurFile, strBackFile)) {
  759. Dbg("Copy backFile to curFile failed: %d", GetLastError());
  760. return false;
  761. } else {
  762. rc = pConfig->ReadConfigValue("CenterSetting", "Server", strServer);
  763. if (rc != Error_Succeed || strServer.IsNullOrEmpty()) {
  764. return false;
  765. }
  766. }
  767. }
  768. return true;
  769. }
  770. ErrorCodeEnum CCenterSettingEntity::UpdateTerminalInfoAtChange(const CSimpleStringA& newTerminalInfo)
  771. {
  772. ErrorCodeEnum result(Error_Succeed);
  773. CSystemStaticInfo sysInfo;
  774. result = GetFunction()->GetSystemStaticInfo(sysInfo);
  775. if (result == Error_Succeed) {
  776. if (sysInfo.strTerminalID == newTerminalInfo) {
  777. result = Error_AlreadyExist;
  778. } else {
  779. CSimpleStringA strTemp = CSimpleStringA::Format("更新终端号信息:%s -> %s", sysInfo.strTerminalID.GetData(), newTerminalInfo.GetData());
  780. LogWarn(Severity_High, Error_Debug, EVENT_CENTERSETTING_CHANGE_ROOT_TERMINALNO, strTemp);
  781. CSimpleStringA strRootCfgPath, rootPath;
  782. ErrorCodeEnum ec = GetFunction()->GetPath("HardwareCfg", strRootCfgPath);
  783. rootPath = strRootCfgPath;
  784. rootPath += SPLIT_SLASH_STR;
  785. rootPath += "root.ini";
  786. inifile_write_str(rootPath, "Terminal", "TerminalNo", newTerminalInfo);
  787. inifile_write_str(rootPath, "Terminal", "LastTerminalNo", sysInfo.strTerminalID);
  788. char tmp[32] = {'\0'};
  789. inifile_read_str_s("Terminal", "TerminalNo", "", tmp, 31, rootPath);
  790. CSimpleStringA strConfirmTerminalNo(tmp);
  791. if (strConfirmTerminalNo != newTerminalInfo) {
  792. Dbg("Update TeminalNo failed: read returned: %s, write into: %s", strConfirmTerminalNo.GetData(), newTerminalInfo.GetData());
  793. result = Error_FailVerify;
  794. }
  795. }
  796. }
  797. return result;
  798. }
  799. bool CCenterSettingEntity::IsParamCurrentUsed(const CSimpleStringA& strTerminalInfo, const CSimpleStringA& strServerIP, DWORD& outMask)
  800. {
  801. bool result(true);
  802. outMask = 0;
  803. CSystemStaticInfo sysInfo;
  804. GetFunction()->GetSystemStaticInfo(sysInfo);
  805. if (sysInfo.strTerminalID.IsNullOrEmpty() || sysInfo.strTerminalID != strTerminalInfo) {
  806. result = false;
  807. } else {
  808. outMask |= 0x1;
  809. }
  810. CSmartPointer<IConfigInfo> pConfig;
  811. CSimpleStringA strServer;
  812. GetFunction()->OpenConfig(Config_CenterSetting, pConfig);
  813. pConfig->ReadConfigValue("CenterSetting", "Server", strServer);
  814. CAutoArray<CSimpleStringA> ipPorts = strServer.Split(' ');
  815. if (strServer.IsNullOrEmpty() || ipPorts.GetCount() != 2 || ipPorts[0] != strServerIP) {
  816. result = false;
  817. } else {
  818. outMask |= 0x2;
  819. }
  820. return result;
  821. }
  822. ErrorCodeEnum CCenterSettingEntity::GetParamCurrentUseing(CustomWebUrlConfig& config)
  823. {
  824. ErrorCodeEnum result(Error_Succeed);
  825. CSystemStaticInfo sysInfo;
  826. result = GetFunction()->GetSystemStaticInfo(sysInfo);
  827. config.strFutureUrl = sysInfo.strTerminalID;
  828. CSmartPointer<IConfigInfo> pConfig;
  829. CSimpleStringA strServer;
  830. result = GetFunction()->OpenConfig(Config_CenterSetting, pConfig);
  831. result = pConfig->ReadConfigValue("CenterSetting", "Server", strServer);
  832. CAutoArray<CSimpleStringA> ipPorts = strServer.Split(' ');
  833. if (ipPorts.GetCount() == 2) {
  834. config.strAdUrl = ipPorts[0];
  835. } else {
  836. config.strAdUrl = "";
  837. }
  838. config.index = WEBURL_ITEM_INDEX_CENTERSETTING;
  839. config.configFrom = WEBURL_CONFIG_CENTESETTING;
  840. config.curStatus = WEBURL_STATUS_PROVIDE;
  841. config.useEnv = WEBURL_ENV_ALL;
  842. config.strRemark = "root.ini&CenterSetting";
  843. return result;
  844. }
  845. void CCenterSettingEntity::RemoveAllCenterSettingFiles()
  846. {
  847. CSimpleStringA strEntityCfgPath;
  848. GetFunction()->GetPath("Cfg", strEntityCfgPath);
  849. array_header_t* subs = fileutil_get_sub_files_a(strEntityCfgPath);
  850. if (subs) {
  851. regex_t reg;
  852. CSimpleStringA pattern = "CenterSetting\.[a-zA-Z0-9_\\(\\)\\-]*\.ini";
  853. int ret = regcomp(&reg, pattern, REG_EXTENDED | REG_NOSUB);
  854. if (ret) {
  855. char ebuff[256];
  856. regerror(ret, &reg, ebuff, 256);
  857. Dbg("regex failed: %s", ebuff);
  858. } else {
  859. Dbg("pattern: %s", pattern.GetData());
  860. for (int i = 0; i < subs->nelts; ++i) {
  861. char* filenamePath = ARRAY_IDX(subs, i, char*);
  862. char* filename = &filenamePath[strEntityCfgPath.GetLength() + 1];
  863. ret = regexec(&reg, filename, 0, NULL, 0);
  864. if (0 == ret) {
  865. Dbg("filename %s matched and remove it.", filename);
  866. fileutil_delete_file(filenamePath);
  867. }
  868. }
  869. }
  870. toolkit_array_free2(subs);
  871. }
  872. if (m_pConnection != NULL) {
  873. m_pConnection->DeleteErrorFiles(strEntityCfgPath);
  874. }
  875. }
  876. ErrorCodeEnum CCenterSettingEntity::ConfirmCenterSettingsFileAndUpdateIfNecessary(const CSimpleStringA& serverIP)
  877. {
  878. CSmartPointer<IConfigInfo> pConfig;
  879. CSimpleStringA strServer;
  880. ErrorCodeEnum result = GetFunction()->OpenConfig(Config_CenterSetting, pConfig);
  881. result = pConfig->ReadConfigValue("CenterSetting", "Server", strServer);
  882. CAutoArray<CSimpleStringA> ipPorts = strServer.Split(' ');
  883. if (strServer.IsNullOrEmpty() || ipPorts.GetCount() !=2 || ipPorts[0] != serverIP) {
  884. result = Error_FailVerify;
  885. }
  886. return result;
  887. }
  888. void CCenterSettingService::Handle_EditWebUrl(SpReqAnsContext<CenterSettingService_EditWebUrl_Req, CenterSettingService_EditWebUrl_Ans>::Pointer ctx)
  889. {
  890. LOG_FUNCTION();
  891. m_pEntity->EditWebUrl(ctx);
  892. }
  893. void CCenterSettingService::Handle_GetWebUrlList(SpReqAnsContext<CenterSettingService_GetWebUrlList_Req, CenterSettingService_GetWebUrlList_Ans>::Pointer ctx)
  894. {
  895. LOG_FUNCTION();
  896. m_pEntity->GetWebUrlList(ctx);
  897. }
  898. void CCenterSettingService::Handle_GetActiveCustomUrl(SpReqAnsContext<CenterSettingService_GetActiveCustomUrl_Req, CenterSettingService_GetActiveCustomUrl_Ans>::Pointer ctx)
  899. {
  900. LOG_FUNCTION();
  901. m_pEntity->GetActiveCustomUrl(ctx);
  902. }
  903. void CCenterSettingService::Handle_EditTerminalBackupInfo(SpReqAnsContext<CenterSettingService_EditTerminalBackupInfo_Req, CenterSettingService_EditTerminalBackupInfo_Ans>::Pointer ctx)
  904. {
  905. LOG_FUNCTION();
  906. m_pEntity->EditTerminalBackupInfo(ctx);
  907. }
  908. void CCenterSettingService::Handle_GetTerminalBackupInfoList(SpReqAnsContext<CenterSettingService_GetTerminalBackupInfoList_Req, CenterSettingService_GetTerminalBackupInfoList_Ans>::Pointer ctx)
  909. {
  910. LOG_FUNCTION();
  911. m_pEntity->GetTerminalBackupInfoList(ctx);
  912. }
  913. void CCenterSettingService::Handle_DownloadCenterFiles(SpReqAnsContext<CenterSettingService_DownloadCenterFiles_Req, CenterSettingService_DownloadCenterFiles_Ans>::Pointer ctx)
  914. {
  915. LOG_FUNCTION();
  916. m_pEntity->DownloadCenterFiles(ctx);
  917. }
  918. SP_BEGIN_ENTITY_MAP()
  919. SP_ENTITY(CCenterSettingEntity)
  920. SP_END_ENTITY_MAP()