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 
35 
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  //------------------------------------------------------------------------
61  //------------------------------------------------------------------------
62  std::string GetHostId() const;
63 
64  //------------------------------------------------------------------------
66  //------------------------------------------------------------------------
67  std::string GetLocation() const;
68 
69  //------------------------------------------------------------------------
71  //------------------------------------------------------------------------
72  const std::string &GetProtocol() const
73  {
74  return pProtocol;
75  }
76 
77  //------------------------------------------------------------------------
79  //------------------------------------------------------------------------
80  void SetProtocol( const std::string &protocol )
81  {
82  pProtocol = protocol;
83  }
84 
85  //------------------------------------------------------------------------
87  //------------------------------------------------------------------------
88  const std::string &GetUserName() const
89  {
90  return pUserName;
91  }
92 
93  //------------------------------------------------------------------------
95  //------------------------------------------------------------------------
96  void SetUserName( const std::string &userName )
97  {
98  pUserName = userName;
99  }
100 
101  //------------------------------------------------------------------------
103  //------------------------------------------------------------------------
104  const std::string &GetPassword() const
105  {
106  return pPassword;
107  }
108 
109  //------------------------------------------------------------------------
111  //------------------------------------------------------------------------
112  void SetPassword( const std::string &password )
113  {
114  pPassword = password;
115  }
116 
117  //------------------------------------------------------------------------
119  //------------------------------------------------------------------------
120  const std::string &GetHostName() const
121  {
122  return pHostName;
123  }
124 
125  //------------------------------------------------------------------------
127  //------------------------------------------------------------------------
128  void SetHostName( const std::string &hostName )
129  {
130  pHostName = hostName;
131  }
132 
133  //------------------------------------------------------------------------
135  //------------------------------------------------------------------------
136  int GetPort() const
137  {
138  return pPort;
139  }
140 
141  //------------------------------------------------------------------------
142  // Set port
143  //------------------------------------------------------------------------
144  void SetPort( int port )
145  {
146  pPort = port;
147  }
148 
149  //------------------------------------------------------------------------
151  //------------------------------------------------------------------------
152  const std::string &GetPath() const
153  {
154  return pPath;
155  }
156 
157  //------------------------------------------------------------------------
159  //------------------------------------------------------------------------
160  void SetPath( const std::string &path )
161  {
162  pPath = path;
163  }
164 
165  //------------------------------------------------------------------------
167  //------------------------------------------------------------------------
168  std::string GetPathWithParams() const;
169 
170  //------------------------------------------------------------------------
172  //------------------------------------------------------------------------
173  const ParamsMap &GetParams() const
174  {
175  return pParams;
176  }
177 
178  //------------------------------------------------------------------------
180  //------------------------------------------------------------------------
182  {
183  return pParams;
184  }
185 
186  //------------------------------------------------------------------------
188  //------------------------------------------------------------------------
189  std::string GetParamsAsString() const;
190 
191  //------------------------------------------------------------------------
193  //------------------------------------------------------------------------
194  void SetParams( const std::string &params );
195 
196  //------------------------------------------------------------------------
198  //------------------------------------------------------------------------
199  bool FromString( const std::string &url );
200 
201  //------------------------------------------------------------------------
203  //------------------------------------------------------------------------
204  void Clear();
205 
206  private:
207  bool ParseHostInfo( const std::string hhostInfo );
208  bool ParsePath( const std::string &path );
209  std::string pHostId;
210  std::string pProtocol;
211  std::string pUserName;
212  std::string pPassword;
213  std::string pHostName;
214  int pPort;
215  std::string pPath;
217 
218  };
219 }
220 
221 #endif // __XRD_CL_URL_HH__