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 std::string GetURL() const 00058 { 00059 return pURL; 00060 } 00061 00062 //------------------------------------------------------------------------ 00064 //------------------------------------------------------------------------ 00065 std::string GetHostId() const 00066 { 00067 return pHostId; 00068 } 00069 00070 //------------------------------------------------------------------------ 00072 //------------------------------------------------------------------------ 00073 std::string GetLocation() const; 00074 00075 //------------------------------------------------------------------------ 00077 //------------------------------------------------------------------------ 00078 const std::string &GetProtocol() const 00079 { 00080 return pProtocol; 00081 } 00082 00083 //------------------------------------------------------------------------ 00085 //------------------------------------------------------------------------ 00086 void SetProtocol( const std::string &protocol ) 00087 { 00088 pProtocol = protocol; 00089 ComputeURL(); 00090 } 00091 00092 //------------------------------------------------------------------------ 00094 //------------------------------------------------------------------------ 00095 const std::string &GetUserName() const 00096 { 00097 return pUserName; 00098 } 00099 00100 //------------------------------------------------------------------------ 00102 //------------------------------------------------------------------------ 00103 void SetUserName( const std::string &userName ) 00104 { 00105 pUserName = userName; 00106 ComputeHostId(); 00107 ComputeURL(); 00108 } 00109 00110 //------------------------------------------------------------------------ 00112 //------------------------------------------------------------------------ 00113 const std::string &GetPassword() const 00114 { 00115 return pPassword; 00116 } 00117 00118 //------------------------------------------------------------------------ 00120 //------------------------------------------------------------------------ 00121 void SetPassword( const std::string &password ) 00122 { 00123 pPassword = password; 00124 ComputeURL(); 00125 } 00126 00127 //------------------------------------------------------------------------ 00129 //------------------------------------------------------------------------ 00130 const std::string &GetHostName() const 00131 { 00132 return pHostName; 00133 } 00134 00135 //------------------------------------------------------------------------ 00137 //------------------------------------------------------------------------ 00138 void SetHostName( const std::string &hostName ) 00139 { 00140 pHostName = hostName; 00141 ComputeHostId(); 00142 ComputeURL(); 00143 } 00144 00145 //------------------------------------------------------------------------ 00147 //------------------------------------------------------------------------ 00148 int GetPort() const 00149 { 00150 return pPort; 00151 } 00152 00153 //------------------------------------------------------------------------ 00154 // Set port 00155 //------------------------------------------------------------------------ 00156 void SetPort( int port ) 00157 { 00158 pPort = port; 00159 ComputeHostId(); 00160 ComputeURL(); 00161 } 00162 00163 //------------------------------------------------------------------------ 00165 //------------------------------------------------------------------------ 00166 const std::string &GetPath() const 00167 { 00168 return pPath; 00169 } 00170 00171 //------------------------------------------------------------------------ 00173 //------------------------------------------------------------------------ 00174 void SetPath( const std::string &path ) 00175 { 00176 pPath = path; 00177 ComputeURL(); 00178 } 00179 00180 //------------------------------------------------------------------------ 00182 //------------------------------------------------------------------------ 00183 std::string GetPathWithParams() const; 00184 00185 //------------------------------------------------------------------------ 00187 //------------------------------------------------------------------------ 00188 const ParamsMap &GetParams() const 00189 { 00190 return pParams; 00191 } 00192 00193 //------------------------------------------------------------------------ 00195 //------------------------------------------------------------------------ 00196 std::string GetParamsAsString() const; 00197 00198 //------------------------------------------------------------------------ 00200 //------------------------------------------------------------------------ 00201 void SetParams( const std::string ¶ms ); 00202 00203 //------------------------------------------------------------------------ 00205 //------------------------------------------------------------------------ 00206 void SetParams( const ParamsMap ¶ms ) 00207 { 00208 pParams = params; 00209 ComputeURL(); 00210 } 00211 00212 //------------------------------------------------------------------------ 00214 //------------------------------------------------------------------------ 00215 bool FromString( const std::string &url ); 00216 00217 //------------------------------------------------------------------------ 00219 //------------------------------------------------------------------------ 00220 void Clear(); 00221 00222 private: 00223 bool ParseHostInfo( const std::string hhostInfo ); 00224 bool ParsePath( const std::string &path ); 00225 void ComputeHostId(); 00226 void ComputeURL(); 00227 std::string pHostId; 00228 std::string pProtocol; 00229 std::string pUserName; 00230 std::string pPassword; 00231 std::string pHostName; 00232 int pPort; 00233 std::string pPath; 00234 ParamsMap pParams; 00235 std::string pURL; 00236 00237 }; 00238 } 00239 00240 #endif // __XRD_CL_URL_HH__