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 GetObfuscatedURL() const;
95
96 //------------------------------------------------------------------------
98 //------------------------------------------------------------------------
99 std::string GetHostId() const
100 {
101 return pHostId;
102 }
103
104 //------------------------------------------------------------------------
107 //------------------------------------------------------------------------
108 std::string GetChannelId() const;
109
110 //------------------------------------------------------------------------
112 //------------------------------------------------------------------------
113 std::string GetLocation() const;
114
115 //------------------------------------------------------------------------
117 //------------------------------------------------------------------------
118 const std::string &GetProtocol() const
119 {
120 return pProtocol;
121 }
122
123 //------------------------------------------------------------------------
125 //------------------------------------------------------------------------
126 void SetProtocol( const std::string &protocol )
127 {
128 pProtocol = protocol;
129 ComputeURL();
130 }
131
132 //------------------------------------------------------------------------
134 //------------------------------------------------------------------------
135 const std::string &GetUserName() const
136 {
137 return pUserName;
138 }
139
140 //------------------------------------------------------------------------
142 //------------------------------------------------------------------------
143 void SetUserName( const std::string &userName )
144 {
145 pUserName = userName;
146 ComputeHostId();
147 ComputeURL();
148 }
149
150 //------------------------------------------------------------------------
152 //------------------------------------------------------------------------
153 const std::string &GetPassword() const
154 {
155 return pPassword;
156 }
157
158 //------------------------------------------------------------------------
160 //------------------------------------------------------------------------
161 void SetPassword( const std::string &password )
162 {
163 pPassword = password;
164 ComputeURL();
165 }
166
167 //------------------------------------------------------------------------
169 //------------------------------------------------------------------------
170 const std::string &GetHostName() const
171 {
172 return pHostName;
173 }
174
175 //------------------------------------------------------------------------
177 //------------------------------------------------------------------------
178 void SetHostName( const std::string &hostName )
179 {
180 pHostName = hostName;
181 ComputeHostId();
182 ComputeURL();
183 }
184
185 //------------------------------------------------------------------------
187 //------------------------------------------------------------------------
188 int GetPort() const
189 {
190 return pPort;
191 }
192
193 //------------------------------------------------------------------------
194 // Set port
195 //------------------------------------------------------------------------
196 void SetPort( int port )
197 {
198 pPort = port;
199 ComputeHostId();
200 ComputeURL();
201 }
202
203 //------------------------------------------------------------------------
204 // Set host and port
205 //------------------------------------------------------------------------
206 void SetHostPort( const std::string &hostName, int port )
207 {
208 pHostName = hostName;
209 pPort = port;
210 ComputeHostId();
211 ComputeURL();
212 }
213
214 //------------------------------------------------------------------------
216 //------------------------------------------------------------------------
217 const std::string &GetPath() const
218 {
219 return pPath;
220 }
221
222 //------------------------------------------------------------------------
224 //------------------------------------------------------------------------
225 void SetPath( const std::string &path )
226 {
227 pPath = path;
228 ComputeURL();
229 }
230
231 //------------------------------------------------------------------------
233 //------------------------------------------------------------------------
234 std::string GetPathWithParams() const;
235
236 //------------------------------------------------------------------------
238 //------------------------------------------------------------------------
239 std::string GetPathWithFilteredParams() const;
240
241 //------------------------------------------------------------------------
243 //------------------------------------------------------------------------
244 const ParamsMap &GetParams() const
245 {
246 return pParams;
247 }
248
249 //------------------------------------------------------------------------
251 //------------------------------------------------------------------------
252 std::string GetParamsAsString() const;
253
254 //------------------------------------------------------------------------
256 //------------------------------------------------------------------------
257 std::string GetLoginToken() const;
258
259 //------------------------------------------------------------------------
263 //------------------------------------------------------------------------
264 std::string GetParamsAsString( bool filter ) const;
265
266 //------------------------------------------------------------------------
268 //------------------------------------------------------------------------
269 void SetParams( const std::string &params );
270
271 //------------------------------------------------------------------------
273 //------------------------------------------------------------------------
274 void SetParams( const ParamsMap &params )
275 {
276 pParams = params;
277 ComputeURL();
278 }
279
280 //------------------------------------------------------------------------
282 //------------------------------------------------------------------------
283 bool FromString( const std::string &url );
284
285 //------------------------------------------------------------------------
287 //------------------------------------------------------------------------
288 void Clear();
289
290 private:
291 bool ParseHostInfo( const std::string hhostInfo );
292 bool ParsePath( const std::string &path );
293 void ComputeHostId();
294 void ComputeURL();
295 bool PathEndsWith( const std::string & sufix ) const;
296 std::string pHostId;
297 std::string pProtocol;
298 std::string pUserName;
299 std::string pPassword;
300 std::string pHostName;
301 int pPort;
302 std::string pPath;
303 ParamsMap pParams;
304 std::string pURL;
305
306 };
307}
308
309#endif // __XRD_CL_URL_HH__
std::string GetChannelId() const
Definition XrdClURL.cc:512
void SetPort(int port)
Definition XrdClURL.hh:196
const std::string & GetPath() const
Get the path.
Definition XrdClURL.hh:217
std::string GetHostId() const
Get the host part of the URL (user:password@host:port)
Definition XrdClURL.hh:99
bool IsMetalink() const
Is it a URL to a metalink.
Definition XrdClURL.cc:465
const std::string & GetPassword() const
Get the password.
Definition XrdClURL.hh:153
void SetParams(const ParamsMap &params)
Set params.
Definition XrdClURL.hh:274
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.
Definition XrdClURL.cc:62
void SetPassword(const std::string &password)
Set the password.
Definition XrdClURL.hh:161
void SetHostPort(const std::string &hostName, int port)
Definition XrdClURL.hh:206
void SetParams(const std::string &params)
Set params.
Definition XrdClURL.cc:402
URL()
Default constructor.
Definition XrdClURL.cc:39
std::string GetPathWithFilteredParams() const
Get the path with params, filteres out 'xrdcl.'.
Definition XrdClURL.cc:331
const std::string & GetUserName() const
Get the username.
Definition XrdClURL.hh:135
std::string GetPathWithParams() const
Get the path with params.
Definition XrdClURL.cc:318
std::string GetURL() const
Get the URL.
Definition XrdClURL.hh:86
std::string GetObfuscatedURL() const
Get the URL with authz information obfuscated.
Definition XrdClURL.cc:498
std::string GetLocation() const
Get location (protocol://host:port/path)
Definition XrdClURL.cc:344
const std::string & GetHostName() const
Get the name of the target host.
Definition XrdClURL.hh:170
void SetPath(const std::string &path)
Set the path.
Definition XrdClURL.hh:225
void SetHostName(const std::string &hostName)
Set the host name.
Definition XrdClURL.hh:178
bool IsLocalFile() const
Definition XrdClURL.cc:474
void SetProtocol(const std::string &protocol)
Set protocol.
Definition XrdClURL.hh:126
std::string GetParamsAsString() const
Get the URL params as string.
Definition XrdClURL.cc:359
const ParamsMap & GetParams() const
Get the URL params.
Definition XrdClURL.hh:244
bool IsSecure() const
Does the protocol indicate encryption.
Definition XrdClURL.cc:482
const std::string & GetProtocol() const
Get the protocol.
Definition XrdClURL.hh:118
bool IsValid() const
Is the url valid.
Definition XrdClURL.cc:452
void Clear()
Clear the url.
Definition XrdClURL.cc:436
bool IsTPC() const
Is the URL used in TPC context.
Definition XrdClURL.cc:490
int GetPort() const
Get the target port.
Definition XrdClURL.hh:188
void SetUserName(const std::string &userName)
Set the username.
Definition XrdClURL.hh:143
std::string GetLoginToken() const
Get the login token if present in the opaque info.
Definition XrdClURL.cc:367