xrootd
Loading...
Searching...
No Matches
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
25namespace XrdCl
26{
27 //----------------------------------------------------------------------------
29 //----------------------------------------------------------------------------
30 class URL
31 {
32 public:
33 typedef std::map<std::string, std::string> ParamsMap;
35
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;
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;
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;
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;
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 //------------------------------------------------------------------------
251 //------------------------------------------------------------------------
252 std::string GetLoginToken() const;
253
254 //------------------------------------------------------------------------
258 //------------------------------------------------------------------------
259 std::string GetParamsAsString( bool filter ) const;
260
261 //------------------------------------------------------------------------
263 //------------------------------------------------------------------------
264 void SetParams( const std::string &params );
265
266 //------------------------------------------------------------------------
268 //------------------------------------------------------------------------
269 void SetParams( const ParamsMap &params )
270 {
271 pParams = params;
272 ComputeURL();
273 }
274
275 //------------------------------------------------------------------------
277 //------------------------------------------------------------------------
278 bool FromString( const std::string &url );
279
280 //------------------------------------------------------------------------
282 //------------------------------------------------------------------------
283 void Clear();
284
285 private:
286 bool ParseHostInfo( const std::string hhostInfo );
287 bool ParsePath( const std::string &path );
290 bool PathEndsWith( const std::string & sufix ) const;
291 std::string pHostId;
292 std::string pProtocol;
293 std::string pUserName;
294 std::string pPassword;
295 std::string pHostName;
296 int pPort;
297 std::string pPath;
299 std::string pURL;
300
301 };
302}
303
304#endif // __XRD_CL_URL_HH__
URL representation.
Definition XrdClURL.hh:31
std::string GetChannelId() const
void SetPort(int port)
Definition XrdClURL.hh:191
std::string GetParamsAsString(bool filter) const
std::string pHostId
Definition XrdClURL.hh:291
const std::string & GetPath() const
Get the path.
Definition XrdClURL.hh:212
std::string GetHostId() const
Get the host part of the URL (user:password@host:port)
Definition XrdClURL.hh:94
bool IsMetalink() const
Is it a URL to a metalink.
const std::string & GetPassword() const
Get the password.
Definition XrdClURL.hh:148
void SetParams(const ParamsMap &params)
Set params.
Definition XrdClURL.hh:269
bool PathEndsWith(const std::string &sufix) const
URL(const std::string &url)
std::map< std::string, std::string > ParamsMap
Definition XrdClURL.hh:33
bool FromString(const std::string &url)
Parse a string and fill the URL fields.
std::string pPath
Definition XrdClURL.hh:297
URL(const char *url)
void SetPassword(const std::string &password)
Set the password.
Definition XrdClURL.hh:156
void SetHostPort(const std::string &hostName, int port)
Definition XrdClURL.hh:201
void SetParams(const std::string &params)
Set params.
URL()
Default constructor.
std::string GetPathWithFilteredParams() const
Get the path with params, filteres out 'xrdcl.'.
const std::string & GetUserName() const
Get the username.
Definition XrdClURL.hh:130
std::string GetPathWithParams() const
Get the path with params.
void ComputeHostId()
std::string GetURL() const
Get the URL.
Definition XrdClURL.hh:86
std::string GetLocation() const
Get location (protocol://host:port/path)
bool ParsePath(const std::string &path)
const std::string & GetHostName() const
Get the name of the target host.
Definition XrdClURL.hh:165
int pPort
Definition XrdClURL.hh:296
void SetPath(const std::string &path)
Set the path.
Definition XrdClURL.hh:220
void SetHostName(const std::string &hostName)
Set the host name.
Definition XrdClURL.hh:173
std::string pHostName
Definition XrdClURL.hh:295
std::string pURL
Definition XrdClURL.hh:299
bool IsLocalFile() const
void SetProtocol(const std::string &protocol)
Set protocol.
Definition XrdClURL.hh:121
std::string GetParamsAsString() const
Get the URL params as string.
void ComputeURL()
ParamsMap pParams
Definition XrdClURL.hh:298
const ParamsMap & GetParams() const
Get the URL params.
Definition XrdClURL.hh:239
bool IsSecure() const
Does the protocol indicate encryption.
const std::string & GetProtocol() const
Get the protocol.
Definition XrdClURL.hh:113
bool IsValid() const
Is the url valid.
void Clear()
Clear the url.
bool IsTPC() const
Is the URL used in TPC context.
std::string pProtocol
Definition XrdClURL.hh:292
std::string pUserName
Definition XrdClURL.hh:293
std::string pPassword
Definition XrdClURL.hh:294
int GetPort() const
Get the target port.
Definition XrdClURL.hh:183
bool ParseHostInfo(const std::string hhostInfo)
void SetUserName(const std::string &userName)
Set the username.
Definition XrdClURL.hh:138
std::string GetLoginToken() const
Get the login token if present in the opaque info.
Definition XrdClAction.hh:34