diff --git a/CHANGELOG b/CHANGELOG index 005ea6f..dea1f60 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,25 @@ +XEngine_Storage V3.13.0.1001 + +增加:st_PermissionFlags增加新的标志位上传限制,现在上传文件也可以进行限制了 +增加:boundary文件上传支持 +优化:选择模式代码 +更新:匹配XENGINE V8.25版本 +修改:获取目录大小函数单独出来了 +修正:上传覆写标识不起作用的问题 +修正:禁用标识在下载的时候没有作用的问题 +修正:配置文件字段逻辑型类型问题 +删除:put方法支持 + +added:st_PermissionFlags a new flag use to upload limit. and now upload file size and enable limit supported +added:boundary upload file supported +improved:select mode code +update:match xengine v8.25 +modify:Wrapped function to get folder size +fixed:upload rewrite flag is not work +fixed:disable flag does not work in download +fixed:configure field is not boolean +delete:upload put method +====================================================================================== XEngine_Storage V3.12.1.1001 修改:不在插入数据当HTTP的HOOK出错 diff --git a/README.en.md b/README.en.md index f7e0fa3..cc9cfb2 100644 --- a/README.en.md +++ b/README.en.md @@ -15,10 +15,10 @@ best storage service for http,more concise code. On going maintenance The purpose of development and implementation based on libXEngine is a cross-platform network storage service feature list: -1. support file http upload and download(use put and get method) +1. support file http upload and download(use post and get method) 2. support http api notify of event and management api interface 3. support http encrypt and cert data transimission -4. support database(mysql and sqlite) record infomation. +4. support database(mysql) record infomation. 5. support load banace 6. supprot http auth 7. support log and config @@ -32,6 +32,7 @@ feature list: 15. support full speed and limit speed 16. permission control 17. upload file rewrite +18. support convert record(Active download) ## install diff --git a/README.md b/README.md index ce1b316..a9993a0 100644 --- a/README.md +++ b/README.md @@ -14,10 +14,10 @@ c c++ file storage service ## 软件特性 基于libXEngine开发并实现的一套简洁高性能跨平台网络存储服务 软件特性: -1. 支持HTTP协议上传和下载(采用PUT和GET) +1. 支持HTTP协议上传和下载(采用POST和GET) 2. 支持HTTP API接口事件通知与管理 3. 支持HTTP加密与证书 -4. 采用数据库(MYSQL和SQLITE)记录信息 +4. 采用数据库(MYSQL)记录信息 5. 支持分布式 6. 支持HTTP验证 7. 支持详尽的日志和配置信息 @@ -31,6 +31,7 @@ c c++ file storage service 15. 支持全速模式和限速模式 16. 权限控制 17. 上传文件覆写 +18. 支持转录(主动下载) ## 安装教程 @@ -104,6 +105,9 @@ P2P广域网文件查找与下载支持 如果是升级安装,下载新版本后修改配置文件就可以直接运行了 如果使用了数据库,需要打开数据库匹配字段和表是否一致 +## 视频教程 +你也可以观看视频教程来了解我们的代码框架情况:https://www.bilibili.com/video/BV1PF4m177Gt + ## 其他问题 你可以参考docment目录下的文档.里面包含了API协议和服务说明. jsoncpp模块在使用的时候编译运行时库选择必须一致.否则会崩溃. diff --git a/XEngine_APPClient/APPClient_Download/APPClient_Download.cpp b/XEngine_APPClient/APPClient_Download/APPClient_Download.cpp index 01c8e26..a33f1da 100644 --- a/XEngine_APPClient/APPClient_Download/APPClient_Download.cpp +++ b/XEngine_APPClient/APPClient_Download/APPClient_Download.cpp @@ -6,7 +6,7 @@ #include #include #pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib") -#pragma comment(lib,"XEngine_NetHelp/NetHelp_APIClient") +#pragma comment(lib,"XEngine_Client/XClient_APIHelp") #pragma comment(lib,"XEngine_SystemSdk/XEngine_SystemApi") #pragma comment(lib,"Ws2_32") #ifdef _WIN64 @@ -24,8 +24,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include @@ -34,8 +34,7 @@ using namespace std; //需要优先配置XEngine //WINDOWS使用VS2022 x86 或者 x64 debug 编译 -//linux::g++ -std=c++17 -Wall -g APPClient_Download.cpp -o APPClient_Download.exe -I ../../XEngine_Source/XEngine_ThirdPart/jsoncpp -L /usr/local/lib/XEngine_Release/XEngine_BaseLib -L /usr/local/lib/XEngine_Release/XEngine_NetHelp -L /usr/local/lib/XEngine_Release/XEngine_SystemSdk -L ../../XEngine_Source/XEngine_ThirdPart/jsoncpp -lXEngine_BaseLib -lNetHelp_APIClient -lXEngine_SystemApi -ljsoncpp -//macos::g++ -std=c++17 -Wall -g APPClient_Download.cpp -o APPClient_Download.exe -I ../../XEngine_Source/XEngine_ThirdPart/jsoncpp -L ../../XEngine_Source/XEngine_ThirdPart/jsoncpp -lXEngine_BaseLib -lNetHelp_APIClient -lXEngine_SystemApi -ljsoncpp +//linux macos::g++ -std=c++17 -Wall -g APPClient_Download.cpp -o APPClient_Download.exe -I ../../XEngine_Source/XEngine_ThirdPart/jsoncpp -L ../../XEngine_Source/XEngine_ThirdPart/jsoncpp -lXEngine_BaseLib -lXClient_APIHelp -lXEngine_SystemApi -ljsoncpp typedef struct { @@ -129,11 +128,11 @@ void P2PFile_Create(list* pStl_ListFile, LPCXSTR lpszFile) bool bComplete = true; for (unsigned int i = 0; i < pStl_ListFile->size(); i++) { - NETHELP_FILEINFO st_TaskInfo; - memset(&st_TaskInfo, '\0', sizeof(NETHELP_FILEINFO)); + XCLIENT_APIFILE st_TaskInfo; + memset(&st_TaskInfo, '\0', sizeof(XCLIENT_APIFILE)); APIClient_File_Query(pSt_P2PFile[i].xhToken, &st_TaskInfo); - if (ENUM_NETHELP_APICLIENT_FILE_STATUS_COMPLETE != st_TaskInfo.en_DownStatus) + if (ENUM_XCLIENT_APIHELP_FILE_STATUS_COMPLETE != st_TaskInfo.en_DownStatus) { bComplete = FALSE; } diff --git a/XEngine_APPClient/APPClient_RestApi/APPClient_RestApi.cpp b/XEngine_APPClient/APPClient_RestApi/APPClient_RestApi.cpp index bddbb1e..121ec2a 100644 --- a/XEngine_APPClient/APPClient_RestApi/APPClient_RestApi.cpp +++ b/XEngine_APPClient/APPClient_RestApi/APPClient_RestApi.cpp @@ -3,7 +3,7 @@ #include #pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib") #pragma comment(lib,"XEngine_Core/XEngine_OPenSsl") -#pragma comment(lib,"XEngine_NetHelp/NetHelp_APIClient") +#pragma comment(lib,"XEngine_Client/XClient_APIHelp") #pragma comment(lib,"Ws2_32") #ifdef _WIN64 #pragma comment(lib,"../../XEngine_Source/x64/Debug/jsoncpp") @@ -23,15 +23,14 @@ #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 /usr/local/lib/XEngine_Release/XEngine_Core -L ../../../XEngine/XEngine_Release/XEngine_Linux/Ubuntu/XEngine_NetHelp -lXEngine_BaseLib -lNetHelp_APIClient -ljsoncpp -Wl,-rpath=../../../XEngine/XEngine_Release/XEngine_Linux/Ubuntu/XEngine_BaseLib:../../../XEngine/XEngine_Release/XEngine_Linux/Ubuntu/XEngine_NetHelp,--disable-new-dtags //需要优先配置XEngine //WINDOWS使用VS2022 x86 或者 x64 debug 编译 //linux使用下面的命令编译 -//g++ -std=c++17 -Wall -g APPClient_RestApi.cpp -o APPClient_RestApi.exe -I ../../XEngine_Source/XEngine_ThirdPart/jsoncpp -L /usr/local/lib/XEngine_Release/XEngine_BaseLib -L /usr/local/lib/XEngine_Release/XEngine_Core -L /usr/local/lib/XEngine_Release/XEngine_NetHelp -L ../../XEngine_Source/XEngine_ThirdPart/jsoncpp -lXEngine_BaseLib -lNetHelp_APIClient -ljsoncpp +//g++ -std=c++17 -Wall -g APPClient_RestApi.cpp -o APPClient_RestApi.exe -I ../../XEngine_Source/XEngine_ThirdPart/jsoncpp -L ../../XEngine_Source/XEngine_ThirdPart/jsoncpp -lXEngine_BaseLib -lXClient_APIHelp -ljsoncpp XCHAR tszBaseBuffer[MAX_PATH]; XCHAR tszHdrBuffer[MAX_PATH]; diff --git a/XEngine_APPClient/APPClient_UPDate/APPClient_UPFile/APPClient_UPFile.cpp b/XEngine_APPClient/APPClient_UPDate/APPClient_UPFile/APPClient_UPFile.cpp index 72de648..a926366 100644 --- a/XEngine_APPClient/APPClient_UPDate/APPClient_UPFile/APPClient_UPFile.cpp +++ b/XEngine_APPClient/APPClient_UPDate/APPClient_UPFile/APPClient_UPFile.cpp @@ -72,10 +72,10 @@ int main(int argc, char** argv) for (; stl_ListIterator != stl_ListUPDate.end(); stl_ListIterator++) { XCHAR tszPathFile[1024]; - NETHELP_FILEINFO st_TaskInfo; + XCLIENT_APIFILE st_TaskInfo; memset(tszPathFile, '\0', sizeof(tszPathFile)); - memset(&st_TaskInfo, '\0', sizeof(NETHELP_FILEINFO)); + memset(&st_TaskInfo, '\0', sizeof(XCLIENT_APIFILE)); _xstprintf(tszPathFile, _X("%s%s"), stl_ListIterator->tszModulePath, stl_ListIterator->tszModuleName); _xtremove(tszPathFile); @@ -87,7 +87,7 @@ int main(int argc, char** argv) { break; } - if (ENUM_NETHELP_APICLIENT_FILE_STATUS_DOWNLOADDING != st_TaskInfo.en_DownStatus) + if (ENUM_XCLIENT_APIHELP_FILE_STATUS_DOWNLOADDING != st_TaskInfo.en_DownStatus) { break; } diff --git a/XEngine_APPClient/APPClient_UPDate/APPClient_UPFile/APPClient_UPHdr.h b/XEngine_APPClient/APPClient_UPDate/APPClient_UPFile/APPClient_UPHdr.h index 8c2aab6..2401497 100644 --- a/XEngine_APPClient/APPClient_UPDate/APPClient_UPFile/APPClient_UPHdr.h +++ b/XEngine_APPClient/APPClient_UPDate/APPClient_UPFile/APPClient_UPHdr.h @@ -3,7 +3,7 @@ #include #pragma comment(lib,"Ws2_32.lib") #pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib.lib") -#pragma comment(lib,"XEngine_NetHelp/NetHelp_APIClient.lib") +#pragma comment(lib,"XEngine_Client/XClient_APIHelp.lib") #pragma comment(lib,"XEngine_SystemSdk/XEngine_SystemApi.lib") #ifdef _WIN64 #pragma comment(lib,"../../../XEngine_Source/x64/Debug/jsoncpp") @@ -24,8 +24,8 @@ using namespace std; #include #include #include -#include -#include +#include +#include #include #include #include diff --git a/XEngine_APPClient/APPClient_UPDate/APPClient_UPMaker/APPClient_UPMaker.cpp b/XEngine_APPClient/APPClient_UPDate/APPClient_UPMaker/APPClient_UPMaker.cpp index aa1e449..10c7be3 100644 --- a/XEngine_APPClient/APPClient_UPDate/APPClient_UPMaker/APPClient_UPMaker.cpp +++ b/XEngine_APPClient/APPClient_UPDate/APPClient_UPMaker/APPClient_UPMaker.cpp @@ -5,7 +5,7 @@ #pragma comment(lib,"Ws2_32.lib") #pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib.lib") #pragma comment(lib,"XEngine_SystemSdk/XEngine_SystemApi.lib") -#pragma comment(lib,"XEngine_NetHelp/NetHelp_APIClient.lib") +#pragma comment(lib,"XEngine_Client/XClient_APIHelp.lib") #ifdef _WIN64 #pragma comment(lib,"../../../XEngine_Source/x64/Debug/jsoncpp") #else @@ -28,8 +28,8 @@ using namespace std; #include #include #include -#include -#include +#include +#include typedef struct { @@ -75,7 +75,7 @@ bool HelpModule_Api_BuildVer(XCHAR* ptszLocalBuffer, XCHAR* ptszRemoteBuffer, in XCHAR** ppszListDir; list stl_ListFile; //枚举文件 - if (!SystemApi_File_EnumFile(lpszPath, &ppszListDir, &nListCount, NULL, NULL, bSubDir, 1)) + if (!SystemApi_File_EnumFile(lpszPath, &ppszListDir, &nListCount, bSubDir, 1)) { return FALSE; } diff --git a/XEngine_APPClient/APPClient_UPDownload/APPClient_UPDownload.cpp b/XEngine_APPClient/APPClient_UPDownload/APPClient_UPDownload.cpp index caad7f8..d9ec325 100644 --- a/XEngine_APPClient/APPClient_UPDownload/APPClient_UPDownload.cpp +++ b/XEngine_APPClient/APPClient_UPDownload/APPClient_UPDownload.cpp @@ -3,7 +3,7 @@ #include #pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib") #pragma comment(lib,"XEngine_Core/XEngine_OPenSsl") -#pragma comment(lib,"XEngine_NetHelp/NetHelp_APIClient") +#pragma comment(lib,"XEngine_Client/XClient_APIHelp") #pragma comment(lib,"Ws2_32") #pragma comment(lib,"../../XEngine_Source/Debug/jsoncpp") #ifdef _WIN64 @@ -24,14 +24,14 @@ #include #include #include -#include -#include +#include +#include using namespace std; //需要优先配置XEngine //WINDOWS使用VS2022 x86 或者 x64 debug 编译 -//linux::g++ -std=c++17 -Wall -g APPClient_UPDownload.cpp -o APPClient_UPDownload.exe -I ../../XEngine_Source/XEngine_ThirdPart/jsoncpp -L /usr/local/lib/XEngine_Release/XEngine_BaseLib -L /usr/local/lib/XEngine_Release/XEngine_Core -L /usr/local/lib/XEngine_Release/XEngine_NetHelp -L ../../XEngine_Source/XEngine_ThirdPart/jsoncpp -lXEngine_BaseLib -lXEngine_OPenSsl -lNetHelp_APIClient -ljsoncpp -//macos::g++ -std=c++17 -Wall -g APPClient_UPDownload.cpp -o APPClient_UPDownload.exe -I ../../XEngine_Source/XEngine_ThirdPart/jsoncpp -L ../../XEngine_Source/XEngine_ThirdPart/jsoncpp -lXEngine_BaseLib -lXEngine_OPenSsl -lNetHelp_APIClient -ljsoncpp +//linux macos::g++ -std=c++17 -Wall -g APPClient_UPDownload.cpp -o APPClient_UPDownload.exe -I ../../XEngine_Source/XEngine_ThirdPart/jsoncpp -L ../../XEngine_Source/XEngine_ThirdPart/jsoncpp -lXEngine_BaseLib -lXEngine_OPenSsl -lXClient_APIHelp -ljsoncpp + //上传文件 void File_UPLoad() diff --git a/XEngine_APPClient/download.html b/XEngine_APPClient/download.html new file mode 100644 index 0000000..935d92f --- /dev/null +++ b/XEngine_APPClient/download.html @@ -0,0 +1,20 @@ + + + + + + Download Page + + + +

File Download Example

+

Click on the link below to download the file:

+ + Download Example File + + + + \ No newline at end of file diff --git a/XEngine_APPClient/upload.html b/XEngine_APPClient/upload.html new file mode 100644 index 0000000..c7207e3 --- /dev/null +++ b/XEngine_APPClient/upload.html @@ -0,0 +1,15 @@ + + + + +Simple File Upload + + +

Upload your file

+
+ Select file to upload: + + +
+ + \ No newline at end of file diff --git a/XEngine_Docment/Docment_en.docx b/XEngine_Docment/Docment_en.docx index 607dafb..c4d02f8 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 1374ba4..483211a 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 a7baf45..bb05b14 100644 --- a/XEngine_Release/XEngine_Config/XEngine_Config.json +++ b/XEngine_Release/XEngine_Config/XEngine_Config.json @@ -72,6 +72,7 @@ "tszCertKey":"./XEngine_Cert/2_www.xyry.org.key" }, "XVer":[ + "3.13.0.1001 Build20240301", "3.12.1.1001 Build20240104", "3.12.0.1001 Build20231025", "3.11.1.1001 Build20230804", diff --git a/XEngine_Release/XEngine_Config/XEngine_LBConfig.json b/XEngine_Release/XEngine_Config/XEngine_LBConfig.json index 991fc3a..8417851 100644 --- a/XEngine_Release/XEngine_Config/XEngine_LBConfig.json +++ b/XEngine_Release/XEngine_Config/XEngine_LBConfig.json @@ -18,25 +18,27 @@ ], "StorageAddr":[ { - "bEnable":1, + "bEnable":false, "nLevel":1, "Size":"1024MB", "XEngine_Key":"storagekey1", "XEngine_Path":"./XEngine_File", "PermissionFlags":{ "CreateDir":false, - "Rewrite":false + "Rewrite":false, + "UPLimit": false } }, { - "bEnable":1, + "bEnable":true, "nLevel":1, "Size":"1024MB", "XEngine_Key":"storagekey2", "XEngine_Path":"./XEngine_File2", "PermissionFlags":{ "CreateDir":false, - "Rewrite":false + "Rewrite":false, + "UPLimit": false } } ] diff --git a/XEngine_Source/StorageModule_APIHelp/APIHelp_Api/APIHelp_Api.cpp b/XEngine_Source/StorageModule_APIHelp/APIHelp_Api/APIHelp_Api.cpp index 8be3222..21a7f3e 100644 --- a/XEngine_Source/StorageModule_APIHelp/APIHelp_Api/APIHelp_Api.cpp +++ b/XEngine_Source/StorageModule_APIHelp/APIHelp_Api/APIHelp_Api.cpp @@ -350,4 +350,108 @@ bool CAPIHelp_Api::APIHelp_Api_UrlParse(XCHAR*** ppptszList, int nListCount, XCH } } return true; +} +/******************************************************************** +函数名称:APIHelp_Api_Boundary +函数功能:boundary头解析,判断上传方法 + 参数.一:ppptszList + In/Out:In + 类型:三级指针 + 可空:N + 意思:输入要解析的列表 + 参数.二:nListCount + In/Out:In + 类型:整数型 + 可空:N + 意思:输入列表个数 + 参数.三:ptszBoundStr + In/Out:Out + 类型:字符指针 + 可空:N + 意思:输出BOUND的字符串 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CAPIHelp_Api::APIHelp_Api_Boundary(XCHAR*** ppptszList, int nListCount, XCHAR* ptszBoundStr) +{ + APIHelp_IsErrorOccur = false; + + bool bRet = false; + LPCXSTR lpszHDRContent = _X("Content-Type"); + //Content-Type: multipart/form-data; boundary=AaB03x + for (int i = 0; i < nListCount; i++) + { + XCHAR tszKeyStr[MAX_PATH] = {}; + XCHAR tszVluStr[MAX_PATH] = {}; + + BaseLib_OperatorString_GetKeyValue((*ppptszList)[i], _X(": "), tszKeyStr, tszVluStr); + + if (0 == _tcsxnicmp(lpszHDRContent, tszKeyStr, _tcsxlen(lpszHDRContent))) + { + XCHAR tszKeySub[MAX_PATH] = {}; + XCHAR tszVluSub[MAX_PATH] = {}; + //multipart/form-data; boundary=AaB03x + if (BaseLib_OperatorString_GetKeyValue(tszVluStr, _X(";"), tszKeySub, tszVluSub)) + { + //boundary=AaB03x + ptszBoundStr[0] = '-';//要少一个字节 + if (BaseLib_OperatorString_GetKeyValue(tszVluSub, _X("="), tszKeyStr, ptszBoundStr + 1)) + { + bRet = true; + break; + } + } + } + } + return bRet; +} +/******************************************************************** +函数名称:APIHelp_Api_GetDIRSize +函数功能:获得目录大小 + 参数.一:lpszDIRStr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要操作s的目录 + 参数.二:pInt_DIRSize + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出得到的目录大小 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CAPIHelp_Api::APIHelp_Api_GetDIRSize(LPCXSTR lpszDIRStr, __int64u* pInt_DIRSize) +{ + int nListCount = 0; + int nPathType = 0; + __int64u nDirCount = 0; //当前目录大小 + XCHAR** ppListFile; + XCHAR tszFilePath[MAX_PATH] = {}; + + _tcsxcpy(tszFilePath, lpszDIRStr); + BaseLib_OperatorString_GetPath(tszFilePath, &nPathType); + //判断是绝对路径还是相对路径 + if (1 == nPathType) + { + _tcsxcat(tszFilePath, _X("\\*")); + } + else if (2 == nPathType) + { + _tcsxcat(tszFilePath, _X("/*")); + } + SystemApi_File_EnumFile(tszFilePath, &ppListFile, &nListCount, true, 1); + for (int i = 0; i < nListCount; i++) + { + struct _xtstat st_FStat; + _xtstat(ppListFile[i], &st_FStat); + nDirCount += st_FStat.st_size; + } + BaseLib_OperatorMemory_Free((XPPPMEM)&ppListFile, nListCount); + *pInt_DIRSize = nDirCount; + 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 index 8dc88ff..be7d33f 100644 --- a/XEngine_Source/StorageModule_APIHelp/APIHelp_Api/APIHelp_Api.h +++ b/XEngine_Source/StorageModule_APIHelp/APIHelp_Api/APIHelp_Api.h @@ -23,6 +23,8 @@ class CAPIHelp_Api bool APIHelp_Api_VerHash(LPCXSTR lpszFileHash, XCHAR** pptszListHdr, int nHdrCount); bool APIHelp_Api_GetIPInfo(LPCXSTR lpszMsgBuffer, int nMsgLen, XENGINE_IPADDRINFO* pSt_IPAddrInfo); bool APIHelp_Api_UrlParse(XCHAR*** ppptszList, int nListCount, XCHAR* ptszFileName, XCHAR* ptszKeyName); + bool APIHelp_Api_Boundary(XCHAR*** ppptszList, int nListCount, XCHAR* ptszBoundStr); + bool APIHelp_Api_GetDIRSize(LPCXSTR lpszDIRStr, __int64u* pInt_DIRSize); 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 0be9169..9e8386d 100644 --- a/XEngine_Source/StorageModule_APIHelp/APIHelp_Define.h +++ b/XEngine_Source/StorageModule_APIHelp/APIHelp_Define.h @@ -284,4 +284,47 @@ extern "C" bool APIHelp_Api_GetIPInfo(LPCXSTR lpszMsgBuffer, int nMsgLen, XENGIN 意思:是否成功 备注: *********************************************************************/ -extern "C" bool APIHelp_Api_UrlParse(XCHAR*** ppptszList, int nListCount, XCHAR* ptszFileName, XCHAR* ptszKeyName); \ No newline at end of file +extern "C" bool APIHelp_Api_UrlParse(XCHAR*** ppptszList, int nListCount, XCHAR* ptszFileName, XCHAR* ptszKeyName); +/******************************************************************** +函数名称:APIHelp_Api_Boundary +函数功能:boundary头解析,判断上传方法 + 参数.一:ppptszList + In/Out:In + 类型:三级指针 + 可空:N + 意思:输入要解析的列表 + 参数.二:nListCount + In/Out:In + 类型:整数型 + 可空:N + 意思:输入列表个数 + 参数.三:ptszBoundStr + In/Out:Out + 类型:字符指针 + 可空:N + 意思:输出BOUND的字符串 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool APIHelp_Api_Boundary(XCHAR*** ppptszList, int nListCount, XCHAR* ptszBoundStr); +/******************************************************************** +函数名称:APIHelp_Api_GetDIRSize +函数功能:获得目录大小 + 参数.一:lpszDIRStr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要操作s的目录 + 参数.二:pInt_DIRSize + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出得到的目录大小 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool APIHelp_Api_GetDIRSize(LPCXSTR lpszDIRStr, __int64u* pInt_DIRSize); \ 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 b1658e3..ec3742c 100644 --- a/XEngine_Source/StorageModule_APIHelp/APIHelp_Distributed/APIHelp_Distributed.cpp +++ b/XEngine_Source/StorageModule_APIHelp/APIHelp_Distributed/APIHelp_Distributed.cpp @@ -13,10 +13,6 @@ *********************************************************************/ CAPIHelp_Distributed::CAPIHelp_Distributed() { - nRandomFront = 0; - nRandomBack = 0; - nUPFront = 0; - nUPBack = 0; } CAPIHelp_Distributed::~CAPIHelp_Distributed() { @@ -81,37 +77,13 @@ bool CAPIHelp_Distributed::APIHelp_Distributed_RandomAddr(list* pStl_Lis } else if (2 == nMode) { - if (nRandomFront >= pStl_ListAddr->size()) - { - nRandomFront = 0; - } - unsigned int i = 0; - for (auto stl_ListIterator = pStl_ListAddr->begin(); stl_ListIterator != pStl_ListAddr->end(); stl_ListIterator++, i++) - { - if (nRandomFront == i) - { - bFound = true; - _tcsxcpy(ptszAddr, stl_ListIterator->c_str()); - break; - } - } + bFound = true; + _tcsxcpy(ptszAddr, pStl_ListAddr->front().c_str()); } else if (3 == nMode) { - if (nRandomBack >= pStl_ListAddr->size()) - { - nRandomBack = 0; - } - unsigned int i = 0; - for (auto stl_ListIterator = pStl_ListAddr->rbegin(); stl_ListIterator != pStl_ListAddr->rend(); stl_ListIterator++, i++) - { - if (nRandomBack == i) - { - bFound = true; - _tcsxcpy(ptszAddr, stl_ListIterator->c_str()); - break; - } - } + bFound = true; + _tcsxcpy(ptszAddr, pStl_ListAddr->back().c_str()); } if (!bFound) @@ -292,6 +264,24 @@ bool CAPIHelp_Distributed::APIHelp_Distributed_UPStorage(listst_PermissionFlags.bUPLimit) + { + if (!pSt_StorageBucket->bEnable) + { + APIHelp_IsErrorOccur = true; + APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_DISABLE; + return false; + } + __int64u nDirCount = 0; //当前目录大小 + APIHelp_Api_GetDIRSize(pSt_StorageBucket->tszFilePath, &nDirCount); + //如果当前目录大小大于设定的大小. + if (nDirCount >= APIHelp_Distributed_GetSize(stl_ListIterator->tszBuckSize)) + { + APIHelp_IsErrorOccur = true; + APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_SIZE; + return false; + } + } } else { @@ -318,36 +308,8 @@ bool CAPIHelp_Distributed::APIHelp_Distributed_UPStorage(listnLevel == nLastLevel) { - int nListCount = 0; __int64u nDirCount = 0; //当前目录大小 - XCHAR** ppListFile; - //处理路径是否有通配符 - XCHAR tszFilePath[MAX_PATH]; - memset(tszFilePath, '\0', MAX_PATH); - - _tcsxcpy(tszFilePath, pSt_StorageBucket->tszFilePath); - if (tszFilePath[_tcsxlen(tszFilePath) - 1] != '*') - { - int nPathType = 0; - BaseLib_OperatorString_GetPath(tszFilePath, &nPathType); - //判断是绝对路径还是相对路径 - if (1 == nPathType) - { - _tcsxcat(tszFilePath, _X("\\*")); - } - else if (2 == nPathType) - { - _tcsxcat(tszFilePath, _X("/*")); - } - } - SystemApi_File_EnumFile(tszFilePath, &ppListFile, &nListCount, true, 1); - for (int j = 0; j < nListCount; j++) - { - struct _xtstat st_FStat; - _xtstat(ppListFile[j], &st_FStat); - nDirCount += st_FStat.st_size; - } - BaseLib_OperatorMemory_Free((XPPPMEM)&ppListFile, nListCount); + APIHelp_Api_GetDIRSize(pSt_StorageBucket->tszFilePath, &nDirCount); //如果当前目录大小大于设定的大小.那么忽略 if (nDirCount >= APIHelp_Distributed_GetSize(stl_ListIterator->tszBuckSize)) { @@ -387,37 +349,13 @@ bool CAPIHelp_Distributed::APIHelp_Distributed_UPStorage(list= stl_BuckSelect.size()) - { - nUPFront = 0; - } - unsigned int i = 0; - for (auto stl_ListIterator = stl_BuckSelect.begin(); stl_ListIterator != stl_BuckSelect.end(); stl_ListIterator++, i++) - { - if (nUPFront == i) - { - bFound = true; - *pSt_StorageBucket = *stl_ListIterator; - break; - } - } + bFound = true; + *pSt_StorageBucket = stl_BuckSelect.front(); } else if (3 == nMode) { - if (nUPBack >= stl_BuckSelect.size()) - { - nUPBack = 0; - } - unsigned int i = 0; - for (auto stl_ListIterator = stl_BuckSelect.rbegin(); stl_ListIterator != stl_BuckSelect.rend(); stl_ListIterator++, i++) - { - if (nUPBack == i) - { - bFound = true; - *pSt_StorageBucket = *stl_ListIterator; - break; - } - } + bFound = true; + *pSt_StorageBucket = stl_BuckSelect.back(); } if (!bFound) @@ -427,7 +365,6 @@ bool CAPIHelp_Distributed::APIHelp_Distributed_UPStorage(listst_LoadBalance.pStl_ListBucket->push_back(st_Bucket); } diff --git a/XEngine_Source/StorageModule_Database/Makefile b/XEngine_Source/StorageModule_Database/Makefile index 6ad1d1a..aa4ad1a 100644 --- a/XEngine_Source/StorageModule_Database/Makefile +++ b/XEngine_Source/StorageModule_Database/Makefile @@ -7,7 +7,7 @@ LIBFLAG = RELEASE = 0 UNICODE = 0 LOADHDR = -I ./ -I ../XEngine_ThirdPart/jsoncpp -LOADSO = -L /usr/local/lib/XEngine_Release/XEngine_BaseLib -L /usr/local/lib/XEngine_Release/XEngine_HelpComponents +LOADSO = LIB = -lXEngine_BaseLib -lHelpComponents_DataBase LIBEX = OBJECTS = Database_File.o Database_Memory.o Database_Help.o pch.o diff --git a/XEngine_Source/StorageModule_Protocol/Makefile b/XEngine_Source/StorageModule_Protocol/Makefile index 6e218f6..ce198b9 100644 --- a/XEngine_Source/StorageModule_Protocol/Makefile +++ b/XEngine_Source/StorageModule_Protocol/Makefile @@ -7,7 +7,7 @@ LIBFLAG = RELEASE = 0 UNICODE = 0 LOADHDR = -I ./ -I ../XEngine_ThirdPart/jsoncpp -LOADSO = -L /usr/local/lib/XEngine_Release/XEngine_BaseLib -L ../XEngine_ThirdPart/jsoncpp +LOADSO = -L ../XEngine_ThirdPart/jsoncpp LIB = -lXEngine_BaseLib -ljsoncpp LIBEX = OBJECTS = Protocol_StoragePacket.o Protocol_StorageParse.o pch.o diff --git a/XEngine_Source/StorageModule_Session/Makefile b/XEngine_Source/StorageModule_Session/Makefile index f5de865..3c2c5f9 100644 --- a/XEngine_Source/StorageModule_Session/Makefile +++ b/XEngine_Source/StorageModule_Session/Makefile @@ -7,7 +7,7 @@ LIBFLAG = RELEASE = 0 UNICODE = 0 LOADHDR = -I ./ -I ../XEngine_ThirdPart/jsoncpp -LOADSO = -L /usr/local/lib/XEngine_Release/XEngine_BaseLib +LOADSO = LIB = -lXEngine_BaseLib LIBEX = OBJECTS = Session_DLStroage.o Session_UPStroage.o Session_User.o pch.o diff --git a/XEngine_Source/StorageModule_Session/Session_Define.h b/XEngine_Source/StorageModule_Session/Session_Define.h index a83a1fa..79a9147 100644 --- a/XEngine_Source/StorageModule_Session/Session_Define.h +++ b/XEngine_Source/StorageModule_Session/Session_Define.h @@ -15,6 +15,12 @@ ////////////////////////////////////////////////////////////////////////// typedef struct { + struct + { + XCHAR tszBoundStr[MAX_PATH]; //boundary信息 + bool bBoundMode; //是否是bound上传模式 + bool bBoundStart; + }st_Boundary; XCHAR tszFileDir[MAX_PATH]; //文件地址 XCHAR tszClientAddr[128]; //操作的用户地址 XCHAR tszFileHash[128]; //文件HASH值 @@ -25,7 +31,7 @@ typedef struct __int64x ullPosStart; //开始位置 __int64x ullPosEnd; //结束位置 bool bRewrite; //是否为覆写 - + int nLimit; //限制工具 XHANDLE xhToken; FILE* pSt_File; @@ -470,4 +476,37 @@ extern "C" bool Session_UPStroage_Close(LPCXSTR lpszClientAddr); 意思:是否成功 备注: *********************************************************************/ -extern "C" bool Session_UPStroage_MaxConnect(LPCXSTR lpszClientAddr); \ No newline at end of file +extern "C" bool Session_UPStroage_MaxConnect(LPCXSTR lpszClientAddr); +/******************************************************************** +函数名称:Session_UPStroage_SetBoundary +函数功能:设置bound模式信息 + 参数.一:lpszClientAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要处理的地址 + 参数.二:lpszBoundary + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入bound字符串 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool Session_UPStroage_SetBoundary(LPCXSTR lpszClientAddr, LPCXSTR lpszBoundary); +/******************************************************************** +函数名称:Session_UPStroage_SetBoundaryStart +函数功能:设置bound模式信息 + 参数.一:lpszClientAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要处理的地址 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool Session_UPStroage_SetBoundaryStart(LPCXSTR lpszClientAddr); \ No newline at end of file diff --git a/XEngine_Source/StorageModule_Session/Session_Stroage/Session_UPStroage.cpp b/XEngine_Source/StorageModule_Session/Session_Stroage/Session_UPStroage.cpp index 3ab9ca3..8e788f7 100644 --- a/XEngine_Source/StorageModule_Session/Session_Stroage/Session_UPStroage.cpp +++ b/XEngine_Source/StorageModule_Session/Session_Stroage/Session_UPStroage.cpp @@ -171,6 +171,13 @@ bool CSession_UPStroage::Session_UPStroage_Insert(LPCXSTR lpszClientAddr, LPCXST } else { + if ((0 == _xtaccess(lpszFileDir, 0)) && !bRewrite) + { + Session_IsErrorOccur = true; + Session_dwErrorCode = ERROR_STORAGE_MODULE_SESSION_REWRITE; + return false; + } + st_Client.st_StorageInfo.pSt_File = _xtfopen(lpszFileDir, _X("wb")); if (NULL == st_Client.st_StorageInfo.pSt_File) { @@ -452,7 +459,11 @@ bool CSession_UPStroage::Session_UPStroage_MaxConnect(LPCXSTR lpszClientAddr) int nExistNumber = 0; st_Locker.lock_shared(); - unordered_map::iterator stl_MapIterator = stl_MapStroage.begin(); + unordered_map::iterator stl_MapIterator = stl_MapStroage.find(lpszClientAddr); + if (stl_MapIterator == stl_MapStroage.end()) + { + + } for (; stl_MapIterator != stl_MapStroage.end(); stl_MapIterator++) { XCHAR tszIPSource[128]; @@ -481,4 +492,73 @@ bool CSession_UPStroage::Session_UPStroage_MaxConnect(LPCXSTR lpszClientAddr) return false; } return true; +} +/******************************************************************** +函数名称:Session_UPStroage_SetBoundary +函数功能:设置bound模式信息 + 参数.一:lpszClientAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要处理的地址 + 参数.二:lpszBoundary + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入bound字符串 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CSession_UPStroage::Session_UPStroage_SetBoundary(LPCXSTR lpszClientAddr, LPCXSTR lpszBoundary) +{ + Session_IsErrorOccur = false; + + st_Locker.lock_shared(); + unordered_map::iterator stl_MapIterator = stl_MapStroage.find(lpszClientAddr); + if (stl_MapIterator == stl_MapStroage.end()) + { + Session_IsErrorOccur = true; + Session_dwErrorCode = ERROR_STORAGE_MODULE_SESSION_NOTFOUND; + st_Locker.unlock_shared(); + return false; + } + stl_MapIterator->second.st_StorageInfo.st_Boundary.bBoundStart = false; + stl_MapIterator->second.st_StorageInfo.st_Boundary.bBoundMode = true; + _tcsxcpy(stl_MapIterator->second.st_StorageInfo.st_Boundary.tszBoundStr, lpszBoundary); + + st_Locker.unlock_shared(); + return true; +} +/******************************************************************** +函数名称:Session_UPStroage_SetBoundaryStart +函数功能:设置bound模式信息 + 参数.一:lpszClientAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要处理的地址 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CSession_UPStroage::Session_UPStroage_SetBoundaryStart(LPCXSTR lpszClientAddr) +{ + Session_IsErrorOccur = false; + + st_Locker.lock_shared(); + unordered_map::iterator stl_MapIterator = stl_MapStroage.find(lpszClientAddr); + if (stl_MapIterator == stl_MapStroage.end()) + { + Session_IsErrorOccur = true; + Session_dwErrorCode = ERROR_STORAGE_MODULE_SESSION_NOTFOUND; + st_Locker.unlock_shared(); + return false; + } + stl_MapIterator->second.st_StorageInfo.st_Boundary.bBoundStart = true; + + st_Locker.unlock_shared(); + return true; } \ No newline at end of file diff --git a/XEngine_Source/StorageModule_Session/Session_Stroage/Session_UPStroage.h b/XEngine_Source/StorageModule_Session/Session_Stroage/Session_UPStroage.h index ca1c781..70ad499 100644 --- a/XEngine_Source/StorageModule_Session/Session_Stroage/Session_UPStroage.h +++ b/XEngine_Source/StorageModule_Session/Session_Stroage/Session_UPStroage.h @@ -32,6 +32,8 @@ class CSession_UPStroage bool Session_UPStroage_Delete(LPCXSTR lpszClientAddr); bool Session_UPStroage_Close(LPCXSTR lpszClientAddr); bool Session_UPStroage_MaxConnect(LPCXSTR lpszClientAddr); + bool Session_UPStroage_SetBoundary(LPCXSTR lpszClientAddr, LPCXSTR lpszBoundary); + bool Session_UPStroage_SetBoundaryStart(LPCXSTR lpszClientAddr); private: bool m_bResume; int m_nMaxConnect; diff --git a/XEngine_Source/StorageModule_Session/StorageModule_Session.def b/XEngine_Source/StorageModule_Session/StorageModule_Session.def index 943c6d6..37e79bd 100644 --- a/XEngine_Source/StorageModule_Session/StorageModule_Session.def +++ b/XEngine_Source/StorageModule_Session/StorageModule_Session.def @@ -27,4 +27,6 @@ EXPORTS Session_UPStorage_GetAll Session_UPStroage_Delete Session_UPStroage_Close - Session_UPStroage_MaxConnect \ No newline at end of file + Session_UPStroage_MaxConnect + Session_UPStroage_SetBoundary + Session_UPStroage_SetBoundaryStart \ No newline at end of file diff --git a/XEngine_Source/StorageModule_Session/pch.cpp b/XEngine_Source/StorageModule_Session/pch.cpp index 9d98696..ae42492 100644 --- a/XEngine_Source/StorageModule_Session/pch.cpp +++ b/XEngine_Source/StorageModule_Session/pch.cpp @@ -127,4 +127,12 @@ extern "C" bool Session_UPStroage_Close(LPCXSTR lpszClientAddr) extern "C" bool Session_UPStroage_MaxConnect(LPCXSTR lpszClientAddr) { return m_UPStorage.Session_UPStroage_MaxConnect(lpszClientAddr); +} +extern "C" bool Session_UPStroage_SetBoundary(LPCXSTR lpszClientAddr, LPCXSTR lpszBoundary) +{ + return m_UPStorage.Session_UPStroage_SetBoundary(lpszClientAddr, lpszBoundary); +} +extern "C" bool Session_UPStroage_SetBoundaryStart(LPCXSTR lpszClientAddr) +{ + return m_UPStorage.Session_UPStroage_SetBoundaryStart(lpszClientAddr); } \ No newline at end of file diff --git a/XEngine_Source/VSCopy_Debug.bat b/XEngine_Source/VSCopy_Debug.bat index bcf1298..46b7e5d 100644 --- a/XEngine_Source/VSCopy_Debug.bat +++ b/XEngine_Source/VSCopy_Debug.bat @@ -5,7 +5,7 @@ copy /y "D:\XEngine\XEngine_SourceCode\Debug\XEngine_ManagePool.dll" "./" copy /y "D:\XEngine\XEngine_SourceCode\Debug\XEngine_OPenSsl.dll" "./" copy /y "D:\XEngine\XEngine_SourceCode\Debug\XEngine_SystemApi.dll" "./" -copy /y "D:\XEngine\XEngine_SourceCode\Debug\NetHelp_APIClient.dll" "./" +copy /y "D:\XEngine\XEngine_SourceCode\Debug\XClient_APIHelp.dll" "./" copy /y "D:\XEngine\XEngine_SourceCode\Debug\HelpComponents_DataBase.dll" "./" copy /y "D:\XEngine\XEngine_SourceCode\Debug\HelpComponents_XLog.dll" "./" diff --git a/XEngine_Source/VSCopy_x64.bat b/XEngine_Source/VSCopy_x64.bat index 72acfbb..32a15ce 100644 --- a/XEngine_Source/VSCopy_x64.bat +++ b/XEngine_Source/VSCopy_x64.bat @@ -5,7 +5,7 @@ copy /y "%XEngine_Lib64%\XEngine_Core\XEngine_ManagePool.dll" "./" copy /y "%XEngine_Lib64%\XEngine_Core\XEngine_OPenSsl.dll" "./" copy /y "%XEngine_Lib64%\XEngine_SystemSdk\XEngine_SystemApi.dll" "./" -copy /y "%XEngine_Lib64%\XEngine_NetHelp\NetHelp_APIClient.dll" "./" +copy /y "%XEngine_Lib64%\XEngine_Client\XClient_APIHelp.dll" "./" copy /y "%XEngine_Lib64%\XEngine_HelpComponents\HelpComponents_DataBase.dll" "./" copy /y "%XEngine_Lib64%\XEngine_HelpComponents\HelpComponents_XLog.dll" "./" diff --git a/XEngine_Source/VSCopy_x86.bat b/XEngine_Source/VSCopy_x86.bat index 3251602..0ebdc4a 100644 --- a/XEngine_Source/VSCopy_x86.bat +++ b/XEngine_Source/VSCopy_x86.bat @@ -5,7 +5,7 @@ copy /y "%XEngine_Lib32%\XEngine_Core\XEngine_ManagePool.dll" "./" copy /y "%XEngine_Lib32%\XEngine_Core\XEngine_OPenSsl.dll" "./" copy /y "%XEngine_Lib32%\XEngine_SystemSdk\XEngine_SystemApi.dll" "./" -copy /y "%XEngine_Lib32%\XEngine_NetHelp\NetHelp_APIClient.dll" "./" +copy /y "%XEngine_Lib32%\XEngine_Client\XClient_APIHelp.dll" "./" copy /y "%XEngine_Lib32%\XEngine_HelpComponents\HelpComponents_DataBase.dll" "./" copy /y "%XEngine_Lib32%\XEngine_HelpComponents\HelpComponents_XLog.dll" "./" diff --git a/XEngine_Source/XEngine_StorageApp/Makefile b/XEngine_Source/XEngine_StorageApp/Makefile index 17478fd..65c3176 100644 --- a/XEngine_Source/XEngine_StorageApp/Makefile +++ b/XEngine_Source/XEngine_StorageApp/Makefile @@ -5,9 +5,8 @@ PLATDIR = RELEASE = 0 UNICODE = 0 LOADHDR = -I ./ -I ../XEngine_ThirdPart/jsoncpp -LOADSO = -L /usr/local/lib/XEngine_Release/XEngine_BaseLib -L /usr/local/lib/XEngine_Release/XEngine_Core -L /usr/local/lib/XEngine_Release/XEngine_SystemSdk -L /usr/local/lib/XEngine_Release/XEngine_HelpComponents -L /usr/local/lib/XEngine_Release/XEngine_RfcComponents -L /usr/local/lib/XEngine_Release/XEngine_NetHelp \ - -L ../StorageModule_Database -L ../StorageModule_Config -L ../StorageModule_Session -L ../StorageModule_APIHelp -L ../StorageModule_Protocol -L ../XEngine_ThirdPart/jsoncpp -LIB = -lXEngine_BaseLib -lXEngine_Algorithm -lXEngine_Core -lXEngine_ManagePool -lXEngine_OPenSsl -lXEngine_ProcFile -lXEngine_SystemApi -lHelpComponents_XLog -lHelpComponents_Packets -lRfcComponents_HttpProtocol -lNetHelp_APIClient \ +LOADSO = -L ../StorageModule_Database -L ../StorageModule_Config -L ../StorageModule_Session -L ../StorageModule_APIHelp -L ../StorageModule_Protocol -L ../XEngine_ThirdPart/jsoncpp +LIB = -lXEngine_BaseLib -lXEngine_Algorithm -lXEngine_Core -lXEngine_ManagePool -lXEngine_OPenSsl -lXClient_APIHelp -lXEngine_ProcFile -lXEngine_SystemApi -lHelpComponents_XLog -lHelpComponents_Packets -lRfcComponents_HttpProtocol \ -lStorageModule_Database -lStorageModule_Config -lStorageModule_Session -lStorageModule_APIHelp -lStorageModule_Protocol \ -ljsoncpp LIBEX = diff --git a/XEngine_Source/XEngine_StorageApp/StorageApp_Download.cpp b/XEngine_Source/XEngine_StorageApp/StorageApp_Download.cpp index 83f8dc6..d4e05e4 100644 --- a/XEngine_Source/XEngine_StorageApp/StorageApp_Download.cpp +++ b/XEngine_Source/XEngine_StorageApp/StorageApp_Download.cpp @@ -266,6 +266,16 @@ bool XEngine_Task_HttpDownload(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, in XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("下载客户端:%s,请求文件失败,可能BUCKET:%s 不正确,错误:%lX"), lpszClientAddr, pSt_HTTPParam->tszHttpUri, StorageHelp_GetLastError()); return false; } + if (!st_StorageBucket.bEnable) + { + st_HDRParam.bIsClose = true; + st_HDRParam.nHttpCode = 404; + + HttpProtocol_Server_SendMsgEx(xhDLHttp, tszSDBuffer, &nSDLen, &st_HDRParam); + XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPDOWNLOAD); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("下载客户端:%s,请求文件失败,请求的BUCKET:%s 已经被禁用"), lpszClientAddr, st_StorageBucket.tszBuckKey); + return false; + } int nPathType = 0; _xstprintf(tszFileDir, _X("%s%s"), st_StorageBucket.tszFilePath, st_StorageBucket.tszFileName); BaseLib_OperatorString_GetPath(tszFileDir, &nPathType); diff --git a/XEngine_Source/XEngine_StorageApp/StorageApp_Hdr.h b/XEngine_Source/XEngine_StorageApp/StorageApp_Hdr.h index 97f4294..74f2655 100644 --- a/XEngine_Source/XEngine_StorageApp/StorageApp_Hdr.h +++ b/XEngine_Source/XEngine_StorageApp/StorageApp_Hdr.h @@ -27,12 +27,16 @@ using namespace std; #include #include #include +#include +#include #include #include #include #include #include #include +#include +#include #include #include #include @@ -41,8 +45,6 @@ using namespace std; #include #include #include -#include -#include #include #include #include @@ -112,10 +114,10 @@ extern XENGINE_LBCONFIG st_LoadbalanceCfg; #pragma comment(lib,"XEngine_Core/XEngine_Core.lib") #pragma comment(lib,"XEngine_Core/XEngine_ManagePool.lib") #pragma comment(lib,"XEngine_Core/XEngine_OPenSsl.lib") +#pragma comment(lib,"XEngine_Client/XClient_APIHelp.lib") #pragma comment(lib,"XEngine_HelpComponents/HelpComponents_XLog.lib") #pragma comment(lib,"XEngine_HelpComponents/HelpComponents_Packets.lib") #pragma comment(lib,"XEngine_RfcComponents/RfcComponents_HttpProtocol.lib") -#pragma comment(lib,"XEngine_NetHelp/NetHelp_APIClient.lib") #pragma comment(lib,"XEngine_SystemSdk/XEngine_SystemApi.lib") #ifdef _WIN64 #ifdef _DEBUG diff --git a/XEngine_Source/XEngine_StorageApp/StorageApp_UPLoader.cpp b/XEngine_Source/XEngine_StorageApp/StorageApp_UPLoader.cpp index 0036b1b..a76fdea 100644 --- a/XEngine_Source/XEngine_StorageApp/StorageApp_UPLoader.cpp +++ b/XEngine_Source/XEngine_StorageApp/StorageApp_UPLoader.cpp @@ -50,9 +50,8 @@ bool XEngine_Task_HttpUPLoader(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, in memset(tszFileDir, '\0', sizeof(tszFileDir)); memset(&st_HDRParam, '\0', sizeof(RFCCOMPONENTS_HTTP_HDRPARAM)); - LPCXSTR lpszMethodPut = _X("PUT"); LPCXSTR lpszMethodPost = _X("POST"); - if ((0 != _tcsxncmp(lpszMethodPut, pSt_HTTPParam->tszHttpMethod, _tcsxlen(lpszMethodPut))) && (0 != _tcsxncmp(lpszMethodPost, pSt_HTTPParam->tszHttpMethod, _tcsxlen(lpszMethodPost)))) + if (0 != _tcsxncmp(lpszMethodPost, pSt_HTTPParam->tszHttpMethod, _tcsxlen(lpszMethodPost))) { st_HDRParam.bIsClose = true; st_HDRParam.nHttpCode = 405; @@ -202,6 +201,7 @@ bool XEngine_Task_HttpUPLoader(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, in return false; } } + int nPathType = 0; _xstprintf(tszFileDir, _X("%s/%s"), st_StorageBucket.tszFilePath, tszFileName); BaseLib_OperatorString_GetPath(tszFileDir, &nPathType); @@ -259,36 +259,85 @@ bool XEngine_Task_HttpUPLoader(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, in if (!Session_UPStroage_Insert(lpszClientAddr, st_StorageBucket.tszBuckKey, tszFileDir, nPosCount, st_StorageBucket.st_PermissionFlags.bRewrite, nPosStart, nPosEnd)) { st_HDRParam.bIsClose = true; - st_HDRParam.nHttpCode = 404; + st_HDRParam.nHttpCode = 500; HttpProtocol_Server_SendMsgEx(xhUPHttp, tszSDBuffer, &nSDLen, &st_HDRParam); XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPUPLOADER); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("上传客户端:%s,插入用户请求失败,文件:%s,错误:%lX"), lpszClientAddr, tszFileDir, Session_GetLastError()); return false; } + //检查上传模式 + XCHAR tszBoundStr[MAX_PATH] = {}; + if (APIHelp_Api_Boundary(&pptszListHdr, nHdrCount, tszBoundStr)) + { + Session_UPStroage_SetBoundary(lpszClientAddr, tszBoundStr); + } XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("上传客户端:%s,请求设置了数据范围:%d - %d/%lld"), lpszClientAddr, nPosStart, nPosEnd, nPosCount); } - Session_UPStroage_Write(lpszClientAddr, lpszMsgBuffer, nMsgLen); + SESSION_STORAGEINFO st_StorageInfo = {}; + Session_UPStroage_GetInfo(lpszClientAddr, &st_StorageInfo); + //处理bound上传模式 + if (st_StorageInfo.st_Boundary.bBoundMode) + { + //是否开始已经处理 + if (st_StorageInfo.st_Boundary.bBoundStart) + { + //已处理,查找结尾 + int nPos = 0; + if (Algorithm_String_XFastMatch(lpszMsgBuffer, st_StorageInfo.st_Boundary.tszBoundStr, &nPos, nMsgLen)) + { + int nRLen = _tcsxlen(st_StorageInfo.st_Boundary.tszBoundStr) + 3; + Session_UPStroage_Write(lpszClientAddr, lpszMsgBuffer, nPos - nRLen); + } + else + { + Session_UPStroage_Write(lpszClientAddr, lpszMsgBuffer, nMsgLen); + } + } + else + { + //没有处理,查找开始 + int nPosStart = 0; + int nPosEnd = 0; + if (Algorithm_String_XFastMatch(lpszMsgBuffer, _X("\r\n\r\n"), &nPosStart, nMsgLen)) + { + if (Algorithm_String_XFastMatch(lpszMsgBuffer + nPosStart, st_StorageInfo.st_Boundary.tszBoundStr, &nPosEnd, nMsgLen - nPosStart)) + { + int nRLen = _tcsxlen(st_StorageInfo.st_Boundary.tszBoundStr) + 3; + Session_UPStroage_Write(lpszClientAddr, lpszMsgBuffer + nPosStart, nPosEnd - nRLen); + } + else + { + Session_UPStroage_Write(lpszClientAddr, lpszMsgBuffer + nPosStart, nMsgLen - nPosStart); + } + Session_UPStroage_SetBoundaryStart(lpszClientAddr); + } + } + } + else + { + Session_UPStroage_Write(lpszClientAddr, lpszMsgBuffer, nMsgLen); + } HttpProtocol_Server_GetRecvModeEx(xhUPHttp, lpszClientAddr, &nRVMode, &nRVCount, &nHDSize); if (nHDSize >= nRVCount) { int nPLen = MAX_PATH; - XCHAR tszPassNotify[MAX_PATH]; - SESSION_STORAGEINFO st_StorageInfo; + XCHAR tszPassNotify[MAX_PATH] = {}; - memset(tszPassNotify, '\0', MAX_PATH); - memset(&st_StorageInfo, '\0', sizeof(SESSION_STORAGEINFO)); Session_UPStroage_GetInfo(lpszClientAddr, &st_StorageInfo); - //大小是否足够 - if (st_StorageInfo.ullCount != st_StorageInfo.ullRWLen) + if (!st_StorageInfo.st_Boundary.bBoundMode) { - st_HDRParam.bIsClose = true; - st_HDRParam.nHttpCode = 200; - Protocol_StoragePacket_UPDown(tszPassNotify, &nPLen, st_StorageInfo.tszBuckKey, st_StorageInfo.tszFileDir, st_StorageInfo.tszClientAddr, st_StorageInfo.ullRWLen, false); - HttpProtocol_Server_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, _X("上传客户端:%s,请求上传文件成功,文件名:%s,总大小:%lld,写入大小:%lld,文件不完整,需要等待断点续传完毕"), lpszClientAddr, tszFileDir, st_StorageInfo.ullCount, st_StorageInfo.ullRWLen); - return true; + //大小是否足够 + if (st_StorageInfo.ullCount != st_StorageInfo.ullRWLen) + { + st_HDRParam.bIsClose = true; + st_HDRParam.nHttpCode = 200; + Protocol_StoragePacket_UPDown(tszPassNotify, &nPLen, st_StorageInfo.tszBuckKey, st_StorageInfo.tszFileDir, st_StorageInfo.tszClientAddr, st_StorageInfo.ullRWLen, false); + HttpProtocol_Server_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, _X("上传客户端:%s,请求上传文件成功,文件名:%s,总大小:%lld,写入大小:%lld,文件不完整,需要等待断点续传完毕"), lpszClientAddr, tszFileDir, st_StorageInfo.ullCount, st_StorageInfo.ullRWLen); + return true; + } } int nHashLen = 0; XBYTE tszHashStr[MAX_PATH]; @@ -324,7 +373,7 @@ bool XEngine_Task_HttpUPLoader(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, in return false; } } - Protocol_StoragePacket_UPDown(tszPassNotify, &nPLen, st_StorageInfo.tszBuckKey, st_StorageInfo.tszFileDir, st_StorageInfo.tszClientAddr, st_StorageInfo.ullCount, false, st_ProtocolFile.st_ProtocolFile.tszFileHash); + Protocol_StoragePacket_UPDown(tszPassNotify, &nPLen, st_StorageInfo.tszBuckKey, st_StorageInfo.tszFileDir, st_StorageInfo.tszClientAddr, st_StorageInfo.ullRWLen, false, st_ProtocolFile.st_ProtocolFile.tszFileHash); //PASS代理 if (st_ServiceCfg.st_XProxy.bUPPass) {