Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/xrootd/XrdCl/XrdClURL.hh was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 //------------------------------------------------------------------------------
0002 // Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN)
0003 // Author: Lukasz Janyst <ljanyst@cern.ch>
0004 //------------------------------------------------------------------------------
0005 // XRootD is free software: you can redistribute it and/or modify
0006 // it under the terms of the GNU Lesser General Public License as published by
0007 // the Free Software Foundation, either version 3 of the License, or
0008 // (at your option) any later version.
0009 //
0010 // XRootD is distributed in the hope that it will be useful,
0011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 // GNU General Public License for more details.
0014 //
0015 // You should have received a copy of the GNU Lesser General Public License
0016 // along with XRootD.  If not, see <http://www.gnu.org/licenses/>.
0017 //------------------------------------------------------------------------------
0018 
0019 #ifndef __XRD_CL_URL_HH__
0020 #define __XRD_CL_URL_HH__
0021 
0022 #include <string>
0023 #include <map>
0024 
0025 namespace XrdCl
0026 {
0027   //----------------------------------------------------------------------------
0028   //! URL representation
0029   //----------------------------------------------------------------------------
0030   class URL
0031   {
0032     public:
0033       typedef std::map<std::string, std::string> ParamsMap; //!< Map of get
0034                                                             //!< params
0035 
0036       //------------------------------------------------------------------------
0037       //! Default constructor
0038       //------------------------------------------------------------------------
0039       URL();
0040 
0041       //------------------------------------------------------------------------
0042       //! Constructor
0043       //!
0044       //! @param url  an url in format:
0045       //!             protocol://user:password\@host:port/path?param1=x&param2=y
0046       //------------------------------------------------------------------------
0047       URL( const std::string &url );
0048 
0049       //------------------------------------------------------------------------
0050       //! Constructor
0051       //!
0052       //! @param url  an url in format:
0053       //!             protocol://user:password\@host:port/path?param1=x&param2=y
0054       //------------------------------------------------------------------------
0055       URL( const char *url );
0056 
0057       //------------------------------------------------------------------------
0058       //! Is the url valid
0059       //------------------------------------------------------------------------
0060       bool IsValid() const;
0061 
0062       //------------------------------------------------------------------------
0063       //! Is it a URL to a metalink
0064       //------------------------------------------------------------------------
0065       bool IsMetalink() const;
0066 
0067       //------------------------------------------------------------------------
0068       //! Is it a URL to a local file
0069       //! (file://localhost
0070       //------------------------------------------------------------------------
0071       bool IsLocalFile() const;
0072 
0073       //------------------------------------------------------------------------
0074       //! Does the protocol indicate encryption
0075       //------------------------------------------------------------------------
0076       bool IsSecure() const;
0077 
0078       //------------------------------------------------------------------------
0079       //! Is the URL used in TPC context
0080       //------------------------------------------------------------------------
0081       bool IsTPC() const;
0082 
0083       //------------------------------------------------------------------------
0084       //! Get the URL
0085       //------------------------------------------------------------------------
0086       std::string GetURL() const
0087       {
0088         return pURL;
0089       }
0090 
0091       //------------------------------------------------------------------------
0092       //! Get the URL with authz information obfuscated
0093       //------------------------------------------------------------------------
0094       std::string GetObfuscatedURL() const;
0095 
0096       //------------------------------------------------------------------------
0097       //! Get the host part of the URL (user:password\@host:port)
0098       //------------------------------------------------------------------------
0099       std::string GetHostId() const
0100       {
0101         return pHostId;
0102       }
0103 
0104       //------------------------------------------------------------------------
0105       //! Get the host part of the URL (user:password\@host:port) plus channel
0106       //! specific CGI (xrdcl.identity & xrd.gsiusrpxy)
0107       //------------------------------------------------------------------------
0108       std::string GetChannelId() const;
0109 
0110       //------------------------------------------------------------------------
0111       //! Get location (protocol://host:port/path)
0112       //------------------------------------------------------------------------
0113       std::string GetLocation() const;
0114 
0115       //------------------------------------------------------------------------
0116       //! Get the protocol
0117       //------------------------------------------------------------------------
0118       const std::string &GetProtocol() const
0119       {
0120         return pProtocol;
0121       }
0122 
0123       //------------------------------------------------------------------------
0124       //! Set protocol
0125       //------------------------------------------------------------------------
0126       void SetProtocol( const std::string &protocol )
0127       {
0128         pProtocol = protocol;
0129         ComputeURL();
0130       }
0131 
0132       //------------------------------------------------------------------------
0133       //! Get the username
0134       //------------------------------------------------------------------------
0135       const std::string &GetUserName() const
0136       {
0137         return pUserName;
0138       }
0139 
0140       //------------------------------------------------------------------------
0141       //! Set the username
0142       //------------------------------------------------------------------------
0143       void SetUserName( const std::string &userName )
0144       {
0145         pUserName = userName;
0146         ComputeHostId();
0147         ComputeURL();
0148       }
0149 
0150       //------------------------------------------------------------------------
0151       //! Get the password
0152       //------------------------------------------------------------------------
0153       const std::string &GetPassword() const
0154       {
0155         return pPassword;
0156       }
0157 
0158       //------------------------------------------------------------------------
0159       //! Set the password
0160       //------------------------------------------------------------------------
0161       void SetPassword( const std::string &password )
0162       {
0163         pPassword = password;
0164         ComputeURL();
0165       }
0166 
0167       //------------------------------------------------------------------------
0168       //! Get the name of the target host
0169       //------------------------------------------------------------------------
0170       const std::string &GetHostName() const
0171       {
0172         return pHostName;
0173       }
0174 
0175       //------------------------------------------------------------------------
0176       //! Set the host name
0177       //------------------------------------------------------------------------
0178       void SetHostName( const std::string &hostName )
0179       {
0180         pHostName = hostName;
0181         ComputeHostId();
0182         ComputeURL();
0183       }
0184 
0185       //------------------------------------------------------------------------
0186       //! Get the target port
0187       //------------------------------------------------------------------------
0188       int GetPort() const
0189       {
0190         return pPort;
0191       }
0192 
0193       //------------------------------------------------------------------------
0194       // Set port
0195       //------------------------------------------------------------------------
0196       void SetPort( int port )
0197       {
0198         pPort = port;
0199         ComputeHostId();
0200         ComputeURL();
0201       }
0202 
0203       //------------------------------------------------------------------------
0204       // Set host and port
0205       //------------------------------------------------------------------------
0206       void SetHostPort( const std::string &hostName, int port )
0207       {
0208         pHostName = hostName;
0209         pPort     = port;
0210         ComputeHostId();
0211         ComputeURL();
0212       }
0213 
0214       //------------------------------------------------------------------------
0215       //! Get the path
0216       //------------------------------------------------------------------------
0217       const std::string &GetPath() const
0218       {
0219         return pPath;
0220       }
0221 
0222       //------------------------------------------------------------------------
0223       //! Set the path
0224       //------------------------------------------------------------------------
0225       void SetPath( const std::string &path )
0226       {
0227         pPath = path;
0228         ComputeURL();
0229       }
0230 
0231       //------------------------------------------------------------------------
0232       //! Get the path with params
0233       //------------------------------------------------------------------------
0234       std::string GetPathWithParams() const;
0235 
0236       //------------------------------------------------------------------------
0237       //! Get the path with params, filteres out 'xrdcl.'
0238       //------------------------------------------------------------------------
0239       std::string GetPathWithFilteredParams() const;
0240 
0241       //------------------------------------------------------------------------
0242       //! Get the URL params
0243       //------------------------------------------------------------------------
0244       const ParamsMap &GetParams() const
0245       {
0246         return pParams;
0247       }
0248 
0249       //------------------------------------------------------------------------
0250       //! Get the URL params as string
0251       //------------------------------------------------------------------------
0252       std::string GetParamsAsString() const;
0253 
0254       //------------------------------------------------------------------------
0255       //! Get the login token if present in the opaque info
0256       //------------------------------------------------------------------------
0257       std::string GetLoginToken() const;
0258 
0259       //------------------------------------------------------------------------
0260       //! Get the URL params as string
0261       //!
0262       //! @param filter : if set to true filters out 'xrdcl.'
0263       //------------------------------------------------------------------------
0264       std::string GetParamsAsString( bool filter ) const;
0265 
0266       //------------------------------------------------------------------------
0267       //! Set params
0268       //------------------------------------------------------------------------
0269       void SetParams( const std::string &params );
0270 
0271       //------------------------------------------------------------------------
0272       //! Set params
0273       //------------------------------------------------------------------------
0274       void SetParams( const ParamsMap &params )
0275       {
0276         pParams = params;
0277         ComputeURL();
0278       }
0279 
0280       //------------------------------------------------------------------------
0281       //! Parse a string and fill the URL fields
0282       //------------------------------------------------------------------------
0283       bool FromString( const std::string &url );
0284 
0285       //------------------------------------------------------------------------
0286       //! Clear the url
0287       //------------------------------------------------------------------------
0288       void Clear();
0289 
0290     private:
0291       bool ParseHostInfo( const std::string hhostInfo );
0292       bool ParsePath( const std::string &path );
0293       void ComputeHostId();
0294       void ComputeURL();
0295       bool PathEndsWith( const std::string & sufix ) const;
0296       std::string pHostId;
0297       std::string pProtocol;
0298       std::string pUserName;
0299       std::string pPassword;
0300       std::string pHostName;
0301       int         pPort;
0302       std::string pPath;
0303       ParamsMap   pParams;
0304       std::string pURL;
0305 
0306   };
0307 }
0308 
0309 #endif // __XRD_CL_URL_HH__