00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00038 #ifndef XRDHTTPREQ_HH
00039 #define XRDHTTPREQ_HH
00040
00041
00042 #include "XrdOuc/XrdOucString.hh"
00043
00044 #include "XProtocol/XProtocol.hh"
00045 #include "XrdXrootd/XrdXrootdBridge.hh"
00046
00047 #include <vector>
00048 #include <string>
00049 #include <map>
00050
00051
00052
00053
00054
00055
00056 #define READV_MAXCHUNKS 512
00057 #define READV_MAXCHUNKSIZE (1024*128)
00058
00059 struct ReadWriteOp {
00060
00061 long long bytestart;
00062 long long byteend;
00063 };
00064
00065 struct DirListInfo {
00066 std::string path;
00067 long long size;
00068 long id;
00069 long flags;
00070 long modtime;
00071 };
00072
00073
00074 class XrdHttpProtocol;
00075 class XrdOucEnv;
00076
00077 class XrdHttpReq : public XrdXrootd::Bridge::Result {
00078 private:
00079
00080 int httpStatusCode;
00081 std::string httpStatusText;
00082
00083
00084 bool m_transfer_encoding_chunked;
00085 long long m_current_chunk_offset;
00086 long long m_current_chunk_size;
00087
00088 int parseContentRange(char *);
00089 int parseHost(char *);
00090 int parseRWOp(char *);
00091
00092
00093 XrdHttpProtocol *prot;
00094
00095 void clientMarshallReadAheadList(int nitems);
00096 void clientUnMarshallReadAheadList(int nitems);
00097
00098
00099 void getfhandle();
00100
00101
00102
00103 int PostProcessChecksum(std::string &digest_header);
00104
00110 int PostProcessHTTPReq(bool final = false);
00111
00112
00113 void parseResource(char *url);
00114
00115 void mapXrdErrorToHttpStatus();
00116 public:
00117
00118 XrdHttpReq(XrdHttpProtocol *protinstance) : keepalive(true) {
00119
00120 prot = protinstance;
00121 length = 0;
00122
00123 depth = 0;
00124 ralist = 0;
00125 opaque = 0;
00126 writtenbytes = 0;
00127 fopened = false;
00128 headerok = false;
00129 };
00130
00131 virtual ~XrdHttpReq();
00132
00133 virtual void reset();
00134
00136 int parseLine(char *line, int len);
00137
00139 int parseFirstLine(char *line, int len);
00140
00142 int parseBody(char *body, long long len);
00143
00145 int ReqReadV();
00146 readahead_list *ralist;
00147
00149 std::string buildPartialHdr(long long bytestart, long long byteend, long long filesize, char *token);
00150
00152 std::string buildPartialHdrEnd(char *token);
00153
00154
00155
00156 void appendOpaque(XrdOucString &s, XrdSecEntity *secent, char *hash, time_t tnow);
00157
00158
00159
00160
00161
00162
00164
00165 enum ReqType {
00166 rtUnset = -1,
00167 rtUnknown = 0,
00168 rtMalformed,
00169 rtGET,
00170 rtHEAD,
00171 rtPUT,
00172 rtOPTIONS,
00173 rtPATCH,
00174 rtDELETE,
00175 rtPROPFIND,
00176 rtMKCOL,
00177 rtMOVE,
00178 rtPOST
00179 };
00180
00182 ReqType request;
00183 std::string requestverb;
00184
00185
00186
00187 std::map<std::string, std::string> allheaders;
00188
00190 XrdOucString resource;
00192 XrdOucEnv *opaque;
00194 XrdOucString resourceplusopaque;
00195
00196
00198 bool headerok;
00199
00200
00201
00203 std::vector<ReadWriteOp> rwOps;
00206 std::vector<ReadWriteOp> rwOps_split;
00207
00208 bool keepalive;
00209 long long length;
00210 int depth;
00211 bool sendcontinue;
00212
00214 std::string host;
00216 std::string destination;
00217
00219 std::string m_req_digest;
00223 XrdOucString m_resource_with_digest;
00225 std::string m_digest_header;
00226
00228 std::string hdr2cgistr;
00229 bool m_appended_hdr2cgistr;
00230
00231
00232
00233
00234
00235
00237 unsigned int rwOpDone, rwOpPartialDone;
00238
00240 ClientRequest xrdreq;
00241
00243 XResponseType xrdresp;
00244 XErrorCode xrderrcode;
00245 std::string etext;
00246 XrdOucString redirdest;
00247
00249 const struct iovec *iovP;
00250 int iovN;
00251 int iovL;
00252 bool final;
00253
00254
00255 long long filesize;
00256 long fileflags;
00257 long filemodtime;
00258 char fhandle[4];
00259 bool fopened;
00260
00262 std::string stringresp;
00263
00265 int reqstate;
00266
00268 long long writtenbytes;
00269
00270
00271
00272
00273
00279 int ProcessHTTPReq();
00280
00281
00282
00283
00284
00285
00286
00312
00313
00314 virtual bool Data(XrdXrootd::Bridge::Context &info,
00315 const
00316 struct iovec *iovP,
00317 int iovN,
00318 int iovL,
00319 bool final
00320 );
00321
00322
00332
00333
00334 virtual bool Done(XrdXrootd::Bridge::Context &info);
00335
00336
00337
00350
00351
00352 virtual bool Error(XrdXrootd::Bridge::Context &info,
00353 int ecode,
00354 const char *etext
00355 );
00356
00357
00370
00371
00372 virtual int File(XrdXrootd::Bridge::Context &info,
00373 int dlen
00374 );
00375
00376
00389
00390
00391 virtual bool Redir(XrdXrootd::Bridge::Context &info,
00392 int port,
00393 const char *hname
00394 );
00395
00396
00397
00398
00399
00400 };
00401
00402
00403
00404 void trim(std::string &str);
00405
00406 #endif
00407