Skip to content

Commit aa5720f

Browse files
committed
added:webdav propfind support
1 parent a3d64b9 commit aa5720f

15 files changed

+191
-4
lines changed

XEngine_Source/StorageModule_Protocol/Protocol_Packet/Protocol_StoragePacket.cpp

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,4 +519,89 @@ bool CProtocol_StoragePacket::Protocol_StoragePacket_Action(XCHAR* ptszMsgBuffer
519519
*pInt_MsgLen = st_JsonRoot.toStyledString().length();
520520
memcpy(ptszMsgBuffer, st_JsonRoot.toStyledString().c_str(), *pInt_MsgLen);
521521
return true;
522+
}
523+
524+
bool CProtocol_StoragePacket::Protocol_StoragePacket_Propfind(XCHAR* ptszMsgBuffer, int* pInt_MsgLen, XCHAR*** ppptszListFile, int nFileCount)
525+
{
526+
Protocol_IsErrorOccur = false;
527+
528+
if ((NULL == ptszMsgBuffer) || (NULL == pInt_MsgLen))
529+
{
530+
Protocol_IsErrorOccur = true;
531+
Protocol_dwErrorCode = ERROR_XENGINE_STORAGE_PROTOCOL_PARAMENT;
532+
return false;
533+
}
534+
// 创建一个 XML 文档
535+
XMLDocument m_XMLDocument;
536+
// XML 声明
537+
XMLDeclaration* pSt_XMLDeclaration = m_XMLDocument.NewDeclaration(R"(xml version="1.0" encoding="utf-8")");
538+
m_XMLDocument.InsertFirstChild(pSt_XMLDeclaration);
539+
540+
// 根元素 <multistatus>
541+
XMLElement* pSt_XMLRoot = m_XMLDocument.NewElement("d:multistatus");
542+
pSt_XMLRoot->SetAttribute("xmlns:d", "DAV:");
543+
m_XMLDocument.InsertEndChild(pSt_XMLRoot);
544+
545+
for (int i = 0; i < nFileCount; i++)
546+
{
547+
XCHAR tszFileName[MAX_PATH] = {};
548+
SYSTEMAPI_FILE_ATTR st_FileAttr = {};
549+
BaseLib_OperatorString_GetFileAndPath((*ppptszListFile)[i], NULL, tszFileName);
550+
SystemApi_File_GetFileAttr((*ppptszListFile)[i], &st_FileAttr);
551+
552+
XCHAR tszGMTTime[64] = {};
553+
BaseLib_OperatorTime_GMTTime(tszGMTTime, st_FileAttr.nModifyTime);
554+
555+
// 子元素 <response>
556+
XMLElement* pSt_XMLResponse = m_XMLDocument.NewElement("d:response");
557+
pSt_XMLRoot->InsertEndChild(pSt_XMLResponse);
558+
//文件
559+
XMLElement* pSt_XMLhref = m_XMLDocument.NewElement("d:href");
560+
pSt_XMLhref->SetText((*ppptszListFile)[i] + 1);
561+
pSt_XMLResponse->InsertEndChild(pSt_XMLhref);
562+
//属性
563+
XMLElement* pSt_XMLPropstat = m_XMLDocument.NewElement("d:propstat");
564+
pSt_XMLResponse->InsertEndChild(pSt_XMLPropstat);
565+
//属性内容
566+
XMLElement* pSt_XMLProp = m_XMLDocument.NewElement("d:prop");
567+
pSt_XMLPropstat->InsertEndChild(pSt_XMLProp);
568+
//属性名称
569+
XMLElement* pSt_XMLPropName = m_XMLDocument.NewElement("d:displayname");
570+
pSt_XMLPropName->SetText(tszFileName);
571+
pSt_XMLProp->InsertEndChild(pSt_XMLPropName);
572+
573+
if (st_FileAttr.bFile)
574+
{
575+
XCHAR tszFileSize[128] = {};
576+
_xstprintf(tszFileSize, _X("%llu"), st_FileAttr.nFileSize);
577+
//属性大小
578+
XMLElement* pSt_XMLLength = m_XMLDocument.NewElement("d:getcontentlength");
579+
pSt_XMLLength->SetText(tszFileSize);
580+
pSt_XMLProp->InsertEndChild(pSt_XMLLength);
581+
//属性修改时间
582+
XMLElement* pSt_XMLModifyTime = m_XMLDocument.NewElement("d:getlastmodified");
583+
pSt_XMLModifyTime->SetText(tszGMTTime);
584+
pSt_XMLProp->InsertEndChild(pSt_XMLModifyTime);
585+
}
586+
else
587+
{
588+
//集合<d:resourcetype><d:collection/></d:resourcetype>
589+
XMLElement* pSt_XMLResource = m_XMLDocument.NewElement("d:resourcetype");
590+
pSt_XMLProp->InsertEndChild(pSt_XMLResource);
591+
592+
XMLElement* pSt_XMLCollection = m_XMLDocument.NewElement("d:collection");
593+
pSt_XMLResource->InsertEndChild(pSt_XMLCollection);
594+
}
595+
//属性状态
596+
XMLElement* pSt_XMLStatus = m_XMLDocument.NewElement("d:status");
597+
pSt_XMLStatus->SetText("HTTP/1.1 200 OK");
598+
pSt_XMLPropstat->InsertEndChild(pSt_XMLStatus);
599+
}
600+
// 将 XML 数据保存到字符串
601+
XMLPrinter m_XMLPrinter;
602+
m_XMLDocument.Print(&m_XMLPrinter);
603+
604+
*pInt_MsgLen = m_XMLPrinter.CStrSize();
605+
memcpy(ptszMsgBuffer, m_XMLPrinter.CStr(), m_XMLPrinter.CStrSize());
606+
return true;
522607
}

XEngine_Source/StorageModule_Protocol/Protocol_Packet/Protocol_StoragePacket.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ class CProtocol_StoragePacket
2424
bool Protocol_StoragePacket_UPDown(XCHAR* ptszMsgBuffer, int* pInt_MsgLen, LPCXSTR lpszBuckKey, LPCXSTR lpszFileName, LPCXSTR lpszClientAddr, __int64x nFileSize, bool bDown, LPCXSTR lpszFileHash = NULL);
2525
bool Protocol_StoragePacket_REQFile(XCHAR* ptszMsgBuffer, int* pInt_MsgLen, LPCXSTR lpszFileName = NULL, LPCXSTR lpszFileHash = NULL, XNETHANDLE xhToken = 0);
2626
bool Protocol_StoragePacket_Action(XCHAR* ptszMsgBuffer, int* pInt_MsgLen, XNETHANDLE xhToken, XENGINE_ACTIONINFO* pSt_ActionInfo);
27+
public:
28+
bool Protocol_StoragePacket_Propfind(XCHAR* ptszMsgBuffer, int* pInt_MsgLen, XCHAR*** ppptszListFile, int nFileCount);
2729
};

XEngine_Source/StorageModule_Protocol/Protocol_Parse/Protocol_StorageParse.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,4 +544,11 @@ bool CProtocol_StorageParse::Protocol_StorageParse_Action(LPCXSTR lpszMsgBuffer,
544544
_tcsxcpy(pSt_ActionInfo->tszFileName, st_JsonRoot["tszFileName"].asCString());
545545
_tcsxcpy(pSt_ActionInfo->tszFileUrl, st_JsonRoot["tszFileUrl"].asCString());
546546
return true;
547+
}
548+
bool CProtocol_StorageParse::Protocol_StorageParse_Propfind(LPCXSTR lpszMsgBuffer, int nMsgLen, XENGINE_ACTIONINFO* pSt_ActionInfo)
549+
{
550+
Protocol_IsErrorOccur = false;
551+
552+
553+
return true;
547554
}

XEngine_Source/StorageModule_Protocol/Protocol_Parse/Protocol_StorageParse.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ class CProtocol_StorageParse
2424
bool Protocol_StorageParse_SpeedLimit(LPCXSTR lpszMsgBuffer, int nMsgLen, int* pInt_Code, int* pInt_Limit);
2525
bool Protocol_StorageParse_P2PToken(LPCXSTR lpszMsgBuffer, int nMsgLen, XNETHANDLE* pxhToken);
2626
bool Protocol_StorageParse_Action(LPCXSTR lpszMsgBuffer, int nMsgLen, XENGINE_ACTIONINFO* pSt_ActionInfo);
27+
public:
28+
bool Protocol_StorageParse_Propfind(LPCXSTR lpszMsgBuffer, int nMsgLen, XENGINE_ACTIONINFO* pSt_ActionInfo);
2729
};

XEngine_Source/StorageModule_Protocol/StorageModule_Protocol.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ EXPORTS
1818
Protocol_StoragePacket_Info
1919
Protocol_StoragePacket_DirOperator
2020
Protocol_StoragePacket_REQFile
21-
Protocol_StoragePacket_Action
21+
Protocol_StoragePacket_Action
22+
Protocol_StoragePacket_Propfind

XEngine_Source/StorageModule_Protocol/StorageModule_Protocol.vcxproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
<PropertyGroup Label="UserMacros" />
7373
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
7474
<LinkIncremental>true</LinkIncremental>
75-
<IncludePath>$(XEngine_Include);../XEngine_Depend/XEngine_Module/jsoncpp;$(IncludePath)</IncludePath>
75+
<IncludePath>$(XEngine_Include);../XEngine_Depend/XEngine_Module/jsoncpp;../XEngine_Depend/XEngine_Module/tinyxml2;..\StorageModule_Protocol;$(IncludePath)</IncludePath>
7676
<LibraryPath>$(XEngine_Lib32);$(LibraryPath)</LibraryPath>
7777
</PropertyGroup>
7878
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -99,6 +99,7 @@
9999
<PrecompiledHeader>Use</PrecompiledHeader>
100100
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
101101
<DisableSpecificWarnings>4819</DisableSpecificWarnings>
102+
<LanguageStandard>stdcpp17</LanguageStandard>
102103
</ClCompile>
103104
<Link>
104105
<SubSystem>Windows</SubSystem>

XEngine_Source/StorageModule_Protocol/StorageProtocol_Define.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,4 +515,6 @@ extern "C" bool Protocol_StoragePacket_REQFile(XCHAR * ptszMsgBuffer, int* pInt_
515515
意思:是否成功
516516
备注:
517517
*********************************************************************/
518-
extern "C" bool Protocol_StoragePacket_Action(XCHAR* ptszMsgBuffer, int* pInt_MsgLen, XNETHANDLE xhToken, XENGINE_ACTIONINFO* pSt_ActionInfo);
518+
extern "C" bool Protocol_StoragePacket_Action(XCHAR* ptszMsgBuffer, int* pInt_MsgLen, XNETHANDLE xhToken, XENGINE_ACTIONINFO* pSt_ActionInfo);
519+
520+
extern "C" bool Protocol_StoragePacket_Propfind(XCHAR* ptszMsgBuffer, int* pInt_MsgLen, XCHAR*** ppptszListFile, int nFileCount);

XEngine_Source/StorageModule_Protocol/pch.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,8 @@ extern "C" bool Protocol_StoragePacket_REQFile(XCHAR * ptszMsgBuffer, int* pInt_
8787
extern "C" bool Protocol_StoragePacket_Action(XCHAR * ptszMsgBuffer, int* pInt_MsgLen, XNETHANDLE xhToken, XENGINE_ACTIONINFO * pSt_ActionInfo)
8888
{
8989
return m_StoragePacket.Protocol_StoragePacket_Action(ptszMsgBuffer, pInt_MsgLen, xhToken, pSt_ActionInfo);
90+
}
91+
extern "C" bool Protocol_StoragePacket_Propfind(XCHAR* ptszMsgBuffer, int* pInt_MsgLen, XCHAR*** ppptszListFile, int nFileCount)
92+
{
93+
return m_StoragePacket.Protocol_StoragePacket_Propfind(ptszMsgBuffer, pInt_MsgLen, ppptszListFile, nFileCount);
9094
}

XEngine_Source/StorageModule_Protocol/pch.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,21 @@
2525
#endif
2626
#endif //PCH_H
2727
#include <json/json.h>
28+
#include <tinyxml2.h>
2829
#include <list>
2930
#include <unordered_map>
31+
#include <filesystem>
3032
using namespace std;
33+
using namespace tinyxml2;
3134
#include <XEngine_Include/XEngine_CommHdr.h>
3235
#include <XEngine_Include/XEngine_Types.h>
3336
#include <XEngine_Include/XEngine_ProtocolHdr.h>
3437
#include <XEngine_Include/XEngine_BaseLib/BaseLib_Define.h>
3538
#include <XEngine_Include/XEngine_BaseLib/BaseLib_Error.h>
3639
#include <XEngine_Include/XEngine_HelpComponents/DataBase_Define.h>
3740
#include <XEngine_Include/XEngine_HelpComponents/DataBase_Error.h>
41+
#include <XEngine_Include/XEngine_SystemSdk/SystemApi_Define.h>
42+
#include <XEngine_Include/XEngine_SystemSdk/SystemApi_Error.h>
3843
#include "../XStorage_Protocol.h"
3944
#include "../StorageModule_Config/Config_Define.h"
4045
#include "../StorageModule_Config/Config_Error.h"
@@ -58,17 +63,22 @@ extern XLONG Protocol_dwErrorCode;
5863

5964
#ifdef _MSC_BUILD
6065
#pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib.lib")
66+
#pragma comment(lib,"XEngine_SystemSdk/XEngine_SystemApi.lib")
6167
#ifdef _DEBUG
6268
#ifdef _WIN64
6369
#pragma comment(lib,"../x64/Debug/jsoncpp")
70+
#pragma comment(lib,"../x64/Debug/tinyxml2")
6471
#else
6572
#pragma comment(lib,"../Debug/jsoncpp")
73+
#pragma comment(lib,"../Debug/tinyxml2")
6674
#endif
6775
#else
6876
#ifdef _WIN64
6977
#pragma comment(lib,"../x64/Release/jsoncpp")
78+
#pragma comment(lib,"../x64/Release/tinyxml2")
7079
#else
7180
#pragma comment(lib,"../Release/jsoncpp")
81+
#pragma comment(lib,"../Release/tinyxml2")
7282
#endif
7383
#endif
7484
#endif

XEngine_Source/XEngine_StorageApp/StorageApp_Center.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ bool XEngine_Task_HttpCenter(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int
5858
LPCXSTR lpszMethodPost = _X("POST");
5959
LPCXSTR lpszMethodOption = _X("OPTIONS");
6060

61+
LPCXSTR lpszMethodPropfind = _X("PROPFIND");
62+
6163
if (st_ServiceCfg.st_XAuth.bCHAuth)
6264
{
6365
XCHAR tszUserName[64];
@@ -144,12 +146,16 @@ bool XEngine_Task_HttpCenter(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int
144146
Storage_TaskAction(tszAPIName, lpszClientAddr, lpszMsgBuffer, nMsgLen, pSt_HTTPParam);
145147
}
146148
}
149+
else if (0 == _tcsxnicmp(lpszMethodPropfind, pSt_HTTPParam->tszHttpMethod, _tcsxlen(lpszMethodPropfind)))
150+
{
151+
Storage_TaskWebdav(lpszClientAddr, lpszMsgBuffer, nMsgLen, pSt_HTTPParam, pptszListHdr, nHdrCount);
152+
}
147153
else if (0 == _tcsxnicmp(lpszMethodOption, pSt_HTTPParam->tszHttpMethod, _tcsxlen(lpszMethodOption)))
148154
{
149155
//用于心跳
150156
st_HDRParam.bIsClose = true;
151157
st_HDRParam.nHttpCode = 200;
152-
LPCXSTR lpszHdrBuffer = _X("Allow: POST GET PUT OPTIONS\r\n");
158+
LPCXSTR lpszHdrBuffer = _X("Allow: POST GET PUT PROPFIND PROPPATCH MKCOL COPY MOVE DELETE LOCK UNLOCK OPTIONS\r\n");
153159
HttpProtocol_Server_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam, NULL, 0, lpszHdrBuffer);
154160
XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER);
155161
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("业务客户端:%s,请求OPTIONS心跳方法成功"), lpszClientAddr);

0 commit comments

Comments
 (0)