FtpControlSocket.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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 TryGetReplyCode();
  106. int GetReplyCode();
  107. CString GetReply();
  108. void LogOnToServer(BOOL bSkipReply = FALSE);
  109. BOOL Send(CString str);
  110. BOOL ParsePwdReply(CString & rawpwd);
  111. BOOL ParsePwdReply(CString & rawpwd, CServerPath & realPath);
  112. BOOL SendAuthSsl();
  113. void DiscardLine(CStringA line);
  114. int FileTransferListState(bool get);
  115. bool NeedModeCommand();
  116. bool NeedOptsCommand();
  117. CString GetListingCmd();
  118. bool InitConnect();
  119. int InitConnectState();
  120. bool IsRoutableAddress(const CString & host);
  121. bool CheckForcePasvIp(CString & host);
  122. void TransferFinished(bool preserveFileTimeForUploads);
  123. virtual void LogSocketMessageRaw(int nMessageType, LPCTSTR pMsg);
  124. virtual bool LoggingSocketMessage(int nMessageType);
  125. virtual int GetSocketOptionVal(int OptionID) const;
  126. void ShowStatus(UINT nID, int type) const;
  127. void ShowStatus(CString status,int type) const;
  128. void ShowTimeoutError(UINT nID) const;
  129. void Close();
  130. BOOL Connect(CString hostAddress, UINT nHostPort);
  131. CString ConvertDomainName(CString domain);
  132. bool ConnectTransferSocket(const CString & host, UINT port);
  133. struct t_ActiveList
  134. {
  135. CFtpControlSocket * pOwner;
  136. __int64 nBytesAvailable;
  137. __int64 nBytesTransferred;
  138. };
  139. static std::list<t_ActiveList> m_InstanceList[2];
  140. static CTime m_CurrentTransferTime[2];
  141. static _int64 m_CurrentTransferLimit[2];
  142. static CCriticalSectionWrapper m_SpeedLimitSync;
  143. _int64 GetAbleToUDSize(bool & beenWaiting, CTime & curTime, _int64 & curLimit, std::list<t_ActiveList>::iterator & iter, enum transferDirection direction, int nBufSize);
  144. _int64 GetSpeedLimit(CTime & time, int valType, int valValue);
  145. void SetDirectoryListing(t_directory * pDirectory, bool bSetWorkingDir = true);
  146. int CheckOverwriteFile();
  147. int CheckOverwriteFileAndCreateTarget();
  148. int FileTransferHandleDirectoryListing(t_directory * pDirectory);
  149. t_directory * m_pDirectoryListing;
  150. CMainThread * m_pOwner;
  151. CFileZillaTools * m_pTools;
  152. CFile * m_pDataFile;
  153. CTransferSocket * m_pTransferSocket;
  154. CStringA m_MultiLine;
  155. CTime m_LastSendTime;
  156. CString m_ServerName;
  157. std::list<CStringA> m_RecvBuffer;
  158. CTime m_LastRecvTime;
  159. class CLogonData;
  160. class CListData;
  161. class CListFileData;
  162. class CFileTransferData;
  163. class CMakeDirData;
  164. #ifndef MPEXT_NO_ZLIB
  165. bool m_useZlib;
  166. bool m_zlibSupported;
  167. int m_zlibLevel;
  168. #endif
  169. bool m_bUTF8;
  170. bool m_bAnnouncesUTF8;
  171. bool m_hasClntCmd;
  172. TFTPServerCapabilities m_serverCapabilities;
  173. CStringA m_ListFile;
  174. __int64 m_ListFileSize;
  175. bool m_isFileZilla;
  176. bool m_awaitsReply;
  177. bool m_skipReply;
  178. char * m_sendBuffer;
  179. int m_sendBufferLen;
  180. bool m_bProtP;
  181. bool m_mayBeMvsFilesystem;
  182. bool m_mayBeBS2000Filesystem;
  183. struct t_operation
  184. {
  185. int nOpMode;
  186. int nOpState;
  187. class COpData //Base class which will store operation specific parameters.
  188. {
  189. public:
  190. COpData() {};
  191. virtual ~COpData() {};
  192. };
  193. COpData * pData;
  194. public:
  195. };
  196. t_operation m_Operation;
  197. CAsyncProxySocketLayer * m_pProxyLayer;
  198. CAsyncSslSocketLayer * m_pSslLayer;
  199. #ifndef MPEXT_NO_GSS
  200. CAsyncGssSocketLayer * m_pGssLayer;
  201. #endif
  202. t_server m_CurrentServer;
  203. private:
  204. BOOL m_bCheckForTimeout;
  205. };
  206. //---------------------------------------------------------------------------
  207. #endif // FtpControlSocketH