65 if( url.length() == 0 )
74 size_t pos = url.find(
"://" );
77 if( pos != std::string::npos )
79 pProtocol = url.substr( 0, pos );
80 current = url.substr( pos+3 );
82 else if( url[0] ==
'/' )
87 else if( url[0] ==
'-' )
102 if (pProtocol ==
"http" || pProtocol ==
"dav") {
105 if (pProtocol ==
"https" || pProtocol ==
"davs") {
113 std::string hostInfo;
115 if( pProtocol ==
"stdio" )
117 else if( pProtocol ==
"file")
119 if( current[0] ==
'/' )
120 current =
"localhost" + current;
121 pos = current.find(
'/' );
122 if( pos == std::string::npos )
126 hostInfo = current.substr( 0, pos );
127 path = current.substr( pos );
132 pos = current.find(
'/' );
133 if( pos == std::string::npos )
137 hostInfo = current.substr( 0, pos );
138 path = current.substr( pos+1 );
142 if( !ParseHostInfo( hostInfo ) )
158 bool URL::ParseHostInfo(
const std::string hostInfo )
160 if( pProtocol ==
"stdio" )
163 if( pProtocol.empty() || hostInfo.empty() )
166 size_t pos = hostInfo.find(
"@" );
167 std::string hostPort;
172 if( pos != std::string::npos )
174 std::string userPass = hostInfo.substr( 0, pos );
175 hostPort = hostInfo.substr( pos+1 );
176 pos = userPass.find(
":" );
181 if( pos != std::string::npos )
183 pUserName = userPass.substr( 0, pos );
184 pPassword = userPass.substr( pos+1 );
190 pUserName = userPass;
202 if( hostPort.length() >= 3 && hostPort[0] ==
'[' )
204 pos = hostPort.find(
"]" );
205 if( pos != std::string::npos )
207 pHostName = hostPort.substr( 0, pos+1 );
208 hostPort.erase( 0, pos+2 );
213 pos = pHostName.find(
"." );
214 const size_t pos2 = pHostName.find(
"[::" );
215 if( pos != std::string::npos && pos2 != std::string::npos )
217 std::string hl = pHostName;
218 std::transform(hl.begin(), hl.end(), hl.begin(),
219 [](
unsigned char c){ return std::tolower(c); });
220 const size_t pos3 = hl.find(
"[::ffff:" );
221 if ( pos3 != std::string::npos )
223 pHostName.erase( 0, 8 );
224 pHostName.erase( pHostName.length()-1, 1 );
228 pHostName.erase( 0, 3 );
229 pHostName.erase( pHostName.length()-1, 1 );
236 pos = hostPort.find(
":" );
237 if( pos != std::string::npos )
239 pHostName = hostPort.substr( 0, pos );
240 hostPort.erase( 0, pos+1 );
244 pHostName = hostPort;
247 if( pHostName.empty() )
254 if( !hostPort.empty() )
257 pPort = ::strtol( hostPort.c_str(), &result, 10 );
258 if( *result !=
'\0' || pPort < 0 || pPort > 65535 )
269 bool URL::ParsePath(
const std::string &path )
271 size_t pos = path.find(
"?" );
272 if( pos != std::string::npos )
274 pPath = path.substr( 0, pos );
275 SetParams( path.substr( pos+1, path.length() ) );
282 std::string::iterator back = pPath.end() - 1;
283 if( pProtocol ==
"file" && *back ==
'/' )
296 std::ostringstream o;
309 std::ostringstream o;
322 std::ostringstream o;
323 o << pProtocol <<
"://";
324 if( pProtocol ==
"file" )
327 o << pHostName <<
":" << pPort <<
"/";
345 auto itr = pParams.find(
"xrd.logintoken" );
346 if( itr == pParams.end() )
356 if( pParams.empty() )
359 std::ostringstream o;
361 ParamsMap::const_iterator it;
362 for( it = pParams.begin(); it != pParams.end(); ++it )
365 if( filter && it->first.compare( 0, 6,
"xrdcl." ) == 0 )
367 if( it != pParams.begin() ) o <<
"&";
368 o << it->first <<
"=" << it->second;
370 std::string ret = o.str();
371 if( ret ==
"?" ) ret.clear();
381 std::string p = params;
389 std::vector<std::string> paramsVect;
390 std::vector<std::string>::iterator it;
392 for( it = paramsVect.begin(); it != paramsVect.end(); ++it )
394 if( it->empty() )
continue;
395 size_t qpos = it->find(
'?' );
396 if( qpos != std::string::npos )
398 pParams[
"xrd.logintoken"] = it->substr( qpos + 1 );
401 size_t pos = it->find(
"=" );
402 if( pos == std::string::npos )
405 pParams[it->substr(0, pos)] = it->substr( pos+1, it->length() );
430 if( pProtocol.empty() )
432 if( pProtocol ==
"file" && pPath.empty() )
434 if( pProtocol ==
"stdio" && pPath !=
"-" )
436 if( pProtocol !=
"file" && pProtocol !=
"stdio" && pHostName.empty() )
445 env->
GetInt(
"MetalinkProcessing", mlProcessing );
446 if( !mlProcessing )
return false;
447 return PathEndsWith(
".meta4" ) || PathEndsWith(
".metalink" );
452 return pProtocol ==
"file" && pHostName ==
"localhost";
460 return ( pProtocol ==
"roots" || pProtocol ==
"xroots" );
468 ParamsMap::const_iterator itr = pParams.find(
"xrdcl.intent" );
469 if( itr != pParams.end() )
470 return itr->second ==
"tpc";
478 bool URL::PathEndsWith(
const std::string & sufix)
const
480 if (sufix.size() > pPath.size())
return false;
481 return std::equal(sufix.rbegin(), sufix.rend(), pPath.rbegin() );
490 std::string ret = pProtocol +
"://" + pHostId +
"/";
493 std::string keys[] = {
"xrdcl.intent",
499 size_t size =
sizeof( keys ) /
sizeof( std::string );
501 for(
size_t i = 0; i < size; ++i )
503 ParamsMap::const_iterator itr = pParams.find( keys[i] );
504 if( itr != pParams.end() )
506 ret += hascgi ?
'&' :
'?';
520 void URL::ComputeHostId()
522 std::ostringstream o;
523 if( !pUserName.empty() )
526 if( !pPassword.empty() )
527 o <<
":" << pPassword;
530 if( pProtocol ==
"file" )
533 o << pHostName <<
":" << pPort;
540 void URL::ComputeURL()
546 std::ostringstream o;
547 if( !pProtocol.empty() )
548 o << pProtocol <<
"://";
550 if( !pUserName.empty() )
553 if( !pPassword.empty() )
554 o <<
":" << pPassword;
558 if( !pHostName.empty() )
560 if( pProtocol ==
"file" )
563 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)
void Error(uint64_t topic, const char *format,...)
Report an error.
void Warning(uint64_t topic, const char *format,...)
Report a warning.
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