xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 
42 #include "XrdOuc/XrdOucString.hh"
43 
44 #include "XProtocol/XProtocol.hh"
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 
59 struct ReadWriteOp {
60  // < 0 means "not specified"
61  long long bytestart;
62  long long byteend;
63 };
64 
65 struct DirListInfo {
66  std::string path;
67  long long size;
68  long id;
69  long flags;
70  long modtime;
71 };
72 
73 
74 class XrdHttpProtocol;
75 class XrdOucEnv;
76 
78 private:
79  // HTTP response parameters to be sent back to the user
81  std::string httpStatusText;
82 
83  int parseContentRange(char *);
84  int parseHost(char *);
85  int parseRWOp(char *);
86 
87  //xmlDocPtr xmlbody; /* the resulting document tree */
89 
90  void clientMarshallReadAheadList(int nitems);
91  void clientUnMarshallReadAheadList(int nitems);
92 
93 
94  void getfhandle();
95 
101  int PostProcessHTTPReq(bool final = false);
102 
103  // Parse a resource string, typically a filename, setting the resource field and the opaque data
104  void parseResource(char *url);
105  // Map an XRootD error code to an appropriate HTTP status code and message
107 public:
108 
109  XrdHttpReq(XrdHttpProtocol *protinstance) : keepalive(true) {
110 
111  prot = protinstance;
112  length = 0;
113  //xmlbody = 0;
114  depth = 0;
115  ralist = 0;
116  opaque = 0;
117  writtenbytes = 0;
118  fopened = false;
119  headerok = false;
120  };
121 
122  virtual ~XrdHttpReq();
123 
124  virtual void reset();
125 
127  int parseLine(char *line, int len);
128 
130  int parseFirstLine(char *line, int len);
131 
133  int parseBody(char *body, long long len);
134 
136  int ReqReadV();
138 
140  std::string buildPartialHdr(long long bytestart, long long byteend, long long filesize, char *token);
141 
143  std::string buildPartialHdrEnd(char *token);
144 
145  // Appends the opaque info that we have
146  // NOTE: this function assumes that the strings are unquoted, and will quote them
147  void appendOpaque(XrdOucString &s, XrdSecEntity *secent, char *hash, time_t tnow);
148 
149  // ----------------
150  // Description of the request. The header/body parsing
151  // is supposed to populate these fields, for fast access while
152  // processing the request
153 
155 
156  enum ReqType {
157  rtUnset = -1,
170  };
171 
174  std::string requestverb;
175 
176  // We have to keep the headers for possible further processing
177  // by external plugins
178  std::map<std::string, std::string> allheaders;
179 
186 
187 
189  bool headerok;
190 
191 
192  // This can be largely optimized...
194  std::vector<ReadWriteOp> rwOps;
197  std::vector<ReadWriteOp> rwOps_split;
198 
199  bool keepalive;
200  long long length; // Total size from client for PUT; total length of response TO client for GET.
201  int depth;
203 
205  std::string host;
207  std::string destination;
208 
210  std::string m_req_digest;
215 
217  std::string hdr2cgistr;
218 
219  //
220  // Area for coordinating request and responses to/from the bridge
221  //
222 
223 
225  unsigned int rwOpDone, rwOpPartialDone;
226 
229 
233  std::string etext;
235 
237  const struct iovec *iovP;
238  int iovN;
239  int iovL;
240  bool final;
241 
242  // The latest stat info got from the xrd layer
243  long long filesize;
244  long fileflags;
246  char fhandle[4];
247  bool fopened;
248 
250  std::string stringresp;
251 
253  int reqstate;
254 
256  long long writtenbytes;
257 
258 
259 
260 
261 
267  int ProcessHTTPReq();
268 
269 
270  // ------------
271  // Items inherited from the Bridge class
272  //
273 
274  //-----------------------------------------------------------------------------
300  //-----------------------------------------------------------------------------
301 
302  virtual bool Data(XrdXrootd::Bridge::Context &info,
303  const
304  struct iovec *iovP,
305  int iovN,
306  int iovL,
307  bool final
308  );
309 
310  //-----------------------------------------------------------------------------
320  //-----------------------------------------------------------------------------
321 
322  virtual bool Done(XrdXrootd::Bridge::Context &info);
323 
324 
325  //-----------------------------------------------------------------------------
338  //-----------------------------------------------------------------------------
339 
340  virtual bool Error(XrdXrootd::Bridge::Context &info,
341  int ecode,
342  const char *etext
343  );
344 
345  //-----------------------------------------------------------------------------
358  //-----------------------------------------------------------------------------
359 
360  virtual int File(XrdXrootd::Bridge::Context &info,
361  int dlen
362  );
363 
364  //-----------------------------------------------------------------------------
377  //-----------------------------------------------------------------------------
378 
379  virtual bool Redir(XrdXrootd::Bridge::Context &info,
380  int port,
381  const char *hname
382  );
383 
384 
385 
386 
387 
388 };
389 
390 
391 
392 void trim(std::string &str);
393 
394 #endif /* XRDHTTPREQ_HH */
395 
long filemodtime
Definition: XrdHttpReq.hh:245
virtual bool Data(XrdXrootd::Bridge::Context &info, const struct iovec *iovP, int iovN, int iovL, bool final)
int depth
Definition: XrdHttpReq.hh:201
XResponseType xrdresp
The last response data we got.
Definition: XrdHttpReq.hh:231
void clientMarshallReadAheadList(int nitems)
Definition: XrdHttpReq.hh:165
std::string requestverb
Definition: XrdHttpReq.hh:174
Definition: XrdHttpReq.hh:161
long modtime
Definition: XrdHttpReq.hh:70
long fileflags
Definition: XrdHttpReq.hh:244
std::string buildPartialHdr(long long bytestart, long long byteend, long long filesize, char *token)
Build a partial header for a multipart response.
int parseFirstLine(char *line, int len)
Parse the first line of the header.
long long writtenbytes
In a long write, we track where we have arrived.
Definition: XrdHttpReq.hh:256
Definition: XProtocol.hh:658
bool sendcontinue
Definition: XrdHttpReq.hh:202
XrdHttpProtocol * prot
Definition: XrdHttpReq.hh:88
std::string destination
The destination field specified in the req.
Definition: XrdHttpReq.hh:207
Definition: XrdXrootdBridge.hh:225
XrdOucString resourceplusopaque
The resource specified by the request, including all the opaque data.
Definition: XrdHttpReq.hh:185
XrdOucString m_resource_with_digest
Definition: XrdHttpReq.hh:214
Definition: XrdHttpReq.hh:77
void parseResource(char *url)
void trim(std::string &str)
int ProcessHTTPReq()
virtual bool Redir(XrdXrootd::Bridge::Context &info, int port, const char *hname)
Definition: XrdHttpReq.hh:168
ReqType
These are the HTTP/DAV requests that we support.
Definition: XrdHttpReq.hh:156
bool fopened
Definition: XrdHttpReq.hh:247
long long size
Definition: XrdHttpReq.hh:67
Definition: XrdHttpReq.hh:59
XrdOucEnv * opaque
The opaque data, after parsing.
Definition: XrdHttpReq.hh:183
XResponseType
Definition: XProtocol.hh:292
int parseLine(char *line, int len)
Parse the header.
int iovL
byte count
Definition: XrdHttpReq.hh:239
std::string etext
Definition: XrdHttpReq.hh:233
long long bytestart
Definition: XrdHttpReq.hh:61
virtual bool Error(XrdXrootd::Bridge::Context &info, int ecode, const char *etext)
Definition: XrdHttpReq.hh:169
bool headerok
Tells if we have finished reading the header.
Definition: XrdHttpReq.hh:189
bool keepalive
Definition: XrdHttpReq.hh:199
std::vector< ReadWriteOp > rwOps
The original list of multiple reads to perform.
Definition: XrdHttpReq.hh:194
char fhandle[4]
Definition: XrdHttpReq.hh:246
virtual int File(XrdXrootd::Bridge::Context &info, int dlen)
Definition: XrdHttpReq.hh:157
int httpStatusCode
Definition: XrdHttpReq.hh:80
int parseHost(char *)
virtual ~XrdHttpReq()
Definition: XrdHttpReq.hh:65
virtual bool Done(XrdXrootd::Bridge::Context &info)
the result context
Definition: XrdHttpReq.hh:167
std::string buildPartialHdrEnd(char *token)
Build the closing part for a multipart response.
std::string hdr2cgistr
Additional opaque info that may come from the hdr2cgi directive.
Definition: XrdHttpReq.hh:217
int PostProcessHTTPReq(bool final=false)
XErrorCode
Definition: XProtocol.hh:324
readahead_list * ralist
Definition: XrdHttpReq.hh:137
Definition: XrdOucEnv.hh:41
std::string host
The host field specified in the req.
Definition: XrdHttpReq.hh:205
std::string httpStatusText
Definition: XrdHttpReq.hh:81
std::vector< ReadWriteOp > rwOps_split
Definition: XrdHttpReq.hh:197
int parseBody(char *body, long long len)
Parse the body of a request, assuming that it&#39;s XML and that it&#39;s entirely in memory.
std::string m_req_digest
The requested digest type.
Definition: XrdHttpReq.hh:210
void getfhandle()
unsigned int rwOpDone
To coordinate multipart responses across multiple calls.
Definition: XrdHttpReq.hh:225
int ReqReadV()
Prepare the buffers for sending a readv request.
void mapXrdErrorToHttpStatus()
Definition: XrdHttpProtocol.hh:76
long id
Definition: XrdHttpReq.hh:68
Definition: XrdXrootdBridge.hh:293
Definition: XrdHttpReq.hh:159
void clientUnMarshallReadAheadList(int nitems)
ClientRequest xrdreq
The last issued xrd request, often pending.
Definition: XrdHttpReq.hh:228
std::string stringresp
If we want to give a string as a response, we compose it here.
Definition: XrdHttpReq.hh:250
long long length
Definition: XrdHttpReq.hh:200
int iovN
array count
Definition: XrdHttpReq.hh:238
Definition: XrdHttpReq.hh:166
int reqstate
State machine to talk to the bridge.
Definition: XrdHttpReq.hh:253
long long filesize
Definition: XrdHttpReq.hh:243
XrdHttpReq(XrdHttpProtocol *protinstance)
Definition: XrdHttpReq.hh:109
int parseRWOp(char *)
Definition: XrdHttpReq.hh:158
long long byteend
Definition: XrdHttpReq.hh:62
void appendOpaque(XrdOucString &s, XrdSecEntity *secent, char *hash, time_t tnow)
XErrorCode xrderrcode
Definition: XrdHttpReq.hh:232
Definition: XrdSecEntity.hh:51
Definition: XProtocol.hh:618
XrdOucString redirdest
Definition: XrdHttpReq.hh:234
virtual void reset()
ReqType request
The request we got.
Definition: XrdHttpReq.hh:173
XrdOucString resource
The resource specified by the request, stripped of opaque data.
Definition: XrdHttpReq.hh:181
Definition: XrdHttpReq.hh:162
Definition: XrdHttpReq.hh:160
struct iovec * iovP
The latest data chunks got from the xrd layer. These are valid only inside the callbacks! ...
Definition: XrdHttpReq.hh:237
std::map< std::string, std::string > allheaders
Definition: XrdHttpReq.hh:178
Definition: XrdHttpReq.hh:164
Definition: XrdOucString.hh:254
unsigned int rwOpPartialDone
Definition: XrdHttpReq.hh:225
long flags
Definition: XrdHttpReq.hh:69
Definition: XrdHttpReq.hh:163
std::string path
Definition: XrdHttpReq.hh:66
int parseContentRange(char *)