00001 //------------------------------------------------------------------------------ 00002 // Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN) 00003 // Author: Lukasz Janyst <ljanyst@cern.ch> 00004 //------------------------------------------------------------------------------ 00005 // XRootD is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU Lesser General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // XRootD is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public License 00016 // along with XRootD. If not, see <http://www.gnu.org/licenses/>. 00017 //------------------------------------------------------------------------------ 00018 00019 #ifndef __XRD_CL_URL_HH__ 00020 #define __XRD_CL_URL_HH__ 00021 00022 #include <string> 00023 #include <map> 00024 00025 namespace XrdCl 00026 { 00027 //---------------------------------------------------------------------------- 00029 //---------------------------------------------------------------------------- 00030 class URL 00031 { 00032 public: 00033 typedef std::map<std::string, std::string> ParamsMap; 00034 00035 00036 //------------------------------------------------------------------------ 00038 //------------------------------------------------------------------------ 00039 URL(); 00040 00041 //------------------------------------------------------------------------ 00046 //------------------------------------------------------------------------ 00047 URL( const std::string &url ); 00048 00049 //------------------------------------------------------------------------ 00054 //------------------------------------------------------------------------ 00055 URL( const char *url ); 00056 00057 //------------------------------------------------------------------------ 00059 //------------------------------------------------------------------------ 00060 bool IsValid() const; 00061 00062 //------------------------------------------------------------------------ 00064 //------------------------------------------------------------------------ 00065 bool IsMetalink() const; 00066 00067 //------------------------------------------------------------------------ 00070 //------------------------------------------------------------------------ 00071 bool IsLocalFile() const; 00072 00073 //------------------------------------------------------------------------ 00075 //------------------------------------------------------------------------ 00076 std::string GetURL() const 00077 { 00078 return pURL; 00079 } 00080 00081 //------------------------------------------------------------------------ 00083 //------------------------------------------------------------------------ 00084 std::string GetHostId() const 00085 { 00086 return pHostId; 00087 } 00088 00089 //------------------------------------------------------------------------ 00091 //------------------------------------------------------------------------ 00092 std::string GetLocation() const; 00093 00094 //------------------------------------------------------------------------ 00096 //------------------------------------------------------------------------ 00097 const std::string &GetProtocol() const 00098 { 00099 return pProtocol; 00100 } 00101 00102 //------------------------------------------------------------------------ 00104 //------------------------------------------------------------------------ 00105 void SetProtocol( const std::string &protocol ) 00106 { 00107 pProtocol = protocol; 00108 ComputeURL(); 00109 } 00110 00111 //------------------------------------------------------------------------ 00113 //------------------------------------------------------------------------ 00114 const std::string &GetUserName() const 00115 { 00116 return pUserName; 00117 } 00118 00119 //------------------------------------------------------------------------ 00121 //------------------------------------------------------------------------ 00122 void SetUserName( const std::string &userName ) 00123 { 00124 pUserName = userName; 00125 ComputeHostId(); 00126 ComputeURL(); 00127 } 00128 00129 //------------------------------------------------------------------------ 00131 //------------------------------------------------------------------------ 00132 const std::string &GetPassword() const 00133 { 00134 return pPassword; 00135 } 00136 00137 //------------------------------------------------------------------------ 00139 //------------------------------------------------------------------------ 00140 void SetPassword( const std::string &password ) 00141 { 00142 pPassword = password; 00143 ComputeURL(); 00144 } 00145 00146 //------------------------------------------------------------------------ 00148 //------------------------------------------------------------------------ 00149 const std::string &GetHostName() const 00150 { 00151 return pHostName; 00152 } 00153 00154 //------------------------------------------------------------------------ 00156 //------------------------------------------------------------------------ 00157 void SetHostName( const std::string &hostName ) 00158 { 00159 pHostName = hostName; 00160 ComputeHostId(); 00161 ComputeURL(); 00162 } 00163 00164 //------------------------------------------------------------------------ 00166 //------------------------------------------------------------------------ 00167 int GetPort() const 00168 { 00169 return pPort; 00170 } 00171 00172 //------------------------------------------------------------------------ 00173 // Set port 00174 //------------------------------------------------------------------------ 00175 void SetPort( int port ) 00176 { 00177 pPort = port; 00178 ComputeHostId(); 00179 ComputeURL(); 00180 } 00181 00182 //------------------------------------------------------------------------ 00183 // Set host and port 00184 //------------------------------------------------------------------------ 00185 void SetHostPort( const std::string &hostName, int port ) 00186 { 00187 pHostName = hostName; 00188 pPort = port; 00189 ComputeHostId(); 00190 ComputeURL(); 00191 } 00192 00193 //------------------------------------------------------------------------ 00195 //------------------------------------------------------------------------ 00196 const std::string &GetPath() const 00197 { 00198 return pPath; 00199 } 00200 00201 //------------------------------------------------------------------------ 00203 //------------------------------------------------------------------------ 00204 void SetPath( const std::string &path ) 00205 { 00206 pPath = path; 00207 ComputeURL(); 00208 } 00209 00210 //------------------------------------------------------------------------ 00212 //------------------------------------------------------------------------ 00213 std::string GetPathWithParams() const; 00214 00215 //------------------------------------------------------------------------ 00217 //------------------------------------------------------------------------ 00218 std::string GetPathWithFilteredParams() const; 00219 00220 //------------------------------------------------------------------------ 00222 //------------------------------------------------------------------------ 00223 const ParamsMap &GetParams() const 00224 { 00225 return pParams; 00226 } 00227 00228 //------------------------------------------------------------------------ 00230 //------------------------------------------------------------------------ 00231 std::string GetParamsAsString() const; 00232 00233 //------------------------------------------------------------------------ 00237 //------------------------------------------------------------------------ 00238 std::string GetParamsAsString( bool filter ) const; 00239 00240 //------------------------------------------------------------------------ 00242 //------------------------------------------------------------------------ 00243 void SetParams( const std::string ¶ms ); 00244 00245 //------------------------------------------------------------------------ 00247 //------------------------------------------------------------------------ 00248 void SetParams( const ParamsMap ¶ms ) 00249 { 00250 pParams = params; 00251 ComputeURL(); 00252 } 00253 00254 //------------------------------------------------------------------------ 00256 //------------------------------------------------------------------------ 00257 bool FromString( const std::string &url ); 00258 00259 //------------------------------------------------------------------------ 00261 //------------------------------------------------------------------------ 00262 void Clear(); 00263 00264 private: 00265 bool ParseHostInfo( const std::string hhostInfo ); 00266 bool ParsePath( const std::string &path ); 00267 void ComputeHostId(); 00268 void ComputeURL(); 00269 bool PathEndsWith( const std::string & sufix ) const; 00270 std::string pHostId; 00271 std::string pProtocol; 00272 std::string pUserName; 00273 std::string pPassword; 00274 std::string pHostName; 00275 int pPort; 00276 std::string pPath; 00277 ParamsMap pParams; 00278 std::string pURL; 00279 00280 }; 00281 } 00282 00283 #endif // __XRD_CL_URL_HH__