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{
112public:
113 explicit Client(FwdState *fwdState);
114 ~Client() override;
115
117 virtual void failed(err_type error = ERR_NONE, int xerrno = 0,
118 ErrorState *ftperr = nullptr);
119
121 virtual void timeout(const CommTimeoutCbParams &io);
122
123 /* Client API */
124 void maybeReadVirginBody() override;
125
126 void writeCommand(const char *buf);
127
130 bool handlePasvReply(Ip::Address &remoteAddr);
131 bool handleEpsvReply(Ip::Address &remoteAddr);
132
133 bool sendEprt();
134 bool sendPort();
135 bool sendPassive();
136 void connectDataChannel();
137 bool openListenSocket();
139
142
143 enum {
169 SENT_DATA_REQUEST, // LIST, NLST or RETR requests..
170 SENT_COMMAND, // General command
171 END
173
174 int state;
177
178protected:
179 /* AsyncJob API */
180 void start() override;
181
182 /* Client API */
183 void closeServer() override;
184 bool doneWithServer() const override;
185 const Comm::ConnectionPointer & dataConnection() const override;
186 void abortAll(const char *reason) override;
187 void noteDelayAwareReadChance() override;
188
190 void ctrlClosed(const CommCloseCbParams &io);
191 void scheduleReadControlReply(int buffered_ok);
192 void readControlReply(const CommIoCbParams &io);
193 virtual void handleControlReply();
194 void writeCommandCallback(const CommIoCbParams &io);
195 virtual void dataChannelConnected(const CommConnectCbParams &io) = 0;
196 void dataRead(const CommIoCbParams &io);
197 void dataComplete();
199 virtual void dataClosed(const CommCloseCbParams &io);
200 void initReadBuf();
201
202 // sending of the request body to the server
203 void sentRequestBody(const CommIoCbParams &io) override;
204 void doneSendingRequestBody() override;
205
209
210private:
211 bool parseControlReply(size_t &bytesUsed);
212
216};
217
218} // namespace Ftp
219
220#endif /* SQUID_FTP_CLIENT_H */
221
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
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:141
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:208
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
enum Ftp::Client::@39 ftp_state_t
CtrlChannel ctrl
FTP control channel state.
Definition: FtpClient.h:140
bool sendPassive()
Definition: FtpClient.cc:653
bool parseControlReply(size_t &bytesUsed)
Definition: FtpClient.cc:1101
AsyncCall::Pointer dataCloser()
creates a data channel Comm close callback
Definition: FtpClient.cc:802
char * old_reply
Definition: FtpClient.h:176
bool shortenReadTimeout
Definition: FtpClient.h:215
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:175
void abortAll(const char *reason) override
abnormal transaction termination; reason is for debugging only
Definition: FtpClient.cc:1053
@ SENT_DATA_REQUEST
Definition: FtpClient.h:169
~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
unsigned char code
Definition: html_quote.c:20
Definition: forward.h:28
const char *const crlf
Definition: FtpClient.cc:40
StatusCode
Definition: StatusCode.h:20

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors