Explorar el Código

Z991239-6443 #comment 其他参数调整

80374374 hace 4 meses
padre
commit
09c4874f0a

+ 33 - 0
Framework/libtoolkit/fileutil.c

@@ -219,6 +219,39 @@ TOOLKIT_API BOOL RemoveFileReadOnlyAttributeA(LPCSTR pszFile)
 	return FALSE;
 }
 
+TOOLKIT_API BOOL IsDirectory(LPCSTR pszDir)
+{
+	char szCurPath[MAX_PATH * 2] = { 0 };
+#ifdef _WIN32
+	HANDLE hFile;
+	WIN32_FIND_DATAA FindFileData = { 0 };
+	
+	_snprintf(szCurPath, MAX_PATH * 2, "%s//*", pszDir);
+	hFile = FindFirstFileA(szCurPath, &FindFileData); /**< find first file by given path. */
+	if (hFile == INVALID_HANDLE_VALUE)
+	{
+		FindClose(hFile);
+		return FALSE; /** 如果不能找到第一个文件,那么没有目录 */
+	}
+	else
+	{
+		FindClose(hFile);
+		return TRUE;
+	}
+#else
+	struct stat buf;
+	snprintf(szCurPath, MAX_PATH * 2, "%s//*", pszDir);
+	if (0 == stat(szCurPath, &buf))
+	{
+		return S_ISDIR(buf.st_mode);
+	}
+	else
+	{
+		return FALSE;
+	}
+#endif
+}
+
 // 递归拷贝所有文件及子文件夹
 TOOLKIT_API BOOL CopyDirA(LPCSTR pszSourceDir, LPCSTR pszDestDir)
 {

+ 2 - 0
Framework/libtoolkit/fileutil.h

@@ -32,6 +32,8 @@ TOOLKIT_API void SureUnixFileAttributeAccessable(LPCSTR pszFile);
 TOOLKIT_API BOOL RemoveFileA(LPCSTR pszFile);
 TOOLKIT_API BOOL RemoveFileReadOnlyAttributeA(LPCSTR pszFile);
 
+TOOLKIT_API BOOL IsDirectory(LPCSTR pszDir);
+
 TOOLKIT_API BOOL CopyDirA(LPCSTR pszSourceDir, LPCSTR pszDestDir);
 
 TOOLKIT_API BOOL CreateDirA(LPCSTR lpDirPath, BOOL bRecursive);

+ 3 - 0
Framework/libtoolkit/shm_mem.c

@@ -87,6 +87,9 @@ TOOLKIT_API int shm_getmem(int key, void** hint, int newcreate)
 #ifndef USE_ANON_MMAP
 
 #ifdef USE_DEVSHM_MMAP
+	int fd = -1;
+	int flag = 0;
+
     WLog_WARN(TAG, "using /dev/shm memory");
     flag = O_RDWR;
     if (newcreate) {

+ 1 - 1
Framework/spbase/sp_pst.h

@@ -2,7 +2,7 @@
 #define SP_PST_H
 
 #pragma once
-//TODO: CrossPlaform 文件移除,没有使用  [Gifur@202584]
+//TODO: CrossPlaform 文件移除,没有使用,待讨论确认  [Gifur@202584]
 #ifdef __cplusplus
 extern "C" {
 #endif

+ 5 - 5
Module/mod_accessauth/AccessAuthFSM.cpp

@@ -151,7 +151,7 @@ struct TimeSynTask : ITaskSp
 			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("decodedSessionKey=%s,%d", decodedSessionKey, decodedSessionKeyLen);
 			DWORD rc = Error_InvalidState;
 			rc = m_fsm->HandleTimeSyn(timeSyncAns.timeDiff, (BYTE*)decodedSessionKey);
-			delete decodedSessionKey;
+			delete [] decodedSessionKey;
 			if (rc == Error_Succeed) {
 				auto pEvent = new FSMEvent(CAccessAuthFSM::Event_EndSyncTime);
 				m_fsm->PostEventFIFO(pEvent);
@@ -704,10 +704,10 @@ DWORD CAccessAuthFSM::HandleGetToken(BYTE* enToken1, BYTE* sharedKey, BYTE* enTo
 	memcpy(enToken2, enToken2_acs, enToken2_acs_len);
 	memcpy(retHash, hash_acs, hash_acs_len);
 
-	delete enToken1_acs;
-	delete sharedKey_acs;
-	delete enToken2_acs;
-	delete hash_acs;
+	delete [] enToken1_acs;
+	delete [] sharedKey_acs;
+	delete [] enToken2_acs;
+	delete [] hash_acs;
 
 	BYTE enToken[512 + 16] = { 0 };
 	memcpy(enToken, enToken1, 256);

+ 12 - 4
Module/mod_accessauth/mod_AccessAuth.cpp

@@ -511,6 +511,7 @@ bool CAccessAuthEntity::SaveAuthKey(BYTE *pKey)
 	if (!DecWithSM2PriKey((BYTE*)key, kenLen, (BYTE*)pPlainKey, &plainKeyLen, (BYTE*)pDecryptPrivateKey, decryprtLen)) {
 		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("使用私钥解密失败!");
 		printPasswdError("终端初始化未完成,请重置秘钥进行初始化");
+		delete[] key;
 		return false;
 	}
 	if (plainKeyLen != KEY_SIZE) {
@@ -518,10 +519,12 @@ bool CAccessAuthEntity::SaveAuthKey(BYTE *pKey)
 	}
 
 	memcpy(m_AuthSessionKey, pPlainKey, KEY_SIZE);
+	delete[] key;
 
 	return true;
 }
 
+//TODO: CrossPlaform 采用 EntityUtil中的 StrBuf2HexBuf  [Gifur@2025821]
 static BYTE* ConvertHexStrToBytes(const char *pszStr)
 {
 	if (pszStr == NULL || strlen(pszStr) == 0)
@@ -617,7 +620,6 @@ bool CAccessAuthEntity::GetTerminalPublicKey(BYTE* pBuf, int& nBufLen, string& p
 	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetTerminalPublicKey")("iPublicKeyLen=%d,iPrivateKeyLen=%d", iPublicKeyLen, iPrivateKeyLen);
 	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetTerminalPublicKey")("[btPublicKey=%s]", (char*)btPublicKey);
 
-	//TODO: CrossPlaform 待定 [Gifur@2025820]
 	char* pEncode = SP::Module::Util::Str2Hex((char*)btPublicKey, iPublicKeyLen);
 	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetTerminalPublicKey")("pEncode=%s,%d", pEncode, strlen(pEncode));
 
@@ -659,6 +661,9 @@ bool CAccessAuthEntity::GetTerminalPublicKey(BYTE* pBuf, int& nBufLen, string& p
 
 	memcpy(pBuf, pDecode, nBufLen);
 	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetTerminalPublicKey")("pBuf[0]=%02X,nBufLen=%d", pBuf[0], nBufLen);
+
+	delete[] pDecode;
+
 	return true;
 }
 
@@ -982,9 +987,12 @@ bool CAccessAuthEntity::SendInitMKReqACS(CInitlizerMKReq& initMKReq)
 	CBlob encInfo;
 	char* hexStr = "21009872C31CBC00D0C8F421D09CF707";
 	BYTE key[KEY_SIZE] = { 0 };
-	memcpy(key, ConvertHexStrToBytes(hexStr), KEY_SIZE);
-	//char key[KEY_SIZE] = { 0 };
-	//memcpy(key, "1234567890123456234", KEY_SIZE);
+	BYTE* btTmp = ConvertHexStrToBytes(hexStr);
+	memcpy(key, btTmp, KEY_SIZE);
+	if (btTmp != NULL) {
+		free(btTmp);
+		btTmp = NULL;
+	}
 	nRet = (ErrorCodeEnum)m_FSM.GetEncTerminalInfoWithKey(encInfo, key);
 	if (nRet != Error_Succeed)
 	{

+ 0 - 104
Module/mod_localmediaplay/AdvertManage/BaseFun.cpp

@@ -42,27 +42,6 @@ void split(const string& src, const string& separator, vector<string>& dest)
 	dest.push_back(substring);
 }
 
-bool  checkDirExist(const string &strPath)
-{
-	if (ExistsDir(strPath.c_str())){
-		return true;
-	}
-	else{
-		return false;
-	}
-}
-
-
-bool checkFileExist(string fileName)
-{
-	if (ExistsFile(fileName.c_str())){
-		return true;
-	}
-	else{
-		return false;
-	}
-}
-
 //TODO: CrossPlaform  [Gifur@2025730]
 void StringToWstring(std::wstring& szDst, std::string str)
 {
@@ -89,86 +68,3 @@ void StringToWstring(std::wstring& szDst, std::string str)
 #endif 
 }
 
-//TODO: CrossPlaform  [Gifur@2025730]
-bool createDir(const string &filePath)
-{
-#ifdef RVC_OS_WIN
-	return 0 == _mkdir(filePath.c_str());
-#else
-	if (CreateDirRecursive(filePath.c_str()))
-	{
-		return true;
-	}
-	else
-	{
-		return false;
-	}
-#endif 
-}
-
-//TODO: CrossPlaform 采用框架统一的函数  [Gifur@2025728]
-BOOL IsDirectory(const char *pDir)
-{
-	char szCurPath[MAX_PATH*2] = {0};
-#ifdef RVC_OS_WIN
-	_snprintf(szCurPath, MAX_PATH * 2, "%s//*", pDir);
-
-	WIN32_FIND_DATAA FindFileData = {0};
-	//ZeroMemory(&FindFileData, sizeof(WIN32_FIND_DATAA));
-
-	HANDLE hFile = FindFirstFileA(szCurPath, &FindFileData); /**< find first file by given path. */
-
-	if (hFile == INVALID_HANDLE_VALUE)
-	{
-		FindClose(hFile);
-		return FALSE; /** 如果不能找到第一个文件,那么没有目录 */
-	}
-	else
-	{
-		FindClose(hFile);
-		return TRUE;
-	}
-
-#else
-	snprintf(szCurPath, MAX_PATH * 2, "%s//*", pDir);
-	struct stat buf;
-	if (0 == stat(szCurPath, &buf))
-	{
-		return S_ISDIR(buf.st_mode);
-	}
-	else
-	{
-		return FALSE;
-	}
-#endif // RVC_OS_WIN
-}
-
-
-
-void getDirs(string path, vector<string> &ownname)
-{
-#ifdef RVC_OS_WIN
-	long   hFile = 0;
-	struct _finddata_t fileinfo;
-	string p;
-	if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1)
-	{
-		do
-		{
-			//如果是目录加入列表  
-			if ((fileinfo.attrib & _A_SUBDIR) && strcmp(fileinfo.name, ".") && strcmp(fileinfo.name, ".."))
-				ownname.push_back(fileinfo.name);
-		} while (_findnext(hFile, &fileinfo) == 0);
-		_findclose(hFile);
-	}
-#else
-	array_header_t* subdirs = fileutil_get_sub_files(path.c_str());
-	int i;
-	for (i = 0; i < subdirs->nelts; ++i) {
-		char* strsubdir = ARRAY_IDX(subdirs, i, char*);
-		ownname.push_back(strsubdir);
-	}
-
-#endif // RVC_OS_WIN
-}
-

+ 0 - 5
Module/mod_localmediaplay/AdvertManage/BaseFun.h

@@ -11,9 +11,4 @@
 using namespace std;
 
 void split(const string& src, const string& separator, vector<string>& dest);
-bool checkDirExist(const string &strPath);
-bool checkFileExist(string fileName);
-void getDirs(string path, vector<string> &ownname);
-bool createDir(const string &filePath);
-bool removeDir(const string &filePaht);
 void StringToWstring(std::wstring& szDst, std::string str);

+ 9 - 16
Module/mod_localmediaplay/AdvertManage/MediaManage.cpp

@@ -7,7 +7,7 @@
 mediaManage::mediaManage()
 {
 	m_curParse.clear();
-	if (checkDirExist(DEFAULT_RESOURSE_PATH))
+	if (ExistsDirA(DEFAULT_RESOURSE_PATH))
 	{
 		//DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Set defaultAdvertPath:%s, defaultDownloadPath:%s", DEFAULT_RESOURSE_PATH, DEFAULT_DOWNLOAD_PATH);
 		setDefaultAddvertPath(string(DEFAULT_RESOURSE_PATH));
@@ -174,18 +174,11 @@ bool mediaManage::AddResourceList(vector<string> resourceList)
 		StringToWstring(wfileName, fileName);
 		StringToWstring(wdirPath, dirPath);
 
-		if (!checkFileExist(dirPath))
+		if (!ExistsFileA(dirPath.c_str()))
 		{
 			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("dir %s not exist!", dirPath.c_str());
 			continue;
 		}
-/*
-		if (!checkFileExist(dirPath) && createDir(dirPath) && !Unzip2Folder((BSTR)wfileName.c_str(), (BSTR)wdirPath.c_str()))
-		{
-			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("unzip %s to %s fail!", fileName.c_str(), dirPath.c_str());
-			continue;
-		}
-		*/
 		string configPath = "";
 		if (!findVaildConfig(dirPath, configPath))
 		{
@@ -219,14 +212,14 @@ void mediaManage::InitResourceListByLocal()
 
 	vector<ResourceParse> headList, branchList, networkList, allList;
 
-	if (!checkFileExist(headFile)) {
+	if (!ExistsFileA(headFile.c_str())) {
 		//DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("head config %s not exist!", headFile.c_str());
 	}
 	else if (!parseResourceIni(headFile.c_str(), headList)) {
 		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("parse head config %s fail!", headFile.c_str());
 	}
 
-	if (!checkFileExist(branchFile)) {
+	if (!ExistsFileA(branchFile.c_str())) {
 		//DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("branch config %s not exist!", branchFile.c_str());
 	}
 	else if (!parseResourceIni(branchFile.c_str(), branchList)) {
@@ -234,7 +227,7 @@ void mediaManage::InitResourceListByLocal()
 	}
 
 
-	if (!checkFileExist(networkFile)) {
+	if (!ExistsFileA(networkFile.c_str())) {
 		//DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("network config %s not exist!", networkFile.c_str());
 	}
 	else if (!parseResourceIni(networkFile.c_str(), networkList)) {
@@ -334,17 +327,17 @@ bool mediaManage::findVaildConfig(string dirPath, string &configPath)
 	string branchFile = dirPath + SPLIT_SLASH_STR + BRANCHINI_NAME;
 	string networkFile = dirPath + SPLIT_SLASH_STR + NETWORKINI_NAME;
 
-	if (checkFileExist(headFile))
+	if (ExistsFileA(headFile.c_str()))
 	{
 		configPath = headFile;
 		return true;
 	}
-	else if (checkFileExist(branchFile))
+	else if (ExistsFileA(branchFile.c_str()))
 	{
 		configPath = branchFile;
 		return true;
 	}
-	else if (checkFileExist(networkFile))
+	else if (ExistsFileA(networkFile.c_str()))
 	{
 		configPath = networkFile;
 		return true;
@@ -355,5 +348,5 @@ bool mediaManage::findVaildConfig(string dirPath, string &configPath)
 
 bool mediaManage::IsResourceExist(string strPath, string strName)
 {
-	return checkFileExist(strPath + strName);
+	return ExistsFileA((strPath + strName).c_str());
 }

+ 5 - 5
Module/mod_recorder/mod_recorder.cpp

@@ -1036,10 +1036,10 @@ on_next:
 		if (0 == memcmp(ptr->d_name, RVC_TRANSATCION_RECORD_SUFFIX, strlen(RVC_TRANSATCION_RECORD_SUFFIX)) ||
 			0 == memcmp(ptr->d_name, RVC_ENCRYPT_TRANSATCION_RECORD_SUFFIX, strlen(RVC_ENCRYPT_TRANSATCION_RECORD_SUFFIX))) {
 			CSimpleStringA srcfile = CSimpleStringA::Format("%s%s", m_TempDir.GetData(), ptr->d_name);
-			unsigned long uSize = GetFileSize(srcfile.GetData());
+			unsigned long uSize = ReadFileSize(srcfile.GetData());
 			if (RVC_MIN_RECORD_FILESIZE >= uSize) {
 				LogWarn(Severity_Low, Error_Debug, LOG_EVT_INVALID_RECORD_FILE, CSimpleStringA::Format("invalid record file %s, delelte it.", srcfile.GetData()).GetData());
-				RvcDeleteFile(srcfile.GetData());
+				RemoveFileA(srcfile.GetData());
 				continue;
 			}
 
@@ -1048,7 +1048,7 @@ on_next:
 				cb.dbg = &rvcDbg;
 				if (false == is_file_encrypted(srcfile.GetData(), &cb)) {
 					if (strstr(ptr->d_name, RVC_FILEENC_STR)) {
-						RvcDeleteFile(srcfile.GetData());
+						RemoveFileA(srcfile.GetData());
 						continue;
 					}
 
@@ -1069,7 +1069,7 @@ on_next:
 						}
 						else {
 							LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_RENAME_FAILED, CSimpleStringA::Format("%s(%d) while rename %s.", strerror(errno), errno, srcfile.GetData()).GetData());
-							RvcDeleteFile(srcfile.GetData());
+							RemoveFileA(srcfile.GetData());
 							continue;
 						}
 					}
@@ -1078,7 +1078,7 @@ on_next:
 
 			if (strstr(srcfile.GetData(), RVC_FILEENC_STR)) {
 				LogWarn(Severity_Low, Error_Debug, LOG_EVT_ABNORMAL_RECORD_FILE, CSimpleStringA::Format("abnormal file %s, delete it.", srcfile.GetData()).GetData());
-				RvcDeleteFile(srcfile.GetData());
+				RemoveFileA(srcfile.GetData());
 				continue;
 			}