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  //------------------------------------------------------------------------
165  //------------------------------------------------------------------------
166  const std::string &GetPath() const
167  {
168  return pPath;
169  }
170 
171  //------------------------------------------------------------------------
173  //------------------------------------------------------------------------
174  void SetPath( const std::string &path )
175  {
176  pPath = path;
177  ComputeURL();
178  }
179 
180  //------------------------------------------------------------------------
182  //------------------------------------------------------------------------
183  std::string GetPathWithParams() const;
184 
185  //------------------------------------------------------------------------
187  //------------------------------------------------------------------------
188  const ParamsMap &GetParams() const
189  {
190  return pParams;
191  }
192 
193  //------------------------------------------------------------------------
195  //------------------------------------------------------------------------
196  std::string GetParamsAsString() const;
197 
198  //------------------------------------------------------------------------
200  //------------------------------------------------------------------------
201  void SetParams( const std::string &params );
202 
203  //------------------------------------------------------------------------
205  //------------------------------------------------------------------------
206  void SetParams( const ParamsMap &params )
207  {
208  pParams = params;
209  ComputeURL();
210  }
211 
212  //------------------------------------------------------------------------
214  //------------------------------------------------------------------------
215  bool FromString( const std::string &url );
216 
217  //------------------------------------------------------------------------
219  //------------------------------------------------------------------------
220  void Clear();
221 
222  private:
223  bool ParseHostInfo( const std::string hhostInfo );
224  bool ParsePath( const std::string &path );
225  void ComputeHostId();
226  void ComputeURL();
227  std::string pHostId;
228  std::string pProtocol;
229  std::string pUserName;
230  std::string pPassword;
231  std::string pHostName;
232  int pPort;
233  std::string pPath;
235  std::string pURL;
236 
237  };
238 }
239 
240 #endif // __XRD_CL_URL_HH__