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.
std::string GetObfuscatedURL () const
 Get the URL with authz information obfuscated.
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 39 of file XrdClURL.cc.

39 :
40 pPort( 1094 )
41 {
42 }

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

47 :
48 pPort( 1094 )
49 {
50 FromString( url );
51 }
bool FromString(const std::string &url)
Parse a string and fill the URL fields.
Definition XrdClURL.cc:62

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

53 : pPort( 1094 )
54 {
55 FromString( url );
56 }

References FromString().

Here is the call graph for this function:

Member Function Documentation

◆ Clear()

void XrdCl::URL::Clear ( )

Clear the url.

Definition at line 436 of file XrdClURL.cc.

437 {
438 pHostId.clear();
439 pProtocol.clear();
440 pUserName.clear();
441 pPassword.clear();
442 pHostName.clear();
443 pPort = 1094;
444 pPath.clear();
445 pParams.clear();
446 pURL.clear();
447 }

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

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

References Clear(), XrdCl::Log::Dump(), XrdCl::Log::DumpMsg, XrdCl::Log::Error(), XrdCl::Log::GetLevel(), XrdCl::DefaultEnv::GetLog(), obfuscateAuth(), unlikely, 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 512 of file XrdClURL.cc.

513 {
514 std::string ret = pProtocol + "://" + pHostId + "/";
515 bool hascgi = false;
516
517 std::string keys[] = { "xrdcl.intent",
518 "xrd.gsiusrpxy",
519 "xrd.gsiusrcrt",
520 "xrd.gsiusrkey",
521 "xrd.sss",
522 "xrd.k5ccname" };
523 size_t size = sizeof( keys ) / sizeof( std::string );
524
525 for( size_t i = 0; i < size; ++i )
526 {
527 ParamsMap::const_iterator itr = pParams.find( keys[i] );
528 if( itr != pParams.end() )
529 {
530 ret += hascgi ? '&' : '?';
531 ret += itr->first;
532 ret += '=';
533 ret += itr->second;
534 hascgi = true;
535 }
536 }
537
538 return ret;
539 }

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()

std::string XrdCl::URL::GetHostId ( ) const
inline

Get the host part of the URL (user:password@host:port)

Definition at line 99 of file XrdClURL.hh.

100 {
101 return pHostId;
102 }

Referenced by XrdCl::FileSystemData::AssignLastURL(), XrdCl::FileSystemData::AssignLoadBalancer(), BuildPrompt(), XrdCl::PostMaster::CollapseRedirect(), XrdCl::ZipArchive::List(), ProgressDisplay::PrintCheckSum(), XrdCl::MessageUtils::RedirectMessage(), XrdCl::MessageUtils::SendMessage(), and XrdCl::AsyncSocketHandler::ToStreamName().

Here is the caller graph for this function:

◆ 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(), 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 344 of file XrdClURL.cc.

345 {
346 std::ostringstream o;
347 o << pProtocol << "://";
348 if( pProtocol == "file" )
349 o << pHostName;
350 else
351 o << pHostName << ":" << pPort << "/";
352 o << pPath;
353 return o.str();
354 }

Referenced by XrdCl::RedirectorRegistry::Get(), XrdCl::HttpFilePlugIn::Open(), and XrdCl::RedirectorRegistry::Release().

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

368 {
369 auto itr = pParams.find( "xrd.logintoken" );
370 if( itr == pParams.end() )
371 return "";
372 return itr->second;
373 }

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

498 {
499 return obfuscateAuth(pURL);
500 }

References obfuscateAuth().

Referenced by XrdCl::FileSystem::FileSystem(), and DoTail().

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(), 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 359 of file XrdClURL.cc.

360 {
361 return GetParamsAsString( false );
362 }
std::string GetParamsAsString() const
Get the URL params as string.
Definition XrdClURL.cc:359

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

379 {
380 if( pParams.empty() )
381 return "";
382
383 std::ostringstream o;
384 o << "?";
385 ParamsMap::const_iterator it;
386 for( it = pParams.begin(); it != pParams.end(); ++it )
387 {
388 // we filter out client specific parameters
389 if( filter && it->first.compare( 0, 6, "xrdcl." ) == 0 )
390 continue;
391 if( it != pParams.begin() ) o << "&";
392 o << it->first << "=" << it->second;
393 }
394 std::string ret = o.str();
395 if( ret == "?" ) ret.clear();
396 return ret;
397 }

◆ 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()

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

332 {
333 std::ostringstream o;
334 if( !pPath.empty() )
335 o << pPath;
336
337 o << GetParamsAsString( true );
338 return o.str();
339 }

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

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

References GetParamsAsString().

Referenced by main(), XrdPosixXrootd::Mkdir(), XrdPosixXrootd::Rename(), XrdPosixXrootd::Rmdir(), 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::PlugInManager::GetFactory(), XrdCl::Utils::InferChecksumType(), XrdCl::CopyProcess::Prepare(), ProgressDisplay::PrintCheckSum(), and XrdCl::XRootDMsgHandler::Process().

Here is the caller graph for this function:

◆ GetURL()

std::string XrdCl::URL::GetURL ( ) const
inline

Get the URL.

Definition at line 86 of file XrdClURL.hh.

87 {
88 return pURL;
89 }

Referenced by XrdCl::FileSystem::FileSystem(), XrdCl::FSExecutor::FSExecutor(), ProgressDisplay::BeginJob(), DoTail(), XrdCl::LocalFileHandler::ExecRequest(), main(), XrdCl::LocalFileHandler::Open(), XrdCl::CopyProcess::Prepare(), XrdCl::XRootDMsgHandler::Process(), and XrdCl::PropertyList::Set().

Here is the caller graph for this function:

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

475 {
476 return pProtocol == "file" && pHostName == "localhost";
477 }

Referenced by XrdCl::Utils::HasPgRW(), XrdCl::Utils::HasXAttr(), XrdCl::Utils::InferChecksumType(), 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 465 of file XrdClURL.cc.

466 {
467 Env *env = DefaultEnv::GetEnv();
468 int mlProcessing = DefaultMetalinkProcessing;
469 env->GetInt( "MetalinkProcessing", mlProcessing );
470 if( !mlProcessing ) return false;
471 return PathEndsWith( ".meta4" ) || PathEndsWith( ".metalink" );
472 }
static Env * GetEnv()
Get default client environment.
const int DefaultMetalinkProcessing

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

Referenced by XrdCl::Utils::InferChecksumType(), and XrdCl::CopyProcess::Prepare().

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

483 {
484 return ( pProtocol == "roots" || pProtocol == "xroots" );
485 }

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

491 {
492 ParamsMap::const_iterator itr = pParams.find( "xrdcl.intent" );
493 if( itr != pParams.end() )
494 return itr->second == "tpc";
495 return false;
496 }

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

453 {
454 if( pProtocol.empty() )
455 return false;
456 if( pProtocol == "file" && pPath.empty() )
457 return false;
458 if( pProtocol == "stdio" && pPath != "-" )
459 return false;
460 if( pProtocol != "file" && pProtocol != "stdio" && pHostName.empty() )
461 return false;
462 return true;
463 }

Referenced by XrdCl::FileSystemUtils::GetSpaceInfo(), 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 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 }

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

403 {
404 pParams.clear();
405 std::string p = params;
406
407 if( p.empty() )
408 return;
409
410 if( p[0] == '?' )
411 p.erase( 0, 1 );
412
413 std::vector<std::string> paramsVect;
414 std::vector<std::string>::iterator it;
415 Utils::splitString( paramsVect, p, "&" );
416 for( it = paramsVect.begin(); it != paramsVect.end(); ++it )
417 {
418 if( it->empty() ) continue;
419 size_t qpos = it->find( '?' );
420 if( qpos != std::string::npos ) // we have login token
421 {
422 pParams["xrd.logintoken"] = it->substr( qpos + 1 );
423 it->erase( qpos );
424 }
425 size_t pos = it->find( "=" );
426 if( pos == std::string::npos )
427 pParams[*it] = "";
428 else
429 pParams[it->substr(0, pos)] = it->substr( pos+1, it->length() );
430 }
431 }
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::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 DoTail(), XrdCl::CopyProcess::Prepare(), 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::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: