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
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 std::string GetURL() const
77 {
78 return pURL;
79 }
80
81 //------------------------------------------------------------------------
83 //------------------------------------------------------------------------
84 std::string GetHostId() const
85 {
86 return pHostId;
87 }
88
89 //------------------------------------------------------------------------
91 //------------------------------------------------------------------------
92 std::string GetLocation() const;
93
94 //------------------------------------------------------------------------
96 //------------------------------------------------------------------------
97 const std::string &GetProtocol() const
98 {
99 return pProtocol;
100 }
101
102 //------------------------------------------------------------------------
104 //------------------------------------------------------------------------
105 void SetProtocol( const std::string &protocol )
106 {
107 pProtocol = protocol;
108 ComputeURL();
109 }
110
111 //------------------------------------------------------------------------
113 //------------------------------------------------------------------------
114 const std::string &GetUserName() const
115 {
116 return pUserName;
117 }
118
119 //------------------------------------------------------------------------
121 //------------------------------------------------------------------------
122 void SetUserName( const std::string &userName )
123 {
124 pUserName = userName;
126 ComputeURL();
127 }
128
129 //------------------------------------------------------------------------
131 //------------------------------------------------------------------------
132 const std::string &GetPassword() const
133 {
134 return pPassword;
135 }
136
137 //------------------------------------------------------------------------
139 //------------------------------------------------------------------------
140 void SetPassword( const std::string &password )
141 {
142 pPassword = password;
143 ComputeURL();
144 }
145
146 //------------------------------------------------------------------------
148 //------------------------------------------------------------------------
149 const std::string &GetHostName() const
150 {
151 return pHostName;
152 }
153
154 //------------------------------------------------------------------------
156 //------------------------------------------------------------------------
157 void SetHostName( const std::string &hostName )
158 {
159 pHostName = hostName;
161 ComputeURL();
162 }
163
164 //------------------------------------------------------------------------
166 //------------------------------------------------------------------------
167 int GetPort() const
168 {
169 return pPort;
170 }
171
172 //------------------------------------------------------------------------
173 // Set port
174 //------------------------------------------------------------------------
175 void SetPort( int port )
176 {
177 pPort = port;
179 ComputeURL();
180 }
181
182 //------------------------------------------------------------------------
183 // Set host and port
184 //------------------------------------------------------------------------
185 void SetHostPort( const std::string &hostName, int port )
186 {
187 pHostName = hostName;
188 pPort = port;
190 ComputeURL();
191 }
192
193 //------------------------------------------------------------------------
195 //------------------------------------------------------------------------
196 const std::string &GetPath() const
197 {
198 return pPath;
199 }
200
201 //------------------------------------------------------------------------
203 //------------------------------------------------------------------------
204 void SetPath( const std::string &path )
205 {
206 pPath = path;
207 ComputeURL();
208 }
209
210 //------------------------------------------------------------------------
212 //------------------------------------------------------------------------
213 std::string GetPathWithParams() const;
214
215 //------------------------------------------------------------------------
217 //------------------------------------------------------------------------
218 std::string GetPathWithFilteredParams() const;
219
220 //------------------------------------------------------------------------
222 //------------------------------------------------------------------------
223 const ParamsMap &GetParams() const
224 {
225 return pParams;
226 }
227
228 //------------------------------------------------------------------------
230 //------------------------------------------------------------------------
231 std::string GetParamsAsString() const;
232
233 //------------------------------------------------------------------------
237 //------------------------------------------------------------------------
238 std::string GetParamsAsString( bool filter ) const;
239
240 //------------------------------------------------------------------------
242 //------------------------------------------------------------------------
243 void SetParams( const std::string &params );
244
245 //------------------------------------------------------------------------
247 //------------------------------------------------------------------------
248 void SetParams( const ParamsMap &params )
249 {
250 pParams = params;
251 ComputeURL();
252 }
253
254 //------------------------------------------------------------------------
256 //------------------------------------------------------------------------
257 bool FromString( const std::string &url );
258
259 //------------------------------------------------------------------------
261 //------------------------------------------------------------------------
262 void Clear();
263
264 private:
265 bool ParseHostInfo( const std::string hhostInfo );
266 bool ParsePath( const std::string &path );
269 bool PathEndsWith( const std::string & sufix ) const;
270 std::string pHostId;
271 std::string pProtocol;
272 std::string pUserName;
273 std::string pPassword;
274 std::string pHostName;
275 int pPort;
276 std::string pPath;
278 std::string pURL;
279
280 };
281}
282
283#endif // __XRD_CL_URL_HH__
URL representation.
Definition: XrdClURL.hh:31
void SetPort(int port)
Definition: XrdClURL.hh:175
std::string GetParamsAsString(bool filter) const
std::string pHostId
Definition: XrdClURL.hh:270
const std::string & GetPath() const
Get the path.
Definition: XrdClURL.hh:196
std::string GetHostId() const
Get the host part of the URL (user:password@host:port)
Definition: XrdClURL.hh:84
bool IsMetalink() const
Is it a URL to a metalink.
const std::string & GetPassword() const
Get the password.
Definition: XrdClURL.hh:132
void SetParams(const ParamsMap &params)
Set params.
Definition: XrdClURL.hh:248
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:276
URL(const char *url)
void SetPassword(const std::string &password)
Set the password.
Definition: XrdClURL.hh:140
void SetHostPort(const std::string &hostName, int port)
Definition: XrdClURL.hh:185
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:114
std::string GetPathWithParams() const
Get the path with params.
void ComputeHostId()
std::string GetURL() const
Get the URL.
Definition: XrdClURL.hh:76
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:149
int pPort
Definition: XrdClURL.hh:275
void SetPath(const std::string &path)
Set the path.
Definition: XrdClURL.hh:204
void SetHostName(const std::string &hostName)
Set the host name.
Definition: XrdClURL.hh:157
std::string pHostName
Definition: XrdClURL.hh:274
std::string pURL
Definition: XrdClURL.hh:278
bool IsLocalFile() const
void SetProtocol(const std::string &protocol)
Set protocol.
Definition: XrdClURL.hh:105
std::string GetParamsAsString() const
Get the URL params as string.
void ComputeURL()
ParamsMap pParams
Definition: XrdClURL.hh:277
const ParamsMap & GetParams() const
Get the URL params.
Definition: XrdClURL.hh:223
const std::string & GetProtocol() const
Get the protocol.
Definition: XrdClURL.hh:97
bool IsValid() const
Is the url valid.
void Clear()
Clear the url.
std::string pProtocol
Definition: XrdClURL.hh:271
std::string pUserName
Definition: XrdClURL.hh:272
std::string pPassword
Definition: XrdClURL.hh:273
int GetPort() const
Get the target port.
Definition: XrdClURL.hh:167
bool ParseHostInfo(const std::string hhostInfo)
void SetUserName(const std::string &userName)
Set the username.
Definition: XrdClURL.hh:122
Definition: XrdClAnyObject.hh:26