]>
Commit | Line | Data |
---|---|---|
92ae4c86 AR |
1 | /* |
2 | * DEBUG: section 33 Client-side Routines | |
3 | */ | |
4 | ||
5 | #ifndef SQUID_SERVERS_FTP_SERVER_H | |
6 | #define SQUID_SERVERS_FTP_SERVER_H | |
7 | ||
8 | #include "client_side.h" | |
9 | ||
10 | namespace Ftp { | |
11 | ||
12 | typedef enum { | |
13 | fssBegin, | |
14 | fssConnected, | |
15 | fssHandleFeat, | |
16 | fssHandlePasv, | |
17 | fssHandlePort, | |
18 | fssHandleDataRequest, | |
19 | fssHandleUploadRequest, | |
20 | fssHandleEprt, | |
21 | fssHandleEpsv, | |
22 | fssHandleCwd, | |
23 | fssHandlePass, | |
24 | fssHandleCdup, | |
25 | fssError | |
26 | } ServerState; | |
27 | ||
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. | |
31 | class MasterState | |
32 | { | |
33 | public: | |
34 | Ip::Address clientDataAddr; ///< address of our FTP client data connection | |
35 | String workingDir; | |
36 | ServerState serverState; ///< what our FTP server is doing | |
37 | bool clientReadGreeting; ///< whether our FTP client read their FTP server greeting | |
38 | ||
39 | MasterState(): serverState(fssBegin), clientReadGreeting(false) {} | |
40 | }; | |
41 | ||
42 | /// Manages a control connection from an FTP client. | |
43 | class Server: public ConnStateData | |
44 | { | |
45 | public: | |
46 | explicit Server(const MasterXaction::Pointer &xact); | |
47 | virtual ~Server(); | |
48 | ||
49 | MasterState master; ///< info shared among our FTP client and server jobs | |
50 | ||
51 | protected: | |
52 | friend void StartListening(); | |
53 | ||
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; | |
63 | ||
64 | /* BodyPipe API */ | |
65 | virtual void noteMoreBodySpaceAvailable(BodyPipe::Pointer); | |
66 | virtual void noteBodyConsumerAborted(BodyPipe::Pointer ptr); | |
67 | ||
68 | /* AsyncJob API */ | |
69 | virtual void start(); | |
70 | ||
71 | /* Comm callbacks */ | |
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); | |
79 | ||
80 | unsigned int listenForDataConnection(); | |
81 | bool createDataConnection(Ip::Address cltAddr); | |
82 | void closeDataConnection(); | |
83 | ||
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(); | |
90 | ||
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); | |
99 | ||
100 | bool handleRequest(String &cmd, String ¶ms); | |
101 | void setDataCommand(); | |
102 | bool checkDataConnPre(); | |
103 | ||
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); | |
116 | ||
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); | |
127 | ||
128 | private: | |
129 | void doProcessRequest(); | |
130 | void shovelUploadData(); | |
131 | ||
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 | |
140 | ||
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 | |
144 | ||
145 | CBDATA_CLASS2(Server); | |
146 | }; | |
147 | ||
148 | } // namespace Ftp | |
149 | ||
150 | #endif /* SQUID_SERVERS_FTP_SERVER_H */ |