FtpControlSocket.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. //---------------------------------------------------------------------------
  2. #ifndef FtpControlSocketH
  3. #define FtpControlSocketH
  4. //---------------------------------------------------------------------------
  5. #include "structures.h"
  6. #include "stdafx.h"
  7. #include "FileZillaApi.h"
  8. #include "FileZillaIntf.h"
  9. //---------------------------------------------------------------------------
  10. class CTransferSocket;
  11. class CMainThread;
  12. //---------------------------------------------------------------------------
  13. class CAsyncProxySocketLayer;
  14. class CFtpListResult;
  15. //---------------------------------------------------------------------------
  16. #define CSMODE_NONE 0x0000
  17. #define CSMODE_CONNECT 0x0001
  18. #define CSMODE_COMMAND 0x0002
  19. #define CSMODE_LIST 0x0004
  20. #define CSMODE_TRANSFER 0x0008
  21. #define CSMODE_DOWNLOAD 0x0010
  22. #define CSMODE_UPLOAD 0x0020
  23. #define CSMODE_TRANSFERERROR 0x0040
  24. #define CSMODE_TRANSFERTIMEOUT 0x0080
  25. #define CSMODE_DELETE 0x0100
  26. #define CSMODE_RMDIR 0x0200
  27. #define CSMODE_DISCONNECT 0x0400
  28. #define CSMODE_MKDIR 0x0800
  29. #define CSMODE_RENAME 0x1000
  30. #define CSMODE_CHMOD 0x2000
  31. #define CSMODE_LISTFILE 0x4000
  32. //---------------------------------------------------------------------------
  33. typedef struct
  34. {
  35. BOOL bResume,bResumeAppend,bType;
  36. __int64 transfersize,transferleft;
  37. } t_transferdata;
  38. //---------------------------------------------------------------------------
  39. class CFtpControlSocket : public CAsyncSocketEx, public CApiLog
  40. {
  41. friend CTransferSocket;
  42. public:
  43. CFtpControlSocket(CMainThread * pMainThread, CFileZillaTools * pTools);
  44. virtual ~CFtpControlSocket();
  45. public:
  46. void Connect(t_server & server);
  47. virtual void OnTimer();
  48. BOOL IsReady();
  49. void List(BOOL bFinish, int nError = 0, CServerPath path = CServerPath(), CString subdir = L"");
  50. void ListFile(CString filename, const CServerPath & path);
  51. void FtpCommand(LPCTSTR pCommand);
  52. void Disconnect();
  53. void FileTransfer(t_transferfile * transferfile = 0, BOOL bFinish = FALSE, int nError = 0);
  54. void Delete(CString filename, const CServerPath & path, bool filenameOnly);
  55. void Rename(CString oldName, CString newName, const CServerPath & path, const CServerPath & newPath);
  56. void MakeDir(const CServerPath & path);
  57. void RemoveDir(CString dirname, const CServerPath & path);
  58. void Chmod(CString filename, const CServerPath & path, int nValue);
  59. void ProcessReply();
  60. void TransferEnd(int nMode);
  61. void Cancel(BOOL bQuit = FALSE);
  62. void SetAsyncRequestResult(int nAction, CAsyncRequestData * pData);
  63. BOOL Create();
  64. void TransfersocketListenFinished(unsigned int ip, unsigned short port);
  65. BOOL m_bKeepAliveActive;
  66. BOOL m_bDidRejectCertificate;
  67. // Some servers are broken. Instead of an empty listing, some MVS servers
  68. // for example they return something "550 no members found"
  69. // Other servers return "550 No files found."
  70. bool IsMisleadingListResponse();
  71. bool UsingMlsd();
  72. bool UsingUtf8();
  73. std::string GetTlsVersionStr();
  74. std::string GetCipherName();
  75. bool HandleSize(int code, __int64 & size);
  76. bool HandleMdtm(int code, t_directory::t_direntry::t_date & date);
  77. void TransferHandleListError();
  78. enum transferDirection
  79. {
  80. download = 0,
  81. upload = 1
  82. };
  83. BOOL RemoveActiveTransfer();
  84. BOOL SpeedLimitAddTransferredBytes(enum transferDirection direction, _int64 nBytesTransferred);
  85. _int64 GetSpeedLimit(enum transferDirection direction, CTime & time);
  86. _int64 GetAbleToTransferSize(enum transferDirection direction, bool &beenWaiting, int nBufSize = 0);
  87. t_server GetCurrentServer();
  88. CFtpListResult * CreateListResult(bool mlst);
  89. public:
  90. virtual void OnReceive(int nErrorCode);
  91. virtual void OnConnect(int nErrorCode);
  92. virtual void OnClose(int nErrorCode);
  93. virtual void OnSend(int nErrorCode);
  94. protected:
  95. // Called by OnTimer()
  96. void ResumeTransfer();
  97. void CheckForTimeout();
  98. void SendKeepAliveCommand();
  99. virtual int OnLayerCallback(std::list<t_callbackMsg> & callbacks);
  100. void SetFileExistsAction(int nAction, COverwriteRequestData * pData);
  101. void SetVerifyCertResult(int nResult, t_SslCertData * pData);
  102. void ResetOperation(int nSuccessful = -1);
  103. void ResetTransferSocket(int Error);
  104. void DoClose(int nError = 0);
  105. int GetReplyCode();
  106. CString GetReply();
  107. void LogOnToServer(BOOL bSkipReply = FALSE);
  108. BOOL Send(CString str);
  109. BOOL ParsePwdReply(CString & rawpwd);
  110. BOOL ParsePwdReply(CString & rawpwd, CServerPath & realPath);
  111. BOOL SendAuthSsl();
  112. void DiscardLine(CStringA line);
  113. int FileTransferListState(bool get);
  114. bool NeedModeCommand();
  115. bool NeedOptsCommand();
  116. CString GetListingCmd();
  117. bool InitConnect();
  118. int InitConnectState();
  119. bool IsRoutableAddress(const CString & host);
  120. bool CheckForcePasvIp(CString & host);
  121. void TransferFinished(bool preserveFileTimeForUploads);
  122. virtual void LogSocketMessageRaw(int nMessageType, LPCTSTR pMsg);
  123. virtual bool LoggingSocketMessage(int nMessageType);
  124. virtual int GetSocketOptionVal(int OptionID) const;
  125. void ShowStatus(UINT nID, int type) const;
  126. void ShowStatus(CString status,int type) const;
  127. void ShowTimeoutError(UINT nID) const;
  128. void Close();
  129. BOOL Connect(CString hostAddress, UINT nHostPort);
  130. CString ConvertDomainName(CString domain);
  131. bool ConnectTransferSocket(const CString & host, UINT port);
  132. struct t_ActiveList
  133. {
  134. CFtpControlSocket * pOwner;
  135. __int64 nBytesAvailable;
  136. __int64 nBytesTransferred;
  137. };
  138. static std::list<t_ActiveList> m_InstanceList[2];
  139. static CTime m_CurrentTransferTime[2];
  140. static _int64 m_CurrentTransferLimit[2];
  141. static CCriticalSectionWrapper m_SpeedLimitSync;
  142. _int64 GetAbleToUDSize(bool & beenWaiting, CTime & curTime, _int64 & curLimit, std::list<t_ActiveList>::iterator & iter, enum transferDirection direction, int nBufSize);
  143. _int64 GetSpeedLimit(CTime & time, int valType, int valValue);
  144. void SetDirectoryListing(t_directory * pDirectory, bool bSetWorkingDir = true);
  145. int CheckOverwriteFile();
  146. int CheckOverwriteFileAndCreateTarget();
  147. int FileTransferHandleDirectoryListing(t_directory * pDirectory);
  148. t_directory * m_pDirectoryListing;
  149. CMainThread * m_pOwner;
  150. CFileZillaTools * m_pTools;
  151. CFile * m_pDataFile;
  152. CTransferSocket * m_pTransferSocket;
  153. CStringA m_MultiLine;
  154. CTime m_LastSendTime;
  155. CString m_ServerName;
  156. std::list<CStringA> m_RecvBuffer;
  157. CTime m_LastRecvTime;
  158. class CLogonData;
  159. class CListData;
  160. class CListFileData;
  161. class CFileTransferData;
  162. class CMakeDirData;
  163. #ifndef MPEXT_NO_ZLIB
  164. bool m_useZlib;
  165. bool m_zlibSupported;
  166. int m_zlibLevel;
  167. #endif
  168. bool m_bUTF8;
  169. bool m_bAnnouncesUTF8;
  170. bool m_hasClntCmd;
  171. TFTPServerCapabilities m_serverCapabilities;
  172. CStringA m_ListFile;
  173. __int64 m_ListFileSize;
  174. bool m_isFileZilla;
  175. bool m_awaitsReply;
  176. bool m_skipReply;
  177. char * m_sendBuffer;
  178. int m_sendBufferLen;
  179. bool m_bProtP;
  180. bool m_mayBeMvsFilesystem;
  181. bool m_mayBeBS2000Filesystem;
  182. struct t_operation
  183. {
  184. int nOpMode;
  185. int nOpState;
  186. class COpData //Base class which will store operation specific parameters.
  187. {
  188. public:
  189. COpData() {};
  190. virtual ~COpData() {};
  191. };
  192. COpData * pData;
  193. public:
  194. };
  195. t_operation m_Operation;
  196. CAsyncProxySocketLayer * m_pProxyLayer;
  197. CAsyncSslSocketLayer * m_pSslLayer;
  198. #ifndef MPEXT_NO_GSS
  199. CAsyncGssSocketLayer * m_pGssLayer;
  200. #endif
  201. t_server m_CurrentServer;
  202. private:
  203. BOOL m_bCheckForTimeout;
  204. };
  205. //---------------------------------------------------------------------------
  206. #endif // FtpControlSocketH