]> git.ipfire.org Git - thirdparty/squid.git/blame - src/servers/FtpServer.h
Cleanup: fix assertion in Store unit tests
[thirdparty/squid.git] / src / servers / FtpServer.h
CommitLineData
92ae4c86 1/*
bde978a6 2 * Copyright (C) 1996-2015 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
44 MasterState(): serverState(fssBegin), clientReadGreeting(false) {}
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
92ae4c86
AR
50};
51
52/// Manages a control connection from an FTP client.
53class Server: public ConnStateData
54{
5c2f68b7 55 CBDATA_CLASS(Server);
4d0ce225
FC
56 // XXX CBDATA_CLASS expands to nonvirtual toCbdata, AsyncJob::toCbdata
57 // is pure virtual. breaks build on clang if override is used
5c2f68b7 58
92ae4c86
AR
59public:
60 explicit Server(const MasterXaction::Pointer &xact);
61 virtual ~Server();
0d253dfa 62 /* AsyncJob API */
4d0ce225 63 virtual void callException(const std::exception &e);
92ae4c86 64
aea65fec
AR
65 // This is a pointer in hope to minimize future changes when MasterState
66 // becomes a part of MasterXaction. Guaranteed not to be nil.
67 MasterState::Pointer master; ///< info shared among our FTP client and server jobs
92ae4c86
AR
68
69protected:
70 friend void StartListening();
71
eacfca83
AR
72 // errors detected before it is possible to create an HTTP request wrapper
73 typedef enum {
74 eekHugeRequest,
75 eekMissingLogin,
76 eekMissingUsername,
77 eekMissingHost,
78 eekUnsupportedCommand,
79 eekInvalidUri,
80 eekMalformedCommand
81 } EarlyErrorKind;
82
92ae4c86 83 /* ConnStateData API */
9bafa70d
AJ
84 virtual ClientSocketContext *parseOneRequest();
85 virtual void processParsedRequest(ClientSocketContext *context);
92ae4c86
AR
86 virtual void notePeerConnection(Comm::ConnectionPointer conn);
87 virtual void clientPinnedConnectionClosed(const CommCloseCbParams &io);
88 virtual void handleReply(HttpReply *header, StoreIOBuffer receivedData);
89 virtual int pipelinePrefetchMax() const;
90 virtual void writeControlMsgAndCall(ClientSocketContext *context, HttpReply *rep, AsyncCall::Pointer &call);
91 virtual time_t idleTimeout() const;
92
93 /* BodyPipe API */
94 virtual void noteMoreBodySpaceAvailable(BodyPipe::Pointer);
95 virtual void noteBodyConsumerAborted(BodyPipe::Pointer ptr);
96
97 /* AsyncJob API */
98 virtual void start();
99
100 /* Comm callbacks */
101 static void AcceptCtrlConnection(const CommAcceptCbParams &params);
102 void acceptDataConnection(const CommAcceptCbParams &params);
103 void readUploadData(const CommIoCbParams &io);
104 void wroteEarlyReply(const CommIoCbParams &io);
105 void wroteReply(const CommIoCbParams &io);
106 void wroteReplyData(const CommIoCbParams &io);
107 void connectedForData(const CommConnectCbParams &params);
108
109 unsigned int listenForDataConnection();
110 bool createDataConnection(Ip::Address cltAddr);
111 void closeDataConnection();
112
1ab04517 113 void calcUri(const SBuf *file);
92ae4c86 114 void changeState(const Ftp::ServerState newState, const char *reason);
eacfca83 115 ClientSocketContext *handleUserRequest(const SBuf &cmd, SBuf &params);
92ae4c86
AR
116 bool checkDataConnPost() const;
117 void replyDataWritingCheckpoint();
118 void maybeReadUploadData();
119
120 void setReply(const int code, const char *msg);
121 void writeCustomReply(const int code, const char *msg, const HttpReply *reply = NULL);
122 void writeEarlyReply(const int code, const char *msg);
123 void writeErrorReply(const HttpReply *reply, const int status);
124 void writeForwardedForeign(const HttpReply *reply);
125 void writeForwardedReply(const HttpReply *reply);
126 void writeForwardedReplyAndCall(const HttpReply *reply, AsyncCall::Pointer &call);
127 void writeReply(MemBuf &mb);
128
eacfca83
AR
129 ClientSocketContext *earlyError(const EarlyErrorKind eek);
130 bool handleRequest(HttpRequest *);
92ae4c86
AR
131 void setDataCommand();
132 bool checkDataConnPre();
133
134 /// a method handling an FTP command; selected by handleRequest()
135 typedef bool (Ftp::Server::*RequestHandler)(String &cmd, String &params);
136 bool handleFeatRequest(String &cmd, String &params);
137 bool handlePasvRequest(String &cmd, String &params);
138 bool handlePortRequest(String &cmd, String &params);
139 bool handleDataRequest(String &cmd, String &params);
140 bool handleUploadRequest(String &cmd, String &params);
141 bool handleEprtRequest(String &cmd, String &params);
142 bool handleEpsvRequest(String &cmd, String &params);
143 bool handleCwdRequest(String &cmd, String &params);
144 bool handlePassRequest(String &cmd, String &params);
145 bool handleCdupRequest(String &cmd, String &params);
146
147 /// a method handling an FTP response; selected by handleReply()
148 typedef void (Ftp::Server::*ReplyHandler)(const HttpReply *reply, StoreIOBuffer data);
149 void handleFeatReply(const HttpReply *header, StoreIOBuffer receivedData);
150 void handlePasvReply(const HttpReply *header, StoreIOBuffer receivedData);
151 void handlePortReply(const HttpReply *header, StoreIOBuffer receivedData);
152 void handleErrorReply(const HttpReply *header, StoreIOBuffer receivedData);
153 void handleDataReply(const HttpReply *header, StoreIOBuffer receivedData);
154 void handleUploadReply(const HttpReply *header, StoreIOBuffer receivedData);
155 void handleEprtReply(const HttpReply *header, StoreIOBuffer receivedData);
156 void handleEpsvReply(const HttpReply *header, StoreIOBuffer receivedData);
157
158private:
159 void doProcessRequest();
160 void shovelUploadData();
e7ce227f 161 void resetLogin(const char *reason);
92ae4c86 162
1ab04517
AR
163 SBuf uri; ///< a URI reconstructed from various FTP message details
164 SBuf host; ///< intended dest. of a transparently intercepted FTP conn
92ae4c86
AR
165 bool gotEpsvAll; ///< restrict data conn setup commands to just EPSV
166 AsyncCall::Pointer onDataAcceptCall; ///< who to call upon data conn acceptance
167 Comm::ConnectionPointer dataListenConn; ///< data connection listening socket
168 Comm::ConnectionPointer dataConn; ///< data connection
169 char uploadBuf[CLIENT_REQ_BUF_SZ]; ///< data connection input buffer
170 size_t uploadAvailSize; ///< number of yet unused uploadBuf bytes
171
172 AsyncCall::Pointer listener; ///< set when we are passively listening
173 AsyncCall::Pointer connector; ///< set when we are actively connecting
174 AsyncCall::Pointer reader; ///< set when we are reading FTP data
92ae4c86
AR
175};
176
177} // namespace Ftp
178
179#endif /* SQUID_SERVERS_FTP_SERVER_H */
f53969cc 180