xrootd
XrdHttpReq.hh
Go to the documentation of this file.
1//------------------------------------------------------------------------------
2// This file is part of XrdHTTP: A pragmatic implementation of the
3// HTTP/WebDAV protocol for the Xrootd framework
4//
5// Copyright (c) 2013 by European Organization for Nuclear Research (CERN)
6// Author: Fabrizio Furano <furano@cern.ch>
7// File Date: Nov 2012
8//------------------------------------------------------------------------------
9// XRootD is free software: you can redistribute it and/or modify
10// it under the terms of the GNU Lesser General Public License as published by
11// the Free Software Foundation, either version 3 of the License, or
12// (at your option) any later version.
13//
14// XRootD is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17// GNU General Public License for more details.
18//
19// You should have received a copy of the GNU Lesser General Public License
20// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
21//------------------------------------------------------------------------------
22
23
24
25
26
27
28
38#ifndef XRDHTTPREQ_HH
39#define XRDHTTPREQ_HH
40
41
43
46
47#include <vector>
48#include <string>
49#include <map>
50
51//#include <libxml/parser.h>
52//#include <libxml/tree.h>
53
54
55
56#define READV_MAXCHUNKS 512
57#define READV_MAXCHUNKSIZE (1024*128)
58
60 // < 0 means "not specified"
61 long long bytestart;
62 long long byteend;
63};
64
66 std::string path;
67 long long size;
68 long id;
69 long flags;
70 long modtime;
71};
72
73
74class XrdHttpProtocol;
75class XrdOucEnv;
76
78private:
79 // HTTP response parameters to be sent back to the user
81 std::string httpStatusText;
82
83 // Whether transfer encoding was requested.
87
88 int parseContentRange(char *);
89 int parseHost(char *);
90 int parseRWOp(char *);
91
92 //xmlDocPtr xmlbody; /* the resulting document tree */
94
97
98
99 void getfhandle();
100
101 // Process the checksum response and return a header that should
102 // be included in the response.
103 int PostProcessChecksum(std::string &digest_header);
104
110 int PostProcessHTTPReq(bool final = false);
111
112 // Parse a resource string, typically a filename, setting the resource field and the opaque data
113 void parseResource(char *url);
114 // Map an XRootD error code to an appropriate HTTP status code and message
116
117 // Sanitize the resource from http[s]://[host]/ questionable prefix
119
125 void selectChecksum(const std::string & userDigest, std::string & selectedChecksum);
126
127public:
128
129 XrdHttpReq(XrdHttpProtocol *protinstance) : keepalive(true) {
130
131 prot = protinstance;
132 length = 0;
133 //xmlbody = 0;
134 depth = 0;
135 ralist = 0;
136 opaque = 0;
137 writtenbytes = 0;
138 fopened = false;
139 headerok = false;
140 };
141
142 virtual ~XrdHttpReq();
143
144 virtual void reset();
145
147 int parseLine(char *line, int len);
148
150 int parseFirstLine(char *line, int len);
151
153 int parseBody(char *body, long long len);
154
156 int ReqReadV();
158
160 std::string buildPartialHdr(long long bytestart, long long byteend, long long filesize, char *token);
161
163 std::string buildPartialHdrEnd(char *token);
164
165 // Appends the opaque info that we have
166 // NOTE: this function assumes that the strings are unquoted, and will quote them
167 void appendOpaque(XrdOucString &s, XrdSecEntity *secent, char *hash, time_t tnow);
168
169 // ----------------
170 // Description of the request. The header/body parsing
171 // is supposed to populate these fields, for fast access while
172 // processing the request
173
175
176 enum ReqType {
189 rtPOST
190 };
191
194 std::string requestverb;
195
196 // We have to keep the headers for possible further processing
197 // by external plugins
198 std::map<std::string, std::string> allheaders;
199
206
207
210
211
212 // This can be largely optimized...
214 std::vector<ReadWriteOp> rwOps;
217 std::vector<ReadWriteOp> rwOps_split;
218
220 long long length; // Total size from client for PUT; total length of response TO client for GET.
221 int depth;
223
225 std::string host;
227 std::string destination;
228
230 std::string m_req_digest;
236 std::string m_digest_header;
237
239 std::string hdr2cgistr;
241
242 //
243 // Area for coordinating request and responses to/from the bridge
244 //
245
246
249
252
256 std::string etext;
258
260 const struct iovec *iovP;
261 int iovN;
262 int iovL;
263 bool final;
264
265 // The latest stat info got from the xrd layer
266 long long filesize;
269 char fhandle[4];
271
273 std::string stringresp;
274
277
279 long long writtenbytes;
280
281
282
283
284
291
292
293 // ------------
294 // Items inherited from the Bridge class
295 //
296
297 //-----------------------------------------------------------------------------
323 //-----------------------------------------------------------------------------
324
325 virtual bool Data(XrdXrootd::Bridge::Context &info,
326 const
327 struct iovec *iovP,
328 int iovN,
329 int iovL,
330 bool final
331 );
332
333 //-----------------------------------------------------------------------------
343 //-----------------------------------------------------------------------------
344
345 virtual bool Done(XrdXrootd::Bridge::Context &info);
346
347
348 //-----------------------------------------------------------------------------
361 //-----------------------------------------------------------------------------
362
364 int ecode,
365 const char *etext
366 );
367
368 //-----------------------------------------------------------------------------
381 //-----------------------------------------------------------------------------
382
384 int dlen
385 );
386
387 //-----------------------------------------------------------------------------
400 //-----------------------------------------------------------------------------
401
403 int port,
404 const char *hname
405 );
406
407
408
409
410
411};
412
413
414
415void trim(std::string &str);
416
417#endif /* XRDHTTPREQ_HH */
418
XErrorCode
Definition: XProtocol.hh:987
XResponseType
Definition: XProtocol.hh:896
void trim(std::string &str)
Definition: XrdHttpProtocol.hh:76
Definition: XrdHttpReq.hh:77
int reqstate
State machine to talk to the bridge.
Definition: XrdHttpReq.hh:276
char fhandle[4]
Definition: XrdHttpReq.hh:269
int PostProcessHTTPReq(bool final=false)
bool keepalive
Definition: XrdHttpReq.hh:219
std::vector< ReadWriteOp > rwOps
The original list of multiple reads to perform.
Definition: XrdHttpReq.hh:214
unsigned int rwOpPartialDone
Definition: XrdHttpReq.hh:248
ReqType
These are the HTTP/DAV requests that we support.
Definition: XrdHttpReq.hh:176
@ rtUnset
Definition: XrdHttpReq.hh:177
@ rtMalformed
Definition: XrdHttpReq.hh:179
@ rtDELETE
Definition: XrdHttpReq.hh:185
@ rtOPTIONS
Definition: XrdHttpReq.hh:183
@ rtMOVE
Definition: XrdHttpReq.hh:188
@ rtHEAD
Definition: XrdHttpReq.hh:181
@ rtGET
Definition: XrdHttpReq.hh:180
@ rtPATCH
Definition: XrdHttpReq.hh:184
@ rtPROPFIND
Definition: XrdHttpReq.hh:186
@ rtPUT
Definition: XrdHttpReq.hh:182
@ rtUnknown
Definition: XrdHttpReq.hh:178
@ rtPOST
Definition: XrdHttpReq.hh:189
@ rtMKCOL
Definition: XrdHttpReq.hh:187
int parseBody(char *body, long long len)
Parse the body of a request, assuming that it's XML and that it's entirely in memory.
std::string httpStatusText
Definition: XrdHttpReq.hh:81
long long length
Definition: XrdHttpReq.hh:220
std::string destination
The destination field specified in the req.
Definition: XrdHttpReq.hh:227
XrdOucString resource
The resource specified by the request, stripped of opaque data.
Definition: XrdHttpReq.hh:201
std::vector< ReadWriteOp > rwOps_split
Definition: XrdHttpReq.hh:217
void selectChecksum(const std::string &userDigest, std::string &selectedChecksum)
bool headerok
Tells if we have finished reading the header.
Definition: XrdHttpReq.hh:209
void clientMarshallReadAheadList(int nitems)
virtual void reset()
virtual bool Redir(XrdXrootd::Bridge::Context &info, int port, const char *hname)
XrdHttpProtocol * prot
Definition: XrdHttpReq.hh:93
std::string m_digest_header
The computed digest for the HTTP response header.
Definition: XrdHttpReq.hh:236
std::string etext
Definition: XrdHttpReq.hh:256
std::string stringresp
If we want to give a string as a response, we compose it here.
Definition: XrdHttpReq.hh:273
XResponseType xrdresp
The last response data we got.
Definition: XrdHttpReq.hh:254
XrdHttpReq(XrdHttpProtocol *protinstance)
Definition: XrdHttpReq.hh:129
std::string requestverb
Definition: XrdHttpReq.hh:194
ReqType request
The request we got.
Definition: XrdHttpReq.hh:193
int ProcessHTTPReq()
virtual bool Done(XrdXrootd::Bridge::Context &info)
the result context
long long writtenbytes
In a long write, we track where we have arrived.
Definition: XrdHttpReq.hh:279
XrdOucEnv * opaque
The opaque data, after parsing.
Definition: XrdHttpReq.hh:203
long fileflags
Definition: XrdHttpReq.hh:267
int PostProcessChecksum(std::string &digest_header)
int iovL
byte count
Definition: XrdHttpReq.hh:262
void sanitizeResourcePfx()
int depth
Definition: XrdHttpReq.hh:221
virtual bool Error(XrdXrootd::Bridge::Context &info, int ecode, const char *etext)
bool fopened
Definition: XrdHttpReq.hh:270
const struct iovec * iovP
The latest data chunks got from the xrd layer. These are valid only inside the callbacks!
Definition: XrdHttpReq.hh:260
int parseHost(char *)
int httpStatusCode
Definition: XrdHttpReq.hh:80
std::string m_req_digest
The requested digest type.
Definition: XrdHttpReq.hh:230
XrdOucString resourceplusopaque
The resource specified by the request, including all the opaque data.
Definition: XrdHttpReq.hh:205
void getfhandle()
int parseRWOp(char *)
std::string hdr2cgistr
Additional opaque info that may come from the hdr2cgi directive.
Definition: XrdHttpReq.hh:239
std::string host
The host field specified in the req.
Definition: XrdHttpReq.hh:225
long filemodtime
Definition: XrdHttpReq.hh:268
int parseFirstLine(char *line, int len)
Parse the first line of the header.
XrdOucString redirdest
Definition: XrdHttpReq.hh:257
long long m_current_chunk_size
Definition: XrdHttpReq.hh:86
void parseResource(char *url)
virtual int File(XrdXrootd::Bridge::Context &info, int dlen)
int parseLine(char *line, int len)
Parse the header.
std::string buildPartialHdrEnd(char *token)
Build the closing part for a multipart response.
int ReqReadV()
Prepare the buffers for sending a readv request.
bool m_transfer_encoding_chunked
Definition: XrdHttpReq.hh:84
void mapXrdErrorToHttpStatus()
bool m_appended_hdr2cgistr
Definition: XrdHttpReq.hh:240
void appendOpaque(XrdOucString &s, XrdSecEntity *secent, char *hash, time_t tnow)
readahead_list * ralist
Definition: XrdHttpReq.hh:157
int iovN
array count
Definition: XrdHttpReq.hh:261
virtual bool Data(XrdXrootd::Bridge::Context &info, const struct iovec *iovP, int iovN, int iovL, bool final)
XrdOucString m_resource_with_digest
Definition: XrdHttpReq.hh:234
long long filesize
Definition: XrdHttpReq.hh:266
long long m_current_chunk_offset
Definition: XrdHttpReq.hh:85
XErrorCode xrderrcode
Definition: XrdHttpReq.hh:255
void clientUnMarshallReadAheadList(int nitems)
std::map< std::string, std::string > allheaders
Definition: XrdHttpReq.hh:198
unsigned int rwOpDone
To coordinate multipart responses across multiple calls.
Definition: XrdHttpReq.hh:248
virtual ~XrdHttpReq()
int parseContentRange(char *)
bool sendcontinue
Definition: XrdHttpReq.hh:222
ClientRequest xrdreq
The last issued xrd request, often pending.
Definition: XrdHttpReq.hh:251
std::string buildPartialHdr(long long bytestart, long long byteend, long long filesize, char *token)
Build a partial header for a multipart response.
Definition: XrdOucEnv.hh:42
Definition: XrdOucString.hh:254
Definition: XrdSecEntity.hh:64
Definition: XrdXrootdBridge.hh:226
Definition: XrdXrootdBridge.hh:294
std::size_t hash(const BasicJsonType &j)
hash a JSON value
Definition: XrdOucJson.hh:5221
Definition: XrdHttpReq.hh:65
long long size
Definition: XrdHttpReq.hh:67
long flags
Definition: XrdHttpReq.hh:69
long id
Definition: XrdHttpReq.hh:68
std::string path
Definition: XrdHttpReq.hh:66
long modtime
Definition: XrdHttpReq.hh:70
Definition: XrdHttpReq.hh:59
long long byteend
Definition: XrdHttpReq.hh:62
long long bytestart
Definition: XrdHttpReq.hh:61
Definition: XProtocol.hh:658
Definition: XProtocol.hh:843