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