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 bool IsSecure() const; 00077 00078 //------------------------------------------------------------------------ 00080 //------------------------------------------------------------------------ 00081 bool IsTPC() const; 00082 00083 //------------------------------------------------------------------------ 00085 //------------------------------------------------------------------------ 00086 std::string GetURL() const 00087 { 00088 return pURL; 00089 } 00090 00091 //------------------------------------------------------------------------ 00093 //------------------------------------------------------------------------ 00094 std::string GetHostId() const 00095 { 00096 return pHostId; 00097 } 00098 00099 //------------------------------------------------------------------------ 00102 //------------------------------------------------------------------------ 00103 std::string GetChannelId() const; 00104 00105 //------------------------------------------------------------------------ 00107 //------------------------------------------------------------------------ 00108 std::string GetLocation() const; 00109 00110 //------------------------------------------------------------------------ 00112 //------------------------------------------------------------------------ 00113 const std::string &GetProtocol() const 00114 { 00115 return pProtocol; 00116 } 00117 00118 //------------------------------------------------------------------------ 00120 //------------------------------------------------------------------------ 00121 void SetProtocol( const std::string &protocol ) 00122 { 00123 pProtocol = protocol; 00124 ComputeURL(); 00125 } 00126 00127 //------------------------------------------------------------------------ 00129 //------------------------------------------------------------------------ 00130 const std::string &GetUserName() const 00131 { 00132 return pUserName; 00133 } 00134 00135 //------------------------------------------------------------------------ 00137 //------------------------------------------------------------------------ 00138 void SetUserName( const std::string &userName ) 00139 { 00140 pUserName = userName; 00141 ComputeHostId(); 00142 ComputeURL(); 00143 } 00144 00145 //------------------------------------------------------------------------ 00147 //------------------------------------------------------------------------ 00148 const std::string &GetPassword() const 00149 { 00150 return pPassword; 00151 } 00152 00153 //------------------------------------------------------------------------ 00155 //------------------------------------------------------------------------ 00156 void SetPassword( const std::string &password ) 00157 { 00158 pPassword = password; 00159 ComputeURL(); 00160 } 00161 00162 //------------------------------------------------------------------------ 00164 //------------------------------------------------------------------------ 00165 const std::string &GetHostName() const 00166 { 00167 return pHostName; 00168 } 00169 00170 //------------------------------------------------------------------------ 00172 //------------------------------------------------------------------------ 00173 void SetHostName( const std::string &hostName ) 00174 { 00175 pHostName = hostName; 00176 ComputeHostId(); 00177 ComputeURL(); 00178 } 00179 00180 //------------------------------------------------------------------------ 00182 //------------------------------------------------------------------------ 00183 int GetPort() const 00184 { 00185 return pPort; 00186 } 00187 00188 //------------------------------------------------------------------------ 00189 // Set port 00190 //------------------------------------------------------------------------ 00191 void SetPort( int port ) 00192 { 00193 pPort = port; 00194 ComputeHostId(); 00195 ComputeURL(); 00196 } 00197 00198 //------------------------------------------------------------------------ 00199 // Set host and port 00200 //------------------------------------------------------------------------ 00201 void SetHostPort( const std::string &hostName, int port ) 00202 { 00203 pHostName = hostName; 00204 pPort = port; 00205 ComputeHostId(); 00206 ComputeURL(); 00207 } 00208 00209 //------------------------------------------------------------------------ 00211 //------------------------------------------------------------------------ 00212 const std::string &GetPath() const 00213 { 00214 return pPath; 00215 } 00216 00217 //------------------------------------------------------------------------ 00219 //------------------------------------------------------------------------ 00220 void SetPath( const std::string &path ) 00221 { 00222 pPath = path; 00223 ComputeURL(); 00224 } 00225 00226 //------------------------------------------------------------------------ 00228 //------------------------------------------------------------------------ 00229 std::string GetPathWithParams() const; 00230 00231 //------------------------------------------------------------------------ 00233 //------------------------------------------------------------------------ 00234 std::string GetPathWithFilteredParams() const; 00235 00236 //------------------------------------------------------------------------ 00238 //------------------------------------------------------------------------ 00239 const ParamsMap &GetParams() const 00240 { 00241 return pParams; 00242 } 00243 00244 //------------------------------------------------------------------------ 00246 //------------------------------------------------------------------------ 00247 std::string GetParamsAsString() const; 00248 00249 //------------------------------------------------------------------------ 00253 //------------------------------------------------------------------------ 00254 std::string GetParamsAsString( bool filter ) const; 00255 00256 //------------------------------------------------------------------------ 00258 //------------------------------------------------------------------------ 00259 void SetParams( const std::string ¶ms ); 00260 00261 //------------------------------------------------------------------------ 00263 //------------------------------------------------------------------------ 00264 void SetParams( const ParamsMap ¶ms ) 00265 { 00266 pParams = params; 00267 ComputeURL(); 00268 } 00269 00270 //------------------------------------------------------------------------ 00272 //------------------------------------------------------------------------ 00273 bool FromString( const std::string &url ); 00274 00275 //------------------------------------------------------------------------ 00277 //------------------------------------------------------------------------ 00278 void Clear(); 00279 00280 private: 00281 bool ParseHostInfo( const std::string hhostInfo ); 00282 bool ParsePath( const std::string &path ); 00283 void ComputeHostId(); 00284 void ComputeURL(); 00285 bool PathEndsWith( const std::string & sufix ) const; 00286 std::string pHostId; 00287 std::string pProtocol; 00288 std::string pUserName; 00289 std::string pPassword; 00290 std::string pHostName; 00291 int pPort; 00292 std::string pPath; 00293 ParamsMap pParams; 00294 std::string pURL; 00295 00296 }; 00297 } 00298 00299 #endif // __XRD_CL_URL_HH__