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  //------------------------------------------------------------------------
61  //------------------------------------------------------------------------
62  std::string GetURL() const
63  {
64  return pURL;
65  }
66 
67  //------------------------------------------------------------------------
69  //------------------------------------------------------------------------
70  std::string GetHostId() const
71  {
72  return pHostId;
73  }
74 
75  //------------------------------------------------------------------------
77  //------------------------------------------------------------------------
78  std::string GetLocation() const;
79 
80  //------------------------------------------------------------------------
82  //------------------------------------------------------------------------
83  const std::string &GetProtocol() const
84  {
85  return pProtocol;
86  }
87 
88  //------------------------------------------------------------------------
90  //------------------------------------------------------------------------
91  void SetProtocol( const std::string &protocol )
92  {
93  pProtocol = protocol;
94  ComputeURL();
95  }
96 
97  //------------------------------------------------------------------------
99  //------------------------------------------------------------------------
100  const std::string &GetUserName() const
101  {
102  return pUserName;
103  }
104 
105  //------------------------------------------------------------------------
107  //------------------------------------------------------------------------
108  void SetUserName( const std::string &userName )
109  {
110  pUserName = userName;
111  ComputeHostId();
112  ComputeURL();
113  }
114 
115  //------------------------------------------------------------------------
117  //------------------------------------------------------------------------
118  const std::string &GetPassword() const
119  {
120  return pPassword;
121  }
122 
123  //------------------------------------------------------------------------
125  //------------------------------------------------------------------------
126  void SetPassword( const std::string &password )
127  {
128  pPassword = password;
129  ComputeURL();
130  }
131 
132  //------------------------------------------------------------------------
134  //------------------------------------------------------------------------
135  const std::string &GetHostName() const
136  {
137  return pHostName;
138  }
139 
140  //------------------------------------------------------------------------
142  //------------------------------------------------------------------------
143  void SetHostName( const std::string &hostName )
144  {
145  pHostName = hostName;
146  ComputeHostId();
147  ComputeURL();
148  }
149 
150  //------------------------------------------------------------------------
152  //------------------------------------------------------------------------
153  int GetPort() const
154  {
155  return pPort;
156  }
157 
158  //------------------------------------------------------------------------
159  // Set port
160  //------------------------------------------------------------------------
161  void SetPort( int port )
162  {
163  pPort = port;
164  ComputeHostId();
165  ComputeURL();
166  }
167 
168  //------------------------------------------------------------------------
169  // Set host and port
170  //------------------------------------------------------------------------
171  void SetHostPort( const std::string &hostName, int port )
172  {
173  pHostName = hostName;
174  pPort = port;
175  ComputeHostId();
176  ComputeURL();
177  }
178 
179  //------------------------------------------------------------------------
181  //------------------------------------------------------------------------
182  const std::string &GetPath() const
183  {
184  return pPath;
185  }
186 
187  //------------------------------------------------------------------------
189  //------------------------------------------------------------------------
190  void SetPath( const std::string &path )
191  {
192  pPath = path;
193  ComputeURL();
194  }
195 
196  //------------------------------------------------------------------------
198  //------------------------------------------------------------------------
199  std::string GetPathWithParams() const;
200 
201  //------------------------------------------------------------------------
203  //------------------------------------------------------------------------
204  const ParamsMap &GetParams() const
205  {
206  return pParams;
207  }
208 
209  //------------------------------------------------------------------------
211  //------------------------------------------------------------------------
212  std::string GetParamsAsString() const;
213 
214  //------------------------------------------------------------------------
216  //------------------------------------------------------------------------
217  void SetParams( const std::string &params );
218 
219  //------------------------------------------------------------------------
221  //------------------------------------------------------------------------
222  void SetParams( const ParamsMap &params )
223  {
224  pParams = params;
225  ComputeURL();
226  }
227 
228  //------------------------------------------------------------------------
230  //------------------------------------------------------------------------
231  bool FromString( const std::string &url );
232 
233  //------------------------------------------------------------------------
235  //------------------------------------------------------------------------
236  void Clear();
237 
238  private:
239  bool ParseHostInfo( const std::string hhostInfo );
240  bool ParsePath( const std::string &path );
241  void ComputeHostId();
242  void ComputeURL();
243  bool PathEndsWith( const std::string & sufix ) const;
244  std::string pHostId;
245  std::string pProtocol;
246  std::string pUserName;
247  std::string pPassword;
248  std::string pHostName;
249  int pPort;
250  std::string pPath;
251  ParamsMap pParams;
252  std::string pURL;
253 
254  };
255 }
256 
257 #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:91
int GetPort() const
Get the target port.
Definition: XrdClURL.hh:153
std::string pHostName
Definition: XrdClURL.hh:248
bool FromString(const std::string &url)
Parse a string and fill the URL fields.
bool ParsePath(const std::string &path)
void SetParams(const std::string &params)
Set params.
std::string GetURL() const
Get the URL.
Definition: XrdClURL.hh:62
std::string GetLocation() const
Get location (protocol://host:port/path)
void SetPath(const std::string &path)
Set the path.
Definition: XrdClURL.hh:190
void SetPort(int port)
Definition: XrdClURL.hh:161
std::string GetHostId() const
Get the host part of the URL (user:password@host:port)
Definition: XrdClURL.hh:70
URL()
Default constructor.
std::string pPassword
Definition: XrdClURL.hh:247
const std::string & GetPath() const
Get the path.
Definition: XrdClURL.hh:182
const std::string & GetPassword() const
Get the password.
Definition: XrdClURL.hh:118
std::string GetPathWithParams() const
Get the path with params.
std::string pPath
Definition: XrdClURL.hh:250
int pPort
Definition: XrdClURL.hh:249
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:135
Definition: XrdClEnv.hh:28
void Clear()
Clear the url.
void SetPassword(const std::string &password)
Set the password.
Definition: XrdClURL.hh:126
std::string pUserName
Definition: XrdClURL.hh:246
std::string pURL
Definition: XrdClURL.hh:252
bool ParseHostInfo(const std::string hhostInfo)
std::string pProtocol
Definition: XrdClURL.hh:245
URL representation.
Definition: XrdClURL.hh:30
void SetUserName(const std::string &userName)
Set the username.
Definition: XrdClURL.hh:108
const std::string & GetProtocol() const
Get the protocol.
Definition: XrdClURL.hh:83
const ParamsMap & GetParams() const
Get the URL params.
Definition: XrdClURL.hh:204
ParamsMap pParams
Definition: XrdClURL.hh:251
void SetParams(const ParamsMap &params)
Set params.
Definition: XrdClURL.hh:222
void ComputeURL()
void SetHostName(const std::string &hostName)
Set the host name.
Definition: XrdClURL.hh:143
void SetHostPort(const std::string &hostName, int port)
Definition: XrdClURL.hh:171
std::string pHostId
Definition: XrdClURL.hh:244
void ComputeHostId()
const std::string & GetUserName() const
Get the username.
Definition: XrdClURL.hh:100