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  /* \param url The string representation of URL
94  \param encoded Set to true if URL is encoded according to RFC 3986 */
95  URL(const std::string& url, bool encoded = false);
96 
98  virtual ~URL();
99 
101  enum Scope {
102  base, onelevel, subtree
103  };
104 
106 
109  void URIDecode(void);
110 
112  const std::string& Protocol() const;
113 
115  void ChangeProtocol(const std::string& newprot);
116 
118  const std::string& Username() const;
119 
121  const std::string& Passwd() const;
122 
124  const std::string& Host() const;
125 
127  void ChangeHost(const std::string& newhost);
128 
130  int Port() const;
131 
133  void ChangePort(int newport);
134 
136  const std::string& Path() const;
137 
139  std::string FullPath() const;
140 
142 
144  std::string FullPathURIEncoded() const;
145 
147  void ChangePath(const std::string& newpath);
148 
150  void ChangeFullPath(const std::string& newpath, bool encoded = false);
151 
153  const std::map<std::string, std::string>& HTTPOptions() const;
154 
156 
160  const std::string& HTTPOption(const std::string& option,
161  const std::string& undefined = "") const;
162 
164 
166  bool AddHTTPOption(const std::string& option, const std::string& value,
167  bool overwrite = true);
168 
170 
171  void RemoveHTTPOption(const std::string& option);
172 
174  const std::list<std::string>& LDAPAttributes() const;
175 
177  void AddLDAPAttribute(const std::string& attribute);
178 
180  Scope LDAPScope() const;
181 
183  void ChangeLDAPScope(const Scope newscope);
184 
186  const std::string& LDAPFilter() const;
187 
189  void ChangeLDAPFilter(const std::string& newfilter);
190 
192  const std::map<std::string, std::string>& Options() const;
193 
195 
199  const std::string& Option(const std::string& option,
200  const std::string& undefined = "") const;
201 
203  const std::map<std::string, std::string>& MetaDataOptions() const;
204 
206 
210  const std::string& MetaDataOption(const std::string& option,
211  const std::string& undefined = "") const;
212 
214 
220  bool AddOption(const std::string& option, const std::string& value,
221  bool overwrite = true);
222 
224 
227  bool AddOption(const std::string& option, bool overwrite = true);
228 
230  void AddMetaDataOption(const std::string& option, const std::string& value,
231  bool overwrite = true);
232 
234  void AddLocation(const URLLocation& location);
235 
237  const std::list<URLLocation>& Locations() const;
238 
240  const std::map<std::string, std::string>& CommonLocOptions() const;
241 
243 
247  const std::string& CommonLocOption(const std::string& option,
248  const std::string&
249  undefined = "") const;
250 
252 
253  void RemoveOption(const std::string& option);
254 
256 
257  void RemoveMetaDataOption(const std::string& option);
258 
260  virtual std::string str(bool encode = false) const;
261 
263  virtual std::string plainstr(bool encode = false) const;
264 
266  virtual std::string fullstr(bool encode = false) const;
267 
269  virtual std::string ConnectionURL() const;
270 
272  bool operator<(const URL& url) const;
273 
275  bool operator==(const URL& url) const;
276 
278  operator bool() const;
280  bool operator!() const;
281 
283  bool StringMatches(const std::string& str) const;
284 
285 
287  std::map<std::string, std::string> ParseOptions(const std::string& optstring,
288  char separator, bool encoded = false);
289 
291 
294  static std::string OptionString(const std::map<std::string,
295  std::string>& options, char separator, bool encode = false);
296 
298 
299  static std::string URIEncode(const std::string& str);
300 
302 
303  static std::string URIDecode(const std::string& str);
304 
305  protected:
307  std::string protocol;
308 
310  std::string username;
311 
313  std::string passwd;
314 
316  std::string host;
317 
319  bool ip6addr;
320 
322  int port;
323 
325  std::string path;
326 
328  std::map<std::string, std::string> httpoptions;
329 
331  std::map<std::string, std::string> metadataoptions;
332 
334  std::list<std::string> ldapattributes;
335 
338 
340  std::string ldapfilter;
341 
343  std::map<std::string, std::string> urloptions;
344 
346  std::list<URLLocation> locations;
347 
349  std::map<std::string, std::string> commonlocoptions;
350 
352  bool valid;
353 
355  static std::string BaseDN2Path(const std::string&);
356 
358  static std::string Path2BaseDN(const std::string&);
359 
361  friend std::ostream& operator<<(std::ostream& out, const URL& u);
362 
364  void ParsePath(bool encoded = false);
365  };
366 
367 
369 
373  : public URL {
374 
375  public:
377  URLLocation(const std::string& url = "");
378 
380  URLLocation(const std::string& url, const std::string& name);
381 
383  URLLocation(const URL& url);
384 
386  URLLocation(const URL& url, const std::string& name);
387 
389  URLLocation(const std::map<std::string, std::string>& options,
390  const std::string& name);
391 
393  virtual ~URLLocation();
394 
396  const std::string& Name() const;
397 
399  virtual std::string str() const;
400 
402  virtual std::string fullstr() const;
403 
404  protected:
406  std::string name;
407  };
408 
409 
411 
413  class PathIterator {
414  public:
416 
418  PathIterator(const std::string& path, bool end = false);
419  ~PathIterator();
420 
423 
426 
428  operator bool() const;
429 
431  std::string operator*() const;
432 
434  std::string Rest() const;
435 
436  private:
437  const std::string& path;
438  std::string::size_type pos;
439  bool end;
440  bool done;
441  };
442 
443 
445  std::list<URL> ReadURLList(const URL& urllist);
446 
447 } // namespace Arc
448 
449 #endif // __ARC_URL_H__