diff --git a/README.en.md b/README.en.md index ef69ad3cd3124e96fa541cc2993d3f3950a2a5ab..5bb0aa9254e22d8cbfe4a8179ccd0347ca68aa15 100644 --- a/README.en.md +++ b/README.en.md @@ -7,8 +7,8 @@ c c++ 存储服务 c c++ 文件存储服务 c c++ file storage service This is an api gateway for uploading and downloading. The service is for users who have business needs for upload and download services (such as developers who need to upload and download servers). -This server is more inclined to store the API interface direction -best storage service for http,batter than nginx and more convenient to manage. On going maintenance +This server is more inclined to storestorage transfer and API Manage interface +best storage service for http,batter than nginx and more convenient to manage,more concise code. On going maintenance ## Software feature The purpose of development and implementation based on libXEngine is a cross-platform network storage service @@ -97,7 +97,6 @@ P2P distributed download is the same as the hyper-threaded download of other dow ## now task P2P WAN file search and download support -upload file code optimization ## other problems You can refer to the document under the docment directory. It contains API protocol and service description. diff --git a/README.md b/README.md index 30d6a345ee4f0693f7b3317d80bc94d429a39ef7..b218776d6ce2c358d09e6833f7c7ab7e39764316 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,8 @@ c c++ 存储服务 c c++ 文件存储服务 c c++ file storage service 这是一个上传下载服务API网关,不是文件同步服务,也不是云存储. 这个服务的主要目的是为了给有上传下载服务业务需求的用户使用(比如需要开发上传下载服务的开发人员). -此服务器更偏向于存储API接口方向. -目前最好的HTTP存储服务,比NGINX更优秀,更方便管理.持续维护中... +此服务器更偏向于存储传输与API接口管理. +目前最好的HTTP存储服务,比NGINX更优秀,更方便管理,代码更简洁.持续维护中... ## 软件特性 基于libXEngine开发并实现的一套简洁高性能跨平台网络存储服务 @@ -95,7 +95,6 @@ P2P分布式下载与其他下载工具的超线程下载一样,原理是使用H ## 当前任务 P2P广域网文件查找与下载支持 -文件上传代码优化 ## 其他问题 你可以参考docment目录下的文档.里面包含了API协议和服务说明. diff --git a/XEngine_APPClient/APPClient_Download/APPClient_Download.cpp b/XEngine_APPClient/APPClient_Download/APPClient_Download.cpp index 3b3d88539e6d0ec8745ea1c75dc7abf62ca553c4..bd21d794faf2d3669c37b0be306d4c9fcedfd29c 100644 --- a/XEngine_APPClient/APPClient_Download/APPClient_Download.cpp +++ b/XEngine_APPClient/APPClient_Download/APPClient_Download.cpp @@ -155,10 +155,14 @@ int main() int nBodyLen = 2048; TCHAR *ptszMsgBody = NULL; //请求分布式存储文件所有位置 - LPCTSTR lpszUrl = _T("http://127.0.0.1:5100/7D54D6E40367F2763B8C8056EADC517F"); + LPCTSTR lpszUrl = _T("http://127.0.0.1:5100/Api/Manage/P2P"); LPCTSTR lpszFile = _T("D:\\XEngine_Storage\\XEngine_APPClient\\Debug\\qq.exe"); - if (!APIHelp_HttpRequest_Get(lpszUrl, &ptszMsgBody, &nBodyLen, &nHTTPCode)) + Json::Value st_JsonRoot; + st_JsonRoot["lpszBuckKey"] = "storagekey2"; + st_JsonRoot["lpszFileHash"] = "781E5E245D69B566979B86E28D23F2C7"; + + if (!APIHelp_HttpRequest_Post(lpszUrl, st_JsonRoot.toStyledString().c_str(), &nHTTPCode, &ptszMsgBody, &nBodyLen)) { return -1; } diff --git a/XEngine_APPClient/APPClient_P2XPClient/APPClient_P2XPClient.cpp b/XEngine_APPClient/APPClient_P2XPClient/APPClient_P2XPClient.cpp index a61f04caa7b499876d8fb323d8efe9abab45c83f..f4dbb2739d7b4fa769d6bafc29026b4a9f7b6abe 100644 --- a/XEngine_APPClient/APPClient_P2XPClient/APPClient_P2XPClient.cpp +++ b/XEngine_APPClient/APPClient_P2XPClient/APPClient_P2XPClient.cpp @@ -33,10 +33,10 @@ SOCKET m_hSocket; int APPClient_P2XPLogin() { - DWORD dwNetType = 0; Json::Value st_JsonRoot; TCHAR tszMsgBuffer[2048]; XENGINE_PROTOCOLHDR st_ProtocolHdr; + ENUM_XENGINE_NETXAPI_SOCKET_CONNECTTYPE dwNetType; memset(tszPublicAddr, '\0', sizeof(tszPublicAddr)); memset(tszPrivateAddr, '\0', sizeof(tszPrivateAddr)); @@ -45,7 +45,7 @@ int APPClient_P2XPLogin() st_ProtocolHdr.wHeader = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_HEADER; st_ProtocolHdr.unOperatorType = ENUM_XENGINE_COMMUNICATION_PROTOCOL_TYPE_P2XP; - st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_AUTH_REQLOGIN; + st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_P2XP_REQLOGIN; st_ProtocolHdr.byVersion = 2; st_ProtocolHdr.wTail = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_TAIL; diff --git a/XEngine_APPClient/APPClient_RestApi/APPClient_RestApi.cpp b/XEngine_APPClient/APPClient_RestApi/APPClient_RestApi.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7f57ff9cb726486a422190e5d350e04925b45898 --- /dev/null +++ b/XEngine_APPClient/APPClient_RestApi/APPClient_RestApi.cpp @@ -0,0 +1,179 @@ +#ifdef _WINDOWS +#include +#include +#include +#pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib") +#pragma comment(lib,"XEngine_NetHelp/NetHelp_APIHelp") +#pragma comment(lib,"Ws2_32") +#else +#ifdef _CENTOS +#include +#else +#include +#endif +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +//g++ -std=c++17 -Wall -g APPClient_RestApi.cpp -o APPClient_RestApi.exe -L ../../../XEngine/XEngine_Release/XEngine_Linux/Ubuntu/XEngine_BaseLib -L ../../../XEngine/XEngine_Release/XEngine_Linux/Ubuntu/XEngine_NetHelp -lXEngine_BaseLib -lNetHelp_APIHelp -ljsoncpp -Wl,-rpath=../../../XEngine/XEngine_Release/XEngine_Linux/Ubuntu/XEngine_BaseLib:../../../XEngine/XEngine_Release/XEngine_Linux/Ubuntu/XEngine_NetHelp,--disable-new-dtags + +//查询 +void API_Manage_Query() +{ + LPCTSTR lpszUrl = _T("http://192.168.1.8:5100/Api/Manage/QueryFile"); + int nLen = 0; + int nCode = 0; + TCHAR* ptszMsgBuffer = NULL; + Json::Value st_JsonRoot; + st_JsonRoot["lpszTimeStart"]; + st_JsonRoot["lpszTimeEnd"]; + st_JsonRoot["lpszBuckKey"] = "storagekey2"; + + if (!APIHelp_HttpRequest_Post(lpszUrl, st_JsonRoot.toStyledString().c_str(), &nCode, &ptszMsgBuffer, &nLen)) + { + printf("API_Manage_Query:%lX\n", APIHelp_GetLastError()); + return; + } + printf("API_Manage_Query:%d,%s\n", nCode, ptszMsgBuffer); + BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); +} +//插入 +void API_Manage_Insert() +{ + LPCTSTR lpszUrl = _T("http://192.168.1.8:5100/Api/Manage/Insert"); + int nLen = 0; + int nCode = 0; + TCHAR* ptszMsgBuffer = NULL; + Json::Value st_JsonRoot; + Json::Value st_JsonArray; + Json::Value st_JsonObject; + + st_JsonObject["nFileSize"] = 10; + st_JsonObject["tszFileHash"] = "85E62C9D28FCE775A68DD126E0519F25"; + st_JsonObject["tszFileName"] = "2.txt"; + st_JsonObject["tszBuckKey"] = "storagekey2"; + st_JsonArray.append(st_JsonObject); + + st_JsonRoot["List"] = st_JsonArray; + st_JsonRoot["Count"] = 1; + + if (!APIHelp_HttpRequest_Post(lpszUrl, st_JsonRoot.toStyledString().c_str(), &nCode, &ptszMsgBuffer, &nLen)) + { + printf("API_Manage_Insert:%lX\n", APIHelp_GetLastError()); + return; + } + printf("API_Manage_Insert:%d,%s\n", nCode, ptszMsgBuffer); + BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); +} +//删除 +void API_Manage_Delete() +{ + LPCTSTR lpszUrl = _T("http://192.168.1.8:5100/Api/Manage/Delete"); + int nLen = 0; + int nCode = 0; + TCHAR* ptszMsgBuffer = NULL; + Json::Value st_JsonRoot; + Json::Value st_JsonArray; + Json::Value st_JsonObject; + + st_JsonObject["tszFileHash"] = "85E62C9D28FCE775A68DD126E0519F25"; + st_JsonArray.append(st_JsonObject); + + st_JsonRoot["List"] = st_JsonArray; + st_JsonRoot["Count"] = 1; + + if (!APIHelp_HttpRequest_Post(lpszUrl, st_JsonRoot.toStyledString().c_str(), &nCode, &ptszMsgBuffer, &nLen)) + { + printf("API_Manage_Delete:%lX\n", APIHelp_GetLastError()); + return; + } + printf("API_Manage_Delete:%d,%s\n", nCode, ptszMsgBuffer); + BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); +} +//文件夹 +void API_Manage_Dir() +{ + LPCTSTR lpszUrl = _T("http://192.168.1.8:5100/Api/Manage/Dir"); + int nLen = 0; + int nCode = 0; + TCHAR* ptszMsgBuffer = NULL; + Json::Value st_JsonRoot; + //创建 + st_JsonRoot["lpszBuckKey"] = "storagekey1"; + st_JsonRoot["lpszUserDir"] = "user"; + st_JsonRoot["nOPerator"] = 1; + if (!APIHelp_HttpRequest_Post(lpszUrl, st_JsonRoot.toStyledString().c_str(), &nCode, &ptszMsgBuffer, &nLen)) + { + printf("API_Manage_Dir:%lX\n", APIHelp_GetLastError()); + return; + } + printf("API_Manage_Dir:%d,%s\n", nCode, ptszMsgBuffer); + BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); + //查询 + st_JsonRoot.clear(); + st_JsonRoot["lpszBuckKey"] = "storagekey1"; + st_JsonRoot["lpszUserDir"]; + st_JsonRoot["nOPerator"] = 0; + if (!APIHelp_HttpRequest_Post(lpszUrl, st_JsonRoot.toStyledString().c_str(), &nCode, &ptszMsgBuffer, &nLen)) + { + printf("API_Manage_Dir:%lX\n", APIHelp_GetLastError()); + return; + } + printf("API_Manage_Dir:%d,%s\n", nCode, ptszMsgBuffer); + BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); + //删除 + st_JsonRoot.clear(); + st_JsonRoot["lpszBuckKey"] = "storagekey1"; + st_JsonRoot["lpszUserDir"] = "user"; + st_JsonRoot["nOPerator"] = 2; + if (!APIHelp_HttpRequest_Post(lpszUrl, st_JsonRoot.toStyledString().c_str(), &nCode, &ptszMsgBuffer, &nLen)) + { + printf("API_Manage_Dir:%lX\n", APIHelp_GetLastError()); + return; + } + printf("API_Manage_Dir:%d,%s\n", nCode, ptszMsgBuffer); + BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); +} +//任务管理 +void API_Manage_Task() +{ + LPCTSTR lpszUrl = _T("http://192.168.1.8:5100/Api/Manage/Task"); + int nLen = 0; + int nCode = 0; + TCHAR* ptszMsgBuffer = NULL; + if (!APIHelp_HttpRequest_Post(lpszUrl, NULL, &nCode, &ptszMsgBuffer, &nLen)) + { + printf("API_Manage_Task:%lX\n", APIHelp_GetLastError()); + return; + } + printf("API_Manage_Task:%d,%s\n", nCode, ptszMsgBuffer); + BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); +} + +int main() +{ +#ifdef _WINDOWS + WSADATA st_WSAData; + WSAStartup(MAKEWORD(2, 2), &st_WSAData); +#endif + + API_Manage_Query(); + API_Manage_Insert(); + API_Manage_Delete(); + API_Manage_Dir(); + API_Manage_Task(); +#ifdef _WINDOWS + WSACleanup(); +#endif + return 0; +} \ No newline at end of file diff --git a/XEngine_APPClient/APPClient_RestApi/APPClient_RestApi.vcxproj b/XEngine_APPClient/APPClient_RestApi/APPClient_RestApi.vcxproj new file mode 100644 index 0000000000000000000000000000000000000000..34be015f08a626358c3df0b1957eae59e43c278d --- /dev/null +++ b/XEngine_APPClient/APPClient_RestApi/APPClient_RestApi.vcxproj @@ -0,0 +1,149 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {1724fb68-563f-49e5-b36a-c1df7bf67930} + APPClientRestApi + 10.0 + + + + Application + true + v142 + MultiByte + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + $(XEngine_Include);$(IncludePath) + $(XEngine_Lib32);$(LibraryPath) + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;_WINDOWS;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/XEngine_APPClient/APPClient_RestApi/APPClient_RestApi.vcxproj.filters b/XEngine_APPClient/APPClient_RestApi/APPClient_RestApi.vcxproj.filters new file mode 100644 index 0000000000000000000000000000000000000000..53c01f0cfb6978291fade8fc741d3c61a8f2e929 --- /dev/null +++ b/XEngine_APPClient/APPClient_RestApi/APPClient_RestApi.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 源文件 + + + \ No newline at end of file diff --git a/XEngine_APPClient/APPClient_RestApi/APPClient_RestApi.vcxproj.user b/XEngine_APPClient/APPClient_RestApi/APPClient_RestApi.vcxproj.user new file mode 100644 index 0000000000000000000000000000000000000000..88a550947edbc3c5003a41726f0749201fdb6822 --- /dev/null +++ b/XEngine_APPClient/APPClient_RestApi/APPClient_RestApi.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/XEngine_APPClient/APPClient_UPDownload/APPClient_UPDownload.cpp b/XEngine_APPClient/APPClient_UPDownload/APPClient_UPDownload.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a8b8cc96224fd1cfa8e5f96c4db9ec29072cbad9 --- /dev/null +++ b/XEngine_APPClient/APPClient_UPDownload/APPClient_UPDownload.cpp @@ -0,0 +1,111 @@ +#ifdef _WINDOWS +#include +#include +#pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib") +#pragma comment(lib,"XEngine_Core/XEngine_OPenSsl") +#pragma comment(lib,"XEngine_NetHelp/NetHelp_APIHelp") +#pragma comment(lib,"Ws2_32") +#else +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +//g++ -std=c++17 -Wall -g APPClient_UPDownload.cpp -o APPClient_UPDownload.exe -L ../../../XEngine/XEngine_Release/XEngine_Linux/Ubuntu/XEngine_BaseLib -L ../../../XEngine/XEngine_Release/XEngine_Linux/Ubuntu/XEngine_Core -L ../../../XEngine/XEngine_Release/XEngine_Linux/Ubuntu/XEngine_NetHelp -lXEngine_BaseLib -lXEngine_OPenSsl -lNetHelp_APIHelp -Wl,-rpath=../../../XEngine/XEngine_Release/XEngine_Linux/Ubuntu/XEngine_BaseLib:../../../XEngine/XEngine_Release/XEngine_Linux/Ubuntu/XEngine_Core:../../../XEngine/XEngine_Release/XEngine_Linux/Ubuntu/XEngine_NetHelp,--disable-new-dtags + +//上传文件 +void File_UPLoad() +{ + LPCTSTR lpszUrl = _T("http://192.168.1.8:5102/2.txt"); + int nLen = 0; + int nCode = 0; + TCHAR* ptszMsgBuffer = NULL; + TCHAR tszBaseBuffer[128]; + TCHAR tszHdrBuffer[MAX_PATH]; + LPCTSTR lpszMsgBuffer = _T("01234"); + LPCTSTR lpszMsgBuffer2 = _T("56789"); + + memset(tszBaseBuffer, '\0', sizeof(tszBaseBuffer)); + memset(tszHdrBuffer, '\0', MAX_PATH); + OPenSsl_Help_BasicEncoder("123123aa", "123123", tszBaseBuffer); + + _stprintf(tszHdrBuffer, _T("Range: bytes=0-5/10\r\nAuthorization: %s\r\n"), tszBaseBuffer); + if (!APIHelp_HttpRequest_Post(lpszUrl, lpszMsgBuffer, &nCode, &ptszMsgBuffer, &nLen, tszHdrBuffer)) + { + printf("upload failed:%lX\n", APIHelp_GetLastError()); + return; + } + printf("upload:%d\n", nCode); + BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); + + memset(tszHdrBuffer, '\0', MAX_PATH); + _stprintf(tszHdrBuffer, _T("Range: bytes=5-9/10\r\nAuthorization: %s\r\n"), tszBaseBuffer); + if (!APIHelp_HttpRequest_Post(lpszUrl, lpszMsgBuffer2, &nCode, &ptszMsgBuffer, &nLen, tszHdrBuffer)) + { + printf("upload failed:%lX\n", APIHelp_GetLastError()); + return; + } + printf("upload:%d\n%s\n", nCode, ptszMsgBuffer); + BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); +} +//下载文件 +void File_Download() +{ + LPCTSTR lpszUrl = _T("http://192.168.1.8:5101/storagekey2/2.txt"); + + int nLen = 0; + int nCode = 0; + TCHAR* ptszMsgBuffer = NULL; + TCHAR tszBaseBuffer[128]; + TCHAR tszHdrBuffer[MAX_PATH]; + + memset(tszBaseBuffer, '\0', sizeof(tszBaseBuffer)); + memset(tszHdrBuffer, '\0', MAX_PATH); + OPenSsl_Help_BasicEncoder("123123aa", "123123", tszBaseBuffer); + + _stprintf(tszHdrBuffer, _T("Range: bytes=0-5\r\nAuthorization: %s\r\n"), tszBaseBuffer); + if (!APIHelp_HttpRequest_Get(lpszUrl, &ptszMsgBuffer, &nLen, &nCode, tszHdrBuffer)) + { + printf("download failed:%lX\n", APIHelp_GetLastError()); + return; + } + printf("download:%d,%s\n", nLen, ptszMsgBuffer); + BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); + + memset(tszHdrBuffer, '\0', MAX_PATH); + _stprintf(tszHdrBuffer, _T("Range: bytes=5-10\r\nAuthorization: %s\r\n"), tszBaseBuffer); + if (!APIHelp_HttpRequest_Get(lpszUrl, &ptszMsgBuffer, &nLen, &nCode, tszHdrBuffer)) + { + printf("download failed:%lX\n", APIHelp_GetLastError()); + return; + } + printf("download:%d,%s\n", nLen, ptszMsgBuffer); + BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); +} + +int main() +{ +#ifdef _WINDOWS + WSADATA st_WSAData; + WSAStartup(MAKEWORD(2, 2), &st_WSAData); +#endif + + File_UPLoad(); + File_Download(); + +#ifdef _WINDOWS + WSACleanup(); +#endif + return 0; +} \ No newline at end of file diff --git a/XEngine_APPClient/APPClient_UPDownload/APPClient_UPDownload.vcxproj b/XEngine_APPClient/APPClient_UPDownload/APPClient_UPDownload.vcxproj new file mode 100644 index 0000000000000000000000000000000000000000..062cd1cb4393a5054d908faa2d3c157c1b74552f --- /dev/null +++ b/XEngine_APPClient/APPClient_UPDownload/APPClient_UPDownload.vcxproj @@ -0,0 +1,149 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {01470ebd-47ec-4ac1-ba0d-c75926dd1e60} + APPClientUPDownload + 10.0 + + + + Application + true + v142 + MultiByte + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + $(XEngine_Include);$(IncludePath) + $(XEngine_Lib32);$(LibraryPath) + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/XEngine_APPClient/APPClient_UPDownload/APPClient_UPDownload.vcxproj.filters b/XEngine_APPClient/APPClient_UPDownload/APPClient_UPDownload.vcxproj.filters new file mode 100644 index 0000000000000000000000000000000000000000..ba4bde416665ca62f7565be8636d3f0a25de2780 --- /dev/null +++ b/XEngine_APPClient/APPClient_UPDownload/APPClient_UPDownload.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 源文件 + + + \ No newline at end of file diff --git a/XEngine_APPClient/APPClient_UPDownload/APPClient_UPDownload.vcxproj.user b/XEngine_APPClient/APPClient_UPDownload/APPClient_UPDownload.vcxproj.user new file mode 100644 index 0000000000000000000000000000000000000000..88a550947edbc3c5003a41726f0749201fdb6822 --- /dev/null +++ b/XEngine_APPClient/APPClient_UPDownload/APPClient_UPDownload.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/XEngine_APPClient/XEngine_APPClient.sln b/XEngine_APPClient/XEngine_APPClient.sln index adedea9de4ee8c8604b54e99e247d0cdb826c727..b046e21890c5c69c8f6ad39881e592c542463a3b 100644 --- a/XEngine_APPClient/XEngine_APPClient.sln +++ b/XEngine_APPClient/XEngine_APPClient.sln @@ -7,6 +7,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "APPClient_P2XPClient", "APP EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "APPClient_Download", "APPClient_Download\APPClient_Download.vcxproj", "{16608D17-1839-48D8-A455-21AAF0257E36}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "APPClient_UPDownload", "APPClient_UPDownload\APPClient_UPDownload.vcxproj", "{01470EBD-47EC-4AC1-BA0D-C75926DD1E60}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "APPClient_RestApi", "APPClient_RestApi\APPClient_RestApi.vcxproj", "{1724FB68-563F-49E5-B36A-C1DF7BF67930}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -31,6 +35,22 @@ Global {16608D17-1839-48D8-A455-21AAF0257E36}.Release|x64.Build.0 = Release|x64 {16608D17-1839-48D8-A455-21AAF0257E36}.Release|x86.ActiveCfg = Release|Win32 {16608D17-1839-48D8-A455-21AAF0257E36}.Release|x86.Build.0 = Release|Win32 + {01470EBD-47EC-4AC1-BA0D-C75926DD1E60}.Debug|x64.ActiveCfg = Debug|x64 + {01470EBD-47EC-4AC1-BA0D-C75926DD1E60}.Debug|x64.Build.0 = Debug|x64 + {01470EBD-47EC-4AC1-BA0D-C75926DD1E60}.Debug|x86.ActiveCfg = Debug|Win32 + {01470EBD-47EC-4AC1-BA0D-C75926DD1E60}.Debug|x86.Build.0 = Debug|Win32 + {01470EBD-47EC-4AC1-BA0D-C75926DD1E60}.Release|x64.ActiveCfg = Release|x64 + {01470EBD-47EC-4AC1-BA0D-C75926DD1E60}.Release|x64.Build.0 = Release|x64 + {01470EBD-47EC-4AC1-BA0D-C75926DD1E60}.Release|x86.ActiveCfg = Release|Win32 + {01470EBD-47EC-4AC1-BA0D-C75926DD1E60}.Release|x86.Build.0 = Release|Win32 + {1724FB68-563F-49E5-B36A-C1DF7BF67930}.Debug|x64.ActiveCfg = Debug|x64 + {1724FB68-563F-49E5-B36A-C1DF7BF67930}.Debug|x64.Build.0 = Debug|x64 + {1724FB68-563F-49E5-B36A-C1DF7BF67930}.Debug|x86.ActiveCfg = Debug|Win32 + {1724FB68-563F-49E5-B36A-C1DF7BF67930}.Debug|x86.Build.0 = Debug|Win32 + {1724FB68-563F-49E5-B36A-C1DF7BF67930}.Release|x64.ActiveCfg = Release|x64 + {1724FB68-563F-49E5-B36A-C1DF7BF67930}.Release|x64.Build.0 = Release|x64 + {1724FB68-563F-49E5-B36A-C1DF7BF67930}.Release|x86.ActiveCfg = Release|Win32 + {1724FB68-563F-49E5-B36A-C1DF7BF67930}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/XEngine_Docment/Docment_en.docx b/XEngine_Docment/Docment_en.docx index 81e8d770eff7ba93b323fdc194d0008773a5566a..ddd228e6d17b9554c8af1db6737101bda568e451 100644 Binary files a/XEngine_Docment/Docment_en.docx and b/XEngine_Docment/Docment_en.docx differ diff --git a/XEngine_Docment/Docment_zh.docx b/XEngine_Docment/Docment_zh.docx index cbec68ba387137f8c9f0f5e1a4d245df2bae0b7a..329d4946eb63f4b2ca68c84e578e986f19aa7215 100644 Binary files a/XEngine_Docment/Docment_zh.docx and b/XEngine_Docment/Docment_zh.docx differ diff --git a/XEngine_Release/XEngine_Config/XEngine_Config.json b/XEngine_Release/XEngine_Config/XEngine_Config.json index 2a7363eb92cdd080aa6de478dc507c1df380f4e3..58f2a323b302c08fad5cfa26aef84d84f1c0b86e 100644 --- a/XEngine_Release/XEngine_Config/XEngine_Config.json +++ b/XEngine_Release/XEngine_Config/XEngine_Config.json @@ -75,6 +75,7 @@ }, "XVer":{ "StorageVersion":[ + "3.4.0.1001 Build20220121", "3.3.0.1001 Build20220106", "3.2.0.1001 Build20211211", "3.1.0.1001 Build20211109", diff --git a/XEngine_Release/XEngine_Config/XEngine_LBConfig.json b/XEngine_Release/XEngine_Config/XEngine_LBConfig.json index 3bd91f77649911479e91dd80d67746d2b0c06327..31cddc370d96386032b6d4fd7a8edf322fc882ac 100644 --- a/XEngine_Release/XEngine_Config/XEngine_LBConfig.json +++ b/XEngine_Release/XEngine_Config/XEngine_LBConfig.json @@ -1,36 +1,45 @@ { - "bDistributed":1, - "LBConfig":{ - "nServerMode":1 - }, - "LoadBalance":{ - "nUseMode":[ - 0 - ], - "CenterAddr":[ - "http://192.168.1.9:5100" - ], - "DownloadAddr":[ - "http://192.168.1.9:5010" - ], - "UPLoaderAddr":[ - "http://192.168.1.9:5102" - ], - "StorageAddr":[ - { - "bEnable":1, - "nLevel":1, - "Size":"1024MB", - "XEngine_Key":"storagekey1", - "XEngine_Path":"./XEngine_File" - }, - { - "bEnable":1, - "nLevel":1, - "Size":"1024MB", - "XEngine_Key":"storagekey2", - "XEngine_Path":"./XEngine_File2" - } - ] - } -} \ No newline at end of file + "bDistributed":1, + "LBDistributed":{ + "nCenterMode":0, + "nUPLoadMode":0, + "nDownldMode":0, + "nStorageMode":0 + }, + "LBLocation":{ + "nCenterMode":0, + "nUPLoadMode":1, + "nDownldMode":0, + "nStorageMode":0 + }, + "LoadBalance":{ + "CenterAddr":[ + "http://192.168.1.9:5100" + ], + "DownloadAddr":[ + "http://192.168.1.9:5010" + ], + "UPLoaderAddr":[ + "http://192.168.1.9:5102" + ], + "StorageAddr":[ + { + "bEnable":1, + "nLevel":1, + "Size":"1024MB", + "XEngine_Key":"storagekey1", + "XEngine_Path":"./XEngine_File" + } +, + { + "bEnable":1, + "nLevel":1, + "Size":"1024MB", + "XEngine_Key":"storagekey2", + "XEngine_Path":"./XEngine_File2" + } + + ] + } + +} diff --git a/XEngine_Release/XEngine_File2/.gitignore b/XEngine_Release/XEngine_File2/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/XEngine_Source/StorageModule_APIHelp/APIHelp_Api/APIHelp_Api.cpp b/XEngine_Source/StorageModule_APIHelp/APIHelp_Api/APIHelp_Api.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5d73f9201d170c9fcc9e9e21b1fc1fb27ca80ea4 --- /dev/null +++ b/XEngine_Source/StorageModule_APIHelp/APIHelp_Api/APIHelp_Api.cpp @@ -0,0 +1,227 @@ +#include "pch.h" +#include "APIHelp_Api.h" +/******************************************************************** +// Created: 2022/01/07 14:36:59 +// File Name: D:\XEngine_Storage\XEngine_Source\StorageModule_APIHelp\APIHelp_Api\APIHelp_Api.cpp +// File Path: D:\XEngine_Storage\XEngine_Source\StorageModule_APIHelp\APIHelp_Api +// File Base: APIHelp_Api +// File Ext: cpp +// Project: XEngine(ͨ) +// Author: qyt +// Purpose: +// History: +*********************************************************************/ +CAPIHelp_Api::CAPIHelp_Api() +{ + +} +CAPIHelp_Api::~CAPIHelp_Api() +{ + +} +////////////////////////////////////////////////////////////////////////// +// к +////////////////////////////////////////////////////////////////////////// +/******************************************************************** +ƣAPIHelp_Api_ProxyAuth +ܣ֤ + .һptszUser + In/OutOut + ַָͣ + ɿգN + ˼û + .ptszPass + In/OutOut + ַָͣ + ɿգN + ˼ + .pptszListHdr + In/OutIn + ָָָͣ + ɿգN + ˼ҪHTTPͷ + .ģnHdrCount + In/OutIn + ͣ + ɿգN + ˼ҪHTTPͷб +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +BOOL CAPIHelp_Api::APIHelp_Api_ProxyAuth(TCHAR* ptszUser, TCHAR* ptszPass, TCHAR** pptszListHdr, int nHdrCount) +{ + APIHelp_IsErrorOccur = FALSE; + + int nSDLen = 1024; + int nAuthType = 0; + int nAuthLen = MAX_PATH; + + TCHAR tszAuthStr[MAX_PATH]; + TCHAR tszSDBuffer[1024]; + + memset(tszAuthStr, '\0', MAX_PATH); + memset(tszSDBuffer, '\0', sizeof(tszSDBuffer)); + //Ƿ֤Ϣ + if (!RfcComponents_HttpHelp_GetAuthInfo(&pptszListHdr, nHdrCount, tszAuthStr, &nAuthLen, &nAuthType)) + { + APIHelp_IsErrorOccur = TRUE; + APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_NOTAUTH; + return FALSE; + } + //ǷBASIC + if (1 != nAuthType) + { + APIHelp_IsErrorOccur = TRUE; + APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_NOTSUPPORT; + return FALSE; + } + OPenSsl_Help_BasicDecoder(tszAuthStr, ptszUser, ptszPass); + return TRUE; +} +/******************************************************************** +ƣAPIHelp_Api_RangeFile +ܣȡHTTPķΧ + .һpInt_SPos + In/OutOut + ָͣ + ɿգN + ˼ʼΧ + .pInt_EPos + In/OutOut + ָͣ + ɿգN + ˼Χ + .pInt_Count + In/OutOut + ָͣ + ɿգN + ˼ܴС + .ģpptszListHdr + In/OutIn + ָָָͣ + ɿգN + ˼HTTPЭͷб + .壺nHdrCount + In/OutIn + ָָָͣ + ɿգN + ˼б +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +BOOL CAPIHelp_Api::APIHelp_Api_RangeFile(int* pInt_SPos, int* pInt_EPos, __int64x* pInt_Count, TCHAR** pptszListHdr, int nHdrCount) +{ + APIHelp_IsErrorOccur = FALSE; + + BOOL bFound = FALSE; + LPCTSTR lpszRangeStr = _T("Range"); + LPCTSTR lpszLengthStr = _T("Content-Length"); + TCHAR tszKeyStr[128]; + TCHAR tszValueStr[128]; + TCHAR tszFieldStr[128]; + + memset(tszKeyStr, '\0', sizeof(tszKeyStr)); + memset(tszValueStr, '\0', sizeof(tszValueStr)); + memset(tszFieldStr, '\0', sizeof(tszFieldStr)); + //ǷзΧ + if (RfcComponents_HttpHelp_GetField(&pptszListHdr, nHdrCount, lpszRangeStr, tszFieldStr)) + { + //Ƿûҵ + int nBPos = 0; //ijЩʱиBYTE + if (NULL != _tcsstr(tszFieldStr, _T("bytes="))) + { + nBPos = 6; + } + if (!BaseLib_OperatorString_GetKeyValue(tszFieldStr + nBPos, "-", tszKeyStr, tszValueStr)) + { + APIHelp_IsErrorOccur = TRUE; + APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_PARSELEN; + return FALSE; + } + //õ 1/2 еĻ + TCHAR tszRangeEnd[128]; + TCHAR tszRangeCount[128]; + + memset(tszRangeEnd, '\0', sizeof(tszRangeEnd)); + memset(tszRangeCount, '\0', sizeof(tszRangeCount)); + if (BaseLib_OperatorString_GetKeyValue(tszValueStr, "/", tszRangeEnd, tszRangeCount)) + { + *pInt_SPos = _ttoi(tszKeyStr); + *pInt_EPos = _ttoi(tszRangeEnd); + *pInt_Count = _ttoi64(tszRangeCount); + } + else + { + *pInt_SPos = _ttoi(tszKeyStr); + *pInt_EPos = _ttoi(tszValueStr); + } + bFound = TRUE; + } + + if (0 == *pInt_Count) + { + if (RfcComponents_HttpHelp_GetField(&pptszListHdr, nHdrCount, lpszLengthStr, tszFieldStr)) + { + *pInt_Count = _ttoi64(tszFieldStr); + bFound = TRUE; + } + } + + if (!bFound) + { + APIHelp_IsErrorOccur = TRUE; + APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_NOTLENGTH; + return FALSE; + } + + return TRUE; +} +/******************************************************************** +ƣAPIHelp_Api_VerHash +ܣ֤HASHֵ + .һlpszFileHash + In/OutIn + ַָͣ + ɿգN + ˼ҪȶԵHASHֵ + .pptszListHdr + In/OutIn + ָָָͣ + ɿգN + ˼HTTPЭͷб + .nHdrCount + In/OutIn + ָָָͣ + ɿգN + ˼б +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +BOOL CAPIHelp_Api::APIHelp_Api_VerHash(LPCTSTR lpszFileHash, TCHAR** pptszListHdr, int nHdrCount) +{ + APIHelp_IsErrorOccur = FALSE; + + LPCTSTR lpszKeyStr = _T("FileHash"); + TCHAR tszValueStr[MAX_PATH]; + memset(tszValueStr, '\0', MAX_PATH); + + if (!RfcComponents_HttpHelp_GetField(&pptszListHdr, nHdrCount, lpszKeyStr, tszValueStr)) + { + APIHelp_IsErrorOccur = TRUE; + APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_NOTHASH; + return FALSE; + } + if (0 != _tcsnicmp(lpszFileHash, tszValueStr, _tcslen(lpszFileHash))) + { + APIHelp_IsErrorOccur = TRUE; + APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_NOTMATCH; + return FALSE; + } + return TRUE; +} \ No newline at end of file diff --git a/XEngine_Source/StorageModule_APIHelp/APIHelp_Api/APIHelp_Api.h b/XEngine_Source/StorageModule_APIHelp/APIHelp_Api/APIHelp_Api.h new file mode 100644 index 0000000000000000000000000000000000000000..3950c354856caf6eb8e8f57e1bc11ee01d010c80 --- /dev/null +++ b/XEngine_Source/StorageModule_APIHelp/APIHelp_Api/APIHelp_Api.h @@ -0,0 +1,26 @@ +#pragma once +/******************************************************************** +// Created: 2022/01/07 14:36:50 +// File Name: D:\XEngine_Storage\XEngine_Source\StorageModule_APIHelp\APIHelp_Api\APIHelp_Api.h +// File Path: D:\XEngine_Storage\XEngine_Source\StorageModule_APIHelp\APIHelp_Api +// File Base: APIHelp_Api +// File Ext: h +// Project: XEngine(ͨ) +// Author: qyt +// Purpose: +// History: +*********************************************************************/ + + +class CAPIHelp_Api +{ +public: + CAPIHelp_Api(); + ~CAPIHelp_Api(); +public: + BOOL APIHelp_Api_ProxyAuth(TCHAR* ptszUser, TCHAR* ptszPass, TCHAR** pptszListHdr, int nHdrCount); + BOOL APIHelp_Api_RangeFile(int* pInt_SPos, int* pInt_EPos, __int64x* pInt_Count, TCHAR** pptszListHdr, int nHdrCount); + BOOL APIHelp_Api_VerHash(LPCTSTR lpszFileHash, TCHAR** pptszListHdr, int nHdrCount); +protected: +private: +}; \ No newline at end of file diff --git a/XEngine_Source/StorageModule_APIHelp/APIHelp_Define.h b/XEngine_Source/StorageModule_APIHelp/APIHelp_Define.h index b986316c44e551d3b3fff553579e61e96100bf3d..fcf6900ef77c281797b161e6fb068871e5f1944c 100644 --- a/XEngine_Source/StorageModule_APIHelp/APIHelp_Define.h +++ b/XEngine_Source/StorageModule_APIHelp/APIHelp_Define.h @@ -20,28 +20,9 @@ typedef struct ////////////////////////////////////////////////////////////////////////// extern "C" DWORD StorageHelp_GetLastError(int* pInt_SysError = NULL); /************************************************************************/ -/* */ +/* 分布式函数 */ /************************************************************************/ /******************************************************************** -函数名称:APIHelp_Distributed_IsMode -函数功能:判断负载模式是否为指定模式 - 参数.一:pStl_ListMode - In/Out:In - 类型:STL容器指针 - 可空:N - 意思:输入支持的模式列表 - 参数.二:nMode - In/Out:In - 类型:整数型 - 可空:N - 意思:输入要判断的模式 -返回值 - 类型:逻辑型 - 意思:是否成功 -备注: -*********************************************************************/ -extern "C" BOOL APIHelp_Distributed_IsMode(list*pStl_ListMode, int nMode); -/******************************************************************** 函数名称:APIHelp_Distributed_RandomAddr 函数功能:随机选择一个负载的重定向服务器地址 参数.一:pStl_ListAddr @@ -54,12 +35,17 @@ extern "C" BOOL APIHelp_Distributed_IsMode(list*pStl_ListMode, int nMode); 类型:字符指针 可空:N 意思:输出获取到的负载地址 + 参数.三:nMode + In/Out:Out + 类型:整数型 + 可空:N + 意思:负载模式 返回值 类型:逻辑型 意思:是否成功 备注: *********************************************************************/ -extern "C" BOOL APIHelp_Distributed_RandomAddr(list* pStl_ListAddr, TCHAR* ptszAddr); +extern "C" BOOL APIHelp_Distributed_RandomAddr(list* pStl_ListAddr, TCHAR* ptszAddr, int nMode); /******************************************************************** 函数名称:APIHelp_Distributed_FileList 函数功能:解析所有解析到的内容并且打包成指定结构 @@ -111,19 +97,143 @@ extern "C" BOOL APIHelp_Distributed_DLStorage(LPCTSTR lpszMsgBuffer, list* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket, int nMode); +/******************************************************************** +函数名称:APIHelp_Distributed_GetPathKey +函数功能:通过BUCKET名称查找对应路径 + 参数.一:pStl_ListBucket + In/Out:In + 类型:STL容器指针 + 可空:N + 意思:输入要操作的BUCKET容器 + 参数.二:lpszBuckKey + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要匹配的BUCKET名称 + 参数.三:ptszFilePath + In/Out:Out + 类型:字符指针 + 可空:N + 意思:输出找到的路径 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" BOOL APIHelp_Distributed_GetPathKey(list* pStl_ListBucket, LPCTSTR lpszBuckKey, TCHAR* ptszFilePath); +/************************************************************************/ +/* 帮助函数 */ +/************************************************************************/ +/******************************************************************** +函数名称:APIHelp_Api_ProxyAuth +函数功能:代理验证 + 参数.一:ptszUser + In/Out:Out + 类型:字符指针 + 可空:N + 意思:输出用户名 + 参数.二:ptszPass + In/Out:Out + 类型:字符指针 + 可空:N + 意思:输出密码 + 参数.三:pptszListHdr + In/Out:In + 类型:指向指针的指针 + 可空:N + 意思:输入要解析的HTTP头 + 参数.四:nHdrCount + In/Out:In + 类型:整数型 + 可空:N + 意思:输入要解析的HTTP头列表个数 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" BOOL APIHelp_Api_ProxyAuth(TCHAR* ptszUser, TCHAR* ptszPass, TCHAR** pptszListHdr, int nHdrCount); +/******************************************************************** +函数名称:APIHelp_Api_RangeFile +函数功能:获取HTTP的范围 + 参数.一:pInt_SPos + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出起始范围 + 参数.二:pInt_EPos + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出结束范围 + 参数.三:pInt_Count + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出总大小 + 参数.四:pptszListHdr + In/Out:In + 类型:指向指针的指针 + 可空:N + 意思:输入HTTP协议头列表 + 参数.五:nHdrCount + In/Out:In + 类型:指向指针的指针 + 可空:N + 意思:输入列表个数 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" BOOL APIHelp_Api_RangeFile(int* pInt_SPos, int* pInt_EPos, __int64x* pInt_Count, TCHAR** pptszListHdr, int nHdrCount); +/******************************************************************** +函数名称:APIHelp_Api_VerHash +函数功能:验证HASH值 + 参数.一:lpszFileHash + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要比对的HASH值 + 参数.二:pptszListHdr + In/Out:In + 类型:指向指针的指针 + 可空:N + 意思:输入HTTP协议头列表 + 参数.三:nHdrCount + In/Out:In + 类型:指向指针的指针 + 可空:N + 意思:输入列表个数 返回值 类型:逻辑型 意思:是否成功 备注: *********************************************************************/ -extern "C" BOOL APIHelp_Distributed_UPStorage(list* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket); \ No newline at end of file +extern "C" BOOL APIHelp_Api_VerHash(LPCTSTR lpszFileHash, TCHAR** pptszListHdr, int nHdrCount); \ No newline at end of file diff --git a/XEngine_Source/StorageModule_APIHelp/APIHelp_Distributed/APIHelp_Distributed.cpp b/XEngine_Source/StorageModule_APIHelp/APIHelp_Distributed/APIHelp_Distributed.cpp index 7de6bc0af4a31a86666a3423396852dcd19ef609..a72bdd5f860d7e3a69501741e7818c61d55a209b 100644 --- a/XEngine_Source/StorageModule_APIHelp/APIHelp_Distributed/APIHelp_Distributed.cpp +++ b/XEngine_Source/StorageModule_APIHelp/APIHelp_Distributed/APIHelp_Distributed.cpp @@ -23,40 +23,6 @@ CAPIHelp_Distributed::~CAPIHelp_Distributed() // к ////////////////////////////////////////////////////////////////////////// /******************************************************************** -ƣAPIHelp_Distributed_IsMode -ܣжϸģʽǷΪָģʽ - .һpStl_ListMode - In/OutIn - ͣSTLָ - ɿգN - ˼ֵ֧ģʽб - .nMode - In/OutIn - ͣ - ɿգN - ˼Ҫжϵģʽ -ֵ - ͣ߼ - ˼Ƿɹ -ע -*********************************************************************/ -BOOL CAPIHelp_Distributed::APIHelp_Distributed_IsMode(list* pStl_ListMode, int nMode) -{ - APIHelp_IsErrorOccur = FALSE; - - BOOL bFound = FALSE; - list::const_iterator stl_ListIterator = pStl_ListMode->begin(); - for (; stl_ListIterator != pStl_ListMode->end(); stl_ListIterator++) - { - if (nMode == *stl_ListIterator) - { - bFound = TRUE; - break; - } - } - return bFound; -} -/******************************************************************** ƣAPIHelp_Distributed_RandomAddr ܣѡһصضַ .һpStl_ListAddr @@ -69,34 +35,66 @@ BOOL CAPIHelp_Distributed::APIHelp_Distributed_IsMode(list* pStl_ListMode, ַָͣ ɿգN ˼ȡĸصַ + .nMode + In/OutOut + ͣ + ɿգN + ˼ģʽ ֵ ͣ߼ ˼Ƿɹ ע *********************************************************************/ -BOOL CAPIHelp_Distributed::APIHelp_Distributed_RandomAddr(list* pStl_ListAddr, TCHAR* ptszAddr) +BOOL CAPIHelp_Distributed::APIHelp_Distributed_RandomAddr(list* pStl_ListAddr, TCHAR* ptszAddr, int nMode) { APIHelp_IsErrorOccur = FALSE; - BOOL bFound = FALSE; - XNETHANDLE xhToken = 0; - - BaseLib_OperatorHandle_Create(&xhToken, 0, pStl_ListAddr->size(), FALSE); - if (xhToken == pStl_ListAddr->size()) + if (!pStl_ListAddr->empty()) { - xhToken--; + APIHelp_IsErrorOccur = TRUE; + APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_PARAMENT; + return FALSE; } - list::const_iterator stl_ListIterator = pStl_ListAddr->begin(); - for (XNETHANDLE i = 0; stl_ListIterator != pStl_ListAddr->end(); stl_ListIterator++, i++) + + BOOL bFound = FALSE; + if (1 == nMode) { - if (xhToken == i) + XNETHANDLE xhToken = 0; + BaseLib_OperatorHandle_Create(&xhToken, 0, pStl_ListAddr->size(), FALSE); + if (xhToken == pStl_ListAddr->size()) { - bFound = TRUE; - _tcscpy(ptszAddr, stl_ListIterator->c_str()); - break; + xhToken--; + } + list::const_iterator stl_ListIterator = pStl_ListAddr->begin(); + for (XNETHANDLE i = 0; stl_ListIterator != pStl_ListAddr->end(); stl_ListIterator++, i++) + { + if (xhToken == i) + { + bFound = TRUE; + _tcscpy(ptszAddr, stl_ListIterator->c_str()); + break; + } } } - return bFound; + else if (2 == nMode) + { + bFound = TRUE; + _tcscpy(ptszAddr, pStl_ListAddr->front().c_str()); + } + else if (3 == nMode) + { + + bFound = TRUE; + _tcscpy(ptszAddr, pStl_ListAddr->back().c_str()); + } + + if (!bFound) + { + APIHelp_IsErrorOccur = TRUE; + APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_NOTFOUND; + return FALSE; + } + return TRUE; } /******************************************************************** ƣAPIHelp_Distributed_FileList @@ -218,22 +216,32 @@ BOOL CAPIHelp_Distributed::APIHelp_Distributed_DLStorage(LPCTSTR lpszMsgBuffer, /******************************************************************** ƣAPIHelp_Distributed_UPStorage ܣֲͨʽ洢бһ洢ַ - .һpStl_ListBucket + .һlpszMsgBuffer + In/OutIn + ַָͣ + ɿգN + ˼ҪURL + .pStl_ListBucket In/OutIn ָͣ ɿգN ˼Ҫб - .pSt_StorageBucket + .pSt_StorageBucket In/OutOut ͣݽṹָ ɿգN ˼ȡĿô洢 + .ģnMode + In/OutIn + ͣ + ɿգN + ˼LBģʽ ֵ ͣ߼ ˼Ƿɹ ע *********************************************************************/ -BOOL CAPIHelp_Distributed::APIHelp_Distributed_UPStorage(list* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket) +BOOL CAPIHelp_Distributed::APIHelp_Distributed_UPStorage(LPCTSTR lpszMsgBuffer, list* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket, int nMode) { APIHelp_IsErrorOccur = FALSE; @@ -243,37 +251,137 @@ BOOL CAPIHelp_Distributed::APIHelp_Distributed_UPStorage(listbegin(); stl_ListIterator != pStl_ListBucket->end(); stl_ListIterator++) + if (4 == nMode) + { + if (!APIHelp_Distributed_DLStorage(lpszMsgBuffer, pStl_ListBucket, pSt_StorageBucket)) + { + return FALSE; + } + } + else { - //ֻõ - if (stl_ListIterator->bEnable) + int nLastLevel = 99999; + list stl_BuckSelect; + //ȵõС + for (auto stl_ListIterator = pStl_ListBucket->begin(); stl_ListIterator != pStl_ListBucket->end(); stl_ListIterator++) { - //ȼ - if (stl_ListIterator->nLevel < nLastLevel) + //ֻõ + if (stl_ListIterator->bEnable) { - int nListCount = 0; - __int64u nDirCount = 0; //ǰĿ¼С - CHAR** ppListFile; - SystemApi_File_EnumFile(stl_ListIterator->tszFilePath, &ppListFile, &nListCount, NULL, NULL, TRUE, 1); - for (int j = 0; j < nListCount; j++) + if (stl_ListIterator->nLevel < nLastLevel) { - struct __stat64 st_FStat; - _stat64(ppListFile[j], &st_FStat); - nDirCount += st_FStat.st_size; + nLastLevel = stl_ListIterator->nLevel; //õС } - BaseLib_OperatorMemory_Free((XPPPMEM)&ppListFile, nListCount); - //ǰĿ¼С趨ĴС.ô - if (nDirCount >= APIHelp_Distributed_GetSize(stl_ListIterator->tszBuckSize)) + } + } + //б + for (auto stl_ListIterator = pStl_ListBucket->begin(); stl_ListIterator != pStl_ListBucket->end(); stl_ListIterator++) + { + //ֻõ + if (stl_ListIterator->bEnable) + { + //ȼ + if (stl_ListIterator->nLevel == nLastLevel) { - continue; + int nListCount = 0; + __int64u nDirCount = 0; //ǰĿ¼С + CHAR** ppListFile; + SystemApi_File_EnumFile(stl_ListIterator->tszFilePath, &ppListFile, &nListCount, NULL, NULL, TRUE, 1); + for (int j = 0; j < nListCount; j++) + { + struct __stat64 st_FStat; + _stat64(ppListFile[j], &st_FStat); + nDirCount += st_FStat.st_size; + } + BaseLib_OperatorMemory_Free((XPPPMEM)&ppListFile, nListCount); + //ǰĿ¼С趨ĴС.ô + if (nDirCount >= APIHelp_Distributed_GetSize(stl_ListIterator->tszBuckSize)) + { + continue; + } + stl_BuckSelect.push_back(*stl_ListIterator); } - bFound = TRUE; - nLastLevel = stl_ListIterator->nLevel; - *pSt_StorageBucket = *stl_ListIterator; } } + //ָͨģʽһkey + if (stl_BuckSelect.empty()) + { + APIHelp_IsErrorOccur = TRUE; + APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_NOTFOUND; + return FALSE; + } + if (1 == nMode) + { + XNETHANDLE xhToken = 0; + BaseLib_OperatorHandle_Create(&xhToken, 0, stl_BuckSelect.size(), FALSE); + if (xhToken == stl_BuckSelect.size()) + { + xhToken--; + } + list::const_iterator stl_ListIterator = stl_BuckSelect.begin(); + for (XNETHANDLE i = 0; stl_ListIterator != stl_BuckSelect.end(); stl_ListIterator++, i++) + { + if (xhToken == i) + { + *pSt_StorageBucket = *stl_ListIterator; + break; + } + } + } + else if (2 == nMode) + { + *pSt_StorageBucket = stl_BuckSelect.front(); + } + else if (3 == nMode) + { + *pSt_StorageBucket = stl_BuckSelect.back(); + } + } + + return TRUE; +} +/******************************************************************** +ƣAPIHelp_Distributed_GetPathKey +ܣͨBUCKETƲҶӦ· + .һpStl_ListBucket + In/OutIn + ͣSTLָ + ɿգN + ˼ҪBUCKET + .lpszBuckKey + In/OutIn + ַָͣ + ɿգN + ˼ҪƥBUCKET + .ptszFilePath + In/OutOut + ַָͣ + ɿգN + ˼ҵ· +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +BOOL CAPIHelp_Distributed::APIHelp_Distributed_GetPathKey(list* pStl_ListBucket, LPCTSTR lpszBuckKey, TCHAR* ptszFilePath) +{ + APIHelp_IsErrorOccur = FALSE; + + if ((NULL == pStl_ListBucket) || (NULL == lpszBuckKey) || (NULL == ptszFilePath)) + { + APIHelp_IsErrorOccur = TRUE; + APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_PARAMENT; + return FALSE; + } + BOOL bFound = FALSE; + for (auto stl_ListIterator = pStl_ListBucket->begin(); stl_ListIterator != pStl_ListBucket->end(); stl_ListIterator++) + { + if (0 == _tcsncmp(lpszBuckKey, stl_ListIterator->tszBuckKey, _tcslen(lpszBuckKey))) + { + _tcscpy(ptszFilePath, stl_ListIterator->tszFilePath); + bFound = TRUE; + break; + } } if (!bFound) { diff --git a/XEngine_Source/StorageModule_APIHelp/APIHelp_Distributed/APIHelp_Distributed.h b/XEngine_Source/StorageModule_APIHelp/APIHelp_Distributed/APIHelp_Distributed.h index 5c9d514c1d9bd50215d254a34cdcf51ae6e4dd69..4241442936f97bd21d739e1ef94db525a984a2d8 100644 --- a/XEngine_Source/StorageModule_APIHelp/APIHelp_Distributed/APIHelp_Distributed.h +++ b/XEngine_Source/StorageModule_APIHelp/APIHelp_Distributed/APIHelp_Distributed.h @@ -18,11 +18,11 @@ public: CAPIHelp_Distributed(); ~CAPIHelp_Distributed(); public: - BOOL APIHelp_Distributed_IsMode(list* pStl_ListMode, int nMode); - BOOL APIHelp_Distributed_RandomAddr(list* pStl_ListAddr, TCHAR* ptszAddr); + BOOL APIHelp_Distributed_RandomAddr(list* pStl_ListAddr, TCHAR* ptszAddr, int nMode); BOOL APIHelp_Distributed_FileList(list* pStl_ListParse, XSTORAGECORE_DBFILE*** pppSt_ListPacket, int* pInt_ListCount); BOOL APIHelp_Distributed_DLStorage(LPCTSTR lpszMsgBuffer, list* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket); - BOOL APIHelp_Distributed_UPStorage(list* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket); + BOOL APIHelp_Distributed_UPStorage(LPCTSTR lpszMsgBuffer, list* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket, int nMode); + BOOL APIHelp_Distributed_GetPathKey(list* pStl_ListBucket, LPCTSTR lpszBuckKey, TCHAR* ptszFilePath); protected: BOOL APIHelp_Distributed_FileListParse(LPCTSTR lpszMsgBuffer, int nMsgLen, XSTORAGECORE_DBFILE* pSt_DBFile); __int64u APIHelp_Distributed_GetSize(LPCTSTR lpszMsgBuffer); diff --git a/XEngine_Source/StorageModule_APIHelp/APIHelp_Error.h b/XEngine_Source/StorageModule_APIHelp/APIHelp_Error.h index d9481cef2acb0b54306042c2ed0aa4462c6d1713..aa66fd142a31e1c0d2e442a285d4339d5e70ee92 100644 --- a/XEngine_Source/StorageModule_APIHelp/APIHelp_Error.h +++ b/XEngine_Source/StorageModule_APIHelp/APIHelp_Error.h @@ -10,6 +10,12 @@ // Purpose: 导出错误 // History: *********************************************************************/ -#define ERROR_STORAGE_MODULE_APIHELP_PARAMENT 0x0030001 -#define ERROR_STORAGE_MODULE_APIHELP_PARSE 0x0030002 -#define ERROR_STORAGE_MODULE_APIHELP_NOTFOUND 0x0030003 \ No newline at end of file +#define ERROR_STORAGE_MODULE_APIHELP_PARAMENT 0x0030001 //参数错误 +#define ERROR_STORAGE_MODULE_APIHELP_PARSE 0x0030002 //解析失败 +#define ERROR_STORAGE_MODULE_APIHELP_NOTFOUND 0x0030003 //没有找到 +#define ERROR_STORAGE_MODULE_APIHELP_NOTAUTH 0x0030010 //没有验证信息 +#define ERROR_STORAGE_MODULE_APIHELP_NOTSUPPORT 0x0030011 //不支持 +#define ERROR_STORAGE_MODULE_APIHELP_NOTLENGTH 0x0030012 //没有长度信息 +#define ERROR_STORAGE_MODULE_APIHELP_PARSELEN 0x0030013 //解析长度失败 +#define ERROR_STORAGE_MODULE_APIHELP_NOTHASH 0x0030014 //没有HASH值 +#define ERROR_STORAGE_MODULE_APIHELP_NOTMATCH 0x0030015 //HASH不匹配 \ No newline at end of file diff --git a/XEngine_Source/StorageModule_APIHelp/Makefile b/XEngine_Source/StorageModule_APIHelp/Makefile index 58b5213eb9752b7fde2492f452f484c19d61898f..ca21933edfaacea51b859133d466cddd792e7f32 100644 --- a/XEngine_Source/StorageModule_APIHelp/Makefile +++ b/XEngine_Source/StorageModule_APIHelp/Makefile @@ -6,7 +6,7 @@ LOADBIN = LIB = LIBEX = -static-libgcc -lrt -ldl -lpthread LOADSO = -Wl,-rpath= -LIBINCLUDE = APIHelp_Distributed.o pch.o +LIBINCLUDE = APIHelp_Distributed.o APIHelp_Api.o pch.o ifeq ($(RELEASE),1) FLAGS = -c -O2 @@ -28,7 +28,9 @@ all:$(LIBINCLUDE) APIHelp_Distributed.o:./APIHelp_Distributed/APIHelp_Distributed.cpp $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(INCLUDE) ./APIHelp_Distributed/APIHelp_Distributed.cpp - +APIHelp_Api.o:./APIHelp_Api/APIHelp_Api.cpp + $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(INCLUDE) ./APIHelp_Api/APIHelp_Api.cpp + pch.o:./pch.cpp $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(INCLUDE) ./pch.cpp diff --git a/XEngine_Source/StorageModule_APIHelp/StorageModule_APIHelp.def b/XEngine_Source/StorageModule_APIHelp/StorageModule_APIHelp.def index 1f0e8e6445fa78cdc403f1136dfdb5d2ff8a96b9..9f9896702f1d9a88c3d61679229c3c1ceac24ba0 100644 --- a/XEngine_Source/StorageModule_APIHelp/StorageModule_APIHelp.def +++ b/XEngine_Source/StorageModule_APIHelp/StorageModule_APIHelp.def @@ -3,8 +3,12 @@ LIBRARY EXPORTS StorageHelp_GetLastError - APIHelp_Distributed_IsMode APIHelp_Distributed_RandomAddr APIHelp_Distributed_FileList APIHelp_Distributed_DLStorage - APIHelp_Distributed_UPStorage \ No newline at end of file + APIHelp_Distributed_UPStorage + APIHelp_Distributed_GetPathKey + + APIHelp_Api_ProxyAuth + APIHelp_Api_RangeFile + APIHelp_Api_VerHash \ No newline at end of file diff --git a/XEngine_Source/StorageModule_APIHelp/StorageModule_APIHelp.vcxproj b/XEngine_Source/StorageModule_APIHelp/StorageModule_APIHelp.vcxproj index b480b95279adaa4c247151722752295e9fe2f3ae..95b37e623ccedae9f41f4c1aab8958b348bc02fa 100644 --- a/XEngine_Source/StorageModule_APIHelp/StorageModule_APIHelp.vcxproj +++ b/XEngine_Source/StorageModule_APIHelp/StorageModule_APIHelp.vcxproj @@ -166,6 +166,7 @@ + @@ -173,6 +174,7 @@ + diff --git a/XEngine_Source/StorageModule_APIHelp/StorageModule_APIHelp.vcxproj.filters b/XEngine_Source/StorageModule_APIHelp/StorageModule_APIHelp.vcxproj.filters index 38ae2d5b44e2fc6237fbd4728204732dd34d800d..14ad6f8d58890be75f7d53e583951b6102428baa 100644 --- a/XEngine_Source/StorageModule_APIHelp/StorageModule_APIHelp.vcxproj.filters +++ b/XEngine_Source/StorageModule_APIHelp/StorageModule_APIHelp.vcxproj.filters @@ -19,6 +19,12 @@ {5b2628b8-77c6-475d-b982-4b4b8815b907} + + {91f72057-f0a5-49ff-88f2-fb003f358183} + + + {70c91174-907f-422b-8db6-f8ee8298447c} + @@ -36,6 +42,9 @@ 头文件 + + 头文件\APIHelp_Api + @@ -47,6 +56,9 @@ 源文件\APIHelp_Distributed + + 源文件\APIHelp_Api + diff --git a/XEngine_Source/StorageModule_APIHelp/pch.cpp b/XEngine_Source/StorageModule_APIHelp/pch.cpp index c792feb4feef628ae9622b05f27a6cec472cf751..69853fe2e436dae8e655096191064947944cf619 100644 --- a/XEngine_Source/StorageModule_APIHelp/pch.cpp +++ b/XEngine_Source/StorageModule_APIHelp/pch.cpp @@ -1,5 +1,6 @@ #include "pch.h" #include "APIHelp_Distributed/APIHelp_Distributed.h" +#include "APIHelp_Api/APIHelp_Api.h" /******************************************************************** // Created: 2021/07/08 16:40:04 // File Name: D:\XEngine_Storage\XEngine_Source\StorageModule_APIHelp\pch.cpp @@ -15,6 +16,7 @@ BOOL APIHelp_IsErrorOccur = FALSE; DWORD APIHelp_dwErrorCode = 0; ////////////////////////////////////////////////////////////////////////// CAPIHelp_Distributed m_APIDistributed; +CAPIHelp_Api m_APIHelp; ////////////////////////////////////////////////////////////////////////// // 导出函数 ////////////////////////////////////////////////////////////////////////// @@ -29,13 +31,9 @@ extern "C" DWORD StorageHelp_GetLastError(int* pInt_SysError) /************************************************************************/ /* */ /************************************************************************/ -extern "C" BOOL APIHelp_Distributed_IsMode(list*pStl_ListMode, int nMode) +extern "C" BOOL APIHelp_Distributed_RandomAddr(list*pStl_ListAddr, TCHAR * ptszAddr, int nMode) { - return m_APIDistributed.APIHelp_Distributed_IsMode(pStl_ListMode, nMode); -} -extern "C" BOOL APIHelp_Distributed_RandomAddr(list*pStl_ListAddr, TCHAR * ptszAddr) -{ - return m_APIDistributed.APIHelp_Distributed_RandomAddr(pStl_ListAddr, ptszAddr); + return m_APIDistributed.APIHelp_Distributed_RandomAddr(pStl_ListAddr, ptszAddr, nMode); } extern "C" BOOL APIHelp_Distributed_FileList(list*pStl_ListParse, XSTORAGECORE_DBFILE * **pppSt_ListPacket, int* pInt_ListCount) { @@ -45,7 +43,26 @@ extern "C" BOOL APIHelp_Distributed_DLStorage(LPCTSTR lpszMsgBuffer, list*pStl_ListBucket, XENGINE_STORAGEBUCKET * pSt_StorageBucket) +extern "C" BOOL APIHelp_Distributed_UPStorage(LPCTSTR lpszMsgBuffer, list*pStl_ListBucket, XENGINE_STORAGEBUCKET * pSt_StorageBucket, int nMode) +{ + return m_APIDistributed.APIHelp_Distributed_UPStorage(lpszMsgBuffer, pStl_ListBucket, pSt_StorageBucket, nMode); +} +extern "C" BOOL APIHelp_Distributed_GetPathKey(list*pStl_ListBucket, LPCTSTR lpszBuckKey, TCHAR * ptszFilePath) +{ + return m_APIDistributed.APIHelp_Distributed_GetPathKey(pStl_ListBucket, lpszBuckKey, ptszFilePath); +} +/************************************************************************/ +/* 帮助函数 */ +/************************************************************************/ +extern "C" BOOL APIHelp_Api_ProxyAuth(TCHAR * ptszUser, TCHAR * ptszPass, TCHAR * *pptszListHdr, int nHdrCount) +{ + return m_APIHelp.APIHelp_Api_ProxyAuth(ptszUser, ptszPass, pptszListHdr, nHdrCount); +} +extern "C" BOOL APIHelp_Api_RangeFile(int* pInt_SPos, int* pInt_EPos, __int64x * pInt_Count, TCHAR * *pptszListHdr, int nHdrCount) +{ + return m_APIHelp.APIHelp_Api_RangeFile(pInt_SPos, pInt_EPos, pInt_Count, pptszListHdr, nHdrCount); +} +extern "C" BOOL APIHelp_Api_VerHash(LPCTSTR lpszFileHash, TCHAR * *pptszListHdr, int nHdrCount) { - return m_APIDistributed.APIHelp_Distributed_UPStorage(pStl_ListBucket, pSt_StorageBucket); + return m_APIHelp.APIHelp_Api_VerHash(lpszFileHash, pptszListHdr, nHdrCount); } \ No newline at end of file diff --git a/XEngine_Source/StorageModule_APIHelp/pch.h b/XEngine_Source/StorageModule_APIHelp/pch.h index 88adabbec4cf9373bf8a2391724f364f6fb8bd87..62f06867ac0947747426a3395e9d9f90950e4b0f 100644 --- a/XEngine_Source/StorageModule_APIHelp/pch.h +++ b/XEngine_Source/StorageModule_APIHelp/pch.h @@ -12,6 +12,7 @@ #include "framework.h" #include #include +#include #else #ifdef _CENTOS #include @@ -33,11 +34,15 @@ using namespace std; #include #include #include +#include +#include #include #include #include #include #include +#include +#include #include "../XStorage_Protocol.h" #include "../StorageModule_Config/Config_Define.h" #include "../XEngine_StorageComponents/XStorage_SQLPacket/SQLPacket_Define.h" @@ -59,5 +64,7 @@ extern DWORD APIHelp_dwErrorCode; #ifdef _WINDOWS #pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib") +#pragma comment(lib,"XEngine_Core/XEngine_OPenSsl") +#pragma comment(lib,"XEngine_RfcComponents/RfcComponents_HttpServer") #pragma comment(lib,"XEngine_SystemSdk/XEngine_SystemApi") #endif \ No newline at end of file diff --git a/XEngine_Source/StorageModule_Config/Config_Define.h b/XEngine_Source/StorageModule_Config/Config_Define.h index de323a460db239dc19a33f875a1e3975ebb358a0..639c02dc2e3f49500c7bf9f3835a3872b46cc8cc 100644 --- a/XEngine_Source/StorageModule_Config/Config_Define.h +++ b/XEngine_Source/StorageModule_Config/Config_Define.h @@ -126,11 +126,20 @@ typedef struct BOOL bDistributed; struct { - int nServerMode; - }st_LBConfig; + int nCenterMode; + int nUPLoadMode; + int nDownldMode; + int nStorageMode; + }st_LBDistributed; + struct + { + int nCenterMode; + int nUPLoadMode; + int nDownldMode; + int nStorageMode; + }st_LBLocation; struct { - list* pStl_ListUseMode; list* pStl_ListCenter; list* pStl_ListDownload; list* pStl_ListUPLoader; diff --git a/XEngine_Source/StorageModule_Config/Config_Error.h b/XEngine_Source/StorageModule_Config/Config_Error.h index f64314c2e479d876d87d68fb687b345bdaa94753..556dabb580bb45ba0bf7611590e9ef10e3036f5f 100644 --- a/XEngine_Source/StorageModule_Config/Config_Error.h +++ b/XEngine_Source/StorageModule_Config/Config_Error.h @@ -25,5 +25,6 @@ #define ERROR_XENGINE_BLOGIC_CONFIG_JSON_P2XP 0x002000A #define ERROR_XENGINE_BLOGIC_CONFIG_JSON_CERT 0x002000B -#define ERROR_XENGINE_BLOGIC_CONFIG_JSON_LBCONFIG 0x0020010 -#define ERROR_XENGINE_BLOGIC_CONFIG_JSON_LAODBALANCE 0x0020011 \ No newline at end of file +#define ERROR_XENGINE_BLOGIC_CONFIG_JSON_LBDISTRIBUTED 0x0020010 +#define ERROR_XENGINE_BLOGIC_CONFIG_JSON_LBLOCATION 0x0020011 +#define ERROR_XENGINE_BLOGIC_CONFIG_JSON_LAODBALANCE 0x0020012 \ No newline at end of file diff --git a/XEngine_Source/StorageModule_Config/Config_Json/Config_Json.cpp b/XEngine_Source/StorageModule_Config/Config_Json/Config_Json.cpp index 27a639af60348ecae3c3ea7ae5d04db916c6833e..d2b546b4daa180c9cd838352c52ff3db21f4fc77 100644 --- a/XEngine_Source/StorageModule_Config/Config_Json/Config_Json.cpp +++ b/XEngine_Source/StorageModule_Config/Config_Json/Config_Json.cpp @@ -293,28 +293,37 @@ BOOL CConfig_Json::Config_Json_LoadBalance(LPCTSTR lpszConfigFile, XENGINE_LBCON } pSt_ServerConfig->bDistributed = st_JsonRoot["bDistributed"].asInt(); - if (st_JsonRoot["LBConfig"].empty() || (1 != st_JsonRoot["LBConfig"].size())) + if (st_JsonRoot["LBDistributed"].empty() || (4 != st_JsonRoot["LBDistributed"].size())) { Config_IsErrorOccur = TRUE; - Config_dwErrorCode = ERROR_XENGINE_BLOGIC_CONFIG_JSON_LBCONFIG; + Config_dwErrorCode = ERROR_XENGINE_BLOGIC_CONFIG_JSON_LBDISTRIBUTED; return FALSE; } - Json::Value st_JsonLBConfig = st_JsonRoot["LBConfig"]; - pSt_ServerConfig->st_LBConfig.nServerMode = st_JsonLBConfig["nUseMode"].asInt(); + Json::Value st_JsonLBDistributed = st_JsonRoot["LBDistributed"]; + pSt_ServerConfig->st_LBDistributed.nCenterMode = st_JsonLBDistributed["nCenterMode"].asInt(); + pSt_ServerConfig->st_LBDistributed.nUPLoadMode = st_JsonLBDistributed["nUPLoadMode"].asInt(); + pSt_ServerConfig->st_LBDistributed.nDownldMode = st_JsonLBDistributed["nDownldMode"].asInt(); + pSt_ServerConfig->st_LBDistributed.nStorageMode = st_JsonLBDistributed["nStorageMode"].asInt(); - if (st_JsonRoot["LoadBalance"].empty() || (5 != st_JsonRoot["LoadBalance"].size())) + if (st_JsonRoot["LBLocation"].empty() || (4 != st_JsonRoot["LBLocation"].size())) { Config_IsErrorOccur = TRUE; - Config_dwErrorCode = ERROR_XENGINE_BLOGIC_CONFIG_JSON_LAODBALANCE; + Config_dwErrorCode = ERROR_XENGINE_BLOGIC_CONFIG_JSON_LBLOCATION; return FALSE; } - Json::Value st_JsonLoadBalance = st_JsonRoot["LoadBalance"]; + Json::Value st_JsonLBLocation = st_JsonRoot["LBLocation"]; + pSt_ServerConfig->st_LBLocation.nCenterMode = st_JsonLBLocation["nCenterMode"].asInt(); + pSt_ServerConfig->st_LBLocation.nUPLoadMode = st_JsonLBLocation["nUPLoadMode"].asInt(); + pSt_ServerConfig->st_LBLocation.nDownldMode = st_JsonLBLocation["nDownldMode"].asInt(); + pSt_ServerConfig->st_LBLocation.nStorageMode = st_JsonLBLocation["nStorageMode"].asInt(); - pSt_ServerConfig->st_LoadBalance.pStl_ListUseMode = new list; - for (unsigned int i = 0; i < st_JsonLoadBalance["nUseMode"].size(); i++) + if (st_JsonRoot["LoadBalance"].empty() || (4 != st_JsonRoot["LoadBalance"].size())) { - pSt_ServerConfig->st_LoadBalance.pStl_ListUseMode->push_back(st_JsonLoadBalance["nUseMode"][i].asInt()); + Config_IsErrorOccur = TRUE; + Config_dwErrorCode = ERROR_XENGINE_BLOGIC_CONFIG_JSON_LAODBALANCE; + return FALSE; } + Json::Value st_JsonLoadBalance = st_JsonRoot["LoadBalance"]; pSt_ServerConfig->st_LoadBalance.pStl_ListCenter = new list; for (unsigned int i = 0; i < st_JsonLoadBalance["CenterAddr"].size(); i++) diff --git a/XEngine_Source/StorageModule_Protocol/Protocol_Packet/Protocol_StoragePacket.cpp b/XEngine_Source/StorageModule_Protocol/Protocol_Packet/Protocol_StoragePacket.cpp index c8e4915aa65bafe22c9b2436ad6076c37c3cb5d0..0b633bae122f590f7acef750b09851617e80da34 100644 --- a/XEngine_Source/StorageModule_Protocol/Protocol_Packet/Protocol_StoragePacket.cpp +++ b/XEngine_Source/StorageModule_Protocol/Protocol_Packet/Protocol_StoragePacket.cpp @@ -323,32 +323,42 @@ BOOL CProtocol_StoragePacket::Protocol_StoragePacket_BasicAuth(LPCTSTR lpszMetho /******************************************************************** 函数名称:Protocol_StoragePacket_UPDown 函数功能:上传下载完成代理通知协议 - 参数.一:lpszFileName + 参数.一:ptszMsgBuffer + In/Out:Out + 类型:字符指针 + 可空:N + 意思:数据包 + 参数.二:pInt_MsgLen + In/Out:Out + 类型:整数型 + 可空:N + 意思:导出数据包大小 + 参数.三:lpszBuckKey + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入文件所属BUCKET + 参数.四:lpszFileName In/Out:In 类型:常量字符指针 可空:N 意思:文件的地址 - 参数.二:lpszClientAddr + 参数.五:lpszClientAddr In/Out:In 类型:常量字符指针 可空:N 意思:用户客户端地址 - 参数.三:nFileSize + 参数.六:nFileSize In/Out:In 类型:整数型 可空:N 意思:文件大小 - 参数.四:ptszMsgBuffer - In/Out:Out - 类型:字符指针 - 可空:N - 意思:数据包 - 参数.五:pInt_MsgLen - In/Out:Out - 类型:整数型 + 参数.七:bDown + In/Out:In + 类型:逻辑型 可空:N - 意思:导出数据包大小 - 参数.六:lpszFileHash + 意思:是上传还是下载 + 参数.八:lpszFileHash In/Out:In 类型:常量字符指针 可空:Y @@ -358,7 +368,7 @@ BOOL CProtocol_StoragePacket::Protocol_StoragePacket_BasicAuth(LPCTSTR lpszMetho 意思:是否成功 备注: *********************************************************************/ -BOOL CProtocol_StoragePacket::Protocol_StoragePacket_UPDown(LPCTSTR lpszFileName, LPCTSTR lpszClientAddr, __int64x nFileSize, TCHAR* ptszMsgBuffer, int* pInt_MsgLen, LPCTSTR lpszFileHash) +BOOL CProtocol_StoragePacket::Protocol_StoragePacket_UPDown(TCHAR* ptszMsgBuffer, int* pInt_MsgLen, LPCTSTR lpszBuckKey, LPCTSTR lpszFileName, LPCTSTR lpszClientAddr, __int64x nFileSize, BOOL bDown, LPCTSTR lpszFileHash /* = NULL */) { Protocol_IsErrorOccur = FALSE; @@ -370,6 +380,8 @@ BOOL CProtocol_StoragePacket::Protocol_StoragePacket_UPDown(LPCTSTR lpszFileName } Json::Value st_JsonRoot; + st_JsonRoot["bDown"] = bDown; + st_JsonRoot["lpszBuckKey"] = lpszBuckKey; st_JsonRoot["lpszFileName"] = lpszFileName; st_JsonRoot["lpszClientAddr"] = lpszClientAddr; st_JsonRoot["nFileSize"] = nFileSize; diff --git a/XEngine_Source/StorageModule_Protocol/Protocol_Packet/Protocol_StoragePacket.h b/XEngine_Source/StorageModule_Protocol/Protocol_Packet/Protocol_StoragePacket.h index 99e54fc812f95935be7f5d4f2c7a6aa969b2dd61..c864df89e1a690b59754bbeea92d71f627cc744f 100644 --- a/XEngine_Source/StorageModule_Protocol/Protocol_Packet/Protocol_StoragePacket.h +++ b/XEngine_Source/StorageModule_Protocol/Protocol_Packet/Protocol_StoragePacket.h @@ -21,5 +21,5 @@ public: BOOL Protocol_StoragePacket_Info(TCHAR* ptszMsgBuffer, int* pInt_MsgLen, SESSION_STORAGEINFO*** pppSt_DLInfo, SESSION_STORAGEINFO*** pppSt_UPInfo, int nDLCount, int nUPCount); BOOL Protocol_StoragePacket_DirOperator(TCHAR* ptszMsgBuffer, int* pInt_MsgLen, TCHAR*** pppszListEnum, int nListCount); BOOL Protocol_StoragePacket_BasicAuth(LPCTSTR lpszMethod, LPCTSTR lpszPostUrl, LPCTSTR lpszClientAddr, LPCTSTR lpszUser, LPCTSTR lpszPass, TCHAR* ptszMsgBuffer, int* pInt_MsgLen); - BOOL Protocol_StoragePacket_UPDown(LPCTSTR lpszFileName, LPCTSTR lpszClientAddr, __int64x nFileSize, TCHAR* ptszMsgBuffer, int* pInt_MsgLen, LPCTSTR lpszFileHash = NULL); + BOOL Protocol_StoragePacket_UPDown(TCHAR* ptszMsgBuffer, int* pInt_MsgLen, LPCTSTR lpszBuckKey, LPCTSTR lpszFileName, LPCTSTR lpszClientAddr, __int64x nFileSize, BOOL bDown, LPCTSTR lpszFileHash = NULL); }; diff --git a/XEngine_Source/StorageModule_Protocol/Protocol_Parse/Protocol_StorageParse.cpp b/XEngine_Source/StorageModule_Protocol/Protocol_Parse/Protocol_StorageParse.cpp index 91e70f9e526c46e8ba2c8fabb03f7ca7a001693b..c2c2d11c62165ced902c8840cb4af9fd6c5a9956 100644 --- a/XEngine_Source/StorageModule_Protocol/Protocol_Parse/Protocol_StorageParse.cpp +++ b/XEngine_Source/StorageModule_Protocol/Protocol_Parse/Protocol_StorageParse.cpp @@ -40,7 +40,7 @@ CProtocol_StorageParse::~CProtocol_StorageParse() 类型:字符指针 可空:N 意思:查询结束时间 - 参数.四:ptszPathKey + 参数.四:ptszBuckKey In/Out:Out 类型:字符指针 可空:Y @@ -60,11 +60,11 @@ CProtocol_StorageParse::~CProtocol_StorageParse() 意思:是否成功 备注: *********************************************************************/ -BOOL CProtocol_StorageParse::Protocol_StorageParse_QueryFile(LPCTSTR lpszMsgBuffer, TCHAR* ptszTimeStart, TCHAR* ptszTimeEnd, TCHAR* ptszPathKey /* = NULL */, TCHAR* ptszFileName /* = NULL */, TCHAR* ptszFileHash /* = NULL */) +BOOL CProtocol_StorageParse::Protocol_StorageParse_QueryFile(LPCTSTR lpszMsgBuffer, TCHAR* ptszTimeStart, TCHAR* ptszTimeEnd, TCHAR* ptszBuckKey /* = NULL */, TCHAR* ptszFileName /* = NULL */, TCHAR* ptszFileHash /* = NULL */) { Protocol_IsErrorOccur = FALSE; - if ((NULL == lpszMsgBuffer) || (NULL == ptszTimeStart) || (NULL == ptszTimeEnd)) + if (NULL == lpszMsgBuffer) { Protocol_IsErrorOccur = TRUE; Protocol_dwErrorCode = ERROR_XENGINE_STORAGE_PROTOCOL_PARAMENT; @@ -113,11 +113,11 @@ BOOL CProtocol_StorageParse::Protocol_StorageParse_QueryFile(LPCTSTR lpszMsgBuff _tcscpy(ptszFileHash, st_JsonRoot["lpszFileHash"].asCString()); } } - if (NULL != ptszPathKey) + if (NULL != ptszBuckKey) { if (!st_JsonRoot["lpszBuckKey"].isNull()) { - _tcscpy(ptszPathKey, st_JsonRoot["lpszBuckKey"].asCString()); + _tcscpy(ptszBuckKey, st_JsonRoot["lpszBuckKey"].asCString()); } } return TRUE; @@ -184,6 +184,10 @@ BOOL CProtocol_StorageParse::Protocol_StorageParse_ReportFile(LPCTSTR lpszMsgBuf (*pppSt_DBFile)[i]->st_ProtocolFile.nFileSize = st_JsonArray[i]["nFileSize"].asInt64(); } + if (!st_JsonArray[i]["tszBuckKey"].isNull()) + { + _tcscpy((*pppSt_DBFile)[i]->tszBuckKey, st_JsonArray[i]["tszBuckKey"].asCString()); + } if (!st_JsonArray[i]["tszFileName"].isNull()) { _tcscpy((*pppSt_DBFile)[i]->st_ProtocolFile.tszFileName, st_JsonArray[i]["tszFileName"].asCString()); @@ -262,8 +266,11 @@ BOOL CProtocol_StorageParse::Protocol_StorageParse_DirOperator(LPCTSTR lpszMsgBu pSt_JsonReader = NULL; *pInt_Operator = st_JsonRoot["nOPerator"].asInt(); - _tcscpy(ptszUserDir, st_JsonRoot["lpszUserDir"].asCString()); _tcscpy(ptszBuckKey, st_JsonRoot["lpszBuckKey"].asCString()); + if (!st_JsonRoot["lpszUserDir"].isNull()) + { + _tcscpy(ptszUserDir, st_JsonRoot["lpszUserDir"].asCString()); + } return TRUE; } /******************************************************************** @@ -284,7 +291,7 @@ BOOL CProtocol_StorageParse::Protocol_StorageParse_DirOperator(LPCTSTR lpszMsgBu 类型:字符指针 可空:N 意思:输出文件客户端地址 - 参数.四:ptszPathKey + 参数.四:ptszBuckKey In/Out:Out 类型:字符指针 可空:N @@ -309,7 +316,7 @@ BOOL CProtocol_StorageParse::Protocol_StorageParse_DirOperator(LPCTSTR lpszMsgBu 意思:是否成功 备注: *********************************************************************/ -BOOL CProtocol_StorageParse::Protocol_StorageParse_ProxyNotify(LPCTSTR lpszMsgBuffer, int nMsgLen, TCHAR* ptszClientAddr, TCHAR* ptszPathKey, TCHAR* ptszFileName, TCHAR* ptszFileHash, __int64x* pInt_FileSize) +BOOL CProtocol_StorageParse::Protocol_StorageParse_ProxyNotify(LPCTSTR lpszMsgBuffer, int nMsgLen, TCHAR* ptszClientAddr, TCHAR* ptszBuckKey, TCHAR* ptszFileName, TCHAR* ptszFileHash, __int64x* pInt_FileSize) { Protocol_IsErrorOccur = FALSE; @@ -337,7 +344,7 @@ BOOL CProtocol_StorageParse::Protocol_StorageParse_ProxyNotify(LPCTSTR lpszMsgBu _tcscpy(ptszClientAddr, st_JsonRoot["lpszClientAddr"].asCString()); _tcscpy(ptszFileName, st_JsonRoot["lpszFileName"].asCString()); _tcscpy(ptszFileHash, st_JsonRoot["lpszFileHash"].asCString()); - _tcscpy(ptszPathKey, st_JsonRoot["lpszPathKey"].asCString()); + _tcscpy(ptszBuckKey, st_JsonRoot["lpszBuckKey"].asCString()); *pInt_FileSize = st_JsonRoot["nFileSize"].asInt64(); return TRUE; diff --git a/XEngine_Source/StorageModule_Protocol/Protocol_Parse/Protocol_StorageParse.h b/XEngine_Source/StorageModule_Protocol/Protocol_Parse/Protocol_StorageParse.h index bea9049cf2162e4987fb6572f710af38a9b02487..95d5683d349fb5b1cc5b6030acf7fb35a5ec99ad 100644 --- a/XEngine_Source/StorageModule_Protocol/Protocol_Parse/Protocol_StorageParse.h +++ b/XEngine_Source/StorageModule_Protocol/Protocol_Parse/Protocol_StorageParse.h @@ -17,8 +17,8 @@ public: CProtocol_StorageParse(); ~CProtocol_StorageParse(); public: - BOOL Protocol_StorageParse_QueryFile(LPCTSTR lpszMsgBuffer, TCHAR* ptszTimeStart, TCHAR* ptszTimeEnd, TCHAR* ptszPathKey = NULL, TCHAR* ptszFileName = NULL, TCHAR* ptszFileHash = NULL); + BOOL Protocol_StorageParse_QueryFile(LPCTSTR lpszMsgBuffer, TCHAR* ptszTimeStart, TCHAR* ptszTimeEnd, TCHAR* ptszBuckKey = NULL, TCHAR* ptszFileName = NULL, TCHAR* ptszFileHash = NULL); BOOL Protocol_StorageParse_ReportFile(LPCTSTR lpszMsgBuffer, int nMsgLen, XSTORAGECORE_DBFILE*** pppSt_DBFile, int* pInt_ListCount); BOOL Protocol_StorageParse_DirOperator(LPCTSTR lpszMsgBuffer, TCHAR* ptszUserDir, TCHAR* ptszBuckKey, int* pInt_Operator); - BOOL Protocol_StorageParse_ProxyNotify(LPCTSTR lpszMsgBuffer, int nMsgLen, TCHAR* ptszClientAddr, TCHAR* ptszPathKey, TCHAR* ptszFileName, TCHAR* ptszFileHash, __int64x* pInt_FileSize); + BOOL Protocol_StorageParse_ProxyNotify(LPCTSTR lpszMsgBuffer, int nMsgLen, TCHAR* ptszClientAddr, TCHAR* ptszBuckKey, TCHAR* ptszFileName, TCHAR* ptszFileHash, __int64x* pInt_FileSize); }; diff --git a/XEngine_Source/StorageModule_Protocol/StorageProtocol_Define.h b/XEngine_Source/StorageModule_Protocol/StorageProtocol_Define.h index fc3e08fd0e9811ba4e7035539975cb4c5469a80c..35c016514b76d49008ff9acc788620c7155d505f 100644 --- a/XEngine_Source/StorageModule_Protocol/StorageProtocol_Define.h +++ b/XEngine_Source/StorageModule_Protocol/StorageProtocol_Define.h @@ -136,7 +136,7 @@ extern "C" BOOL Protocol_P2XPParse_Connect(LPCTSTR lpszMsgBuffer, int nMsgLen, X 类型:字符指针 可空:N 意思:输出文件客户端地址 - 参数.四:ptszPathKey + 参数.四:ptszBuckKey In/Out:Out 类型:字符指针 可空:N @@ -161,7 +161,7 @@ extern "C" BOOL Protocol_P2XPParse_Connect(LPCTSTR lpszMsgBuffer, int nMsgLen, X 意思:是否成功 备注: *********************************************************************/ -extern "C" BOOL Protocol_StorageParse_ProxyNotify(LPCTSTR lpszMsgBuffer, int nMsgLen, TCHAR * ptszClientAddr, TCHAR * ptszPathKey, TCHAR * ptszFileName, TCHAR * ptszFileHash, __int64x * pInt_FileSize); +extern "C" BOOL Protocol_StorageParse_ProxyNotify(LPCTSTR lpszMsgBuffer, int nMsgLen, TCHAR * ptszClientAddr, TCHAR * ptszBuckKey, TCHAR * ptszFileName, TCHAR * ptszFileHash, __int64x * pInt_FileSize); /******************************************************************** 函数名称:Protocol_StorageParse_QueryFile 函数功能:文件查询请求解析函数 @@ -195,7 +195,7 @@ extern "C" BOOL Protocol_StorageParse_ProxyNotify(LPCTSTR lpszMsgBuffer, int nMs 意思:是否成功 备注: *********************************************************************/ -extern "C" BOOL Protocol_StorageParse_QueryFile(LPCSTR lpszMsgBuffer, CHAR * ptszTimeStart, CHAR * ptszTimeEnd, CHAR * ptszPathKey = NULL, CHAR * ptszFileName = NULL, CHAR * ptszFileHash = NULL); +extern "C" BOOL Protocol_StorageParse_QueryFile(LPCSTR lpszMsgBuffer, CHAR * ptszTimeStart, CHAR * ptszTimeEnd, CHAR * ptszBuckKey = NULL, CHAR * ptszFileName = NULL, CHAR * ptszFileHash = NULL); /******************************************************************** 函数名称:Protocol_StorageParse_ReportFile 函数功能:解析文件报告协议 @@ -488,32 +488,42 @@ extern "C" BOOL Protocol_StoragePacket_BasicAuth(LPCTSTR lpszMethod, LPCTSTR lps /******************************************************************** 函数名称:Protocol_StoragePacket_UPDown 函数功能:上传下载完成代理通知协议 - 参数.一:lpszFileName + 参数.一:ptszMsgBuffer + In/Out:Out + 类型:字符指针 + 可空:N + 意思:数据包 + 参数.二:pInt_MsgLen + In/Out:Out + 类型:整数型 + 可空:N + 意思:导出数据包大小 + 参数.三:lpszBuckKey + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入文件所属BUCKET + 参数.四:lpszFileName In/Out:In 类型:常量字符指针 可空:N 意思:文件的地址 - 参数.二:lpszClientAddr + 参数.五:lpszClientAddr In/Out:In 类型:常量字符指针 可空:N 意思:用户客户端地址 - 参数.三:nFileSize + 参数.六:nFileSize In/Out:In 类型:整数型 可空:N 意思:文件大小 - 参数.四:ptszMsgBuffer - In/Out:Out - 类型:字符指针 - 可空:N - 意思:数据包 - 参数.五:pInt_MsgLen - In/Out:Out - 类型:整数型 + 参数.七:bDown + In/Out:In + 类型:逻辑型 可空:N - 意思:导出数据包大小 - 参数.六:lpszFileHash + 意思:是上传还是下载 + 参数.八:lpszFileHash In/Out:In 类型:常量字符指针 可空:Y @@ -523,7 +533,7 @@ extern "C" BOOL Protocol_StoragePacket_BasicAuth(LPCTSTR lpszMethod, LPCTSTR lps 意思:是否成功 备注: *********************************************************************/ -extern "C" BOOL Protocol_StoragePacket_UPDown(LPCTSTR lpszFileName, LPCTSTR lpszClientAddr, __int64x nFileSize, TCHAR * ptszMsgBuffer, int* pInt_MsgLen, LPCTSTR lpszFileHash = NULL); +extern "C" BOOL Protocol_StoragePacket_UPDown(TCHAR * ptszMsgBuffer, int* pInt_MsgLen, LPCTSTR lpszBuckKey, LPCTSTR lpszFileName, LPCTSTR lpszClientAddr, __int64x nFileSize, BOOL bDown, LPCTSTR lpszFileHash = NULL); /******************************************************************** 函数名称:Protocol_StorageParse_QueryFile 函数功能:查询回复打包协议 diff --git a/XEngine_Source/StorageModule_Protocol/pch.cpp b/XEngine_Source/StorageModule_Protocol/pch.cpp index 72151045227abbd666ab51e0ddeff2ccd41e8346..0cc739b1b1f7a069ec98649b980fc31cdaee911e 100644 --- a/XEngine_Source/StorageModule_Protocol/pch.cpp +++ b/XEngine_Source/StorageModule_Protocol/pch.cpp @@ -50,13 +50,13 @@ extern "C" BOOL Protocol_P2XPParse_Connect(LPCTSTR lpszMsgBuffer, int nMsgLen, X return m_P2XPParse.Protocol_P2XPParse_Connect(lpszMsgBuffer, nMsgLen, pSt_IOProtocol); } ////////////////////////////////////////////////////////////////////////// -extern "C" BOOL Protocol_StorageParse_ProxyNotify(LPCTSTR lpszMsgBuffer, int nMsgLen, TCHAR * ptszClientAddr, TCHAR * ptszPathKey, TCHAR * ptszFileName, TCHAR * ptszFileHash, __int64x * pInt_FileSize) +extern "C" BOOL Protocol_StorageParse_ProxyNotify(LPCTSTR lpszMsgBuffer, int nMsgLen, TCHAR * ptszClientAddr, TCHAR * ptszBuckKey, TCHAR * ptszFileName, TCHAR * ptszFileHash, __int64x * pInt_FileSize) { - return m_StorageParse.Protocol_StorageParse_ProxyNotify(lpszMsgBuffer, nMsgLen, ptszClientAddr, ptszPathKey, ptszFileName, ptszFileHash, pInt_FileSize); + return m_StorageParse.Protocol_StorageParse_ProxyNotify(lpszMsgBuffer, nMsgLen, ptszClientAddr, ptszBuckKey, ptszFileName, ptszFileHash, pInt_FileSize); } -extern "C" BOOL Protocol_StorageParse_QueryFile(LPCTSTR lpszMsgBuffer, TCHAR * ptszTimeStart, TCHAR * ptszTimeEnd, CHAR * ptszPathKey, TCHAR * ptszFileName, TCHAR * ptszFileHash) +extern "C" BOOL Protocol_StorageParse_QueryFile(LPCTSTR lpszMsgBuffer, TCHAR * ptszTimeStart, TCHAR * ptszTimeEnd, CHAR * ptszBuckKey, TCHAR * ptszFileName, TCHAR * ptszFileHash) { - return m_StorageParse.Protocol_StorageParse_QueryFile(lpszMsgBuffer, ptszTimeStart, ptszTimeEnd, ptszPathKey, ptszFileName, ptszFileHash); + return m_StorageParse.Protocol_StorageParse_QueryFile(lpszMsgBuffer, ptszTimeStart, ptszTimeEnd, ptszBuckKey, ptszFileName, ptszFileHash); } extern "C" BOOL Protocol_StorageParse_ReportFile(LPCTSTR lpszMsgBuffer, int nMsgLen, XSTORAGECORE_DBFILE * **pppSt_DBFile, int* pInt_ListCount) { @@ -98,9 +98,9 @@ extern "C" BOOL Protocol_StoragePacket_BasicAuth(LPCTSTR lpszMethod, LPCTSTR lps { return m_StoragePacket.Protocol_StoragePacket_BasicAuth(lpszMethod, lpszPostUrl, lpszClientAddr, lpszUser, lpszPass, ptszMsgBuffer, pInt_MsgLen); } -extern "C" BOOL Protocol_StoragePacket_UPDown(LPCTSTR lpszFileName, LPCTSTR lpszClientAddr, __int64x nFileSize, TCHAR * ptszMsgBuffer, int* pInt_MsgLen, LPCTSTR lpszFileHash) +extern "C" BOOL Protocol_StoragePacket_UPDown(TCHAR * ptszMsgBuffer, int* pInt_MsgLen, LPCTSTR lpszBuckKey, LPCTSTR lpszFileName, LPCTSTR lpszClientAddr, __int64x nFileSize, BOOL bDown, LPCTSTR lpszFileHash) { - return m_StoragePacket.Protocol_StoragePacket_UPDown(lpszFileName, lpszClientAddr, nFileSize, ptszMsgBuffer, pInt_MsgLen, lpszFileHash); + return m_StoragePacket.Protocol_StoragePacket_UPDown(ptszMsgBuffer, pInt_MsgLen, lpszBuckKey, lpszFileName, lpszClientAddr, nFileSize, bDown, lpszFileHash); } extern "C" BOOL Protocol_StoragePacket_QueryFile(TCHAR * ptszMsgBuffer, int* pInt_MsgLen, XSTORAGECORE_DBFILE * **pppSt_DBFile, int nListCount, LPCTSTR lpszTimeStart, LPCTSTR lpszTimeEnd) { diff --git a/XEngine_Source/StorageModule_Session/Session_Define.h b/XEngine_Source/StorageModule_Session/Session_Define.h index 6445346681a44021cff3d2c6b60e224dbf5f0f6a..323f7c3675b64d1fcafa3ae18a520c954bf6298e 100644 --- a/XEngine_Source/StorageModule_Session/Session_Define.h +++ b/XEngine_Source/StorageModule_Session/Session_Define.h @@ -18,6 +18,7 @@ typedef struct TCHAR tszFileDir[MAX_PATH]; //文件地址 TCHAR tszClientAddr[128]; //操作的用户地址 TCHAR tszFileHash[128]; //文件HASH值 + TCHAR tszBuckKey[128]; //BUCKKey __int64x ullCount; //总大小 __int64x ullRWCount; //读取(写入)总大小 __int64x ullRWLen; //已经读取(写入)的大小 @@ -110,32 +111,37 @@ extern "C" BOOL Session_DLStroage_Destory(); 类型:常量字符指针 可空:N 意思:输入要操作的客户端 - 参数.二:lpszFileDir + 参数.二:lpszBuckKey + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入BUCKET名称 + 参数.三:lpszFileDir In/Out:In 类型:常量字符指针 可空:N 意思:输入文件地址 - 参数.三:pInt_Count + 参数.四:pInt_Count In/Out:Out 类型:整数型指针 可空:N 意思:输出文件大小 - 参数.四:pInt_LeftCount + 参数.五:pInt_LeftCount In/Out:Out 类型:整数型指针 可空:N 意思:输出需要读取大小 - 参数.五:nPosStart + 参数.六:nPosStart In/Out:In 类型:整数型 可空:Y 意思:输入开始位置 - 参数.六:nPostEnd + 参数.七:nPostEnd In/Out:In 类型:整数型 可空:Y 意思:输入结束位置 - 参数.七:lpszFileHash + 参数.八:lpszFileHash In/Out:In 类型:常量字符指针 可空:Y @@ -145,7 +151,7 @@ extern "C" BOOL Session_DLStroage_Destory(); 意思:是否成功 备注: *********************************************************************/ -extern "C" BOOL Session_DLStroage_Insert(LPCTSTR lpszClientAddr, LPCTSTR lpszFileDir, __int64x * pInt_Count, __int64x * pInt_LeftCount, int nPosStart = 0, int nPostEnd = 0, LPCTSTR lpszFileHash = NULL); +extern "C" BOOL Session_DLStroage_Insert(LPCTSTR lpszClientAddr, LPCTSTR lpszBuckKey, LPCTSTR lpszFileDir, __int64x * pInt_Count, __int64x * pInt_LeftCount, int nPosStart = 0, int nPostEnd = 0, LPCTSTR lpszFileHash = NULL); /******************************************************************** 函数名称:Session_DLStroage_GetBuffer 函数功能:获得下载器中指定缓冲区 @@ -290,27 +296,32 @@ extern "C" BOOL Session_UPStroage_Destory(); 类型:常量字符指针 可空:N 意思:输入要操作的客户端 - 参数.二:lpszFileDir + 参数.二:lpszBuckKey + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入BUCKET名称 + 参数.三:lpszFileDir In/Out:In 类型:常量字符指针 可空:N 意思:输入文件地址 - 参数.三:nFileSize + 参数.四:nFileSize In/Out:Out 类型:整数型 可空:N 意思:输入文件大小 - 参数.四:nLeftCount + 参数.五:nLeftCount In/Out:In 类型:整数型 可空:N 意思:输入需要写入的大小 - 参数.五:nPosStart + 参数.六:nPosStart In/Out:In 类型:整数型 可空:Y 意思:输入起始位置 - 参数.六:nPostEnd + 参数.七:nPostEnd In/Out:In 类型:整数型 可空:Y @@ -320,7 +331,7 @@ extern "C" BOOL Session_UPStroage_Destory(); 意思:是否成功 备注: *********************************************************************/ -extern "C" BOOL Session_UPStroage_Insert(LPCTSTR lpszClientAddr, LPCTSTR lpszFileDir, __int64x nFileSize, __int64x nLeftCount, int nPosStart = 0, int nPostEnd = 0); +extern "C" BOOL Session_UPStroage_Insert(LPCTSTR lpszClientAddr, LPCTSTR lpszBuckKey, LPCTSTR lpszFileDir, __int64x nFileSize, __int64x nLeftCount, int nPosStart = 0, int nPostEnd = 0); /******************************************************************** 函数名称:Session_UPStroage_GetInfo 函数功能:获取上传客户端信息 diff --git a/XEngine_Source/StorageModule_Session/Session_Stroage/Session_DLStroage.cpp b/XEngine_Source/StorageModule_Session/Session_Stroage/Session_DLStroage.cpp index dfea2b539ebe789747701d6966ac9507b67d928b..372a34b30bccf599373b83e2bc62002dd6775be5 100644 --- a/XEngine_Source/StorageModule_Session/Session_Stroage/Session_DLStroage.cpp +++ b/XEngine_Source/StorageModule_Session/Session_Stroage/Session_DLStroage.cpp @@ -66,32 +66,37 @@ BOOL CSession_DLStroage::Session_DLStroage_Destory() 类型:常量字符指针 可空:N 意思:输入要操作的客户端 - 参数.二:lpszFileDir + 参数.二:lpszBuckKey + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入BUCKET名称 + 参数.三:lpszFileDir In/Out:In 类型:常量字符指针 可空:N 意思:输入文件地址 - 参数.三:pInt_Count + 参数.四:pInt_Count In/Out:Out 类型:整数型指针 可空:N 意思:输出文件大小 - 参数.四:pInt_LeftCount + 参数.五:pInt_LeftCount In/Out:Out 类型:整数型指针 可空:N 意思:输出需要读取大小 - 参数.五:nPosStart + 参数.六:nPosStart In/Out:In 类型:整数型 可空:Y 意思:输入开始位置 - 参数.六:nPostEnd + 参数.七:nPostEnd In/Out:In 类型:整数型 可空:Y 意思:输入结束位置 - 参数.七:lpszFileHash + 参数.八:lpszFileHash In/Out:In 类型:常量字符指针 可空:Y @@ -101,7 +106,7 @@ BOOL CSession_DLStroage::Session_DLStroage_Destory() 意思:是否成功 备注: *********************************************************************/ -BOOL CSession_DLStroage::Session_DLStroage_Insert(LPCTSTR lpszClientAddr, LPCTSTR lpszFileDir, __int64x* pInt_Count, __int64x* pInt_LeftCount, int nPosStart /* = 0 */, int nPostEnd /* = 0 */, LPCTSTR lpszFileHash /* = NULL */) +BOOL CSession_DLStroage::Session_DLStroage_Insert(LPCTSTR lpszClientAddr, LPCTSTR lpszBuckKey, LPCTSTR lpszFileDir, __int64x* pInt_Count, __int64x* pInt_LeftCount, int nPosStart /* = 0 */, int nPostEnd /* = 0 */, LPCTSTR lpszFileHash /* = NULL */) { Session_IsErrorOccur = FALSE; @@ -139,6 +144,7 @@ BOOL CSession_DLStroage::Session_DLStroage_Insert(LPCTSTR lpszClientAddr, LPCTST st_Client.ullCount = st_FStat.st_size; _tcscpy(st_Client.tszFileDir, lpszFileDir); _tcscpy(st_Client.tszClientAddr, lpszClientAddr); + _tcscpy(st_Client.tszBuckKey, lpszBuckKey); if (NULL != lpszFileHash) { _tcscpy(st_Client.tszFileHash, lpszFileHash); diff --git a/XEngine_Source/StorageModule_Session/Session_Stroage/Session_DLStroage.h b/XEngine_Source/StorageModule_Session/Session_Stroage/Session_DLStroage.h index 6b9e85965f6a6dc914e32d09da361f26f0ee0837..8df77b2c179a80a4d68f6a33e526baf66adb3f36 100644 --- a/XEngine_Source/StorageModule_Session/Session_Stroage/Session_DLStroage.h +++ b/XEngine_Source/StorageModule_Session/Session_Stroage/Session_DLStroage.h @@ -19,7 +19,7 @@ public: public: BOOL Session_DLStroage_Init(int nTryTime); BOOL Session_DLStroage_Destory(); - BOOL Session_DLStroage_Insert(LPCTSTR lpszClientAddr, LPCTSTR lpszFileDir, __int64x* pInt_Count, __int64x* pInt_LeftCount, int nPosStart = 0, int nPostEnd = 0, LPCTSTR lpszFileHash = NULL); + BOOL Session_DLStroage_Insert(LPCTSTR lpszClientAddr, LPCTSTR lpszBuckKey, LPCTSTR lpszFileDir, __int64x* pInt_Count, __int64x* pInt_LeftCount, int nPosStart = 0, int nPostEnd = 0, LPCTSTR lpszFileHash = NULL); BOOL Session_DLStroage_GetBuffer(LPCTSTR lpszClientAddr, TCHAR* ptszMsgBuffer, int* pInt_MsgLen); BOOL Session_DLStroage_GetInfo(LPCTSTR lpszClientAddr, SESSION_STORAGEINFO* pSt_StorageInfo); BOOL Session_DLStroage_GetCount(int* pInt_ListCount); diff --git a/XEngine_Source/StorageModule_Session/Session_Stroage/Session_UPStroage.cpp b/XEngine_Source/StorageModule_Session/Session_Stroage/Session_UPStroage.cpp index 60f246c3ed709cd741d2666a0111021d75940e89..669bc0f96336a1fc3caab8f8e988952c4dc47b04 100644 --- a/XEngine_Source/StorageModule_Session/Session_Stroage/Session_UPStroage.cpp +++ b/XEngine_Source/StorageModule_Session/Session_Stroage/Session_UPStroage.cpp @@ -66,27 +66,32 @@ BOOL CSession_UPStroage::Session_UPStroage_Destory() 类型:常量字符指针 可空:N 意思:输入要操作的客户端 - 参数.二:lpszFileDir + 参数.二:lpszBuckKey + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入BUCKET名称 + 参数.三:lpszFileDir In/Out:In 类型:常量字符指针 可空:N 意思:输入文件地址 - 参数.三:nFileSize + 参数.四:nFileSize In/Out:Out 类型:整数型 可空:N 意思:输入文件大小 - 参数.四:nLeftCount + 参数.五:nLeftCount In/Out:In 类型:整数型 可空:N 意思:输入需要写入的大小 - 参数.五:nPosStart + 参数.六:nPosStart In/Out:In 类型:整数型 可空:Y 意思:输入起始位置 - 参数.六:nPostEnd + 参数.七:nPostEnd In/Out:In 类型:整数型 可空:Y @@ -96,7 +101,7 @@ BOOL CSession_UPStroage::Session_UPStroage_Destory() 意思:是否成功 备注: *********************************************************************/ -BOOL CSession_UPStroage::Session_UPStroage_Insert(LPCTSTR lpszClientAddr, LPCTSTR lpszFileDir, __int64x nFileSize, __int64x nLeftCount, int nPosStart /* = 0 */, int nPostEnd /* = 0 */) +BOOL CSession_UPStroage::Session_UPStroage_Insert(LPCTSTR lpszClientAddr, LPCTSTR lpszBuckKey, LPCTSTR lpszFileDir, __int64x nFileSize, __int64x nLeftCount, int nPosStart /* = 0 */, int nPostEnd /* = 0 */) { Session_IsErrorOccur = FALSE; @@ -120,17 +125,18 @@ BOOL CSession_UPStroage::Session_UPStroage_Insert(LPCTSTR lpszClientAddr, LPCTST SESSION_STORAGEUPLOADER st_Client; memset(&st_Client, '\0', sizeof(SESSION_STORAGEUPLOADER)); - + //填充下载信息 st_Client.st_StorageInfo.ullPosStart = nPosStart; st_Client.st_StorageInfo.ullPosEnd = nPostEnd; st_Client.st_StorageInfo.ullRWCount = nLeftCount; st_Client.st_StorageInfo.ullCount = nFileSize; + _tcscpy(st_Client.st_StorageInfo.tszBuckKey, lpszBuckKey); _tcscpy(st_Client.st_StorageInfo.tszFileDir, lpszFileDir); _tcscpy(st_Client.st_StorageInfo.tszClientAddr, lpszClientAddr); - //填充下载信息 - if ((m_bResume) && ((0 != nPosStart) || (0 != nPostEnd))) + //文件是否存在 + if ((m_bResume) && ((0 != nPosStart) || (0 != nPostEnd)) && (0 == _taccess(lpszFileDir, 0))) { - st_Client.st_StorageInfo.pSt_File = _tfopen(lpszFileDir, _T("ab+")); + st_Client.st_StorageInfo.pSt_File = _tfopen(lpszFileDir, _T("rb+")); if (NULL == st_Client.st_StorageInfo.pSt_File) { Session_IsErrorOccur = TRUE; @@ -251,7 +257,7 @@ BOOL CSession_UPStroage::Session_UPStroage_Write(LPCTSTR lpszClientAddr, LPCTSTR break; } } - stl_MapIterator->second.st_StorageInfo.ullRWLen += nMsgLen; + stl_MapIterator->second.st_StorageInfo.ullRWLen += nWLen; st_Locker.unlock_shared(); return TRUE; } diff --git a/XEngine_Source/StorageModule_Session/Session_Stroage/Session_UPStroage.h b/XEngine_Source/StorageModule_Session/Session_Stroage/Session_UPStroage.h index ed112e05a95e7e08feb6149bba1cf676205530ea..c92937e7c998a93323edce94203e1a9050a7b27e 100644 --- a/XEngine_Source/StorageModule_Session/Session_Stroage/Session_UPStroage.h +++ b/XEngine_Source/StorageModule_Session/Session_Stroage/Session_UPStroage.h @@ -24,7 +24,7 @@ public: public: BOOL Session_UPStroage_Init(BOOL bUPResume = FALSE); BOOL Session_UPStroage_Destory(); - BOOL Session_UPStroage_Insert(LPCTSTR lpszClientAddr, LPCTSTR lpszFileDir, __int64x nFileSize, __int64x nLeftCount, int nPosStart = 0, int nPostEnd = 0); + BOOL Session_UPStroage_Insert(LPCTSTR lpszClientAddr, LPCTSTR lpszBuckKey, LPCTSTR lpszFileDir, __int64x nFileSize, __int64x nLeftCount, int nPosStart = 0, int nPostEnd = 0); BOOL Session_UPStroage_GetInfo(LPCTSTR lpszClientAddr, SESSION_STORAGEINFO* pSt_StorageInfo); BOOL Session_UPStroage_Write(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMsgLen); BOOL Session_UPStroage_Exist(LPCTSTR lpszClientAddr); diff --git a/XEngine_Source/StorageModule_Session/pch.cpp b/XEngine_Source/StorageModule_Session/pch.cpp index 0393f9d30647fef4e4fd598c44159298f374682c..3f718cd799f94cc7c7145d3edce08bc102eeeee9 100644 --- a/XEngine_Source/StorageModule_Session/pch.cpp +++ b/XEngine_Source/StorageModule_Session/pch.cpp @@ -56,9 +56,9 @@ extern "C" BOOL Session_DLStroage_Destory() { return m_DLStorage.Session_DLStroage_Destory(); } -extern "C" BOOL Session_DLStroage_Insert(LPCTSTR lpszClientAddr, LPCTSTR lpszFileDir, __int64x * pInt_Count, __int64x * pInt_LeftCount, int nPosStart, int nPostEnd, LPCTSTR lpszFileHash) +extern "C" BOOL Session_DLStroage_Insert(LPCTSTR lpszClientAddr, LPCTSTR lpszBuckKey, LPCTSTR lpszFileDir, __int64x * pInt_Count, __int64x * pInt_LeftCount, int nPosStart, int nPostEnd, LPCTSTR lpszFileHash) { - return m_DLStorage.Session_DLStroage_Insert(lpszClientAddr, lpszFileDir, pInt_Count, pInt_LeftCount, nPosStart, nPostEnd, lpszFileHash); + return m_DLStorage.Session_DLStroage_Insert(lpszClientAddr, lpszBuckKey, lpszFileDir, pInt_Count, pInt_LeftCount, nPosStart, nPostEnd, lpszFileHash); } extern "C" BOOL Session_DLStroage_GetBuffer(LPCTSTR lpszClientAddr, TCHAR * ptszMsgBuffer, int* pInt_MsgLen) { @@ -92,9 +92,9 @@ extern "C" BOOL Session_UPStroage_Destory() { return m_UPStorage.Session_UPStroage_Destory(); } -extern "C" BOOL Session_UPStroage_Insert(LPCTSTR lpszClientAddr, LPCTSTR lpszFileDir, __int64x nFileSize, __int64x nLeftCount, int nPosStart, int nPostEnd) +extern "C" BOOL Session_UPStroage_Insert(LPCTSTR lpszClientAddr, LPCTSTR lpszBuckKey, LPCTSTR lpszFileDir, __int64x nFileSize, __int64x nLeftCount, int nPosStart, int nPostEnd) { - return m_UPStorage.Session_UPStroage_Insert(lpszClientAddr, lpszFileDir, nFileSize, nLeftCount, nPosStart, nPostEnd); + return m_UPStorage.Session_UPStroage_Insert(lpszClientAddr, lpszBuckKey, lpszFileDir, nFileSize, nLeftCount, nPosStart, nPostEnd); } extern "C" BOOL Session_UPStroage_GetInfo(LPCTSTR lpszClientAddr, SESSION_STORAGEINFO * pSt_StorageInfo) { diff --git a/XEngine_Source/StorageModule_Session/pch.h b/XEngine_Source/StorageModule_Session/pch.h index 218bbcbcce0068860bde3b1edcd7f793f8fc42ab..05b469ca37f20810915fc8aea1c1b4fd4f06bfa9 100644 --- a/XEngine_Source/StorageModule_Session/pch.h +++ b/XEngine_Source/StorageModule_Session/pch.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include diff --git a/XEngine_Source/XEngine_StorageApp/StorageApp_Center.cpp b/XEngine_Source/XEngine_StorageApp/StorageApp_Center.cpp index 9555ad28a8527f757cc638b54a8557fead6abc27..4277b1479224aec8f61ab8697ad5ff9b33d2ce22 100644 --- a/XEngine_Source/XEngine_StorageApp/StorageApp_Center.cpp +++ b/XEngine_Source/XEngine_StorageApp/StorageApp_Center.cpp @@ -56,21 +56,69 @@ BOOL XEngine_Task_HttpCenter(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int memset(&st_HDRParam, '\0', sizeof(RFCCOMPONENTS_HTTP_HDRPARAM)); LPCTSTR lpszMethodPost = _T("POST"); - LPCTSTR lpszMethodGet = _T("GET"); LPCTSTR lpszMethodOption = _T("OPTIONS"); - if (0 == _tcsnicmp(lpszMethodPost, pSt_HTTPParam->tszHttpMethod, _tcslen(lpszMethodPost))) + if (st_ServiceCfg.st_XProxy.st_XProxyAuth.bAuth) { - if (!XEngine_APPHelp_ProxyAuth(lpszClientAddr, lpszMethodPost, pSt_HTTPParam->tszHttpUri, pptszListHdr, nHdrCount, STORAGE_NETTYPE_HTTPCENTER)) + TCHAR tszUserName[64]; + TCHAR tszUserPass[64]; + + memset(tszUserName, '\0', sizeof(tszUserName)); + memset(tszUserPass, '\0', sizeof(tszUserPass)); + if (!APIHelp_Api_ProxyAuth(tszUserName, tszUserPass, pptszListHdr, nHdrCount)) { + st_HDRParam.bIsClose = TRUE; + st_HDRParam.bAuth = TRUE; + st_HDRParam.nHttpCode = 401; + + RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam); + XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("业务客户端:%s,用户验证失败,错误:%lX"), lpszClientAddr, APIHelp_GetLastError()); return FALSE; } - if (st_ServiceCfg.st_XProxy.st_XProxyAuth.bAuth) + if (_tcslen(st_ServiceCfg.st_XProxy.st_XProxyAuth.tszAuthProxy) > 0) { - st_HDRParam.bAuth = TRUE; + int nBLen = 0; + int nResponseCode = 0; + TCHAR* ptszBody = NULL; + + Protocol_StoragePacket_BasicAuth(pSt_HTTPParam->tszHttpMethod, pSt_HTTPParam->tszHttpUri, lpszClientAddr, tszUserName, tszUserPass, tszSDBuffer, &nSDLen); + APIHelp_HttpRequest_Post(st_ServiceCfg.st_XProxy.st_XProxyAuth.tszAuthProxy, tszSDBuffer, &nResponseCode, &ptszBody, &nBLen); + if (200 != nResponseCode) + { + st_HDRParam.bIsClose = TRUE; + st_HDRParam.bAuth = TRUE; + st_HDRParam.nHttpCode = nResponseCode; + + RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam); + XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("业务客户端:%s,用户验证失败,用户名:%s,密码:%s,错误码:%d,错误内容:%s"), tszUserName, tszUserPass, tszUserPass, nResponseCode, ptszBody); + } + BaseLib_OperatorMemory_FreeCStyle((VOID**)&ptszBody); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("业务客户端:%s,代理服务:%s 验证通过,用户名:%s,密码:%s"), lpszClientAddr, st_ServiceCfg.st_XProxy.st_XProxyAuth.tszAuthProxy, tszUserName, tszUserPass); } + else + { + if (!Session_User_Exist(tszUserName, tszUserPass)) + { + st_HDRParam.bIsClose = TRUE; + st_HDRParam.bAuth = TRUE; + st_HDRParam.nHttpCode = 401; + + RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam); + XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("业务客户端:%s,验证用户失败,无法继续"), lpszClientAddr); + return FALSE; + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("业务客户端:%s,本地验证用户验证通过,用户名:%s,密码:%s"), lpszClientAddr, tszUserName, tszUserPass); + } + st_HDRParam.bAuth = TRUE; + } + + if (0 == _tcsnicmp(lpszMethodPost, pSt_HTTPParam->tszHttpMethod, _tcslen(lpszMethodPost))) + { //使用重定向? - if (APIHelp_Distributed_IsMode(st_LoadbalanceCfg.st_LoadBalance.pStl_ListUseMode, STORAGE_NETTYPE_HTTPCENTER)) + if (st_LoadbalanceCfg.st_LBDistributed.nCenterMode > 0) { TCHAR tszHdrBuffer[1024]; TCHAR tszStorageAddr[128]; @@ -81,7 +129,7 @@ BOOL XEngine_Task_HttpCenter(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int st_HDRParam.bIsClose = TRUE; st_HDRParam.nHttpCode = 302; - APIHelp_Distributed_RandomAddr(st_LoadbalanceCfg.st_LoadBalance.pStl_ListCenter, tszStorageAddr); + APIHelp_Distributed_RandomAddr(st_LoadbalanceCfg.st_LoadBalance.pStl_ListCenter, tszStorageAddr, st_LoadbalanceCfg.st_LBDistributed.nCenterMode); _stprintf(tszHdrBuffer, _T("Location: %s%s\r\n"), tszStorageAddr, pSt_HTTPParam->tszHttpUri); RfcComponents_HttpServer_SendMsgEx(xhDLHttp, tszSDBuffer, &nSDLen, &st_HDRParam, NULL, 0, tszHdrBuffer); @@ -110,18 +158,6 @@ BOOL XEngine_Task_HttpCenter(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int XEngine_Task_Manage(tszAPIName, lpszClientAddr, lpszMsgBuffer, nMsgLen, pSt_HTTPParam, pptszListHdr, nHdrCount); } } - else if (0 == _tcsnicmp(lpszMethodGet, pSt_HTTPParam->tszHttpMethod, _tcslen(lpszMethodGet))) - { - if (!XEngine_APPHelp_ProxyAuth(lpszClientAddr, lpszMethodGet, pSt_HTTPParam->tszHttpUri, pptszListHdr, nHdrCount, STORAGE_NETTYPE_HTTPCENTER)) - { - return FALSE; - } - if (st_ServiceCfg.st_XProxy.st_XProxyAuth.bAuth) - { - st_HDRParam.bAuth = TRUE; - } - XEngine_Task_P2PGet(pSt_HTTPParam->tszHttpUri + 1, lpszClientAddr, pSt_HTTPParam); - } else if (0 == _tcsnicmp(lpszMethodOption, pSt_HTTPParam->tszHttpMethod, _tcslen(lpszMethodOption))) { //用于心跳 diff --git a/XEngine_Source/XEngine_StorageApp/StorageApp_Download.cpp b/XEngine_Source/XEngine_StorageApp/StorageApp_Download.cpp index 102b81f53ea732a715c7b785fbe91ef23e9f431d..8106562b0ba2b29948d799e4f8a215bcb5dc6148 100644 --- a/XEngine_Source/XEngine_StorageApp/StorageApp_Download.cpp +++ b/XEngine_Source/XEngine_StorageApp/StorageApp_Download.cpp @@ -65,7 +65,7 @@ void CALLBACK XEngine_Download_CBSend(LPCSTR lpszClientAddr, SOCKET hSocket, LPV Session_DLStroage_GetInfo(lpszClientAddr, &st_StorageInfo); - Protocol_StoragePacket_UPDown(st_StorageInfo.tszFileDir, st_StorageInfo.tszClientAddr, st_StorageInfo.ullRWCount, tszProxyStr, &nPLen, st_StorageInfo.tszFileHash); + Protocol_StoragePacket_UPDown(tszProxyStr, &nPLen, st_StorageInfo.tszFileDir, st_StorageInfo.tszBuckKey, st_StorageInfo.tszClientAddr, st_StorageInfo.ullRWCount, TRUE, st_StorageInfo.tszFileHash); if (APIHelp_HttpRequest_Post(st_ServiceCfg.st_XProxy.st_XProxyPass.tszDLPass, tszProxyStr, &nHttpCode)) { XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("下载客户端:%s,请求完成通知返回值:%d,文件:%s,地址:%s"), lpszClientAddr, nHttpCode, st_StorageInfo.tszFileDir, st_ServiceCfg.st_XProxy.st_XProxyPass.tszDLPass); @@ -119,16 +119,65 @@ BOOL XEngine_Task_HttpDownload(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, in XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("下载客户端:%s,发送的方法不支持"), lpszClientAddr); return FALSE; } - if (!XEngine_APPHelp_ProxyAuth(lpszClientAddr, lpszMethodGet, pSt_HTTPParam->tszHttpUri, pptszListHdr, nHdrCount, STORAGE_NETTYPE_HTTPDOWNLOAD)) - { - return FALSE; - } + if (st_ServiceCfg.st_XProxy.st_XProxyAuth.bAuth) { + TCHAR tszUserName[64]; + TCHAR tszUserPass[64]; + + memset(tszUserName, '\0', sizeof(tszUserName)); + memset(tszUserPass, '\0', sizeof(tszUserPass)); + if (!APIHelp_Api_ProxyAuth(tszUserName, tszUserPass, pptszListHdr, nHdrCount)) + { + st_HDRParam.bIsClose = TRUE; + st_HDRParam.bAuth = TRUE; + st_HDRParam.nHttpCode = 401; + + RfcComponents_HttpServer_SendMsgEx(xhDLHttp, tszSDBuffer, &nSDLen, &st_HDRParam); + XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPDOWNLOAD); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("下载客户端:%s,用户验证失败,错误:%lX"), lpszClientAddr, APIHelp_GetLastError()); + return FALSE; + } + if (_tcslen(st_ServiceCfg.st_XProxy.st_XProxyAuth.tszAuthProxy) > 0) + { + int nBLen = 0; + int nResponseCode = 0; + TCHAR* ptszBody = NULL; + + Protocol_StoragePacket_BasicAuth(pSt_HTTPParam->tszHttpMethod, pSt_HTTPParam->tszHttpUri, lpszClientAddr, tszUserName, tszUserPass, tszSDBuffer, &nSDLen); + APIHelp_HttpRequest_Post(st_ServiceCfg.st_XProxy.st_XProxyAuth.tszAuthProxy, tszSDBuffer, &nResponseCode, &ptszBody, &nBLen); + if (200 != nResponseCode) + { + st_HDRParam.bIsClose = TRUE; + st_HDRParam.bAuth = TRUE; + st_HDRParam.nHttpCode = nResponseCode; + + RfcComponents_HttpServer_SendMsgEx(xhDLHttp, tszSDBuffer, &nSDLen, &st_HDRParam); + XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPDOWNLOAD); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("下载客户端:%s,用户验证失败,用户名:%s,密码:%s,错误码:%d,错误内容:%s"), tszUserName, tszUserPass, tszUserPass, nResponseCode, ptszBody); + } + BaseLib_OperatorMemory_FreeCStyle((VOID**)&ptszBody); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("下载客户端:%s,代理服务:%s 验证通过,用户名:%s,密码:%s"), lpszClientAddr, st_ServiceCfg.st_XProxy.st_XProxyAuth.tszAuthProxy, tszUserName, tszUserPass); + } + else + { + if (!Session_User_Exist(tszUserName, tszUserPass)) + { + st_HDRParam.bIsClose = TRUE; + st_HDRParam.bAuth = TRUE; + st_HDRParam.nHttpCode = 401; + + RfcComponents_HttpServer_SendMsgEx(xhDLHttp, tszSDBuffer, &nSDLen, &st_HDRParam); + XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPDOWNLOAD); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("下载客户端:%s,验证用户失败,无法继续"), lpszClientAddr); + return FALSE; + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("下载客户端:%s,本地验证用户验证通过,用户名:%s,密码:%s"), lpszClientAddr, tszUserName, tszUserPass); + } st_HDRParam.bAuth = TRUE; } //使用重定向,这是分布式重定向实现 - if (APIHelp_Distributed_IsMode(st_LoadbalanceCfg.st_LoadBalance.pStl_ListUseMode, STORAGE_NETTYPE_HTTPDOWNLOAD)) + if (st_LoadbalanceCfg.st_LBDistributed.nDownldMode > 0) { TCHAR tszHdrBuffer[1024]; TCHAR tszStorageAddr[128]; @@ -139,7 +188,7 @@ BOOL XEngine_Task_HttpDownload(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, in st_HDRParam.bIsClose = TRUE; st_HDRParam.nHttpCode = 302; - APIHelp_Distributed_RandomAddr(st_LoadbalanceCfg.st_LoadBalance.pStl_ListDownload, tszStorageAddr); + APIHelp_Distributed_RandomAddr(st_LoadbalanceCfg.st_LoadBalance.pStl_ListDownload, tszStorageAddr, st_LoadbalanceCfg.st_LBDistributed.nDownldMode); _stprintf(tszHdrBuffer, _T("Location: %s%s\r\n"), tszStorageAddr, pSt_HTTPParam->tszHttpUri); RfcComponents_HttpServer_SendMsgEx(xhDLHttp, tszSDBuffer, &nSDLen, &st_HDRParam, NULL, 0, tszHdrBuffer); @@ -152,7 +201,7 @@ BOOL XEngine_Task_HttpDownload(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, in int nPosStart = 0; int nPosEnd = 0; __int64x nPosCount = 0; - if (XEngine_APPHelp_RangeFile(lpszClientAddr, &nPosStart, &nPosEnd, &nPosCount, pptszListHdr, nHdrCount, STORAGE_NETTYPE_HTTPDOWNLOAD)) + if (APIHelp_Api_RangeFile(&nPosStart, &nPosEnd, &nPosCount, pptszListHdr, nHdrCount)) { //是否启用了断点续传 if (st_ServiceCfg.st_XStorage.bResumable) @@ -165,13 +214,14 @@ BOOL XEngine_Task_HttpDownload(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, in nPosStart = 0; nPosEnd = 0; } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("下载客户端:%s,客户端的请求设置了数据范围:%d - %d/%lld"), lpszClientAddr, nPosStart, nPosEnd, nPosCount); } XENGINE_STORAGEBUCKET st_StorageBucket; memset(&st_StorageBucket, '\0', sizeof(XENGINE_STORAGEBUCKET)); //分布式存储 if (!APIHelp_Distributed_DLStorage(pSt_HTTPParam->tszHttpUri, st_LoadbalanceCfg.st_LoadBalance.pStl_ListBucket, &st_StorageBucket)) { - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("下载客户端:%s,请求文件失败,可能BUCKET:% 不正确,错误:%lX"), lpszClientAddr, pSt_HTTPParam->tszHttpUri, APIHelp_GetLastError()); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("下载客户端:%s,请求文件失败,可能BUCKET:%s 不正确,错误:%lX"), lpszClientAddr, pSt_HTTPParam->tszHttpUri, APIHelp_GetLastError()); return FALSE; } _stprintf(tszFileDir, _T("%s%s"), st_StorageBucket.tszFilePath, st_StorageBucket.tszFileName); @@ -188,7 +238,7 @@ BOOL XEngine_Task_HttpDownload(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, in BaseLib_OperatorString_StrToHex((char*)tszHashKey, nHashLen, tszHashStr); BaseLib_OperatorString_GetFileAndPath(tszFileDir, NULL, NULL, NULL, st_HDRParam.tszMimeType); //插入数据 - if (!Session_DLStroage_Insert(lpszClientAddr, tszFileDir, &ullCount, &ullSize, nPosStart, nPosEnd, tszHashStr)) + if (!Session_DLStroage_Insert(lpszClientAddr, st_StorageBucket.tszBuckKey, tszFileDir, &ullCount, &ullSize, nPosStart, nPosEnd, tszHashStr)) { st_HDRParam.bIsClose = TRUE; st_HDRParam.nHttpCode = 404; diff --git a/XEngine_Source/XEngine_StorageApp/StorageApp_Hdr.h b/XEngine_Source/XEngine_StorageApp/StorageApp_Hdr.h index 51aafc26715e8332aca72ead67d2f225b80397a5..560b6ea3705b5181a57cf0559aeb93319c9a5521 100644 --- a/XEngine_Source/XEngine_StorageApp/StorageApp_Hdr.h +++ b/XEngine_Source/XEngine_StorageApp/StorageApp_Hdr.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -112,7 +113,6 @@ extern XENGINE_LBCONFIG st_LoadbalanceCfg; #include "Storage_APPTask/Storage_TaskPass.h" #include "Storage_APPTask/Storage_TaskP2p.h" #include "Storage_APPTask/Storage_TaskManage.h" -#include "Storage_APPHelp/Storage_APPHelp.h" #ifdef _WINDOWS #pragma comment(lib,"Ws2_32.lib") diff --git a/XEngine_Source/XEngine_StorageApp/StorageApp_P2XPNet.cpp b/XEngine_Source/XEngine_StorageApp/StorageApp_P2XPNet.cpp index 76ee2173f67698aad7a48f58e97596e7deae943a..1f2d6b5609503eed40ef943699851372a27dadc6 100644 --- a/XEngine_Source/XEngine_StorageApp/StorageApp_P2XPNet.cpp +++ b/XEngine_Source/XEngine_StorageApp/StorageApp_P2XPNet.cpp @@ -220,15 +220,17 @@ BOOL XEngine_Task_TCPP2xp(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, LPCTSTR lpszClie { TCHAR tszTimeStart[MAX_PATH]; TCHAR tszTimeEnd[MAX_PATH]; + TCHAR tszBuckKey[MAX_PATH]; TCHAR tszFileName[MAX_PATH]; TCHAR tszFileHash[MAX_PATH]; memset(tszTimeStart, '\0', MAX_PATH); memset(tszTimeEnd, '\0', MAX_PATH); + memset(tszBuckKey, '\0', MAX_PATH); memset(tszFileName, '\0', MAX_PATH); memset(tszFileHash, '\0', MAX_PATH); //用于验证协议是否正确 - if (!Protocol_StorageParse_QueryFile(lpszMsgBuffer, tszTimeStart, tszTimeEnd, tszFileName, tszFileHash)) + if (!Protocol_StorageParse_QueryFile(lpszMsgBuffer, tszTimeStart, tszTimeEnd, tszBuckKey, tszFileName, tszFileHash)) { Protocol_P2XPPacket_Common(pSt_ProtocolHdr, tszSDBuffer, &nSDLen, 400, "协议错误"); XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_TCPP2XP); @@ -254,7 +256,7 @@ BOOL XEngine_Task_TCPP2xp(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, LPCTSTR lpszClie XEngine_Net_SendMsg(pppszP2XPClient[i], (LPCTSTR)pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR), STORAGE_NETTYPE_TCPP2XP); XEngine_Net_SendMsg(pppszP2XPClient[i], lpszMsgBuffer, nMsgLen, STORAGE_NETTYPE_TCPP2XP); } - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("客户端:%s,请求查询文件:%s,用户个数:%d"), lpszClientAddr, tszFileName, tszFileHash, nListCount--); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("客户端:%s,请求查询Buck:%s 中的文件名:%s,HASH:%s,用户个数:%d"), lpszClientAddr, tszBuckKey, tszFileName, tszFileHash, nListCount); BaseLib_OperatorMemory_Free((XPPPMEM)&pppszP2XPClient, nListCount); } else diff --git a/XEngine_Source/XEngine_StorageApp/StorageApp_UPLoader.cpp b/XEngine_Source/XEngine_StorageApp/StorageApp_UPLoader.cpp index aafd1974cd6e753cd39904ff017e2339e0fc6bcd..086ebbb8a002a0ace485604b891691bc3b1319e7 100644 --- a/XEngine_Source/XEngine_StorageApp/StorageApp_UPLoader.cpp +++ b/XEngine_Source/XEngine_StorageApp/StorageApp_UPLoader.cpp @@ -50,9 +50,9 @@ BOOL XEngine_Task_HttpUPLoader(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, in memset(tszFileDir, '\0', sizeof(tszFileDir)); memset(&st_HDRParam, '\0', sizeof(RFCCOMPONENTS_HTTP_HDRPARAM)); - LPCTSTR lpszMethodGet = _T("PUT"); - - if (0 != _tcsncmp(lpszMethodGet, pSt_HTTPParam->tszHttpMethod, _tcslen(lpszMethodGet))) + LPCTSTR lpszMethodPut = _T("PUT"); + LPCTSTR lpszMethodPost = _T("POST"); + if ((0 != _tcsncmp(lpszMethodPut, pSt_HTTPParam->tszHttpMethod, _tcslen(lpszMethodPut))) && (0 != _tcsncmp(lpszMethodPost, pSt_HTTPParam->tszHttpMethod, _tcslen(lpszMethodPost)))) { st_HDRParam.bIsClose = TRUE; st_HDRParam.nHttpCode = 405; @@ -62,16 +62,65 @@ BOOL XEngine_Task_HttpUPLoader(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, in XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("上传客户端:%s,发送的方法:%s 不支持"), lpszClientAddr, pSt_HTTPParam->tszHttpMethod); return FALSE; } - if (!XEngine_APPHelp_ProxyAuth(lpszClientAddr, lpszMethodGet, pSt_HTTPParam->tszHttpUri, pptszListHdr, nHdrCount, STORAGE_NETTYPE_HTTPUPLOADER)) - { - return FALSE; - } + //用户验证 if (st_ServiceCfg.st_XProxy.st_XProxyAuth.bAuth) { + TCHAR tszUserName[64]; + TCHAR tszUserPass[64]; + + memset(tszUserName, '\0', sizeof(tszUserName)); + memset(tszUserPass, '\0', sizeof(tszUserPass)); + if (!APIHelp_Api_ProxyAuth(tszUserName, tszUserPass, pptszListHdr, nHdrCount)) + { + st_HDRParam.bIsClose = TRUE; + st_HDRParam.bAuth = TRUE; + st_HDRParam.nHttpCode = 401; + + RfcComponents_HttpServer_SendMsgEx(xhUPHttp, tszSDBuffer, &nSDLen, &st_HDRParam); + XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPUPLOADER); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("上传客户端:%s,用户验证失败,错误:%lX"), lpszClientAddr, APIHelp_GetLastError()); + return FALSE; + } + if (_tcslen(st_ServiceCfg.st_XProxy.st_XProxyAuth.tszAuthProxy) > 0) + { + int nBLen = 0; + int nResponseCode = 0; + TCHAR* ptszBody = NULL; + + Protocol_StoragePacket_BasicAuth(pSt_HTTPParam->tszHttpMethod, pSt_HTTPParam->tszHttpUri, lpszClientAddr, tszUserName, tszUserPass, tszSDBuffer, &nSDLen); + APIHelp_HttpRequest_Post(st_ServiceCfg.st_XProxy.st_XProxyAuth.tszAuthProxy, tszSDBuffer, &nResponseCode, &ptszBody, &nBLen); + if (200 != nResponseCode) + { + st_HDRParam.bIsClose = TRUE; + st_HDRParam.bAuth = TRUE; + st_HDRParam.nHttpCode = nResponseCode; + + RfcComponents_HttpServer_SendMsgEx(xhUPHttp, tszSDBuffer, &nSDLen, &st_HDRParam); + XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPUPLOADER); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("上传客户端:%s,用户验证失败,用户名:%s,密码:%s,错误码:%d,错误内容:%s"), tszUserName, tszUserPass, tszUserPass, nResponseCode, ptszBody); + } + BaseLib_OperatorMemory_FreeCStyle((VOID**)&ptszBody); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("上传客户端:%s,代理服务:%s 验证通过,用户名:%s,密码:%s"), lpszClientAddr, st_ServiceCfg.st_XProxy.st_XProxyAuth.tszAuthProxy, tszUserName, tszUserPass); + } + else + { + if (!Session_User_Exist(tszUserName, tszUserPass)) + { + st_HDRParam.bIsClose = TRUE; + st_HDRParam.bAuth = TRUE; + st_HDRParam.nHttpCode = 401; + + RfcComponents_HttpServer_SendMsgEx(xhUPHttp, tszSDBuffer, &nSDLen, &st_HDRParam); + XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPUPLOADER); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("上传客户端:%s,验证用户失败,无法继续"), lpszClientAddr); + return FALSE; + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("上传客户端:%s,本地验证用户验证通过,用户名:%s,密码:%s"), lpszClientAddr, tszUserName, tszUserPass); + } st_HDRParam.bAuth = TRUE; } //使用重定向? - if (APIHelp_Distributed_IsMode(st_LoadbalanceCfg.st_LoadBalance.pStl_ListUseMode, STORAGE_NETTYPE_HTTPUPLOADER)) + if (st_LoadbalanceCfg.st_LBDistributed.nUPLoadMode > 0) { TCHAR tszHdrBuffer[1024]; TCHAR tszStorageAddr[128]; @@ -82,7 +131,7 @@ BOOL XEngine_Task_HttpUPLoader(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, in st_HDRParam.bIsClose = TRUE; st_HDRParam.nHttpCode = 302; - APIHelp_Distributed_RandomAddr(st_LoadbalanceCfg.st_LoadBalance.pStl_ListUPLoader, tszStorageAddr); + APIHelp_Distributed_RandomAddr(st_LoadbalanceCfg.st_LoadBalance.pStl_ListUPLoader, tszStorageAddr, st_LoadbalanceCfg.st_LBDistributed.nUPLoadMode); _stprintf(tszHdrBuffer, _T("Location: %s%s\r\n"), tszStorageAddr, pSt_HTTPParam->tszHttpUri); RfcComponents_HttpServer_SendMsgEx(xhDLHttp, tszSDBuffer, &nSDLen, &st_HDRParam, NULL, 0, tszHdrBuffer); @@ -97,7 +146,7 @@ BOOL XEngine_Task_HttpUPLoader(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, in XENGINE_STORAGEBUCKET st_StorageBucket; memset(&st_StorageBucket, '\0', sizeof(XENGINE_STORAGEBUCKET)); - if (!APIHelp_Distributed_UPStorage(st_LoadbalanceCfg.st_LoadBalance.pStl_ListBucket, &st_StorageBucket)) + if (!APIHelp_Distributed_UPStorage(pSt_HTTPParam->tszHttpUri, st_LoadbalanceCfg.st_LoadBalance.pStl_ListBucket, &st_StorageBucket, st_LoadbalanceCfg.st_LBLocation.nUPLoadMode)) { XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("上传客户端:%s,请求上传文件失败,可能BUCKET:% 不正确,错误:%lX"), lpszClientAddr, pSt_HTTPParam->tszHttpUri, APIHelp_GetLastError()); return FALSE; @@ -109,27 +158,32 @@ BOOL XEngine_Task_HttpUPLoader(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, in int nPosStart = 0; int nPosEnd = 0; __int64x nPosCount = 0; - //得到长度大小 - if (XEngine_APPHelp_RangeFile(lpszClientAddr, &nPosStart, &nPosEnd, &nPosCount, pptszListHdr, nHdrCount, STORAGE_NETTYPE_HTTPUPLOADER)) + //得到断点续传大小 + if (!APIHelp_Api_RangeFile(&nPosStart, &nPosEnd, &nPosCount, pptszListHdr, nHdrCount)) + { + st_HDRParam.bIsClose = TRUE; + st_HDRParam.nHttpCode = 411; + RfcComponents_HttpServer_SendMsgEx(xhUPHttp, tszSDBuffer, &nSDLen, &st_HDRParam); + XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPUPLOADER); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("上传客户端:%s,没有用户数据大小字段,无法继续"), lpszClientAddr); + return FALSE; + } + //是新的还是断点续传的 + if ((0 != nPosStart) || (0 != nPosEnd)) { - //是新的还是断点续传的 - if ((0 != nPosStart) || (0 != nPosEnd)) + //是否启用了断点续传 + if (!st_ServiceCfg.st_XStorage.bResumable) { - //是否启用了断点续传 - if (!st_ServiceCfg.st_XStorage.bResumable) - { - st_HDRParam.bIsClose = TRUE; - st_HDRParam.nHttpCode = 416; + st_HDRParam.bIsClose = TRUE; + st_HDRParam.nHttpCode = 416; - RfcComponents_HttpServer_SendMsgEx(xhUPHttp, tszSDBuffer, &nSDLen, &st_HDRParam); - XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPUPLOADER); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("上传客户端:%s,请求断点续传上传文件失败,服务端关闭了此功能,文件:%s,错误:%lX"), lpszClientAddr, tszFileDir, Session_GetLastError()); - return FALSE; - } + RfcComponents_HttpServer_SendMsgEx(xhUPHttp, tszSDBuffer, &nSDLen, &st_HDRParam); + XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPUPLOADER); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("上传客户端:%s,请求断点续传上传文件失败,服务端关闭了此功能,文件:%s,错误:%lX"), lpszClientAddr, tszFileDir, Session_GetLastError()); + return FALSE; } } - RfcComponents_HttpServer_GetRecvModeEx(xhUPHttp, lpszClientAddr, &nRVMode, &nRVCount, &nHDSize); - if (!Session_UPStroage_Insert(lpszClientAddr, tszFileDir, nPosCount, nRVCount, nPosStart, nPosEnd)) + if (!Session_UPStroage_Insert(lpszClientAddr, st_StorageBucket.tszBuckKey, tszFileDir, nPosCount, nRVCount, nPosStart, nPosEnd)) { st_HDRParam.bIsClose = TRUE; st_HDRParam.nHttpCode = 404; @@ -139,21 +193,17 @@ BOOL XEngine_Task_HttpUPLoader(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, in XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("上传客户端:%s,插入用户请求失败,文件:%s,错误:%lX"), lpszClientAddr, tszFileDir, Session_GetLastError()); return FALSE; } - } - if (nMsgLen <= 0) - { - st_HDRParam.bIsClose = TRUE; - st_HDRParam.nHttpCode = 411; - RfcComponents_HttpServer_SendMsgEx(xhUPHttp, tszSDBuffer, &nSDLen, &st_HDRParam); - XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPUPLOADER); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("上传客户端:%s,用户数据大小为0?"), lpszClientAddr); - return FALSE; + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("上传客户端:%s,请求设置了数据范围:%d - %d/%lld"), lpszClientAddr, nPosStart, nPosEnd, nPosCount); } Session_UPStroage_Write(lpszClientAddr, lpszMsgBuffer, nMsgLen); RfcComponents_HttpServer_GetRecvModeEx(xhUPHttp, lpszClientAddr, &nRVMode, &nRVCount, &nHDSize); if (nHDSize >= nRVCount) { + int nPLen = MAX_PATH; + TCHAR tszPassNotify[MAX_PATH]; SESSION_STORAGEINFO st_StorageInfo; + + memset(tszPassNotify, '\0', MAX_PATH); memset(&st_StorageInfo, '\0', sizeof(SESSION_STORAGEINFO)); Session_UPStroage_Close(lpszClientAddr); @@ -177,20 +227,32 @@ BOOL XEngine_Task_HttpUPLoader(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, in _tcscpy(st_ProtocolFile.st_ProtocolFile.tszFilePath, st_StorageBucket.tszFilePath); _tcscpy(st_ProtocolFile.st_ProtocolFile.tszFileName, pSt_HTTPParam->tszHttpUri + 1); - st_ProtocolFile.st_ProtocolFile.nFileSize = nRVCount; + st_ProtocolFile.st_ProtocolFile.nFileSize = st_StorageInfo.ullFSize; OPenSsl_Api_Digest(tszFileDir, tszHashStr, &nHashLen, TRUE, st_ServiceCfg.st_XStorage.nHashMode); BaseLib_OperatorString_StrToHex((char*)tszHashStr, nHashLen, st_ProtocolFile.st_ProtocolFile.tszFileHash); //处理结果 - if (!XEngine_APPHelp_VerHash(lpszClientAddr, tszFileDir, st_ProtocolFile.st_ProtocolFile.tszFileHash, pptszListHdr, nHdrCount)) + if (st_ServiceCfg.st_XStorage.bUPHash) { - st_HDRParam.bIsClose = TRUE; - st_HDRParam.nHttpCode = 403; - RfcComponents_HttpServer_SendMsgEx(xhUPHttp, tszSDBuffer, &nSDLen, &st_HDRParam); - XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPUPLOADER); - return FALSE; + if (APIHelp_Api_VerHash(st_ProtocolFile.st_ProtocolFile.tszFileHash, pptszListHdr, nHdrCount)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("上传客户端:%s,上传的文件信息HASH效验成功,文件:%s HASH:%s"), lpszClientAddr, tszFileDir, st_ProtocolFile.st_ProtocolFile.tszFileHash); + } + else + { + st_HDRParam.bIsClose = TRUE; + st_HDRParam.nHttpCode = 403; + _tremove(tszFileDir); + RfcComponents_HttpServer_SendMsgEx(xhUPHttp, tszSDBuffer, &nSDLen, &st_HDRParam); + XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPUPLOADER); + + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("上传客户端:%s,上传的文件信息HASH校验失败,无法继续,文件:%s 已被删除,HASH:%s,错误:%lX"), lpszClientAddr, tszFileDir, st_ProtocolFile.st_ProtocolFile.tszFileHash, APIHelp_GetLastError()); + return FALSE; + } } + BOOL bRet = TRUE; + Protocol_StoragePacket_UPDown(tszPassNotify, &nPLen, st_StorageInfo.tszBuckKey, st_StorageInfo.tszFileDir, st_StorageInfo.tszClientAddr, st_StorageInfo.ullRWCount, FALSE, st_ProtocolFile.st_ProtocolFile.tszFileHash); if (0 != st_ServiceCfg.st_XSql.nSQLType) { _tcscpy(st_ProtocolFile.tszBuckKey, st_StorageBucket.tszBuckKey); @@ -206,7 +268,7 @@ BOOL XEngine_Task_HttpUPLoader(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, in { st_HDRParam.bIsClose = TRUE; st_HDRParam.nHttpCode = 200; - RfcComponents_HttpServer_SendMsgEx(xhUPHttp, tszSDBuffer, &nSDLen, &st_HDRParam); + RfcComponents_HttpServer_SendMsgEx(xhUPHttp, tszSDBuffer, &nSDLen, &st_HDRParam, tszPassNotify, nPLen); XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPUPLOADER); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("上传客户端:%s,请求上传文件成功,文件名:%s,大小:%d"), lpszClientAddr, tszFileDir, nRVCount); } @@ -214,7 +276,7 @@ BOOL XEngine_Task_HttpUPLoader(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, in { st_HDRParam.bIsClose = TRUE; st_HDRParam.nHttpCode = 403; - RfcComponents_HttpServer_SendMsgEx(xhUPHttp, tszSDBuffer, &nSDLen, &st_HDRParam); + RfcComponents_HttpServer_SendMsgEx(xhUPHttp, tszSDBuffer, &nSDLen, &st_HDRParam, tszPassNotify, nPLen); XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPUPLOADER); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("上传客户端:%s,请求上传文件失败,插入数据库失败:%s,错误:%lX"), lpszClientAddr, tszFileDir, XStorageDB_GetLastError()); } @@ -223,24 +285,15 @@ BOOL XEngine_Task_HttpUPLoader(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, in { st_HDRParam.bIsClose = TRUE; st_HDRParam.nHttpCode = 200; - RfcComponents_HttpServer_SendMsgEx(xhUPHttp, tszSDBuffer, &nSDLen, &st_HDRParam); + RfcComponents_HttpServer_SendMsgEx(xhUPHttp, tszSDBuffer, &nSDLen, &st_HDRParam, tszPassNotify, nPLen); XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPUPLOADER); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _T("上传客户端:%s,请求上传文件成功,文件名:%s,大小:%d,数据库没有启用,不插入数据库"), lpszClientAddr, tszFileDir, nRVCount); } //PASS代理 if (st_ServiceCfg.st_XProxy.st_XProxyPass.bUPPass && bRet) { - int nPLen = MAX_PATH; int nHttpCode = 0; - TCHAR tszProxyStr[MAX_PATH]; - SESSION_STORAGEINFO st_StorageInfo; - - memset(tszProxyStr, '\0', MAX_PATH); - memset(&st_StorageInfo, '\0', sizeof(SESSION_STORAGEINFO)); - - Session_UPStroage_GetInfo(lpszClientAddr, &st_StorageInfo); - Protocol_StoragePacket_UPDown(st_StorageInfo.tszFileDir, st_StorageInfo.tszClientAddr, st_StorageInfo.ullRWCount, tszProxyStr, &nPLen, st_ProtocolFile.st_ProtocolFile.tszFileHash); - if (APIHelp_HttpRequest_Post(st_ServiceCfg.st_XProxy.st_XProxyPass.tszUPPass, tszProxyStr, &nHttpCode)) + if (APIHelp_HttpRequest_Post(st_ServiceCfg.st_XProxy.st_XProxyPass.tszUPPass, tszPassNotify, &nHttpCode)) { XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("上传客户端:%s,请求完成通知返回值:%d,文件:%s,地址:%s"), lpszClientAddr, nHttpCode, st_StorageInfo.tszFileDir, st_ServiceCfg.st_XProxy.st_XProxyPass.tszUPPass); } diff --git a/XEngine_Source/XEngine_StorageApp/Storage_APPHelp/Storage_APPHelp.cpp b/XEngine_Source/XEngine_StorageApp/Storage_APPHelp/Storage_APPHelp.cpp deleted file mode 100644 index 55bab52291adac4cf29bc87a2cf87d4582d5f3c7..0000000000000000000000000000000000000000 --- a/XEngine_Source/XEngine_StorageApp/Storage_APPHelp/Storage_APPHelp.cpp +++ /dev/null @@ -1,211 +0,0 @@ -#include "../StorageApp_Hdr.h" - -BOOL XEngine_APPHelp_ProxyAuth(LPCTSTR lpszClientAddr, LPCTSTR lpszMethod, LPCTSTR lpszPostUrl, TCHAR** pptszListHdr, int nHdrCount, int nSDType) -{ - int nSDLen = 1024; - int nAuthType = 0; - int nAuthLen = MAX_PATH; - LPCTSTR lpszClientType; - TCHAR tszAuthStr[MAX_PATH]; - TCHAR tszSDBuffer[1024]; - RFCCOMPONENTS_HTTP_HDRPARAM st_HDRParam; - - memset(tszAuthStr, '\0', MAX_PATH); - memset(tszSDBuffer, '\0', sizeof(tszSDBuffer)); - memset(&st_HDRParam, '\0', sizeof(RFCCOMPONENTS_HTTP_HDRPARAM)); - - if (!st_ServiceCfg.st_XProxy.st_XProxyAuth.bAuth) - { - return TRUE; - } - - if (STORAGE_NETTYPE_HTTPDOWNLOAD == nSDType) - { - lpszClientType = _T("下载客户端"); - } - else if (STORAGE_NETTYPE_HTTPUPLOADER == nSDType) - { - lpszClientType = _T("上传客户端"); - } - else - { - lpszClientType = _T("业务客户端"); - } - - if (!RfcComponents_HttpHelp_GetAuthInfo(&pptszListHdr, nHdrCount, tszAuthStr, &nAuthLen, &nAuthType)) - { - st_HDRParam.bIsClose = TRUE; - st_HDRParam.bAuth = TRUE; - st_HDRParam.nHttpCode = 402; - - RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam); - XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, nSDType); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("%s:%s,没有验证信息,无法继续"), lpszClientType, lpszClientAddr); - return FALSE; - } - - if (1 == nAuthType) - { - TCHAR tszUserName[64]; - TCHAR tszUserPass[64]; - - memset(tszUserName, '\0', sizeof(tszUserName)); - memset(tszUserPass, '\0', sizeof(tszUserPass)); - - OPenSsl_Help_BasicDecoder(tszAuthStr, tszUserName, tszUserPass); - if (_tcslen(st_ServiceCfg.st_XProxy.st_XProxyAuth.tszAuthProxy) > 0) - { - int nBLen = 0; - int nResponseCode = 0; - TCHAR* ptszBody = NULL; - - Protocol_StoragePacket_BasicAuth(lpszMethod, lpszPostUrl, lpszClientAddr, tszUserName, tszUserPass, tszSDBuffer, &nSDLen); - APIHelp_HttpRequest_Post(st_ServiceCfg.st_XProxy.st_XProxyAuth.tszAuthProxy, tszSDBuffer, &nResponseCode, &ptszBody, &nBLen); - if (200 == nResponseCode) - { - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("%s:%s,代理服务:%s 验证通过,用户名:%s,密码:%s"), lpszClientType, lpszClientAddr, st_ServiceCfg.st_XProxy.st_XProxyAuth.tszAuthProxy, tszUserName, tszUserPass); - } - else - { - st_HDRParam.bIsClose = TRUE; - st_HDRParam.bAuth = TRUE; - st_HDRParam.nHttpCode = nResponseCode; - - RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam); - XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, nSDType); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("%s:%s,用户验证失败,用户名:%s,密码:%s,错误码:%d,错误内容:%s"), lpszClientType, lpszClientAddr, tszUserPass, tszUserPass, nResponseCode, ptszBody); - } - BaseLib_OperatorMemory_FreeCStyle((VOID**)&ptszBody); - } - else - { - if (!Session_User_Exist(tszUserName, tszUserPass)) - { - st_HDRParam.bIsClose = TRUE; - st_HDRParam.bAuth = TRUE; - st_HDRParam.nHttpCode = 402; - - RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam); - XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, nSDType); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("%s:%s,验证用户失败,无法继续"), lpszClientType, lpszClientAddr); - return FALSE; - } - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("%s:%s,本地验证用户验证通过,用户名:%s,密码:%s"), lpszClientType, lpszClientAddr, tszUserName, tszUserPass); - } - } - else - { - st_HDRParam.bIsClose = TRUE; - st_HDRParam.bAuth = TRUE; - st_HDRParam.nHttpCode = 402; - - RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam); - XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, nSDType); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("%s:%s,没有验证信息,无法继续"), lpszClientType, lpszClientAddr); - return FALSE; - } - return TRUE; -} -BOOL XEngine_APPHelp_RangeFile(LPCTSTR lpszClientAddr, int* pInt_SPos, int* pInt_EPos, __int64x* pInt_Count, TCHAR** pptszListHdr, int nHdrCount, int nSDType) -{ - LPCTSTR lpszRangeStr = _T("Range"); - LPCTSTR lpszLengthStr = _T("Content-Length"); - LPCTSTR lpszClientType; - TCHAR tszKeyStr[128]; - TCHAR tszValueStr[128]; - TCHAR tszFieldStr[128]; - - memset(tszKeyStr, '\0', sizeof(tszKeyStr)); - memset(tszValueStr, '\0', sizeof(tszValueStr)); - memset(tszFieldStr, '\0', sizeof(tszFieldStr)); - - if (STORAGE_NETTYPE_HTTPDOWNLOAD == nSDType) - { - lpszClientType = _T("下载客户端"); - } - else if (STORAGE_NETTYPE_HTTPUPLOADER == nSDType) - { - lpszClientType = _T("上传客户端"); - } - else - { - lpszClientType = _T("业务客户端"); - } - //是否有范围 - if (RfcComponents_HttpHelp_GetField(&pptszListHdr, nHdrCount, lpszRangeStr, tszFieldStr)) - { - //是否没有找到 - int nBPos = 0; //某些时候有个BYTE - if (NULL != _tcsstr(tszFieldStr, _T("bytes="))) - { - nBPos = 6; - } - if (!BaseLib_OperatorString_GetKeyValue(tszFieldStr + nBPos, "-", tszKeyStr, tszValueStr)) - { - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("%s:%s,请求内容有范围信息,但是解析失败,内容:%s"), lpszClientType, lpszClientAddr, tszFieldStr); - return FALSE; - } - //得到 1/2 如果有的话 - TCHAR tszRangeEnd[128]; - TCHAR tszRangeCount[128]; - - memset(tszRangeEnd, '\0', sizeof(tszRangeEnd)); - memset(tszRangeCount, '\0', sizeof(tszRangeCount)); - if (BaseLib_OperatorString_GetKeyValue(tszValueStr, "/", tszRangeEnd, tszRangeCount)) - { - *pInt_SPos = _ttoi(tszKeyStr); - *pInt_EPos = _ttoi(tszRangeEnd); - *pInt_Count = _ttoi64(tszRangeCount); - } - else - { - *pInt_SPos = _ttoi(tszKeyStr); - *pInt_EPos = _ttoi(tszValueStr); - } - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("%s:%s,客户端的请求设置了数据范围:%d - %d/%lld"), lpszClientType, lpszClientAddr, *pInt_SPos, *pInt_EPos, *pInt_Count); - } - else - { - if (STORAGE_NETTYPE_HTTPDOWNLOAD == nSDType) - { - return FALSE; - } - if (!RfcComponents_HttpHelp_GetField(&pptszListHdr, nHdrCount, lpszLengthStr, tszFieldStr)) - { - return FALSE; - } - *pInt_Count = _ttoi64(tszFieldStr); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("%s:%s,请求内容是新的数据,大小:%lld"), lpszClientType, lpszClientAddr, *pInt_Count); - } - return TRUE; -} -BOOL XEngine_APPHelp_VerHash(LPCTSTR lpszClientAddr, LPCTSTR lpszFileName, LPCTSTR lpszFileHash, TCHAR** pptszListHdr, int nHdrCount) -{ - if (st_ServiceCfg.st_XStorage.bUPHash) - { - LPCTSTR lpszKeyStr = _T("FileHash"); - TCHAR tszValueStr[MAX_PATH]; - memset(tszValueStr, '\0', MAX_PATH); - - if (RfcComponents_HttpHelp_GetField(&pptszListHdr, nHdrCount, lpszKeyStr, tszValueStr)) - { - if (0 == _tcsnicmp(lpszFileHash, tszValueStr, _tcslen(lpszFileHash))) - { - _tremove(lpszFileName); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("上传客户端:%s,上传的文件信息HASH效验成功,文件:%s 原始HASH:%s,计算HASH:%s"), lpszClientAddr, lpszFileName, tszValueStr, lpszFileHash); - } - else - { - _tremove(lpszFileName); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("上传客户端:%s,上传的文件信息HASH校验失败,无法继续,文件:%s 已被删除,原始HASH:%s,计算HASH:%s"), lpszClientAddr, lpszFileName, tszValueStr, lpszFileHash); - return FALSE; - } - } - else - { - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("上传客户端:%s,上传的信息没有附带HASH值,无法验证文件的正确性"), lpszClientAddr); - return FALSE; - } - } - return TRUE; -} \ No newline at end of file diff --git a/XEngine_Source/XEngine_StorageApp/Storage_APPHelp/Storage_APPHelp.h b/XEngine_Source/XEngine_StorageApp/Storage_APPHelp/Storage_APPHelp.h deleted file mode 100644 index 68475e3a5e8304704e2b8bc665f9a68883fb15ec..0000000000000000000000000000000000000000 --- a/XEngine_Source/XEngine_StorageApp/Storage_APPHelp/Storage_APPHelp.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -BOOL XEngine_APPHelp_ProxyAuth(LPCTSTR lpszClientAddr, LPCTSTR lpszMethod, LPCTSTR lpszPostUrl, TCHAR** pptszListHdr, int nHdrCount, int nSDType = STORAGE_NETTYPE_HTTPDOWNLOAD); -BOOL XEngine_APPHelp_RangeFile(LPCTSTR lpszClientAddr, int* pInt_SPos, int* pInt_EPos, __int64x* pInt_Count, TCHAR** pptszListHdr, int nHdrCount, int nSDType = STORAGE_NETTYPE_HTTPDOWNLOAD); -BOOL XEngine_APPHelp_VerHash(LPCTSTR lpszClientAddr, LPCTSTR lpszFileName, LPCTSTR lpszFileHash, TCHAR** pptszListHdr, int nHdrCount); \ No newline at end of file diff --git a/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskManage.cpp b/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskManage.cpp index c2151338812f8624d4f37eeeaf9c31d12e28b51e..e108fe1375ddfbcb6caba3fcceec7251b2d8f986 100644 --- a/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskManage.cpp +++ b/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskManage.cpp @@ -2,10 +2,10 @@ BOOL XEngine_Task_Manage(LPCTSTR lpszAPIName, LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMsgLen, RFCCOMPONENTS_HTTP_REQPARAM* pSt_HTTPParam, TCHAR** pptszListHdr, int nHdrCount) { - int nSDLen = 2048; - int nRVLen = 2048; - TCHAR tszSDBuffer[2048]; - TCHAR tszRVBuffer[2048]; + int nSDLen = 10240; + int nRVLen = 10240; + TCHAR tszSDBuffer[10240]; + TCHAR tszRVBuffer[10240]; RFCCOMPONENTS_HTTP_HDRPARAM st_HDRParam; memset(tszSDBuffer, '\0', sizeof(tszSDBuffer)); @@ -21,7 +21,55 @@ BOOL XEngine_Task_Manage(LPCTSTR lpszAPIName, LPCTSTR lpszClientAddr, LPCTSTR lp XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("业务客户端:%s,处理用户重载配置文件成功"), lpszClientAddr); } - else if (0 == _tcsnicmp(XENGINE_STORAGE_APP_METHOD_ADD, lpszAPIName, _tcslen(XENGINE_STORAGE_APP_METHOD_ADD))) + else if (0 == _tcsnicmp(XENGINE_STORAGE_APP_METHOD_QUERY, lpszAPIName, _tcslen(XENGINE_STORAGE_APP_METHOD_QUERY))) + { + //查询文件列表 + int nMsgLen = 10240; + TCHAR tszFileName[MAX_PATH]; + TCHAR tszFileHash[MAX_PATH]; + TCHAR tszBucketKey[128]; + TCHAR tszTimeStart[128]; + TCHAR tszTimeEnd[128]; + TCHAR tszMsgBuffer[10240]; + + memset(tszFileName, '\0', MAX_PATH); + memset(tszFileHash, '\0', MAX_PATH); + memset(tszBucketKey, '\0', sizeof(tszBucketKey)); + memset(tszTimeStart, '\0', sizeof(tszTimeStart)); + memset(tszTimeEnd, '\0', sizeof(tszTimeEnd)); + memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer)); + + int nListCount = 0; + XSTORAGECORE_DBFILE** ppSt_ListFile; + Protocol_StorageParse_QueryFile(lpszMsgBuffer, tszTimeStart, tszTimeEnd, tszBucketKey, tszFileName, tszFileHash); + if (0 == st_ServiceCfg.st_XSql.nSQLType) + { + st_HDRParam.bIsClose = TRUE; + st_HDRParam.nHttpCode = 406; + + RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam); + XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _T("业务客户端:%s,请求查询文件列表失败,服务器没有启用这个功能"), lpszClientAddr); + } + else + { + if (1 == st_ServiceCfg.st_XSql.nSQLType) + { + XStorage_MySql_FileQuery(&ppSt_ListFile, &nListCount, tszTimeStart, tszTimeEnd, tszBucketKey, tszFileName, tszFileHash); + } + else + { + XStorage_SQLite_FileQuery(&ppSt_ListFile, &nListCount, tszTimeStart, tszTimeEnd, tszBucketKey, tszFileName, tszFileHash); + } + + Protocol_StoragePacket_QueryFile(tszMsgBuffer, &nMsgLen, &ppSt_ListFile, nListCount, tszTimeStart, tszTimeEnd); + RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam, tszMsgBuffer, nMsgLen); + XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER); + BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_ListFile, nListCount); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("业务客户端:%s,请求查询文件列表成功,列表个数:%d"), lpszClientAddr, nListCount); + } + } + else if (0 == _tcsnicmp(XENGINE_STORAGE_APP_METHOD_INSERT, lpszAPIName, _tcslen(XENGINE_STORAGE_APP_METHOD_INSERT))) { int nListCount = 0; XSTORAGECORE_DBFILE** ppSt_DBFile; @@ -29,44 +77,39 @@ BOOL XEngine_Task_Manage(LPCTSTR lpszAPIName, LPCTSTR lpszClientAddr, LPCTSTR lp Protocol_StorageParse_ReportFile(lpszMsgBuffer, nMsgLen, &ppSt_DBFile, &nListCount); for (int i = 0; i < nListCount; i++) { - if (0 == ppSt_DBFile[i]->st_ProtocolFile.nFileSize) + TCHAR tszFileDir[1024]; + memset(tszFileDir, '\0', sizeof(tszFileDir)); + //判断下文件是否存在就行了 + if (_tcslen(ppSt_DBFile[i]->tszBuckKey) > 0) { - int nHashLen = 0; - UCHAR tszHashStr[MAX_PATH]; - TCHAR tszFileDir[1024]; - struct __stat64 st_FStat; - - memset(tszHashStr, '\0', MAX_PATH); - memset(tszFileDir, '\0', sizeof(tszFileDir)); - - _stprintf(tszFileDir, _T("%s/%s"), ppSt_DBFile[i]->st_ProtocolFile.tszFilePath, ppSt_DBFile[i]->st_ProtocolFile.tszFileName); - - int nRet = _stat64(tszFileDir, &st_FStat); - if (0 != nRet) - { - st_HDRParam.bIsClose = TRUE; - st_HDRParam.nHttpCode = 404; - RfcComponents_HttpServer_SendMsgEx(xhUPHttp, tszSDBuffer, &nSDLen, &st_HDRParam); - XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("业务客户端:%s,请求添加文件到数据库失败,文件不存在,文件;%s"), lpszClientAddr, tszFileDir); - return FALSE; - } - //获取大小 - ppSt_DBFile[i]->st_ProtocolFile.nFileSize = st_FStat.st_size; - //计算HASH - OPenSsl_Api_Digest(tszFileDir, tszHashStr, &nHashLen, TRUE, st_ServiceCfg.st_XStorage.nHashMode); - BaseLib_OperatorString_StrToHex((char*)tszHashStr, nHashLen, ppSt_DBFile[i]->st_ProtocolFile.tszFileHash); + APIHelp_Distributed_GetPathKey(st_LoadbalanceCfg.st_LoadBalance.pStl_ListBucket, ppSt_DBFile[i]->tszBuckKey, ppSt_DBFile[i]->st_ProtocolFile.tszFilePath); } - if (0 != st_ServiceCfg.st_XSql.nSQLType) + _stprintf(tszFileDir, _T("%s/%s"), ppSt_DBFile[i]->st_ProtocolFile.tszFilePath, ppSt_DBFile[i]->st_ProtocolFile.tszFileName); + if (0 != _taccess(tszFileDir, 0)) { - if (1 == st_ServiceCfg.st_XSql.nSQLType) - { - XStorage_MySql_FileInsert(ppSt_DBFile[i]); - } - else - { - XStorage_SQLite_FileInsert(ppSt_DBFile[i]); - } + st_HDRParam.bIsClose = TRUE; + st_HDRParam.nHttpCode = 404; + RfcComponents_HttpServer_SendMsgEx(xhUPHttp, tszSDBuffer, &nSDLen, &st_HDRParam); + XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("业务客户端:%s,请求添加文件到数据库失败,文件不存在,文件;%s"), lpszClientAddr, tszFileDir); + return FALSE; + } + if (0 == st_ServiceCfg.st_XSql.nSQLType) + { + st_HDRParam.bIsClose = TRUE; + st_HDRParam.nHttpCode = 501; + RfcComponents_HttpServer_SendMsgEx(xhUPHttp, tszSDBuffer, &nSDLen, &st_HDRParam); + XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("业务客户端:%s,请求添加文件到数据库失败,服务器没有启用数据库,不支持此功能,文件;%s"), lpszClientAddr, tszFileDir); + return FALSE; + } + if (1 == st_ServiceCfg.st_XSql.nSQLType) + { + XStorage_MySql_FileInsert(ppSt_DBFile[i]); + } + else + { + XStorage_SQLite_FileInsert(ppSt_DBFile[i]); } 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); } @@ -74,7 +117,7 @@ BOOL XEngine_Task_Manage(LPCTSTR lpszAPIName, LPCTSTR lpszClientAddr, LPCTSTR lp XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER); BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_DBFile, nListCount); } - else if (0 == _tcsnicmp(XENGINE_STORAGE_APP_METHOD_DEL, lpszAPIName, _tcslen(XENGINE_STORAGE_APP_METHOD_DEL))) + else if (0 == _tcsnicmp(XENGINE_STORAGE_APP_METHOD_DELETE, lpszAPIName, _tcslen(XENGINE_STORAGE_APP_METHOD_DELETE))) { int nListCount = 0; XSTORAGECORE_DBFILE** ppSt_DBFile; @@ -90,7 +133,7 @@ BOOL XEngine_Task_Manage(LPCTSTR lpszAPIName, LPCTSTR lpszClientAddr, LPCTSTR lp XSTORAGECORE_DBFILE** ppSt_DBQuery; if (1 == st_ServiceCfg.st_XSql.nSQLType) { - XStorage_MySql_FileQuery(&ppSt_DBQuery, &nQueryCount, NULL, NULL, NULL, ppSt_DBFile[i]->st_ProtocolFile.tszFileHash); + XStorage_MySql_FileQuery(&ppSt_DBQuery, &nQueryCount, NULL, NULL, NULL, NULL, ppSt_DBFile[i]->st_ProtocolFile.tszFileHash); //删除数据库与文件 for (int i = 0; i < nQueryCount; i++) { @@ -98,12 +141,13 @@ BOOL XEngine_Task_Manage(LPCTSTR lpszAPIName, LPCTSTR lpszClientAddr, LPCTSTR lp memset(tszFilePath, '\0', sizeof(tszFilePath)); _stprintf(tszFilePath, _T("%s/%s"), ppSt_DBQuery[i]->st_ProtocolFile.tszFilePath, ppSt_DBQuery[i]->st_ProtocolFile.tszFileName); - XStorage_MySql_FileDelete(NULL, ppSt_DBQuery[i]->st_ProtocolFile.tszFileHash); + XStorage_MySql_FileDelete(NULL, NULL, ppSt_DBQuery[i]->st_ProtocolFile.tszFileHash); + _tremove(tszFilePath); } } else { - XStorage_SQLite_FileQuery(&ppSt_DBQuery, &nQueryCount, NULL, NULL, NULL, ppSt_DBFile[i]->st_ProtocolFile.tszFileHash); + XStorage_SQLite_FileQuery(&ppSt_DBQuery, &nQueryCount, NULL, NULL, NULL, NULL, ppSt_DBFile[i]->st_ProtocolFile.tszFileHash); //删除数据库与文件 for (int i = 0; i < nQueryCount; i++) { @@ -111,7 +155,8 @@ BOOL XEngine_Task_Manage(LPCTSTR lpszAPIName, LPCTSTR lpszClientAddr, LPCTSTR lp memset(tszFilePath, '\0', sizeof(tszFilePath)); _stprintf(tszFilePath, _T("%s/%s"), ppSt_DBQuery[i]->st_ProtocolFile.tszFilePath, ppSt_DBQuery[i]->st_ProtocolFile.tszFileName); - XStorage_SQLite_FileDelete(NULL, ppSt_DBQuery[i]->st_ProtocolFile.tszFileHash); + XStorage_SQLite_FileDelete(NULL, NULL, ppSt_DBQuery[i]->st_ProtocolFile.tszFileHash); + _tremove(tszFilePath); } } XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("业务客户端:%s,请求删除文件HASH成功,文件名:%s"), lpszClientAddr, ppSt_DBFile[i]->st_ProtocolFile.tszFileHash); @@ -130,10 +175,14 @@ BOOL XEngine_Task_Manage(LPCTSTR lpszAPIName, LPCTSTR lpszClientAddr, LPCTSTR lp XSTORAGECORE_DBFILE** ppSt_DBQuery; memset(tszFileDir, '\0', sizeof(tszFileDir)); + if (_tcslen(ppSt_DBFile[i]->tszBuckKey) > 0) + { + APIHelp_Distributed_GetPathKey(st_LoadbalanceCfg.st_LoadBalance.pStl_ListBucket, ppSt_DBFile[i]->tszBuckKey, ppSt_DBFile[i]->st_ProtocolFile.tszFilePath); + } _stprintf(tszFileDir, _T("%s/%s"), ppSt_DBFile[i]->st_ProtocolFile.tszFilePath, ppSt_DBFile[i]->st_ProtocolFile.tszFileName); if (1 == st_ServiceCfg.st_XSql.nSQLType) { - XStorage_MySql_FileQuery(&ppSt_DBQuery, &nQueryCount, NULL, NULL, tszFileDir); + XStorage_MySql_FileQuery(&ppSt_DBQuery, &nQueryCount, NULL, NULL, NULL, tszFileDir); //删除数据库与文件 for (int i = 0; i < nQueryCount; i++) { @@ -141,12 +190,13 @@ BOOL XEngine_Task_Manage(LPCTSTR lpszAPIName, LPCTSTR lpszClientAddr, LPCTSTR lp memset(tszFilePath, '\0', sizeof(tszFilePath)); _stprintf(tszFilePath, _T("%s/%s"), ppSt_DBQuery[i]->st_ProtocolFile.tszFilePath, ppSt_DBQuery[i]->st_ProtocolFile.tszFileName); - XStorage_MySql_FileDelete(NULL, ppSt_DBQuery[i]->st_ProtocolFile.tszFileHash); + XStorage_MySql_FileDelete(NULL, NULL, ppSt_DBQuery[i]->st_ProtocolFile.tszFileHash); + _tremove(tszFilePath); } } else { - XStorage_SQLite_FileQuery(&ppSt_DBQuery, &nQueryCount, NULL, NULL, tszFileDir); + XStorage_SQLite_FileQuery(&ppSt_DBQuery, &nQueryCount, NULL, NULL, NULL, tszFileDir); //删除数据库与文件 for (int i = 0; i < nQueryCount; i++) { @@ -154,14 +204,15 @@ BOOL XEngine_Task_Manage(LPCTSTR lpszAPIName, LPCTSTR lpszClientAddr, LPCTSTR lp memset(tszFilePath, '\0', sizeof(tszFilePath)); _stprintf(tszFilePath, _T("%s/%s"), ppSt_DBQuery[i]->st_ProtocolFile.tszFilePath, ppSt_DBQuery[i]->st_ProtocolFile.tszFileName); - XStorage_SQLite_FileDelete(NULL, ppSt_DBQuery[i]->st_ProtocolFile.tszFileHash); + XStorage_SQLite_FileDelete(NULL, NULL, ppSt_DBQuery[i]->st_ProtocolFile.tszFileHash); + _tremove(tszFilePath); } } 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); } else { - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("业务客户端:%s,请求删除文件名称失败,因为没有启用数据库,删除的HASH:%s"), lpszClientAddr, ppSt_DBFile[i]->st_ProtocolFile.tszFilePath, ppSt_DBFile[i]->st_ProtocolFile.tszFileName); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("业务客户端:%s,请求删除文件名称失败,因为没有启用数据库,删除的文件:%s/%s"), lpszClientAddr, ppSt_DBFile[i]->st_ProtocolFile.tszFilePath, ppSt_DBFile[i]->st_ProtocolFile.tszFileName); } } } @@ -169,72 +220,6 @@ BOOL XEngine_Task_Manage(LPCTSTR lpszAPIName, LPCTSTR lpszClientAddr, LPCTSTR lp XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER); BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_DBFile, nListCount); } - else if (0 == _tcsnicmp(XENGINE_STORAGE_APP_METHOD_QUERYFILE, lpszAPIName, _tcslen(XENGINE_STORAGE_APP_METHOD_QUERYFILE))) - { - //查询文件列表 - int nMsgLen = 10240; - TCHAR tszFileName[MAX_PATH]; - TCHAR tszFileHash[MAX_PATH]; - TCHAR tszBucketKey[128]; - TCHAR tszTimeStart[128]; - TCHAR tszTimeEnd[128]; - TCHAR tszMsgBuffer[10240]; - - memset(tszFileName, '\0', MAX_PATH); - memset(tszFileHash, '\0', MAX_PATH); - memset(tszBucketKey, '\0', sizeof(tszBucketKey)); - memset(tszTimeStart, '\0', sizeof(tszTimeStart)); - memset(tszTimeEnd, '\0', sizeof(tszTimeEnd)); - memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer)); - - int nListCount = 0; - XSTORAGECORE_DBFILE** ppSt_ListFile; - Protocol_StorageParse_QueryFile(lpszMsgBuffer, tszTimeStart, tszTimeEnd, tszBucketKey, tszFileName, tszFileHash); - - if (0 == st_ServiceCfg.st_XSql.nSQLType) - { - st_HDRParam.bIsClose = TRUE; - st_HDRParam.nHttpCode = 406; - - RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam); - XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _T("业务客户端:%s,请求查询文件列表失败,服务器没有启用这个功能"), lpszClientAddr); - } - else - { - if (1 == st_ServiceCfg.st_XSql.nSQLType) - { - XStorage_MySql_FileQuery(&ppSt_ListFile, &nListCount, tszTimeStart, tszTimeEnd, tszFileName, tszFileHash); - } - else - { - XStorage_SQLite_FileQuery(&ppSt_ListFile, &nListCount, tszTimeStart, tszTimeEnd, tszFileName, tszFileHash); - } - - Protocol_StoragePacket_QueryFile(tszMsgBuffer, &nMsgLen, &ppSt_ListFile, nListCount, tszTimeStart, tszTimeEnd); - RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam, tszMsgBuffer, nMsgLen); - XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER); - BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_ListFile, nListCount); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("业务客户端:%s,请求查询文件列表成功,列表个数:%d"), lpszClientAddr, nListCount); - } - } - else if (0 == _tcsnicmp(XENGINE_STORAGE_APP_METHOD_TASK, lpszAPIName, _tcslen(XENGINE_STORAGE_APP_METHOD_TASK))) - { - int nDLCount = 0; - int nUPCount = 0; - SESSION_STORAGEINFO** ppSt_DLInfo; - SESSION_STORAGEINFO** ppSt_UPInfo; - - Session_DLStorage_GetAll(&ppSt_DLInfo, &nDLCount); - Session_UPStorage_GetAll(&ppSt_UPInfo, &nUPCount); - - Protocol_StoragePacket_Info(tszRVBuffer, &nRVLen, &ppSt_DLInfo, &ppSt_UPInfo, nDLCount, nUPCount); - RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam, tszRVBuffer, nRVLen); - XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER); - BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_DLInfo, nDLCount); - BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_UPInfo, nUPCount); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("业务客户端:%s,请求获取上传下载信息成功,下载个数:%d,上传个数:%d"), lpszClientAddr, nDLCount, nUPCount); - } else if (0 == _tcsnicmp(XENGINE_STORAGE_APP_METHOD_DIR, lpszAPIName, _tcslen(XENGINE_STORAGE_APP_METHOD_DIR))) { int nOPCode = 0; @@ -242,14 +227,26 @@ BOOL XEngine_Task_Manage(LPCTSTR lpszAPIName, LPCTSTR lpszClientAddr, LPCTSTR lp CHAR** ppszListDir = NULL; TCHAR tszUserDir[MAX_PATH]; TCHAR tszBuckKey[MAX_PATH]; + TCHAR tszBuckPath[MAX_PATH]; TCHAR tszRealDir[1024]; memset(tszUserDir, '\0', MAX_PATH); memset(tszBuckKey, '\0', MAX_PATH); + memset(tszBuckPath, '\0', MAX_PATH); memset(tszRealDir, '\0', sizeof(tszRealDir)); Protocol_StorageParse_DirOperator(lpszMsgBuffer, tszUserDir, tszBuckKey, &nOPCode); - _stprintf(tszRealDir, _T("%s/%s"), tszBuckKey, tszUserDir); + APIHelp_Distributed_GetPathKey(st_LoadbalanceCfg.st_LoadBalance.pStl_ListBucket, tszBuckKey, tszBuckPath); + + if (_tcslen(tszUserDir) > 0) + { + _stprintf(tszRealDir, _T("%s/%s"), tszBuckPath, tszUserDir); + } + else + { + _stprintf(tszRealDir, _T("%s"), tszBuckPath); + } + if (0 == nOPCode) { if (!SystemApi_File_EnumFile(tszRealDir, &ppszListDir, &nListCount, NULL, NULL, TRUE, 2)) @@ -301,99 +298,172 @@ BOOL XEngine_Task_Manage(LPCTSTR lpszAPIName, LPCTSTR lpszClientAddr, LPCTSTR lp XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("业务客户端:%s,请求删除文件夹:%s,成功"), lpszClientAddr, tszRealDir); } } - else if (0 == _tcsnicmp(XENGINE_STORAGE_APP_METHOD_LAN, lpszAPIName, _tcslen(XENGINE_STORAGE_APP_METHOD_LAN))) + else if (0 == _tcsnicmp(XENGINE_STORAGE_APP_METHOD_TASK, lpszAPIName, _tcslen(XENGINE_STORAGE_APP_METHOD_TASK))) { - TCHAR tszPubAddr[128]; - TCHAR tszPriAddr[128]; + int nDLCount = 0; + int nUPCount = 0; + SESSION_STORAGEINFO** ppSt_DLInfo; + SESSION_STORAGEINFO** ppSt_UPInfo; - memset(tszPubAddr, '\0', sizeof(tszPubAddr)); - memset(tszPriAddr, '\0', sizeof(tszPriAddr)); + Session_DLStorage_GetAll(&ppSt_DLInfo, &nDLCount); + Session_UPStorage_GetAll(&ppSt_UPInfo, &nUPCount); - if (!Protocol_P2XPParse_List(lpszMsgBuffer, nMsgLen, tszPubAddr, tszPriAddr)) + Protocol_StoragePacket_Info(tszRVBuffer, &nRVLen, &ppSt_DLInfo, &ppSt_UPInfo, nDLCount, nUPCount); + RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam, tszRVBuffer, nRVLen); + XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER); + BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_DLInfo, nDLCount); + BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_UPInfo, nUPCount); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("业务客户端:%s,请求获取上传下载信息成功,下载个数:%d,上传个数:%d"), lpszClientAddr, nDLCount, nUPCount); + } + else if (0 == _tcsnicmp(XENGINE_STORAGE_APP_METHOD_P2P, lpszAPIName, _tcslen(XENGINE_STORAGE_APP_METHOD_P2P))) + { + TCHAR tszBuckKey[MAX_PATH]; + TCHAR tszFileName[MAX_PATH]; + TCHAR tszFileHash[MAX_PATH]; + + memset(tszBuckKey, '\0', MAX_PATH); + memset(tszFileName, '\0', MAX_PATH); + memset(tszFileHash, '\0', MAX_PATH); + + Protocol_StorageParse_QueryFile(lpszMsgBuffer, NULL, NULL, tszBuckKey, tszFileName, tszFileHash); + + if ((_tcslen(tszFileHash) <= 0) && (_tcslen(tszFileName) <= 0)) { - Protocol_P2XPPacket_Common(NULL, tszRVBuffer, &nRVLen, 400, "协议错误"); - RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam, tszRVBuffer, nRVLen); + st_HDRParam.bIsClose = TRUE; + st_HDRParam.nHttpCode = 400; + + RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam); XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("P2XP客户端:%s,列表请求失败,协议解析错误,错误码:%lX"), lpszClientAddr, Protocol_GetLastError()); - return FALSE; + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("业务客户端:%s,请求文件查询失败,参数不正确,无法继续"), lpszClientAddr); + return TRUE; } - //请求同步列表 - if (_tcslen(tszPriAddr) > 0) + //是否启用数据库 + if (0 == st_ServiceCfg.st_XSql.nSQLType) { - int nListCount = 0; - XENGINE_P2XPPEER_PROTOCOL** ppSt_ListClients; - if (!P2XPPeer_Manage_GetLan(tszPubAddr, tszPriAddr, &ppSt_ListClients, &nListCount)) - { - Protocol_P2XPPacket_Common(NULL, tszRVBuffer, &nRVLen, 500, "协议错误"); - RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam, tszRVBuffer, nRVLen); - XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("P2XP客户端:%s,列表请求失败,请求同步局域网列表失败,公有地址:%s,私有地址:%s,错误码:%lX"), lpszClientAddr, tszPubAddr, tszPriAddr, P2XPPeer_GetLastError()); - return FALSE; - } - Protocol_P2XPPacket_Lan(NULL, &ppSt_ListClients, nListCount, tszRVBuffer, &nRVLen); - RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam, tszRVBuffer, nRVLen); + st_HDRParam.bIsClose = TRUE; + st_HDRParam.nHttpCode = 501; + + RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam); XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER); - BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_ListClients, nListCount); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("客户端:%s,请求同步局域网列表成功,公有地址:%s,私有地址:%s"), lpszClientAddr, tszPubAddr, tszPriAddr); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("业务客户端:%s,请求文件查询失败,服务器没有启用数据库,无法继续"), lpszClientAddr); + return TRUE; + } + //首先判断本机存在不 + int nListCount = 0; + XSTORAGECORE_DBFILE** pppSt_ListFile; + if (1 == st_ServiceCfg.st_XSql.nSQLType) + { + XStorage_MySql_FileQuery(&pppSt_ListFile, &nListCount, NULL, NULL, NULL, NULL, tszFileHash); } else { - //公网下所有列表 - int nListCount = 0; - TCHAR** ppszClientList; - list stl_ListClient; - if (P2XPPeer_Manage_GetLList(tszPubAddr, &ppszClientList, &nListCount)) - { - for (int i = 0; i < nListCount; i++) - { - int nLanCount = 0; - XENGINE_P2XPPEER_PROTOCOL** ppSt_ListClients; + XStorage_SQLite_FileQuery(&pppSt_ListFile, &nListCount, NULL, NULL, NULL, NULL, tszFileHash); + } + if (nListCount > 0) + { + st_HDRParam.bIsClose = TRUE; + st_HDRParam.nHttpCode = 200; - if (P2XPPeer_Manage_GetLan(tszPubAddr, ppszClientList[i], &ppSt_ListClients, &nLanCount)) - { - for (int j = 0; j < nLanCount; j++) - { - stl_ListClient.push_back(*ppSt_ListClients[j]); - } - BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_ListClients, nLanCount); - } - } - BaseLib_OperatorMemory_Free((XPPPMEM)&ppszClientList, nListCount); + for (int i = 0; i < nListCount; i++) + { + _stprintf(pppSt_ListFile[i]->tszTableName, _T("127.0.0.1:%d"), st_ServiceCfg.nStorageDLPort); } - Protocol_P2XPPacket_WLan(NULL, &stl_ListClient, tszRVBuffer, &nRVLen); + Protocol_StoragePacket_QueryFile(tszRVBuffer, &nRVLen, &pppSt_ListFile, nListCount); + BaseLib_OperatorMemory_Free((XPPPMEM)&pppSt_ListFile, nListCount); + RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam, tszRVBuffer, nRVLen); XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("客户端:%s,请求同步局域网列表成功,公有地址:%s,私有地址:%s"), lpszClientAddr, tszPubAddr, tszPriAddr); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("业务客户端:%s,请求文件查询,发现本地拥有此文件.直接返回"), lpszClientAddr); + return TRUE; } - } - else if (0 == _tcsnicmp(XENGINE_STORAGE_APP_METHOD_QUERY, lpszAPIName, _tcslen(XENGINE_STORAGE_APP_METHOD_QUERY))) - { - TCHAR tszUserName[128]; - XENGINE_P2XP_PEERINFO st_PeerInfo; - - memset(tszUserName, '\0', sizeof(tszUserName)); - memset(&st_PeerInfo, '\0', sizeof(XENGINE_P2XP_PEERINFO)); - if (!Protocol_P2XPParse_User(lpszMsgBuffer, nMsgLen, tszUserName)) + //根据使用模式来操作 + if (0 == st_ServiceCfg.st_P2xp.nMode) { - Protocol_P2XPPacket_Common(NULL, tszRVBuffer, &nRVLen, 400, "协议错误"); - RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam, tszRVBuffer, nRVLen); + st_HDRParam.bIsClose = TRUE; + st_HDRParam.nHttpCode = 405; + + RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam); XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("P2XP客户端:%s,查询用户失败,协议解析错误,错误码:%lX"), lpszClientAddr, Protocol_GetLastError()); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("业务客户端:%s,暂时不支持的请求"), lpszClientAddr); return FALSE; - } - if (!P2XPPeer_Manage_GetUser(tszUserName, &st_PeerInfo)) + else if (1 == st_ServiceCfg.st_P2xp.nMode) { - Protocol_P2XPPacket_Common(NULL, tszRVBuffer, &nRVLen, 500, "协议错误"); - RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam, tszRVBuffer, nRVLen); + st_HDRParam.bIsClose = TRUE; + st_HDRParam.nHttpCode = 405; + + RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam); XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("P2XP客户端:%s,查询用户失败,获取用户失败,用户名:%s,错误码:%lX"), lpszClientAddr, tszUserName, P2XPPeer_GetLastError()); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("业务客户端:%s,暂时不支持的请求"), lpszClientAddr); return FALSE; } - Protocol_P2XPPacket_User(NULL, &st_PeerInfo.st_PeerAddr, tszRVBuffer, &nRVLen); - RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam, tszRVBuffer, nRVLen); - XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("客户端:%s,请求查询用户:%s 成功"), lpszClientAddr, tszUserName); + else + { + //开始广播请求文件 + SOCKET hSDSocket; + SOCKET hRVSocket; + list stl_ListFile; + + Protocol_P2XPPacket_QueryFile(tszSDBuffer, &nSDLen, NULL, tszFileHash); + NetCore_BroadCast_SendInit(&hSDSocket, st_ServiceCfg.st_P2xp.nRVPort, st_ServiceCfg.tszIPAddr); + NetCore_BroadCast_RecvInit(&hRVSocket, st_ServiceCfg.st_P2xp.nSDPort); + + if (!NetCore_BroadCast_Send(hSDSocket, tszSDBuffer, nSDLen)) + { + st_HDRParam.bIsClose = TRUE; + st_HDRParam.nHttpCode = 500; + + RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam); + XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER); + NetCore_BroadCast_Close(hSDSocket); + NetCore_BroadCast_Close(hRVSocket); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("业务客户端:%s,发送广播请求失败,错误:%lX"), lpszClientAddr, NetCore_GetLastError()); + return FALSE; + } + NetCore_BroadCast_Close(hSDSocket); + + time_t nTimeStart = time(NULL); + while (1) + { + APIHELP_LBFILEINFO st_FileInfo; + memset(&st_FileInfo, '\0', sizeof(APIHELP_LBFILEINFO)); + + st_FileInfo.nMsgLen = sizeof(st_FileInfo.tszMsgBuffer); + if (NetCore_BroadCast_Recv(hRVSocket, st_FileInfo.tszMsgBuffer, &st_FileInfo.nMsgLen)) + { + stl_ListFile.push_back(st_FileInfo); + } + time_t nTimeEnd = time(NULL); + if ((nTimeEnd - nTimeStart) > st_ServiceCfg.st_P2xp.nTime) + { + //大于ntime秒,退出 + break; + } + } + NetCore_BroadCast_Close(hRVSocket); + + if (stl_ListFile.empty()) + { + st_HDRParam.bIsClose = TRUE; + st_HDRParam.nHttpCode = 404; + RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam); + } + else + { + st_HDRParam.bIsClose = TRUE; + st_HDRParam.nHttpCode = 200; + + int nListCount = 0; + XSTORAGECORE_DBFILE** ppSt_ListPacket; + APIHelp_Distributed_FileList(&stl_ListFile, &ppSt_ListPacket, &nListCount); + Protocol_StoragePacket_QueryFile(tszRVBuffer, &nRVLen, &ppSt_ListPacket, nListCount); + RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam, tszRVBuffer, nRVLen); + BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_ListPacket, nListCount); + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("业务客户端:%s,请求局域网文件列表成功,文件分布服务器个数:%d"), lpszClientAddr, stl_ListFile.size()); + XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER); + stl_ListFile.clear(); + } } return TRUE; } \ No newline at end of file diff --git a/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskManage.h b/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskManage.h index 646ab92122389e313832b349de0c7c42b92fa9a3..e7a65bc67c01a63dbb6b2d6fc3a52ad71f05dcb7 100644 --- a/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskManage.h +++ b/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskManage.h @@ -1,11 +1,10 @@ #pragma once -#define XENGINE_STORAGE_APP_METHOD_ADD _T("Add") -#define XENGINE_STORAGE_APP_METHOD_DEL _T("Del") -#define XENGINE_STORAGE_APP_METHOD_QUERYFILE _T("Query") -#define XENGINE_STORAGE_APP_METHOD_TASK _T("Task") -#define XENGINE_STORAGE_APP_METHOD_DIR _T("Dir") -#define XENGINE_STORAGE_APP_METHOD_LAN _T("Lan") +#define XENGINE_STORAGE_APP_METHOD_INSERT _T("Insert") +#define XENGINE_STORAGE_APP_METHOD_DELETE _T("Delete") #define XENGINE_STORAGE_APP_METHOD_QUERY _T("Query") +#define XENGINE_STORAGE_APP_METHOD_DIR _T("Dir") +#define XENGINE_STORAGE_APP_METHOD_TASK _T("Task") +#define XENGINE_STORAGE_APP_METHOD_P2P _T("P2P") BOOL XEngine_Task_Manage(LPCTSTR lpszAPIName, LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMsgLen, RFCCOMPONENTS_HTTP_REQPARAM* pSt_HTTPParam, TCHAR** pptszListHdr, int nHdrCount); \ No newline at end of file diff --git a/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskP2p.cpp b/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskP2p.cpp index 69fdcdad53ed55de461678b86f8c239195fb176a..c027f524949ac6783c514c750b7b773edf454bd1 100644 --- a/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskP2p.cpp +++ b/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskP2p.cpp @@ -6,6 +6,7 @@ XHTHREAD XEngine_Task_P2PThread() TCHAR tszIPAddr[128]; TCHAR tszTimeStart[64]; TCHAR tszTimeEnd[64]; + TCHAR tszBuckKey[MAX_PATH]; TCHAR tszFileName[MAX_PATH]; TCHAR tszFileHash[MAX_PATH]; @@ -16,13 +17,14 @@ XHTHREAD XEngine_Task_P2PThread() memset(tszIPAddr, '\0', sizeof(tszIPAddr)); memset(tszTimeStart, '\0', sizeof(tszTimeStart)); memset(tszTimeEnd, '\0', sizeof(tszTimeEnd)); + memset(tszBuckKey, '\0', MAX_PATH); memset(tszFileName, '\0', MAX_PATH); memset(tszFileHash, '\0', MAX_PATH); if (NetCore_BroadCast_Recv(hBroadSocket, tszMsgBuffer, &nMsgLen, tszIPAddr)) { //收到文件查询请求 - if (Protocol_StorageParse_QueryFile(tszMsgBuffer, tszTimeStart, tszTimeEnd, tszFileName, tszFileHash)) + if (Protocol_StorageParse_QueryFile(tszMsgBuffer, tszTimeStart, tszTimeEnd, tszBuckKey, tszFileName, tszFileHash)) { //查询文件是否存在数据库,不存在不关心 if (0 != st_ServiceCfg.st_XSql.nSQLType) @@ -31,11 +33,11 @@ XHTHREAD XEngine_Task_P2PThread() XSTORAGECORE_DBFILE** pppSt_ListFile; if (1 == st_ServiceCfg.st_XSql.nSQLType) { - XStorage_MySql_FileQuery(&pppSt_ListFile, &nListCount, tszTimeStart, tszTimeEnd, tszFileName, tszFileHash); + XStorage_MySql_FileQuery(&pppSt_ListFile, &nListCount, tszTimeStart, tszTimeEnd, tszBuckKey, tszFileName, tszFileHash); } else { - XStorage_SQLite_FileQuery(&pppSt_ListFile, &nListCount, tszTimeStart, tszTimeEnd, tszFileName, tszFileHash); + XStorage_SQLite_FileQuery(&pppSt_ListFile, &nListCount, tszTimeStart, tszTimeEnd, tszBuckKey, tszFileName, tszFileHash); } if (nListCount > 0) { @@ -54,136 +56,4 @@ XHTHREAD XEngine_Task_P2PThread() } } return 0; -} -BOOL XEngine_Task_P2PGet(LPCTSTR lpszFileHash, LPCTSTR lpszClientAddr, RFCCOMPONENTS_HTTP_REQPARAM* pSt_HTTPParam) -{ - int nSDLen = 2048; - int nRVLen = 2048; - int nMsgLen = 2048; - TCHAR tszSDBuffer[2048]; - TCHAR tszRVBuffer[2048]; - TCHAR tszMsgBuffer[2048]; - RFCCOMPONENTS_HTTP_HDRPARAM st_HDRParam; - - memset(tszSDBuffer, '\0', sizeof(tszSDBuffer)); - memset(tszRVBuffer, '\0', sizeof(tszRVBuffer)); - memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer)); - memset(&st_HDRParam, '\0', sizeof(RFCCOMPONENTS_HTTP_HDRPARAM)); - //首先判断本机存在不 - if (0 != st_ServiceCfg.st_XSql.nSQLType) - { - int nListCount = 0; - XSTORAGECORE_DBFILE** pppSt_ListFile; - if (1 == st_ServiceCfg.st_XSql.nSQLType) - { - XStorage_MySql_FileQuery(&pppSt_ListFile, &nListCount, NULL, NULL, NULL, lpszFileHash); - } - else - { - XStorage_SQLite_FileQuery(&pppSt_ListFile, &nListCount, NULL, NULL, NULL, lpszFileHash); - } - if (nListCount > 0) - { - st_HDRParam.bIsClose = TRUE; - st_HDRParam.nHttpCode = 200; - - _stprintf(pppSt_ListFile[0]->tszTableName, _T("127.0.0.1:%d"), st_ServiceCfg.nStorageDLPort); - Protocol_StoragePacket_QueryFile(tszRVBuffer, &nRVLen, &pppSt_ListFile, nListCount); - BaseLib_OperatorMemory_Free((XPPPMEM)&pppSt_ListFile, nListCount); - - RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszMsgBuffer, &nMsgLen, &st_HDRParam, tszRVBuffer, nRVLen); - XEngine_Net_SendMsg(lpszClientAddr, tszMsgBuffer, nMsgLen, STORAGE_NETTYPE_HTTPCENTER); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("广播端:%s,请求文件查询,发现本地拥有此文件.直接返回"), lpszClientAddr); - return TRUE; - } - } - //根据使用模式来操作 - if (0 == st_ServiceCfg.st_P2xp.nMode) - { - st_HDRParam.bIsClose = TRUE; - st_HDRParam.nHttpCode = 405; - - RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszMsgBuffer, &nMsgLen, &st_HDRParam); - XEngine_Net_SendMsg(lpszClientAddr, tszMsgBuffer, nMsgLen, STORAGE_NETTYPE_HTTPCENTER); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("广播端:%s,暂时不支持的请求"), lpszClientAddr); - return FALSE; - } - else if (1 == st_ServiceCfg.st_P2xp.nMode) - { - st_HDRParam.bIsClose = TRUE; - st_HDRParam.nHttpCode = 405; - - RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszMsgBuffer, &nMsgLen, &st_HDRParam); - XEngine_Net_SendMsg(lpszClientAddr, tszMsgBuffer, nMsgLen, STORAGE_NETTYPE_HTTPCENTER); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("广播端:%s,暂时不支持的请求"), lpszClientAddr); - return FALSE; - } - else - { - //开始广播请求文件 - SOCKET hSDSocket; - SOCKET hRVSocket; - list stl_ListFile; - - Protocol_P2XPPacket_QueryFile(tszSDBuffer, &nSDLen, NULL, lpszFileHash); - NetCore_BroadCast_SendInit(&hSDSocket, st_ServiceCfg.st_P2xp.nRVPort, st_ServiceCfg.tszIPAddr); - NetCore_BroadCast_RecvInit(&hRVSocket, st_ServiceCfg.st_P2xp.nSDPort); - - if (!NetCore_BroadCast_Send(hSDSocket, tszSDBuffer, nSDLen)) - { - st_HDRParam.bIsClose = TRUE; - st_HDRParam.nHttpCode = 500; - - RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszMsgBuffer, &nMsgLen, &st_HDRParam); - XEngine_Net_SendMsg(lpszClientAddr, tszMsgBuffer, nMsgLen, STORAGE_NETTYPE_HTTPCENTER); - NetCore_BroadCast_Close(hSDSocket); - NetCore_BroadCast_Close(hRVSocket); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("广播端:%s,发送广播请求失败,错误:%lX"), lpszClientAddr, NetCore_GetLastError()); - return FALSE; - } - NetCore_BroadCast_Close(hSDSocket); - - time_t nTimeStart = time(NULL); - while (1) - { - APIHELP_LBFILEINFO st_FileInfo; - memset(&st_FileInfo, '\0', sizeof(APIHELP_LBFILEINFO)); - - st_FileInfo.nMsgLen = sizeof(st_FileInfo.tszMsgBuffer); - if (NetCore_BroadCast_Recv(hRVSocket, st_FileInfo.tszMsgBuffer, &st_FileInfo.nMsgLen)) - { - stl_ListFile.push_back(st_FileInfo); - } - time_t nTimeEnd = time(NULL); - if ((nTimeEnd - nTimeStart) > st_ServiceCfg.st_P2xp.nTime) - { - //大于ntime秒,退出 - break; - } - } - NetCore_BroadCast_Close(hRVSocket); - - if (stl_ListFile.empty()) - { - st_HDRParam.bIsClose = TRUE; - st_HDRParam.nHttpCode = 404; - RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszMsgBuffer, &nMsgLen, &st_HDRParam); - } - else - { - st_HDRParam.bIsClose = TRUE; - st_HDRParam.nHttpCode = 200; - - int nListCount = 0; - XSTORAGECORE_DBFILE** ppSt_ListPacket; - APIHelp_Distributed_FileList(&stl_ListFile, &ppSt_ListPacket, &nListCount); - Protocol_StoragePacket_QueryFile(tszRVBuffer, &nRVLen, &ppSt_ListPacket, nListCount); - RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszMsgBuffer, &nMsgLen, &st_HDRParam, tszRVBuffer, nRVLen); - BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_ListPacket, nListCount); - } - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("广播端:%s,请求局域网文件列表成功,文件分布服务器个数:%d"), lpszClientAddr, stl_ListFile.size()); - XEngine_Net_SendMsg(lpszClientAddr, tszMsgBuffer, nMsgLen, STORAGE_NETTYPE_HTTPCENTER); - stl_ListFile.clear(); - } - return TRUE; } \ No newline at end of file diff --git a/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskP2p.h b/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskP2p.h index 7e7cec192b18f6a45d6f1c516bcbf4947bac2f41..6e051e50b966794c63a463ae717258a7fec903c2 100644 --- a/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskP2p.h +++ b/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskP2p.h @@ -1,4 +1,3 @@ #pragma once -XHTHREAD XEngine_Task_P2PThread(); -BOOL XEngine_Task_P2PGet(LPCTSTR lpszFileHash, LPCTSTR lpszClientAddr, RFCCOMPONENTS_HTTP_REQPARAM* pSt_HTTPParam); \ No newline at end of file +XHTHREAD XEngine_Task_P2PThread(); \ No newline at end of file diff --git a/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskPass.cpp b/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskPass.cpp index 27e94745b280e1d3556991492184226430738a95..644e578fa3febbcc462f3a86217a7cd7cb03cc89 100644 --- a/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskPass.cpp +++ b/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskPass.cpp @@ -38,7 +38,6 @@ BOOL XEngine_Task_Pass(LPCTSTR lpszAPIName, LPCTSTR lpszClientAddr, LPCTSTR lpsz memset(tszClientAddr, '\0', sizeof(tszClientAddr)); Protocol_StorageParse_ProxyNotify(lpszMsgBuffer, nMsgLen, tszClientAddr, tszPathKey, tszFileName, tszFileHash, &nFileSize); - RfcComponents_HttpServer_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam); XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("业务客户端:%s,请求的下载文件通知协议成功,文件:%s,大小:%lld"), lpszClientAddr, tszFileName, nFileSize); diff --git a/XEngine_Source/XEngine_StorageApp/XEngine_StorageApp.vcxproj b/XEngine_Source/XEngine_StorageApp/XEngine_StorageApp.vcxproj index 3f2dc98deff3ca774dd3a65b0b9c73208c919fd0..3386144e3a97335203c63fd60d81cdad97d86e45 100644 --- a/XEngine_Source/XEngine_StorageApp/XEngine_StorageApp.vcxproj +++ b/XEngine_Source/XEngine_StorageApp/XEngine_StorageApp.vcxproj @@ -155,7 +155,6 @@ - @@ -170,7 +169,6 @@ - diff --git a/XEngine_Source/XEngine_StorageApp/XEngine_StorageApp.vcxproj.filters b/XEngine_Source/XEngine_StorageApp/XEngine_StorageApp.vcxproj.filters index f6efca70db079e31a41cbaac10e070b0e40540b4..39a8cbb20fdb5d0397d1baa8692435ed157925d4 100644 --- a/XEngine_Source/XEngine_StorageApp/XEngine_StorageApp.vcxproj.filters +++ b/XEngine_Source/XEngine_StorageApp/XEngine_StorageApp.vcxproj.filters @@ -19,12 +19,6 @@ {40f770d9-b733-4850-8351-c1ab77d56900} - - {a417f386-25d6-47ac-a994-5ffcf8b453ea} - - - {5625d0f7-4a2d-4a18-86b6-adaaa214ad88} - @@ -48,9 +42,6 @@ 源文件\Storage_APPTask - - 源文件\Storage_APPHelp - 源文件 @@ -83,9 +74,6 @@ 头文件\Storage_APPTask - - 头文件\Storage_APPHelp - 头文件 diff --git a/XEngine_Source/XEngine_StorageComponents/XStorage_P2XPPeer/P2XPPeer_Manage/P2XPPeer_Manage.cpp b/XEngine_Source/XEngine_StorageComponents/XStorage_P2XPPeer/P2XPPeer_Manage/P2XPPeer_Manage.cpp index fd5f9ebaca6dfb7f4245e672faf9f063ee970825..70da7652765e5a658057c7dfcf2db4cabc48048e 100644 --- a/XEngine_Source/XEngine_StorageComponents/XStorage_P2XPPeer/P2XPPeer_Manage/P2XPPeer_Manage.cpp +++ b/XEngine_Source/XEngine_StorageComponents/XStorage_P2XPPeer/P2XPPeer_Manage/P2XPPeer_Manage.cpp @@ -429,7 +429,7 @@ BOOL CP2XPPeer_Manage::P2XPPeer_Manage_GetAllList(TCHAR*** pppszP2XPClient, int* { _tcscpy((*pppszP2XPClient)[i], stl_MapIterator->first.c_str()); } - *pInt_ListCount = stl_MapClients.size(); + *pInt_ListCount = stl_MapPeerAddr.size(); st_rwLocker.unlock_shared(); return TRUE; } diff --git a/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/Makefile b/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/Makefile index 6964aab3f3cf1185b7da8064d31cdf95ab05fd95..0841a1753bcac933e5ee500b6981b0e885d34b81 100644 --- a/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/Makefile +++ b/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/Makefile @@ -7,7 +7,7 @@ LOADBIN = -L /usr/local/lib/XEngine_Release/XEngine_BaseLib -L /usr/local/lib/XE LIB = -lXEngine_BaseLib -lHelpComponents_DataBase LIBEX = -static-libgcc -lrt -ldl LOADSO = -Wl,-rpath=./,--disable-new-dtags -LIBINCLUDE = XStorage_MySql.o XStorage_SQLite.o pch.o +LIBINCLUDE = XStorage_SQLHelp.o XStorage_MySql.o XStorage_SQLite.o pch.o ifeq ($(RELEASE),1) FLAGS = -c -O2 @@ -26,6 +26,8 @@ endif all:$(LIBINCLUDE) $(CC) $(DEBUG) $(LIBINCLUDE) -o libXStorage_SQLPacket.so -shared $(LOADBIN) $(LIB) $(LIBEX) $(LOADSO) +XStorage_SQLHelp.o:./XStorage_SQLHelp/XStorage_SQLHelp.cpp + $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(INCLUDE) ./XStorage_SQLHelp/XStorage_SQLHelp.cpp XStorage_MySql.o:./XStorage_MySql/XStorage_MySql.cpp $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(INCLUDE) ./XStorage_MySql/XStorage_MySql.cpp XStorage_SQLite.o:./XStorage_SQLite/XStorage_SQLite.cpp diff --git a/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/SQLPacket_Define.h b/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/SQLPacket_Define.h index eb49bf702c980d930b286590b37c7010bd3379f7..09e12713d9413726380ad0d899b1cab23709b5fa 100644 --- a/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/SQLPacket_Define.h +++ b/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/SQLPacket_Define.h @@ -53,12 +53,17 @@ extern "C" BOOL XStorage_MySql_FileInsert(XSTORAGECORE_DBFILE *pSt_DBManage); /******************************************************************** 函数名称:XStorage_MySql_FileDelete 函数功能:删除一个数据库文件信息 - 参数.一:lpszFile + 参数.一:lpszBuckKey + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:所属BUCK名称 + 参数.二:lpszFile In/Out:In 类型:常量字符指针 可空:Y 意思:要删除的文件全路径 - 参数.二:lpszHash + 参数.三:lpszHash In/Out:In 类型:常量字符指针 可空:Y @@ -68,7 +73,7 @@ extern "C" BOOL XStorage_MySql_FileInsert(XSTORAGECORE_DBFILE *pSt_DBManage); 意思:是否成功 备注:参数不能全为空,不会删除文件 *********************************************************************/ -extern "C" BOOL XStorage_MySql_FileDelete(LPCSTR lpszFile = NULL, LPCSTR lpszHash = NULL); +extern "C" BOOL XStorage_MySql_FileDelete(LPCTSTR lpszBuckKey = NULL, LPCSTR lpszFile = NULL, LPCSTR lpszHash = NULL); /******************************************************************** 函数名称:XStorage_MySql_FileQuery 函数功能:查询文件信息 @@ -92,80 +97,32 @@ extern "C" BOOL XStorage_MySql_FileDelete(LPCSTR lpszFile = NULL, LPCSTR lpszHas 类型:常量字符指针 可空:Y 意思:查找结束时间,20190730 - 参数.五:lpszFile + 参数.五:lpszBuckKey In/Out:In 类型:常量字符指针 可空:Y - 意思:要查询的名称 - 参数.六:lpszHash + 意思:查询的BUCK名 + 参数.六:lpszFile In/Out:In 类型:常量字符指针 可空:Y - 意思:要查询的文件MD5 -返回值 - 类型:逻辑型 - 意思:是否成功 -备注:返回假可能没有查找到,这条记录不存在.参数lpszFile和lpszMD5不能全为空 -*********************************************************************/ -extern "C" BOOL XStorage_MySql_FileQuery(XSTORAGECORE_DBFILE * **pppSt_ListFile, int* pInt_ListCount, LPCSTR lpszTimeStart = NULL, LPCSTR lpszTimeEnd = NULL, LPCSTR lpszFile = NULL, LPCSTR lpszHash = NULL); -/******************************************************************** -函数名称:XStorage_MySql_FileQueryForTable -函数功能:通过指定表名称查询所有文件 - 参数.一:pppSt_ListFile - In/Out:Out - 类型:三级指针 - 可空:N - 意思:输出查询到的文件信息 - 参数.二:pInt_ListCount - In/Out:Out - 类型:三级指针 - 可空:N - 意思:导出获取到的列表个数 - 参数.三:lpszTableName - In/Out:In - 类型:常量字符指针 - 可空:N - 意思:输入要查询的表名称 -返回值 - 类型:逻辑型 - 意思:是否成功 -备注:参数一需要调用基础库的内存释放函数进行释放内存 -*********************************************************************/ -extern "C" BOOL XStorage_MySql_FileQueryForTable(XSTORAGECORE_DBFILE * **pppSt_ListFile, int* pInt_ListCount, LPCSTR lpszTableName); -/******************************************************************** -函数名称:XStorage_MySql_FileQueryForHash -函数功能:通过HASH查询文件信息 - 参数.一:pSt_FileInfo - In/Out:Out - 类型:数据结构指针 - 可空:N - 意思:输出查询到的文件信息 - 参数.二:lpszFileMD5 - In/Out:In - 类型:常量字符指针 - 可空:N - 意思:输入要查询的文件MD5 - 参数.三:lpszUser - In/Out:In - 类型:常量字符指针 - 可空:N - 意思:输入文件所属用户 - 参数.四:lpszTimeStart + 意思:要查询的名称 + 参数.七:lpszHash In/Out:In 类型:常量字符指针 可空:Y - 意思:输入开始时间 - 参数.五:lpszTimeEnd + 意思:要查询的文件HASH + 参数.八:lpszTableName In/Out:In 类型:常量字符指针 可空:Y - 意思:输入结束时间 + 意思:输入要查询的表明,为NULL所有 返回值 类型:逻辑型 意思:是否成功 -备注: +备注:返回假可能没有查找到,这条记录不存在.参数lpszFile和lpszMD5不能全为空 *********************************************************************/ -extern "C" BOOL XStorage_MySql_FileQueryForHash(XSTORAGECORE_DBFILE* pSt_FileInfo, LPCSTR lpszFileMD5, LPCSTR lpszUser = NULL, LPCSTR lpszTimeStart = NULL, LPCSTR lpszTimeEnd = NULL); +extern "C" BOOL XStorage_MySql_FileQuery(XSTORAGECORE_DBFILE * **pppSt_ListFile, int* pInt_ListCount, LPCSTR lpszTimeStart = NULL, LPCSTR lpszTimeEnd = NULL, LPCTSTR lpszBuckKey = NULL, LPCSTR lpszFile = NULL, LPCSTR lpszHash = NULL, LPCTSTR lpszTableName = NULL); /************************************************************************/ /* SQLITE数据库函数 */ /************************************************************************/ @@ -214,12 +171,17 @@ extern "C" BOOL XStorage_SQLite_FileInsert(XSTORAGECORE_DBFILE* pSt_DBManage); /******************************************************************** 函数名称:XStorage_SQLite_FileDelete 函数功能:删除一个数据库文件信息 - 参数.一:lpszFile + 参数.一:lpszBuckKey + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:所属BUCK名称 + 参数.二:lpszFile In/Out:In 类型:常量字符指针 可空:Y 意思:要删除的文件全路径 - 参数.二:lpszHash + 参数.三:lpszHash In/Out:In 类型:常量字符指针 可空:Y @@ -229,7 +191,7 @@ extern "C" BOOL XStorage_SQLite_FileInsert(XSTORAGECORE_DBFILE* pSt_DBManage); 意思:是否成功 备注:参数不能全为空,不会删除文件 *********************************************************************/ -extern "C" BOOL XStorage_SQLite_FileDelete(LPCTSTR lpszFile = NULL, LPCTSTR lpszHash = NULL); +extern "C" BOOL XStorage_SQLite_FileDelete(LPCTSTR lpszBuckKey = NULL, LPCTSTR lpszFile = NULL, LPCTSTR lpszHash = NULL); /******************************************************************** 函数名称:XStorage_SQLite_FileQuery 函数功能:查询文件信息 @@ -253,43 +215,139 @@ extern "C" BOOL XStorage_SQLite_FileDelete(LPCTSTR lpszFile = NULL, LPCTSTR lpsz 类型:常量字符指针 可空:Y 意思:查找结束时间,20190730 - 参数.五:lpszFile + 参数.五:lpszBuckKey + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:查询的BUCK名 + 参数.六:lpszFile In/Out:In 类型:常量字符指针 可空:Y 意思:要查询的名称 - 参数.六:lpszHash + 参数.七:lpszHash In/Out:In 类型:常量字符指针 可空:Y 意思:要查询的文件HASH + 参数.八:lpszTableName + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:输入要查询的表明,为NULL所有 返回值 类型:逻辑型 意思:是否成功 备注:返回假可能没有查找到,这条记录不存在.参数lpszFile和lpszHash不能全为空 *********************************************************************/ -extern "C" BOOL XStorage_SQLite_FileQuery(XSTORAGECORE_DBFILE*** pppSt_ListFile, int* pInt_ListCount, LPCTSTR lpszTimeStart = NULL, LPCTSTR lpszTimeEnd = NULL, LPCTSTR lpszFile = NULL, LPCTSTR lpszHash = NULL); +extern "C" BOOL XStorage_SQLite_FileQuery(XSTORAGECORE_DBFILE*** pppSt_ListFile, int* pInt_ListCount, LPCTSTR lpszTimeStart = NULL, LPCTSTR lpszTimeEnd = NULL, LPCTSTR lpszBuckKey = NULL, LPCTSTR lpszFile = NULL, LPCTSTR lpszHash = NULL, LPCTSTR lpszTableName = NULL); +/************************************************************************/ +/* SQL帮助函数集 */ +/************************************************************************/ /******************************************************************** -函数名称:XStorage_SQLite_FileQueryForTable -函数功能:通过指定表名称查询所有文件 - 参数.一:pppSt_ListFile +函数名称:XStorage_SQLHelp_Insert +函数功能:数据插入函数 + 参数.一:ptszSQLBuffer In/Out:Out - 类型:三级指针 + 类型:字符指针 可空:N - 意思:输出查询到的文件信息 - 参数.二:pInt_ListCount - In/Out:Out - 类型:三级指针 + 意思:输出打好包的插入语句 + 参数.二:pSt_DBFile + In/Out:In + 类型:数据结构指针 + 可空:N + 意思:输入要插入的数据 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" BOOL XStorage_SQLHelp_Insert(TCHAR* ptszSQLBuffer, XSTORAGECORE_DBFILE* pSt_DBFile); +/******************************************************************** +函数名称:XStorage_SQLHelp_Delete +函数功能:删除语句 + 参数.一:ptszSQLBuffer + In/Out:In + 类型:字符指针 可空:N - 意思:导出获取到的列表个数 - 参数.三:lpszTableName + 意思:输出打好包的查询语句 + 参数.二:lpszTableName + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:输入要查询的表名称 + 参数.三:lpszBuckKey + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:输入BUCKET名 + 参数.四:lpszFileName + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:输入文件名称 + 参数.五:lpszFileHash In/Out:In 类型:常量字符指针 + 可空:Y + 意思:输入文件HASH值 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" BOOL XStorage_SQLHelp_Delete(TCHAR* ptszSQLBuffer, LPCTSTR lpszTableName, LPCTSTR lpszBuckKey = NULL, LPCTSTR lpszFileName = NULL, LPCTSTR lpszFileHash = NULL); +/******************************************************************** +函数名称:XStorage_SQLHelp_Query +函数功能:数据库查询打包函数 + 参数.一:ptszSQLBuffer + In/Out:In + 类型:字符指针 可空:N + 意思:输出打好包的查询语句 + 参数.二:lpszTableName + In/Out:In + 类型:常量字符指针 + 可空:Y 意思:输入要查询的表名称 + 参数.三:lpszBuckKey + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:输入BUCKET名 + 参数.四:lpszFilePath + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:输入文件路径 + 参数.五:lpszFileName + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:输入文件名称 + 参数.六:lpszFileHash + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:输入文件HASH值 + 参数.七:lpszFileUser + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:输入文件所属用户 + 参数.八:lpszTimeStart + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:输入文件开始时间范围 + 参数.九:lpszTimeEnd + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:输入文件结束时间范围 返回值 类型:逻辑型 意思:是否成功 -备注:参数一需要调用基础库的内存释放函数进行释放内存 +备注: *********************************************************************/ -extern "C" BOOL XStorage_SQLite_FileQueryForTable(XSTORAGECORE_DBFILE*** pppSt_ListFile, int* pInt_ListCount, LPCTSTR lpszTableName); \ No newline at end of file +extern "C" BOOL XStorage_SQLHelp_Query(TCHAR* ptszSQLBuffer, LPCTSTR lpszTableName, LPCTSTR lpszBuckKey = NULL, LPCTSTR lpszFilePath = NULL, LPCTSTR lpszFileName = NULL, LPCTSTR lpszFileHash = NULL, LPCTSTR lpszFileUser = NULL, LPCTSTR lpszTimeStart = NULL, LPCTSTR lpszTimeEnd = NULL); \ No newline at end of file diff --git a/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/SQLPacket_Error.h b/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/SQLPacket_Error.h index ad04d443e2ee998a5de3c6f3177c610516ba631d..822132d62625055463d4481504b9edb2978542e5 100644 --- a/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/SQLPacket_Error.h +++ b/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/SQLPacket_Error.h @@ -18,8 +18,4 @@ #define ERROR_XENGINE_XSTROGE_CORE_DB_INSERTFILE_PARAMENT 0x130B0010 //参数错误 #define ERROR_XENGINE_XSTROGE_CORE_DB_DELETEFILE_PARAMENT 0x130B0020 //参数错误 #define ERROR_XENGINE_XSTROGE_CORE_DB_QUERYFILE_PARAMENT 0x130B0030 //参数错误 -#define ERROR_XENGINE_XSTROGE_CORE_DB_QUERYFILE_EMPTY 0x130B0031 //查找数据为空 -#define ERROR_XENGINE_XSTROGE_CORE_DB_QUERYFILETABLE_PARAMENT 0x130B00B1//参数错误 -#define ERROR_XENGINE_XSTROGE_CORE_DB_QUERYFILETABLE_EMPTY 0x130B00B2 //空的表 -#define ERROR_XENGINE_XSTROGE_CORE_DB_QUERYMD5_PARAMENT 0x130B00D0 //参数错误 -#define ERROR_XENGINE_XSTROGE_CORE_DB_QUERYMD5_NOTFOUND 0x130B00D1 //没有找到 \ No newline at end of file +#define ERROR_XENGINE_XSTROGE_CORE_DB_QUERYFILE_EMPTY 0x130B0031 //查找数据为空 \ No newline at end of file diff --git a/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/XStorage_MySql/XStorage_MySql.cpp b/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/XStorage_MySql/XStorage_MySql.cpp index 080e0382ec72da118b74e5b6e8da81b28de4a7cf..1a8ce7c57fbe5aff1b2e4bb7b4239dc80c1a8b7f 100644 --- a/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/XStorage_MySql/XStorage_MySql.cpp +++ b/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/XStorage_MySql/XStorage_MySql.cpp @@ -137,24 +137,9 @@ BOOL CXStorage_MySql::XStorage_MySql_FileInsert(XSTORAGECORE_DBFILE *pSt_DBFile) } BaseLib_OperatorMemory_Free((void***)&ppSt_ListFile, nListCount); TCHAR tszSQLStatement[2048]; - TCHAR tszTableName[64]; - XENGINE_LIBTIMER st_LibTimer; - memset(tszSQLStatement, '\0', sizeof(tszSQLStatement)); - memset(tszTableName, '\0', sizeof(tszTableName)); - memset(&st_LibTimer, '\0', sizeof(XENGINE_LIBTIMER)); - //òڱ - BaseLib_OperatorTime_GetSysTime(&st_LibTimer); - if (_tcslen(pSt_DBFile->tszTableName) > 0) - { - _tcscpy(tszTableName, pSt_DBFile->tszTableName); - } - else - { - _stprintf_s(tszTableName, _T("%04d%02d"), st_LibTimer.wYear, st_LibTimer.wMonth); - } - // - _stprintf_s(tszSQLStatement, _T("INSERT INTO `%s` (BuckKey,FilePath,FileName,FileHash,FileUser,FileSize,FileTime) VALUES('%s','%s','%s','%s','%s',%lld,now())"), tszTableName, pSt_DBFile->tszBuckKey, pSt_DBFile->st_ProtocolFile.tszFilePath, pSt_DBFile->st_ProtocolFile.tszFileName, pSt_DBFile->st_ProtocolFile.tszFileHash, pSt_DBFile->st_ProtocolFile.tszFileUser, pSt_DBFile->st_ProtocolFile.nFileSize); + + XStorage_SQLHelp_Insert(tszSQLStatement, pSt_DBFile); if (!DataBase_MySQL_Execute(xhDBSQL, tszSQLStatement)) { XStorage_IsErrorOccur = TRUE; @@ -166,12 +151,17 @@ BOOL CXStorage_MySql::XStorage_MySql_FileInsert(XSTORAGECORE_DBFILE *pSt_DBFile) /******************************************************************** ƣXStorage_MySql_FileDelete ܣɾһݿļϢ - .һlpszFile + .һlpszBuckKey + In/OutIn + ַָͣ + ɿգY + ˼BUCK + .lpszFile In/OutIn ַָͣ ɿգY ˼Ҫɾļȫ· - .lpszHash + .lpszHash In/OutIn ַָͣ ɿգY @@ -181,7 +171,7 @@ BOOL CXStorage_MySql::XStorage_MySql_FileInsert(XSTORAGECORE_DBFILE *pSt_DBFile) ˼Ƿɹ עȫΪ,ɾļ *********************************************************************/ -BOOL CXStorage_MySql::XStorage_MySql_FileDelete(LPCTSTR lpszFile, LPCTSTR lpszHash) +BOOL CXStorage_MySql::XStorage_MySql_FileDelete(LPCTSTR lpszBuckKey /* = NULL */, LPCTSTR lpszFile /* = NULL */, LPCTSTR lpszHash /* = NULL */) { XStorage_IsErrorOccur = FALSE; @@ -191,7 +181,6 @@ BOOL CXStorage_MySql::XStorage_MySql_FileDelete(LPCTSTR lpszFile, LPCTSTR lpszHa XStorage_dwErrorCode = ERROR_XENGINE_XSTROGE_CORE_DB_DELETEFILE_PARAMENT; return FALSE; } - TCHAR tszSQLStatement[1024]; int nListCount = 0; XSTORAGECORE_DBFILE **ppSt_ListFile; if (!XStorage_MySql_FileQuery(&ppSt_ListFile, &nListCount, NULL, NULL, lpszFile, lpszHash)) @@ -201,15 +190,10 @@ BOOL CXStorage_MySql::XStorage_MySql_FileDelete(LPCTSTR lpszFile, LPCTSTR lpszHa //ѵɾ for (int i = 0; i < nListCount; i++) { - memset(tszSQLStatement, '\0', sizeof(tszSQLStatement)); - if (NULL == lpszHash) - { - _stprintf_s(tszSQLStatement, _T("DELETE FROM `%s` WHERE FileName = '%s'"), ppSt_ListFile[i]->tszTableName, ppSt_ListFile[i]->st_ProtocolFile.tszFileName); - } - else - { - _stprintf_s(tszSQLStatement, _T("DELETE FROM `%s` WHERE FileHash = '%s'"), ppSt_ListFile[i]->tszTableName, ppSt_ListFile[i]->st_ProtocolFile.tszFileHash); - } + TCHAR tszSQLStatement[1024]; + memset(tszSQLStatement, '\0', sizeof(tszSQLStatement)); + XStorage_SQLHelp_Delete(tszSQLStatement, ppSt_ListFile[i]->tszTableName, lpszBuckKey, lpszFile, lpszHash); + if (!DataBase_MySQL_Execute(xhDBSQL, tszSQLStatement)) { XStorage_IsErrorOccur = TRUE; @@ -243,22 +227,32 @@ BOOL CXStorage_MySql::XStorage_MySql_FileDelete(LPCTSTR lpszFile, LPCTSTR lpszHa ַָͣ ɿգY ˼ҽʱ,20190730 - .壺lpszFile + .壺lpszBuckKey + In/OutIn + ַָͣ + ɿգY + ˼ѯBUCK + .lpszFile In/OutIn ַָͣ ɿգY ˼Ҫѯ - .lpszHash + .ߣlpszHash In/OutIn ַָͣ ɿգY ˼ҪѯļHASH + .ˣlpszTableName + In/OutIn + ַָͣ + ɿգY + ˼Ҫѯı,ΪNULL ֵ ͣ߼ ˼Ƿɹ עؼٿûвҵ,¼.lpszFilelpszHashȫΪ *********************************************************************/ -BOOL CXStorage_MySql::XStorage_MySql_FileQuery(XSTORAGECORE_DBFILE*** pppSt_ListFile, int* pInt_ListCount, LPCTSTR lpszTimeStart /* = NULL */, LPCTSTR lpszTimeEnd /* = NULL */, LPCTSTR lpszBuckKey /* = NULL */, LPCTSTR lpszFile /* = NULL */, LPCTSTR lpszHash /* = NULL */) +BOOL CXStorage_MySql::XStorage_MySql_FileQuery(XSTORAGECORE_DBFILE*** pppSt_ListFile, int* pInt_ListCount, LPCTSTR lpszTimeStart /* = NULL */, LPCTSTR lpszTimeEnd /* = NULL */, LPCTSTR lpszBuckKey /* = NULL */, LPCTSTR lpszFile /* = NULL */, LPCTSTR lpszHash /* = NULL */, LPCTSTR lpszTableName /* = NULL */) { XStorage_IsErrorOccur = FALSE; @@ -272,121 +266,147 @@ BOOL CXStorage_MySql::XStorage_MySql_FileQuery(XSTORAGECORE_DBFILE*** pppSt_List XHDATA xhTable = 0; __int64u nllLine = 0; __int64u nllRow = 0; + list stl_ListFile; + TCHAR tszSQLStatement[1024]; memset(tszSQLStatement, '\0', sizeof(tszSQLStatement)); - //Ƿʱ䷶Χ - if ((NULL != lpszTimeStart) && (NULL != lpszTimeEnd)) - { - if (_tcslen(lpszTimeStart) > 0 && _tcslen(lpszTimeEnd) > 0) - { - _stprintf_s(tszSQLStatement, _T("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'XEngine_Storage' AND TABLE_NAME BETWEEN '%s' AND '%s'"), lpszTimeStart, lpszTimeEnd); - } - else - { - _stprintf_s(tszSQLStatement, _T("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'XEngine_Storage'")); - } - } - else - { - _stprintf_s(tszSQLStatement, _T("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'XEngine_Storage'")); - } - if (!DataBase_MySQL_ExecuteQuery(xhDBSQL, &xhTable, tszSQLStatement, &nllLine, &nllRow)) - { - XStorage_IsErrorOccur = TRUE; - XStorage_dwErrorCode = DataBase_GetLastError(); - return FALSE; - } - list stl_ListFile; - //ѵ - for (__int64u i = 0; i < nllLine; i++) - { - TCHAR **pptszResult = DataBase_MySQL_GetResult(xhDBSQL, xhTable); - if (NULL == pptszResult[0]) - { - continue; - } - __int64u dwLineResult = 0; - __int64u dwFieldResult = 0; - XNETHANDLE xhResult; - memset(tszSQLStatement, '\0', sizeof(tszSQLStatement)); - //жϲѯʽ - if (NULL != lpszFile) - { - if (_tcslen(lpszFile) > 0) - { - TCHAR tszFilePath[MAX_PATH]; - TCHAR tszFileName[MAX_PATH]; - - memset(tszFilePath, '\0', MAX_PATH); - memset(tszFileName, '\0', MAX_PATH); - BaseLib_OperatorString_GetFileAndPath(lpszFile, tszFilePath, tszFileName); - _stprintf_s(tszSQLStatement, _T("SELECT * FROM `%s` WHERE FilePath = '%s' AND FileName = '%s'"), pptszResult[0], tszFilePath, tszFileName); - } - else - { - _stprintf_s(tszSQLStatement, _T("SELECT * FROM `%s`"), pptszResult[0]); - } - } - if (NULL != lpszHash) - { - if (_tcslen(lpszHash) > 0) + if (NULL == lpszTableName) + { + //Ƿʱ䷶Χ + if ((NULL != lpszTimeStart) && (NULL != lpszTimeEnd)) + { + if (_tcslen(lpszTimeStart) > 0 && _tcslen(lpszTimeEnd) > 0) { - _stprintf_s(tszSQLStatement, _T("SELECT * FROM `%s` WHERE FileHash = '%s'"), pptszResult[0], lpszHash); + _stprintf_s(tszSQLStatement, _T("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'XEngine_Storage' AND TABLE_NAME BETWEEN '%s' AND '%s'"), lpszTimeStart, lpszTimeEnd); } else { - _stprintf_s(tszSQLStatement, _T("SELECT * FROM `%s`"), pptszResult[0]); + _stprintf_s(tszSQLStatement, _T("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'XEngine_Storage'")); } - } - //ѯļ - if (DataBase_MySQL_ExecuteQuery(xhDBSQL, &xhResult, tszSQLStatement, &dwLineResult, &dwFieldResult)) - { - //ѭȡвҵļ - for (__int64u j = 0; j < dwLineResult; j++) - { - TCHAR **pptszFileResult = DataBase_MySQL_GetResult(xhDBSQL, xhResult); + } + else + { + _stprintf_s(tszSQLStatement, _T("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'XEngine_Storage'")); + } + if (!DataBase_MySQL_ExecuteQuery(xhDBSQL, &xhTable, tszSQLStatement, &nllLine, &nllRow)) + { + XStorage_IsErrorOccur = TRUE; + XStorage_dwErrorCode = DataBase_GetLastError(); + return FALSE; + } + //ѵ + for (__int64u i = 0; i < nllLine; i++) + { + TCHAR** pptszResult = DataBase_MySQL_GetResult(xhDBSQL, xhTable); + if (NULL == pptszResult[0]) + { + continue; + } + __int64u dwLineResult = 0; + __int64u dwFieldResult = 0; + XNETHANDLE xhResult; + memset(tszSQLStatement, '\0', sizeof(tszSQLStatement)); + + XStorage_SQLHelp_Query(tszSQLStatement, pptszResult[0], lpszBuckKey, NULL, lpszFile, lpszHash, NULL, lpszTimeStart, lpszTimeEnd); + //ѯļ + if (DataBase_MySQL_ExecuteQuery(xhDBSQL, &xhResult, tszSQLStatement, &dwLineResult, &dwFieldResult)) + { + //ѭȡвҵļ + for (__int64u j = 0; j < dwLineResult; j++) + { + TCHAR** pptszFileResult = DataBase_MySQL_GetResult(xhDBSQL, xhResult); + + XSTORAGECORE_DBFILE st_DBFile; + memset(&st_DBFile, '\0', sizeof(XSTORAGECORE_DBFILE)); + + _tcscpy(st_DBFile.tszTableName, pptszResult[0]); + + if (NULL != pptszFileResult[1]) + { + _tcscpy(st_DBFile.tszBuckKey, pptszFileResult[1]); + } + if (NULL != pptszFileResult[2]) + { + _tcscpy(st_DBFile.st_ProtocolFile.tszFilePath, pptszFileResult[2]); + } + if (NULL != pptszFileResult[3]) + { + _tcscpy(st_DBFile.st_ProtocolFile.tszFileName, pptszFileResult[3]); + } + if (NULL != pptszFileResult[4]) + { + _tcscpy(st_DBFile.st_ProtocolFile.tszFileHash, pptszFileResult[4]); + } + if (NULL != pptszFileResult[5]) + { + _tcscpy(st_DBFile.st_ProtocolFile.tszFileUser, pptszFileResult[5]); + } + if (NULL != pptszFileResult[6]) + { + st_DBFile.st_ProtocolFile.nFileSize = _ttoi64(pptszFileResult[6]); + } + if (NULL != pptszFileResult[7]) + { + _tcscpy(st_DBFile.st_ProtocolFile.tszFileTime, pptszFileResult[7]); + } + stl_ListFile.push_back(st_DBFile); + } + DataBase_MySQL_FreeResult(xhDBSQL, xhResult); + } + } + DataBase_MySQL_FreeResult(xhDBSQL, xhTable); + } + else + { + XStorage_SQLHelp_Query(tszSQLStatement, lpszTableName, lpszBuckKey, NULL, lpszFile, lpszHash, NULL, lpszTimeStart, lpszTimeEnd); + //ѯļ + if (DataBase_MySQL_ExecuteQuery(xhDBSQL, &xhTable, tszSQLStatement, &nllLine, &nllRow)) + { + //ѭȡвҵļ + for (__int64u i = 0; i < nllLine; i++) + { + TCHAR** pptszFileResult = DataBase_MySQL_GetResult(xhDBSQL, xhTable); - XSTORAGECORE_DBFILE st_DBFile; - memset(&st_DBFile, '\0', sizeof(XSTORAGECORE_DBFILE)); + XSTORAGECORE_DBFILE st_DBFile; + memset(&st_DBFile, '\0', sizeof(XSTORAGECORE_DBFILE)); - _tcscpy(st_DBFile.tszTableName, pptszResult[0]); + _tcscpy(st_DBFile.tszTableName, lpszTableName); if (NULL != pptszFileResult[1]) { _tcscpy(st_DBFile.tszBuckKey, pptszFileResult[1]); } - if (NULL != pptszFileResult[2]) - { - _tcscpy(st_DBFile.st_ProtocolFile.tszFilePath, pptszFileResult[2]); - } - if (NULL != pptszFileResult[3]) - { - _tcscpy(st_DBFile.st_ProtocolFile.tszFileName, pptszFileResult[3]); - } + if (NULL != pptszFileResult[2]) + { + _tcscpy(st_DBFile.st_ProtocolFile.tszFilePath, pptszFileResult[2]); + } + if (NULL != pptszFileResult[3]) + { + _tcscpy(st_DBFile.st_ProtocolFile.tszFileName, pptszFileResult[3]); + } if (NULL != pptszFileResult[4]) { _tcscpy(st_DBFile.st_ProtocolFile.tszFileHash, pptszFileResult[4]); } - if (NULL != pptszFileResult[5]) - { - _tcscpy(st_DBFile.st_ProtocolFile.tszFileUser, pptszFileResult[5]); - } - if (NULL != pptszFileResult[6]) - { - st_DBFile.st_ProtocolFile.nFileSize = _ttoi64(pptszFileResult[6]); - } - if (NULL != pptszFileResult[7]) - { - _tcscpy(st_DBFile.st_ProtocolFile.tszFileTime, pptszFileResult[7]); - } - stl_ListFile.push_back(st_DBFile); - } - DataBase_MySQL_FreeResult(xhDBSQL, xhResult); - } + if (NULL != pptszFileResult[5]) + { + _tcscpy(st_DBFile.st_ProtocolFile.tszFileUser, pptszFileResult[5]); + } + if (NULL != pptszFileResult[6]) + { + st_DBFile.st_ProtocolFile.nFileSize = _ttoi64(pptszFileResult[6]); + } + if (NULL != pptszFileResult[7]) + { + _tcscpy(st_DBFile.st_ProtocolFile.tszFileTime, pptszFileResult[7]); + } + stl_ListFile.push_back(st_DBFile); + } + DataBase_MySQL_FreeResult(xhDBSQL, xhTable); + } } - DataBase_MySQL_FreeResult(xhDBSQL, xhTable); - + //ǷΪ if (stl_ListFile.empty()) { XStorage_IsErrorOccur = TRUE; @@ -404,237 +424,6 @@ BOOL CXStorage_MySql::XStorage_MySql_FileQuery(XSTORAGECORE_DBFILE*** pppSt_List stl_ListFile.clear(); return TRUE; } -/******************************************************************** -ƣXStorage_MySql_FileQueryForTable -ܣָͨƲѯļ - .һpppSt_ListFile - In/OutOut - ָͣ - ɿգN - ˼ѯļϢ - .pInt_ListCount - In/OutOut - ָͣ - ɿգN - ˼ȡб - .lpszTableName - In/OutIn - ַָͣ - ɿգN - ˼Ҫѯı -ֵ - ͣ߼ - ˼Ƿɹ -עһҪûڴͷźͷڴ -*********************************************************************/ -BOOL CXStorage_MySql::XStorage_MySql_FileQueryForTable(XSTORAGECORE_DBFILE*** pppSt_ListFile, int* pInt_ListCount, LPCTSTR lpszTableName) -{ - XStorage_IsErrorOccur = FALSE; - - if ((NULL == pppSt_ListFile) || (NULL == pInt_ListCount) || (NULL == lpszTableName)) - { - XStorage_IsErrorOccur = TRUE; - XStorage_dwErrorCode = ERROR_XENGINE_XSTROGE_CORE_DB_QUERYFILETABLE_PARAMENT; - return FALSE; - } - //ѯ - XHDATA xhTable = 0; - __int64u nllLine = 0; - __int64u nllRow = 0; - - TCHAR tszSQLStatement[1024]; - memset(tszSQLStatement, '\0', sizeof(tszSQLStatement)); - //Ƿʱ䷶Χ - _stprintf_s(tszSQLStatement, _T("SELECT * FROM `%s`"), lpszTableName); - DataBase_MySQL_ExecuteQuery(xhDBSQL, &xhTable, tszSQLStatement, &nllLine, &nllRow); - if (nllLine <= 0) - { - XStorage_IsErrorOccur = TRUE; - XStorage_dwErrorCode = ERROR_XENGINE_XSTROGE_CORE_DB_QUERYFILETABLE_EMPTY; - return FALSE; - } - BaseLib_OperatorMemory_Malloc((XPPPMEM)pppSt_ListFile, (int)nllLine, sizeof(XSTORAGECORE_DBFILE)); - //ѭȡвҵļ - for (__int64u i = 0; i < nllLine; i++) - { - TCHAR** pptszFileResult = DataBase_MySQL_GetResult(xhDBSQL, xhTable); - - _tcscpy((*pppSt_ListFile)[i]->tszTableName, lpszTableName); - - if (NULL != pptszFileResult[1]) - { - _tcscpy((*pppSt_ListFile)[i]->tszBuckKey, pptszFileResult[1]); - } - if (NULL != pptszFileResult[2]) - { - _tcscpy((*pppSt_ListFile)[i]->st_ProtocolFile.tszFilePath, pptszFileResult[2]); - } - if (NULL != pptszFileResult[3]) - { - _tcscpy((*pppSt_ListFile)[i]->st_ProtocolFile.tszFileName, pptszFileResult[3]); - } - if (NULL != pptszFileResult[4]) - { - _tcscpy((*pppSt_ListFile)[i]->st_ProtocolFile.tszFileHash, pptszFileResult[4]); - } - if (NULL != pptszFileResult[5]) - { - _tcscpy((*pppSt_ListFile)[i]->st_ProtocolFile.tszFileUser, pptszFileResult[5]); - } - if (NULL != pptszFileResult[6]) - { - (*pppSt_ListFile)[i]->st_ProtocolFile.nFileSize = _ttoi64(pptszFileResult[6]); - } - if (NULL != pptszFileResult[7]) - { - _tcscpy((*pppSt_ListFile)[i]->st_ProtocolFile.tszFileTime, pptszFileResult[7]); - } - } - DataBase_MySQL_FreeResult(xhDBSQL, xhTable); - *pInt_ListCount = (int)nllLine; - return TRUE; -} -/******************************************************************** -ƣXStorage_MySql_FileQueryForHash -ܣͨMD5ѯļϢ - .һpSt_FileInfo - In/OutOut - ͣݽṹָ - ɿգN - ˼ѯļϢ - .lpszFileHash - In/OutIn - ַָͣ - ɿգN - ˼ҪѯļMD5 - .lpszUser - In/OutIn - ַָͣ - ɿգN - ˼ļû - .ģlpszTimeStart - In/OutIn - ַָͣ - ɿգY - ˼뿪ʼʱ - .壺lpszTimeEnd - In/OutIn - ַָͣ - ɿգY - ˼ʱ -ֵ - ͣ߼ - ˼Ƿɹ -ע -*********************************************************************/ -BOOL CXStorage_MySql::XStorage_MySql_FileQueryForHash(XSTORAGECORE_DBFILE* pSt_FileInfo, LPCTSTR lpszFileHash, LPCTSTR lpszUser, LPCTSTR lpszTimeStart, LPCTSTR lpszTimeEnd) -{ - XStorage_IsErrorOccur = FALSE; - - if ((NULL == pSt_FileInfo) || (NULL == lpszFileHash)) - { - XStorage_IsErrorOccur = TRUE; - XStorage_dwErrorCode = ERROR_XENGINE_XSTROGE_CORE_DB_QUERYMD5_PARAMENT; - return FALSE; - } - //ѯ - XHDATA xhTable = 0; - __int64u nllLine = 0; - __int64u nllRow = 0; - BOOL bFound = FALSE; - TCHAR tszSQLStatement[1024]; - memset(tszSQLStatement, '\0', sizeof(tszSQLStatement)); - //Ƿʱ䷶Χ - if ((NULL != lpszTimeStart) && (NULL != lpszTimeEnd)) - { - _stprintf_s(tszSQLStatement, _T("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'XStorage_Storage' AND TABLE_NAME BETWEEN '%s' AND '%s'"), lpszTimeStart, lpszTimeEnd); - } - else - { - _stprintf_s(tszSQLStatement, _T("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'XStorage_Storage'")); - } - if (!DataBase_MySQL_ExecuteQuery(xhDBSQL, &xhTable, tszSQLStatement, &nllLine, &nllRow)) - { - XStorage_IsErrorOccur = TRUE; - XStorage_dwErrorCode = DataBase_GetLastError(); - return FALSE; - } - //ѵ - for (__int64u i = 0; i < nllLine; i++) - { - TCHAR** pptszResult = DataBase_MySQL_GetResult(xhDBSQL, xhTable); - if (NULL == pptszResult[0]) - { - continue; - } - __int64u dwLineResult = 0; - __int64u dwFieldResult = 0; - XNETHANDLE xhResult; - - memset(tszSQLStatement, '\0', sizeof(tszSQLStatement)); - //жϲѯʽ - if (NULL == lpszUser) - { - _stprintf_s(tszSQLStatement, _T("SELECT * FROM `%s` WHERE FileHash = '%s'"), pptszResult[0], lpszFileHash); - } - else - { - _stprintf_s(tszSQLStatement, _T("SELECT * FROM `%s` WHERE FileHash = '%s' AND FileUser = '%s'"), pptszResult[0], lpszFileHash, lpszUser); - } - //ѯļ - if (DataBase_MySQL_ExecuteQuery(xhDBSQL, &xhResult, tszSQLStatement, &dwLineResult, &dwFieldResult)) - { - //ѭȡвҵļ - for (__int64u j = 0; j < dwLineResult; j++) - { - TCHAR** pptszFileResult = DataBase_MySQL_GetResult(xhDBSQL, xhResult); - - _tcscpy(pSt_FileInfo->tszTableName, pptszResult[0]); - - if (NULL != pptszFileResult[1]) - { - _tcscpy(pSt_FileInfo->tszBuckKey, pptszFileResult[1]); - } - if (NULL != pptszFileResult[2]) - { - _tcscpy(pSt_FileInfo->st_ProtocolFile.tszFilePath, pptszFileResult[2]); - } - if (NULL != pptszFileResult[3]) - { - _tcscpy(pSt_FileInfo->st_ProtocolFile.tszFileName, pptszFileResult[3]); - } - if (NULL != pptszFileResult[4]) - { - _tcscpy(pSt_FileInfo->st_ProtocolFile.tszFileUser, pptszFileResult[4]); - } - if (NULL != pptszFileResult[5]) - { - pSt_FileInfo->st_ProtocolFile.nFileSize = _ttoi64(pptszFileResult[5]); - } - if (NULL != pptszFileResult[6]) - { - _tcscpy(pSt_FileInfo->st_ProtocolFile.tszFileHash, pptszFileResult[6]); - } - if (NULL != pptszFileResult[7]) - { - _tcscpy(pSt_FileInfo->st_ProtocolFile.tszFileTime, pptszFileResult[7]); - } - bFound = TRUE; - break; - } - DataBase_MySQL_FreeResult(xhDBSQL, xhResult); - } - } - DataBase_MySQL_FreeResult(xhDBSQL, xhTable); - - if (!bFound) - { - XStorage_IsErrorOccur = TRUE; - XStorage_dwErrorCode = ERROR_XENGINE_XSTROGE_CORE_DB_QUERYMD5_NOTFOUND; - return FALSE; - } - return TRUE; -} ////////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////// @@ -771,8 +560,7 @@ BOOL CXStorage_MySql::XStorage_MySql_TimeDel() //ɾļ int nListCount = 0; XSTORAGECORE_DBFILE **ppSt_ListFile; - XStorage_MySql_FileQueryForTable(&ppSt_ListFile, &nListCount, pptszResult[0]); - + XStorage_MySql_FileQuery(&ppSt_ListFile, &nListCount, NULL, NULL, NULL, NULL, NULL, pptszResult[0]); for (int i = 0; i < nListCount; i++) { //ɾļ @@ -804,6 +592,9 @@ XHTHREAD CXStorage_MySql::XStorage_MySql_Thread(LPVOID lParam) time_t nTimeEnd = 0; int nTime = 60 * 60 * 12; + pClass_This->XStorage_MySql_TimeDel(); + pClass_This->XStorage_MySql_CreateTable(); + while (pClass_This->bIsRun) { if ((nTimeEnd - nTimeStart) > nTime) diff --git a/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/XStorage_MySql/XStorage_MySql.h b/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/XStorage_MySql/XStorage_MySql.h index 40e5ee1ba2174728686779ef9af910ad34682b4a..d98ade3f67e1877e9c093ddf78eec411c85dd7b7 100644 --- a/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/XStorage_MySql/XStorage_MySql.h +++ b/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/XStorage_MySql/XStorage_MySql.h @@ -20,10 +20,8 @@ public: BOOL XStorage_MySql_Init(DATABASE_MYSQL_CONNECTINFO* pSt_DBConnector, int nTimeMonth = 1); BOOL XStorage_MySql_Destory(); BOOL XStorage_MySql_FileInsert(XSTORAGECORE_DBFILE *pSt_DBManage); - BOOL XStorage_MySql_FileDelete(LPCTSTR lpszFile = NULL, LPCTSTR lpszHash = NULL); - BOOL XStorage_MySql_FileQuery(XSTORAGECORE_DBFILE*** pppSt_ListFile, int* pInt_ListCount, LPCTSTR lpszTimeStart = NULL, LPCTSTR lpszTimeEnd = NULL, LPCTSTR lpszBuckKey = NULL, LPCTSTR lpszFile = NULL, LPCTSTR lpszHash = NULL); - BOOL XStorage_MySql_FileQueryForTable(XSTORAGECORE_DBFILE*** pppSt_ListFile, int* pInt_ListCount, LPCTSTR lpszTableName); - BOOL XStorage_MySql_FileQueryForHash(XSTORAGECORE_DBFILE* pSt_FileInfo, LPCTSTR lpszFileHash, LPCTSTR lpszUser = NULL, LPCTSTR lpszTimeStart = NULL, LPCTSTR lpszTimeEnd = NULL); + BOOL XStorage_MySql_FileDelete(LPCTSTR lpszBuckKey = NULL, LPCTSTR lpszFile = NULL, LPCTSTR lpszHash = NULL); + BOOL XStorage_MySql_FileQuery(XSTORAGECORE_DBFILE*** pppSt_ListFile, int* pInt_ListCount, LPCTSTR lpszTimeStart = NULL, LPCTSTR lpszTimeEnd = NULL, LPCTSTR lpszBuckKey = NULL, LPCTSTR lpszFile = NULL, LPCTSTR lpszHash = NULL, LPCTSTR lpszTableName = NULL); protected: BOOL XStorage_MySql_CreateTable(); BOOL XStorage_MySql_TimeMonth(LPCTSTR lpszStartTime, int* pInt_Month); diff --git a/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/XStorage_SQLHelp/XStorage_SQLHelp.cpp b/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/XStorage_SQLHelp/XStorage_SQLHelp.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4085548588fd8505a22c403f6f574b90175735d0 --- /dev/null +++ b/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/XStorage_SQLHelp/XStorage_SQLHelp.cpp @@ -0,0 +1,301 @@ +#include "pch.h" +#include "XStorage_SQLHelp.h" +/******************************************************************** +// Created: 2022/01/06 10:24:07 +// File Name: D:\XEngine_Storage\XEngine_Source\XEngine_StorageComponents\XStorage_SQLPacket\XStorage_SQLHelp\XStorage_SQLHelp.cpp +// File Path: D:\XEngine_Storage\XEngine_Source\XEngine_StorageComponents\XStorage_SQLPacket\XStorage_SQLHelp +// File Base: XStorage_SQLHelp +// File Ext: cpp +// Project: XEngine(ͨ) +// Author: qyt +// Purpose: SQLݿ﷨ +// History: +*********************************************************************/ +CXStorage_SQLHelp::CXStorage_SQLHelp() +{ +} +CXStorage_SQLHelp::~CXStorage_SQLHelp() +{ +} +////////////////////////////////////////////////////////////////////////// +// к +////////////////////////////////////////////////////////////////////////// +/******************************************************************** +ƣXStorage_SQLHelp_Insert +ܣݲ뺯 + .һptszSQLBuffer + In/OutOut + ַָͣ + ɿգN + ˼ðIJ + .pSt_DBFile + In/OutIn + ͣݽṹָ + ɿգN + ˼Ҫ +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +BOOL CXStorage_SQLHelp::XStorage_SQLHelp_Insert(TCHAR* ptszSQLBuffer, XSTORAGECORE_DBFILE* pSt_DBFile) +{ + XStorage_IsErrorOccur = FALSE; + + TCHAR tszTableName[64]; + XENGINE_LIBTIMER st_LibTimer; + + memset(tszTableName, '\0', sizeof(tszTableName)); + memset(&st_LibTimer, '\0', sizeof(XENGINE_LIBTIMER)); + //òڱ + BaseLib_OperatorTime_GetSysTime(&st_LibTimer); + + if (_tcslen(pSt_DBFile->tszTableName) > 0) + { + _tcscpy(tszTableName, pSt_DBFile->tszTableName); + } + else + { + _stprintf(tszTableName, _T("%04d%02d"), st_LibTimer.wYear, st_LibTimer.wMonth); + } + + _stprintf(ptszSQLBuffer, _T("INSERT INTO `%s` (BuckKey,FilePath,FileName,FileHash,FileUser,FileSize,FileTime) VALUES('%s','%s','%s','%s','%s',%lld,'%04d-%02d-%02d %02d:%02d:%02d')"), tszTableName, pSt_DBFile->tszBuckKey, pSt_DBFile->st_ProtocolFile.tszFilePath, pSt_DBFile->st_ProtocolFile.tszFileName, pSt_DBFile->st_ProtocolFile.tszFileHash, pSt_DBFile->st_ProtocolFile.tszFileUser, pSt_DBFile->st_ProtocolFile.nFileSize, st_LibTimer.wYear, st_LibTimer.wMonth, st_LibTimer.wDay, st_LibTimer.wHour, st_LibTimer.wMinute, st_LibTimer.wSecond); + return TRUE; +} +/******************************************************************** +ƣXStorage_SQLHelp_Delete +ܣɾ + .һptszSQLBuffer + In/OutIn + ַָͣ + ɿգN + ˼ðIJѯ + .lpszTableName + In/OutIn + ַָͣ + ɿգY + ˼Ҫѯı + .lpszBuckKey + In/OutIn + ַָͣ + ɿգY + ˼BUCKET + .ģlpszFileName + In/OutIn + ַָͣ + ɿգY + ˼ļ + .壺lpszFileHash + In/OutIn + ַָͣ + ɿգY + ˼ļHASHֵ +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +BOOL CXStorage_SQLHelp::XStorage_SQLHelp_Delete(TCHAR* ptszSQLBuffer, LPCTSTR lpszTableName, LPCTSTR lpszBuckKey /* = NULL */, LPCTSTR lpszFileName /* = NULL */, LPCTSTR lpszFileHash /* = NULL */) +{ + XStorage_IsErrorOccur = FALSE; + + TCHAR tszSQLQuery[1024]; + memset(tszSQLQuery, '\0', sizeof(tszSQLQuery)); + + XStorage_SQLHelp_Packet(tszSQLQuery, lpszBuckKey, NULL, lpszFileName, lpszFileHash); + _stprintf(ptszSQLBuffer, _T("DELETE FROM `%s` %s"), lpszTableName, tszSQLQuery); + return TRUE; +} +/******************************************************************** +ƣXStorage_SQLHelp_Query +ܣݿѯ + .һptszSQLBuffer + In/OutIn + ַָͣ + ɿգN + ˼ðIJѯ + .lpszTableName + In/OutIn + ַָͣ + ɿգY + ˼Ҫѯı + .lpszBuckKey + In/OutIn + ַָͣ + ɿգY + ˼BUCKET + .ģlpszFilePath + In/OutIn + ַָͣ + ɿգY + ˼ļ· + .壺lpszFileName + In/OutIn + ַָͣ + ɿգY + ˼ļ + .lpszFileHash + In/OutIn + ַָͣ + ɿգY + ˼ļHASHֵ + .ߣlpszFileUser + In/OutIn + ַָͣ + ɿգY + ˼ļû + .ˣlpszTimeStart + In/OutIn + ַָͣ + ɿգY + ˼ļʼʱ䷶Χ + .ţlpszTimeEnd + In/OutIn + ַָͣ + ɿգY + ˼ļʱ䷶Χ +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +BOOL CXStorage_SQLHelp::XStorage_SQLHelp_Query(TCHAR* ptszSQLBuffer, LPCTSTR lpszTableName, LPCTSTR lpszBuckKey /* = NULL */, LPCTSTR lpszFilePath /* = NULL */, LPCTSTR lpszFileName /* = NULL */, LPCTSTR lpszFileHash /* = NULL */, LPCTSTR lpszFileUser /* = NULL */, LPCTSTR lpszTimeStart /* = NULL */, LPCTSTR lpszTimeEnd /* = NULL */) +{ + XStorage_IsErrorOccur = FALSE; + + BOOL bInit = FALSE; + TCHAR tszSQLQuery[1024]; + memset(tszSQLQuery, '\0', sizeof(tszSQLQuery)); + + _stprintf(ptszSQLBuffer, _T("SELECT * FROM `%s`"), lpszTableName); + XStorage_SQLHelp_Packet(tszSQLQuery, lpszBuckKey, lpszFilePath, lpszFileName, lpszFileHash, lpszFileUser, lpszTimeStart, lpszTimeEnd); + _tcscat(ptszSQLBuffer, tszSQLQuery); + return TRUE; +} +////////////////////////////////////////////////////////////////////////// +// +////////////////////////////////////////////////////////////////////////// +BOOL CXStorage_SQLHelp::XStorage_SQLHelp_Packet(TCHAR* ptszSQLBuffer, LPCTSTR lpszBuckKey /* = NULL */, LPCTSTR lpszFilePath /* = NULL */, LPCTSTR lpszFileName /* = NULL */, LPCTSTR lpszFileHash /* = NULL */, LPCTSTR lpszFileUser /* = NULL */, LPCTSTR lpszTimeStart /* = NULL */, LPCTSTR lpszTimeEnd /* = NULL */) +{ + XStorage_IsErrorOccur = FALSE; + + BOOL bInit = FALSE; + TCHAR tszSQLQuery[MAX_PATH]; + memset(tszSQLQuery, '\0', MAX_PATH); + //ļBUCKET + if (NULL != lpszBuckKey) + { + if (_tcslen(lpszBuckKey) > 0) + { + if (bInit) + { + _tcscat(ptszSQLBuffer, _T(" AND ")); + } + else + { + _tcscat(ptszSQLBuffer, _T(" WHERE ")); + } + memset(tszSQLQuery, '\0', MAX_PATH); + _stprintf(tszSQLQuery, _T("BuckKey = '%s'"), lpszBuckKey); + _tcscat(ptszSQLBuffer, tszSQLQuery); + bInit = TRUE; + } + } + //ļ· + if (NULL != lpszFilePath) + { + if (_tcslen(lpszFilePath) > 0) + { + if (bInit) + { + _tcscat(ptszSQLBuffer, _T(" AND ")); + } + else + { + _tcscat(ptszSQLBuffer, _T("WHERE ")); + } + memset(tszSQLQuery, '\0', MAX_PATH); + _stprintf(tszSQLQuery, _T("FilePath = '%s'"), lpszFilePath); + _tcscat(ptszSQLBuffer, tszSQLQuery); + bInit = TRUE; + } + } + //ļ + if (NULL != lpszFileName) + { + if (_tcslen(lpszFileName) > 0) + { + if (bInit) + { + _tcscat(ptszSQLBuffer, _T(" AND ")); + } + else + { + _tcscat(ptszSQLBuffer, _T("WHERE ")); + } + memset(tszSQLQuery, '\0', MAX_PATH); + _stprintf(tszSQLQuery, _T("FileName = '%s'"), lpszFileName); + _tcscat(ptszSQLBuffer, tszSQLQuery); + bInit = TRUE; + } + } + //ļHASH + if (NULL != lpszFileHash) + { + if (_tcslen(lpszFileHash) > 0) + { + if (bInit) + { + _tcscat(ptszSQLBuffer, _T(" AND ")); + } + else + { + _tcscat(ptszSQLBuffer, _T("WHERE ")); + } + memset(tszSQLQuery, '\0', MAX_PATH); + _stprintf(tszSQLQuery, _T("FileHash = '%s'"), lpszFileHash); + _tcscat(ptszSQLBuffer, tszSQLQuery); + bInit = TRUE; + } + } + //ļû + if (NULL != lpszFileUser) + { + if (_tcslen(lpszFileUser) > 0) + { + if (bInit) + { + _tcscat(ptszSQLBuffer, _T(" AND ")); + } + else + { + _tcscat(ptszSQLBuffer, _T("WHERE ")); + } + memset(tszSQLQuery, '\0', MAX_PATH); + _stprintf(tszSQLQuery, _T("FileUser = '%s'"), lpszFileUser); + _tcscat(ptszSQLBuffer, tszSQLQuery); + bInit = TRUE; + } + } + //ʱ䷶Χ + if ((NULL != lpszTimeStart) && (NULL != lpszTimeEnd)) + { + if ((_tcslen(lpszTimeStart) > 0) && (_tcslen(lpszTimeEnd) > 0)) + { + if (bInit) + { + _tcscat(ptszSQLBuffer, _T(" AND ")); + } + else + { + _tcscat(ptszSQLBuffer, _T("WHERE ")); + } + memset(tszSQLQuery, '\0', MAX_PATH); + _stprintf(tszSQLQuery, _T("BETWEEN '%s' AND '%s'"), lpszTimeStart, lpszTimeEnd); + _tcscat(ptszSQLBuffer, tszSQLQuery); + bInit = TRUE; + } + } + + return TRUE; +} \ No newline at end of file diff --git a/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/XStorage_SQLHelp/XStorage_SQLHelp.h b/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/XStorage_SQLHelp/XStorage_SQLHelp.h new file mode 100644 index 0000000000000000000000000000000000000000..3be251235aa3fc2b965323ca27268e1b3a933f03 --- /dev/null +++ b/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/XStorage_SQLHelp/XStorage_SQLHelp.h @@ -0,0 +1,25 @@ +#pragma once +/******************************************************************** +// Created: 2022/01/06 10:23:13 +// File Name: D:\XEngine_Storage\XEngine_Source\XEngine_StorageComponents\XStorage_SQLPacket\XStorage_SQLHelp\XStorage_SQLHelp.h +// File Path: D:\XEngine_Storage\XEngine_Source\XEngine_StorageComponents\XStorage_SQLPacket\XStorage_SQLHelp +// File Base: XStorage_SQLHelp +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: SQL数据库语法帮助类 +// History: +*********************************************************************/ + +class CXStorage_SQLHelp +{ +public: + CXStorage_SQLHelp(); + ~CXStorage_SQLHelp(); +public: + BOOL XStorage_SQLHelp_Insert(TCHAR* ptszSQLBuffer, XSTORAGECORE_DBFILE* pSt_DBFile); + BOOL XStorage_SQLHelp_Delete(TCHAR* ptszSQLBuffer, LPCTSTR lpszTableName, LPCTSTR lpszBuckKey = NULL, LPCTSTR lpszFileName = NULL, LPCTSTR lpszFileHash = NULL); + BOOL XStorage_SQLHelp_Query(TCHAR* ptszSQLBuffer, LPCTSTR lpszTableName, LPCTSTR lpszBuckKey = NULL, LPCTSTR lpszFilePath = NULL, LPCTSTR lpszFileName = NULL, LPCTSTR lpszFileHash = NULL, LPCTSTR lpszFileUser = NULL, LPCTSTR lpszTimeStart = NULL, LPCTSTR lpszTimeEnd = NULL); +protected: + BOOL XStorage_SQLHelp_Packet(TCHAR* ptszSQLBuffer, LPCTSTR lpszBuckKey = NULL, LPCTSTR lpszFilePath = NULL, LPCTSTR lpszFileName = NULL, LPCTSTR lpszFileHash = NULL, LPCTSTR lpszFileUser = NULL, LPCTSTR lpszTimeStart = NULL, LPCTSTR lpszTimeEnd = NULL); +}; diff --git a/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/XStorage_SQLPacket.def b/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/XStorage_SQLPacket.def index 71311abe9b62c40e67abe8f05f00cd68ceab29ac..d1c67342e11bb2d602c2ed0cab58277b7b42904c 100644 --- a/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/XStorage_SQLPacket.def +++ b/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/XStorage_SQLPacket.def @@ -8,12 +8,9 @@ EXPORTS XStorage_MySql_FileInsert XStorage_MySql_FileDelete XStorage_MySql_FileQuery - XStorage_MySql_FileQueryForTable - XStorage_MySql_FileQueryForHash XStorage_SQLite_Init XStorage_SQLite_Destory XStorage_SQLite_FileInsert XStorage_SQLite_FileDelete - XStorage_SQLite_FileQuery - XStorage_SQLite_FileQueryForTable \ No newline at end of file + XStorage_SQLite_FileQuery \ No newline at end of file diff --git a/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/XStorage_SQLite/XStorage_SQLite.cpp b/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/XStorage_SQLite/XStorage_SQLite.cpp index 8e647d5aa9027e1dc9c3f8717b78e7ff1e894f40..891ab4e1d8a7f9f4a21f073e335a94db7069b2a6 100644 --- a/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/XStorage_SQLite/XStorage_SQLite.cpp +++ b/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/XStorage_SQLite/XStorage_SQLite.cpp @@ -136,25 +136,10 @@ BOOL CXStorage_SQLite::XStorage_SQLite_FileInsert(XSTORAGECORE_DBFILE* pSt_DBFil return TRUE; } BaseLib_OperatorMemory_Free((void***)&ppSt_ListFile, nListCount); - TCHAR tszSQLStatement[2048]; - TCHAR tszTableName[64]; - XENGINE_LIBTIMER st_LibTimer; + TCHAR tszSQLStatement[2048]; + memset(tszSQLStatement, '\0', sizeof(tszSQLStatement)); - memset(tszSQLStatement, '\0', sizeof(tszSQLStatement)); - memset(tszTableName, '\0', sizeof(tszTableName)); - memset(&st_LibTimer, '\0', sizeof(XENGINE_LIBTIMER)); - //获得插入日期表 - BaseLib_OperatorTime_GetSysTime(&st_LibTimer); - if (_tcslen(pSt_DBFile->tszTableName) > 0) - { - _tcscpy(tszTableName, pSt_DBFile->tszTableName); - } - else - { - _stprintf_s(tszTableName, _T("%04d%02d"), st_LibTimer.wYear, st_LibTimer.wMonth); - } - //插入语句 - _stprintf_s(tszSQLStatement, _T("INSERT INTO `%s` (BuckKey,FilePath,FileName,FileHash,FileUser,FileSize,FileTime) VALUES('%s','%s','%s','%s','%s',%lld,DATETIME('now', 'localtime'))"), tszTableName, pSt_DBFile->tszBuckKey, pSt_DBFile->st_ProtocolFile.tszFilePath, pSt_DBFile->st_ProtocolFile.tszFileName, pSt_DBFile->st_ProtocolFile.tszFileHash, pSt_DBFile->st_ProtocolFile.tszFileUser, pSt_DBFile->st_ProtocolFile.nFileSize); + XStorage_SQLHelp_Insert(tszSQLStatement, pSt_DBFile); if (!DataBase_SQLite_Exec(xhSQL, tszSQLStatement)) { XStorage_IsErrorOccur = TRUE; @@ -166,12 +151,17 @@ BOOL CXStorage_SQLite::XStorage_SQLite_FileInsert(XSTORAGECORE_DBFILE* pSt_DBFil /******************************************************************** 函数名称:XStorage_SQLite_FileDelete 函数功能:删除一个数据库文件信息 - 参数.一:lpszFile + 参数.一:lpszBuckKey + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:所属BUCK名称 + 参数.二:lpszFile In/Out:In 类型:常量字符指针 可空:Y 意思:要删除的文件全路径 - 参数.二:lpszHash + 参数.三:lpszHash In/Out:In 类型:常量字符指针 可空:Y @@ -181,7 +171,7 @@ BOOL CXStorage_SQLite::XStorage_SQLite_FileInsert(XSTORAGECORE_DBFILE* pSt_DBFil 意思:是否成功 备注:参数不能全为空,不会删除文件 *********************************************************************/ -BOOL CXStorage_SQLite::XStorage_SQLite_FileDelete(LPCTSTR lpszFile, LPCTSTR lpszHash) +BOOL CXStorage_SQLite::XStorage_SQLite_FileDelete(LPCTSTR lpszBuckKey /* = NULL */, LPCTSTR lpszFile /* = NULL */, LPCTSTR lpszHash /* = NULL */) { XStorage_IsErrorOccur = FALSE; @@ -191,25 +181,19 @@ BOOL CXStorage_SQLite::XStorage_SQLite_FileDelete(LPCTSTR lpszFile, LPCTSTR lpsz XStorage_dwErrorCode = ERROR_XENGINE_XSTROGE_CORE_DB_DELETEFILE_PARAMENT; return FALSE; } - TCHAR tszSQLStatement[1024]; int nListCount = 0; XSTORAGECORE_DBFILE** ppSt_ListFile; - if (!XStorage_SQLite_FileQuery(&ppSt_ListFile, &nListCount, NULL, NULL, lpszFile, lpszHash)) + if (!XStorage_SQLite_FileQuery(&ppSt_ListFile, &nListCount, NULL, NULL, lpszBuckKey, lpszFile, lpszHash)) { return FALSE; } //轮训查找删除 for (int i = 0; i < nListCount; i++) { + TCHAR tszSQLStatement[1024]; memset(tszSQLStatement, '\0', sizeof(tszSQLStatement)); - if (NULL == lpszHash) - { - _stprintf_s(tszSQLStatement, _T("DELETE FROM `%s` WHERE FileName = '%s'"), ppSt_ListFile[i]->tszTableName, ppSt_ListFile[i]->st_ProtocolFile.tszFileName); - } - else - { - _stprintf_s(tszSQLStatement, _T("DELETE FROM `%s` WHERE FileHash = '%s'"), ppSt_ListFile[i]->tszTableName, ppSt_ListFile[i]->st_ProtocolFile.tszFileHash); - } + XStorage_SQLHelp_Delete(tszSQLStatement, ppSt_ListFile[i]->tszTableName, lpszBuckKey, lpszFile, lpszHash); + if (!DataBase_SQLite_Exec(xhSQL, tszSQLStatement)) { XStorage_IsErrorOccur = TRUE; @@ -243,22 +227,32 @@ BOOL CXStorage_SQLite::XStorage_SQLite_FileDelete(LPCTSTR lpszFile, LPCTSTR lpsz 类型:常量字符指针 可空:Y 意思:查找结束时间,20190730 - 参数.五:lpszFile + 参数.五:lpszBuckKey + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:查询的BUCK名 + 参数.六:lpszFile In/Out:In 类型:常量字符指针 可空:Y 意思:要查询的名称 - 参数.六:lpszHash + 参数.七:lpszHash In/Out:In 类型:常量字符指针 可空:Y 意思:要查询的文件HASH + 参数.八:lpszTableName + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:输入要查询的表明,为NULL所有 返回值 类型:逻辑型 意思:是否成功 备注:返回假可能没有查找到,这条记录不存在.参数lpszFile和lpszHash不能全为空 *********************************************************************/ -BOOL CXStorage_SQLite::XStorage_SQLite_FileQuery(XSTORAGECORE_DBFILE*** pppSt_ListFile, int* pInt_ListCount, LPCTSTR lpszTimeStart /* = NULL */, LPCTSTR lpszTimeEnd /* = NULL */, LPCTSTR lpszFile /* = NULL */, LPCTSTR lpszHash /* = NULL */) +BOOL CXStorage_SQLite::XStorage_SQLite_FileQuery(XSTORAGECORE_DBFILE*** pppSt_ListFile, int* pInt_ListCount, LPCTSTR lpszTimeStart /* = NULL */, LPCTSTR lpszTimeEnd /* = NULL */, LPCTSTR lpszBuckKey /* = NULL */, LPCTSTR lpszFile /* = NULL */, LPCTSTR lpszHash /* = NULL */, LPCTSTR lpszTableName /* = NULL */) { XStorage_IsErrorOccur = FALSE; @@ -273,110 +267,126 @@ BOOL CXStorage_SQLite::XStorage_SQLite_FileQuery(XSTORAGECORE_DBFILE*** pppSt_Li int nRow = 0; TCHAR** pptszResult; TCHAR tszSQLStatement[1024]; + list stl_ListFile; + memset(tszSQLStatement, '\0', sizeof(tszSQLStatement)); - //检查是否时间范围检索 - if ((NULL != lpszTimeStart) && (NULL != lpszTimeEnd)) + if (NULL == lpszTableName) { - if (_tcslen(lpszTimeStart) > 0 && _tcslen(lpszTimeEnd) > 0) - { - _stprintf_s(tszSQLStatement, _T("SELECT NAME FROM SQLITE_MASTER WHERE TYPE = 'table' AND NAME BETWEEN '%s' AND '%s'"), lpszTimeStart, lpszTimeEnd); - } - else - { - _stprintf_s(tszSQLStatement, _T("SELECT NAME FROM SQLITE_MASTER WHERE TYPE = 'table'")); - } - } - else - { - _stprintf_s(tszSQLStatement, _T("SELECT NAME FROM SQLITE_MASTER WHERE TYPE = 'table'")); - } - if (!DataBase_SQLite_GetTable(xhSQL, tszSQLStatement, &pptszResult, &nLine, &nRow)) - { - XStorage_IsErrorOccur = TRUE; - XStorage_dwErrorCode = DataBase_GetLastError(); - return FALSE; - } - list stl_ListFile; - //轮训 - for (int i = 0; i < nLine; i++) - { - if (!XStorage_SQLite_IsNumber(pptszResult[i])) - { - continue; - } - int nLineResult = 0; - int nFieldResult = 0; - memset(tszSQLStatement, '\0', sizeof(tszSQLStatement)); - //判断查询方式 - if (NULL != lpszFile) + //检查是否时间范围检索 + if ((NULL != lpszTimeStart) && (NULL != lpszTimeEnd)) { - if (_tcslen(lpszFile) > 0) + if (_tcslen(lpszTimeStart) > 0 && _tcslen(lpszTimeEnd) > 0) { - TCHAR tszFilePath[MAX_PATH]; - TCHAR tszFileName[MAX_PATH]; - - memset(tszFilePath, '\0', MAX_PATH); - memset(tszFileName, '\0', MAX_PATH); - - BaseLib_OperatorString_GetFileAndPath(lpszFile, tszFilePath, tszFileName); - _stprintf_s(tszSQLStatement, _T("SELECT * FROM `%s` WHERE FilePath = '%s' AND FileName = '%s'"), pptszResult[i], tszFilePath, tszFileName); + _stprintf_s(tszSQLStatement, _T("SELECT NAME FROM SQLITE_MASTER WHERE TYPE = 'table' AND NAME BETWEEN '%s' AND '%s'"), lpszTimeStart, lpszTimeEnd); } else { - _stprintf_s(tszSQLStatement, _T("SELECT * FROM `%s`"), pptszResult[i]); + _stprintf_s(tszSQLStatement, _T("SELECT NAME FROM SQLITE_MASTER WHERE TYPE = 'table'")); } } - if (NULL != lpszHash) + else + { + _stprintf_s(tszSQLStatement, _T("SELECT NAME FROM SQLITE_MASTER WHERE TYPE = 'table'")); + } + if (!DataBase_SQLite_GetTable(xhSQL, tszSQLStatement, &pptszResult, &nLine, &nRow)) { - if (_tcslen(lpszHash) > 0) + XStorage_IsErrorOccur = TRUE; + XStorage_dwErrorCode = DataBase_GetLastError(); + return FALSE; + } + //轮训 + for (int i = 0; i < nLine; i++) + { + if (!XStorage_SQLite_IsNumber(pptszResult[i])) { - _stprintf_s(tszSQLStatement, _T("SELECT * FROM `%s` WHERE FileHash = '%s'"), pptszResult[i], lpszHash); + continue; } - else + int nLineResult = 0; + int nFieldResult = 0; + memset(tszSQLStatement, '\0', sizeof(tszSQLStatement)); + XStorage_SQLHelp_Query(tszSQLStatement, pptszResult[i], lpszBuckKey, NULL, lpszFile, lpszHash, NULL, lpszTimeStart, lpszTimeEnd); + //查询文件 + TCHAR** pptszFileResult; + if (DataBase_SQLite_GetTable(xhSQL, tszSQLStatement, &pptszFileResult, &nLineResult, &nFieldResult)) { - _stprintf_s(tszSQLStatement, _T("SELECT * FROM `%s`"), pptszResult[i]); + int nFiled = nFieldResult; + //循环获取所有查找到的文件 + for (int j = 0; j < nLineResult; j++) + { + XSTORAGECORE_DBFILE st_DBFile; + memset(&st_DBFile, '\0', sizeof(XSTORAGECORE_DBFILE)); + + _tcscpy(st_DBFile.tszTableName, pptszResult[i]); + nFiled++; + + _tcscpy(st_DBFile.tszBuckKey, pptszFileResult[nFiled]); + nFiled++; + + _tcscpy(st_DBFile.st_ProtocolFile.tszFilePath, pptszFileResult[nFiled]); + nFiled++; + + _tcscpy(st_DBFile.st_ProtocolFile.tszFileName, pptszFileResult[nFiled]); + nFiled++; + + _tcscpy(st_DBFile.st_ProtocolFile.tszFileHash, pptszFileResult[nFiled]); + nFiled++; + + _tcscpy(st_DBFile.st_ProtocolFile.tszFileUser, pptszFileResult[nFiled]); + nFiled++; + + st_DBFile.st_ProtocolFile.nFileSize = _ttoi64(pptszFileResult[nFiled]); + nFiled++; + + _tcscpy(st_DBFile.st_ProtocolFile.tszFileTime, pptszFileResult[nFiled]); + nFiled++; + stl_ListFile.push_back(st_DBFile); + } + DataBase_SQLite_FreeTable(pptszFileResult); } } - //查询文件 - TCHAR** pptszFileResult; - if (DataBase_SQLite_GetTable(xhSQL, tszSQLStatement, &pptszFileResult, &nLineResult, &nFieldResult)) + DataBase_SQLite_FreeTable(pptszResult); + } + else + { + XStorage_SQLHelp_Query(tszSQLStatement, lpszTableName, lpszBuckKey, NULL, lpszFile, lpszHash, NULL, lpszTimeStart, lpszTimeEnd); + TCHAR** pptszFileResult; + if (DataBase_SQLite_GetTable(xhSQL, tszSQLStatement, &pptszFileResult, &nLine, &nRow)) { - int nFiled = nFieldResult; + int nFiled = nRow; //循环获取所有查找到的文件 - for (int j = 0; j < nLineResult; j++) + for (int i = 0; i < nLine; i++) { XSTORAGECORE_DBFILE st_DBFile; memset(&st_DBFile, '\0', sizeof(XSTORAGECORE_DBFILE)); - _tcscpy(st_DBFile.tszTableName, pptszResult[i]); - nFiled++; + _tcscpy(st_DBFile.tszTableName, lpszTableName); + nFiled++; _tcscpy(st_DBFile.tszBuckKey, pptszFileResult[nFiled]); nFiled++; - _tcscpy(st_DBFile.st_ProtocolFile.tszFilePath, pptszFileResult[nFiled]); - nFiled++; + _tcscpy(st_DBFile.st_ProtocolFile.tszFilePath, pptszFileResult[nFiled]); + nFiled++; _tcscpy(st_DBFile.st_ProtocolFile.tszFileName, pptszFileResult[nFiled]); nFiled++; _tcscpy(st_DBFile.st_ProtocolFile.tszFileHash, pptszFileResult[nFiled]); nFiled++; - + _tcscpy(st_DBFile.st_ProtocolFile.tszFileUser, pptszFileResult[nFiled]); nFiled++; st_DBFile.st_ProtocolFile.nFileSize = _ttoi64(pptszFileResult[nFiled]); nFiled++; - + _tcscpy(st_DBFile.st_ProtocolFile.tszFileTime, pptszFileResult[nFiled]); nFiled++; stl_ListFile.push_back(st_DBFile); } DataBase_SQLite_FreeTable(pptszFileResult); } - } - DataBase_SQLite_FreeTable(pptszResult); + } if (stl_ListFile.empty()) { XStorage_IsErrorOccur = TRUE; @@ -394,88 +404,6 @@ BOOL CXStorage_SQLite::XStorage_SQLite_FileQuery(XSTORAGECORE_DBFILE*** pppSt_Li stl_ListFile.clear(); return TRUE; } -/******************************************************************** -函数名称:XStorage_SQLite_FileQueryForTable -函数功能:通过指定表名称查询所有文件 - 参数.一:pppSt_ListFile - In/Out:Out - 类型:三级指针 - 可空:N - 意思:输出查询到的文件信息 - 参数.二:pInt_ListCount - In/Out:Out - 类型:三级指针 - 可空:N - 意思:导出获取到的列表个数 - 参数.三:lpszTableName - In/Out:In - 类型:常量字符指针 - 可空:N - 意思:输入要查询的表名称 -返回值 - 类型:逻辑型 - 意思:是否成功 -备注:参数一需要调用基础库的内存释放函数进行释放内存 -*********************************************************************/ -BOOL CXStorage_SQLite::XStorage_SQLite_FileQueryForTable(XSTORAGECORE_DBFILE*** pppSt_ListFile, int* pInt_ListCount, LPCTSTR lpszTableName) -{ - XStorage_IsErrorOccur = FALSE; - - if ((NULL == pppSt_ListFile) || (NULL == pInt_ListCount) || (NULL == lpszTableName)) - { - XStorage_IsErrorOccur = TRUE; - XStorage_dwErrorCode = ERROR_XENGINE_XSTROGE_CORE_DB_QUERYFILETABLE_PARAMENT; - return FALSE; - } - //查询 - XHDATA xhTable = 0; - int nLine = 0; - int nRow = 0; - TCHAR** pptszResulte; - TCHAR tszSQLStatement[1024]; - memset(tszSQLStatement, '\0', sizeof(tszSQLStatement)); - //检查是否时间范围检索 - _stprintf_s(tszSQLStatement, _T("SELECT * FROM `%s`"), lpszTableName); - DataBase_SQLite_GetTable(xhSQL, tszSQLStatement, &pptszResulte, &nLine, &nRow); - if (nLine <= 0) - { - XStorage_IsErrorOccur = TRUE; - XStorage_dwErrorCode = ERROR_XENGINE_XSTROGE_CORE_DB_QUERYFILETABLE_EMPTY; - return FALSE; - } - *pInt_ListCount = nLine; - BaseLib_OperatorMemory_Malloc((XPPPMEM)pppSt_ListFile, nLine, sizeof(XSTORAGECORE_DBFILE)); - //循环获取所有查找到的文件 - int nFiled = nRow; - for (int i = 0; i < nLine; i++) - { - nFiled++; - _tcscpy((*pppSt_ListFile)[i]->tszTableName, lpszTableName); - - _tcscpy((*pppSt_ListFile)[i]->tszBuckKey, pptszResulte[nFiled]); - nFiled++; - - _tcscpy((*pppSt_ListFile)[i]->st_ProtocolFile.tszFilePath, pptszResulte[nFiled]); - nFiled++; - - _tcscpy((*pppSt_ListFile)[i]->st_ProtocolFile.tszFileName, pptszResulte[nFiled]); - nFiled++; - - _tcscpy((*pppSt_ListFile)[i]->st_ProtocolFile.tszFileHash, pptszResulte[nFiled]); - nFiled++; - - _tcscpy((*pppSt_ListFile)[i]->st_ProtocolFile.tszFileUser, pptszResulte[nFiled]); - nFiled++; - - (*pppSt_ListFile)[i]->st_ProtocolFile.nFileSize = _ttoi64(pptszResulte[nFiled]); - nFiled++; - - _tcscpy((*pppSt_ListFile)[i]->st_ProtocolFile.tszFileTime, pptszResulte[nFiled]); - nFiled++; - } - DataBase_MySQL_FreeResult(xhSQL, xhTable); - return TRUE; -} ////////////////////////////////////////////////////////////////////////// // 保护函数 ////////////////////////////////////////////////////////////////////////// @@ -612,7 +540,7 @@ BOOL CXStorage_SQLite::XStorage_SQLite_TimeDel() //删除文件 int nListCount = 0; XSTORAGECORE_DBFILE** ppSt_ListFile; - XStorage_SQLite_FileQueryForTable(&ppSt_ListFile, &nListCount, pptszResult[i]); + XStorage_SQLite_FileQuery(&ppSt_ListFile, &nListCount, NULL, NULL, NULL, NULL, NULL, pptszResult[i]); for (int i = 0; i < nListCount; i++) { //删除文件 @@ -656,6 +584,9 @@ XHTHREAD CXStorage_SQLite::XStorage_SQLite_Thread(LPVOID lParam) time_t nTimeEnd = 0; int nTime = 60 * 60 * 12; + pClass_This->XStorage_SQLite_TimeDel(); + pClass_This->XStorage_SQLite_CreateTable(); + while (pClass_This->bIsRun) { if ((nTimeEnd - nTimeStart) > nTime) diff --git a/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/XStorage_SQLite/XStorage_SQLite.h b/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/XStorage_SQLite/XStorage_SQLite.h index 5472654eff708037f4362bbf7dc1b1ef0c8849e9..bbf2e2047bcad18cd7c5663b0364f86ad489942f 100644 --- a/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/XStorage_SQLite/XStorage_SQLite.h +++ b/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/XStorage_SQLite/XStorage_SQLite.h @@ -21,9 +21,8 @@ public: BOOL XStorage_SQLite_Init(LPCTSTR lpszSQLFile, int nTimeMonth = 1); BOOL XStorage_SQLite_Destory(); BOOL XStorage_SQLite_FileInsert(XSTORAGECORE_DBFILE* pSt_DBManage); - BOOL XStorage_SQLite_FileDelete(LPCTSTR lpszFile = NULL, LPCTSTR lpszHash = NULL); - BOOL XStorage_SQLite_FileQuery(XSTORAGECORE_DBFILE*** pppSt_ListFile, int* pInt_ListCount, LPCTSTR lpszTimeStart = NULL, LPCTSTR lpszTimeEnd = NULL, LPCTSTR lpszFile = NULL, LPCTSTR lpszHash = NULL); - BOOL XStorage_SQLite_FileQueryForTable(XSTORAGECORE_DBFILE*** pppSt_ListFile, int* pInt_ListCount, LPCTSTR lpszTableName); + BOOL XStorage_SQLite_FileDelete(LPCTSTR lpszBuckKey = NULL, LPCTSTR lpszFile = NULL, LPCTSTR lpszHash = NULL); + BOOL XStorage_SQLite_FileQuery(XSTORAGECORE_DBFILE*** pppSt_ListFile, int* pInt_ListCount, LPCTSTR lpszTimeStart = NULL, LPCTSTR lpszTimeEnd = NULL, LPCTSTR lpszBuckKey = NULL, LPCTSTR lpszFile = NULL, LPCTSTR lpszHash = NULL, LPCTSTR lpszTableName = NULL); protected: BOOL XStorage_SQLite_CreateTable(); BOOL XStorage_SQLite_TimeMonth(LPCTSTR lpszStartTime, int* pInt_Month); diff --git a/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/pch.cpp b/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/pch.cpp index 8df24de1792182988fb0bdb7ce07331268846941..1b9118aea2de3e1cd07e2eb646dae20951a9e40f 100644 --- a/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/pch.cpp +++ b/XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/pch.cpp @@ -1,6 +1,7 @@ #include "pch.h" #include "XStorage_MySql/XStorage_MySql.h" #include "XStorage_SQLite/XStorage_SQLite.h" +#include "XStorage_SQLHelp/XStorage_SQLHelp.h" /******************************************************************** // Created: 2021/06/10 11:10:16 // File Name: D:\XEngine_Storage\XEngine_Source\XEngine_StorageComponents\XStorage_SQLPacket\pch.cpp @@ -17,6 +18,7 @@ DWORD XStorage_dwErrorCode = 0; ////////////////////////////////////////////////////////////////////////// CXStorage_MySql m_MySql; CXStorage_SQLite m_SQLite; +CXStorage_SQLHelp m_SQLHelp; ////////////////////////////////////////////////////////////////////////// /// 导出的函数 ////////////////////////////////////////////////////////////////////////// @@ -43,21 +45,13 @@ extern "C" BOOL XStorage_MySql_FileInsert(XSTORAGECORE_DBFILE * pSt_DBManage) { return m_MySql.XStorage_MySql_FileInsert(pSt_DBManage); } -extern "C" BOOL XStorage_MySql_FileDelete(LPCTSTR lpszFile, LPCTSTR lpszHash) +extern "C" BOOL XStorage_MySql_FileDelete(LPCTSTR lpszBuckKey, LPCTSTR lpszFile, LPCTSTR lpszHash) { - return m_MySql.XStorage_MySql_FileDelete(lpszFile, lpszHash); + return m_MySql.XStorage_MySql_FileDelete(lpszBuckKey, lpszFile, lpszHash); } -extern "C" BOOL XStorage_MySql_FileQuery(XSTORAGECORE_DBFILE * **pppSt_ListFile, int* pInt_ListCount, LPCTSTR lpszTimeStart, LPCTSTR lpszTimeEnd, LPCTSTR lpszFile, LPCTSTR lpszHash) +extern "C" BOOL XStorage_MySql_FileQuery(XSTORAGECORE_DBFILE * **pppSt_ListFile, int* pInt_ListCount, LPCTSTR lpszTimeStart, LPCTSTR lpszTimeEnd, LPCTSTR lpszBuckKey, LPCTSTR lpszFile, LPCTSTR lpszHash, LPCTSTR lpszTableName) { - return m_MySql.XStorage_MySql_FileQuery(pppSt_ListFile, pInt_ListCount, lpszTimeStart, lpszTimeEnd, lpszFile, lpszHash); -} -extern "C" BOOL XStorage_MySql_FileQueryForTable(XSTORAGECORE_DBFILE * **pppSt_ListFile, int* pInt_ListCount, LPCTSTR lpszTableName) -{ - return m_MySql.XStorage_MySql_FileQueryForTable(pppSt_ListFile, pInt_ListCount, lpszTableName); -} -extern "C" BOOL XStorage_MySql_FileQueryForHash(XSTORAGECORE_DBFILE * pSt_FileInfo, LPCTSTR lpszFileMD5, LPCTSTR lpszUser, LPCTSTR lpszTimeStart, LPCTSTR lpszTimeEnd) -{ - return m_MySql.XStorage_MySql_FileQueryForHash(pSt_FileInfo, lpszFileMD5, lpszUser, lpszTimeStart, lpszTimeEnd); + return m_MySql.XStorage_MySql_FileQuery(pppSt_ListFile, pInt_ListCount, lpszTimeStart, lpszTimeEnd, lpszBuckKey, lpszFile, lpszHash, lpszTableName); } /************************************************************************/ /* SQLITE数据库函数 */ @@ -74,15 +68,26 @@ extern "C" BOOL XStorage_SQLite_FileInsert(XSTORAGECORE_DBFILE * pSt_DBManage) { return m_SQLite.XStorage_SQLite_FileInsert(pSt_DBManage); } -extern "C" BOOL XStorage_SQLite_FileDelete(LPCTSTR lpszFile, LPCTSTR lpszHash) +extern "C" BOOL XStorage_SQLite_FileDelete(LPCTSTR lpszBuckKey, LPCTSTR lpszFile, LPCTSTR lpszHash) +{ + return m_SQLite.XStorage_SQLite_FileDelete(lpszBuckKey, lpszFile, lpszHash); +} +extern "C" BOOL XStorage_SQLite_FileQuery(XSTORAGECORE_DBFILE * **pppSt_ListFile, int* pInt_ListCount, LPCTSTR lpszTimeStart, LPCTSTR lpszTimeEnd, LPCTSTR lpszBuckKey, LPCTSTR lpszFile, LPCTSTR lpszHash, LPCTSTR lpszTableName) +{ + return m_SQLite.XStorage_SQLite_FileQuery(pppSt_ListFile, pInt_ListCount, lpszTimeStart, lpszTimeEnd, lpszBuckKey, lpszFile, lpszHash, lpszTableName); +} +/************************************************************************/ +/* SQL帮助函数集 */ +/************************************************************************/ +extern "C" BOOL XStorage_SQLHelp_Insert(TCHAR * ptszSQLBuffer, XSTORAGECORE_DBFILE * pSt_DBFile) { - return m_SQLite.XStorage_SQLite_FileDelete(lpszFile, lpszHash); + return m_SQLHelp.XStorage_SQLHelp_Insert(ptszSQLBuffer, pSt_DBFile); } -extern "C" BOOL XStorage_SQLite_FileQuery(XSTORAGECORE_DBFILE * **pppSt_ListFile, int* pInt_ListCount, LPCTSTR lpszTimeStart, LPCTSTR lpszTimeEnd, LPCTSTR lpszFile, LPCTSTR lpszHash) +extern "C" BOOL XStorage_SQLHelp_Delete(TCHAR * ptszSQLBuffer, LPCTSTR lpszTableName, LPCTSTR lpszBuckKey, LPCTSTR lpszFileName, LPCTSTR lpszFileHash) { - return m_SQLite.XStorage_SQLite_FileQuery(pppSt_ListFile, pInt_ListCount, lpszTimeStart, lpszTimeEnd, lpszFile, lpszHash); + return m_SQLHelp.XStorage_SQLHelp_Delete(ptszSQLBuffer, lpszTableName, lpszBuckKey, lpszFileName, lpszFileHash); } -extern "C" BOOL XStorage_SQLite_FileQueryForTable(XSTORAGECORE_DBFILE * **pppSt_ListFile, int* pInt_ListCount, LPCTSTR lpszTableName) +extern "C" BOOL XStorage_SQLHelp_Query(TCHAR * ptszSQLBuffer, LPCTSTR lpszTableName, LPCTSTR lpszBuckKey, LPCTSTR lpszFilePath, LPCTSTR lpszFileName, LPCTSTR lpszFileHash, LPCTSTR lpszFileUser, LPCTSTR lpszTimeStart, LPCTSTR lpszTimeEnd) { - return m_SQLite.XStorage_SQLite_FileQueryForTable(pppSt_ListFile, pInt_ListCount, lpszTableName); + return m_SQLHelp.XStorage_SQLHelp_Query(ptszSQLBuffer, lpszTableName, lpszBuckKey, lpszFilePath, lpszFileName, lpszFileHash, lpszFileUser, lpszTimeStart, lpszTimeEnd); } \ No newline at end of file