XRootD
XrdCl::URL Class Reference

URL representation. More...

#include <XrdClURL.hh>

+ Collaboration diagram for XrdCl::URL:

Public Types

typedef std::map< std::string, std::string > ParamsMap
 

Public Member Functions

 URL ()
 Default constructor. More...
 
 URL (const char *url)
 
 URL (const std::string &url)
 
void Clear ()
 Clear the url. More...
 
bool FromString (const std::string &url)
 Parse a string and fill the URL fields. More...
 
std::string GetChannelId () const
 
std::string GetHostId () const
 Get the host part of the URL (user:password@host:port) More...
 
const std::string & GetHostName () const
 Get the name of the target host. More...
 
std::string GetLocation () const
 Get location (protocol://host:port/path) More...
 
std::string GetLoginToken () const
 Get the login token if present in the opaque info. More...
 
std::string GetObfuscatedURL () const
 Get the URL with authz information obfuscated. More...
 
const ParamsMap & GetParams () const
 Get the URL params. More...
 
std::string GetParamsAsString () const
 Get the URL params as string. More...
 
std::string GetParamsAsString (bool filter) const
 Get the URL params as string. More...
 
const std::string & GetPassword () const
 Get the password. More...
 
const std::string & GetPath () const
 Get the path. More...
 
std::string GetPathWithFilteredParams () const
 Get the path with params, filteres out 'xrdcl.'. More...
 
std::string GetPathWithParams () const
 Get the path with params. More...
 
int GetPort () const
 Get the target port. More...
 
const std::string & GetProtocol () const
 Get the protocol. More...
 
std::string GetURL () const
 Get the URL. More...
 
const std::string & GetUserName () const
 Get the username. More...
 
bool IsLocalFile () const
 
bool IsMetalink () const
 Is it a URL to a metalink. More...
 
bool IsSecure () const
 Does the protocol indicate encryption. More...
 
bool IsTPC () const
 Is the URL used in TPC context. More...
 
bool IsValid () const
 Is the url valid. More...
 
void SetHostName (const std::string &hostName)
 Set the host name. More...
 
void SetHostPort (const std::string &hostName, int port)
 
void SetParam (const std::string &name, const std::string &value)
 Set a single param. More...
 
void SetParams (const ParamsMap &params)
 Set params. More...
 
void SetParams (const std::string &params)
 Set params. More...
 
void SetPassword (const std::string &password)
 Set the password. More...
 
void SetPath (const std::string &path)
 Set the path. More...
 
void SetPort (int port)
 
void SetProtocol (const std::string &protocol)
 Set protocol. More...
 
void SetUserName (const std::string &userName)
 Set the username. More...
 

Detailed Description

URL representation.

Definition at line 30 of file XrdClURL.hh.

Member Typedef Documentation

◆ ParamsMap

typedef std::map<std::string, std::string> XrdCl::URL::ParamsMap

Map of get params

Definition at line 33 of file XrdClURL.hh.

Constructor & Destructor Documentation

◆ URL() [1/3]

XrdCl::URL::URL ( )

Default constructor.

Definition at line 36 of file XrdClURL.cc.

36  :
37  pPort( 1094 )
38  {
39  }

◆ URL() [2/3]

XrdCl::URL::URL ( const std::string &  url)

Constructor

Parameters
urlan url in format: protocol://user:password@host:port/path?param1=x&param2=y

Definition at line 44 of file XrdClURL.cc.

44  :
45  pPort( 1094 )
46  {
47  FromString( url );
48  }
bool FromString(const std::string &url)
Parse a string and fill the URL fields.
Definition: XrdClURL.cc:59

References FromString().

+ Here is the call graph for this function:

◆ URL() [3/3]

XrdCl::URL::URL ( const char *  url)

Constructor

Parameters
urlan url in format: protocol://user:password@host:port/path?param1=x&param2=y

Definition at line 50 of file XrdClURL.cc.

50  : pPort( 1094 )
51  {
52  FromString( url );
53  }

References FromString().

+ Here is the call graph for this function:

Member Function Documentation

◆ Clear()

void XrdCl::URL::Clear ( )

Clear the url.

Definition at line 412 of file XrdClURL.cc.

413  {
414  pHostId.clear();
415  pProtocol.clear();
416  pUserName.clear();
417  pPassword.clear();
418  pHostName.clear();
419  pPort = 1094;
420  pPath.clear();
421  pParams.clear();
422  pURL.clear();
423  }

Referenced by FromString().

+ Here is the caller graph for this function:

◆ FromString()

bool XrdCl::URL::FromString ( const std::string &  url)

Parse a string and fill the URL fields.

Definition at line 59 of file XrdClURL.cc.

60  {
61  Log *log = DefaultEnv::GetLog();
62 
63  Clear();
64 
65  if( url.length() == 0 )
66  {
67  log->Error( UtilityMsg, "The given URL is empty" );
68  return false;
69  }
70 
71  //--------------------------------------------------------------------------
72  // Extract the protocol, assume file:// if none found
73  //--------------------------------------------------------------------------
74  size_t pos = url.find( "://" );
75 
76  std::string current;
77  if( pos != std::string::npos )
78  {
79  pProtocol = url.substr( 0, pos );
80  current = url.substr( pos+3 );
81  }
82  else if( url[0] == '/' )
83  {
84  pProtocol = "file";
85  current = url;
86  }
87  else if( url[0] == '-' )
88  {
89  pProtocol = "stdio";
90  current = "-";
91  pPort = 0;
92  }
93  else
94  {
95  pProtocol = "root";
96  current = url;
97  }
98 
99  //--------------------------------------------------------------------------
100  // If the protocol is HTTP(S) or DAV(S), change the default port number
101  //--------------------------------------------------------------------------
102  if (pProtocol == "http" || pProtocol == "dav") {
103  pPort = 80;
104  }
105  if (pProtocol == "https" || pProtocol == "davs") {
106  pPort = 443;
107  }
108 
109  //--------------------------------------------------------------------------
110  // Extract host info and path
111  //--------------------------------------------------------------------------
112  std::string path;
113  std::string hostInfo;
114 
115  if( pProtocol == "stdio" )
116  path = current;
117  else if( pProtocol == "file")
118  {
119  if( current[0] == '/' )
120  current = "localhost" + current;
121  pos = current.find( '/' );
122  if( pos == std::string::npos )
123  hostInfo = current;
124  else
125  {
126  hostInfo = current.substr( 0, pos );
127  path = current.substr( pos );
128  }
129  }
130  else
131  {
132  pos = current.find( '/' );
133  if( pos == std::string::npos )
134  hostInfo = current;
135  else
136  {
137  hostInfo = current.substr( 0, pos );
138  path = current.substr( pos+1 );
139  }
140  }
141 
142  if( !ParseHostInfo( hostInfo ) )
143  {
144  log->Warning( UtilityMsg, "Failed to parse host info: %s",
145  hostInfo.c_str() );
146  Clear();
147  return false;
148  }
149 
150  ParsePath( path );
151  ComputeURL();
152  return true;
153  }
static Log * GetLog()
Get default log.
void Clear()
Clear the url.
Definition: XrdClURL.cc:412
const uint64_t UtilityMsg
XrdSysError Log
Definition: XrdConfig.cc:113

References Clear(), XrdCl::Log::Error(), XrdCl::DefaultEnv::GetLog(), XrdCl::UtilityMsg, and XrdCl::Log::Warning().

Referenced by URL().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetChannelId()

std::string XrdCl::URL::GetChannelId ( ) const

Get the host part of the URL (user:password@host:port) plus channel specific CGI (xrdcl.identity & xrd.gsiusrpxy)

Definition at line 488 of file XrdClURL.cc.

489  {
490  std::string ret = pProtocol + "://" + pHostId + "/";
491  bool hascgi = false;
492 
493  std::string keys[] = { "xrdcl.intent",
494  "xrd.gsiusrpxy",
495  "xrd.gsiusrcrt",
496  "xrd.gsiusrkey",
497  "xrd.sss",
498  "xrd.k5ccname" };
499  size_t size = sizeof( keys ) / sizeof( std::string );
500 
501  for( size_t i = 0; i < size; ++i )
502  {
503  ParamsMap::const_iterator itr = pParams.find( keys[i] );
504  if( itr != pParams.end() )
505  {
506  ret += hascgi ? '&' : '?';
507  ret += itr->first;
508  ret += '=';
509  ret += itr->second;
510  hascgi = true;
511  }
512  }
513 
514  return ret;
515  }

Referenced by XrdCl::Channel::Channel(), XrdCl::XRootDChannelInfo::XRootDChannelInfo(), XrdCl::PostMaster::CollapseRedirect(), XrdCl::PostMaster::ForceDisconnect(), XrdCl::PostMaster::ForceReconnect(), XrdCl::PostMasterImpl::GetChannel(), XrdCl::SIDMgrPool::GetSIDMgr(), and XrdCl::PostMaster::QueryTransport().

+ Here is the caller graph for this function:

◆ GetHostId()

◆ GetHostName()

const std::string& XrdCl::URL::GetHostName ( ) const
inline

Get the name of the target host.

Definition at line 170 of file XrdClURL.hh.

171  {
172  return pHostName;
173  }

Referenced by XrdCl::Stream::CanCollapse(), XrdCl::AsyncSocketHandler::DoTlsHandShake(), XrdCl::Stream::EnableLink(), and XrdCl::Utils::GetHostAddresses().

+ Here is the caller graph for this function:

◆ GetLocation()

std::string XrdCl::URL::GetLocation ( ) const

Get location (protocol://host:port/path)

Get protocol://host:port/path.

Definition at line 320 of file XrdClURL.cc.

321  {
322  std::ostringstream o;
323  o << pProtocol << "://";
324  if( pProtocol == "file" )
325  o << pHostName;
326  else
327  o << pHostName << ":" << pPort << "/";
328  o << pPath;
329  return o.str();
330  }

Referenced by XrdCl::RedirectorRegistry::Get(), XrdCl::RedirectorRegistry::Release(), and XrdCl::RedirectEntry::ToString().

+ Here is the caller graph for this function:

◆ GetLoginToken()

std::string XrdCl::URL::GetLoginToken ( ) const

Get the login token if present in the opaque info.

Definition at line 343 of file XrdClURL.cc.

344  {
345  auto itr = pParams.find( "xrd.logintoken" );
346  if( itr == pParams.end() )
347  return "";
348  return itr->second;
349  }

Referenced by XrdCl::XRootDTransport::InitializeChannel().

+ Here is the caller graph for this function:

◆ GetObfuscatedURL()

std::string XrdCl::URL::GetObfuscatedURL ( ) const

Get the URL with authz information obfuscated.

Definition at line 474 of file XrdClURL.cc.

474  {
475  return obfuscateAuth(pURL);
476  }
std::string obfuscateAuth(const std::string &input)

References obfuscateAuth().

Referenced by XrdCl::FileSystem::FileSystem(), XrdCl::FileStateHandler::AfterForkChild(), DoTail(), XrdPosixAdmin::isOK(), XrdCl::FileStateHandler::OnClose(), XrdCl::FileStateHandler::OnOpen(), and XrdCl::FileStateHandler::TimeOutRequests().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetParams()

const ParamsMap& XrdCl::URL::GetParams ( ) const
inline

Get the URL params.

Definition at line 244 of file XrdClURL.hh.

245  {
246  return pParams;
247  }

Referenced by XrdCl::Channel::Channel(), XrdCl::Utils::CheckEC(), XrdCl::GetEcHandler(), XrdCl::Utils::GetIntParameter(), XrdCl::FileSystemUtils::GetSpaceInfo(), XrdCl::Utils::GetStringParameter(), XrdClHttp::InjectBearerToken(), XrdCl::FileStateHandler::OnOpen(), XrdCl::CopyProcess::Prepare(), XrdCl::XRootDMsgHandler::Process(), XrdCl::MessageUtils::RewriteCGIAndPath(), and XrdCl::ClassicCopyJob::Run().

+ Here is the caller graph for this function:

◆ GetParamsAsString() [1/2]

std::string XrdCl::URL::GetParamsAsString ( ) const

Get the URL params as string.

Definition at line 335 of file XrdClURL.cc.

336  {
337  return GetParamsAsString( false );
338  }
std::string GetParamsAsString() const
Get the URL params as string.
Definition: XrdClURL.cc:335

Referenced by GetPathWithFilteredParams(), and GetPathWithParams().

+ Here is the caller graph for this function:

◆ GetParamsAsString() [2/2]

std::string XrdCl::URL::GetParamsAsString ( bool  filter) const

Get the URL params as string.

Get the URL params as string

Parameters
filter: if set to true filters out 'xrdcl.'

Definition at line 354 of file XrdClURL.cc.

355  {
356  if( pParams.empty() )
357  return "";
358 
359  std::ostringstream o;
360  o << "?";
361  ParamsMap::const_iterator it;
362  for( it = pParams.begin(); it != pParams.end(); ++it )
363  {
364  // we filter out client specific parameters
365  if( filter && it->first.compare( 0, 6, "xrdcl." ) == 0 )
366  continue;
367  if( it != pParams.begin() ) o << "&";
368  o << it->first << "=" << it->second;
369  }
370  std::string ret = o.str();
371  if( ret == "?" ) ret.clear();
372  return ret;
373  }

◆ GetPassword()

const std::string& XrdCl::URL::GetPassword ( ) const
inline

Get the password.

Definition at line 153 of file XrdClURL.hh.

154  {
155  return pPassword;
156  }

Referenced by XrdCl::XRootDMsgHandler::Process().

+ Here is the caller graph for this function:

◆ GetPath()

◆ GetPathWithFilteredParams()

std::string XrdCl::URL::GetPathWithFilteredParams ( ) const

Get the path with params, filteres out 'xrdcl.'.

Definition at line 307 of file XrdClURL.cc.

308  {
309  std::ostringstream o;
310  if( !pPath.empty() )
311  o << pPath;
312 
313  o << GetParamsAsString( true );
314  return o.str();
315  }

References GetParamsAsString().

Referenced by XrdCl::MessageUtils::RewriteCGIAndPath().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetPathWithParams()

std::string XrdCl::URL::GetPathWithParams ( ) const

Get the path with params.

Definition at line 294 of file XrdClURL.cc.

295  {
296  std::ostringstream o;
297  if( !pPath.empty() )
298  o << pPath;
299 
300  o << GetParamsAsString();
301  return o.str();
302  }

References GetParamsAsString().

Referenced by XrdPosixAdmin::FanOut(), main(), XrdPosixXrootd::Mkdir(), XrdPosixDir::Open(), XrdPosixAdmin::Query(), XrdPosixXrootd::Rename(), XrdPosixXrootd::Rmdir(), XrdPosixAdmin::Stat(), XrdPosixXrootd::Statvfs(), XrdPosixXrootd::Truncate(), and XrdPosixXrootd::Unlink().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetPort()

int XrdCl::URL::GetPort ( ) const
inline

Get the target port.

Definition at line 188 of file XrdClURL.hh.

189  {
190  return pPort;
191  }

Referenced by XrdPosixXrootd::endPoint(), and XrdCl::Utils::GetHostAddresses().

+ Here is the caller graph for this function:

◆ GetProtocol()

const std::string& XrdCl::URL::GetProtocol ( ) const
inline

Get the protocol.

Definition at line 118 of file XrdClURL.hh.

119  {
120  return pProtocol;
121  }

Referenced by XrdCl::Channel::Channel(), XrdCl::PostMaster::CollapseRedirect(), XrdCl::PostMasterImpl::GetChannel(), XrdCl::PlugInManager::GetFactory(), XrdCl::Utils::InferChecksumType(), is_http_url(), XrdCl::CopyProcess::Prepare(), ProgressDisplay::PrintCheckSum(), XrdCl::XRootDMsgHandler::Process(), and XrdClHttp::Filesystem::ThirdPartyCopy().

+ Here is the caller graph for this function:

◆ GetURL()

◆ GetUserName()

const std::string& XrdCl::URL::GetUserName ( ) const
inline

Get the username.

Definition at line 135 of file XrdClURL.hh.

136  {
137  return pUserName;
138  }

Referenced by XrdCl::XRootDMsgHandler::Process().

+ Here is the caller graph for this function:

◆ IsLocalFile()

bool XrdCl::URL::IsLocalFile ( ) const

Is it a URL to a local file (file://localhost

Definition at line 450 of file XrdClURL.cc.

451  {
452  return pProtocol == "file" && pHostName == "localhost";
453  }

Referenced by XrdCl::FileStateHandler::~FileStateHandler(), XrdCl::Utils::HasKSameFS(), XrdCl::Utils::HasPgRW(), XrdCl::Utils::HasXAttr(), XrdCl::Utils::InferChecksumType(), XrdCl::FileStateHandler::OnOpen(), ProgressDisplay::PrintCheckSum(), and XrdCl::XRootDMsgHandler::Process().

+ Here is the caller graph for this function:

◆ IsMetalink()

bool XrdCl::URL::IsMetalink ( ) const

Is it a URL to a metalink.

Definition at line 441 of file XrdClURL.cc.

442  {
443  Env *env = DefaultEnv::GetEnv();
444  int mlProcessing = DefaultMetalinkProcessing;
445  env->GetInt( "MetalinkProcessing", mlProcessing );
446  if( !mlProcessing ) return false;
447  return PathEndsWith( ".meta4" ) || PathEndsWith( ".metalink" );
448  }
static Env * GetEnv()
Get default client environment.
const int DefaultMetalinkProcessing

References XrdCl::DefaultMetalinkProcessing, XrdCl::DefaultEnv::GetEnv(), and XrdCl::Env::GetInt().

Referenced by XrdCl::FileStateHandler::~FileStateHandler(), XrdCl::Utils::InferChecksumType(), XrdCl::FileStateHandler::OnOpen(), XrdCl::CopyProcess::Prepare(), and XrdCl::XRootDMsgHandler::Process().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsSecure()

bool XrdCl::URL::IsSecure ( ) const

Does the protocol indicate encryption.

Definition at line 458 of file XrdClURL.cc.

459  {
460  return ( pProtocol == "roots" || pProtocol == "xroots" );
461  }

Referenced by XrdCl::XRootDTransport::InitializeChannel().

+ Here is the caller graph for this function:

◆ IsTPC()

bool XrdCl::URL::IsTPC ( ) const

Is the URL used in TPC context.

Definition at line 466 of file XrdClURL.cc.

467  {
468  ParamsMap::const_iterator itr = pParams.find( "xrdcl.intent" );
469  if( itr != pParams.end() )
470  return itr->second == "tpc";
471  return false;
472  }

Referenced by XrdCl::XRootDTransport::InitializeChannel().

+ Here is the caller graph for this function:

◆ IsValid()

bool XrdCl::URL::IsValid ( ) const

Is the url valid.

Definition at line 428 of file XrdClURL.cc.

429  {
430  if( pProtocol.empty() )
431  return false;
432  if( pProtocol == "file" && pPath.empty() )
433  return false;
434  if( pProtocol == "stdio" && pPath != "-" )
435  return false;
436  if( pProtocol != "file" && pProtocol != "stdio" && pHostName.empty() )
437  return false;
438  return true;
439  }

Referenced by XrdCl::Stream::EnableLink(), XrdCl::FileSystemUtils::GetSpaceInfo(), XrdPosixAdmin::isOK(), main(), XrdCl::CopyProcess::Prepare(), XrdCl::XRootDMsgHandler::Process(), XrdPosixXrootd::Rename(), XrdCl::MessageUtils::SendMessage(), and XrdCl::XRootDMsgHandler::SetLoadBalancer().

+ Here is the caller graph for this function:

◆ SetHostName()

void XrdCl::URL::SetHostName ( const std::string &  hostName)
inline

Set the host name.

Definition at line 178 of file XrdClURL.hh.

179  {
180  pHostName = hostName;
181  ComputeHostId();
182  ComputeURL();
183  }

Referenced by XrdPosixAdmin::FanOut().

+ Here is the caller graph for this function:

◆ SetHostPort()

void XrdCl::URL::SetHostPort ( const std::string &  hostName,
int  port 
)
inline

Definition at line 206 of file XrdClURL.hh.

207  {
208  pHostName = hostName;
209  pPort = port;
210  ComputeHostId();
211  ComputeURL();
212  }

◆ SetParam()

void XrdCl::URL::SetParam ( const std::string &  name,
const std::string &  value 
)
inline

Set a single param.

Definition at line 283 of file XrdClURL.hh.

284  {
285  pParams[name] = value;
286  ComputeURL();
287  }

◆ SetParams() [1/2]

void XrdCl::URL::SetParams ( const ParamsMap &  params)
inline

Set params.

Definition at line 274 of file XrdClURL.hh.

275  {
276  pParams = params;
277  ComputeURL();
278  }

◆ SetParams() [2/2]

void XrdCl::URL::SetParams ( const std::string &  params)

Set params.

Definition at line 378 of file XrdClURL.cc.

379  {
380  pParams.clear();
381  std::string p = params;
382 
383  if( p.empty() )
384  return;
385 
386  if( p[0] == '?' )
387  p.erase( 0, 1 );
388 
389  std::vector<std::string> paramsVect;
390  std::vector<std::string>::iterator it;
391  Utils::splitString( paramsVect, p, "&" );
392  for( it = paramsVect.begin(); it != paramsVect.end(); ++it )
393  {
394  if( it->empty() ) continue;
395  size_t qpos = it->find( '?' );
396  if( qpos != std::string::npos ) // we have login token
397  {
398  pParams["xrd.logintoken"] = it->substr( qpos + 1 );
399  it->erase( qpos );
400  }
401  size_t pos = it->find( "=" );
402  if( pos == std::string::npos )
403  pParams[*it] = "";
404  else
405  pParams[it->substr(0, pos)] = it->substr( pos+1, it->length() );
406  }
407  }
static void splitString(Container &result, const std::string &input, const std::string &delimiter)
Split a string.
Definition: XrdClUtils.hh:56

References XrdCl::Utils::splitString().

Referenced by XrdCl::Channel::Channel(), XrdClS3::Filesystem::Filesystem(), XrdCl::FileStateHandler::OnOpen(), XrdCl::XRootDMsgHandler::Process(), XrdCl::MessageUtils::RewriteCGIAndPath(), and XrdCl::ClassicCopyJob::Run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetPassword()

void XrdCl::URL::SetPassword ( const std::string &  password)
inline

Set the password.

Definition at line 161 of file XrdClURL.hh.

162  {
163  pPassword = password;
164  ComputeURL();
165  }

Referenced by XrdCl::XRootDMsgHandler::Process().

+ Here is the caller graph for this function:

◆ SetPath()

void XrdCl::URL::SetPath ( const std::string &  path)
inline

Set the path.

Definition at line 225 of file XrdClURL.hh.

226  {
227  pPath = path;
228  ComputeURL();
229  }

Referenced by XrdClS3::Filesystem::Filesystem(), XrdCl::ZipListHandler::ZipListHandler(), DoTail(), XrdCl::FileStateHandler::OnOpen(), XrdCl::CopyProcess::Prepare(), XrdCl::XRootDMsgHandler::Process(), and XrdCl::MessageUtils::RewriteCGIAndPath().

+ Here is the caller graph for this function:

◆ SetPort()

void XrdCl::URL::SetPort ( int  port)
inline

Definition at line 196 of file XrdClURL.hh.

197  {
198  pPort = port;
199  ComputeHostId();
200  ComputeURL();
201  }

Referenced by XrdPosixAdmin::FanOut().

+ Here is the caller graph for this function:

◆ SetProtocol()

void XrdCl::URL::SetProtocol ( const std::string &  protocol)
inline

Set protocol.

Definition at line 126 of file XrdClURL.hh.

127  {
128  pProtocol = protocol;
129  ComputeURL();
130  }

Referenced by XrdCl::Channel::Channel(), XrdCl::FileSystem::DirList(), and XrdCl::XRootDMsgHandler::Process().

+ Here is the caller graph for this function:

◆ SetUserName()

void XrdCl::URL::SetUserName ( const std::string &  userName)
inline

Set the username.

Definition at line 143 of file XrdClURL.hh.

144  {
145  pUserName = userName;
146  ComputeHostId();
147  ComputeURL();
148  }

Referenced by XrdCl::XRootDMsgHandler::Process().

+ Here is the caller graph for this function:

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