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  //------------------------------------------------------------------------
51  //------------------------------------------------------------------------
52  bool IsValid() const;
53 
54  //------------------------------------------------------------------------
56  //------------------------------------------------------------------------
57  bool IsMetalink() const;
58 
59  //------------------------------------------------------------------------
62  //------------------------------------------------------------------------
63  bool IsLocalFile() const;
64 
65  //------------------------------------------------------------------------
67  //------------------------------------------------------------------------
68  std::string GetURL() const
69  {
70  return pURL;
71  }
72 
73  //------------------------------------------------------------------------
75  //------------------------------------------------------------------------
76  std::string GetHostId() const
77  {
78  return pHostId;
79  }
80 
81  //------------------------------------------------------------------------
83  //------------------------------------------------------------------------
84  std::string GetLocation() const;
85 
86  //------------------------------------------------------------------------
88  //------------------------------------------------------------------------
89  const std::string &GetProtocol() const
90  {
91  return pProtocol;
92  }
93 
94  //------------------------------------------------------------------------
96  //------------------------------------------------------------------------
97  void SetProtocol( const std::string &protocol )
98  {
99  pProtocol = protocol;
100  ComputeURL();
101  }
102 
103  //------------------------------------------------------------------------
105  //------------------------------------------------------------------------
106  const std::string &GetUserName() const
107  {
108  return pUserName;
109  }
110 
111  //------------------------------------------------------------------------
113  //------------------------------------------------------------------------
114  void SetUserName( const std::string &userName )
115  {
116  pUserName = userName;
117  ComputeHostId();
118  ComputeURL();
119  }
120 
121  //------------------------------------------------------------------------
123  //------------------------------------------------------------------------
124  const std::string &GetPassword() const
125  {
126  return pPassword;
127  }
128 
129  //------------------------------------------------------------------------
131  //------------------------------------------------------------------------
132  void SetPassword( const std::string &password )
133  {
134  pPassword = password;
135  ComputeURL();
136  }
137 
138  //------------------------------------------------------------------------
140  //------------------------------------------------------------------------
141  const std::string &GetHostName() const
142  {
143  return pHostName;
144  }
145 
146  //------------------------------------------------------------------------
148  //------------------------------------------------------------------------
149  void SetHostName( const std::string &hostName )
150  {
151  pHostName = hostName;
152  ComputeHostId();
153  ComputeURL();
154  }
155 
156  //------------------------------------------------------------------------
158  //------------------------------------------------------------------------
159  int GetPort() const
160  {
161  return pPort;
162  }
163 
164  //------------------------------------------------------------------------
165  // Set port
166  //------------------------------------------------------------------------
167  void SetPort( int port )
168  {
169  pPort = port;
170  ComputeHostId();
171  ComputeURL();
172  }
173 
174  //------------------------------------------------------------------------
175  // Set host and port
176  //------------------------------------------------------------------------
177  void SetHostPort( const std::string &hostName, int port )
178  {
179  pHostName = hostName;
180  pPort = port;
181  ComputeHostId();
182  ComputeURL();
183  }
184 
185  //------------------------------------------------------------------------
187  //------------------------------------------------------------------------
188  const std::string &GetPath() const
189  {
190  return pPath;
191  }
192 
193  //------------------------------------------------------------------------
195  //------------------------------------------------------------------------
196  void SetPath( const std::string &path )
197  {
198  pPath = path;
199  ComputeURL();
200  }
201 
202  //------------------------------------------------------------------------
204  //------------------------------------------------------------------------
205  std::string GetPathWithParams() const;
206 
207  //------------------------------------------------------------------------
209  //------------------------------------------------------------------------
210  std::string GetPathWithFilteredParams() const;
211 
212  //------------------------------------------------------------------------
214  //------------------------------------------------------------------------
215  const ParamsMap &GetParams() const
216  {
217  return pParams;
218  }
219 
220  //------------------------------------------------------------------------
222  //------------------------------------------------------------------------
223  std::string GetParamsAsString() const;
224 
225  //------------------------------------------------------------------------
229  //------------------------------------------------------------------------
230  std::string GetParamsAsString( bool filter ) const;
231 
232  //------------------------------------------------------------------------
234  //------------------------------------------------------------------------
235  void SetParams( const std::string &params );
236 
237  //------------------------------------------------------------------------
239  //------------------------------------------------------------------------
240  void SetParams( const ParamsMap &params )
241  {
242  pParams = params;
243  ComputeURL();
244  }
245 
246  //------------------------------------------------------------------------
248  //------------------------------------------------------------------------
249  bool FromString( const std::string &url );
250 
251  //------------------------------------------------------------------------
253  //------------------------------------------------------------------------
254  void Clear();
255 
256  private:
257  bool ParseHostInfo( const std::string hhostInfo );
258  bool ParsePath( const std::string &path );
259  void ComputeHostId();
260  void ComputeURL();
261  bool PathEndsWith( const std::string & sufix ) const;
262  std::string pHostId;
263  std::string pProtocol;
264  std::string pUserName;
265  std::string pPassword;
266  std::string pHostName;
267  int pPort;
268  std::string pPath;
270  std::string pURL;
271 
272  };
273 }
274 
275 #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:97
std::string GetLocation() const
Get location (protocol://host:port/path)
const std::string & GetPassword() const
Get the password.
Definition: XrdClURL.hh:124
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:266
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:141
bool ParsePath(const std::string &path)
int GetPort() const
Get the target port.
Definition: XrdClURL.hh:159
bool IsMetalink() const
Is it a URL to a metalink.
const std::string & GetPath() const
Get the path.
Definition: XrdClURL.hh:188
void SetParams(const std::string &params)
Set params.
void SetPath(const std::string &path)
Set the path.
Definition: XrdClURL.hh:196
void SetPort(int port)
Definition: XrdClURL.hh:167
URL()
Default constructor.
const std::string & GetUserName() const
Get the username.
Definition: XrdClURL.hh:106
std::string pPassword
Definition: XrdClURL.hh:265
std::string pPath
Definition: XrdClURL.hh:268
int pPort
Definition: XrdClURL.hh:267
const std::string & GetProtocol() const
Get the protocol.
Definition: XrdClURL.hh:89
void Clear()
Clear the url.
void SetPassword(const std::string &password)
Set the password.
Definition: XrdClURL.hh:132
std::string GetHostId() const
Get the host part of the URL (user:password@host:port)
Definition: XrdClURL.hh:76
std::string pUserName
Definition: XrdClURL.hh:264
std::string pURL
Definition: XrdClURL.hh:270
std::string GetURL() const
Get the URL.
Definition: XrdClURL.hh:68
bool ParseHostInfo(const std::string hhostInfo)
std::string pProtocol
Definition: XrdClURL.hh:263
URL representation.
Definition: XrdClURL.hh:30
void SetUserName(const std::string &userName)
Set the username.
Definition: XrdClURL.hh:114
ParamsMap pParams
Definition: XrdClURL.hh:269
void SetParams(const ParamsMap &params)
Set params.
Definition: XrdClURL.hh:240
void ComputeURL()
void SetHostName(const std::string &hostName)
Set the host name.
Definition: XrdClURL.hh:149
bool PathEndsWith(const std::string &sufix) const
const ParamsMap & GetParams() const
Get the URL params.
Definition: XrdClURL.hh:215
void SetHostPort(const std::string &hostName, int port)
Definition: XrdClURL.hh:177
std::string pHostId
Definition: XrdClURL.hh:262
std::string GetPathWithParams() const
Get the path with params.
void ComputeHostId()