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