XRootD
Loading...
Searching...
No Matches
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.
 
 URL (const char *url)
 
 URL (const std::string &url)
 
void Clear ()
 Clear the url.
 
bool FromString (const std::string &url)
 Parse a string and fill the URL fields.
 
std::string GetChannelId () const
 
std::string GetHostId () const
 Get the host part of the URL (user:password@host:port)
 
const std::string & GetHostName () const
 Get the name of the target host.
 
std::string GetLocation () const
 Get location (protocol://host:port/path)
 
std::string GetLoginToken () const
 Get the login token if present in the opaque info.
 
const ParamsMapGetParams () const
 Get the URL params.
 
std::string GetParamsAsString () const
 Get the URL params as string.
 
std::string GetParamsAsString (bool filter) const
 Get the URL params as string.
 
const std::string & GetPassword () const
 Get the password.
 
const std::string & GetPath () const
 Get the path.
 
std::string GetPathWithFilteredParams () const
 Get the path with params, filteres out 'xrdcl.'.
 
std::string GetPathWithParams () const
 Get the path with params.
 
int GetPort () const
 Get the target port.
 
const std::string & GetProtocol () const
 Get the protocol.
 
std::string GetURL () const
 Get the URL.
 
const std::string & GetUserName () const
 Get the username.
 
bool IsLocalFile () const
 
bool IsMetalink () const
 Is it a URL to a metalink.
 
bool IsSecure () const
 Does the protocol indicate encryption.
 
bool IsTPC () const
 Is the URL used in TPC context.
 
bool IsValid () const
 Is the url valid.
 
void SetHostName (const std::string &hostName)
 Set the host name.
 
void SetHostPort (const std::string &hostName, int port)
 
void SetParams (const ParamsMap &params)
 Set params.
 
void SetParams (const std::string &params)
 Set params.
 
void SetPassword (const std::string &password)
 Set the password.
 
void SetPath (const std::string &path)
 Set the path.
 
void SetPort (int port)
 
void SetProtocol (const std::string &protocol)
 Set protocol.
 
void SetUserName (const std::string &userName)
 Set the username.
 

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 35 of file XrdClURL.cc.

35 :
36 pPort( 1094 )
37 {
38 }

◆ 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 43 of file XrdClURL.cc.

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

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 49 of file XrdClURL.cc.

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

References FromString().

+ Here is the call graph for this function:

Member Function Documentation

◆ Clear()

void XrdCl::URL::Clear ( )

Clear the url.

Definition at line 422 of file XrdClURL.cc.

423 {
424 pHostId.clear();
425 pProtocol.clear();
426 pUserName.clear();
427 pPassword.clear();
428 pHostName.clear();
429 pPort = 1094;
430 pPath.clear();
431 pParams.clear();
432 pURL.clear();
433 }

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 58 of file XrdClURL.cc.

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

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

Referenced by URL(), and 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 494 of file XrdClURL.cc.

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

Referenced by XrdCl::Channel::Channel(), XrdCl::XRootDChannelInfo::XRootDChannelInfo(), XrdCl::PostMaster::CollapseRedirect(), XrdCl::PostMaster::ForceDisconnect(), XrdCl::PostMaster::ForceReconnect(), 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 165 of file XrdClURL.hh.

166 {
167 return pHostName;
168 }

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

+ 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 330 of file XrdClURL.cc.

331 {
332 std::ostringstream o;
333 o << pProtocol << "://";
334 if( pProtocol == "file" )
335 o << pHostName;
336 else
337 o << pHostName << ":" << pPort << "/";
338 o << pPath;
339 return o.str();
340 }

Referenced by XrdCl::RedirectorRegistry::Get(), XrdCl::HttpFilePlugIn::Open(), 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 353 of file XrdClURL.cc.

354 {
355 auto itr = pParams.find( "xrd.logintoken" );
356 if( itr == pParams.end() )
357 return "";
358 return itr->second;
359 }

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

+ Here is the caller graph for this function:

◆ GetParams()

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

Get the URL params.

Definition at line 239 of file XrdClURL.hh.

240 {
241 return pParams;
242 }

Referenced by XrdCl::Channel::Channel(), XrdCl::Utils::CheckEC(), XrdCl::GetEcHandler(), XrdCl::Utils::GetIntParameter(), XrdCl::FileSystemUtils::GetSpaceInfo(), XrdCl::Utils::GetStringParameter(), XrdCl::FileStateHandler::OnOpen(), XrdCl::HttpFilePlugIn::Open(), 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 345 of file XrdClURL.cc.

346 {
347 return GetParamsAsString( false );
348 }
std::string GetParamsAsString() const
Get the URL params as string.
Definition XrdClURL.cc:345

References GetParamsAsString().

Referenced by GetParamsAsString(), GetPathWithFilteredParams(), and GetPathWithParams().

+ Here is the call graph for this function:
+ 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 364 of file XrdClURL.cc.

365 {
366 if( pParams.empty() )
367 return "";
368
369 std::ostringstream o;
370 o << "?";
371 ParamsMap::const_iterator it;
372 for( it = pParams.begin(); it != pParams.end(); ++it )
373 {
374 // we filter out client specific parameters
375 if( filter && it->first.compare( 0, 6, "xrdcl." ) == 0 )
376 continue;
377 if( it != pParams.begin() ) o << "&";
378 o << it->first << "=" << it->second;
379 }
380 std::string ret = o.str();
381 if( ret == "?" ) ret.clear();
382 return ret;
383 }

◆ GetPassword()

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

Get the password.

Definition at line 148 of file XrdClURL.hh.

149 {
150 return pPassword;
151 }

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

+ Here is the caller graph for this function:

◆ GetPath()

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

◆ GetPathWithFilteredParams()

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

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

Definition at line 317 of file XrdClURL.cc.

318 {
319 std::ostringstream o;
320 if( !pPath.empty() )
321 o << pPath;
322
323 o << GetParamsAsString( true );
324 return o.str();
325 }

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 304 of file XrdClURL.cc.

305 {
306 std::ostringstream o;
307 if( !pPath.empty() )
308 o << pPath;
309
310 o << GetParamsAsString();
311 return o.str();
312 }

References GetParamsAsString().

Referenced by XrdPosixAdmin::FanOut(), main(), XrdPosixXrootd::Mkdir(), XrdPosixDir::Open(), XrdPosixAdmin::Query(), XrdPosixXrootd::Rename(), XrdPosixXrootd::Rmdir(), XrdPosixAdmin::Stat(), 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 183 of file XrdClURL.hh.

184 {
185 return pPort;
186 }

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

+ Here is the caller graph for this function:

◆ GetProtocol()

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

Get the protocol.

Definition at line 113 of file XrdClURL.hh.

114 {
115 return pProtocol;
116 }

Referenced by XrdCl::Channel::Channel(), XrdCl::PostMaster::CollapseRedirect(), XrdCl::PlugInManager::GetFactory(), XrdCl::Utils::InferChecksumType(), XrdCl::HttpFileSystemPlugIn::Mv(), XrdCl::CopyProcess::Prepare(), ProgressDisplay::PrintCheckSum(), XrdCl::XRootDMsgHandler::Process(), and XrdCl::HttpFileSystemPlugIn::Stat().

+ Here is the caller graph for this function:

◆ GetURL()

◆ GetUserName()

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

Get the username.

Definition at line 130 of file XrdClURL.hh.

131 {
132 return pUserName;
133 }

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 460 of file XrdClURL.cc.

461 {
462 return pProtocol == "file" && pHostName == "localhost";
463 }

Referenced by XrdCl::FileStateHandler::~FileStateHandler(), 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 451 of file XrdClURL.cc.

452 {
453 Env *env = DefaultEnv::GetEnv();
454 int mlProcessing = DefaultMetalinkProcessing;
455 env->GetInt( "MetalinkProcessing", mlProcessing );
456 if( !mlProcessing ) return false;
457 return PathEndsWith( ".meta4" ) || PathEndsWith( ".metalink" );
458 }
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 468 of file XrdClURL.cc.

469 {
470 return ( pProtocol == "roots" || pProtocol == "xroots" );
471 }

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 476 of file XrdClURL.cc.

477 {
478 ParamsMap::const_iterator itr = pParams.find( "xrdcl.intent" );
479 if( itr != pParams.end() )
480 return itr->second == "tpc";
481 return false;
482 }

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 438 of file XrdClURL.cc.

439 {
440 if( pProtocol.empty() )
441 return false;
442 if( pProtocol == "file" && pPath.empty() )
443 return false;
444 if( pProtocol == "stdio" && pPath != "-" )
445 return false;
446 if( pProtocol != "file" && pProtocol != "stdio" && pHostName.empty() )
447 return false;
448 return true;
449 }

Referenced by XrdCl::Stream::EnableLink(), XrdCl::FileSystemUtils::GetSpaceInfo(), XrdPosixAdmin::isOK(), main(), 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 173 of file XrdClURL.hh.

174 {
175 pHostName = hostName;
176 ComputeHostId();
177 ComputeURL();
178 }

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 201 of file XrdClURL.hh.

202 {
203 pHostName = hostName;
204 pPort = port;
205 ComputeHostId();
206 ComputeURL();
207 }

◆ SetParams() [1/2]

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

Set params.

Definition at line 269 of file XrdClURL.hh.

270 {
271 pParams = params;
272 ComputeURL();
273 }

◆ SetParams() [2/2]

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

Set params.

Definition at line 388 of file XrdClURL.cc.

389 {
390 pParams.clear();
391 std::string p = params;
392
393 if( p.empty() )
394 return;
395
396 if( p[0] == '?' )
397 p.erase( 0, 1 );
398
399 std::vector<std::string> paramsVect;
400 std::vector<std::string>::iterator it;
401 Utils::splitString( paramsVect, p, "&" );
402 for( it = paramsVect.begin(); it != paramsVect.end(); ++it )
403 {
404 if( it->empty() ) continue;
405 size_t qpos = it->find( '?' );
406 if( qpos != std::string::npos ) // we have login token
407 {
408 pParams["xrd.logintoken"] = it->substr( qpos + 1 );
409 it->erase( qpos );
410 }
411 size_t pos = it->find( "=" );
412 if( pos == std::string::npos )
413 pParams[*it] = "";
414 else
415 pParams[it->substr(0, pos)] = it->substr( pos+1, it->length() );
416 }
417 }
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(), 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 156 of file XrdClURL.hh.

157 {
158 pPassword = password;
159 ComputeURL();
160 }

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 220 of file XrdClURL.hh.

221 {
222 pPath = path;
223 ComputeURL();
224 }

Referenced by XrdCl::ZipListHandler::ZipListHandler(), XrdCl::HttpFileSystemPlugIn::DirList(), DoTail(), XrdCl::HttpFileSystemPlugIn::MkDir(), XrdCl::FileStateHandler::OnOpen(), XrdCl::CopyProcess::Prepare(), XrdCl::MessageUtils::RewriteCGIAndPath(), XrdCl::HttpFileSystemPlugIn::Rm(), and XrdCl::HttpFileSystemPlugIn::RmDir().

+ Here is the caller graph for this function:

◆ SetPort()

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

Definition at line 191 of file XrdClURL.hh.

192 {
193 pPort = port;
194 ComputeHostId();
195 ComputeURL();
196 }

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 121 of file XrdClURL.hh.

122 {
123 pProtocol = protocol;
124 ComputeURL();
125 }

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 138 of file XrdClURL.hh.

139 {
140 pUserName = userName;
141 ComputeHostId();
142 ComputeURL();
143 }

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

+ Here is the caller graph for this function:

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