]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ftp/Elements.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / ftp / Elements.cc
CommitLineData
1ab04517 1/*
4ac4a490 2 * Copyright (C) 1996-2017 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.
1ab04517
AR
7 */
8
bbc27441
AJ
9/* DEBUG: section 09 File Transfer Protocol (FTP) */
10
1ab04517
AR
11#include "squid.h"
12#include "ftp/Elements.h"
43446566
AR
13#include "HttpHdrCc.h"
14#include "HttpReply.h"
65e41a45 15#include "sbuf/SBuf.h"
1ab04517 16
ecb19f1a
AR
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
22// HTTP and FTP.
23AnyP::ProtocolVersion
24Ftp::ProtocolVersion()
25{
26 return AnyP::ProtocolVersion(AnyP::PROTO_FTP, 1, 1);
27}
28
43446566
AR
29HttpReply *
30Ftp::HttpReplyWrapper(const int ftpStatus, const char *ftpReason, const Http::StatusCode httpStatus, const int64_t clen)
31{
32 HttpReply *const reply = new HttpReply;
ecb19f1a 33
2592bc70 34 AnyP::ProtocolVersion httpVersion = Http::ProtocolVersion(
3cc0f4e7 35 Ftp::ProtocolVersion().major, Ftp::ProtocolVersion().minor);
ecb19f1a
AR
36 reply->sline.set(httpVersion, httpStatus);
37
43446566 38 HttpHeader &header = reply->header;
789217a2 39 header.putTime(Http::HdrType::DATE, squid_curtime);
43446566
AR
40 {
41 HttpHdrCc cc;
42 cc.Private(String());
43 header.putCc(&cc);
44 }
45 if (ftpStatus > 0)
789217a2 46 header.putInt(Http::HdrType::FTP_STATUS, ftpStatus);
43446566 47 if (ftpReason)
789217a2 48 header.putStr(Http::HdrType::FTP_REASON, ftpReason);
43446566 49 if (clen >= 0)
789217a2 50 header.putInt64(Http::HdrType::CONTENT_LENGTH, clen);
43446566
AR
51 reply->hdrCacheInit();
52 return reply;
53}
54
1ab04517
AR
55const SBuf &
56Ftp::cmdAppe()
57{
58 static const SBuf cmd("APPE");
59 return cmd;
60}
61
62const SBuf &
63Ftp::cmdAuth()
64{
65 static const SBuf cmd("AUTH");
66 return cmd;
67}
68
69const SBuf &
70Ftp::cmdCwd()
71{
72 static const SBuf cmd("CWD");
73 return cmd;
74}
75
76const SBuf &
77Ftp::cmdDele()
78{
79 static const SBuf cmd("DELE");
80 return cmd;
81}
82
83const SBuf &
84Ftp::cmdEprt()
85{
86 static const SBuf cmd("EPRT");
87 return cmd;
88}
89
90const SBuf &
91Ftp::cmdEpsv()
92{
93 static const SBuf cmd("EPSV");
94 return cmd;
95}
96
97const SBuf &
98Ftp::cmdList()
99{
100 static const SBuf cmd("LIST");
101 return cmd;
102}
103
104const SBuf &
105Ftp::cmdMkd()
106{
107 static const SBuf cmd("MKD");
108 return cmd;
109}
110
111const SBuf &
112Ftp::cmdMlsd()
113{
114 static const SBuf cmd("MLSD");
115 return cmd;
116}
117
118const SBuf &
119Ftp::cmdMlst()
120{
121 static const SBuf cmd("MLST");
122 return cmd;
123}
124
125const SBuf &
126Ftp::cmdNlst()
127{
128 static const SBuf cmd("NLST");
129 return cmd;
130}
131
132const SBuf &
133Ftp::cmdRetr()
134{
135 static const SBuf cmd("RETR");
136 return cmd;
137}
138
139const SBuf &
140Ftp::cmdRmd()
141{
142 static const SBuf cmd("RMD");
143 return cmd;
144}
145
146const SBuf &
147Ftp::cmdRnfr()
148{
149 static const SBuf cmd("RNFR");
150 return cmd;
151}
152
153const SBuf &
154Ftp::cmdRnto()
155{
156 static const SBuf cmd("RNTO");
157 return cmd;
158}
159
160const SBuf &
161Ftp::cmdSmnt()
162{
163 static const SBuf cmd("SMNT");
164 return cmd;
165}
166
167const SBuf &
168Ftp::cmdStat()
169{
170 static const SBuf cmd("STAT");
171 return cmd;
172}
173
174const SBuf &
175Ftp::cmdStor()
176{
177 static const SBuf cmd("STOR");
178 return cmd;
179}
180
181const SBuf &
182Ftp::cmdStou()
183{
184 static const SBuf cmd("STOU");
185 return cmd;
186}
187
188const SBuf &
189Ftp::cmdUser()
190{
191 static const SBuf cmd("USER");
192 return cmd;
193}
f53969cc 194