ControlSocket.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. // FileZilla - a Windows ftp client
  2. // Copyright (C) 2002-2004 - Tim Kosse <[email protected]>
  3. // This program is free software; you can redistribute it and/or
  4. // modify it under the terms of the GNU General Public License
  5. // as published by the Free Software Foundation; either version 2
  6. // of the License, or (at your option) any later version.
  7. // This program is distributed in the hope that it will be useful,
  8. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. // GNU General Public License for more details.
  11. // You should have received a copy of the GNU General Public License
  12. // along with this program; if not, write to the Free Software
  13. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. // ControlSocket.h: Schnittstelle für die Klasse CControlSocket.
  15. //
  16. //////////////////////////////////////////////////////////////////////
  17. #if !defined(AFX_CONTROLSOCKET_H__173B4310_5E72_4F4B_A4F0_4E3D4CFAF4A5__INCLUDED_)
  18. #define AFX_CONTROLSOCKET_H__173B4310_5E72_4F4B_A4F0_4E3D4CFAF4A5__INCLUDED_
  19. #if _MSC_VER > 1000
  20. #pragma once
  21. #endif // _MSC_VER > 1000
  22. #include "AsyncSocketEx.h"
  23. #include "FileZillaApi.h"
  24. #include "ApiLog.h"
  25. #include "structures.h" // Hinzugefügt von der Klassenansicht
  26. #ifndef MPEXT_NO_IDENT
  27. #include "IdentServerControl.h" // Added by ClassView
  28. #endif
  29. #define CSMODE_NONE 0x0000
  30. #define CSMODE_CONNECT 0x0001
  31. #define CSMODE_COMMAND 0x0002
  32. #define CSMODE_LIST 0x0004
  33. #define CSMODE_TRANSFER 0x0008
  34. #define CSMODE_DOWNLOAD 0x0010
  35. #define CSMODE_UPLOAD 0x0020
  36. #define CSMODE_TRANSFERERROR 0x0040
  37. #define CSMODE_TRANSFERTIMEOUT 0x0080
  38. #define CSMODE_DELETE 0x0100
  39. #define CSMODE_RMDIR 0x0200
  40. #define CSMODE_DISCONNECT 0x0400
  41. #define CSMODE_MKDIR 0x0800
  42. #define CSMODE_RENAME 0x1000
  43. #define CSMODE_CHMOD 0x2000
  44. #ifdef MPEXT
  45. #define CSMODE_LISTFILE 0x4000
  46. #endif
  47. typedef struct
  48. {
  49. BOOL bResume,bType;
  50. __int64 transfersize,transferleft,nTransferStart;
  51. } t_transferdata;
  52. class CMainThread;
  53. class CAsyncProxySocketLayer;
  54. #ifndef MPEXT_NO_SSL
  55. class CAsyncSslSocketLayer;
  56. #endif
  57. #ifndef MPEXT_NO_GSS
  58. class CAsyncGssSocketLayer;
  59. #endif
  60. class CTransferSocket;
  61. class CFileZillaTools;
  62. #define BUFSIZE 16384
  63. class CControlSocket : public CAsyncSocketEx, public CApiLog
  64. {
  65. public:
  66. CControlSocket(CMainThread *pMainThread, CFileZillaTools * pTools);
  67. virtual ~CControlSocket();
  68. enum transferDirection
  69. {
  70. download = 0,
  71. upload = 1
  72. };
  73. //Operations
  74. virtual void Connect(t_server &server)=0;
  75. virtual void List(BOOL bFinish, int nError=0, CServerPath path=CServerPath(), CString subdir=_MPT(""), int nListMode = 0)=0;
  76. #ifdef MPEXT
  77. virtual void ListFile(CServerPath path=CServerPath(), CString fileName = _MPT(""))=0;
  78. #endif
  79. virtual void FtpCommand(LPCTSTR pCommand)=0;
  80. virtual void Disconnect()=0;
  81. virtual void FileTransfer(t_transferfile *transferfile = 0, BOOL bFinish = FALSE, int nError = 0)=0;
  82. virtual void Delete(CString filename, const CServerPath &path)=0;
  83. virtual void Rename(CString oldName, CString newName, const CServerPath &path, const CServerPath &newPath)=0;
  84. virtual void MakeDir(const CServerPath &path)=0;
  85. virtual void RemoveDir(CString dirname, const CServerPath &path)=0;
  86. virtual void Cancel(BOOL bQuit=FALSE)=0;
  87. virtual void Chmod(CString filename, const CServerPath &path, int nValue)=0;
  88. virtual void SetAsyncRequestResult(int nAction, CAsyncRequestData *pData)=0;
  89. virtual void OnTimer()=0; //Called every 1000 msecs
  90. virtual BOOL IsReady()=0; //ALWAYS return return TRUE if processing a command (Return false if keepalive is in progress for example)
  91. virtual void ProcessReply()=0;
  92. virtual void TransferEnd(int nMode)=0;
  93. virtual void DoClose(int nErrorCode = 0)=0;
  94. t_server GetCurrentServer();
  95. void ShowStatus(UINT nID, int type) const;
  96. void ShowStatus(CString status,int type) const;
  97. #ifdef MPEXT
  98. virtual bool UsingMlsd() = 0;
  99. virtual std::string GetTlsVersionStr() = 0;
  100. virtual std::string GetCipherName() = 0;
  101. #endif
  102. virtual int OnLayerCallback(std::list<t_callbackMsg>& callbacks);
  103. protected:
  104. void Close();
  105. BOOL Connect(CString hostAddress, UINT nHostPort);
  106. CString ConvertDomainName(CString domain);
  107. void SetDirectoryListing(t_directory *pDirectory, bool bSetWorkingDir = true);
  108. t_directory *m_pDirectoryListing;
  109. CMainThread *m_pOwner;
  110. CFileZillaTools * m_pTools;
  111. #ifndef MPEXT_NO_IDENT
  112. CIdentServerControl *m_pIdentControl;
  113. #endif
  114. //Speed limit
  115. public:
  116. BOOL RemoveActiveTransfer();
  117. BOOL SpeedLimitAddTransferredBytes(enum transferDirection direction, _int64 nBytesTransferred);
  118. _int64 GetSpeedLimit(enum transferDirection direction, CTime &time);
  119. _int64 GetAbleToTransferSize(enum transferDirection direction, bool &beenWaiting, int nBufSize = 0);
  120. protected:
  121. struct t_ActiveList
  122. {
  123. CControlSocket *pOwner;
  124. __int64 nBytesAvailable;
  125. __int64 nBytesTransferred;
  126. };
  127. static std::list<t_ActiveList> m_InstanceList[2];
  128. static CTime m_CurrentTransferTime[2];
  129. static _int64 m_CurrentTransferLimit[2];
  130. static CCriticalSection m_SpeedLimitSync;
  131. _int64 GetAbleToUDSize( bool &beenWaiting, CTime &curTime, _int64 &curLimit, std::list<t_ActiveList>::iterator &iter, enum transferDirection direction, int nBufSize);
  132. #ifndef MPEXT_NO_SPEED_LIM_RULES
  133. _int64 GetSpeedLimit(CTime &time, int valType, int valValue, SPEEDLIMITSLIST &list);
  134. #else
  135. _int64 GetSpeedLimit(CTime &time, int valType, int valValue);
  136. #endif
  137. //End Speed limit
  138. virtual void LogSocketMessage(int nMessageType, LPCTSTR pMsgFormat);
  139. public:
  140. struct t_operation
  141. {
  142. int nOpMode;
  143. int nOpState;
  144. class COpData //Base class which will store operation specific parameters.
  145. {
  146. public:
  147. COpData() {};
  148. virtual ~COpData() {};
  149. };
  150. COpData *pData;
  151. public:
  152. };
  153. protected:
  154. t_operation m_Operation;
  155. CAsyncProxySocketLayer* m_pProxyLayer;
  156. #ifndef MPEXT_NO_SSL
  157. CAsyncSslSocketLayer* m_pSslLayer;
  158. #endif
  159. #ifndef MPEXT_NO_GSS
  160. CAsyncGssSocketLayer* m_pGssLayer;
  161. #endif
  162. t_server m_CurrentServer;
  163. };
  164. #endif // !defined(AFX_CONTROLSOCKET_H__173B4310_5E72_4F4B_A4F0_4E3D4CFAF4A5__INCLUDED_)