1 | #ifndef __FTPCONTROLSOCKET_H__ |
---|
2 | #define __FTPCONTROLSOCKET_H__ |
---|
3 | |
---|
4 | #include "logging_private.h" |
---|
5 | #include "ControlSocket.h" |
---|
6 | #include "externalipresolver.h" |
---|
7 | #include "rtt.h" |
---|
8 | |
---|
9 | #include <wx/regex.h> |
---|
10 | |
---|
11 | #define RECVBUFFERSIZE 4096 |
---|
12 | #define MAXLINELEN 2000 |
---|
13 | |
---|
14 | class CTransferSocket; |
---|
15 | class CFtpTransferOpData; |
---|
16 | class CRawTransferOpData; |
---|
17 | class CTlsSocket; |
---|
18 | |
---|
19 | class CFtpControlSocket final : public CRealControlSocket |
---|
20 | { |
---|
21 | friend class CTransferSocket; |
---|
22 | public: |
---|
23 | CFtpControlSocket(CFileZillaEnginePrivate & engine); |
---|
24 | virtual ~CFtpControlSocket(); |
---|
25 | virtual void TransferEnd(); |
---|
26 | |
---|
27 | virtual bool SetAsyncRequestReply(CAsyncRequestNotification *pNotification); |
---|
28 | |
---|
29 | protected: |
---|
30 | |
---|
31 | virtual int ResetOperation(int nErrorCode); |
---|
32 | |
---|
33 | virtual int Connect(const CServer &server); |
---|
34 | virtual int List(CServerPath path = CServerPath(), wxString subDir = _T(""), int flags = 0); |
---|
35 | int ListParseResponse(); |
---|
36 | int ListSubcommandResult(int prevResult); |
---|
37 | int ListSend(); |
---|
38 | int ListCheckTimezoneDetection(CDirectoryListing& listing); |
---|
39 | |
---|
40 | int ChangeDir(CServerPath path = CServerPath(), wxString subDir = _T(""), bool link_discovery = false); |
---|
41 | int ChangeDirParseResponse(); |
---|
42 | int ChangeDirSubcommandResult(int prevResult); |
---|
43 | int ChangeDirSend(); |
---|
44 | |
---|
45 | virtual int FileTransfer(const wxString localFile, const CServerPath &remotePath, |
---|
46 | const wxString &remoteFile, bool download, |
---|
47 | const CFileTransferCommand::t_transferSettings& transferSettings); |
---|
48 | int FileTransferParseResponse(); |
---|
49 | int FileTransferSubcommandResult(int prevResult); |
---|
50 | int FileTransferSend(); |
---|
51 | int FileTransferTestResumeCapability(); |
---|
52 | |
---|
53 | virtual int RawCommand(const wxString& command); |
---|
54 | int RawCommandSend(); |
---|
55 | int RawCommandParseResponse(); |
---|
56 | |
---|
57 | virtual int Delete(const CServerPath& path, std::deque<wxString>&& files); |
---|
58 | int DeleteSubcommandResult(int prevResult); |
---|
59 | int DeleteSend(); |
---|
60 | int DeleteParseResponse(); |
---|
61 | |
---|
62 | virtual int RemoveDir(const CServerPath& path, const wxString& subDir); |
---|
63 | int RemoveDirSubcommandResult(int prevResult); |
---|
64 | int RemoveDirSend(); |
---|
65 | int RemoveDirParseResponse(); |
---|
66 | |
---|
67 | virtual int Mkdir(const CServerPath& path); |
---|
68 | virtual int MkdirParseResponse(); |
---|
69 | virtual int MkdirSend(); |
---|
70 | |
---|
71 | virtual int Rename(const CRenameCommand& command); |
---|
72 | virtual int RenameParseResponse(); |
---|
73 | virtual int RenameSubcommandResult(int prevResult); |
---|
74 | virtual int RenameSend(); |
---|
75 | |
---|
76 | virtual int Chmod(const CChmodCommand& command); |
---|
77 | virtual int ChmodParseResponse(); |
---|
78 | virtual int ChmodSubcommandResult(int prevResult); |
---|
79 | virtual int ChmodSend(); |
---|
80 | |
---|
81 | virtual int Transfer(const wxString& cmd, CFtpTransferOpData* oldData); |
---|
82 | virtual int TransferParseResponse(); |
---|
83 | virtual int TransferSend(); |
---|
84 | |
---|
85 | virtual void OnConnect(); |
---|
86 | virtual void OnReceive(); |
---|
87 | |
---|
88 | bool SendCommand(wxString const& str, bool maskArgs = false, bool measureRTT = true); |
---|
89 | |
---|
90 | // Parse the latest reply line from the server |
---|
91 | void ParseLine(wxString line); |
---|
92 | |
---|
93 | // Parse the actual response and delegate it to the handlers. |
---|
94 | // It's the last line in a multi-line response. |
---|
95 | void ParseResponse(); |
---|
96 | |
---|
97 | void ParseFeat(wxString line); |
---|
98 | |
---|
99 | virtual int SendNextCommand(); |
---|
100 | virtual int ParseSubcommandResult(int prevResult); |
---|
101 | |
---|
102 | int GetReplyCode() const; |
---|
103 | |
---|
104 | int Logon(); |
---|
105 | int LogonParseResponse(); |
---|
106 | int LogonSend(); |
---|
107 | |
---|
108 | wxString GetPassiveCommand(CRawTransferOpData& data); |
---|
109 | bool ParsePasvResponse(CRawTransferOpData* pData); |
---|
110 | bool ParseEpsvResponse(CRawTransferOpData* pData); |
---|
111 | |
---|
112 | // Some servers are broken. Instead of an empty listing, some MVS servers |
---|
113 | // for example they return "550 no members found" |
---|
114 | // Other servers return "550 No files found." |
---|
115 | bool IsMisleadingListResponse() const; |
---|
116 | |
---|
117 | int GetExternalIPAddress(wxString& address); |
---|
118 | |
---|
119 | // Checks if listing2 is a subset of listing1. Compares only filenames. |
---|
120 | bool CheckInclusion(const CDirectoryListing& listing1, const CDirectoryListing& listing2); |
---|
121 | |
---|
122 | void StartKeepaliveTimer(); |
---|
123 | |
---|
124 | bool GetLoginSequence(const CServer& server); |
---|
125 | |
---|
126 | wxString m_Response; |
---|
127 | wxString m_MultilineResponseCode; |
---|
128 | std::vector<wxString> m_MultilineResponseLines; |
---|
129 | |
---|
130 | CTransferSocket *m_pTransferSocket; |
---|
131 | |
---|
132 | // Some servers keep track of the offset specified by REST between sessions |
---|
133 | // So we always sent a REST 0 for a normal transfer following a restarted one |
---|
134 | bool m_sentRestartOffset; |
---|
135 | |
---|
136 | char m_receiveBuffer[RECVBUFFERSIZE]; |
---|
137 | int m_bufferLen; |
---|
138 | int m_repliesToSkip; // Set to the amount of pending replies if cancelling an action |
---|
139 | |
---|
140 | int m_pendingReplies; |
---|
141 | |
---|
142 | CExternalIPResolver* m_pIPResolver; |
---|
143 | |
---|
144 | CTlsSocket* m_pTlsSocket; |
---|
145 | bool m_protectDataChannel; |
---|
146 | |
---|
147 | int m_lastTypeBinary; |
---|
148 | |
---|
149 | // Used by keepalive code so that we're not using keep alive |
---|
150 | // till the end of time. Stop after a couple of minutes. |
---|
151 | CMonotonicClock m_lastCommandCompletionTime; |
---|
152 | |
---|
153 | timer_id m_idleTimer{}; |
---|
154 | |
---|
155 | CLatencyMeasurement m_rtt; |
---|
156 | |
---|
157 | virtual void operator()(CEventBase const& ev); |
---|
158 | |
---|
159 | void OnExternalIPAddress(); |
---|
160 | void OnTimer(timer_id id); |
---|
161 | |
---|
162 | wxRegEx m_pasvReplyRegex; // Have it as class member to avoid recompiling the regex on each transfer or listing |
---|
163 | }; |
---|
164 | |
---|
165 | class CIOThread; |
---|
166 | |
---|
167 | class CFtpTransferOpData |
---|
168 | { |
---|
169 | public: |
---|
170 | CFtpTransferOpData() = default; |
---|
171 | virtual ~CFtpTransferOpData() {} |
---|
172 | |
---|
173 | TransferEndReason transferEndReason{TransferEndReason::successful}; |
---|
174 | bool tranferCommandSent{}; |
---|
175 | |
---|
176 | int64_t resumeOffset{}; |
---|
177 | bool binary{true}; |
---|
178 | }; |
---|
179 | |
---|
180 | class CFtpFileTransferOpData final : public CFileTransferOpData, public CFtpTransferOpData |
---|
181 | { |
---|
182 | public: |
---|
183 | CFtpFileTransferOpData(bool is_download, const wxString& local_file, const wxString& remote_file, const CServerPath& remote_path); |
---|
184 | virtual ~CFtpFileTransferOpData(); |
---|
185 | |
---|
186 | CIOThread *pIOThread{}; |
---|
187 | bool fileDidExist{true}; |
---|
188 | }; |
---|
189 | |
---|
190 | class CRawTransferOpData final : public COpData |
---|
191 | { |
---|
192 | public: |
---|
193 | CRawTransferOpData(); |
---|
194 | wxString cmd; |
---|
195 | |
---|
196 | CFtpTransferOpData* pOldData; |
---|
197 | |
---|
198 | bool bPasv; |
---|
199 | bool bTriedPasv; |
---|
200 | bool bTriedActive; |
---|
201 | |
---|
202 | wxString host; |
---|
203 | int port; |
---|
204 | }; |
---|
205 | |
---|
206 | #endif |
---|