FtpClient.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2019 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 
16 class String;
17 namespace Ftp
18 {
19 
20 extern const char *const crlf;
21 
24 class Channel
25 {
26 public:
28  void opened(const Comm::ConnectionPointer &conn, const AsyncCall::Pointer &aCloser);
29 
33  void close();
34 
35  void forget();
36 
37  void clear();
38 
40 
47 
49 private:
51 };
52 
56 {
57 public:
58  CtrlChannel();
59  ~CtrlChannel();
60 
61  char *buf;
62  size_t size;
63  size_t offset;
65  char *last_command;
66  char *last_reply;
67  int replycode;
68 
69 private:
70  CtrlChannel(const CtrlChannel &); // not implemented
71  CtrlChannel &operator =(const CtrlChannel &); // not implemented
72 };
73 
77 {
78 public:
79  DataChannel();
80  ~DataChannel();
81 
82  void addr(const Ip::Address &addr);
83 
84 public:
86  char *host;
87  unsigned short port;
89 };
90 
92 class Client: public ::Client
93 {
95 
96 public:
97  explicit Client(FwdState *fwdState);
98  virtual ~Client();
99 
101  virtual void failed(err_type error = ERR_NONE, int xerrno = 0,
102  ErrorState *ftperr = nullptr);
103 
105  virtual void timeout(const CommTimeoutCbParams &io);
106 
107  /* Client API */
108  virtual void maybeReadVirginBody();
109 
110  void writeCommand(const char *buf);
111 
114  bool handlePasvReply(Ip::Address &remoteAddr);
115  bool handleEpsvReply(Ip::Address &remoteAddr);
116 
117  bool sendEprt();
118  bool sendPort();
119  bool sendPassive();
120  void connectDataChannel();
121  bool openListenSocket();
122  void switchTimeoutToDataChannel();
123 
126 
127  enum {
153  SENT_DATA_REQUEST, // LIST, NLST or RETR requests..
154  SENT_COMMAND, // General command
155  END
156  } ftp_state_t;
157 
158  int state;
159  char *old_request;
160  char *old_reply;
161 
162 protected:
163  /* AsyncJob API */
164  virtual void start();
165 
166  /* Client API */
167  virtual void closeServer();
168  virtual bool doneWithServer() const;
169  virtual const Comm::ConnectionPointer & dataConnection() const;
170  virtual void abortAll(const char *reason);
171 
172  virtual Http::StatusCode failedHttpStatus(err_type &error);
173  void ctrlClosed(const CommCloseCbParams &io);
174  void scheduleReadControlReply(int buffered_ok);
175  void readControlReply(const CommIoCbParams &io);
176  virtual void handleControlReply();
177  void writeCommandCallback(const CommIoCbParams &io);
178  virtual void dataChannelConnected(const CommConnectCbParams &io) = 0;
179  void dataRead(const CommIoCbParams &io);
180  void dataComplete();
181  AsyncCall::Pointer dataCloser();
182  virtual void dataClosed(const CommCloseCbParams &io);
183  void initReadBuf();
184 
185  // sending of the request body to the server
186  virtual void sentRequestBody(const CommIoCbParams &io);
187  virtual void doneSendingRequestBody();
188 
189 private:
190  bool parseControlReply(size_t &bytesUsed);
191 
195 };
196 
197 } // namespace Ftp
198 
199 #endif /* SQUID_FTP_CLIENT_H */
200 
AsyncCall::Pointer closer
Comm close handler callback.
Definition: FtpClient.h:50
const char *const crlf
Definition: FtpClient.cc:35
void error(char *format,...)
FTP client functionality shared among FTP Gateway and Relay clients.
Definition: FtpClient.h:92
void clear()
remove the close handler, leave connection open
Definition: FtpClient.cc:108
CtrlChannel ctrl
FTP control channel state.
Definition: FtpClient.h:124
MemBuf * readBuf
Definition: FtpClient.h:85
void forget()
Definition: FtpClient.cc:98
bool shortenReadTimeout
Definition: FtpClient.h:194
DataChannel data
FTP data channel state.
Definition: FtpClient.h:125
char * last_command
Definition: FtpClient.h:65
StatusCode
Definition: StatusCode.h:20
AsyncCall::Pointer opener
Comm opener handler callback.
Definition: FtpClient.h:48
wordlist * message
Definition: FtpClient.h:64
#define CBDATA_CLASS(type)
Definition: cbdata.h:302
void * addr
Definition: membanger.c:46
Comm::ConnectionPointer listenConn
Definition: FtpClient.h:46
void const char * buf
Definition: stub_helper.cc:16
void close()
planned close: removes the close handler and calls comm_close
Definition: FtpClient.cc:87
char * last_reply
Definition: FtpClient.h:66
void opened(const Comm::ConnectionPointer &conn, const AsyncCall::Pointer &aCloser)
called after the socket is opened, sets up close handler
Definition: FtpClient.cc:71
Definition: MemBuf.h:23
Definition: forward.h:27
char * old_reply
Definition: FtpClient.h:160
Comm::ConnectionPointer conn
channel descriptor
Definition: FtpClient.h:39
err_type
Definition: err_type.h:12
unsigned short port
Definition: FtpClient.h:87
char * old_request
Definition: FtpClient.h:159

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors