2 * DEBUG: section 33 Client-side Routines
5 #ifndef SQUID_SERVERS_FTP_SERVER_H
6 #define SQUID_SERVERS_FTP_SERVER_H
8 #include "client_side.h"
19 fssHandleUploadRequest
,
28 // TODO: This should become a part of MasterXaction when we start sending
29 // master transactions to the clients/ code.
30 /// Transaction information shared among our FTP client and server jobs.
34 Ip::Address clientDataAddr
; ///< address of our FTP client data connection
36 ServerState serverState
; ///< what our FTP server is doing
37 bool clientReadGreeting
; ///< whether our FTP client read their FTP server greeting
39 MasterState(): serverState(fssBegin
), clientReadGreeting(false) {}
42 /// Manages a control connection from an FTP client.
43 class Server
: public ConnStateData
46 explicit Server(const MasterXaction::Pointer
&xact
);
49 MasterState master
; ///< info shared among our FTP client and server jobs
52 friend void StartListening();
54 /* ConnStateData API */
55 virtual ClientSocketContext
*parseOneRequest(Http::ProtocolVersion
&ver
);
56 virtual void processParsedRequest(ClientSocketContext
*context
, const Http::ProtocolVersion
&ver
);
57 virtual void notePeerConnection(Comm::ConnectionPointer conn
);
58 virtual void clientPinnedConnectionClosed(const CommCloseCbParams
&io
);
59 virtual void handleReply(HttpReply
*header
, StoreIOBuffer receivedData
);
60 virtual int pipelinePrefetchMax() const;
61 virtual void writeControlMsgAndCall(ClientSocketContext
*context
, HttpReply
*rep
, AsyncCall::Pointer
&call
);
62 virtual time_t idleTimeout() const;
65 virtual void noteMoreBodySpaceAvailable(BodyPipe::Pointer
);
66 virtual void noteBodyConsumerAborted(BodyPipe::Pointer ptr
);
72 static void AcceptCtrlConnection(const CommAcceptCbParams
¶ms
);
73 void acceptDataConnection(const CommAcceptCbParams
¶ms
);
74 void readUploadData(const CommIoCbParams
&io
);
75 void wroteEarlyReply(const CommIoCbParams
&io
);
76 void wroteReply(const CommIoCbParams
&io
);
77 void wroteReplyData(const CommIoCbParams
&io
);
78 void connectedForData(const CommConnectCbParams
¶ms
);
80 unsigned int listenForDataConnection();
81 bool createDataConnection(Ip::Address cltAddr
);
82 void closeDataConnection();
84 void calcUri(const char *file
= NULL
);
85 void changeState(const Ftp::ServerState newState
, const char *reason
);
86 bool handleUserRequest(const String
&cmd
, String
¶ms
);
87 bool checkDataConnPost() const;
88 void replyDataWritingCheckpoint();
89 void maybeReadUploadData();
91 void setReply(const int code
, const char *msg
);
92 void writeCustomReply(const int code
, const char *msg
, const HttpReply
*reply
= NULL
);
93 void writeEarlyReply(const int code
, const char *msg
);
94 void writeErrorReply(const HttpReply
*reply
, const int status
);
95 void writeForwardedForeign(const HttpReply
*reply
);
96 void writeForwardedReply(const HttpReply
*reply
);
97 void writeForwardedReplyAndCall(const HttpReply
*reply
, AsyncCall::Pointer
&call
);
98 void writeReply(MemBuf
&mb
);
100 bool handleRequest(String
&cmd
, String
¶ms
);
101 void setDataCommand();
102 bool checkDataConnPre();
104 /// a method handling an FTP command; selected by handleRequest()
105 typedef bool (Ftp::Server::*RequestHandler
)(String
&cmd
, String
¶ms
);
106 bool handleFeatRequest(String
&cmd
, String
¶ms
);
107 bool handlePasvRequest(String
&cmd
, String
¶ms
);
108 bool handlePortRequest(String
&cmd
, String
¶ms
);
109 bool handleDataRequest(String
&cmd
, String
¶ms
);
110 bool handleUploadRequest(String
&cmd
, String
¶ms
);
111 bool handleEprtRequest(String
&cmd
, String
¶ms
);
112 bool handleEpsvRequest(String
&cmd
, String
¶ms
);
113 bool handleCwdRequest(String
&cmd
, String
¶ms
);
114 bool handlePassRequest(String
&cmd
, String
¶ms
);
115 bool handleCdupRequest(String
&cmd
, String
¶ms
);
117 /// a method handling an FTP response; selected by handleReply()
118 typedef void (Ftp::Server::*ReplyHandler
)(const HttpReply
*reply
, StoreIOBuffer data
);
119 void handleFeatReply(const HttpReply
*header
, StoreIOBuffer receivedData
);
120 void handlePasvReply(const HttpReply
*header
, StoreIOBuffer receivedData
);
121 void handlePortReply(const HttpReply
*header
, StoreIOBuffer receivedData
);
122 void handleErrorReply(const HttpReply
*header
, StoreIOBuffer receivedData
);
123 void handleDataReply(const HttpReply
*header
, StoreIOBuffer receivedData
);
124 void handleUploadReply(const HttpReply
*header
, StoreIOBuffer receivedData
);
125 void handleEprtReply(const HttpReply
*header
, StoreIOBuffer receivedData
);
126 void handleEpsvReply(const HttpReply
*header
, StoreIOBuffer receivedData
);
129 void doProcessRequest();
130 void shovelUploadData();
132 String uri
; ///< a URI reconstructed from various FTP message details
133 String host
; ///< intended dest. of a transparently intercepted FTP conn
134 bool gotEpsvAll
; ///< restrict data conn setup commands to just EPSV
135 AsyncCall::Pointer onDataAcceptCall
; ///< who to call upon data conn acceptance
136 Comm::ConnectionPointer dataListenConn
; ///< data connection listening socket
137 Comm::ConnectionPointer dataConn
; ///< data connection
138 char uploadBuf
[CLIENT_REQ_BUF_SZ
]; ///< data connection input buffer
139 size_t uploadAvailSize
; ///< number of yet unused uploadBuf bytes
141 AsyncCall::Pointer listener
; ///< set when we are passively listening
142 AsyncCall::Pointer connector
; ///< set when we are actively connecting
143 AsyncCall::Pointer reader
; ///< set when we are reading FTP data
145 CBDATA_CLASS2(Server
);
150 #endif /* SQUID_SERVERS_FTP_SERVER_H */