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