FtpClient.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2022 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 
17 class String;
18 namespace Ftp
19 {
20 
21 extern const char *const crlf;
22 
27 class ErrorDetail: public ::ErrorDetail {
29 
30 public:
31  explicit ErrorDetail(const int code): completionCode(code) {}
32 
33  /* ErrorDetail API */
34  virtual SBuf brief() const override;
35  virtual SBuf verbose(const HttpRequestPointer &) const override;
36 
37 private:
39 };
40 
43 class Channel
44 {
45 public:
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 
67 private:
69 };
70 
74 {
75 public:
76  CtrlChannel();
77  ~CtrlChannel();
78 
79  char *buf;
80  size_t size;
81  size_t offset;
83  char *last_command;
84  char *last_reply;
85  int replycode;
86 
87 private:
88  CtrlChannel(const CtrlChannel &); // not implemented
89  CtrlChannel &operator =(const CtrlChannel &); // not implemented
90 };
91 
95 {
96 public:
97  DataChannel();
98  ~DataChannel();
99 
100  void addr(const Ip::Address &addr);
101 
102 public:
104  char *host;
105  unsigned short port;
107 };
108 
110 class Client: public ::Client
111 {
113 
114 public:
115  explicit Client(FwdState *fwdState);
116  virtual ~Client();
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  virtual void maybeReadVirginBody();
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;
177  char *old_request;
178  char *old_reply;
179 
180 protected:
181  /* AsyncJob API */
182  virtual void start();
183 
184  /* Client API */
185  virtual void closeServer();
186  virtual bool doneWithServer() const;
187  virtual const Comm::ConnectionPointer & dataConnection() const;
188  virtual void abortAll(const char *reason);
189  virtual void noteDelayAwareReadChance();
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  virtual void sentRequestBody(const CommIoCbParams &io);
206  virtual void doneSendingRequestBody();
207 
211 
212 private:
213  bool parseControlReply(size_t &bytesUsed);
214 
218 };
219 
220 } // namespace Ftp
221 
222 #endif /* SQUID_FTP_CLIENT_H */
223 
void error(char *format,...)
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
@ SENT_DATA_REQUEST
Definition: FtpClient.h:171
bool handleEpsvReply(Ip::Address &remoteAddr)
Definition: FtpClient.cc:491
virtual void closeServer()
Definition: FtpClient.cc:233
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
virtual const Comm::ConnectionPointer & dataConnection() const
Definition: FtpClient.cc:902
virtual void abortAll(const char *reason)
abnormal transaction termination; reason is for debugging only
Definition: FtpClient.cc:1053
void dataComplete()
Definition: FtpClient.cc:1024
void scheduleReadControlReply(int buffered_ok)
Definition: FtpClient.cc:325
virtual void doneSendingRequestBody()
Definition: FtpClient.cc:1087
bool openListenSocket()
Definition: FtpClient.cc:795
void writeCommand(const char *buf)
Definition: FtpClient.cc:823
virtual void maybeReadVirginBody()
read response data from the network
Definition: FtpClient.cc:915
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
virtual void start()
called by AsyncStart; do not call directly
Definition: FtpClient.cc:215
void connectDataChannel()
Definition: FtpClient.cc:762
virtual ~Client()
Definition: FtpClient.cc:205
void writeCommandCallback(const CommIoCbParams &io)
Definition: FtpClient.cc:855
virtual bool doneWithServer() const
Definition: FtpClient.cc:256
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
JobWait< Comm::ConnOpener > dataConnWait
Definition: FtpClient.h:210
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
CBDATA_CLASS(Client)
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: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 noteDelayAwareReadChance()
Definition: FtpClient.cc:908
virtual void dataChannelConnected(const CommConnectCbParams &io)=0
char * old_request
Definition: FtpClient.h:177
enum Ftp::Client::@40 ftp_state_t
virtual void sentRequestBody(const CommIoCbParams &io)
Definition: FtpClient.cc:1076
virtual void dataClosed(const CommCloseCbParams &io)
handler called by Comm when FTP data channel is closed unexpectedly
Definition: FtpClient.cc:810
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)
virtual SBuf verbose(const HttpRequestPointer &) const override
Definition: FtpClient.cc:81
int completionCode
FTP reply completion code.
Definition: FtpClient.h:38
virtual 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