Procházet zdrojové kódy

Z991239-6443 #comment loadcmbpirnt

80374374 před 2 měsíci
rodič
revize
682e2893ee
1 změnil soubory, kde provedl 51 přidání a 63 odebrání
  1. 51 63
      Module/mod_ContactlessCard/ContactlessFSM.cpp

+ 51 - 63
Module/mod_ContactlessCard/ContactlessFSM.cpp

@@ -9,8 +9,11 @@
 #include "publicFunExport.h"
 #include "CommEntityUtil.hpp"
 #ifdef RVC_OS_WIN
+#define CMBPRINT_LIBRARY_NAME "CMBPrint.dll"
 #else
 #include <dlfcn.h>
+#include <winpr/crt.h>
+#define CMBPRINT_LIBRARY_NAME "libCMBPrint.so"
 #endif //RVC_OS_WIN
 
 
@@ -1197,10 +1200,6 @@ int CContactlessCardFSM::PreOnline(SpReqAnsContext<ContactlessCardService_PreOnl
 		}
 		return 0;
 	}
-	//if (m_cardType == CI_CARDTYPE_IC)
-	//{
-	//	ProcessRestrict();
-	//	CardholderVerify();
 	m_pCardProcess->TermRiskManage();
 	CSimpleStringA taaResult;
 	BYTE bt9f27 = 0;
@@ -1240,12 +1239,7 @@ int CContactlessCardFSM::PreOnline(SpReqAnsContext<ContactlessCardService_PreOnl
 
 	char arqcLen[8];
 	ZeroMemory(arqcLen,sizeof(arqcLen));
-	//TODO: CrossPlaform  [Gifur@2025729]
-#ifdef RVC_OS_WIN
-    itoa(lenRet, arqcLen, 10);
-#else
-    sprintf(arqcLen, "%d", lenRet);
-#endif // RVC_OS_WIN
+	_itoa(lenRet, arqcLen, 10);
 	ICData appExpiryDate(false,0x5f,0x24);
 	if (m_pCardProcess->FindTagValue(TAG_VECTOR_IC,appExpiryDate,false,0) == -1)
 	{
@@ -1365,11 +1359,29 @@ int CContactlessCardFSM::PreOnline(SpReqAnsContext<ContactlessCardService_PreOnl
 
 	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("data to host(less)[%s],baseICData length:%d", txtresult.c_str(), baseICData.length());
 
+	if (pCID != NULL)
+	{
+		delete[] pCID;
+		pCID = NULL;
+	}
+
 	if (m_pDataToARQC != NULL)
 	{
-		delete []m_pDataToARQC;
+		delete [] m_pDataToARQC;
 		m_pDataToARQC = NULL;
 	}
+
+	if (pIssueBankLen != NULL)
+	{
+		delete[] pIssueBankLen;
+		pIssueBankLen = NULL;
+	}
+
+	if (pExpireDate != NULL) {
+		delete[] pExpireDate;
+		pExpireDate = NULL;
+	}
+
 	ctx->Answer(Error_Succeed);
 	return 0;
 }
@@ -1500,59 +1512,41 @@ int CContactlessCardFSM::QueryCardInfo(SpReqAnsContext<ContactlessCardService_Qu
 
 bool CContactlessCardFSM::LoadCMBPrint(CSimpleStringA csBinPath)
 {
-	if (cmdDecodeEx == NULL) {
-		CSimpleStringA csCMBPrint("");
+	if (cmdDecodeEx != NULL) return true;
 
-		//TODO: CrossPlaform  [Gifur@2025730]
-#ifdef RVC_OS_WIN
-		csCMBPrint = "CMBPrint.dll";
-		csCMBPrint = csBinPath + SPLIT_SLASH_STR + csCMBPrint;
-		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("cmbpath %s", (const char*)csCMBPrint);
-		HMODULE hr = LoadLibraryA(csCMBPrint);
-		if (hr == NULL)
-		{
-			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA2J18")("Load CMBPrint failed(%d).", hr);
-			return false;
-		}
-		if ((cmdDecodeMag2 = (lpCMBdecodeMag2)GetProcAddress(hr, "CMBdecodeMag2")) == NULL)
-		{
-			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA2J18")("Get Mag2 address failed.");
-			return false;
-		}
-		if ((cmdDecodeEx = (lpCMBdecodeEx)GetProcAddress(hr, "CMBdecodeEx")) == NULL)
-		{
-			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA2J18")("Get Mag23Ex address failed.");
-			cmdDecodeMag2 = NULL;
-			return false;
+	bool result(false);
+	CSimpleStringA csCMBPrint(CMBPRINT_LIBRARY_NAME);
+	csCMBPrint = csBinPath + SPLIT_SLASH_STR + csCMBPrint;
+	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("cmbpath %s", (const char*)csCMBPrint);
+	do
+	{
+		if (!ExistsFileA(csCMBPrint)) {
+			DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setResultCode("RTA2J18")("Load CMBPrint %s failed: no exist", (const char*)csCMBPrint);
+			break;
 		}
-#else
-		csCMBPrint = "libCMBPrint.so";
-		csCMBPrint = csBinPath + "/" + csCMBPrint;
-		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("cmbpath %s", (const char*)csCMBPrint);
-		void* hr = NULL;
-		hr = dlopen(csCMBPrint, RTLD_LAZY);
-		if (hr == NULL)
-		{
-			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA2J18")("Load CMBPrint failed(%s).", dlerror());
-			return false;
+		toolkit_lib_t cmbPrintLib;
+		int res = toolkit_dlopen(csCMBPrint, &cmbPrintLib);
+		if (res != 0) {
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA2J18")("toolkit_dlopen[%s] failed with error %s.", csCMBPrint.GetData(), toolkit_dlerror(&cmbPrintLib));
+			break;
 		}
-		//pfunc_unpack = (PF_unpack)dlsym(hLib, "_Z6unpackPcS_i");
-		if ((cmdDecodeMag2 = (lpCMBdecodeMag2)dlsym(hr, "CMBdecodeMag2")) == NULL)
+		if ((res = toolkit_dlsym(&cmbPrintLib, "CMBdecodeMag2", (void**)&cmdDecodeMag2)) != 0)
 		{
-			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA2J18")("Get Mag2 address failed.");
-			return false;
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA2J18")("Get 'CMBdecodeMag2' Func address failed with error: %s", toolkit_dlerror(&cmbPrintLib));
+			break;
 		}
-		if ((cmdDecodeEx = (lpCMBdecodeEx)dlsym(hr, "CMBdecodeEx")) == NULL)
+		if ((res = toolkit_dlsym(&cmbPrintLib, "CMBdecodeEx", (void**)&cmdDecodeEx)) != 0)
 		{
-			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA2J18")("Get Mag23Ex address failed.");
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA2J18")("Get 'CMBdecodeEx' Func address failed with error: %s", toolkit_dlerror(&cmbPrintLib));
 			cmdDecodeMag2 = NULL;
-			return false;
+			break;
 		}
-#endif
-		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Load %s succ.", (const char*)csCMBPrint);
-	}
+		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Load %s suc.", (const char*)csCMBPrint);
+		result = true;
 
-	return true;
+	} while (false);
+
+	return result;
 }
 
 void CContactlessCardFSM::GetCardProcessLastErr(ErrorCodeEnum& eErrCode, CSimpleStringA& ApiName, CSimpleStringA& alarmMsg, CSimpleStringA& csErrMsgWithReturnCode)
@@ -1954,14 +1948,7 @@ int CContactlessCardFSM::PreOnlineJS(SpReqAnsContext<ContactlessCardService_Read
 	}
 	char arqcLen[8];
 	ZeroMemory(arqcLen, sizeof(arqcLen));
-	//TODO: CrossPlaform  [Gifur@2025729]
-#ifdef RVC_OS_WIN
-	itoa(lenRet, arqcLen, 10);
-#else
-	sprintf(arqcLen, "%d", lenRet);
-#endif // RVC_OS_WIN
-
-	
+	_itoa(lenRet, arqcLen, 10);
 
 	ICData track2(false, 0x57, 0x00), ICCardSerial(false, 0x5f, 0x34), appExpiryDate(false, 0x5f, 0x24);
 	string t2ICAccount(""), t2ICCardSerial(""), t2ICCVC(""), t2ICTrack2(""), cardType("0"),t2ICExpireDate("");
@@ -2121,6 +2108,7 @@ int CContactlessCardFSM::PreOnlineJS(SpReqAnsContext<ContactlessCardService_Read
 
 	if (pCID != NULL)
 		delete[]pCID;
+
 	if (pIssueBankLen != NULL)
 		delete[]pIssueBankLen;