]> git.ipfire.org Git - thirdparty/squid.git/blame - src/servers/FtpServer.h
Fixed clang -Winconsistent-missing-override warning.
[thirdparty/squid.git] / src / servers / FtpServer.h
CommitLineData
92ae4c86 1/*
ef57eb7b 2 * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
bbc27441
AJ
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.
92ae4c86
AR
7 */
8
bbc27441
AJ
9/* DEBUG: section 33 Client-side Routines */
10
92ae4c86
AR
11#ifndef SQUID_SERVERS_FTP_SERVER_H
12#define SQUID_SERVERS_FTP_SERVER_H
13
aea65fec 14#include "base/Lock.h"
8939f9c9 15#include "client_side.h"
92ae4c86 16
27c841f6
AR
17namespace Ftp
18{
92ae4c86
AR
19
20typedef enum {
21 fssBegin,
22 fssConnected,
23 fssHandleFeat,
24 fssHandlePasv,
25 fssHandlePort,
26 fssHandleDataRequest,
27 fssHandleUploadRequest,
28 fssHandleEprt,
29 fssHandleEpsv,
30 fssHandleCwd,
31 fssHandlePass,
32 fssHandleCdup,
33 fssError
34} ServerState;
35
36// TODO: This should become a part of MasterXaction when we start sending
37// master transactions to the clients/ code.
38/// Transaction information shared among our FTP client and server jobs.
aea65fec 39class MasterState: public RefCountable
92ae4c86
AR
40{
41public:
aea65fec
AR
42 typedef RefCount<MasterState> Pointer;
43
92cfc72f 44 MasterState(): serverState(fssBegin), clientReadGreeting(false), userDataDone(0), waitForOriginData(false) {}
aea65fec 45
92ae4c86 46 Ip::Address clientDataAddr; ///< address of our FTP client data connection
43446566 47 SBuf workingDir; ///< estimated current working directory for URI formation
92ae4c86
AR
48 ServerState serverState; ///< what our FTP server is doing
49 bool clientReadGreeting; ///< whether our FTP client read their FTP server greeting
92cfc72f
CT
50 /// Squid will send or has sent this final status code to the FTP client
51 int userDataDone;
52 /// whether the transfer on the Squid-origin data connection is not over yet
53 bool waitForOriginData;
92ae4c86
AR
54};
55
56/// Manages a control connection from an FTP client.
57class Server: public ConnStateData
58{
5c2f68b7 59 CBDATA_CLASS(Server);
4d0ce225
FC
60 // XXX CBDATA_CLASS expands to nonvirtual toCbdata, AsyncJob::toCbdata
61 // is pure virtual. breaks build on clang if override is used
5c2f68b7 62
92ae4c86
AR
63public:
64 explicit Server(const MasterXaction::Pointer &xact);
65 virtual ~Server();
0d253dfa 66 /* AsyncJob API */
4d0ce225 67 virtual void callException(const std::exception &e);
92ae4c86 68
92cfc72f
CT
69 /// Called by Ftp::Client class when it is done receiving or
70 /// sending data. Waits for both agents to be done before
71 /// responding to the FTP client and closing the data connection.
72 void originDataCompletionCheckpoint();
73
aea65fec
AR
74 // This is a pointer in hope to minimize future changes when MasterState
75 // becomes a part of MasterXaction. Guaranteed not to be nil.
76 MasterState::Pointer master; ///< info shared among our FTP client and server jobs
92ae4c86
AR
77
78protected:
79 friend void StartListening();
80
eacfca83 81 // errors detected before it is possible to create an HTTP request wrapper
3aab028c
FC
82 enum class EarlyErrorKind {
83 HugeRequest,
84 MissingLogin,
85 MissingUsername,
86 MissingHost,
87 UnsupportedCommand,
88 InvalidUri,
89 MalformedCommand
90 };
eacfca83 91
92ae4c86 92 /* ConnStateData API */
d3dddfb5
AJ
93 virtual Http::Stream *parseOneRequest();
94 virtual void processParsedRequest(Http::Stream *context);
92ae4c86
AR
95 virtual void notePeerConnection(Comm::ConnectionPointer conn);
96 virtual void clientPinnedConnectionClosed(const CommCloseCbParams &io);
97 virtual void handleReply(HttpReply *header, StoreIOBuffer receivedData);
98 virtual int pipelinePrefetchMax() const;
84540b47 99 virtual void writeControlMsgAndCall(HttpReply *rep, AsyncCall::Pointer &call);
92ae4c86
AR
100 virtual time_t idleTimeout() const;
101
102 /* BodyPipe API */
103 virtual void noteMoreBodySpaceAvailable(BodyPipe::Pointer);
104 virtual void noteBodyConsumerAborted(BodyPipe::Pointer ptr);
105
106 /* AsyncJob API */
107 virtual void start();
108
109 /* Comm callbacks */
110 static void AcceptCtrlConnection(const CommAcceptCbParams &params);
111 void acceptDataConnection(const CommAcceptCbParams &params);
112 void readUploadData(const CommIoCbParams &io);
113 void wroteEarlyReply(const CommIoCbParams &io);
114 void wroteReply(const CommIoCbParams &io);
115 void wroteReplyData(const CommIoCbParams &io);
116 void connectedForData(const CommConnectCbParams &params);
117
118 unsigned int listenForDataConnection();
119 bool createDataConnection(Ip::Address cltAddr);
120 void closeDataConnection();
121
92cfc72f
CT
122 /// Called after data trasfer on client-to-squid data connection is
123 /// finished.
124 void userDataCompletionCheckpoint(int finalStatusCode);
125
126 /// Writes the data-transfer status reply to the FTP client and
127 /// closes the data connection.
128 void completeDataExchange();
129
1ab04517 130 void calcUri(const SBuf *file);
92ae4c86 131 void changeState(const Ftp::ServerState newState, const char *reason);
d3dddfb5 132 Http::Stream *handleUserRequest(const SBuf &cmd, SBuf &params);
92ae4c86
AR
133 bool checkDataConnPost() const;
134 void replyDataWritingCheckpoint();
135 void maybeReadUploadData();
136
137 void setReply(const int code, const char *msg);
138 void writeCustomReply(const int code, const char *msg, const HttpReply *reply = NULL);
139 void writeEarlyReply(const int code, const char *msg);
140 void writeErrorReply(const HttpReply *reply, const int status);
141 void writeForwardedForeign(const HttpReply *reply);
142 void writeForwardedReply(const HttpReply *reply);
143 void writeForwardedReplyAndCall(const HttpReply *reply, AsyncCall::Pointer &call);
144 void writeReply(MemBuf &mb);
145
d3dddfb5 146 Http::Stream *earlyError(const EarlyErrorKind eek);
eacfca83 147 bool handleRequest(HttpRequest *);
92ae4c86
AR
148 void setDataCommand();
149 bool checkDataConnPre();
150
151 /// a method handling an FTP command; selected by handleRequest()
152 typedef bool (Ftp::Server::*RequestHandler)(String &cmd, String &params);
153 bool handleFeatRequest(String &cmd, String &params);
154 bool handlePasvRequest(String &cmd, String &params);
155 bool handlePortRequest(String &cmd, String &params);
156 bool handleDataRequest(String &cmd, String &params);
157 bool handleUploadRequest(String &cmd, String &params);
158 bool handleEprtRequest(String &cmd, String &params);
159 bool handleEpsvRequest(String &cmd, String &params);
160 bool handleCwdRequest(String &cmd, String &params);
161 bool handlePassRequest(String &cmd, String &params);
162 bool handleCdupRequest(String &cmd, String &params);
163
164 /// a method handling an FTP response; selected by handleReply()
165 typedef void (Ftp::Server::*ReplyHandler)(const HttpReply *reply, StoreIOBuffer data);
166 void handleFeatReply(const HttpReply *header, StoreIOBuffer receivedData);
167 void handlePasvReply(const HttpReply *header, StoreIOBuffer receivedData);
168 void handlePortReply(const HttpReply *header, StoreIOBuffer receivedData);
169 void handleErrorReply(const HttpReply *header, StoreIOBuffer receivedData);
170 void handleDataReply(const HttpReply *header, StoreIOBuffer receivedData);
171 void handleUploadReply(const HttpReply *header, StoreIOBuffer receivedData);
172 void handleEprtReply(const HttpReply *header, StoreIOBuffer receivedData);
173 void handleEpsvReply(const HttpReply *header, StoreIOBuffer receivedData);
174
175private:
176 void doProcessRequest();
177 void shovelUploadData();
e7ce227f 178 void resetLogin(const char *reason);
92ae4c86 179
1ab04517
AR
180 SBuf uri; ///< a URI reconstructed from various FTP message details
181 SBuf host; ///< intended dest. of a transparently intercepted FTP conn
92ae4c86
AR
182 bool gotEpsvAll; ///< restrict data conn setup commands to just EPSV
183 AsyncCall::Pointer onDataAcceptCall; ///< who to call upon data conn acceptance
184 Comm::ConnectionPointer dataListenConn; ///< data connection listening socket
185 Comm::ConnectionPointer dataConn; ///< data connection
186 char uploadBuf[CLIENT_REQ_BUF_SZ]; ///< data connection input buffer
187 size_t uploadAvailSize; ///< number of yet unused uploadBuf bytes
188
189 AsyncCall::Pointer listener; ///< set when we are passively listening
190 AsyncCall::Pointer connector; ///< set when we are actively connecting
191 AsyncCall::Pointer reader; ///< set when we are reading FTP data
92ae4c86
AR
192};
193
194} // namespace Ftp
195
196#endif /* SQUID_SERVERS_FTP_SERVER_H */
f53969cc 197