CernVM-FS  2.13.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
options.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_OPTIONS_H_
6 #define CVMFS_OPTIONS_H_
7 
8 #include <stdint.h>
9 
10 #include <cassert>
11 #include <map>
12 #include <string>
13 #include <vector>
14 
15 #ifdef CVMFS_NAMESPACE_GUARD
16 namespace CVMFS_NAMESPACE_GUARD {
17 #endif
18 
23  public:
24  void SetTemplate(std::string name, std::string val);
25  std::string GetTemplate(std::string name);
26  bool HasTemplate(std::string name);
27  bool ParseString(std::string *input);
28 
29  private:
30  std::map<std::string, std::string> templates_;
31 };
32 
34  public:
35  explicit DefaultOptionsTemplateManager(std::string fqrn);
36 
37  private:
38  static const char *kTemplateIdentFqrn;
39  static const char *kTemplateIdentOrg;
40 };
41 
50  public:
51  explicit OptionsManager(OptionsTemplateManager *opt_templ_mgr_param)
52  : taint_environment_(true) {
53  if (opt_templ_mgr_param != NULL) {
54  opt_templ_mgr_ = opt_templ_mgr_param;
55  } else {
56  opt_templ_mgr_ = new OptionsTemplateManager();
57  }
58  }
59 
60  OptionsManager(const OptionsManager &opt_mgr) {
61  config_ = opt_mgr.config_;
62  protected_parameters_ = opt_mgr.protected_parameters_;
63  templatable_values_ = opt_mgr.templatable_values_;
64  taint_environment_ = opt_mgr.taint_environment_;
65 
66  opt_templ_mgr_ = new OptionsTemplateManager(*(opt_mgr.opt_templ_mgr_));
67  }
68 
69  virtual ~OptionsManager() { delete opt_templ_mgr_; }
70 
74  void SwitchTemplateManager(OptionsTemplateManager *opt_templ_mgr_param);
75 
85  virtual void ParsePath(const std::string &config_file,
86  const bool external) = 0;
87 
91  void ParseDefault(const std::string &fqrn);
92 
96  void ClearConfig();
97 
104  bool IsDefined(const std::string &key);
105 
113  bool GetValue(const std::string &key, std::string *value) const;
114 
122  std::string GetValueOrDie(const std::string &key);
123 
132  bool GetSource(const std::string &key, std::string *value);
133 
140  bool IsOn(const std::string &param_value) const;
141 
148  bool IsOff(const std::string &param_value) const;
149 
155  std::vector<std::string> GetAllKeys();
156 
161  std::vector<std::string> GetEnvironmentSubset(const std::string &key_prefix,
162  bool strip_prefix);
163 
172  std::string Dump();
173 
174  bool HasConfigRepository(const std::string &fqrn, std::string *config_path);
175 
180  void ProtectParameter(const std::string &param);
181 
185  void SetValue(const std::string &key, const std::string &value);
186 
191  void SetValueFromTalk(const std::string &key, const std::string &value);
192 
196  void UnsetValue(const std::string &key);
197 
198  void set_taint_environment(bool value) { taint_environment_ = value; }
199 
200  protected:
205  struct ConfigValue {
206  std::string value;
207  std::string source;
208  };
209 
210  std::string TrimParameter(const std::string &parameter);
211  std::string SanitizeParameterAssignment(std::string *line,
212  std::vector<std::string> *tokens);
213  void PopulateParameter(const std::string &param, const ConfigValue val);
214  void ParseValue(const std::string param, ConfigValue *val);
215  void UpdateEnvironment(const std::string &param, ConfigValue val);
216  std::map<std::string, ConfigValue> config_;
217  std::map<std::string, std::string> protected_parameters_;
218  std::map<std::string, std::string> templatable_values_;
219 
226 
227  private:
228  // NOLINTNEXTLINE(bugprone-unhandled-self-assignment,cert-oop54-cpp)
229  OptionsManager &operator=(const OptionsManager & /* other */) {
230  assert(false);
231  }
232 }; // class OptionManager
233 
234 
251  public:
253  OptionsTemplateManager *opt_templ_mgr_param = NULL)
254  : OptionsManager(opt_templ_mgr_param) { }
255  virtual void ParsePath(const std::string &config_file,
256  const bool external __attribute__((unused))) {
257  (void)TryParsePath(config_file);
258  }
259  // Libcvmfs returns success or failure, the fuse module fails silently
260  bool TryParsePath(const std::string &config_file);
261 }; // class SimpleOptionsManager
262 
263 
271  public:
273  OptionsTemplateManager *opt_templ_mgr_param = NULL)
274  : OptionsManager(opt_templ_mgr_param) { }
275  void ParsePath(const std::string &config_file, const bool external);
276 }; // class BashOptionsManager
277 
278 
279 #ifdef CVMFS_NAMESPACE_GUARD
280 } // namespace CVMFS_NAMESPACE_GUARD
281 #endif
282 
283 #endif // CVMFS_OPTIONS_H_
static const char * kTemplateIdentOrg
Definition: options.h:39
static const char * kTemplateIdentFqrn
Definition: options.h:38
OptionsManager(OptionsTemplateManager *opt_templ_mgr_param)
Definition: options.h:51
void set_taint_environment(bool value)
Definition: options.h:198
std::map< std::string, std::string > protected_parameters_
Definition: options.h:217
std::map< std::string, std::string > templatable_values_
Definition: options.h:218
OptionsTemplateManager * opt_templ_mgr_
Definition: options.h:220
BashOptionsManager(OptionsTemplateManager *opt_templ_mgr_param=NULL)
Definition: options.h:272
assert((mem||(size==0))&&"Out Of Memory")
struct cvmcache_object_info __attribute__
Definition: atomic.h:24
std::map< std::string, ConfigValue > config_
Definition: options.h:216
SimpleOptionsParser(OptionsTemplateManager *opt_templ_mgr_param=NULL)
Definition: options.h:252
std::map< std::string, std::string > templates_
Definition: options.h:30
virtual void ParsePath(const std::string &config_file, const bool external __attribute__((unused)))
Definition: options.h:255
OptionsManager & operator=(const OptionsManager &)
Definition: options.h:229
OptionsManager(const OptionsManager &opt_mgr)
Definition: options.h:60
bool taint_environment_
Definition: options.h:225
virtual ~OptionsManager()
Definition: options.h:69