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
00132 static void PeriodicUpdate();
00133
00134 private:
00135
00136
00138 int (XrdHttpProtocol::*Resume)();
00139
00141 static int InitSecurity();
00142
00144 static X509_STORE *PrepareStore();
00145
00147 int StartSimpleResp(int code, const char *desc, const char *header_to_add, long long bodylen, bool keepalive);
00148
00150 int SendData(const char *body, int bodylen);
00151
00153 void Cleanup();
00154
00156 void Reset();
00157
00160 int GetVOMSData(XrdLink *lp);
00161
00164 int getDataOneShot(int blen, bool wait=false);
00165
00167 static BIO *CreateBIO(XrdLink *lp);
00168
00170 static int Config(const char *fn, XrdOucEnv *myEnv);
00171 static int xtrace(XrdOucStream &Config);
00172 static int xsslcert(XrdOucStream &Config);
00173 static int xsslkey(XrdOucStream &Config);
00174 static int xsecxtractor(XrdOucStream &Config);
00175 static int xexthandler(XrdOucStream & Config, const char *ConfigFN, XrdOucEnv *myEnv);
00176 static int xsslcadir(XrdOucStream &Config);
00177 static int xsslcipherfilter(XrdOucStream &Config);
00178 static int xdesthttps(XrdOucStream &Config);
00179 static int xlistdeny(XrdOucStream &Config);
00180 static int xlistredir(XrdOucStream &Config);
00181 static int xselfhttps2http(XrdOucStream &Config);
00182 static int xembeddedstatic(XrdOucStream &Config);
00183 static int xstaticredir(XrdOucStream &Config);
00184 static int xstaticpreload(XrdOucStream &Config);
00185 static int xgmap(XrdOucStream &Config);
00186 static int xsslcafile(XrdOucStream &Config);
00187 static int xsslverifydepth(XrdOucStream &Config);
00188 static int xsecretkey(XrdOucStream &Config);
00189 static int xheader2cgi(XrdOucStream &Config);
00190
00191 static XrdHttpSecXtractor *secxtractor;
00192
00193
00194 static int LoadSecXtractor(XrdSysError *eDest, const char *libName,
00195 const char *libParms);
00196
00197
00198 #define MAX_XRDHTTPEXTHANDLERS 4
00199 static struct XrdHttpExtHandlerInfo {
00200 char name[16];
00201 XrdHttpExtHandler *ptr;
00202 } exthandler[MAX_XRDHTTPEXTHANDLERS];
00203 static int exthandlercnt;
00204
00205
00206 static int LoadExtHandler(XrdSysError *eDest, const char *libName,
00207 const char *configFN, const char *libParms,
00208 XrdOucEnv *myEnv, const char *instName);
00209
00210
00211
00212
00213
00214 static XrdHttpExtHandler *FindMatchingExtHandler(const XrdHttpReq &);
00215
00216
00217 static bool ExtHandlerLoaded(const char *handlername);
00218
00220 XrdBuffer *myBuff;
00222 char *myBuffStart, *myBuffEnd;
00223
00225 XrdOucString tmpline;
00226
00228 int BuffAvailable();
00230 int BuffUsed();
00232 int BuffFree();
00233
00235 void BuffConsume(int blen);
00237 int BuffgetData(int blen, char **data, bool wait);
00239 int BuffgetLine(XrdOucString &dest);
00240
00242 int SendSimpleResp(int code, const char *desc, const char *header_to_add, const char *body, long long bodylen, bool keepalive);
00243
00245
00246 int StartChunkedResp(int code, const char *desc, const char *header_to_add, bool keepalive);
00247
00249
00250 int ChunkResp(const char *body, long long bodylen);
00251
00253 char *GetClientIPStr();
00254
00256 bool DoingLogin;
00257
00259 long ResumeBytes;
00260
00262 static SSL_CTX *sslctx;
00263
00265 static X509_STORE *verify_store;
00266 static XrdSysRWLock x509_store_lock;
00267
00269 SSL *ssl;
00270
00272 BIO *sbio;
00273
00275 static BIO *sslbio_err;
00276
00278 bool ishttps;
00279
00282 bool ssldone;
00283
00284 static XrdCryptoFactory *myCryptoFactory;
00285 protected:
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306 static XrdScheduler *Sched;
00307 static XrdBuffManager *BPool;
00308 static XrdSysError eDest;
00309 static XrdSecService *CIA;
00310
00312 XrdLink *Link;
00313
00316 char *Addr_str;
00317
00319 static XrdOucGMap *servGMap;
00320
00322 XrdXrootd::Bridge *Bridge;
00323
00324
00327 XrdHttpReq CurrentReq;
00328
00329
00330
00331
00332
00333
00335 static int hailWait;
00336
00338 static int readWait;
00339
00341 static int Port;
00342
00344 static char * Port_str;
00345
00347 static int Window;
00348
00350 static char *sslcert, *sslkey, *sslcadir, *sslcafile, *sslcipherfilter;
00351
00353 static char *gridmap;
00354
00356 static char *secretkey;
00357
00359 static int sslverifydepth;
00360
00362 static bool isdesthttps;
00363
00365 static char *listredir;
00366
00368 static bool listdeny;
00369
00371 static bool selfhttps2http;
00372
00374 static bool embeddedstatic;
00375
00376
00377 static char *staticredir;
00378
00379
00380 struct StaticPreloadInfo {
00381 char *data;
00382 int len;
00383 };
00384 static XrdOucHash<StaticPreloadInfo> *staticpreload;
00385
00387 static kXR_int32 myRole;
00388
00390 static std::map< std::string, std::string > hdr2cgimap;
00391
00393 static int m_bio_type;
00394
00396 static BIO_METHOD *m_bio_method;
00397 };
00398 #endif