xrootd
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  bool IsSecure() const;
77 
78  //------------------------------------------------------------------------
80  //------------------------------------------------------------------------
81  bool IsTPC() const;
82 
83  //------------------------------------------------------------------------
85  //------------------------------------------------------------------------
86  std::string GetURL() const
87  {
88  return pURL;
89  }
90 
91  //------------------------------------------------------------------------
93  //------------------------------------------------------------------------
94  std::string GetHostId() const
95  {
96  return pHostId;
97  }
98 
99  //------------------------------------------------------------------------
102  //------------------------------------------------------------------------
103  std::string GetChannelId() const;
104 
105  //------------------------------------------------------------------------
107  //------------------------------------------------------------------------
108  std::string GetLocation() const;
109 
110  //------------------------------------------------------------------------
112  //------------------------------------------------------------------------
113  const std::string &GetProtocol() const
114  {
115  return pProtocol;
116  }
117 
118  //------------------------------------------------------------------------
120  //------------------------------------------------------------------------
121  void SetProtocol( const std::string &protocol )
122  {
123  pProtocol = protocol;
124  ComputeURL();
125  }
126 
127  //------------------------------------------------------------------------
129  //------------------------------------------------------------------------
130  const std::string &GetUserName() const
131  {
132  return pUserName;
133  }
134 
135  //------------------------------------------------------------------------
137  //------------------------------------------------------------------------
138  void SetUserName( const std::string &userName )
139  {
140  pUserName = userName;
141  ComputeHostId();
142  ComputeURL();
143  }
144 
145  //------------------------------------------------------------------------
147  //------------------------------------------------------------------------
148  const std::string &GetPassword() const
149  {
150  return pPassword;
151  }
152 
153  //------------------------------------------------------------------------
155  //------------------------------------------------------------------------
156  void SetPassword( const std::string &password )
157  {
158  pPassword = password;
159  ComputeURL();
160  }
161 
162  //------------------------------------------------------------------------
164  //------------------------------------------------------------------------
165  const std::string &GetHostName() const
166  {
167  return pHostName;
168  }
169 
170  //------------------------------------------------------------------------
172  //------------------------------------------------------------------------
173  void SetHostName( const std::string &hostName )
174  {
175  pHostName = hostName;
176  ComputeHostId();
177  ComputeURL();
178  }
179 
180  //------------------------------------------------------------------------
182  //------------------------------------------------------------------------
183  int GetPort() const
184  {
185  return pPort;
186  }
187 
188  //------------------------------------------------------------------------
189  // Set port
190  //------------------------------------------------------------------------
191  void SetPort( int port )
192  {
193  pPort = port;
194  ComputeHostId();
195  ComputeURL();
196  }
197 
198  //------------------------------------------------------------------------
199  // Set host and port
200  //------------------------------------------------------------------------
201  void SetHostPort( const std::string &hostName, int port )
202  {
203  pHostName = hostName;
204  pPort = port;
205  ComputeHostId();
206  ComputeURL();
207  }
208 
209  //------------------------------------------------------------------------
211  //------------------------------------------------------------------------
212  const std::string &GetPath() const
213  {
214  return pPath;
215  }
216 
217  //------------------------------------------------------------------------
219  //------------------------------------------------------------------------
220  void SetPath( const std::string &path )
221  {
222  pPath = path;
223  ComputeURL();
224  }
225 
226  //------------------------------------------------------------------------
228  //------------------------------------------------------------------------
229  std::string GetPathWithParams() const;
230 
231  //------------------------------------------------------------------------
233  //------------------------------------------------------------------------
234  std::string GetPathWithFilteredParams() const;
235 
236  //------------------------------------------------------------------------
238  //------------------------------------------------------------------------
239  const ParamsMap &GetParams() const
240  {
241  return pParams;
242  }
243 
244  //------------------------------------------------------------------------
246  //------------------------------------------------------------------------
247  std::string GetParamsAsString() const;
248 
249  //------------------------------------------------------------------------
253  //------------------------------------------------------------------------
254  std::string GetParamsAsString( bool filter ) const;
255 
256  //------------------------------------------------------------------------
258  //------------------------------------------------------------------------
259  void SetParams( const std::string &params );
260 
261  //------------------------------------------------------------------------
263  //------------------------------------------------------------------------
264  void SetParams( const ParamsMap &params )
265  {
266  pParams = params;
267  ComputeURL();
268  }
269 
270  //------------------------------------------------------------------------
272  //------------------------------------------------------------------------
273  bool FromString( const std::string &url );
274 
275  //------------------------------------------------------------------------
277  //------------------------------------------------------------------------
278  void Clear();
279 
280  private:
281  bool ParseHostInfo( const std::string hhostInfo );
282  bool ParsePath( const std::string &path );
283  void ComputeHostId();
284  void ComputeURL();
285  bool PathEndsWith( const std::string & sufix ) const;
286  std::string pHostId;
287  std::string pProtocol;
288  std::string pUserName;
289  std::string pPassword;
290  std::string pHostName;
291  int pPort;
292  std::string pPath;
294  std::string pURL;
295 
296  };
297 }
298 
299 #endif // __XRD_CL_URL_HH__
bool PathEndsWith(const std::string &sufix) const
std::map< std::string, std::string > ParamsMap
Definition: XrdClURL.hh:33
void SetProtocol(const std::string &protocol)
Set protocol.
Definition: XrdClURL.hh:121
int GetPort() const
Get the target port.
Definition: XrdClURL.hh:183
bool IsLocalFile() const
std::string pHostName
Definition: XrdClURL.hh:290
bool FromString(const std::string &url)
Parse a string and fill the URL fields.
bool ParsePath(const std::string &path)
bool IsTPC() const
Is the URL used in TPC context.
void SetParams(const std::string &params)
Set params.
std::string GetURL() const
Get the URL.
Definition: XrdClURL.hh:86
std::string GetLocation() const
Get location (protocol://host:port/path)
void SetPath(const std::string &path)
Set the path.
Definition: XrdClURL.hh:220
void SetPort(int port)
Definition: XrdClURL.hh:191
std::string GetHostId() const
Get the host part of the URL (user:password@host:port)
Definition: XrdClURL.hh:94
URL()
Default constructor.
std::string pPassword
Definition: XrdClURL.hh:289
const std::string & GetPath() const
Get the path.
Definition: XrdClURL.hh:212
const std::string & GetPassword() const
Get the password.
Definition: XrdClURL.hh:148
bool IsSecure() const
Does the protocol indicate encryption.
std::string GetPathWithParams() const
Get the path with params.
std::string pPath
Definition: XrdClURL.hh:292
int pPort
Definition: XrdClURL.hh:291
bool IsMetalink() const
Is it a URL to a metalink.
bool IsValid() const
Is the url valid.
std::string GetParamsAsString() const
Get the URL params as string.
const std::string & GetHostName() const
Get the name of the target host.
Definition: XrdClURL.hh:165
Definition: XrdClAnyObject.hh:25
void Clear()
Clear the url.
void SetPassword(const std::string &password)
Set the password.
Definition: XrdClURL.hh:156
std::string pUserName
Definition: XrdClURL.hh:288
std::string GetPathWithFilteredParams() const
Get the path with params, filteres out &#39;xrdcl.&#39;.
std::string GetChannelId() const
std::string pURL
Definition: XrdClURL.hh:294
bool ParseHostInfo(const std::string hhostInfo)
std::string pProtocol
Definition: XrdClURL.hh:287
URL representation.
Definition: XrdClURL.hh:30
void SetUserName(const std::string &userName)
Set the username.
Definition: XrdClURL.hh:138
const std::string & GetProtocol() const
Get the protocol.
Definition: XrdClURL.hh:113
const ParamsMap & GetParams() const
Get the URL params.
Definition: XrdClURL.hh:239
ParamsMap pParams
Definition: XrdClURL.hh:293
void SetParams(const ParamsMap &params)
Set params.
Definition: XrdClURL.hh:264
void ComputeURL()
void SetHostName(const std::string &hostName)
Set the host name.
Definition: XrdClURL.hh:173
void SetHostPort(const std::string &hostName, int port)
Definition: XrdClURL.hh:201
std::string pHostId
Definition: XrdClURL.hh:286
void ComputeHostId()
const std::string & GetUserName() const
Get the username.
Definition: XrdClURL.hh:130