浏览代码

Z991239-6192 #comment: 录像加解密库日志优化

80274480 5 月之前
父节点
当前提交
3efaa60523

+ 2 - 7
Module/mod_SalesRecorder/mod_SalesRecorder.cpp

@@ -297,11 +297,6 @@ static unsigned long GetFileSize(const char* pfilename)
 
 static void rvcDbg(filecrypt_loglevel elevel, const char* fmt, ...)
 {
-	LOG_LEVEL_E eloglevel = LOG_LEVEL_DEBUG;
-	if (FILECRYPT_LOG_INFO <= elevel) {
-		eloglevel = LOG_LEVEL_INFO;
-	}
-
 	va_list arg;
 	va_start(arg, fmt);
 
@@ -309,13 +304,13 @@ static void rvcDbg(filecrypt_loglevel elevel, const char* fmt, ...)
 	if (n >= MAX_LOG_LEN) {
 		char* buf = (char*)malloc((size_t)(n + 1));
 		vsnprintf(buf, n + 1, fmt, arg);
-		DbgWithLink(eloglevel, LOG_TYPE_SYSTEM)("%s", buf);
+		DbgWithLink((LOG_LEVEL_E)elevel, LOG_TYPE_SYSTEM)("%s", buf);
 		free(buf);
 	}
 	else {
 		char strlog[MAX_LOG_LEN] = { 0 };
 		vsnprintf(strlog, MAX_LOG_LEN, fmt, arg);
-		DbgWithLink(eloglevel, LOG_TYPE_SYSTEM)("%s", strlog);
+		DbgWithLink((LOG_LEVEL_E)elevel, LOG_TYPE_SYSTEM)("%s", strlog);
 	}
 	va_end(arg);
 }

+ 2 - 7
Module/mod_recorder/mod_recorder.cpp

@@ -93,11 +93,6 @@ static void LogRecordFileInfo(const char* pszMessage)
 
 static void rvcDbg(filecrypt_loglevel elevel, const char* fmt, ...)
 {
-	LOG_LEVEL_E eloglevel = LOG_LEVEL_DEBUG;
-	if (FILECRYPT_LOG_INFO <= elevel) {
-		eloglevel = LOG_LEVEL_INFO;
-	}
-
 	va_list arg;
 	va_start(arg, fmt);
 
@@ -105,13 +100,13 @@ static void rvcDbg(filecrypt_loglevel elevel, const char* fmt, ...)
 	if (n >= MAX_LOG_LEN) {
 		char* buf = (char*)malloc((size_t)(n + 1));
 		vsnprintf(buf, n + 1, fmt, arg);
-		DbgWithLink(eloglevel, LOG_TYPE_SYSTEM)("%s", buf);
+		DbgWithLink((LOG_LEVEL_E)elevel, LOG_TYPE_SYSTEM)("%s", buf);
 		free(buf);
 	}
 	else{
 		char strlog[MAX_LOG_LEN] = {0};
 		vsnprintf(strlog, MAX_LOG_LEN, fmt, arg);
-		DbgWithLink(eloglevel, LOG_TYPE_SYSTEM)("%s", strlog);
+		DbgWithLink((LOG_LEVEL_E)elevel, LOG_TYPE_SYSTEM)("%s", strlog);
 	}
 	va_end(arg);
 }

+ 23 - 23
Other/libfilecryption/filecryption.cpp

@@ -48,7 +48,7 @@ static int encrypt_asf_file(char* poutfilename, char* phead, uint32_t uheaderlen
 	char strGuid[HEADER_OBJECT_GUID_LEN] = { 0 };
 	fread(strGuid, 1, HEADER_OBJECT_GUID_LEN, pSrcFile);
 	if (0 != memcmp(strGuid, ASF_Header_GUID, HEADER_OBJECT_GUID_LEN)) {
-		safe_log(pcallback, FILECRYPT_LOG_ERROR, "%s", "math guid failed, current format is not surpport!");
+		safe_log(pcallback, FILECRYPT_LEVEL_ERROR, "%s", "math guid failed, current format is not surpport!");
 		fclose(pDestFile);
 		return iret;
 	}
@@ -100,22 +100,22 @@ static int encrypt_mp4_file(char* poutfilename, char* phead, uint32_t uheaderlen
 
 	unsigned int unoencryptlen = get_noencrypt_boxs_size(pSrcFile, pcallback, true);
 	if (0 == unoencryptlen) {
-		safe_log(pcallback, FILECRYPT_LOG_ERROR, "get not encrypt boxs size failed.");
+		safe_log(pcallback, FILECRYPT_LEVEL_ERROR, "get not encrypt boxs size failed.");
 		return iret;
 	}
-	//safe_log(pcallback, FILECRYPT_LOG_DEBUG, "not encrypt file length is %u.", unoencryptlen);
+	//safe_log(pcallback, FILECRYPT_LEVEL_DEBUG, "not encrypt file length is %u.", unoencryptlen);
 
 	FILE* pDestFile = fopen(poutfilename, "wb");
 	if (NULL == pDestFile) {
 		fclose(pSrcFile);
-		safe_log(pcallback, FILECRYPT_LOG_ERROR, "open output file failed.");
+		safe_log(pcallback, FILECRYPT_LEVEL_ERROR, "open output file failed.");
 		return iret;
 	}
 
 	fseek(pSrcFile, 0, SEEK_END);
 	uint32_t usrcfilelen = (uint32_t)ftell(pSrcFile);
 	rewind(pSrcFile);
-	safe_log(pcallback, FILECRYPT_LOG_DEBUG, "src file length is %u.", usrcfilelen);
+	safe_log(pcallback, FILECRYPT_LEVEL_DEBUG, "src file length is %u.", usrcfilelen);
 
 	//1. 新增自定义文件头
 	fwrite(phead, 1, uheaderlen, pDestFile);
@@ -150,7 +150,7 @@ static int encrypt_mp4_file(char* poutfilename, char* phead, uint32_t uheaderlen
 	unsigned char* pobjdataenc = (unsigned char*)malloc(iencdatalen);
 	
 	if (0 == SM4EncECBMode(pstrkey, pmoovboxdata, umoovboxlen, pobjdataenc, &iencdatalen)) {
-		safe_log(pcallback, FILECRYPT_LOG_DEBUG, "after encode, moov box length is %u.", iencdatalen);
+		safe_log(pcallback, FILECRYPT_LEVEL_DEBUG, "after encode, moov box length is %u.", iencdatalen);
 		if (iencdatalen > 0) {
 			//3. 填充加密后的moov box长度
 			fwrite(&iencdatalen, 1, sizeof(uint32_t), pDestFile);
@@ -161,7 +161,7 @@ static int encrypt_mp4_file(char* poutfilename, char* phead, uint32_t uheaderlen
 	}
 	
 	if(0 != iret){
-		safe_log(pcallback, FILECRYPT_LOG_ERROR, "SM4 encrypt moovbox failed, and src moovbox len is %d.", umoovboxlen);
+		safe_log(pcallback, FILECRYPT_LEVEL_ERROR, "SM4 encrypt moovbox failed, and src moovbox len is %d.", umoovboxlen);
 	}
 	
 	fclose(pDestFile);
@@ -273,7 +273,7 @@ static int decrypt_mp4_file(char* poutfilename, FILE* pSrcFile, unsigned char* p
 	if (0 == unoencryptlen) {
 		return iret;
 	}
-	safe_log(pcallback, FILECRYPT_LOG_DEBUG, "not encrypt file length is %u.", unoencryptlen);
+	safe_log(pcallback, FILECRYPT_LEVEL_DEBUG, "not encrypt file length is %u.", unoencryptlen);
 
 	//1. 填充ftyp, free, mdat box
 	char* data_buffer = (char*)malloc(RVC_READ_BUFFER_SIZE);
@@ -294,7 +294,7 @@ static int decrypt_mp4_file(char* poutfilename, FILE* pSrcFile, unsigned char* p
 	//2. 获取加密后的moov box大小
 	uint32_t uencryptboxsize = 0;
 	fread(&uencryptboxsize, 1, sizeof(uint32_t), pSrcFile);
-	safe_log(pcallback, FILECRYPT_LOG_DEBUG, "encrypt moov box size is = %d.", uencryptboxsize);
+	safe_log(pcallback, FILECRYPT_LEVEL_DEBUG, "encrypt moov box size is = %d.", uencryptboxsize);
 
 	if (uencryptboxsize > 0) {
 		//3. 读取加密后的moov box
@@ -305,7 +305,7 @@ static int decrypt_mp4_file(char* poutfilename, FILE* pSrcFile, unsigned char* p
 
 		//4. 解密moov box
 		SM4DecECBMode(pstrkey, pmoovboxdata, uencryptboxsize, pdecmoovboxdata, &ioutlen);
-		safe_log(pcallback, FILECRYPT_LOG_DEBUG, "decrypt moov box size is = %d.", ioutlen);
+		safe_log(pcallback, FILECRYPT_LEVEL_DEBUG, "decrypt moov box size is = %d.", ioutlen);
 
 		//5. 填充解密后的moov box
 		fwrite(pdecmoovboxdata, 1, ioutlen, pDestFile);
@@ -316,7 +316,7 @@ static int decrypt_mp4_file(char* poutfilename, FILE* pSrcFile, unsigned char* p
 		iret = 0;
 	}
 	else {
-		safe_log(pcallback, FILECRYPT_LOG_ERROR, "get encrypt moovbox failed, decrypt failed!");
+		safe_log(pcallback, FILECRYPT_LEVEL_ERROR, "get encrypt moovbox failed, decrypt failed!");
 	}
 
 	fclose(pDestFile);
@@ -330,20 +330,20 @@ int decryption_file(char* poutfile, uint32_t uoutlen, const char* pfilename, con
 	int iret = -1;
 
 	if (NULL == pfilename || eversion >= sizeof(cryption_ver_flag_table)/sizeof(char*) || eversion < 0){
-		safe_log(pcallback, FILECRYPT_LOG_ERROR, "%s","invalid encryption version param.");
+		safe_log(pcallback, FILECRYPT_LEVEL_ERROR, "%s","invalid encryption version param.");
 		return iret;
 	}
 
 	FILE* pSrcFile = fopen(pfilename, "rb");
 	if (NULL == pSrcFile){
-		safe_log(pcallback, FILECRYPT_LOG_ERROR, "open file %s failed!",pfilename);
+		safe_log(pcallback, FILECRYPT_LEVEL_ERROR, "open file %s failed!",pfilename);
 		return iret;
 	}
 
 	char strrvcflag[RVC_FILE_HEADER_FLAG_LEN] = {0};
 	fread(strrvcflag,1, RVC_FILE_HEADER_FLAG_LEN, pSrcFile);
 	if (0 != memcmp(strrvcflag, rvc_header, RVC_FILE_HEADER_FLAG_LEN)){
-		safe_log(pcallback, FILECRYPT_LOG_INFO, "file %s is not encryption!",pfilename);
+		safe_log(pcallback, FILECRYPT_LEVEL_INFO, "file %s is not encryption!",pfilename);
 		fclose(pSrcFile);
 		return iret;
 	}
@@ -356,7 +356,7 @@ int decryption_file(char* poutfile, uint32_t uoutlen, const char* pfilename, con
 
 	if (0 != memcmp(prvcbuffer+sizeof(uint32_t), cryption_ver_flag_table[eversion], RVC_CRYPTION_VER_FLAG_LEN)){
 		if (0 == memcmp(prvcbuffer+sizeof(uint32_t), cryption_ver_flag_table[eversion], RVC_CRYPTION_VER_FLAG_LEN-1)){
-			safe_log(pcallback, FILECRYPT_LOG_ERROR, "file %s is encrypt but decrypt version is not matched!",pfilename);
+			safe_log(pcallback, FILECRYPT_LEVEL_ERROR, "file %s is encrypt but decrypt version is not matched!",pfilename);
 		} 
 		fclose(pSrcFile);
 		safe_free(prvcbuffer);
@@ -397,7 +397,7 @@ bool is_file_encrypted(const char* pfilename, const filecryption_callback_t* pca
 
 	FILE* pSrcFile = fopen(pfilename, "rb");
 	if (NULL == pSrcFile){
-		safe_log(pcallback, FILECRYPT_LOG_ERROR, "open file %s failed!",pfilename);
+		safe_log(pcallback, FILECRYPT_LEVEL_ERROR, "open file %s failed!",pfilename);
 		return bret;
 	}
 
@@ -407,7 +407,7 @@ bool is_file_encrypted(const char* pfilename, const filecryption_callback_t* pca
 			bret = true;
 		} 
 		else{
-			safe_log(pcallback, FILECRYPT_LOG_INFO, "file %s is not encryption!",pfilename);
+			safe_log(pcallback, FILECRYPT_LEVEL_INFO, "file %s is not encryption!",pfilename);
 		}
 	}
 	fclose(pSrcFile);
@@ -425,13 +425,13 @@ int rvc_file_decrypt(unsigned char** pdechead, uint32_t* udecheadlen, int* ioffs
 {
 	int iret = -1;
 	if (NULL == pfilename || eversion >= sizeof(cryption_ver_flag_table)/sizeof(char*) || eversion < 0){
-		safe_log(pcallback, FILECRYPT_LOG_ERROR, "%s","invalid cryption version param.");
+		safe_log(pcallback, FILECRYPT_LEVEL_ERROR, "%s","invalid cryption version param.");
 		return iret;
 	}
 
 	FILE* pSrcFile = fopen(pfilename, "rb");
 	if (NULL == pSrcFile){
-		safe_log(pcallback, FILECRYPT_LOG_ERROR, "open file %s failed!",pfilename);
+		safe_log(pcallback, FILECRYPT_LEVEL_ERROR, "open file %s failed!",pfilename);
 		return iret;
 	}
 
@@ -441,7 +441,7 @@ int rvc_file_decrypt(unsigned char** pdechead, uint32_t* udecheadlen, int* ioffs
 	char strrvcflag[RVC_FILE_HEADER_FLAG_LEN] = {0};
 	fread(strrvcflag,1, RVC_FILE_HEADER_FLAG_LEN, pSrcFile);
 	if (0 != memcmp(strrvcflag, rvc_header, RVC_FILE_HEADER_FLAG_LEN)){
-		safe_log(pcallback, FILECRYPT_LOG_INFO, "file %s is not encrypted!",pfilename);
+		safe_log(pcallback, FILECRYPT_LEVEL_INFO, "file %s is not encrypted!",pfilename);
 		*pdechead = NULL;
 		*udecheadlen = 0;
 		*ioffset = 0;
@@ -458,7 +458,7 @@ int rvc_file_decrypt(unsigned char** pdechead, uint32_t* udecheadlen, int* ioffs
 
 		if (0 != memcmp(prvcbuffer+sizeof(uint32_t), cryption_ver_flag_table[eversion], RVC_CRYPTION_VER_FLAG_LEN)){
 			if (0 == memcmp(prvcbuffer+sizeof(uint32_t), cryption_ver_flag_table[eversion], RVC_CRYPTION_VER_FLAG_LEN-1)){
-				safe_log(pcallback, FILECRYPT_LOG_ERROR, "file %s encryption and decrption version is not matched!",pfilename);
+				safe_log(pcallback, FILECRYPT_LEVEL_ERROR, "file %s encryption and decrption version is not matched!",pfilename);
 			} 
 			safe_free(prvcbuffer);
 			fclose(pSrcFile);
@@ -473,7 +473,7 @@ int rvc_file_decrypt(unsigned char** pdechead, uint32_t* udecheadlen, int* ioffs
 
 		int ijson = get_file_json_infos_from_rvc_header(pstrjson, ujsonlen, prvcbuffer, irvcheadlen - RVC_FILE_HEADER_FLAG_LEN - sizeof(uint32_t));
 		if (0 == ijson){
-			safe_log(pcallback, FILECRYPT_LOG_DEBUG, "get_file_json_infos_from_rvc_header success!");
+			safe_log(pcallback, FILECRYPT_LEVEL_DEBUG, "get_file_json_infos_from_rvc_header success!");
 		}
 		safe_free(prvcbuffer);
 	}
@@ -481,7 +481,7 @@ int rvc_file_decrypt(unsigned char** pdechead, uint32_t* udecheadlen, int* ioffs
 	char strasfheader[ASF_HEADER_GUID_LEN] = {0};
 	if (ASF_HEADER_GUID_LEN == fread(strasfheader, 1, ASF_HEADER_GUID_LEN, pSrcFile)){
 		if (0 != memcmp(strasfheader, ASF_Header_GUID, ASF_HEADER_GUID_LEN)){
-			safe_log(pcallback, FILECRYPT_LOG_ERROR, "file %s is current not surrport format!",pfilename);
+			safe_log(pcallback, FILECRYPT_LEVEL_ERROR, "file %s is current not surrport format!",pfilename);
 			fclose(pSrcFile);
 			return iret;
 		}

+ 5 - 4
Other/libfilecryption/filecryption.h

@@ -35,10 +35,11 @@ enum eRvcCryptionVersion{
 };
 
 enum filecrypt_loglevel {
-	FILECRYPT_LOG_NO,
-	FILECRYPT_LOG_DEBUG,
-	FILECRYPT_LOG_INFO,
-	FILECRYPT_LOG_ERROR
+	FILECRYPT_LEVEL_DEBUG,
+	FILECRYPT_LEVEL_INFO,
+	FILECRYPT_LEVEL_WARN,
+	FILECRYPT_LEVEL_ERROR,
+	FILECRYPT_LEVEL_FATAL
 };
 
 typedef struct filecryption_callback_s  {

+ 9 - 9
Other/libfilecryption/mp4info.cpp

@@ -29,10 +29,10 @@ uint32_t get_noencrypt_boxs_size(FILE* pSrcFile, const filecryption_callback_t*
 	fread(&box_head, sizeof(box_head_t), 1, pSrcFile);
 	unsigned int uboxsize = big_to_small_endian_32bit(box_head.ibox_size);
 	if (BOX_FTYP != big_to_small_endian_32bit(box_head.box_type)) {
-		safe_log(pcallback, FILECRYPT_LOG_ERROR, "get ftyp box failed.");
+		safe_log(pcallback, FILECRYPT_LEVEL_ERROR, "get ftyp box failed.");
 		return 0;
 	}
-	safe_log(pcallback, FILECRYPT_LOG_DEBUG, "get ftyp box success, box size is %d.", uboxsize);
+	safe_log(pcallback, FILECRYPT_LEVEL_DEBUG, "get ftyp box success, box size is %d.", uboxsize);
 	uret += uboxsize;
 	fseek(pSrcFile, uboxsize - sizeof(box_head_t), SEEK_CUR);
 
@@ -40,10 +40,10 @@ uint32_t get_noencrypt_boxs_size(FILE* pSrcFile, const filecryption_callback_t*
 	fread(&box_head, sizeof(box_head_t), 1, pSrcFile);
 	uboxsize = big_to_small_endian_32bit(box_head.ibox_size);
 	if (FREE_BOX != big_to_small_endian_32bit(box_head.box_type)) {
-		safe_log(pcallback, FILECRYPT_LOG_ERROR, "get free box failed.");
+		safe_log(pcallback, FILECRYPT_LEVEL_ERROR, "get free box failed.");
 		return 0;
 	}
-	safe_log(pcallback, FILECRYPT_LOG_DEBUG, "get free box success, box size is %d.", uboxsize);
+	safe_log(pcallback, FILECRYPT_LEVEL_DEBUG, "get free box success, box size is %d.", uboxsize);
 	uret += uboxsize;
 	fseek(pSrcFile, uboxsize - sizeof(box_head_t), SEEK_CUR);
 
@@ -51,12 +51,12 @@ uint32_t get_noencrypt_boxs_size(FILE* pSrcFile, const filecryption_callback_t*
 	fread(&box_head, sizeof(box_head_t), 1, pSrcFile);
 	uboxsize = big_to_small_endian_32bit(box_head.ibox_size);
 	if (MDAT_BOX != big_to_small_endian_32bit(box_head.box_type)) {
-		safe_log(pcallback, FILECRYPT_LOG_ERROR, "get mdat box failed.");
+		safe_log(pcallback, FILECRYPT_LEVEL_ERROR, "get mdat box failed.");
 		return 0;
 	}
-	safe_log(pcallback, FILECRYPT_LOG_DEBUG, "get mdat box success, box size is %d.", uboxsize);
+	safe_log(pcallback, FILECRYPT_LEVEL_DEBUG, "get mdat box success, box size is %d.", uboxsize);
 	uret += uboxsize;
-	safe_log(pcallback, FILECRYPT_LOG_DEBUG, "ftyp box, free box and mdat box total size is %u.", uret);
+	safe_log(pcallback, FILECRYPT_LEVEL_DEBUG, "ftyp box, free box and mdat box total size is %u.", uret);
 
 	//moov box
 	if (bgetmoov) {
@@ -64,10 +64,10 @@ uint32_t get_noencrypt_boxs_size(FILE* pSrcFile, const filecryption_callback_t*
 		fread(&box_head, sizeof(box_head_t), 1, pSrcFile);
 		uboxsize = big_to_small_endian_32bit(box_head.ibox_size);
 		if (MOOV_BOX != big_to_small_endian_32bit(box_head.box_type)) {
-			safe_log(pcallback, FILECRYPT_LOG_ERROR, "get moov box failed.");
+			safe_log(pcallback, FILECRYPT_LEVEL_ERROR, "get moov box failed.");
 			return 0;
 		}
-		safe_log(pcallback, FILECRYPT_LOG_DEBUG, "get moov box success, box size is %d.", uboxsize);
+		safe_log(pcallback, FILECRYPT_LEVEL_DEBUG, "get moov box success, box size is %d.", uboxsize);
 	}
 
 	fseek(pSrcFile, ipostion, SEEK_SET);

+ 3 - 3
Other/libfilecryption/rvcfileheader.cpp

@@ -25,7 +25,7 @@ int constrcut_rvc_file_header(char* pbuffer, uint32_t* ulen, const char* pfilena
 	//4. 源文件hash值
 	char strhash[RVC_FILE_HASH_LEN] = {0};
 	if (get_srcfile_hash(strhash, RVC_FILE_HASH_LEN, pfilename)){
-		safe_log(pcallback, FILECRYPT_LOG_ERROR, "%s","get file hash failed!");
+		safe_log(pcallback, FILECRYPT_LEVEL_ERROR, "%s","get file hash failed!");
 		return iret;
 	}
 	if (0 == fill_tag_buffer(pbuffer + udatalen, *ulen - udatalen, strhash, RVC_FILE_HASH_LEN)){
@@ -140,12 +140,12 @@ int get_key_from_header_info(unsigned char* pkey, uint32_t ukeysize, char* phead
 
 	rvc_fileheader_t t_param = {0};
 	if (0 != get_rvc_file_header_info(&t_param, pheader, udatalen, pcallback)){
-		safe_log(pcallback, FILECRYPT_LOG_ERROR, "%s", "get rvc file header infos failed!");
+		safe_log(pcallback, FILECRYPT_LEVEL_ERROR, "%s", "get rvc file header infos failed!");
 		return iret;
 	}
 
 	if (0 == GenerateSM4Key(pkey, ukeysize, t_param.strhash, RVC_FILE_HASH_LEN, t_param.usrcfilelen)){
-		safe_log(pcallback, FILECRYPT_LOG_DEBUG, "%s", "Generate SM4Key success!");
+		safe_log(pcallback, FILECRYPT_LEVEL_DEBUG, "%s", "Generate SM4Key success!");
 		iret = 0;
 	}