Skip to content

Commit

Permalink
Getting Brian's proposal, preparing for a few little changes
Browse files Browse the repository at this point in the history
Merge branch 'multiple_external_handlers' of https://github.com/bbockelm/xrootd into bbockelm-multiple_external_handlers
  • Loading branch information
ffurano committed Oct 13, 2017
2 parents 01db447 + 92fe3c0 commit 12b18e0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
26 changes: 19 additions & 7 deletions src/XrdHttp/XrdHttpProtocol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ SSL_CTX *XrdHttpProtocol::sslctx = 0;
BIO *XrdHttpProtocol::sslbio_err = 0;
XrdCryptoFactory *XrdHttpProtocol::myCryptoFactory = 0;
XrdHttpSecXtractor *XrdHttpProtocol::secxtractor = 0;
XrdHttpExtHandler *XrdHttpProtocol::exthandler = 0;
std::vector<XrdHttpExtHandler *> XrdHttpProtocol::exthandler;
std::map< std::string, std::string > XrdHttpProtocol::hdr2cgimap;

static const unsigned char *s_server_session_id_context = (const unsigned char *) "XrdHTTPSessionCtx";
Expand Down Expand Up @@ -739,7 +739,7 @@ int XrdHttpProtocol::Process(XrdLink *lp) // We ignore the argument here
// Now we have everything that is needed to try the login
// Remember that if there is an exthandler then it has the responsibility
// for authorization in the paths that it manages
if (!exthandler || !exthandler->MatchesPath(CurrentReq.requestverb.c_str(), CurrentReq.resource.c_str())) {
if (FindMatchingExtHandler(CurrentReq)) {
if (!Bridge) {
if (SecEntity.name)
Bridge = XrdXrootd::Bridge::Login(&CurrentReq, Link, &SecEntity, SecEntity.name, "XrdHttp");
Expand Down Expand Up @@ -2437,20 +2437,32 @@ int XrdHttpProtocol::LoadExtHandler(XrdSysError *myeDest, const char *libName,
const char *configFN, const char *libParms,
XrdOucEnv *myEnv) {

// We don't want to load it more than once
if (exthandler) return 1;

XrdVersionInfo *myVer = &XrdVERSIONINFOVAR(XrdgetProtocol);
XrdOucPinLoader myLib(myeDest, myVer, "exthandlerlib", libName);
XrdHttpExtHandler *(*ep)(XrdHttpExtHandlerArgs);

// Get the entry point of the object creator
//
ep = (XrdHttpExtHandler *(*)(XrdHttpExtHandlerArgs))(myLib.Resolve("XrdHttpGetExtHandler"));
if (ep && (exthandler = ep(myeDest, configFN, libParms, myEnv))) return 0;

XrdHttpExtHandler *newhandler;
if (ep && (newhandler = ep(myeDest, configFN, libParms, myEnv))) {
exthandler.push_back(newhandler);
return 0;
}

myLib.Unload();
return 1;
}



// Locates a matching external handler for a given request, if available
XrdHttpExtHandler * XrdHttpProtocol::FindMatchingExtHandler(const XrdHttpReq &req) {
std::vector<XrdHttpExtHandler *>::const_iterator it;
for (it = exthandler.begin(); it != exthandler.end(); it++) {
if ((*it)->MatchesPath(req.requestverb.c_str(), req.resource.c_str())) {
return *it;
}
}
return nullptr;
}
10 changes: 9 additions & 1 deletion src/XrdHttp/XrdHttpProtocol.hh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@

#include <openssl/ssl.h>

#include <vector>

#include "XrdHttpReq.hh"

/******************************************************************************/
Expand Down Expand Up @@ -170,7 +172,7 @@ private:
static int xheader2cgi(XrdOucStream &Config);

static XrdHttpSecXtractor *secxtractor;
static XrdHttpExtHandler *exthandler;
static std::vector<XrdHttpExtHandler *> exthandler;

// Loads the SecXtractor plugin, if available
static int LoadSecXtractor(XrdSysError *eDest, const char *libName,
Expand All @@ -181,6 +183,12 @@ private:
const char *configFN, const char *libParms,
XrdOucEnv *myEnv);

// Determines whether one of the loaded ExtHandlers are interested in
// handling a given request.
//
// Returns NULL if there is no matching handler.
static XrdHttpExtHandler *FindMatchingExtHandler(const XrdHttpReq &);

/// Circular Buffer used to read the request
XrdBuffer *myBuff;
/// The circular pointers
Expand Down
6 changes: 4 additions & 2 deletions src/XrdHttp/XrdHttpReq.cc
Original file line number Diff line number Diff line change
Expand Up @@ -776,9 +776,11 @@ int XrdHttpReq::ProcessHTTPReq() {


// Verify if we have an external handler for this request
if (prot->exthandler && prot->exthandler->MatchesPath(this->requestverb.c_str(), this->resource.c_str())) {

XrdHttpExtHandler *exthandler = prot->FindMatchingExtHandler(*this);
if (exthandler) {
XrdHttpExtReq xreq(this, prot);
int r = prot->exthandler->ProcessReq(xreq);
int r = exthandler->ProcessReq(xreq);
reset();
if (!r) return 1; // All went fine, response sent
if (r < 0) return -1; // There was a hard error... close the connection
Expand Down

0 comments on commit 12b18e0

Please sign in to comment.