Skip to content

Commit cd125eb

Browse files
committed
added:boundary upload file supported
1 parent 4956209 commit cd125eb

File tree

12 files changed

+281
-21
lines changed

12 files changed

+281
-21
lines changed

XEngine_Source/StorageModule_APIHelp/APIHelp_Api/APIHelp_Api.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,4 +350,60 @@ bool CAPIHelp_Api::APIHelp_Api_UrlParse(XCHAR*** ppptszList, int nListCount, XCH
350350
}
351351
}
352352
return true;
353+
}
354+
/********************************************************************
355+
函数名称:APIHelp_Api_Boundary
356+
函数功能:boundary头解析,判断上传方法
357+
参数.一:ppptszList
358+
In/Out:In
359+
类型:三级指针
360+
可空:N
361+
意思:输入要解析的列表
362+
参数.二:nListCount
363+
In/Out:In
364+
类型:整数型
365+
可空:N
366+
意思:输入列表个数
367+
参数.三:ptszBoundStr
368+
In/Out:Out
369+
类型:字符指针
370+
可空:N
371+
意思:输出BOUND的字符串
372+
返回值
373+
类型:逻辑型
374+
意思:是否成功
375+
备注:
376+
*********************************************************************/
377+
bool CAPIHelp_Api::APIHelp_Api_Boundary(XCHAR*** ppptszList, int nListCount, XCHAR* ptszBoundStr)
378+
{
379+
APIHelp_IsErrorOccur = false;
380+
381+
bool bRet = false;
382+
LPCXSTR lpszHDRContent = _X("Content-Type");
383+
//Content-Type: multipart/form-data; boundary=AaB03x
384+
for (int i = 0; i < nListCount; i++)
385+
{
386+
XCHAR tszKeyStr[MAX_PATH] = {};
387+
XCHAR tszVluStr[MAX_PATH] = {};
388+
389+
BaseLib_OperatorString_GetKeyValue((*ppptszList)[i], _X(": "), tszKeyStr, tszVluStr);
390+
391+
if (0 == _tcsxnicmp(lpszHDRContent, tszKeyStr, _tcsxlen(lpszHDRContent)))
392+
{
393+
XCHAR tszKeySub[MAX_PATH] = {};
394+
XCHAR tszVluSub[MAX_PATH] = {};
395+
//multipart/form-data; boundary=AaB03x
396+
if (BaseLib_OperatorString_GetKeyValue(tszVluStr, _X(";"), tszKeySub, tszVluSub))
397+
{
398+
//boundary=AaB03x
399+
ptszBoundStr[0] = '-';//要少一个字节
400+
if (BaseLib_OperatorString_GetKeyValue(tszVluSub, _X("="), tszKeyStr, ptszBoundStr + 1))
401+
{
402+
bRet = true;
403+
break;
404+
}
405+
}
406+
}
407+
}
408+
return bRet;
353409
}

XEngine_Source/StorageModule_APIHelp/APIHelp_Api/APIHelp_Api.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class CAPIHelp_Api
2323
bool APIHelp_Api_VerHash(LPCXSTR lpszFileHash, XCHAR** pptszListHdr, int nHdrCount);
2424
bool APIHelp_Api_GetIPInfo(LPCXSTR lpszMsgBuffer, int nMsgLen, XENGINE_IPADDRINFO* pSt_IPAddrInfo);
2525
bool APIHelp_Api_UrlParse(XCHAR*** ppptszList, int nListCount, XCHAR* ptszFileName, XCHAR* ptszKeyName);
26+
bool APIHelp_Api_Boundary(XCHAR*** ppptszList, int nListCount, XCHAR* ptszBoundStr);
2627
protected:
2728
private:
2829
};

XEngine_Source/StorageModule_APIHelp/APIHelp_Define.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,28 @@ extern "C" bool APIHelp_Api_GetIPInfo(LPCXSTR lpszMsgBuffer, int nMsgLen, XENGIN
284284
意思:是否成功
285285
备注:
286286
*********************************************************************/
287-
extern "C" bool APIHelp_Api_UrlParse(XCHAR*** ppptszList, int nListCount, XCHAR* ptszFileName, XCHAR* ptszKeyName);
287+
extern "C" bool APIHelp_Api_UrlParse(XCHAR*** ppptszList, int nListCount, XCHAR* ptszFileName, XCHAR* ptszKeyName);
288+
/********************************************************************
289+
函数名称:APIHelp_Api_Boundary
290+
函数功能:boundary头解析,判断上传方法
291+
参数.一:ppptszList
292+
In/Out:In
293+
类型:三级指针
294+
可空:N
295+
意思:输入要解析的列表
296+
参数.二:nListCount
297+
In/Out:In
298+
类型:整数型
299+
可空:N
300+
意思:输入列表个数
301+
参数.三:ptszBoundStr
302+
In/Out:Out
303+
类型:字符指针
304+
可空:N
305+
意思:输出BOUND的字符串
306+
返回值
307+
类型:逻辑型
308+
意思:是否成功
309+
备注:
310+
*********************************************************************/
311+
extern "C" bool APIHelp_Api_Boundary(XCHAR*** ppptszList, int nListCount, XCHAR* ptszBoundStr);

XEngine_Source/StorageModule_APIHelp/StorageModule_APIHelp.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ EXPORTS
1313
APIHelp_Api_RangeFile
1414
APIHelp_Api_VerHash
1515
APIHelp_Api_GetIPInfo
16-
APIHelp_Api_UrlParse
16+
APIHelp_Api_UrlParse
17+
APIHelp_Api_Boundary

XEngine_Source/StorageModule_APIHelp/pch.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,8 @@ extern "C" bool APIHelp_Api_GetIPInfo(LPCXSTR lpszMsgBuffer, int nMsgLen, XENGIN
7373
extern "C" bool APIHelp_Api_UrlParse(XCHAR * **ppptszList, int nListCount, XCHAR * ptszFileName, XCHAR * ptszKeyName)
7474
{
7575
return m_APIHelp.APIHelp_Api_UrlParse(ppptszList, nListCount, ptszFileName, ptszKeyName);
76+
}
77+
extern "C" bool APIHelp_Api_Boundary(XCHAR * **ppptszList, int nListCount, XCHAR * ptszBoundStr)
78+
{
79+
return m_APIHelp.APIHelp_Api_Boundary(ppptszList, nListCount, ptszBoundStr);
7680
}

XEngine_Source/StorageModule_Session/Session_Define.h

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
//////////////////////////////////////////////////////////////////////////
1616
typedef struct
1717
{
18+
struct
19+
{
20+
XCHAR tszBoundStr[MAX_PATH]; //boundary信息
21+
bool bBoundMode; //是否是bound上传模式
22+
bool bBoundStart;
23+
}st_Boundary;
1824
XCHAR tszFileDir[MAX_PATH]; //文件地址
1925
XCHAR tszClientAddr[128]; //操作的用户地址
2026
XCHAR tszFileHash[128]; //文件HASH值
@@ -25,7 +31,7 @@ typedef struct
2531
__int64x ullPosStart; //开始位置
2632
__int64x ullPosEnd; //结束位置
2733
bool bRewrite; //是否为覆写
28-
34+
2935
int nLimit; //限制工具
3036
XHANDLE xhToken;
3137
FILE* pSt_File;
@@ -470,4 +476,37 @@ extern "C" bool Session_UPStroage_Close(LPCXSTR lpszClientAddr);
470476
意思:是否成功
471477
备注:
472478
*********************************************************************/
473-
extern "C" bool Session_UPStroage_MaxConnect(LPCXSTR lpszClientAddr);
479+
extern "C" bool Session_UPStroage_MaxConnect(LPCXSTR lpszClientAddr);
480+
/********************************************************************
481+
函数名称:Session_UPStroage_SetBoundary
482+
函数功能:设置bound模式信息
483+
参数.一:lpszClientAddr
484+
In/Out:In
485+
类型:常量字符指针
486+
可空:N
487+
意思:输入要处理的地址
488+
参数.二:lpszBoundary
489+
In/Out:In
490+
类型:常量字符指针
491+
可空:N
492+
意思:输入bound字符串
493+
返回值
494+
类型:逻辑型
495+
意思:是否成功
496+
备注:
497+
*********************************************************************/
498+
extern "C" bool Session_UPStroage_SetBoundary(LPCXSTR lpszClientAddr, LPCXSTR lpszBoundary);
499+
/********************************************************************
500+
函数名称:Session_UPStroage_SetBoundaryStart
501+
函数功能:设置bound模式信息
502+
参数.一:lpszClientAddr
503+
In/Out:In
504+
类型:常量字符指针
505+
可空:N
506+
意思:输入要处理的地址
507+
返回值
508+
类型:逻辑型
509+
意思:是否成功
510+
备注:
511+
*********************************************************************/
512+
extern "C" bool Session_UPStroage_SetBoundaryStart(LPCXSTR lpszClientAddr);

XEngine_Source/StorageModule_Session/Session_Stroage/Session_UPStroage.cpp

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,11 @@ bool CSession_UPStroage::Session_UPStroage_MaxConnect(LPCXSTR lpszClientAddr)
452452

453453
int nExistNumber = 0;
454454
st_Locker.lock_shared();
455-
unordered_map<string, SESSION_STORAGEUPLOADER>::iterator stl_MapIterator = stl_MapStroage.begin();
455+
unordered_map<string, SESSION_STORAGEUPLOADER>::iterator stl_MapIterator = stl_MapStroage.find(lpszClientAddr);
456+
if (stl_MapIterator == stl_MapStroage.end())
457+
{
458+
459+
}
456460
for (; stl_MapIterator != stl_MapStroage.end(); stl_MapIterator++)
457461
{
458462
XCHAR tszIPSource[128];
@@ -481,4 +485,73 @@ bool CSession_UPStroage::Session_UPStroage_MaxConnect(LPCXSTR lpszClientAddr)
481485
return false;
482486
}
483487
return true;
488+
}
489+
/********************************************************************
490+
函数名称:Session_UPStroage_SetBoundary
491+
函数功能:设置bound模式信息
492+
参数.一:lpszClientAddr
493+
In/Out:In
494+
类型:常量字符指针
495+
可空:N
496+
意思:输入要处理的地址
497+
参数.二:lpszBoundary
498+
In/Out:In
499+
类型:常量字符指针
500+
可空:N
501+
意思:输入bound字符串
502+
返回值
503+
类型:逻辑型
504+
意思:是否成功
505+
备注:
506+
*********************************************************************/
507+
bool CSession_UPStroage::Session_UPStroage_SetBoundary(LPCXSTR lpszClientAddr, LPCXSTR lpszBoundary)
508+
{
509+
Session_IsErrorOccur = false;
510+
511+
st_Locker.lock_shared();
512+
unordered_map<string, SESSION_STORAGEUPLOADER>::iterator stl_MapIterator = stl_MapStroage.find(lpszClientAddr);
513+
if (stl_MapIterator == stl_MapStroage.end())
514+
{
515+
Session_IsErrorOccur = true;
516+
Session_dwErrorCode = ERROR_STORAGE_MODULE_SESSION_NOTFOUND;
517+
st_Locker.unlock_shared();
518+
return false;
519+
}
520+
stl_MapIterator->second.st_StorageInfo.st_Boundary.bBoundStart = false;
521+
stl_MapIterator->second.st_StorageInfo.st_Boundary.bBoundMode = true;
522+
_tcsxcpy(stl_MapIterator->second.st_StorageInfo.st_Boundary.tszBoundStr, lpszBoundary);
523+
524+
st_Locker.unlock_shared();
525+
return true;
526+
}
527+
/********************************************************************
528+
函数名称:Session_UPStroage_SetBoundaryStart
529+
函数功能:设置bound模式信息
530+
参数.一:lpszClientAddr
531+
In/Out:In
532+
类型:常量字符指针
533+
可空:N
534+
意思:输入要处理的地址
535+
返回值
536+
类型:逻辑型
537+
意思:是否成功
538+
备注:
539+
*********************************************************************/
540+
bool CSession_UPStroage::Session_UPStroage_SetBoundaryStart(LPCXSTR lpszClientAddr)
541+
{
542+
Session_IsErrorOccur = false;
543+
544+
st_Locker.lock_shared();
545+
unordered_map<string, SESSION_STORAGEUPLOADER>::iterator stl_MapIterator = stl_MapStroage.find(lpszClientAddr);
546+
if (stl_MapIterator == stl_MapStroage.end())
547+
{
548+
Session_IsErrorOccur = true;
549+
Session_dwErrorCode = ERROR_STORAGE_MODULE_SESSION_NOTFOUND;
550+
st_Locker.unlock_shared();
551+
return false;
552+
}
553+
stl_MapIterator->second.st_StorageInfo.st_Boundary.bBoundStart = true;
554+
555+
st_Locker.unlock_shared();
556+
return true;
484557
}

XEngine_Source/StorageModule_Session/Session_Stroage/Session_UPStroage.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class CSession_UPStroage
3232
bool Session_UPStroage_Delete(LPCXSTR lpszClientAddr);
3333
bool Session_UPStroage_Close(LPCXSTR lpszClientAddr);
3434
bool Session_UPStroage_MaxConnect(LPCXSTR lpszClientAddr);
35+
bool Session_UPStroage_SetBoundary(LPCXSTR lpszClientAddr, LPCXSTR lpszBoundary);
36+
bool Session_UPStroage_SetBoundaryStart(LPCXSTR lpszClientAddr);
3537
private:
3638
bool m_bResume;
3739
int m_nMaxConnect;

XEngine_Source/StorageModule_Session/StorageModule_Session.def

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ EXPORTS
2727
Session_UPStorage_GetAll
2828
Session_UPStroage_Delete
2929
Session_UPStroage_Close
30-
Session_UPStroage_MaxConnect
30+
Session_UPStroage_MaxConnect
31+
Session_UPStroage_SetBoundary
32+
Session_UPStroage_SetBoundaryStart

XEngine_Source/StorageModule_Session/pch.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,12 @@ extern "C" bool Session_UPStroage_Close(LPCXSTR lpszClientAddr)
127127
extern "C" bool Session_UPStroage_MaxConnect(LPCXSTR lpszClientAddr)
128128
{
129129
return m_UPStorage.Session_UPStroage_MaxConnect(lpszClientAddr);
130+
}
131+
extern "C" bool Session_UPStroage_SetBoundary(LPCXSTR lpszClientAddr, LPCXSTR lpszBoundary)
132+
{
133+
return m_UPStorage.Session_UPStroage_SetBoundary(lpszClientAddr, lpszBoundary);
134+
}
135+
extern "C" bool Session_UPStroage_SetBoundaryStart(LPCXSTR lpszClientAddr)
136+
{
137+
return m_UPStorage.Session_UPStroage_SetBoundaryStart(lpszClientAddr);
130138
}

0 commit comments

Comments
 (0)