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 //------------------------------------------------------------------------ 00051 //------------------------------------------------------------------------ 00052 bool IsValid() const; 00053 00054 //------------------------------------------------------------------------ 00056 //------------------------------------------------------------------------ 00057 bool IsMetalink() const; 00058 00059 //------------------------------------------------------------------------ 00062 //------------------------------------------------------------------------ 00063 bool IsLocalFile() const; 00064 00065 //------------------------------------------------------------------------ 00067 //------------------------------------------------------------------------ 00068 std::string GetURL() const 00069 { 00070 return pURL; 00071 } 00072 00073 //------------------------------------------------------------------------ 00075 //------------------------------------------------------------------------ 00076 std::string GetHostId() const 00077 { 00078 return pHostId; 00079 } 00080 00081 //------------------------------------------------------------------------ 00083 //------------------------------------------------------------------------ 00084 std::string GetLocation() const; 00085 00086 //------------------------------------------------------------------------ 00088 //------------------------------------------------------------------------ 00089 const std::string &GetProtocol() const 00090 { 00091 return pProtocol; 00092 } 00093 00094 //------------------------------------------------------------------------ 00096 //------------------------------------------------------------------------ 00097 void SetProtocol( const std::string &protocol ) 00098 { 00099 pProtocol = protocol; 00100 ComputeURL(); 00101 } 00102 00103 //------------------------------------------------------------------------ 00105 //------------------------------------------------------------------------ 00106 const std::string &GetUserName() const 00107 { 00108 return pUserName; 00109 } 00110 00111 //------------------------------------------------------------------------ 00113 //------------------------------------------------------------------------ 00114 void SetUserName( const std::string &userName ) 00115 { 00116 pUserName = userName; 00117 ComputeHostId(); 00118 ComputeURL(); 00119 } 00120 00121 //------------------------------------------------------------------------ 00123 //------------------------------------------------------------------------ 00124 const std::string &GetPassword() const 00125 { 00126 return pPassword; 00127 } 00128 00129 //------------------------------------------------------------------------ 00131 //------------------------------------------------------------------------ 00132 void SetPassword( const std::string &password ) 00133 { 00134 pPassword = password; 00135 ComputeURL(); 00136 } 00137 00138 //------------------------------------------------------------------------ 00140 //------------------------------------------------------------------------ 00141 const std::string &GetHostName() const 00142 { 00143 return pHostName; 00144 } 00145 00146 //------------------------------------------------------------------------ 00148 //------------------------------------------------------------------------ 00149 void SetHostName( const std::string &hostName ) 00150 { 00151 pHostName = hostName; 00152 ComputeHostId(); 00153 ComputeURL(); 00154 } 00155 00156 //------------------------------------------------------------------------ 00158 //------------------------------------------------------------------------ 00159 int GetPort() const 00160 { 00161 return pPort; 00162 } 00163 00164 //------------------------------------------------------------------------ 00165 // Set port 00166 //------------------------------------------------------------------------ 00167 void SetPort( int port ) 00168 { 00169 pPort = port; 00170 ComputeHostId(); 00171 ComputeURL(); 00172 } 00173 00174 //------------------------------------------------------------------------ 00175 // Set host and port 00176 //------------------------------------------------------------------------ 00177 void SetHostPort( const std::string &hostName, int port ) 00178 { 00179 pHostName = hostName; 00180 pPort = port; 00181 ComputeHostId(); 00182 ComputeURL(); 00183 } 00184 00185 //------------------------------------------------------------------------ 00187 //------------------------------------------------------------------------ 00188 const std::string &GetPath() const 00189 { 00190 return pPath; 00191 } 00192 00193 //------------------------------------------------------------------------ 00195 //------------------------------------------------------------------------ 00196 void SetPath( const std::string &path ) 00197 { 00198 pPath = path; 00199 ComputeURL(); 00200 } 00201 00202 //------------------------------------------------------------------------ 00204 //------------------------------------------------------------------------ 00205 std::string GetPathWithParams() const; 00206 00207 //------------------------------------------------------------------------ 00209 //------------------------------------------------------------------------ 00210 std::string GetPathWithFilteredParams() const; 00211 00212 //------------------------------------------------------------------------ 00214 //------------------------------------------------------------------------ 00215 const ParamsMap &GetParams() const 00216 { 00217 return pParams; 00218 } 00219 00220 //------------------------------------------------------------------------ 00222 //------------------------------------------------------------------------ 00223 std::string GetParamsAsString() const; 00224 00225 //------------------------------------------------------------------------ 00229 //------------------------------------------------------------------------ 00230 std::string GetParamsAsString( bool filter ) const; 00231 00232 //------------------------------------------------------------------------ 00234 //------------------------------------------------------------------------ 00235 void SetParams( const std::string ¶ms ); 00236 00237 //------------------------------------------------------------------------ 00239 //------------------------------------------------------------------------ 00240 void SetParams( const ParamsMap ¶ms ) 00241 { 00242 pParams = params; 00243 ComputeURL(); 00244 } 00245 00246 //------------------------------------------------------------------------ 00248 //------------------------------------------------------------------------ 00249 bool FromString( const std::string &url ); 00250 00251 //------------------------------------------------------------------------ 00253 //------------------------------------------------------------------------ 00254 void Clear(); 00255 00256 private: 00257 bool ParseHostInfo( const std::string hhostInfo ); 00258 bool ParsePath( const std::string &path ); 00259 void ComputeHostId(); 00260 void ComputeURL(); 00261 bool PathEndsWith( const std::string & sufix ) const; 00262 std::string pHostId; 00263 std::string pProtocol; 00264 std::string pUserName; 00265 std::string pPassword; 00266 std::string pHostName; 00267 int pPort; 00268 std::string pPath; 00269 ParamsMap pParams; 00270 std::string pURL; 00271 00272 }; 00273 } 00274 00275 #endif // __XRD_CL_URL_HH__