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