ARC SDK
URL.h
1 // -*- indent-tabs-mode: nil -*-
2 
3 #ifndef __ARC_URL_H__
4 #define __ARC_URL_H__
5 
6 #include <iostream>
7 #include <list>
8 #include <map>
9 #include <string>
10 
11 
12 // Default ports for different protocols
13 #define RC_DEFAULT_PORT 389
14 #define HTTP_DEFAULT_PORT 80
15 #define HTTPS_DEFAULT_PORT 443
16 #define HTTPG_DEFAULT_PORT 8443
17 #define LDAP_DEFAULT_PORT 389
18 #define FTP_DEFAULT_PORT 21
19 #define GSIFTP_DEFAULT_PORT 2811
20 #define LFC_DEFAULT_PORT 5010
21 #define XROOTD_DEFAULT_PORT 1094
22 
23 
24 namespace Arc {
25 
26  class URLLocation;
27 
29 
86  class URL {
87 
88  public:
90  URL();
91 
93 
100  URL(const std::string& url, bool encoded = false, int defaultPort = -1, const std::string& defaultPath = "");
101 
103  virtual ~URL();
104 
106  enum Scope {
107  base, onelevel, subtree
108  };
109 
111 
114  void URIDecode(void);
115 
117  const std::string& Protocol() const;
118 
120  void ChangeProtocol(const std::string& newprot);
121 
123  const std::string& Username() const;
124 
126  const std::string& Passwd() const;
127 
129  const std::string& Host() const;
130 
132  void ChangeHost(const std::string& newhost);
133 
135  int Port() const;
136 
138  void ChangePort(int newport);
139 
141  const std::string& Path() const;
142 
144  std::string FullPath() const;
145 
147 
149  std::string FullPathURIEncoded() const;
150 
152  void ChangePath(const std::string& newpath);
153 
155  void ChangeFullPath(const std::string& newpath, bool encoded = false);
156 
158  const std::map<std::string, std::string>& HTTPOptions() const;
159 
161 
165  const std::string& HTTPOption(const std::string& option,
166  const std::string& undefined = "") const;
167 
169 
171  bool AddHTTPOption(const std::string& option, const std::string& value,
172  bool overwrite = true);
173 
175 
176  void RemoveHTTPOption(const std::string& option);
177 
179  const std::list<std::string>& LDAPAttributes() const;
180 
182  void AddLDAPAttribute(const std::string& attribute);
183 
185  Scope LDAPScope() const;
186 
188  void ChangeLDAPScope(const Scope newscope);
189 
191  const std::string& LDAPFilter() const;
192 
194  void ChangeLDAPFilter(const std::string& newfilter);
195 
197  const std::map<std::string, std::string>& Options() const;
198 
200 
204  const std::string& Option(const std::string& option,
205  const std::string& undefined = "") const;
206 
208  const std::map<std::string, std::string>& MetaDataOptions() const;
209 
211 
215  const std::string& MetaDataOption(const std::string& option,
216  const std::string& undefined = "") const;
217 
219 
225  bool AddOption(const std::string& option, const std::string& value,
226  bool overwrite = true);
227 
229 
232  bool AddOption(const std::string& option, bool overwrite = true);
233 
235  void AddMetaDataOption(const std::string& option, const std::string& value,
236  bool overwrite = true);
237 
239  void AddLocation(const URLLocation& location);
240 
242  const std::list<URLLocation>& Locations() const;
243 
245  const std::map<std::string, std::string>& CommonLocOptions() const;
246 
248 
252  const std::string& CommonLocOption(const std::string& option,
253  const std::string&
254  undefined = "") const;
255 
257 
258  void RemoveOption(const std::string& option);
259 
261 
262  void RemoveMetaDataOption(const std::string& option);
263 
265  virtual std::string str(bool encode = false) const;
266 
268  virtual std::string plainstr(bool encode = false) const;
269 
271  virtual std::string fullstr(bool encode = false) const;
272 
274  virtual std::string ConnectionURL() const;
275 
277  bool operator<(const URL& url) const;
278 
280  bool operator==(const URL& url) const;
281 
283  operator bool() const;
285  bool operator!() const;
286 
288  bool StringMatches(const std::string& str) const;
289 
290 
292  std::map<std::string, std::string> ParseOptions(const std::string& optstring,
293  char separator, bool encoded = false);
294 
296 
299  static std::string OptionString(const std::map<std::string,
300  std::string>& options, char separator, bool encode = false);
301 
303 
304  static std::string URIEncode(const std::string& str);
305 
307 
308  static std::string URIDecode(const std::string& str);
309 
310  protected:
312  std::string protocol;
313 
315  std::string username;
316 
318  std::string passwd;
319 
321  std::string host;
322 
324  bool ip6addr;
325 
327  int port;
328 
330  std::string path;
331 
333  std::map<std::string, std::string> httpoptions;
334 
336  std::map<std::string, std::string> metadataoptions;
337 
339  std::list<std::string> ldapattributes;
340 
343 
345  std::string ldapfilter;
346 
348  std::map<std::string, std::string> urloptions;
349 
351  std::list<URLLocation> locations;
352 
354  std::map<std::string, std::string> commonlocoptions;
355 
357  bool valid;
358 
360  static std::string BaseDN2Path(const std::string&);
361 
363  static std::string Path2BaseDN(const std::string&);
364 
366  friend std::ostream& operator<<(std::ostream& out, const URL& u);
367 
369  void ParsePath(bool encoded = false);
370  };
371 
372 
374 
378  : public URL {
379 
380  public:
382  URLLocation(const std::string& url = "");
383 
385  URLLocation(const std::string& url, const std::string& name);
386 
388  URLLocation(const URL& url);
389 
391  URLLocation(const URL& url, const std::string& name);
392 
394  URLLocation(const std::map<std::string, std::string>& options,
395  const std::string& name);
396 
398  virtual ~URLLocation();
399 
401  const std::string& Name() const;
402 
404  virtual std::string str() const;
405 
407  virtual std::string fullstr() const;
408 
409  protected:
411  std::string name;
412  };
413 
414 
416 
418  class PathIterator {
419  public:
421 
423  PathIterator(const std::string& path, bool end = false);
424  ~PathIterator();
425 
428 
431 
433  operator bool() const;
434 
436  std::string operator*() const;
437 
439  std::string Rest() const;
440 
441  private:
442  const std::string& path;
443  std::string::size_type pos;
444  bool end;
445  bool done;
446  };
447 
448 
450  std::list<URL> ReadURLList(const URL& urllist);
451 
452 } // namespace Arc
453 
454 #endif // __ARC_URL_H__