@@ -21,15 +21,107 @@ BOOL XEngine_Task_Manage(LPCTSTR lpszAPIName, LPCTSTR lpszClientAddr, LPCTSTR lp
2121 {
2222 if (0 == ppSt_DBFile[i]->st_ProtocolFile .nFileSize )
2323 {
24- TCHAR tszFileDir[MAX_PATH];
25- _stprintf (tszFileDir, _T (" %s %s" ), ppSt_DBFile[i]->st_ProtocolFile .tszFilePath , ppSt_DBFile[i]->st_ProtocolFile .tszFileName );
26- XStorageSQL_File_FileInsert (ppSt_DBFile[i]);
24+ int nHashLen = 0 ;
25+ UCHAR tszHashStr[MAX_PATH];
26+ TCHAR tszFileDir[1024 ];
27+ struct __stat64 st_FStat;
28+
29+ memset (tszHashStr, ' \0 ' , MAX_PATH);
30+ memset (tszFileDir, ' \0 ' , sizeof (tszFileDir));
31+
32+ _stprintf (tszFileDir, _T (" %s/%s" ), ppSt_DBFile[i]->st_ProtocolFile .tszFilePath , ppSt_DBFile[i]->st_ProtocolFile .tszFileName );
33+
34+ int nRet = _stat64 (tszFileDir, &st_FStat);
35+ if (0 != nRet)
36+ {
37+ st_HDRParam.bIsClose = TRUE ;
38+ st_HDRParam.nHttpCode = 404 ;
39+ RfcComponents_HttpServer_SendMsgEx (xhUPHttp, tszSDBuffer, &nSDLen, &st_HDRParam);
40+ XEngine_Net_SendMsg (lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER);
41+ XLOG_PRINT (xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T (" 业务客户端:%s,请求添加文件到数据库失败,文件不存在,文件;%s" ), lpszClientAddr, tszFileDir);
42+ return FALSE ;
43+ }
44+ // 获取大小
45+ ppSt_DBFile[i]->st_ProtocolFile .nFileSize = st_FStat.st_size ;
46+ // 计算HASH
47+ OPenSsl_Api_Digest (tszFileDir, tszHashStr, &nHashLen, TRUE , st_ServiceCfg.st_XStorage .nHashMode );
48+ BaseLib_OperatorString_StrToHex ((char *)tszHashStr, nHashLen, ppSt_DBFile[i]->st_ProtocolFile .tszFileHash );
49+ }
50+ if (0 != st_ServiceCfg.st_XSql .nSQLType )
51+ {
52+ if (1 == st_ServiceCfg.st_XSql .nSQLType )
53+ {
54+ XStorageSQL_File_FileInsert (ppSt_DBFile[i]);
55+ }
56+ else
57+ {
58+ XStorage_SQLite_FileInsert (ppSt_DBFile[i]);
59+ }
60+ }
61+ XLOG_PRINT (xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T (" 业务客户端:%s,请求添加文件到数据库成功,文件名:%s/%s" ), lpszClientAddr, ppSt_DBFile[i]->st_ProtocolFile .tszFilePath , ppSt_DBFile[i]->st_ProtocolFile .tszFileName );
62+ }
63+ st_HDRParam.bIsClose = TRUE ;
64+ st_HDRParam.nHttpCode = 200 ;
65+ RfcComponents_HttpServer_SendMsgEx (xhUPHttp, tszSDBuffer, &nSDLen, &st_HDRParam);
66+ XEngine_Net_SendMsg (lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER);
67+ BaseLib_OperatorMemory_Free ((XPPPMEM)&ppSt_DBFile, nListCount);
68+ }
69+ else if (0 == _tcsnicmp (XENGINE_STORAGE_APP_METHOD_DEL, lpszAPIName, _tcslen (XENGINE_STORAGE_APP_METHOD_DEL)))
70+ {
71+ int nListCount = 0 ;
72+ XSTORAGECORE_DBFILE** ppSt_DBFile;
73+
74+ XStorageProtocol_Core_ReportFileParse (lpszMsgBuffer, nMsgLen, &ppSt_DBFile, &nListCount);
75+ for (int i = 0 ; i < nListCount; i++)
76+ {
77+ if (_tcslen (ppSt_DBFile[i]->st_ProtocolFile .tszFileHash ) > 0 )
78+ {
79+ if (0 != st_ServiceCfg.st_XSql .nSQLType )
80+ {
81+ int nQueryCount = 0 ;
82+ XSTORAGECORE_DBFILE** ppSt_DBQuery;
83+ if (1 == st_ServiceCfg.st_XSql .nSQLType )
84+ {
85+ XStorageSQL_File_FileQuery (&ppSt_DBQuery, &nQueryCount, NULL , NULL , NULL , ppSt_DBFile[i]->st_ProtocolFile .tszFileHash );
86+ // 删除数据库与文件
87+ for (int i = 0 ; i < nQueryCount; i++)
88+ {
89+ TCHAR tszFilePath[1024 ];
90+ memset (tszFilePath, ' \0 ' , sizeof (tszFilePath));
91+
92+ _stprintf (tszFilePath, _T (" %s/%s" ), ppSt_DBFile[i]->st_ProtocolFile .tszFilePath , ppSt_DBFile[i]->st_ProtocolFile .tszFileName );
93+ XStorageSQL_File_FileDelete (NULL , ppSt_DBFile[i]->st_ProtocolFile .tszFileHash );
94+ }
95+ }
96+ else
97+ {
98+ XStorage_SQLite_FileQuery (&ppSt_DBQuery, &nQueryCount, NULL , NULL , NULL , ppSt_DBFile[i]->st_ProtocolFile .tszFileHash );
99+ // 删除数据库与文件
100+ for (int i = 0 ; i < nQueryCount; i++)
101+ {
102+ TCHAR tszFilePath[1024 ];
103+ memset (tszFilePath, ' \0 ' , sizeof (tszFilePath));
104+
105+ _stprintf (tszFilePath, _T (" %s/%s" ), ppSt_DBFile[i]->st_ProtocolFile .tszFilePath , ppSt_DBFile[i]->st_ProtocolFile .tszFileName );
106+ XStorage_SQLite_FileDelete (NULL , ppSt_DBFile[i]->st_ProtocolFile .tszFileHash );
107+ }
108+ }
109+ }
110+ else
111+ {
112+
113+ }
114+ }
115+ else
116+ {
27117 }
118+ XLOG_PRINT (xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T (" 业务客户端:%s,请求删除文件成功,文件名:%s/%s" ), lpszClientAddr, ppSt_DBFile[i]->st_ProtocolFile .tszFilePath , ppSt_DBFile[i]->st_ProtocolFile .tszFileName );
28119 }
120+ st_HDRParam.bIsClose = TRUE ;
29121 st_HDRParam.nHttpCode = 200 ;
30122 RfcComponents_HttpServer_SendMsgEx (xhUPHttp, tszSDBuffer, &nSDLen, &st_HDRParam);
31123 XEngine_Net_SendMsg (lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER);
32- XLOG_PRINT (xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T ( " 业务客户端:%s " ), lpszClientAddr );
124+ BaseLib_OperatorMemory_Free ((XPPPMEM)&ppSt_DBFile, nListCount );
33125 }
34126 return TRUE ;
35127}
0 commit comments