xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
XrdClURL.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN)
3 // Author: Lukasz Janyst <ljanyst@cern.ch>
4 //------------------------------------------------------------------------------
5 // XRootD is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // XRootD is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with XRootD. If not, see <http://www.gnu.org/licenses/>.
17 //------------------------------------------------------------------------------
18 
19 #ifndef __XRD_CL_URL_HH__
20 #define __XRD_CL_URL_HH__
21 
22 #include <string>
23 #include <map>
24 
25 namespace XrdCl
26 {
27  //----------------------------------------------------------------------------
29  //----------------------------------------------------------------------------
30  class URL
31  {
32  public:
33  typedef std::map<std::string, std::string> ParamsMap;
34 
36  //------------------------------------------------------------------------
38  //------------------------------------------------------------------------
39  URL();
40 
41  //------------------------------------------------------------------------
46  //------------------------------------------------------------------------
47  URL( const std::string &url );
48 
49  //------------------------------------------------------------------------
54  //------------------------------------------------------------------------
55  URL( const char *url );
56 
57  //------------------------------------------------------------------------
59  //------------------------------------------------------------------------
60  bool IsValid() const;
61 
62  //------------------------------------------------------------------------
64  //------------------------------------------------------------------------
65  bool IsMetalink() const;
66 
67  //------------------------------------------------------------------------
70  //------------------------------------------------------------------------
71  bool IsLocalFile() const;
72 
73  //------------------------------------------------------------------------
75  //------------------------------------------------------------------------
76  std::string GetURL() const
77  {
78  return pURL;
79  }
80 
81  //------------------------------------------------------------------------
83  //------------------------------------------------------------------------
84  std::string GetHostId() const
85  {
86  return pHostId;
87  }
88 
89  //------------------------------------------------------------------------
91  //------------------------------------------------------------------------
92  std::string GetLocation() const;
93 
94  //------------------------------------------------------------------------
96  //------------------------------------------------------------------------
97  const std::string &GetProtocol() const
98  {
99  return pProtocol;
100  }
101 
102  //------------------------------------------------------------------------
104  //------------------------------------------------------------------------
105  void SetProtocol( const std::string &protocol )
106  {
107  pProtocol = protocol;
108  ComputeURL();
109  }
110 
111  //------------------------------------------------------------------------
113  //------------------------------------------------------------------------
114  const std::string &GetUserName() const
115  {
116  return pUserName;
117  }
118 
119  //------------------------------------------------------------------------
121  //------------------------------------------------------------------------
122  void SetUserName( const std::string &userName )
123  {
124  pUserName = userName;
125  ComputeHostId();
126  ComputeURL();
127  }
128 
129  //------------------------------------------------------------------------
131  //------------------------------------------------------------------------
132  const std::string &GetPassword() const
133  {
134  return pPassword;
135  }
136 
137  //------------------------------------------------------------------------
139  //------------------------------------------------------------------------
140  void SetPassword( const std::string &password )
141  {
142  pPassword = password;
143  ComputeURL();
144  }
145 
146  //------------------------------------------------------------------------
148  //------------------------------------------------------------------------
149  const std::string &GetHostName() const
150  {
151  return pHostName;
152  }
153 
154  //------------------------------------------------------------------------
156  //------------------------------------------------------------------------
157  void SetHostName( const std::string &hostName )
158  {
159  pHostName = hostName;
160  ComputeHostId();
161  ComputeURL();
162  }
163 
164  //------------------------------------------------------------------------
166  //------------------------------------------------------------------------
167  int GetPort() const
168  {
169  return pPort;
170  }
171 
172  //------------------------------------------------------------------------
173  // Set port
174  //------------------------------------------------------------------------
175  void SetPort( int port )
176  {
177  pPort = port;
178  ComputeHostId();
179  ComputeURL();
180  }
181 
182  //------------------------------------------------------------------------
183  // Set host and port
184  //------------------------------------------------------------------------
185  void SetHostPort( const std::string &hostName, int port )
186  {
187  pHostName = hostName;
188  pPort = port;
189  ComputeHostId();
190  ComputeURL();
191  }
192 
193  //------------------------------------------------------------------------
195  //------------------------------------------------------------------------
196  const std::string &GetPath() const
197  {
198  return pPath;
199  }
200 
201  //------------------------------------------------------------------------
203  //------------------------------------------------------------------------
204  void SetPath( const std::string &path )
205  {
206  pPath = path;
207  ComputeURL();
208  }
209 
210  //------------------------------------------------------------------------
212  //------------------------------------------------------------------------
213  std::string GetPathWithParams() const;
214 
215  //------------------------------------------------------------------------
217  //------------------------------------------------------------------------
218  std::string GetPathWithFilteredParams() const;
219 
220  //------------------------------------------------------------------------
222  //------------------------------------------------------------------------
223  const ParamsMap &GetParams() const
224  {
225  return pParams;
226  }
227 
228  //------------------------------------------------------------------------
230  //------------------------------------------------------------------------
231  std::string GetParamsAsString() const;
232 
233  //------------------------------------------------------------------------
237  //------------------------------------------------------------------------
238  std::string GetParamsAsString( bool filter ) const;
239 
240  //------------------------------------------------------------------------
242  //------------------------------------------------------------------------
243  void SetParams( const std::string &params );
244 
245  //------------------------------------------------------------------------
247  //------------------------------------------------------------------------
248  void SetParams( const ParamsMap &params )
249  {
250  pParams = params;
251  ComputeURL();
252  }
253 
254  //------------------------------------------------------------------------
256  //------------------------------------------------------------------------
257  bool FromString( const std::string &url );
258 
259  //------------------------------------------------------------------------
261  //------------------------------------------------------------------------
262  void Clear();
263 
264  private:
265  bool ParseHostInfo( const std::string hhostInfo );
266  bool ParsePath( const std::string &path );
267  void ComputeHostId();
268  void ComputeURL();
269  bool PathEndsWith( const std::string & sufix ) const;
270  std::string pHostId;
271  std::string pProtocol;
272  std::string pUserName;
273  std::string pPassword;
274  std::string pHostName;
275  int pPort;
276  std::string pPath;
278  std::string pURL;
279 
280  };
281 }
282 
283 #endif // __XRD_CL_URL_HH__
std::map< std::string, std::string > ParamsMap
Definition: XrdClURL.hh:33
bool IsLocalFile() const
std::string GetParamsAsString() const
Get the URL params as string.
void SetProtocol(const std::string &protocol)
Set protocol.
Definition: XrdClURL.hh:105
std::string GetLocation() const
Get location (protocol://host:port/path)
const std::string & GetPassword() const
Get the password.
Definition: XrdClURL.hh:132
std::string GetPathWithFilteredParams() const
Get the path with params, filteres out &#39;xrdcl.&#39;.
bool IsValid() const
Is the url valid.
std::string pHostName
Definition: XrdClURL.hh:274
bool FromString(const std::string &url)
Parse a string and fill the URL fields.
const std::string & GetHostName() const
Get the name of the target host.
Definition: XrdClURL.hh:149
bool ParsePath(const std::string &path)
int GetPort() const
Get the target port.
Definition: XrdClURL.hh:167
bool IsMetalink() const
Is it a URL to a metalink.
const std::string & GetPath() const
Get the path.
Definition: XrdClURL.hh:196
void SetParams(const std::string &params)
Set params.
void SetPath(const std::string &path)
Set the path.
Definition: XrdClURL.hh:204
void SetPort(int port)
Definition: XrdClURL.hh:175
URL()
Default constructor.
const std::string & GetUserName() const
Get the username.
Definition: XrdClURL.hh:114
std::string pPassword
Definition: XrdClURL.hh:273
std::string pPath
Definition: XrdClURL.hh:276
int pPort
Definition: XrdClURL.hh:275
const std::string & GetProtocol() const
Get the protocol.
Definition: XrdClURL.hh:97
void Clear()
Clear the url.
void SetPassword(const std::string &password)
Set the password.
Definition: XrdClURL.hh:140
std::string GetHostId() const
Get the host part of the URL (user:password@host:port)
Definition: XrdClURL.hh:84
std::string pUserName
Definition: XrdClURL.hh:272
std::string pURL
Definition: XrdClURL.hh:278
std::string GetURL() const
Get the URL.
Definition: XrdClURL.hh:76
bool ParseHostInfo(const std::string hhostInfo)
std::string pProtocol
Definition: XrdClURL.hh:271
URL representation.
Definition: XrdClURL.hh:30
void SetUserName(const std::string &userName)
Set the username.
Definition: XrdClURL.hh:122
ParamsMap pParams
Definition: XrdClURL.hh:277
void SetParams(const ParamsMap &params)
Set params.
Definition: XrdClURL.hh:248
void ComputeURL()
void SetHostName(const std::string &hostName)
Set the host name.
Definition: XrdClURL.hh:157
bool PathEndsWith(const std::string &sufix) const
const ParamsMap & GetParams() const
Get the URL params.
Definition: XrdClURL.hh:223
void SetHostPort(const std::string &hostName, int port)
Definition: XrdClURL.hh:185
std::string pHostId
Definition: XrdClURL.hh:270
std::string GetPathWithParams() const
Get the path with params.
void ComputeHostId()