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 //------------------------------------------------------------------------ 00164 // Set host and port 00165 //------------------------------------------------------------------------ 00166 void SetHostPort( const std::string &hostName, int port ) 00167 { 00168 pHostName = hostName; 00169 pPort = port; 00170 ComputeHostId(); 00171 ComputeURL(); 00172 } 00173 00174 //------------------------------------------------------------------------ 00176 //------------------------------------------------------------------------ 00177 const std::string &GetPath() const 00178 { 00179 return pPath; 00180 } 00181 00182 //------------------------------------------------------------------------ 00184 //------------------------------------------------------------------------ 00185 void SetPath( const std::string &path ) 00186 { 00187 pPath = path; 00188 ComputeURL(); 00189 } 00190 00191 //------------------------------------------------------------------------ 00193 //------------------------------------------------------------------------ 00194 std::string GetPathWithParams() const; 00195 00196 //------------------------------------------------------------------------ 00198 //------------------------------------------------------------------------ 00199 const ParamsMap &GetParams() const 00200 { 00201 return pParams; 00202 } 00203 00204 //------------------------------------------------------------------------ 00206 //------------------------------------------------------------------------ 00207 std::string GetParamsAsString() const; 00208 00209 //------------------------------------------------------------------------ 00211 //------------------------------------------------------------------------ 00212 void SetParams( const std::string ¶ms ); 00213 00214 //------------------------------------------------------------------------ 00216 //------------------------------------------------------------------------ 00217 void SetParams( const ParamsMap ¶ms ) 00218 { 00219 pParams = params; 00220 ComputeURL(); 00221 } 00222 00223 //------------------------------------------------------------------------ 00225 //------------------------------------------------------------------------ 00226 bool FromString( const std::string &url ); 00227 00228 //------------------------------------------------------------------------ 00230 //------------------------------------------------------------------------ 00231 void Clear(); 00232 00233 private: 00234 bool ParseHostInfo( const std::string hhostInfo ); 00235 bool ParsePath( const std::string &path ); 00236 void ComputeHostId(); 00237 void ComputeURL(); 00238 std::string pHostId; 00239 std::string pProtocol; 00240 std::string pUserName; 00241 std::string pPassword; 00242 std::string pHostName; 00243 int pPort; 00244 std::string pPath; 00245 ParamsMap pParams; 00246 std::string pURL; 00247 00248 }; 00249 } 00250 00251 #endif // __XRD_CL_URL_HH__