64 if( url.length() == 0 )
73 size_t pos = url.find(
"://" );
76 if( pos != std::string::npos )
78 pProtocol = url.substr( 0, pos );
79 current = url.substr( pos+3 );
81 else if( url[0] ==
'/' )
86 else if( url[0] ==
'-' )
101 if (pProtocol ==
"http") {
104 if (pProtocol ==
"https") {
112 std::string hostInfo;
114 if( pProtocol ==
"stdio" )
116 else if( pProtocol ==
"file")
118 if( current[0] ==
'/' )
119 current =
"localhost" + current;
120 pos = current.find(
'/' );
121 if( pos == std::string::npos )
125 hostInfo = current.substr( 0, pos );
126 path = current.substr( pos );
131 pos = current.find(
'/' );
132 if( pos == std::string::npos )
136 hostInfo = current.substr( 0, pos );
137 path = current.substr( pos+1 );
141 if( !ParseHostInfo( hostInfo ) )
147 if( !ParsePath( path ) )
166 url.c_str(), pProtocol.c_str(), pUserName.c_str(),
167 pPassword.c_str(), pHostName.c_str(), pPort, pPath.c_str() );
174 bool URL::ParseHostInfo(
const std::string hostInfo )
176 if( pProtocol ==
"stdio" )
179 if( pProtocol.empty() || hostInfo.empty() )
182 size_t pos = hostInfo.find(
"@" );
183 std::string hostPort;
188 if( pos != std::string::npos )
190 std::string userPass = hostInfo.substr( 0, pos );
191 hostPort = hostInfo.substr( pos+1 );
192 pos = userPass.find(
":" );
197 if( pos != std::string::npos )
199 pUserName = userPass.substr( 0, pos );
200 pPassword = userPass.substr( pos+1 );
201 if( pPassword.empty() )
208 pUserName = userPass;
209 if( pUserName.empty() )
222 if( hostPort.length() >= 3 && hostPort[0] ==
'[' )
224 pos = hostPort.find(
"]" );
225 if( pos != std::string::npos )
227 pHostName = hostPort.substr( 0, pos+1 );
228 hostPort.erase( 0, pos+2 );
233 pos = pHostName.find(
"." );
234 size_t pos2 = pHostName.find(
"[::ffff" );
235 size_t pos3 = pHostName.find(
"[::" );
236 if( pos != std::string::npos && pos3 != std::string::npos &&
237 pos2 == std::string::npos )
239 pHostName.erase( 0, 3 );
240 pHostName.erase( pHostName.length()-1, 1 );
246 pos = hostPort.find(
":" );
247 if( pos != std::string::npos )
249 pHostName = hostPort.substr( 0, pos );
250 hostPort.erase( 0, pos+1 );
254 pHostName = hostPort;
257 if( pHostName.empty() )
264 if( !hostPort.empty() )
267 pPort = ::strtol( hostPort.c_str(), &result, 0 );
279 bool URL::ParsePath(
const std::string &path )
281 size_t pos = path.find(
"?" );
282 if( pos != std::string::npos )
284 pPath = path.substr( 0, pos );
285 SetParams( path.substr( pos+1, path.length() ) );
292 std::string::iterator back = pPath.end() - 1;
293 if( pProtocol ==
"file" && *back ==
'/' )
306 std::ostringstream o;
319 std::ostringstream o;
332 std::ostringstream o;
333 o << pProtocol <<
"://";
334 if( pProtocol ==
"file" )
337 o << pHostName <<
":" << pPort <<
"/";
355 auto itr = pParams.find(
"xrd.logintoken" );
356 if( itr == pParams.end() )
366 if( pParams.empty() )
369 std::ostringstream o;
371 ParamsMap::const_iterator it;
372 for( it = pParams.begin(); it != pParams.end(); ++it )
375 if( filter && it->first.compare( 0, 6,
"xrdcl." ) == 0 )
377 if( it != pParams.begin() ) o <<
"&";
378 o << it->first <<
"=" << it->second;
380 std::string ret = o.str();
381 if( ret ==
"?" ) ret.clear();
391 std::string p = params;
399 std::vector<std::string> paramsVect;
400 std::vector<std::string>::iterator it;
402 for( it = paramsVect.begin(); it != paramsVect.end(); ++it )
404 if( it->empty() )
continue;
405 size_t qpos = it->find(
'?' );
406 if( qpos != std::string::npos )
408 pParams[
"xrd.logintoken"] = it->substr( qpos + 1 );
411 size_t pos = it->find(
"=" );
412 if( pos == std::string::npos )
415 pParams[it->substr(0, pos)] = it->substr( pos+1, it->length() );
440 if( pProtocol.empty() )
442 if( pProtocol ==
"file" && pPath.empty() )
444 if( pProtocol ==
"stdio" && pPath !=
"-" )
446 if( pProtocol !=
"file" && pProtocol !=
"stdio" && pHostName.empty() )
455 env->
GetInt(
"MetalinkProcessing", mlProcessing );
456 if( !mlProcessing )
return false;
457 return PathEndsWith(
".meta4" ) || PathEndsWith(
".metalink" );
462 return pProtocol ==
"file" && pHostName ==
"localhost";
470 return ( pProtocol ==
"roots" || pProtocol ==
"xroots" );
478 ParamsMap::const_iterator itr = pParams.find(
"xrdcl.intent" );
479 if( itr != pParams.end() )
480 return itr->second ==
"tpc";
484 bool URL::PathEndsWith(
const std::string & sufix)
const
486 if (sufix.size() > pPath.size())
return false;
487 return std::equal(sufix.rbegin(), sufix.rend(), pPath.rbegin() );
496 std::string ret = pProtocol +
"://" + pHostId +
"/";
499 std::string keys[] = {
"xrdcl.intent",
505 size_t size =
sizeof( keys ) /
sizeof( std::string );
507 for(
size_t i = 0; i < size; ++i )
509 ParamsMap::const_iterator itr = pParams.find( keys[i] );
510 if( itr != pParams.end() )
512 ret += hascgi ?
'&' :
'?';
526 void URL::ComputeHostId()
528 std::ostringstream o;
529 if( !pUserName.empty() )
532 if( !pPassword.empty() )
533 o <<
":" << pPassword;
536 if( pProtocol ==
"file" )
539 o << pHostName <<
":" << pPort;
546 void URL::ComputeURL()
551 std::ostringstream o;
552 if( !pProtocol.empty() )
553 o << pProtocol <<
"://";
555 if( !pUserName.empty() )
558 if( !pPassword.empty() )
559 o <<
":" << pPassword;
563 if( !pHostName.empty() )
565 if( pProtocol ==
"file" )
568 o << pHostName <<
":" << pPort <<
"/";
static Log * GetLog()
Get default log.
static Env * GetEnv()
Get default client environment.
bool GetInt(const std::string &key, int &value)
void Error(uint64_t topic, const char *format,...)
Report an error.
void Dump(uint64_t topic, const char *format,...)
Print a dump message.
std::string GetChannelId() const
bool IsMetalink() const
Is it a URL to a metalink.
bool FromString(const std::string &url)
Parse a string and fill the URL fields.
void SetParams(const std::string ¶ms)
Set params.
URL()
Default constructor.
std::string GetPathWithFilteredParams() const
Get the path with params, filteres out 'xrdcl.'.
std::string GetPathWithParams() const
Get the path with params.
std::string GetLocation() const
Get location (protocol://host:port/path)
std::string GetParamsAsString() const
Get the URL params as string.
bool IsSecure() const
Does the protocol indicate encryption.
bool IsValid() const
Is the url valid.
void Clear()
Clear the url.
bool IsTPC() const
Is the URL used in TPC context.
std::string GetLoginToken() const
Get the login token if present in the opaque info.
static void splitString(Container &result, const std::string &input, const std::string &delimiter)
Split a string.
const int DefaultMetalinkProcessing
const uint64_t UtilityMsg