Skip to content

Commit 208ece1

Browse files
committed
added:upload and download action support
1 parent 6dff64e commit 208ece1

File tree

13 files changed

+186
-2
lines changed

13 files changed

+186
-2
lines changed

XEngine_Source/StorageModule_APIHelp/APIHelp_Define.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,30 @@ extern "C" bool APIHelp_Distributed_FileList(list<APIHELP_LBFILEINFO>* pStl_List
9595
*********************************************************************/
9696
extern "C" bool APIHelp_Distributed_DLStorage(LPCXSTR lpszMsgBuffer, list<XENGINE_STORAGEBUCKET>* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket);
9797
/********************************************************************
98+
函数名称:APIHelp_Distributed_GetPathKey
99+
函数功能:通过BUCKET名称查找对应路径
100+
参数.一:pStl_ListBucket
101+
In/Out:In
102+
类型:STL容器指针
103+
可空:N
104+
意思:输入要操作的BUCKET容器
105+
参数.二:lpszBuckKey
106+
In/Out:In
107+
类型:常量字符指针
108+
可空:N
109+
意思:输入要匹配的BUCKET名称
110+
参数.三:ptszFilePath
111+
In/Out:Out
112+
类型:字符指针
113+
可空:N
114+
意思:输出找到的路径
115+
返回值
116+
类型:逻辑型
117+
意思:是否成功
118+
备注:
119+
*********************************************************************/
120+
extern "C" bool APIHelp_Distributed_CTStorage(LPCXSTR lpszMsgBuffer, list<XENGINE_STORAGEBUCKET>* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket);
121+
/********************************************************************
98122
函数名称:APIHelp_Distributed_UPStorage
99123
函数功能:通过分布式存储列表获得一个存储地址
100124
参数.一:pStl_ListBucket

XEngine_Source/StorageModule_APIHelp/APIHelp_Distributed/APIHelp_Distributed.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,58 @@ bool CAPIHelp_Distributed::APIHelp_Distributed_DLStorage(LPCXSTR lpszMsgBuffer,
212212
return true;
213213
}
214214
/********************************************************************
215+
函数名称:APIHelp_Distributed_CTStorage
216+
函数功能:通过KEY得到一个对应下载地址
217+
参数.一:lpszMsgBuffer
218+
In/Out:In
219+
类型:常量字符指针
220+
可空:N
221+
意思:输入要解析的URL
222+
参数.二:pStl_ListBucket
223+
In/Out:In
224+
类型:容器指针
225+
可空:N
226+
意思:输入要解析的列表
227+
参数.三:pSt_StorageBucket
228+
In/Out:Out
229+
类型:数据结构指针
230+
可空:N
231+
意思:输出获取到的可用存储
232+
返回值
233+
类型:逻辑型
234+
意思:是否成功
235+
备注:
236+
*********************************************************************/
237+
bool CAPIHelp_Distributed::APIHelp_Distributed_CTStorage(LPCXSTR lpszMsgBuffer, list<XENGINE_STORAGEBUCKET>* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket)
238+
{
239+
APIHelp_IsErrorOccur = false;
240+
241+
if ((NULL == lpszMsgBuffer) || (NULL == pSt_StorageBucket))
242+
{
243+
APIHelp_IsErrorOccur = true;
244+
APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_PARAMENT;
245+
return false;
246+
}
247+
bool bFound = false;
248+
//获得对应存储
249+
for (auto stl_ListIterator = pStl_ListBucket->begin(); stl_ListIterator != pStl_ListBucket->end(); stl_ListIterator++)
250+
{
251+
if (0 == _tcsxncmp(lpszMsgBuffer, stl_ListIterator->tszBuckKey, _tcsxlen(lpszMsgBuffer)))
252+
{
253+
bFound = true;
254+
*pSt_StorageBucket = *stl_ListIterator;
255+
break;
256+
}
257+
}
258+
if (!bFound)
259+
{
260+
APIHelp_IsErrorOccur = true;
261+
APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_NOTFOUND;
262+
return false;
263+
}
264+
return true;
265+
}
266+
/********************************************************************
215267
函数名称:APIHelp_Distributed_UPStorage
216268
函数功能:通过分布式存储列表获得一个存储地址
217269
参数.一:pStl_ListBucket

XEngine_Source/StorageModule_APIHelp/APIHelp_Distributed/APIHelp_Distributed.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class CAPIHelp_Distributed
2121
bool APIHelp_Distributed_RandomAddr(list<string>* pStl_ListAddr, XCHAR* ptszAddr, int nMode);
2222
bool APIHelp_Distributed_FileList(list<APIHELP_LBFILEINFO>* pStl_ListParse, XSTORAGECORE_DBFILE*** pppSt_ListPacket, int* pInt_ListCount);
2323
bool APIHelp_Distributed_DLStorage(LPCXSTR lpszMsgBuffer, list<XENGINE_STORAGEBUCKET>* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket);
24+
bool APIHelp_Distributed_CTStorage(LPCXSTR lpszMsgBuffer, list<XENGINE_STORAGEBUCKET>* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket);
2425
bool APIHelp_Distributed_UPStorage(list<XENGINE_STORAGEBUCKET>* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket, int nMode);
2526
bool APIHelp_Distributed_GetPathKey(list<XENGINE_STORAGEBUCKET>* pStl_ListBucket, LPCXSTR lpszBuckKey, XCHAR* ptszFilePath);
2627
protected:

XEngine_Source/StorageModule_APIHelp/StorageModule_APIHelp.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ EXPORTS
66
APIHelp_Distributed_RandomAddr
77
APIHelp_Distributed_FileList
88
APIHelp_Distributed_DLStorage
9+
APIHelp_Distributed_CTStorage
910
APIHelp_Distributed_UPStorage
1011
APIHelp_Distributed_GetPathKey
1112

XEngine_Source/StorageModule_APIHelp/StorageModule_APIHelp.vcxproj

Lines changed: 1 addition & 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;..\StorageModule_APIHelp;$(IncludePath)</IncludePath>
7676
<LibraryPath>$(XEngine_Lib32);$(LibraryPath)</LibraryPath>
7777
</PropertyGroup>
7878
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">

XEngine_Source/StorageModule_APIHelp/pch.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ extern "C" bool APIHelp_Distributed_DLStorage(LPCXSTR lpszMsgBuffer, list<XENGIN
4343
{
4444
return m_APIDistributed.APIHelp_Distributed_DLStorage(lpszMsgBuffer, pStl_ListBucket, pSt_StorageBucket);
4545
}
46+
extern "C" bool APIHelp_Distributed_CTStorage(LPCXSTR lpszMsgBuffer, list<XENGINE_STORAGEBUCKET>*pStl_ListBucket, XENGINE_STORAGEBUCKET * pSt_StorageBucket)
47+
{
48+
return m_APIDistributed.APIHelp_Distributed_CTStorage(lpszMsgBuffer, pStl_ListBucket, pSt_StorageBucket);
49+
}
4650
extern "C" bool APIHelp_Distributed_UPStorage(list<XENGINE_STORAGEBUCKET>*pStl_ListBucket, XENGINE_STORAGEBUCKET * pSt_StorageBucket, int nMode)
4751
{
4852
return m_APIDistributed.APIHelp_Distributed_UPStorage(pStl_ListBucket, pSt_StorageBucket, nMode);

XEngine_Source/XEngine_StorageApp/StorageApp_Center.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ bool XEngine_Task_HttpCenter(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int
141141
}
142142
else if (0 == _tcsxnicmp(lpszMehtodAction, tszAPIMethod, _tcsxlen(lpszMehtodAction)))
143143
{
144-
144+
Storage_TaskAction(tszAPIName, lpszClientAddr, lpszMsgBuffer, nMsgLen, pSt_HTTPParam);
145145
}
146146
}
147147
else if (0 == _tcsxnicmp(lpszMethodOption, pSt_HTTPParam->tszHttpMethod, _tcsxlen(lpszMethodOption)))

XEngine_Source/XEngine_StorageApp/StorageApp_Hdr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ extern XENGINE_LBCONFIG st_LoadbalanceCfg;
108108
#include "Storage_APPTask/Storage_TaskPass.h"
109109
#include "Storage_APPTask/Storage_TaskP2p.h"
110110
#include "Storage_APPTask/Storage_TaskManage.h"
111+
#include "Storage_APPTask/Storage_TaskAction.h"
111112

112113
#ifdef _MSC_BUILD
113114
#pragma comment(lib,"Ws2_32.lib")
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#include "../StorageApp_Hdr.h"
2+
3+
void CALLBACK Storage_TaskAction_Callback(XHANDLE xhToken, double dlTotal, double dlNow, double ulTotal, double ulNow, ENUM_XCLIENT_APIHELP_FILE_STATUS en_DownHttpStatus, XPVOID lParam)
4+
{
5+
6+
}
7+
bool Storage_TaskAction(LPCXSTR lpszAPIName, LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int nMsgLen, RFCCOMPONENTS_HTTP_REQPARAM* pSt_HTTPParam)
8+
{
9+
int nSDLen = 10240;
10+
int nRVLen = 10240;
11+
XCHAR tszSDBuffer[10240] = {};
12+
XCHAR tszRVBuffer[10240] = {};
13+
LPCXSTR lpszAPIDownload = _X("download");
14+
LPCXSTR lpszAPIUPload = _X("upload");
15+
XENGINE_ACTIONINFO st_ActionInfo = {};
16+
RFCCOMPONENTS_HTTP_HDRPARAM st_HDRParam = {};
17+
18+
st_HDRParam.bIsClose = true;
19+
st_HDRParam.nHttpCode = 200;
20+
21+
if (!Protocol_StorageParse_Action(lpszMsgBuffer, nMsgLen, &st_ActionInfo))
22+
{
23+
st_HDRParam.nHttpCode = 400;
24+
HttpProtocol_Server_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam);
25+
XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER);
26+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("业务客户端:%s,处理用户转录动作失败,协议解析失败,负载内容:%s"), lpszClientAddr, lpszMsgBuffer);
27+
return false;
28+
}
29+
XCHAR tszFileName[MAX_PATH] = {};
30+
XENGINE_STORAGEBUCKET st_StorageBucket = {};
31+
if (!APIHelp_Distributed_CTStorage(st_ActionInfo.tszBucketStr, st_LoadbalanceCfg.st_LoadBalance.pStl_ListBucket, &st_StorageBucket))
32+
{
33+
st_HDRParam.nHttpCode = 400;
34+
HttpProtocol_Server_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam);
35+
XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER);
36+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("业务客户端:%s,处理用户转录动作失败,存储Key解析失败,URL:%s,路径:%s,Bucket:%s"), lpszClientAddr, st_ActionInfo.tszFileUrl, st_ActionInfo.tszFileName, st_ActionInfo.tszBucketStr);
37+
return false;
38+
}
39+
if (0 == _tcsxnicmp(lpszAPIDownload, lpszAPIName, _tcsxlen(lpszAPIDownload)))
40+
{
41+
XHANDLE xhAction = APIClient_File_Create(st_ActionInfo.tszFileName, tszFileName, true, NULL, Storage_TaskAction_Callback);
42+
if (NULL == xhAction)
43+
{
44+
st_HDRParam.nHttpCode = 501;
45+
HttpProtocol_Server_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam);
46+
XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER);
47+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("业务客户端:%s,处理用户转录动作失败,下载文件失败,URL:%s,路径:%s,Bucket:%s"), lpszClientAddr, st_ActionInfo.tszFileUrl, tszFileName, st_ActionInfo.tszBucketStr);
48+
return false;
49+
}
50+
//APIClient_File_SetMaxSpeed(xhAction);
51+
XNETHANDLE xhToken = 0;
52+
BaseLib_OperatorHandle_Create(&xhToken);
53+
Session_Action_Insert(xhToken, xhAction, &st_ActionInfo);
54+
Protocol_StoragePacket_Action(tszRVBuffer, &nRVLen, xhToken, &st_ActionInfo);
55+
HttpProtocol_Server_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam, tszRVBuffer, nRVLen);
56+
XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER);
57+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("业务客户端:%s,处理用户下载动作成功,URL:%s,路径:%s,句柄:%lld"), lpszClientAddr, st_ActionInfo.tszFileUrl, tszFileName, xhToken);
58+
}
59+
else if (0 == _tcsxnicmp(lpszAPIUPload, lpszAPIName, _tcsxlen(lpszAPIUPload)))
60+
{
61+
XHANDLE xhAction = APIClient_File_Create(st_ActionInfo.tszFileName, tszFileName, false, NULL, Storage_TaskAction_Callback);
62+
if (NULL == xhAction)
63+
{
64+
st_HDRParam.nHttpCode = 501;
65+
HttpProtocol_Server_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam);
66+
XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER);
67+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("业务客户端:%s,处理用户转录动作失败,下载文件失败,URL:%s,路径:%s,Bucket:%s"), lpszClientAddr, st_ActionInfo.tszFileUrl, tszFileName, st_ActionInfo.tszBucketStr);
68+
return false;
69+
}
70+
//APIClient_File_SetMaxSpeed(xhAction);
71+
XNETHANDLE xhToken = 0;
72+
BaseLib_OperatorHandle_Create(&xhToken);
73+
Session_Action_Insert(xhToken, xhAction, &st_ActionInfo);
74+
Protocol_StoragePacket_Action(tszRVBuffer, &nRVLen, xhToken, &st_ActionInfo);
75+
HttpProtocol_Server_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam, tszRVBuffer, nRVLen);
76+
XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER);
77+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("业务客户端:%s,处理用户上传动作成功,URL:%s,路径:%s,句柄:%lld"), lpszClientAddr, st_ActionInfo.tszFileUrl, tszFileName, xhToken);
78+
}
79+
80+
return true;
81+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#pragma once
2+
3+
void CALLBACK Storage_TaskAction_Callback(XHANDLE xhToken, double dlTotal, double dlNow, double ulTotal, double ulNow, ENUM_XCLIENT_APIHELP_FILE_STATUS en_DownHttpStatus, XPVOID lParam);
4+
bool Storage_TaskAction(LPCXSTR lpszAPIName, LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int nMsgLen, RFCCOMPONENTS_HTTP_REQPARAM* pSt_HTTPParam);

0 commit comments

Comments
 (0)