|
||||
File indexing completed on 2025-01-18 10:15:40
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¶m2=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¶m2=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 host part of the URL (user:password\@host:port) 0093 //------------------------------------------------------------------------ 0094 std::string GetHostId() const 0095 { 0096 return pHostId; 0097 } 0098 0099 //------------------------------------------------------------------------ 0100 //! Get the host part of the URL (user:password\@host:port) plus channel 0101 //! specific CGI (xrdcl.identity & xrd.gsiusrpxy) 0102 //------------------------------------------------------------------------ 0103 std::string GetChannelId() const; 0104 0105 //------------------------------------------------------------------------ 0106 //! Get location (protocol://host:port/path) 0107 //------------------------------------------------------------------------ 0108 std::string GetLocation() const; 0109 0110 //------------------------------------------------------------------------ 0111 //! Get the protocol 0112 //------------------------------------------------------------------------ 0113 const std::string &GetProtocol() const 0114 { 0115 return pProtocol; 0116 } 0117 0118 //------------------------------------------------------------------------ 0119 //! Set protocol 0120 //------------------------------------------------------------------------ 0121 void SetProtocol( const std::string &protocol ) 0122 { 0123 pProtocol = protocol; 0124 ComputeURL(); 0125 } 0126 0127 //------------------------------------------------------------------------ 0128 //! Get the username 0129 //------------------------------------------------------------------------ 0130 const std::string &GetUserName() const 0131 { 0132 return pUserName; 0133 } 0134 0135 //------------------------------------------------------------------------ 0136 //! Set the username 0137 //------------------------------------------------------------------------ 0138 void SetUserName( const std::string &userName ) 0139 { 0140 pUserName = userName; 0141 ComputeHostId(); 0142 ComputeURL(); 0143 } 0144 0145 //------------------------------------------------------------------------ 0146 //! Get the password 0147 //------------------------------------------------------------------------ 0148 const std::string &GetPassword() const 0149 { 0150 return pPassword; 0151 } 0152 0153 //------------------------------------------------------------------------ 0154 //! Set the password 0155 //------------------------------------------------------------------------ 0156 void SetPassword( const std::string &password ) 0157 { 0158 pPassword = password; 0159 ComputeURL(); 0160 } 0161 0162 //------------------------------------------------------------------------ 0163 //! Get the name of the target host 0164 //------------------------------------------------------------------------ 0165 const std::string &GetHostName() const 0166 { 0167 return pHostName; 0168 } 0169 0170 //------------------------------------------------------------------------ 0171 //! Set the host name 0172 //------------------------------------------------------------------------ 0173 void SetHostName( const std::string &hostName ) 0174 { 0175 pHostName = hostName; 0176 ComputeHostId(); 0177 ComputeURL(); 0178 } 0179 0180 //------------------------------------------------------------------------ 0181 //! Get the target port 0182 //------------------------------------------------------------------------ 0183 int GetPort() const 0184 { 0185 return pPort; 0186 } 0187 0188 //------------------------------------------------------------------------ 0189 // Set port 0190 //------------------------------------------------------------------------ 0191 void SetPort( int port ) 0192 { 0193 pPort = port; 0194 ComputeHostId(); 0195 ComputeURL(); 0196 } 0197 0198 //------------------------------------------------------------------------ 0199 // Set host and port 0200 //------------------------------------------------------------------------ 0201 void SetHostPort( const std::string &hostName, int port ) 0202 { 0203 pHostName = hostName; 0204 pPort = port; 0205 ComputeHostId(); 0206 ComputeURL(); 0207 } 0208 0209 //------------------------------------------------------------------------ 0210 //! Get the path 0211 //------------------------------------------------------------------------ 0212 const std::string &GetPath() const 0213 { 0214 return pPath; 0215 } 0216 0217 //------------------------------------------------------------------------ 0218 //! Set the path 0219 //------------------------------------------------------------------------ 0220 void SetPath( const std::string &path ) 0221 { 0222 pPath = path; 0223 ComputeURL(); 0224 } 0225 0226 //------------------------------------------------------------------------ 0227 //! Get the path with params 0228 //------------------------------------------------------------------------ 0229 std::string GetPathWithParams() const; 0230 0231 //------------------------------------------------------------------------ 0232 //! Get the path with params, filteres out 'xrdcl.' 0233 //------------------------------------------------------------------------ 0234 std::string GetPathWithFilteredParams() const; 0235 0236 //------------------------------------------------------------------------ 0237 //! Get the URL params 0238 //------------------------------------------------------------------------ 0239 const ParamsMap &GetParams() const 0240 { 0241 return pParams; 0242 } 0243 0244 //------------------------------------------------------------------------ 0245 //! Get the URL params as string 0246 //------------------------------------------------------------------------ 0247 std::string GetParamsAsString() const; 0248 0249 //------------------------------------------------------------------------ 0250 //! Get the login token if present in the opaque info 0251 //------------------------------------------------------------------------ 0252 std::string GetLoginToken() const; 0253 0254 //------------------------------------------------------------------------ 0255 //! Get the URL params as string 0256 //! 0257 //! @param filter : if set to true filters out 'xrdcl.' 0258 //------------------------------------------------------------------------ 0259 std::string GetParamsAsString( bool filter ) const; 0260 0261 //------------------------------------------------------------------------ 0262 //! Set params 0263 //------------------------------------------------------------------------ 0264 void SetParams( const std::string ¶ms ); 0265 0266 //------------------------------------------------------------------------ 0267 //! Set params 0268 //------------------------------------------------------------------------ 0269 void SetParams( const ParamsMap ¶ms ) 0270 { 0271 pParams = params; 0272 ComputeURL(); 0273 } 0274 0275 //------------------------------------------------------------------------ 0276 //! Parse a string and fill the URL fields 0277 //------------------------------------------------------------------------ 0278 bool FromString( const std::string &url ); 0279 0280 //------------------------------------------------------------------------ 0281 //! Clear the url 0282 //------------------------------------------------------------------------ 0283 void Clear(); 0284 0285 private: 0286 bool ParseHostInfo( const std::string hhostInfo ); 0287 bool ParsePath( const std::string &path ); 0288 void ComputeHostId(); 0289 void ComputeURL(); 0290 bool PathEndsWith( const std::string & sufix ) const; 0291 std::string pHostId; 0292 std::string pProtocol; 0293 std::string pUserName; 0294 std::string pPassword; 0295 std::string pHostName; 0296 int pPort; 0297 std::string pPath; 0298 ParamsMap pParams; 0299 std::string pURL; 0300 0301 }; 0302 } 0303 0304 #endif // __XRD_CL_URL_HH__
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |