XRootD
TPC::TPCHandler Class Reference

#include <XrdHttpTpcTPC.hh>

+ Inheritance diagram for TPC::TPCHandler:
+ Collaboration diagram for TPC::TPCHandler:

Public Member Functions

 TPCHandler (XrdSysError *log, const char *config, XrdOucEnv *myEnv)
 
virtual ~TPCHandler ()
 
virtual int Init (const char *cfgfile)
 Initializes the external request handler. More...
 
virtual bool MatchesPath (const char *verb, const char *path)
 Tells if the incoming path is recognized as one of the paths that have to be processed. More...
 
virtual int ProcessReq (XrdHttpExtReq &req)
 
- Public Member Functions inherited from XrdHttpExtHandler
 XrdHttpExtHandler ()
 Constructor. More...
 
virtual ~XrdHttpExtHandler ()
 Destructor. More...
 

Static Public Attributes

static constexpr std::string_view OSS_TASK_OPAQUE = "oss.task=httptpc"
 

Detailed Description

Definition at line 48 of file XrdHttpTpcTPC.hh.

Constructor & Destructor Documentation

◆ TPCHandler()

TPCHandler::TPCHandler ( XrdSysError *  log,
const char *  config,
XrdOucEnv *  myEnv 
)

Definition at line 453 of file XrdHttpTpcTPC.cc.

453  :
454  m_allow_local(false),
455  m_allow_private(true),
456  m_desthttps(false),
457  m_fixed_route(false),
458  m_low_speed_limit(10*1024),
459  m_low_speed_time(2*60),
460  m_timeout(60),
461  m_first_timeout(120),
462  m_log(log->logger(), "TPC_"),
463  m_sfs(NULL)
464 {
465  if (!Configure(config, myEnv)) {
466  throw std::runtime_error("Failed to configure the HTTP third-party-copy handler.");
467  }
468 
469 // Extract out the TPC monitoring object (we share it with xrootd).
470 //
471  XrdXrootdGStream *gs = (XrdXrootdGStream*)myEnv->GetPtr("Tpc.gStream*");
472  if (gs)
473  TPCLogRecord::tpcMonitor = new XrdXrootdTpcMon("http",log->logger(),*gs);
474 }
void * GetPtr(const char *varname)
Definition: XrdOucEnv.cc:281
XrdSysLogger * logger(XrdSysLogger *lp=0)
Definition: XrdSysError.hh:175

References XrdOucEnv::GetPtr(), and XrdSysError::logger().

+ Here is the call graph for this function:

◆ ~TPCHandler()

TPCHandler::~TPCHandler ( )
virtual

Definition at line 445 of file XrdHttpTpcTPC.cc.

445  {
446  m_sfs = NULL;
447 }

Member Function Documentation

◆ Init()

virtual int TPC::TPCHandler::Init ( const char *  cfgfile)
inlinevirtual

Initializes the external request handler.

Implements XrdHttpExtHandler.

Definition at line 56 of file XrdHttpTpcTPC.hh.

56 {return 0;}

◆ MatchesPath()

bool TPCHandler::MatchesPath ( const char *  verb,
const char *  path 
)
virtual

Tells if the incoming path is recognized as one of the paths that have to be processed.

Implements XrdHttpExtHandler.

Definition at line 364 of file XrdHttpTpcTPC.cc.

364  {
365  return !strcmp(verb, "COPY") || !strcmp(verb, "OPTIONS");
366 }

◆ ProcessReq()

int TPCHandler::ProcessReq ( XrdHttpExtReq &  )
virtual

Process an HTTP request and send the response using the calling XrdHttpProtocol instance directly Returns 0 if ok, non0 if errors

Implements XrdHttpExtHandler.

Definition at line 398 of file XrdHttpTpcTPC.cc.

398  {
399  if (req.verb == "OPTIONS") {
400  return ProcessOptionsReq(req);
401  }
402  auto header = XrdOucTUtils::caseInsensitiveFind(req.headers,"credential");
403  if (header != req.headers.end()) {
404  if (header->second != "none") {
405  m_log.Emsg("ProcessReq", "COPY requested an unsupported credential type: ", header->second.c_str());
406  return req.SendSimpleResp(400, NULL, NULL, "COPY requestd an unsupported Credential type", 0);
407  }
408  }
409  auto srcHeader = XrdOucTUtils::caseInsensitiveFind(req.headers,"source");
410  auto dstHeader = XrdOucTUtils::caseInsensitiveFind(req.headers,"destination");
411  // A Source header asks for a pull, a Destination header for a push; asking
412  // for both at once is ambiguous, so the request is rejected instead of
413  // arbitrarily honouring one of the two.
414  if (srcHeader != req.headers.end() && dstHeader != req.headers.end()) {
415  const char *error_both = "COPY rejected: both a Source and a Destination header were specified";
416  m_log.Emsg("ProcessReq", error_both);
417  return req.SendSimpleResp(400, NULL, NULL, error_both, 0);
418  }
419  if (srcHeader != req.headers.end()) {
420  std::string src = PrepareURL(srcHeader->second);
421  if (!IsAllowedScheme(src)) {
422  const char *error_src = "COPY rejected: disallowed scheme in source URL";
423  m_log.Emsg("ProcessReq", error_src, src.c_str());
424  return req.SendSimpleResp(400, NULL, NULL, error_src, 0);
425  }
426  return ProcessPullReq(src, req);
427  }
428  if (dstHeader != req.headers.end()) {
429  const std::string& dst = dstHeader->second;
430  if (!IsAllowedScheme(dst)) {
431  const char *error_dst = "COPY rejected: disallowed scheme in destination URL";
432  m_log.Emsg("ProcessReq", error_dst, dst.c_str());
433  return req.SendSimpleResp(400, NULL, NULL, error_dst, 0);
434  }
435  return ProcessPushReq(dst, req);
436  }
437  m_log.Emsg("ProcessReq", "COPY verb requested but no source or destination specified.");
438  return req.SendSimpleResp(400, NULL, NULL, "No Source or Destination specified", 0);
439 }
static std::string PrepareURL(const std::string &url)
static bool IsAllowedScheme(const std::string &url)
static std::map< std::string, T >::const_iterator caseInsensitiveFind(const std::map< std::string, T > &m, const std::string &lowerCaseSearchKey)
Definition: XrdOucTUtils.hh:79
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.cc:116

References XrdOucTUtils::caseInsensitiveFind(), XrdSysError::Emsg(), XrdHttpExtReq::headers, IsAllowedScheme(), PrepareURL(), XrdHttpExtReq::SendSimpleResp(), and XrdHttpExtReq::verb.

+ Here is the call graph for this function:

Member Data Documentation

◆ OSS_TASK_OPAQUE

constexpr std::string_view TPC::TPCHandler::OSS_TASK_OPAQUE = "oss.task=httptpc"
staticconstexpr

Definition at line 57 of file XrdHttpTpcTPC.hh.

Referenced by XrdHttpTpcUtils::prepareOpenURL().


The documentation for this class was generated from the following files: