FtpClient.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9/* DEBUG: section 09 File Transfer Protocol (FTP) */
10
11#ifndef SQUID_FTP_CLIENT_H
12#define SQUID_FTP_CLIENT_H
13
14#include "clients/Client.h"
15#include "error/Detail.h"
16
17class String;
18namespace Ftp
19{
20
21extern const char *const crlf;
22
29
30public:
31 explicit ErrorDetail(const int code): completionCode(code) {}
32
33 /* ErrorDetail API */
34 SBuf brief() const override;
35 SBuf verbose(const HttpRequestPointer &) const override;
36
37private:
39};
40
44{
45public:
47 void opened(const Comm::ConnectionPointer &conn, const AsyncCall::Pointer &aCloser);
48
52 void close();
53
54 void forget();
55
56 void clear();
57
59
66
67private:
69};
70
74{
75public:
78
79 char *buf;
80 size_t size;
81 size_t offset;
86
87private:
88 CtrlChannel(const CtrlChannel &); // not implemented
89 CtrlChannel &operator =(const CtrlChannel &); // not implemented
90};
91
95{
96public:
99
100 void addr(const Ip::Address &addr);
101
102public:
104 char *host;
105 unsigned short port;
107};
108
110class Client: public ::Client
111{
113
114public:
115 explicit Client(FwdState *fwdState);
116 ~Client() override;
117
119 virtual void failed(err_type error = ERR_NONE, int xerrno = 0,
120 ErrorState *ftperr = nullptr);
121
123 virtual void timeout(const CommTimeoutCbParams &io);
124
125 /* Client API */
126 void maybeReadVirginBody() override;
127
128 void writeCommand(const char *buf);
129
132 bool handlePasvReply(Ip::Address &remoteAddr);
133 bool handleEpsvReply(Ip::Address &remoteAddr);
134
135 bool sendEprt();
136 bool sendPort();
137 bool sendPassive();
138 void connectDataChannel();
139 bool openListenSocket();
141
144
145 enum {
171 SENT_DATA_REQUEST, // LIST, NLST or RETR requests..
172 SENT_COMMAND, // General command
173 END
175
176 int state;
179
180protected:
181 /* AsyncJob API */
182 void start() override;
183
184 /* Client API */
185 void closeServer() override;
186 bool doneWithServer() const override;
187 const Comm::ConnectionPointer & dataConnection() const override;
188 void abortAll(const char *reason) override;
189 void noteDelayAwareReadChance() override;
190
192 void ctrlClosed(const CommCloseCbParams &io);
193 void scheduleReadControlReply(int buffered_ok);
194 void readControlReply(const CommIoCbParams &io);
195 virtual void handleControlReply();
196 void writeCommandCallback(const CommIoCbParams &io);
197 virtual void dataChannelConnected(const CommConnectCbParams &io) = 0;
198 void dataRead(const CommIoCbParams &io);
199 void dataComplete();
201 virtual void dataClosed(const CommCloseCbParams &io);
202 void initReadBuf();
203
204 // sending of the request body to the server
205 void sentRequestBody(const CommIoCbParams &io) override;
206 void doneSendingRequestBody() override;
207
211
212private:
213 bool parseControlReply(size_t &bytesUsed);
214
218};
219
220} // namespace Ftp
221
222#endif /* SQUID_FTP_CLIENT_H */
223
void error(char *format,...)
Definition: Client.h:35
interface for supplying additional information about a transaction failure
Definition: Detail.h:21
void forget()
Definition: FtpClient.cc:118
Comm::ConnectionPointer listenConn
Definition: FtpClient.h:65
void close()
planned close: removes the close handler and calls comm_close
Definition: FtpClient.cc:107
void opened(const Comm::ConnectionPointer &conn, const AsyncCall::Pointer &aCloser)
called after the socket is opened, sets up close handler
Definition: FtpClient.cc:90
void clear()
remove the close handler, leave connection open
Definition: FtpClient.cc:128
AsyncCall::Pointer closer
Comm close handler callback.
Definition: FtpClient.h:68
Comm::ConnectionPointer conn
channel descriptor
Definition: FtpClient.h:58
FTP client functionality shared among FTP Gateway and Relay clients.
Definition: FtpClient.h:111
virtual Http::StatusCode failedHttpStatus(err_type &error)
Definition: FtpClient.cc:311
void start() override
called by AsyncStart; do not call directly
Definition: FtpClient.cc:215
bool handleEpsvReply(Ip::Address &remoteAddr)
Definition: FtpClient.cc:491
virtual void handleControlReply()
Definition: FtpClient.cc:419
void dataRead(const CommIoCbParams &io)
Definition: FtpClient.cc:955
void initReadBuf()
Definition: FtpClient.cc:221
bool sendPort()
Definition: FtpClient.cc:646
void dataComplete()
Definition: FtpClient.cc:1024
void closeServer() override
Definition: FtpClient.cc:233
void scheduleReadControlReply(int buffered_ok)
Definition: FtpClient.cc:325
bool openListenSocket()
Definition: FtpClient.cc:795
void sentRequestBody(const CommIoCbParams &io) override
Definition: FtpClient.cc:1076
void writeCommand(const char *buf)
Definition: FtpClient.cc:823
virtual void timeout(const CommTimeoutCbParams &io)
read timeout handler
Definition: FtpClient.cc:890
bool handlePasvReply(Ip::Address &remoteAddr)
Definition: FtpClient.cc:455
void switchTimeoutToDataChannel()
Definition: FtpClient.cc:1065
enum Ftp::Client::@38 ftp_state_t
void connectDataChannel()
Definition: FtpClient.cc:762
bool doneWithServer() const override
Definition: FtpClient.cc:256
void writeCommandCallback(const CommIoCbParams &io)
Definition: FtpClient.cc:855
Client(FwdState *fwdState)
Definition: FtpClient.cc:184
bool sendEprt()
Definition: FtpClient.cc:607
void readControlReply(const CommIoCbParams &io)
Definition: FtpClient.cc:362
DataChannel data
FTP data channel state.
Definition: FtpClient.h:143
void doneSendingRequestBody() override
Definition: FtpClient.cc:1087
void maybeReadVirginBody() override
read response data from the network
Definition: FtpClient.cc:915
JobWait< Comm::ConnOpener > dataConnWait
Definition: FtpClient.h:210
const Comm::ConnectionPointer & dataConnection() const override
Definition: FtpClient.cc:902
virtual void failed(err_type error=ERR_NONE, int xerrno=0, ErrorState *ftperr=nullptr)
handle a fatal transaction error, closing the control connection
Definition: FtpClient.cc:262
CtrlChannel ctrl
FTP control channel state.
Definition: FtpClient.h:142
bool sendPassive()
Definition: FtpClient.cc:653
bool parseControlReply(size_t &bytesUsed)
Definition: FtpClient.cc:1101
@ SENT_DATA_REQUEST
Definition: FtpClient.h:171
AsyncCall::Pointer dataCloser()
creates a data channel Comm close callback
Definition: FtpClient.cc:802
char * old_reply
Definition: FtpClient.h:178
bool shortenReadTimeout
Definition: FtpClient.h:217
void ctrlClosed(const CommCloseCbParams &io)
handler called by Comm when FTP control channel is closed unexpectedly
Definition: FtpClient.cc:879
virtual void dataChannelConnected(const CommConnectCbParams &io)=0
char * old_request
Definition: FtpClient.h:177
void abortAll(const char *reason) override
abnormal transaction termination; reason is for debugging only
Definition: FtpClient.cc:1053
~Client() override
Definition: FtpClient.cc:205
virtual void dataClosed(const CommCloseCbParams &io)
handler called by Comm when FTP data channel is closed unexpectedly
Definition: FtpClient.cc:810
void noteDelayAwareReadChance() override
Definition: FtpClient.cc:908
char * last_reply
Definition: FtpClient.h:84
CtrlChannel(const CtrlChannel &)
char * last_command
Definition: FtpClient.h:83
CtrlChannel & operator=(const CtrlChannel &)
wordlist * message
Definition: FtpClient.h:82
unsigned short port
Definition: FtpClient.h:105
MemBuf * readBuf
Definition: FtpClient.h:103
void addr(const Ip::Address &addr)
import host and port
Definition: FtpClient.cc:173
MEMPROXY_CLASS(Ftp::ErrorDetail)
SBuf verbose(const HttpRequestPointer &) const override
Definition: FtpClient.cc:81
int completionCode
FTP reply completion code.
Definition: FtpClient.h:38
SBuf brief() const override
Definition: FtpClient.cc:75
ErrorDetail(const int code)
Definition: FtpClient.h:31
Definition: MemBuf.h:24
Definition: SBuf.h:94
err_type
Definition: forward.h:14
@ ERR_NONE
Definition: forward.h:15
Definition: forward.h:24
const char *const crlf
Definition: FtpClient.cc:40
StatusCode
Definition: StatusCode.h:20
int code
Definition: smb-errors.c:145

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors