1+ #include " pch.h"
2+ #include " Session_FTPContral.h"
3+ /* *******************************************************************
4+ // Created: 2024/08/05 16:14:56
5+ // File Name: D:\XEngine_Storage\XEngine_Source\StorageModule_Session\Session_FTPContral\Session_FTPContral.cpp
6+ // File Path: D:\XEngine_Storage\XEngine_Source\StorageModule_Session\Session_FTPContral
7+ // File Base: Session_FTPContral
8+ // File Ext: cpp
9+ // Project: XEngine
10+ // Author: qyt
11+ // Purpose: FTP会话
12+ // History:
13+ *********************************************************************/
14+ CSession_FTPContral::CSession_FTPContral ()
15+ {
16+ }
17+ CSession_FTPContral::~CSession_FTPContral ()
18+ {
19+ }
20+ // ////////////////////////////////////////////////////////////////////////
21+ // 公有函数
22+ // ////////////////////////////////////////////////////////////////////////
23+ /* *******************************************************************
24+ 函数名称:Session_FTP_Insert
25+ 函数功能:插入一个会话
26+ 参数.一:lpszClientAddr
27+ In/Out:In
28+ 类型:常量字符指针
29+ 可空:N
30+ 意思:输入客户端地址
31+ 参数.二:bUPLoader
32+ In/Out:In
33+ 类型:逻辑型
34+ 可空:N
35+ 意思:输入是否为上传会话
36+ 返回值
37+ 类型:逻辑型
38+ 意思:是否成功
39+ 备注:
40+ *********************************************************************/
41+ bool CSession_FTPContral::Session_FTP_Insert (LPCXSTR lpszClientAddr, bool bUPLoader)
42+ {
43+ Session_IsErrorOccur = false ;
44+
45+ SESSION_FTPCONTRAL st_FTPSession = {};
46+
47+ st_FTPSession.nTimeStart = time (NULL );
48+ st_FTPSession.bUPLoader = bUPLoader;
49+
50+ st_Locker.lock ();
51+ stl_MapAction.insert (make_pair (lpszClientAddr, st_FTPSession));
52+ st_Locker.unlock ();
53+ return true ;
54+ }
55+ /* *******************************************************************
56+ 函数名称:Session_FTP_Set
57+ 函数功能:设置
58+ 参数.一:lpszClientAddr
59+ In/Out:In
60+ 类型:常量字符指针
61+ 可空:N
62+ 意思:输入客户端地址
63+ 参数.二:lpszFileName
64+ In/Out:In
65+ 类型:常量字符指针
66+ 可空:Y
67+ 意思:输入要操作的文件
68+ 参数.三:lpszFilePath
69+ In/Out:In
70+ 类型:常量字符指针
71+ 可空:Y
72+ 意思:输入要操作的文件路径
73+ 参数.四:lpszAlisName
74+ In/Out:In
75+ 类型:常量字符指针
76+ 可空:Y
77+ 意思:输入路径别名
78+ 返回值
79+ 类型:逻辑型
80+ 意思:是否成功
81+ 备注:
82+ *********************************************************************/
83+ bool CSession_FTPContral::Session_FTP_Set (LPCXSTR lpszClientAddr, LPCXSTR lpszFileName, LPCXSTR lpszFilePath, LPCXSTR lpszAlisName)
84+ {
85+ Session_IsErrorOccur = false ;
86+
87+ std::shared_lock<std::shared_mutex> st_AutoLock (st_Locker);
88+
89+ unordered_map<xstring, SESSION_FTPCONTRAL >::iterator stl_MapIterator = stl_MapAction.find (lpszClientAddr);
90+ if (stl_MapIterator == stl_MapAction.end ())
91+ {
92+ Session_IsErrorOccur = true ;
93+ Session_dwErrorCode = ERROR_STORAGE_MODULE_SESSION_NOTFOUND ;
94+ return NULL ;
95+ }
96+
97+ if (NULL != lpszFileName)
98+ {
99+ memset (stl_MapIterator->second .tszFileName , ' \0 ' , sizeof (stl_MapIterator->second .tszFileName ));
100+ _tcsxcpy (stl_MapIterator->second .tszFileName , lpszFileName);
101+ }
102+ if (NULL != lpszFilePath)
103+ {
104+ memset (stl_MapIterator->second .tszFilePath , ' \0 ' , sizeof (stl_MapIterator->second .tszFilePath ));
105+ _tcsxcpy (stl_MapIterator->second .tszFilePath , lpszFilePath);
106+ }
107+ if (NULL != lpszAlisName)
108+ {
109+ memset (stl_MapIterator->second .tszAlisPath , ' \0 ' , sizeof (stl_MapIterator->second .tszAlisPath ));
110+ _tcsxcpy (stl_MapIterator->second .tszAlisPath , lpszAlisName);
111+ }
112+ return true ;
113+ }
114+ /* *******************************************************************
115+ 函数名称:Session_FTP_Get
116+ 函数功能:获取信息
117+ 参数.一:lpszClientAddr
118+ In/Out:In
119+ 类型:常量字符指针
120+ 可空:N
121+ 意思:输入要操作的客户端地址
122+ 参数.二:ptszFileName
123+ In/Out:Out
124+ 类型:字符指针
125+ 可空:Y
126+ 意思:输出操作的文件
127+ 参数.三:ptszFilePath
128+ In/Out:Out
129+ 类型:字符指针
130+ 可空:Y
131+ 意思:输出操作的文件路径
132+ 参数.四:ptszAlisPath
133+ In/Out:Out
134+ 类型:字符指针
135+ 可空:Y
136+ 意思:输出操作的路径别名
137+ 返回值
138+ 类型:逻辑型
139+ 意思:是否成功
140+ 备注:
141+ *********************************************************************/
142+ bool CSession_FTPContral::Session_FTP_Get (LPCXSTR lpszClientAddr, XCHAR * ptszFileName, XCHAR * ptszFilePath, XCHAR * ptszAlisPath)
143+ {
144+ Session_IsErrorOccur = false ;
145+
146+ std::shared_lock<std::shared_mutex> st_AutoLock (st_Locker);
147+ unordered_map<xstring, SESSION_FTPCONTRAL >::iterator stl_MapIterator = stl_MapAction.find (lpszClientAddr);
148+ if (stl_MapIterator == stl_MapAction.end ())
149+ {
150+ Session_IsErrorOccur = true ;
151+ Session_dwErrorCode = ERROR_STORAGE_MODULE_SESSION_NOTFOUND ;
152+ return NULL ;
153+ }
154+
155+ if (NULL != ptszFilePath)
156+ {
157+ _tcsxcpy (ptszFilePath, stl_MapIterator->second .tszFilePath );
158+ }
159+ if (NULL != ptszFileName)
160+ {
161+ _tcsxcpy (ptszFileName, stl_MapIterator->second .tszFileName );
162+ }
163+ if (NULL != ptszAlisPath)
164+ {
165+ _tcsxcpy (ptszAlisPath, stl_MapIterator->second .tszAlisPath );
166+ }
167+ return true ;
168+ }
169+ /* *******************************************************************
170+ 函数名称:Session_FTP_SetSocket
171+ 函数功能:设置网络句柄
172+ 参数.一:lpszClientAddr
173+ In/Out:In
174+ 类型:常量字符指针
175+ 可空:N
176+ 意思:输入要操作的客户端地址
177+ 参数.二:nPort
178+ In/Out:In
179+ 类型:整数型
180+ 可空:N
181+ 意思:输入操作的端口
182+ 参数.二:xhToken
183+ In/Out:In
184+ 类型:句柄
185+ 可空:N
186+ 意思:输入操作的套接字句柄
187+ 返回值
188+ 类型:逻辑型
189+ 意思:是否设置成功
190+ 备注:
191+ *********************************************************************/
192+ bool CSession_FTPContral::Session_FTP_SetSocket (LPCXSTR lpszClientAddr, int nPort, XHANDLE xhToken)
193+ {
194+ Session_IsErrorOccur = false ;
195+ std::shared_lock<std::shared_mutex> st_AutoLock (st_Locker);
196+ unordered_map<xstring, SESSION_FTPCONTRAL >::iterator stl_MapIterator = stl_MapAction.find (lpszClientAddr);
197+ if (stl_MapIterator == stl_MapAction.end ())
198+ {
199+ Session_IsErrorOccur = true ;
200+ Session_dwErrorCode = ERROR_STORAGE_MODULE_SESSION_NOTFOUND ;
201+ return NULL ;
202+ }
203+ stl_MapIterator->second .nPort = nPort;
204+ stl_MapIterator->second .xhToken = xhToken;
205+ return true ;
206+ }
207+ /* *******************************************************************
208+ 函数名称:Session_FTP_GetSocket
209+ 函数功能:获取网络句柄
210+ 参数.一:lpszClientAddr
211+ In/Out:In
212+ 类型:常量字符指针
213+ 可空:N
214+ 意思:输入要操作的客户端地址
215+ 参数.二:pInt_Port
216+ In/Out:Out
217+ 类型:整数型指针
218+ 可空:Y
219+ 意思:输出操作的端口
220+ 返回值
221+ 类型:句柄
222+ 意思:返回获取到的网络句柄
223+ 备注:
224+ *********************************************************************/
225+ XHANDLE CSession_FTPContral::Session_FTP_GetSocket (LPCXSTR lpszClientAddr, int * pInt_Port)
226+ {
227+ Session_IsErrorOccur = false ;
228+
229+ std::shared_lock<std::shared_mutex> st_AutoLock (st_Locker);
230+ unordered_map<xstring, SESSION_FTPCONTRAL >::iterator stl_MapIterator = stl_MapAction.find (lpszClientAddr);
231+ if (stl_MapIterator == stl_MapAction.end ())
232+ {
233+ Session_IsErrorOccur = true ;
234+ Session_dwErrorCode = ERROR_STORAGE_MODULE_SESSION_NOTFOUND ;
235+ return NULL ;
236+ }
237+
238+ if (NULL != pInt_Port)
239+ {
240+ *pInt_Port = stl_MapIterator->second .nPort ;
241+ }
242+ return stl_MapIterator->second .xhToken ;
243+ }
244+ /* *******************************************************************
245+ 函数名称:Session_FTP_SetRetr
246+ 函数功能:设置断点续传
247+ 参数.一:lpszClientAddr
248+ In/Out:In
249+ 类型:常量字符指针
250+ 可空:N
251+ 意思:输入要操作的客户端地址
252+ 参数.二:nPos
253+ In/Out:In
254+ 类型:整数型
255+ 可空:N
256+ 意思:输入断点续传位置
257+ 返回值
258+ 类型:逻辑型
259+ 意思:是否成功
260+ 备注:
261+ *********************************************************************/
262+ bool CSession_FTPContral::Session_FTP_SetRetr (LPCXSTR lpszClientAddr, __int64u nPos)
263+ {
264+ Session_IsErrorOccur = false ;
265+
266+ std::shared_lock<std::shared_mutex> st_AutoLock (st_Locker);
267+ unordered_map<xstring, SESSION_FTPCONTRAL >::iterator stl_MapIterator = stl_MapAction.find (lpszClientAddr);
268+ if (stl_MapIterator == stl_MapAction.end ())
269+ {
270+ Session_IsErrorOccur = true ;
271+ Session_dwErrorCode = ERROR_STORAGE_MODULE_SESSION_NOTFOUND ;
272+ return false ;
273+ }
274+ stl_MapIterator->second .nPos = nPos;
275+ return true ;
276+ }
277+ /* *******************************************************************
278+ 函数名称:Session_FTP_GetRetr
279+ 函数功能:获取断点续传
280+ 参数.一:lpszClientAddr
281+ In/Out:In
282+ 类型:常量字符指针
283+ 可空:N
284+ 意思:输入要操作的客户端地址
285+ 参数.二:pInt_Pos
286+ In/Out:Out
287+ 类型:整数型指针
288+ 可空:Y
289+ 意思:输出断点续传位置
290+ 返回值
291+ 类型:逻辑型
292+ 意思:是否成功
293+ 备注:
294+ *********************************************************************/
295+ bool CSession_FTPContral::Session_FTP_GetRetr (LPCXSTR lpszClientAddr, __int64u* pInt_Pos)
296+ {
297+ Session_IsErrorOccur = false ;
298+
299+ std::shared_lock<std::shared_mutex> st_AutoLock (st_Locker);
300+ unordered_map<xstring, SESSION_FTPCONTRAL >::iterator stl_MapIterator = stl_MapAction.find (lpszClientAddr);
301+ if (stl_MapIterator == stl_MapAction.end ())
302+ {
303+ Session_IsErrorOccur = true ;
304+ Session_dwErrorCode = ERROR_STORAGE_MODULE_SESSION_NOTFOUND ;
305+ return false ;
306+ }
307+ *pInt_Pos = stl_MapIterator->second .nPort ;
308+ return true ;
309+ }
310+ /* *******************************************************************
311+ 函数名称:Session_FTP_Delete
312+ 函数功能:删除一个会话
313+ 参数.一:lpszClientAddr
314+ In/Out:In
315+ 类型:常量字符指针
316+ 可空:N
317+ 意思:输入要操作的客户端地址
318+ 返回值
319+ 类型:逻辑型
320+ 意思:是否成功
321+ 备注:
322+ *********************************************************************/
323+ bool CSession_FTPContral::Session_FTP_Delete (LPCXSTR lpszClientAddr)
324+ {
325+ Session_IsErrorOccur = false ;
326+
327+ std::unique_lock<std::shared_mutex> st_AutoLock (st_Locker);
328+
329+ unordered_map<xstring, SESSION_FTPCONTRAL >::iterator stl_MapIterator = stl_MapAction.find (lpszClientAddr);
330+ if (stl_MapIterator != stl_MapAction.end ())
331+ {
332+ stl_MapAction.erase (stl_MapIterator);
333+ }
334+ return true ;
335+ }
0 commit comments