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 int parseContentRange(char *);
00084 int parseHost(char *);
00085 int parseRWOp(char *);
00086
00087
00088 XrdHttpProtocol *prot;
00089
00090 void clientMarshallReadAheadList(int nitems);
00091 void clientUnMarshallReadAheadList(int nitems);
00092
00093
00094 void getfhandle();
00095
00101 int PostProcessHTTPReq(bool final = false);
00102
00103
00104 void parseResource(char *url);
00105
00106 void mapXrdErrorToHttpStatus();
00107 public:
00108
00109 XrdHttpReq(XrdHttpProtocol *protinstance) : keepalive(true) {
00110
00111 prot = protinstance;
00112 length = 0;
00113
00114 depth = 0;
00115 ralist = 0;
00116 opaque = 0;
00117 writtenbytes = 0;
00118 fopened = false;
00119 headerok = false;
00120 };
00121
00122 virtual ~XrdHttpReq();
00123
00124 virtual void reset();
00125
00127 int parseLine(char *line, int len);
00128
00130 int parseFirstLine(char *line, int len);
00131
00133 int parseBody(char *body, long long len);
00134
00136 int ReqReadV();
00137 readahead_list *ralist;
00138
00140 std::string buildPartialHdr(long long bytestart, long long byteend, long long filesize, char *token);
00141
00143 std::string buildPartialHdrEnd(char *token);
00144
00145
00146
00147 void appendOpaque(XrdOucString &s, XrdSecEntity *secent, char *hash, time_t tnow);
00148
00149
00150
00151
00152
00153
00155
00156 enum ReqType {
00157 rtUnset = -1,
00158 rtUnknown = 0,
00159 rtMalformed,
00160 rtGET,
00161 rtHEAD,
00162 rtPUT,
00163 rtOPTIONS,
00164 rtPATCH,
00165 rtDELETE,
00166 rtPROPFIND,
00167 rtMKCOL,
00168 rtMOVE,
00169 rtPOST
00170 };
00171
00173 ReqType request;
00174 std::string requestverb;
00175
00176
00177
00178 std::map<std::string, std::string> allheaders;
00179
00181 XrdOucString resource;
00183 XrdOucEnv *opaque;
00185 XrdOucString resourceplusopaque;
00186
00187
00189 bool headerok;
00190
00191
00192
00194 std::vector<ReadWriteOp> rwOps;
00197 std::vector<ReadWriteOp> rwOps_split;
00198
00199 bool keepalive;
00200 long long length;
00201 int depth;
00202 bool sendcontinue;
00203
00205 std::string host;
00207 std::string destination;
00208
00210 std::string m_req_digest;
00214 XrdOucString m_resource_with_digest;
00215
00217 std::string hdr2cgistr;
00218
00219
00220
00221
00222
00223
00225 unsigned int rwOpDone, rwOpPartialDone;
00226
00228 ClientRequest xrdreq;
00229
00231 XResponseType xrdresp;
00232 XErrorCode xrderrcode;
00233 std::string etext;
00234 XrdOucString redirdest;
00235
00237 const struct iovec *iovP;
00238 int iovN;
00239 int iovL;
00240 bool final;
00241
00242
00243 long long filesize;
00244 long fileflags;
00245 long filemodtime;
00246 char fhandle[4];
00247 bool fopened;
00248
00250 std::string stringresp;
00251
00253 int reqstate;
00254
00256 long long writtenbytes;
00257
00258
00259
00260
00261
00267 int ProcessHTTPReq();
00268
00269
00270
00271
00272
00273
00274
00300
00301
00302 virtual bool Data(XrdXrootd::Bridge::Context &info,
00303 const
00304 struct iovec *iovP,
00305 int iovN,
00306 int iovL,
00307 bool final
00308 );
00309
00310
00320
00321
00322 virtual bool Done(XrdXrootd::Bridge::Context &info);
00323
00324
00325
00338
00339
00340 virtual bool Error(XrdXrootd::Bridge::Context &info,
00341 int ecode,
00342 const char *etext
00343 );
00344
00345
00358
00359
00360 virtual int File(XrdXrootd::Bridge::Context &info,
00361 int dlen
00362 );
00363
00364
00377
00378
00379 virtual bool Redir(XrdXrootd::Bridge::Context &info,
00380 int port,
00381 const char *hname
00382 );
00383
00384
00385
00386
00387
00388 };
00389
00390
00391
00392 void trim(std::string &str);
00393
00394 #endif
00395