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 "Xrd/XrdObject.hh"
00045 #include "XrdXrootd/XrdXrootdBridge.hh"
00046 #include "XrdOuc/XrdOucStream.hh"
00047 #include "Xrd/XrdProtocol.hh"
00048 #include "XrdOuc/XrdOucHash.hh"
00049
00050 #include <openssl/ssl.h>
00051
00052 #include <vector>
00053
00054 #include "XrdHttpReq.hh"
00055
00056
00057
00058
00059
00060
00061 #ifndef __GNUC__
00062 #define __attribute__(x)
00063 #endif
00064
00065 class XrdOucTokenizer;
00066 class XrdOucTrace;
00067 class XrdBuffer;
00068 class XrdLink;
00069 class XrdXrootdProtocol;
00070 class XrdHttpSecXtractor;
00071 class XrdHttpExtHandler;
00072 struct XrdVersionInfo;
00073 class XrdOucGMap;
00074
00075 class XrdHttpProtocol : public XrdProtocol {
00076
00077 friend class XrdHttpReq;
00078 friend class XrdHttpExtReq;
00079
00080 public:
00081
00083 static int Configure(char *parms, XrdProtocol_Config *pi);
00084
00086 void DoIt() {
00087 if (Resume) (*this.*Resume)();
00088 }
00089
00091 XrdProtocol *Match(XrdLink *lp);
00092
00094 int Process(XrdLink *lp);
00095
00096
00098 void Recycle(XrdLink *lp, int consec, const char *reason);
00099
00101 int Stats(char *buff, int blen, int do_sync = 0);
00102
00103
00104
00105
00107 int doStat(char *fname);
00108
00110 int doChksum(const XrdOucString &fname);
00111
00113 XrdHttpProtocol(const XrdHttpProtocol&) = default;
00114 XrdHttpProtocol operator =(const XrdHttpProtocol &rhs);
00115 XrdHttpProtocol(bool imhttps);
00116 ~XrdHttpProtocol() {
00117 Cleanup();
00118 }
00119
00120 static XrdObjectQ<XrdHttpProtocol> ProtStack;
00121 XrdObject<XrdHttpProtocol> ProtLink;
00122
00123
00125 XrdSecEntity SecEntity;
00126
00128 bool isHTTPS() { return ishttps; }
00129
00130 private:
00131
00132
00134 int (XrdHttpProtocol::*Resume)();
00135
00137 static bool InitTLS();
00138
00140 static bool InitSecurity();
00141
00143 int StartSimpleResp(int code, const char *desc, const char *header_to_add, long long bodylen, bool keepalive);
00144
00146 int SendData(const char *body, int bodylen);
00147
00149 void Cleanup();
00150
00152 void Reset();
00153
00156 int GetVOMSData(XrdLink *lp);
00157
00160 int getDataOneShot(int blen, bool wait=false);
00161
00163 static BIO *CreateBIO(XrdLink *lp);
00164
00166 static int Config(const char *fn, XrdOucEnv *myEnv);
00167 static const char *Configed();
00168 static int xtrace(XrdOucStream &Config);
00169 static int xsslcert(XrdOucStream &Config);
00170 static int xsslkey(XrdOucStream &Config);
00171 static int xsecxtractor(XrdOucStream &Config);
00172 static int xexthandler(XrdOucStream & Config, const char *ConfigFN, XrdOucEnv *myEnv);
00173 static int xsslcadir(XrdOucStream &Config);
00174 static int xsslcipherfilter(XrdOucStream &Config);
00175 static int xdesthttps(XrdOucStream &Config);
00176 static int xlistdeny(XrdOucStream &Config);
00177 static int xlistredir(XrdOucStream &Config);
00178 static int xselfhttps2http(XrdOucStream &Config);
00179 static int xembeddedstatic(XrdOucStream &Config);
00180 static int xstaticredir(XrdOucStream &Config);
00181 static int xstaticpreload(XrdOucStream &Config);
00182 static int xgmap(XrdOucStream &Config);
00183 static int xsslcafile(XrdOucStream &Config);
00184 static int xsslverifydepth(XrdOucStream &Config);
00185 static int xsecretkey(XrdOucStream &Config);
00186 static int xheader2cgi(XrdOucStream &Config);
00187 static int xhttpsmode(XrdOucStream &Config);
00188
00189 static XrdHttpSecXtractor *secxtractor;
00190
00191
00192 static int LoadSecXtractor(XrdSysError *eDest, const char *libName,
00193 const char *libParms);
00194
00195
00196 #define MAX_XRDHTTPEXTHANDLERS 4
00197 static struct XrdHttpExtHandlerInfo {
00198 char name[16];
00199 XrdHttpExtHandler *ptr;
00200 } exthandler[MAX_XRDHTTPEXTHANDLERS];
00201 static int exthandlercnt;
00202
00203
00204 static int LoadExtHandler(XrdSysError *eDest, const char *libName,
00205 const char *configFN, const char *libParms,
00206 XrdOucEnv *myEnv, const char *instName);
00207
00208
00209
00210
00211
00212 static XrdHttpExtHandler *FindMatchingExtHandler(const XrdHttpReq &);
00213
00214
00215 static bool ExtHandlerLoaded(const char *handlername);
00216
00218 XrdBuffer *myBuff;
00220 char *myBuffStart, *myBuffEnd;
00221
00223 XrdOucString tmpline;
00224
00226 int BuffAvailable();
00228 int BuffUsed();
00230 int BuffFree();
00231
00233 void BuffConsume(int blen);
00235 int BuffgetData(int blen, char **data, bool wait);
00237 int BuffgetLine(XrdOucString &dest);
00238
00240 int SendSimpleResp(int code, const char *desc, const char *header_to_add, const char *body, long long bodylen, bool keepalive);
00241
00243
00244 int StartChunkedResp(int code, const char *desc, const char *header_to_add, bool keepalive);
00245
00247
00248 int ChunkResp(const char *body, long long bodylen);
00249
00251 char *GetClientIPStr();
00252
00254 bool DoingLogin;
00255
00257 long ResumeBytes;
00258
00260 SSL *ssl;
00261
00263 BIO *sbio;
00264
00266 static BIO *sslbio_err;
00267
00269 bool ishttps;
00270
00273 bool ssldone;
00274
00275
00276 protected:
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295 static XrdScheduler *Sched;
00296 static XrdBuffManager *BPool;
00297 static XrdSysError eDest;
00298 static XrdSecService *CIA;
00299
00301 XrdLink *Link;
00302
00305 char *Addr_str;
00306
00308 static XrdOucGMap *servGMap;
00309
00311 XrdXrootd::Bridge *Bridge;
00312
00313
00316 XrdHttpReq CurrentReq;
00317
00318
00319
00320
00321
00322
00324 static int hailWait;
00325
00327 static int readWait;
00328
00330 static int Port;
00331
00333 static char * Port_str;
00334
00336 static char *sslcert, *sslkey, *sslcadir, *sslcafile, *sslcipherfilter;
00337
00339 static char *gridmap;
00340
00342 static char *secretkey;
00343
00345 static int sslverifydepth;
00346
00348 static bool isdesthttps;
00349
00351 static char *listredir;
00352
00354 static bool listdeny;
00355
00357 static bool selfhttps2http;
00358
00360 static bool embeddedstatic;
00361
00362
00363 static char *staticredir;
00364
00365
00366 struct StaticPreloadInfo {
00367 char *data;
00368 int len;
00369 };
00370 static XrdOucHash<StaticPreloadInfo> *staticpreload;
00371
00373 static kXR_int32 myRole;
00374
00376 static std::map< std::string, std::string > hdr2cgimap;
00377
00379 static int m_bio_type;
00380
00382 static BIO_METHOD *m_bio_method;
00383 };
00384 #endif