00001
00002
00003 #ifndef __ARC_URL_H__
00004 #define __ARC_URL_H__
00005
00006 #include <iostream>
00007 #include <list>
00008 #include <map>
00009 #include <string>
00010
00011
00013 #define RC_DEFAULT_PORT 389
00014 #define RLS_DEFAULT_PORT 39281
00015 #define HTTP_DEFAULT_PORT 80
00016 #define HTTPS_DEFAULT_PORT 443
00017 #define HTTPG_DEFAULT_PORT 8443
00018 #define LDAP_DEFAULT_PORT 389
00019 #define FTP_DEFAULT_PORT 21
00020 #define GSIFTP_DEFAULT_PORT 2811
00021 #define LFC_DEFAULT_PORT 5010
00022 #define XROOTD_DEFAULT_PORT 1094
00023
00024
00025 namespace Arc {
00026
00027 class URLLocation;
00028
00029
00030
00032
00087 class URL {
00088
00089 public:
00092 URL();
00093
00095 URL(const std::string& url);
00096
00098 virtual ~URL();
00099
00101 enum Scope {
00102 base, onelevel, subtree
00103 };
00104
00106 const std::string& Protocol() const;
00107
00109 void ChangeProtocol(const std::string& newprot);
00110
00112 bool IsSecureProtocol() const;
00113
00115 const std::string& Username() const;
00116
00118 const std::string& Passwd() const;
00119
00121 const std::string& Host() const;
00122
00124 void ChangeHost(const std::string& newhost);
00125
00127 int Port() const;
00128
00130 void ChangePort(int newport);
00131
00133 const std::string& Path() const;
00134
00136 std::string FullPath() const;
00137
00141 std::string FullPathURIEncoded() const;
00142
00144 void ChangePath(const std::string& newpath);
00145
00147 void ChangeFullPath(const std::string& newpath);
00148
00150 const std::map<std::string, std::string>& HTTPOptions() const;
00151
00156 const std::string& HTTPOption(const std::string& option,
00157 const std::string& undefined = "") const;
00158
00161 bool AddHTTPOption(const std::string& option, const std::string& value,
00162 bool overwrite = true);
00163
00166 void RemoveHTTPOption(const std::string& option);
00167
00169 const std::list<std::string>& LDAPAttributes() const;
00170
00172 void AddLDAPAttribute(const std::string& attribute);
00173
00175 Scope LDAPScope() const;
00176
00178 void ChangeLDAPScope(const Scope newscope);
00179
00181 const std::string& LDAPFilter() const;
00182
00184 void ChangeLDAPFilter(const std::string& newfilter);
00185
00187 const std::map<std::string, std::string>& Options() const;
00188
00193 const std::string& Option(const std::string& option,
00194 const std::string& undefined = "") const;
00195
00197 const std::map<std::string, std::string>& MetaDataOptions() const;
00198
00203 const std::string& MetaDataOption(const std::string& option,
00204 const std::string& undefined = "") const;
00205
00211 bool AddOption(const std::string& option, const std::string& value,
00212 bool overwrite = true);
00213
00217 bool AddOption(const std::string& option, bool overwrite = true);
00218
00220 void AddMetaDataOption(const std::string& option, const std::string& value,
00221 bool overwrite = true);
00222
00224 void AddLocation(const URLLocation& location);
00225
00227 const std::list<URLLocation>& Locations() const;
00228
00230 const std::map<std::string, std::string>& CommonLocOptions() const;
00231
00236 const std::string& CommonLocOption(const std::string& option,
00237 const std::string&
00238 undefined = "") const;
00239
00242 void RemoveOption(const std::string& option);
00243
00246 void RemoveMetaDataOption(const std::string& option);
00247
00249 virtual std::string str() const;
00250
00252 virtual std::string plainstr() const;
00253
00255 virtual std::string fullstr() const;
00256
00258 virtual std::string ConnectionURL() const;
00259
00261 bool operator<(const URL& url) const;
00262
00264 bool operator==(const URL& url) const;
00265
00267 operator bool() const;
00268 bool operator!() const;
00269
00271 bool StringMatches(const std::string& str) const;
00272
00273
00275 std::map<std::string, std::string> ParseOptions(const std::string& optstring,
00276 char separator);
00277
00279 static std::string OptionString(const std::map<std::string,
00280 std::string>& options, char separator);
00281
00282 protected:
00284 std::string protocol;
00285
00287 std::string username;
00288
00290 std::string passwd;
00291
00293 std::string host;
00294
00296 bool ip6addr;
00297
00299 int port;
00300
00302 std::string path;
00303
00305 std::map<std::string, std::string> httpoptions;
00306
00308 std::map<std::string, std::string> metadataoptions;
00309
00311 std::list<std::string> ldapattributes;
00312
00314 Scope ldapscope;
00315
00317 std::string ldapfilter;
00318
00320 std::map<std::string, std::string> urloptions;
00321
00323 std::list<URLLocation> locations;
00324
00326 std::map<std::string, std::string> commonlocoptions;
00327
00329 bool valid;
00330
00332 static std::string BaseDN2Path(const std::string&);
00333
00335 static std::string Path2BaseDN(const std::string&);
00336
00338 friend std::ostream& operator<<(std::ostream& out, const URL& u);
00339
00341 void ParsePath(void);
00342 };
00343
00344
00346
00347 class URLLocation
00348 : public URL {
00349
00350 public:
00352 URLLocation(const std::string& url = "");
00353
00355 URLLocation(const std::string& url, const std::string& name);
00356
00358 URLLocation(const URL& url);
00359
00361 URLLocation(const URL& url, const std::string& name);
00362
00364 URLLocation(const std::map<std::string, std::string>& options,
00365 const std::string& name);
00366
00368 virtual ~URLLocation();
00369
00371 const std::string& Name() const;
00372
00374 virtual std::string str() const;
00375
00377 virtual std::string fullstr() const;
00378
00379 protected:
00381 std::string name;
00382 };
00383
00384
00386 class PathIterator {
00387 public:
00391 PathIterator(const std::string& path, bool end = false);
00392 ~PathIterator();
00393
00395 PathIterator& operator++();
00396
00398 PathIterator& operator--();
00399
00401 operator bool() const;
00402
00404 std::string operator*() const;
00405
00407 std::string Rest() const;
00408
00409 private:
00410 const std::string& path;
00411 std::string::size_type pos;
00412 bool end;
00413 bool done;
00414 };
00415
00416
00418 std::list<URL> ReadURLList(const URL& urllist);
00419
00420 }
00421
00422 #endif // __ARC_URL_H__