68 if( url.length() == 0 )
77 size_t pos = url.find(
"://" );
80 if( pos != std::string::npos )
82 pProtocol = url.substr( 0, pos );
83 current = url.substr( pos+3 );
85 else if( url[0] ==
'/' )
90 else if( url[0] ==
'-' )
105 if (pProtocol ==
"http") {
108 if (pProtocol ==
"https") {
116 std::string hostInfo;
118 if( pProtocol ==
"stdio" )
120 else if( pProtocol ==
"file")
122 if( current[0] ==
'/' )
123 current =
"localhost" + current;
124 pos = current.find(
'/' );
125 if( pos == std::string::npos )
129 hostInfo = current.substr( 0, pos );
130 path = current.substr( pos );
135 pos = current.find(
'/' );
136 if( pos == std::string::npos )
140 hostInfo = current.substr( 0, pos );
141 path = current.substr( pos+1 );
145 if( !ParseHostInfo( hostInfo ) )
151 if( !ParsePath( path ) )
162 std::string urlLog = url;
174 urlLog.c_str(), pProtocol.c_str(), pUserName.c_str(),
175 pPassword.c_str(), pHostName.c_str(), pPort, pPath.c_str() );
182 bool URL::ParseHostInfo(
const std::string hostInfo )
184 if( pProtocol ==
"stdio" )
187 if( pProtocol.empty() || hostInfo.empty() )
190 size_t pos = hostInfo.find(
"@" );
191 std::string hostPort;
196 if( pos != std::string::npos )
198 std::string userPass = hostInfo.substr( 0, pos );
199 hostPort = hostInfo.substr( pos+1 );
200 pos = userPass.find(
":" );
205 if( pos != std::string::npos )
207 pUserName = userPass.substr( 0, pos );
208 pPassword = userPass.substr( pos+1 );
214 pUserName = userPass;
226 if( hostPort.length() >= 3 && hostPort[0] ==
'[' )
228 pos = hostPort.find(
"]" );
229 if( pos != std::string::npos )
231 pHostName = hostPort.substr( 0, pos+1 );
232 hostPort.erase( 0, pos+2 );
237 pos = pHostName.find(
"." );
238 const size_t pos2 = pHostName.find(
"[::" );
239 if( pos != std::string::npos && pos2 != std::string::npos )
241 std::string hl = pHostName;
242 std::transform(hl.begin(), hl.end(), hl.begin(),
243 [](
unsigned char c){ return std::tolower(c); });
244 const size_t pos3 = hl.find(
"[::ffff:" );
245 if ( pos3 != std::string::npos )
247 pHostName.erase( 0, 8 );
248 pHostName.erase( pHostName.length()-1, 1 );
252 pHostName.erase( 0, 3 );
253 pHostName.erase( pHostName.length()-1, 1 );
260 pos = hostPort.find(
":" );
261 if( pos != std::string::npos )
263 pHostName = hostPort.substr( 0, pos );
264 hostPort.erase( 0, pos+1 );
268 pHostName = hostPort;
271 if( pHostName.empty() )
278 if( !hostPort.empty() )
281 pPort = ::strtol( hostPort.c_str(), &result, 10 );
282 if( *result !=
'\0' || pPort < 0 || pPort > 65535 )
293 bool URL::ParsePath(
const std::string &path )
295 size_t pos = path.find(
"?" );
296 if( pos != std::string::npos )
298 pPath = path.substr( 0, pos );
299 SetParams( path.substr( pos+1, path.length() ) );
306 std::string::iterator back = pPath.end() - 1;
307 if( pProtocol ==
"file" && *back ==
'/' )
320 std::ostringstream o;
333 std::ostringstream o;
346 std::ostringstream o;
347 o << pProtocol <<
"://";
348 if( pProtocol ==
"file" )
351 o << pHostName <<
":" << pPort <<
"/";
369 auto itr = pParams.find(
"xrd.logintoken" );
370 if( itr == pParams.end() )
380 if( pParams.empty() )
383 std::ostringstream o;
385 ParamsMap::const_iterator it;
386 for( it = pParams.begin(); it != pParams.end(); ++it )
389 if( filter && it->first.compare( 0, 6,
"xrdcl." ) == 0 )
391 if( it != pParams.begin() ) o <<
"&";
392 o << it->first <<
"=" << it->second;
394 std::string ret = o.str();
395 if( ret ==
"?" ) ret.clear();
405 std::string p = params;
413 std::vector<std::string> paramsVect;
414 std::vector<std::string>::iterator it;
416 for( it = paramsVect.begin(); it != paramsVect.end(); ++it )
418 if( it->empty() )
continue;
419 size_t qpos = it->find(
'?' );
420 if( qpos != std::string::npos )
422 pParams[
"xrd.logintoken"] = it->substr( qpos + 1 );
425 size_t pos = it->find(
"=" );
426 if( pos == std::string::npos )
429 pParams[it->substr(0, pos)] = it->substr( pos+1, it->length() );
454 if( pProtocol.empty() )
456 if( pProtocol ==
"file" && pPath.empty() )
458 if( pProtocol ==
"stdio" && pPath !=
"-" )
460 if( pProtocol !=
"file" && pProtocol !=
"stdio" && pHostName.empty() )
469 env->
GetInt(
"MetalinkProcessing", mlProcessing );
470 if( !mlProcessing )
return false;
471 return PathEndsWith(
".meta4" ) || PathEndsWith(
".metalink" );
476 return pProtocol ==
"file" && pHostName ==
"localhost";
484 return ( pProtocol ==
"roots" || pProtocol ==
"xroots" );
492 ParamsMap::const_iterator itr = pParams.find(
"xrdcl.intent" );
493 if( itr != pParams.end() )
494 return itr->second ==
"tpc";
502 bool URL::PathEndsWith(
const std::string & sufix)
const
504 if (sufix.size() > pPath.size())
return false;
505 return std::equal(sufix.rbegin(), sufix.rend(), pPath.rbegin() );
514 std::string ret = pProtocol +
"://" + pHostId +
"/";
517 std::string keys[] = {
"xrdcl.intent",
523 size_t size =
sizeof( keys ) /
sizeof( std::string );
525 for(
size_t i = 0; i < size; ++i )
527 ParamsMap::const_iterator itr = pParams.find( keys[i] );
528 if( itr != pParams.end() )
530 ret += hascgi ?
'&' :
'?';
544 void URL::ComputeHostId()
546 std::ostringstream o;
547 if( !pUserName.empty() )
550 if( !pPassword.empty() )
551 o <<
":" << pPassword;
554 if( pProtocol ==
"file" )
557 o << pHostName <<
":" << pPort;
564 void URL::ComputeURL()
570 std::ostringstream o;
571 if( !pProtocol.empty() )
572 o << pProtocol <<
"://";
574 if( !pUserName.empty() )
577 if( !pPassword.empty() )
578 o <<
":" << pPassword;
582 if( !pHostName.empty() )
584 if( pProtocol ==
"file" )
587 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