00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __XRDHTTP_PROTOCOL_H__
00025 #define __XRDHTTP_PROTOCOL_H__
00026
00037 #include <stdlib.h>
00038 #include <unistd.h>
00039 #include <sys/types.h>
00040
00041 #include "XrdSys/XrdSysError.hh"
00042 #include "XrdSys/XrdSysPthread.hh"
00043 #include "XrdSec/XrdSecInterface.hh"
00044 #include "XrdCrypto/XrdCryptoFactory.hh"
00045 #include "Xrd/XrdObject.hh"
00046 #include "XrdXrootd/XrdXrootdBridge.hh"
00047 #include "XrdOuc/XrdOucStream.hh"
00048 #include "Xrd/XrdProtocol.hh"
00049 #include "XrdOuc/XrdOucHash.hh"
00050
00051 #include <openssl/ssl.h>
00052
00053 #include <vector>
00054
00055 #include "XrdHttpReq.hh"
00056
00057
00058
00059
00060
00061
00062 #ifndef __GNUC__
00063 #define __attribute__(x)
00064 #endif
00065
00066 class XrdOucTokenizer;
00067 class XrdOucTrace;
00068 class XrdBuffer;
00069 class XrdLink;
00070 class XrdXrootdProtocol;
00071 class XrdHttpSecXtractor;
00072 class XrdHttpExtHandler;
00073 struct XrdVersionInfo;
00074 class XrdOucGMap;
00075
00076 class XrdHttpProtocol : public XrdProtocol {
00077
00078 friend class XrdHttpReq;
00079 friend class XrdHttpExtReq;
00080
00081 public:
00082
00084 static int Configure(char *parms, XrdProtocol_Config *pi);
00085
00087 void DoIt() {
00088 if (Resume) (*this.*Resume)();
00089 }
00090
00092 XrdProtocol *Match(XrdLink *lp);
00093
00095 int Process(XrdLink *lp);
00096
00097
00099 void Recycle(XrdLink *lp, int consec, const char *reason);
00100
00102 int Stats(char *buff, int blen, int do_sync = 0);
00103
00104
00105
00106
00108 int doStat(char *fname);
00109
00111 int doChksum(const XrdOucString &fname);
00112
00114 XrdHttpProtocol(const XrdHttpProtocol&) = default;
00115 XrdHttpProtocol operator =(const XrdHttpProtocol &rhs);
00116 XrdHttpProtocol(bool imhttps);
00117 ~XrdHttpProtocol() {
00118 Cleanup();
00119 }
00120
00121 static XrdObjectQ<XrdHttpProtocol> ProtStack;
00122 XrdObject<XrdHttpProtocol> ProtLink;
00123
00124
00126 XrdSecEntity SecEntity;
00127
00129 bool isHTTPS() { return ishttps; }
00130
00131 private:
00132
00133
00135 int (XrdHttpProtocol::*Resume)();
00136
00138 static int InitSecurity();
00139
00141 int StartSimpleResp(int code, const char *desc, const char *header_to_add, long long bodylen, bool keepalive);
00142
00144 int SendData(const char *body, int bodylen);
00145
00147 void Cleanup();
00148
00150 void Reset();
00151
00154 int GetVOMSData(XrdLink *lp);
00155
00158 int getDataOneShot(int blen, bool wait=false);
00159
00161 static BIO *CreateBIO(XrdLink *lp);
00162
00164 static int Config(const char *fn, XrdOucEnv *myEnv);
00165 static int xtrace(XrdOucStream &Config);
00166 static int xsslcert(XrdOucStream &Config);
00167 static int xsslkey(XrdOucStream &Config);
00168 static int xsecxtractor(XrdOucStream &Config);
00169 static int xexthandler(XrdOucStream & Config, const char *ConfigFN, XrdOucEnv *myEnv);
00170 static int xsslcadir(XrdOucStream &Config);
00171 static int xsslcipherfilter(XrdOucStream &Config);
00172 static int xdesthttps(XrdOucStream &Config);
00173 static int xlistdeny(XrdOucStream &Config);
00174 static int xlistredir(XrdOucStream &Config);
00175 static int xselfhttps2http(XrdOucStream &Config);
00176 static int xembeddedstatic(XrdOucStream &Config);
00177 static int xstaticredir(XrdOucStream &Config);
00178 static int xstaticpreload(XrdOucStream &Config);
00179 static int xgmap(XrdOucStream &Config);
00180 static int xsslcafile(XrdOucStream &Config);
00181 static int xsslverifydepth(XrdOucStream &Config);
00182 static int xsecretkey(XrdOucStream &Config);
00183 static int xheader2cgi(XrdOucStream &Config);
00184
00185 static XrdHttpSecXtractor *secxtractor;
00186
00187
00188 static int LoadSecXtractor(XrdSysError *eDest, const char *libName,
00189 const char *libParms);
00190
00191
00192 #define MAX_XRDHTTPEXTHANDLERS 4
00193 static struct XrdHttpExtHandlerInfo {
00194 char name[16];
00195 XrdHttpExtHandler *ptr;
00196 } exthandler[MAX_XRDHTTPEXTHANDLERS];
00197 static int exthandlercnt;
00198
00199
00200 static int LoadExtHandler(XrdSysError *eDest, const char *libName,
00201 const char *configFN, const char *libParms,
00202 XrdOucEnv *myEnv, const char *instName);
00203
00204
00205
00206
00207
00208 static XrdHttpExtHandler *FindMatchingExtHandler(const XrdHttpReq &);
00209
00210
00211 static bool ExtHandlerLoaded(const char *handlername);
00212
00214 XrdBuffer *myBuff;
00216 char *myBuffStart, *myBuffEnd;
00217
00219 XrdOucString tmpline;
00220
00222 int BuffAvailable();
00224 int BuffUsed();
00226 int BuffFree();
00227
00229 void BuffConsume(int blen);
00231 int BuffgetData(int blen, char **data, bool wait);
00233 int BuffgetLine(XrdOucString &dest);
00234
00236 int SendSimpleResp(int code, const char *desc, const char *header_to_add, const char *body, long long bodylen, bool keepalive);
00237
00239
00240 int StartChunkedResp(int code, const char *desc, const char *header_to_add, bool keepalive);
00241
00243
00244 int ChunkResp(const char *body, long long bodylen);
00245
00247 char *GetClientIPStr();
00248
00250 bool DoingLogin;
00251
00253 long ResumeBytes;
00254
00256 static SSL_CTX *sslctx;
00257
00259 SSL *ssl;
00260
00262 BIO *sbio;
00263
00265 static BIO *sslbio_err;
00266
00268 bool ishttps;
00269
00272 bool ssldone;
00273
00274 static XrdCryptoFactory *myCryptoFactory;
00275 protected:
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296 static XrdScheduler *Sched;
00297 static XrdBuffManager *BPool;
00298 static XrdSysError eDest;
00299 static XrdSecService *CIA;
00300
00302 XrdLink *Link;
00303
00306 char *Addr_str;
00307
00309 static XrdOucGMap *servGMap;
00310
00312 XrdXrootd::Bridge *Bridge;
00313
00314
00317 XrdHttpReq CurrentReq;
00318
00319
00320
00321
00322
00323
00325 static int hailWait;
00326
00328 static int readWait;
00329
00331 static int Port;
00332
00334 static char * Port_str;
00335
00337 static int Window;
00338
00340 static char *sslcert, *sslkey, *sslcadir, *sslcafile, *sslcipherfilter;
00341
00343 static char *gridmap;
00344
00346 static char *secretkey;
00347
00349 static int sslverifydepth;
00350
00352 static bool isdesthttps;
00353
00355 static char *listredir;
00356
00358 static bool listdeny;
00359
00361 static bool selfhttps2http;
00362
00364 static bool embeddedstatic;
00365
00366
00367 static char *staticredir;
00368
00369
00370 struct StaticPreloadInfo {
00371 char *data;
00372 int len;
00373 };
00374 static XrdOucHash<StaticPreloadInfo> *staticpreload;
00375
00377 static kXR_int32 myRole;
00378
00380 static std::map< std::string, std::string > hdr2cgimap;
00381
00383 static int m_bio_type;
00384
00386 static BIO_METHOD *m_bio_method;
00387 };
00388 #endif