ARC SDK
ArcConfig.h
1 // -*- indent-tabs-mode: nil -*-
2 
3 #ifndef __ARC_CONFIG_H__
4 #define __ARC_CONFIG_H__
5 
6 #include <string>
7 #include <list>
8 #include <arc/XMLNode.h>
9 #include <arc/StringConv.h>
10 
11 namespace Arc {
12 
14 
26  class Config
27  : public XMLNode {
28  private:
29  std::string file_name_;
30  public:
32  Config() : XMLNode(NS(), "ArcConfig") {}
34  Config(const NS& ns)
35  : XMLNode(ns, "ArcConfig") {}
37  Config(const char *filename);
39  Config(const std::string& xml_str)
40  : XMLNode(xml_str) {}
42 
45  : XMLNode(xml) {}
47 
49  Config(XMLNode xml, const std::string& filename)
50  : XMLNode(xml) {
51  file_name_ = filename;
52  }
53  ~Config(void);
55  Config(long cfg_ptr_addr);
57  Config(const Config& cfg);
59 
60  void print(void);
62  bool parse(const char *filename);
64  const std::string& getFileName(void) const {
65  return file_name_;
66  }
68  void setFileName(const std::string& filename) {
69  file_name_ = filename;
70  }
72  void save(const char *filename);
73 
75 
78  static bool elementtobool(Arc::XMLNode pnode,const char* ename,bool& val);
79 
81 
84  static bool elementtoenum(Arc::XMLNode pnode,const char* ename,int& val,const char* const opts[]);
85 
87 
90  template<typename T> static bool elementtoint(Arc::XMLNode pnode,const char* ename,T& val) {
91  std::string v = ename?pnode[ename]:pnode;
92  if(v.empty()) return true; // default
93  return Arc::stringto(v,val);
94  }
95 
96  };
97 
99 
104  class BaseConfig {
105  protected:
107  std::list<std::string> plugin_paths;
108  public:
110 
113  std::string credential;
115  std::string key;
117  std::string cert;
119  std::string proxy;
121  std::string cafile;
123  std::string cadir;
125  std::string otoken;
129  BaseConfig();
130  virtual ~BaseConfig() {}
132  void AddPluginsPath(const std::string& path);
134 
137  void AddCredential(const std::string& cred);
139  void AddPrivateKey(const std::string& path);
141  void AddCertificate(const std::string& path);
143  void AddProxy(const std::string& path);
145  void AddCAFile(const std::string& path);
147  void AddCADir(const std::string& path);
149  void AddOToken(const std::string& token);
151  void AddOverlay(XMLNode cfg);
153  void GetOverlay(std::string fname);
155 
157  virtual XMLNode MakeConfig(XMLNode cfg) const;
158  };
159 
160 } // namespace Arc
161 
162 #endif /* __ARC_CONFIG_H__ */
Arc namespace contains all core ARC classes.
Definition: ArcConfig.h:11
const std::string & getFileName(void) const
Returns file name of config file or empty string if it was generated from the XMLNode subtree...
Definition: ArcConfig.h:64
Config()
Creates empty XML tree.
Definition: ArcConfig.h:32
std::string cafile
Path to CA certificate.
Definition: ArcConfig.h:121
static bool elementtobool(Arc::XMLNode pnode, const char *ename, bool &val)
Helper method for processing element value.
void GetOverlay(std::string fname)
Read overlay from file.
Config(XMLNode xml)
Acquire existing XML (sub)tree.
Definition: ArcConfig.h:44
Config(const std::string &xml_str)
Parse configuration document from string.
Definition: ArcConfig.h:39
void print(void)
Print structure of document for debugging purposes.
std::list< std::string > plugin_paths
List of file system paths to ARC plugin files.
Definition: ArcConfig.h:107
void AddOverlay(XMLNode cfg)
Add configuration overlay.
Wrapper for LibXML library Tree interface.
Definition: XMLNode.h:61
std::string cadir
Path to directory of CA certificates.
Definition: ArcConfig.h:123
Class to represent an XML namespace.
Definition: XMLNode.h:28
Configuration for client interface.
Definition: ArcConfig.h:104
Config(XMLNode xml, const std::string &filename)
Acquire existing XML (sub)tree and set config file.
Definition: ArcConfig.h:49
std::string key
Path to private key.
Definition: ArcConfig.h:115
void save(const char *filename)
Save config to file.
bool parse(const char *filename)
Parse configuration document from file at filename.
static bool elementtoenum(Arc::XMLNode pnode, const char *ename, int &val, const char *const opts[])
Helper method for processing element value.
std::string proxy
Path to proxy certificate.
Definition: ArcConfig.h:119
std::string credential
Credential stored as string.
Definition: ArcConfig.h:113
std::string otoken
Authentication token.
Definition: ArcConfig.h:125
void AddCertificate(const std::string &path)
Add certificate.
void AddCredential(const std::string &cred)
Add credential string.
void AddPluginsPath(const std::string &path)
Adds non-standard location of plugins.
void setFileName(const std::string &filename)
Set the file name of config file.
Definition: ArcConfig.h:68
Config(const NS &ns)
Creates an empty configuration object with the given namespace.
Definition: ArcConfig.h:34
void AddCADir(const std::string &path)
Add CA directory.
static bool elementtoint(Arc::XMLNode pnode, const char *ename, T &val)
Helper method for processing element value.
Definition: ArcConfig.h:90
void AddOToken(const std::string &token)
Add authentication token.
void AddPrivateKey(const std::string &path)
Add private key.
std::string cert
Path to certificate.
Definition: ArcConfig.h:117
void AddProxy(const std::string &path)
Add credentials proxy.
T stringto(const std::string &s)
This method converts a string to any type.
Definition: StringConv.h:22
Configuration element - represents (sub)tree of ARC XML configuration.
Definition: ArcConfig.h:26
virtual XMLNode MakeConfig(XMLNode cfg) const
Adds plugin configuration into common configuration tree supplied in &#39;cfg&#39; argument.
BaseConfig()
Construct new BaseConfig. Plugin paths are determined automatically.
XMLNode overlay
Configuration overlay.
Definition: ArcConfig.h:127
void AddCAFile(const std::string &path)
Add CA file.