Back to index

nordugrid-arc-nox  1.1.0~rc6
URL.h
Go to the documentation of this file.
00001 // -*- indent-tabs-mode: nil -*-
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 SRM_DEFAULT_PORT 8443
00019 #define LDAP_DEFAULT_PORT 389
00020 #define FTP_DEFAULT_PORT 21
00021 #define GSIFTP_DEFAULT_PORT 2811
00022 #define LFC_DEFAULT_PORT 5010
00023 
00024 
00025 namespace Arc {
00026 
00027   class URLLocation;
00028 
00029 
00031 
00074   class URL {
00075 
00076   public:
00079     URL();
00080 
00082     URL(const std::string& url);
00083 
00085     virtual ~URL();
00086 
00088     enum Scope {
00089       base, onelevel, subtree
00090     };
00091 
00093     const std::string& Protocol() const;
00094 
00096     void ChangeProtocol(const std::string& newprot);
00097 
00099     bool IsSecureProtocol() const;
00100 
00102     const std::string& Username() const;
00103 
00105     const std::string& Passwd() const;
00106 
00108     const std::string& Host() const;
00109 
00111     void ChangeHost(const std::string& newhost);
00112 
00114     int Port() const;
00115 
00117     void ChangePort(int newport);
00118 
00120     const std::string& Path() const;
00121 
00123     std::string FullPath() const;
00124 
00126     void ChangePath(const std::string& newpath);
00127 
00129     const std::map<std::string, std::string>& HTTPOptions() const;
00130 
00135     const std::string& HTTPOption(const std::string& option,
00136                                   const std::string& undefined = "") const;
00137 
00139     const std::list<std::string>& LDAPAttributes() const;
00140 
00142     void AddLDAPAttribute(const std::string& attribute);
00143 
00145     Scope LDAPScope() const;
00146 
00148     void ChangeLDAPScope(const Scope newscope);
00149 
00151     const std::string& LDAPFilter() const;
00152 
00154     void ChangeLDAPFilter(const std::string& newfilter);
00155 
00157     const std::map<std::string, std::string>& Options() const;
00158 
00163     const std::string& Option(const std::string& option,
00164                               const std::string& undefined = "") const;
00165 
00167     const std::map<std::string, std::string>& MetaDataOptions() const;
00168 
00173     const std::string& MetaDataOption(const std::string& option,
00174                                       const std::string& undefined = "") const;
00175 
00177     void AddOption(const std::string& option, const std::string& value,
00178                    bool overwrite = true);
00179 
00181     const std::list<URLLocation>& Locations() const;
00182 
00184     const std::map<std::string, std::string>& CommonLocOptions() const;
00185 
00190     const std::string& CommonLocOption(const std::string& option,
00191                                        const std::string&
00192                                        undefined = "") const;
00193 
00195     virtual std::string str() const;
00196 
00198     virtual std::string fullstr() const;
00199 
00201     virtual std::string ConnectionURL() const;
00202 
00204     bool operator<(const URL& url) const;
00205 
00207     bool operator==(const URL& url) const;
00208 
00210     operator bool() const;
00211     bool operator!() const;
00212 
00214     std::map<std::string, std::string> ParseOptions(const std::string& optstring,
00215                                                     char separator);
00216 
00218     static std::string OptionString(const std::map<std::string,
00219                                                    std::string>& options, char separator);
00220 
00221   protected:
00223     std::string protocol;
00224 
00226     std::string username;
00227 
00229     std::string passwd;
00230 
00232     std::string host;
00233 
00235     bool ip6addr;
00236 
00238     int port;
00239 
00241     std::string path;
00242 
00244     std::map<std::string, std::string> httpoptions;
00245 
00247     std::map<std::string, std::string> metadataoptions;
00248 
00250     std::list<std::string> ldapattributes;
00251 
00253     Scope ldapscope;
00254 
00256     std::string ldapfilter;
00257 
00259     std::map<std::string, std::string> urloptions;
00260 
00262     std::list<URLLocation> locations;
00263 
00265     std::map<std::string, std::string> commonlocoptions;
00266 
00268     bool valid;
00269 
00271     static std::string BaseDN2Path(const std::string&);
00272 
00274     static std::string Path2BaseDN(const std::string&);
00275 
00277     friend std::ostream& operator<<(std::ostream& out, const URL& u);
00278   };
00279 
00280 
00282 
00283   class URLLocation
00284     : public URL {
00285 
00286   public:
00288     URLLocation(const std::string& url);
00289 
00291     URLLocation(const std::string& url, const std::string& name);
00292 
00294     URLLocation(const URL& url);
00295 
00297     URLLocation(const URL& url, const std::string& name);
00298 
00300     URLLocation(const std::map<std::string, std::string>& options,
00301                 const std::string& name);
00302 
00304     virtual ~URLLocation();
00305 
00307     const std::string& Name() const;
00308 
00310     virtual std::string str() const;
00311 
00313     virtual std::string fullstr() const;
00314 
00315   protected:
00317     std::string name;
00318   };
00319 
00320 
00322   class PathIterator {
00323   public:
00327     PathIterator(const std::string& path, bool end = false);
00328     ~PathIterator();
00329 
00331     PathIterator& operator++();
00332 
00334     PathIterator& operator--();
00335 
00337     operator bool() const;
00338 
00340     std::string operator*() const;
00341 
00343     std::string Rest() const;
00344 
00345   private:
00346     const std::string& path;
00347     std::string::size_type pos;
00348     bool end;
00349     bool done;
00350   };
00351 
00352 
00354   std::list<URL> ReadURLList(const URL& urllist);
00355 
00356 } // namespace Arc
00357 
00358 #endif //  __ARC_URL_H__