67 if( url.length() == 0 )
76 size_t pos = url.find(
"://" );
79 if( pos != std::string::npos )
81 pProtocol = url.substr( 0, pos );
82 current = url.substr( pos+3 );
84 else if( url[0] ==
'/' )
89 else if( url[0] ==
'-' )
104 if (pProtocol ==
"http") {
107 if (pProtocol ==
"https") {
115 std::string hostInfo;
117 if( pProtocol ==
"stdio" )
119 else if( pProtocol ==
"file")
121 if( current[0] ==
'/' )
122 current =
"localhost" + current;
123 pos = current.find(
'/' );
124 if( pos == std::string::npos )
128 hostInfo = current.substr( 0, pos );
129 path = current.substr( pos );
134 pos = current.find(
'/' );
135 if( pos == std::string::npos )
139 hostInfo = current.substr( 0, pos );
140 path = current.substr( pos+1 );
144 if( !ParseHostInfo( hostInfo ) )
150 if( !ParsePath( path ) )
161 std::string urlLog = url;
173 urlLog.c_str(), pProtocol.c_str(), pUserName.c_str(),
174 pPassword.c_str(), pHostName.c_str(), pPort, pPath.c_str() );
181 bool URL::ParseHostInfo(
const std::string hostInfo )
183 if( pProtocol ==
"stdio" )
186 if( pProtocol.empty() || hostInfo.empty() )
189 size_t pos = hostInfo.find(
"@" );
190 std::string hostPort;
195 if( pos != std::string::npos )
197 std::string userPass = hostInfo.substr( 0, pos );
198 hostPort = hostInfo.substr( pos+1 );
199 pos = userPass.find(
":" );
204 if( pos != std::string::npos )
206 pUserName = userPass.substr( 0, pos );
207 pPassword = userPass.substr( pos+1 );
208 if( pPassword.empty() )
215 pUserName = userPass;
216 if( pUserName.empty() )
229 if( hostPort.length() >= 3 && hostPort[0] ==
'[' )
231 pos = hostPort.find(
"]" );
232 if( pos != std::string::npos )
234 pHostName = hostPort.substr( 0, pos+1 );
235 hostPort.erase( 0, pos+2 );
240 pos = pHostName.find(
"." );
241 size_t pos2 = pHostName.find(
"[::ffff" );
242 size_t pos3 = pHostName.find(
"[::" );
243 if( pos != std::string::npos && pos3 != std::string::npos &&
244 pos2 == std::string::npos )
246 pHostName.erase( 0, 3 );
247 pHostName.erase( pHostName.length()-1, 1 );
253 pos = hostPort.find(
":" );
254 if( pos != std::string::npos )
256 pHostName = hostPort.substr( 0, pos );
257 hostPort.erase( 0, pos+1 );
261 pHostName = hostPort;
264 if( pHostName.empty() )
271 if( !hostPort.empty() )
274 pPort = ::strtol( hostPort.c_str(), &result, 0 );
286 bool URL::ParsePath(
const std::string &path )
288 size_t pos = path.find(
"?" );
289 if( pos != std::string::npos )
291 pPath = path.substr( 0, pos );
292 SetParams( path.substr( pos+1, path.length() ) );
299 std::string::iterator back = pPath.end() - 1;
300 if( pProtocol ==
"file" && *back ==
'/' )
313 std::ostringstream o;
326 std::ostringstream o;
339 std::ostringstream o;
340 o << pProtocol <<
"://";
341 if( pProtocol ==
"file" )
344 o << pHostName <<
":" << pPort <<
"/";
362 auto itr = pParams.find(
"xrd.logintoken" );
363 if( itr == pParams.end() )
373 if( pParams.empty() )
376 std::ostringstream o;
378 ParamsMap::const_iterator it;
379 for( it = pParams.begin(); it != pParams.end(); ++it )
382 if( filter && it->first.compare( 0, 6,
"xrdcl." ) == 0 )
384 if( it != pParams.begin() ) o <<
"&";
385 o << it->first <<
"=" << it->second;
387 std::string ret = o.str();
388 if( ret ==
"?" ) ret.clear();
398 std::string p = params;
406 std::vector<std::string> paramsVect;
407 std::vector<std::string>::iterator it;
409 for( it = paramsVect.begin(); it != paramsVect.end(); ++it )
411 if( it->empty() )
continue;
412 size_t qpos = it->find(
'?' );
413 if( qpos != std::string::npos )
415 pParams[
"xrd.logintoken"] = it->substr( qpos + 1 );
418 size_t pos = it->find(
"=" );
419 if( pos == std::string::npos )
422 pParams[it->substr(0, pos)] = it->substr( pos+1, it->length() );
447 if( pProtocol.empty() )
449 if( pProtocol ==
"file" && pPath.empty() )
451 if( pProtocol ==
"stdio" && pPath !=
"-" )
453 if( pProtocol !=
"file" && pProtocol !=
"stdio" && pHostName.empty() )
462 env->
GetInt(
"MetalinkProcessing", mlProcessing );
463 if( !mlProcessing )
return false;
464 return PathEndsWith(
".meta4" ) || PathEndsWith(
".metalink" );
469 return pProtocol ==
"file" && pHostName ==
"localhost";
477 return ( pProtocol ==
"roots" || pProtocol ==
"xroots" );
485 ParamsMap::const_iterator itr = pParams.find(
"xrdcl.intent" );
486 if( itr != pParams.end() )
487 return itr->second ==
"tpc";
495 bool URL::PathEndsWith(
const std::string & sufix)
const
497 if (sufix.size() > pPath.size())
return false;
498 return std::equal(sufix.rbegin(), sufix.rend(), pPath.rbegin() );
507 std::string ret = pProtocol +
"://" + pHostId +
"/";
510 std::string keys[] = {
"xrdcl.intent",
516 size_t size =
sizeof( keys ) /
sizeof( std::string );
518 for(
size_t i = 0; i < size; ++i )
520 ParamsMap::const_iterator itr = pParams.find( keys[i] );
521 if( itr != pParams.end() )
523 ret += hascgi ?
'&' :
'?';
537 void URL::ComputeHostId()
539 std::ostringstream o;
540 if( !pUserName.empty() )
543 if( !pPassword.empty() )
544 o <<
":" << pPassword;
547 if( pProtocol ==
"file" )
550 o << pHostName <<
":" << pPort;
557 void URL::ComputeURL()
563 std::ostringstream o;
564 if( !pProtocol.empty() )
565 o << pProtocol <<
"://";
567 if( !pUserName.empty() )
570 if( !pPassword.empty() )
571 o <<
":" << pPassword;
575 if( !pHostName.empty() )
577 if( pProtocol ==
"file" )
580 o << pHostName <<
":" << pPort <<
"/";
std::string obfuscateAuth(const std::string &input)
static Log * GetLog()
Get default log.
static Env * GetEnv()
Get default client environment.
bool GetInt(const std::string &key, int &value)
@ DumpMsg
print details of the request and responses
void Error(uint64_t topic, const char *format,...)
Report an error.
LogLevel GetLevel() const
Get the log level.
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 GetObfuscatedURL() const
Get the URL with authz information obfuscated.
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