Back to index

nordugrid-arc-nox  1.1.0~rc6
UserConfig.h
Go to the documentation of this file.
00001 // -*- indent-tabs-mode: nil -*-
00002 
00003 #ifndef __ARC_USERCONFIG_H__
00004 #define __ARC_USERCONFIG_H__
00005 
00006 #include <list>
00007 #include <vector>
00008 #include <map>
00009 #include <string>
00010 
00011 #include <arc/ArcConfig.h>
00012 #include <arc/DateTime.h>
00013 #include <arc/URL.h>
00014 
00015 namespace Arc {
00016 
00017   typedef std::map<std::string, std::list<URL> > URLListMap;
00018 
00019   class Logger;
00020   class XMLNode;
00021 
00022   enum ServiceType {
00023     COMPUTING,
00024     INDEX
00025   };
00026 
00027   std::string tostring(const ServiceType st);
00028 
00029   class initializeCredentialsType {
00030    public:
00031     typedef enum {
00032       SkipCredentials,
00033       TryCredentials,
00034       RequireCredentials
00035     } initializeType;
00036     initializeCredentialsType(void):val(RequireCredentials) { };
00037     initializeCredentialsType(initializeType v):val(v) { };
00038     bool operator==(initializeType v) { return (val == v); };
00039     bool operator!=(initializeType v) { return (val != v); };
00040    private:
00041     initializeType val;
00042   };
00043 
00045 
00096   class UserConfig {
00097   public:
00099 
00113     UserConfig(initializeCredentialsType initializeCredentials = initializeCredentialsType());
00115 
00144     UserConfig(const std::string& conffile,
00145                initializeCredentialsType initializeCredentials = initializeCredentialsType(),
00146                bool loadSysConfig = true);
00148 
00173     UserConfig(const std::string& conffile,
00174                const std::string& jfile,
00175                initializeCredentialsType initializeCredentials = initializeCredentialsType(),
00176                bool loadSysConfig = true);
00178 
00185     UserConfig(const long int& ptraddr);
00186     ~UserConfig() {}
00187 
00189 
00253     void InitializeCredentials();
00255 
00266     bool CredentialsFound() const {
00267       return !((proxyPath.empty() && (certificatePath.empty() || keyPath.empty())) || caCertificatesDirectory.empty());
00268     }
00269 
00271 
00334     bool LoadConfigurationFile(const std::string& conffile, bool ignoreJobListFile = true);
00335 
00337 
00347     bool SaveToFile(const std::string& filename) const;
00348 
00350 
00361     void ApplyToConfig(BaseConfig& ccfg) const;
00362 
00364 
00370     operator bool() const { return ok; }
00372 
00376     bool operator!() const { return !ok; }
00377 
00379 
00397     bool JobListFile(const std::string& path);
00399 
00407     const std::string& JobListFile() const { return joblistfile; }
00408 
00410 
00446     bool AddServices(const std::list<std::string>& services, ServiceType st);
00448 
00476     bool AddServices(const std::list<std::string>& selected,
00477                      const std::list<std::string>& rejected,
00478                      ServiceType st);
00479 
00481 
00493     const URLListMap& GetSelectedServices(ServiceType st) const;
00495 
00507     const URLListMap& GetRejectedServices(ServiceType st) const;
00508 
00510 
00520     void ClearSelectedServices();
00522 
00532     void ClearSelectedServices(ServiceType st);
00534 
00544     void ClearRejectedServices();
00546 
00556     void ClearRejectedServices(ServiceType st);
00557 
00559 
00578     bool Timeout(int newTimeout);
00580 
00587     int  Timeout() const { return timeout; }
00588 
00590 
00603     bool Verbosity(const std::string& newVerbosity);
00605 
00614     const std::string& Verbosity() const { return verbosity; }
00615 
00617 
00635     bool Broker(const std::string& name);
00637 
00653     bool Broker(const std::string& name, const std::string& argument) { broker = std::make_pair<std::string, std::string>(name, argument); return true;}
00655 
00663     const std::pair<std::string, std::string>& Broker() const { return broker; }
00664 
00666 
00676     bool Bartender(const std::vector<URL>& urls) { bartenders = urls; return true; }
00678 
00686     void AddBartender(const URL& url) { bartenders.push_back(url); }
00688 
00695     const std::vector<URL>& Bartender() const { return bartenders; }
00696 
00698 
00710     bool VOMSServerPath(const std::string& path) { vomsServerPath = path; return true; }
00712 
00719     const std::string& VOMSServerPath() const { return vomsServerPath; }
00720 
00722 
00732     bool UserName(const std::string& name) { username = name; return true; }
00734 
00741     const std::string& UserName() const { return username; }
00742 
00744 
00754     bool Password(const std::string& newPassword) { password = newPassword; return true; }
00756 
00763     const std::string& Password() const { return password; }
00764 
00766 
00779     bool ProxyPath(const std::string& newProxyPath) { proxyPath = newProxyPath; return true;}
00781 
00787     const std::string& ProxyPath() const { return proxyPath; }
00788 
00790 
00807     bool CertificatePath(const std::string& newCertificatePath) { certificatePath = newCertificatePath; return true; }
00809 
00817     const std::string& CertificatePath() const { return certificatePath; }
00818 
00820 
00838     bool KeyPath(const std::string& newKeyPath) { keyPath = newKeyPath; return true; }
00840 
00851     const std::string& KeyPath() const { return keyPath; }
00852 
00854 
00867     bool KeyPassword(const std::string& newKeyPassword) { keyPassword = newKeyPassword; return true; }
00869 
00878     const std::string& KeyPassword() const { return keyPassword; }
00879 
00881 
00893     bool KeySize(int newKeySize) { keySize = newKeySize; return true;}
00895 
00904     int KeySize() const { return keySize; }
00905 
00907 
00920     bool CACertificatePath(const std::string& newCACertificatePath) { caCertificatePath = newCACertificatePath; return true; }
00922 
00929     const std::string& CACertificatePath() const { return caCertificatePath; }
00930 
00932 
00948     bool CACertificatesDirectory(const std::string& newCACertificatesDirectory) { caCertificatesDirectory = newCACertificatesDirectory; return true; }
00950 
00958     const std::string& CACertificatesDirectory() const { return caCertificatesDirectory; }
00959 
00961 
00973     bool CertificateLifeTime(const Period& newCertificateLifeTime) { certificateLifeTime = newCertificateLifeTime; return true; }
00975 
00982     const Period& CertificateLifeTime() const { return certificateLifeTime; }
00983 
00985 
00993     bool SLCS(const URL& newSLCS) { slcs = newSLCS; return true; }
00995 
01000     const URL& SLCS() const { return slcs; }
01001 
01003 
01013     bool StoreDirectory(const std::string& newStoreDirectory) { storeDirectory = newStoreDirectory; return true; }
01015 
01022     const std::string& StoreDirectory() const { return storeDirectory; }
01023 
01025 
01034     bool IdPName(const std::string& name) { idPName = name; return true; }
01036 
01042     const std::string& IdPName() const { return idPName; }
01043 
01045 
01059     bool OverlayFile(const std::string& path) { overlayfile = path; return true; }
01061 
01065     const std::string& OverlayFile() const { return overlayfile; }
01066 
01068 
01076     bool UtilsDirPath(const std::string& dir) { utilsdir = dir; return true; }
01078 
01082     const std::string& UtilsDirPath() const { return utilsdir; };
01083 
01085 
01091     static const std::string ARCUSERDIRECTORY;
01093 
01097     static const std::string SYSCONFIG;
01099 
01105     static const std::string DEFAULTCONFIG;
01107 
01111     static const std::string EXAMPLECONFIG;
01112 
01114 
01121     static const int DEFAULT_TIMEOUT = 20;
01122 
01124 
01132     static const std::string DEFAULT_BROKER;
01133 
01134   private:
01135     void setDefaults();
01136     static bool makeDir(const std::string& path);
01137     static bool copyFile(const std::string& source, const std::string& destination);
01138     bool ResolveAlias(URLListMap& services, ServiceType st,
01139                       std::list<std::string>& resolvedAlias);
01140     bool ResolveAlias(std::pair<URLListMap, URLListMap>& services,
01141                       std::list<std::string>& resolvedAlias);
01142     bool CreateDefaultConfigurationFile() const;
01143 
01144     std::string joblistfile;
01145 
01146     int timeout;
01147 
01148     std::string verbosity;
01149 
01150     // Broker name and arguments.
01151     std::pair<std::string, std::string> broker;
01152 
01153     std::pair<URLListMap, URLListMap> selectedServices;
01154     std::pair<URLListMap, URLListMap> rejectedServices;
01155 
01156     // Vector needed for random access.
01157     std::vector<URL> bartenders;
01158 
01159     std::string proxyPath;
01160     std::string certificatePath;
01161     std::string keyPath;
01162     std::string keyPassword;
01163     int keySize;
01164     std::string caCertificatePath;
01165     std::string caCertificatesDirectory;
01166     Period certificateLifeTime;
01167 
01168     URL slcs;
01169 
01170     std::string vomsServerPath;
01171 
01172     std::string storeDirectory;
01173 
01174     std::string idPName;
01175 
01176     std::string username;
01177     std::string password;
01178 
01179     std::string overlayfile;
01180     std::string utilsdir;
01181 
01182     // Private members not refered to outside this class:
01183     // Alias map.
01184     XMLNode aliasMap;
01185 
01186     bool ok;
01187 
01188     static Logger logger;
01189   };
01190 
01191 } // namespace Arc
01192 
01193 #endif // __ARC_USERCONFIG_H__