FtpClient.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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();
123 
126 
127  enum {
153  SENT_DATA_REQUEST, // LIST, NLST or RETR requests..
154  SENT_COMMAND, // General command
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 
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();
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 
virtual void closeServer()
Definition: FtpClient.cc:217
void scheduleReadControlReply(int buffered_ok)
Definition: FtpClient.cc:309
virtual void doneSendingRequestBody()
Definition: FtpClient.cc:1052
AsyncCall::Pointer closer
Comm close handler callback.
Definition: FtpClient.h:50
bool handleEpsvReply(Ip::Address &remoteAddr)
Definition: FtpClient.cc:475
virtual void dataClosed(const CommCloseCbParams &io)
handler called by Comm when FTP data channel is closed unexpectedly
Definition: FtpClient.cc:792
AsyncCall::Pointer dataCloser()
creates a data channel Comm close callback
Definition: FtpClient.cc:784
void writeCommand(const char *buf)
Definition: FtpClient.cc:804
CtrlChannel & operator=(const CtrlChannel &)
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
virtual void maybeReadVirginBody()
read response data from the network
Definition: FtpClient.cc:887
virtual void timeout(const CommTimeoutCbParams &io)
read timeout handler
Definition: FtpClient.cc:869
CtrlChannel ctrl
FTP control channel state.
Definition: FtpClient.h:124
CBDATA_CLASS(Client)
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
void writeCommandCallback(const CommIoCbParams &io)
Definition: FtpClient.cc:836
wordlist * message
Definition: FtpClient.h:64
virtual void start()
called by AsyncStart; do not call directly
Definition: FtpClient.cc:199
bool sendPassive()
Definition: FtpClient.cc:637
virtual ~Client()
Definition: FtpClient.cc:185
Comm::ConnectionPointer listenConn
Definition: FtpClient.h:46
virtual void handleControlReply()
Definition: FtpClient.cc:403
void readControlReply(const CommIoCbParams &io)
Definition: FtpClient.cc:346
void const char * buf
Definition: stub_helper.cc:16
virtual void dataChannelConnected(const CommConnectCbParams &io)=0
enum Ftp::Client::@41 ftp_state_t
void switchTimeoutToDataChannel()
Definition: FtpClient.cc:1030
void close()
planned close: removes the close handler and calls comm_close
Definition: FtpClient.cc:87
void addr(const Ip::Address &addr)
import host and port
Definition: FtpClient.cc:153
bool sendPort()
Definition: FtpClient.cc:630
bool sendEprt()
Definition: FtpClient.cc:591
char * last_reply
Definition: FtpClient.h:66
bool parseControlReply(size_t &bytesUsed)
Definition: FtpClient.cc:1066
void connectDataChannel()
Definition: FtpClient.cc:746
void opened(const Comm::ConnectionPointer &conn, const AsyncCall::Pointer &aCloser)
called after the socket is opened, sets up close handler
Definition: FtpClient.cc:71
virtual bool doneWithServer() const
Definition: FtpClient.cc:240
Client(FwdState *fwdState)
Definition: FtpClient.cc:164
Definition: MemBuf.h:23
bool openListenSocket()
Definition: FtpClient.cc:777
virtual Http::StatusCode failedHttpStatus(err_type &error)
Definition: FtpClient.cc:295
virtual void sentRequestBody(const CommIoCbParams &io)
Definition: FtpClient.cc:1041
void dataRead(const CommIoCbParams &io)
Definition: FtpClient.cc:920
void ctrlClosed(const CommCloseCbParams &io)
handler called by Comm when FTP control channel is closed unexpectedly
Definition: FtpClient.cc:860
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:246
char * old_reply
Definition: FtpClient.h:160
Comm::ConnectionPointer conn
channel descriptor
Definition: FtpClient.h:39
virtual const Comm::ConnectionPointer & dataConnection() const
Definition: FtpClient.cc:881
void dataComplete()
Definition: FtpClient.cc:989
err_type
Definition: err_type.h:12
virtual void abortAll(const char *reason)
abnormal transaction termination; reason is for debugging only
Definition: FtpClient.cc:1018
void initReadBuf()
Definition: FtpClient.cc:205
unsigned short port
Definition: FtpClient.h:87
bool handlePasvReply(Ip::Address &remoteAddr)
Definition: FtpClient.cc:439
char * old_request
Definition: FtpClient.h:159

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors