2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 09 File Transfer Protocol (FTP) */
12 #include "ftp/Elements.h"
13 #include "HttpHdrCc.h"
14 #include "HttpReply.h"
15 #include "sbuf/SBuf.h"
17 // FTP does not have a notion of a "protocol version" but we need something for
18 // compatibility with the current HttpMsg wrapping layer. We use version 1.1:
19 // * some ICAP services probably expect /1.0 or /1.1 when parsing HTTP headers;
20 // * FTP commands are sent on a "persistent by default" connection, just like
21 // HTTP/1.1. Using 1.1 leads to fewer exceptions in current code shared by
24 Ftp::ProtocolVersion()
26 return AnyP::ProtocolVersion(AnyP::PROTO_FTP
, 1, 1);
30 Ftp::HttpReplyWrapper(const int ftpStatus
, const char *ftpReason
, const Http::StatusCode httpStatus
, const int64_t clen
)
32 HttpReply
*const reply
= new HttpReply
;
34 AnyP::ProtocolVersion httpVersion
= Http::ProtocolVersion(
35 Ftp::ProtocolVersion().major
, Ftp::ProtocolVersion().minor
);
36 reply
->sline
.set(httpVersion
, httpStatus
);
38 HttpHeader
&header
= reply
->header
;
39 header
.putTime(Http::HdrType::DATE
, squid_curtime
);
46 header
.putInt(Http::HdrType::FTP_STATUS
, ftpStatus
);
48 header
.putStr(Http::HdrType::FTP_REASON
, ftpReason
);
50 header
.putInt64(Http::HdrType::CONTENT_LENGTH
, clen
);
51 reply
->hdrCacheInit();
58 static const SBuf
cmd("APPE");
65 static const SBuf
cmd("AUTH");
72 static const SBuf
cmd("CWD");
79 static const SBuf
cmd("DELE");
86 static const SBuf
cmd("EPRT");
93 static const SBuf
cmd("EPSV");
100 static const SBuf
cmd("LIST");
107 static const SBuf
cmd("MKD");
114 static const SBuf
cmd("MLSD");
121 static const SBuf
cmd("MLST");
128 static const SBuf
cmd("NLST");
135 static const SBuf
cmd("RETR");
142 static const SBuf
cmd("RMD");
149 static const SBuf
cmd("RNFR");
156 static const SBuf
cmd("RNTO");
163 static const SBuf
cmd("SMNT");
170 static const SBuf
cmd("STAT");
177 static const SBuf
cmd("STOR");
184 static const SBuf
cmd("STOU");
191 static const SBuf
cmd("USER");