CernVM-FS  2.12.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  private:
29  std::map<std::string, std::string> templates_;
30 };
31 
33  public:
34  explicit DefaultOptionsTemplateManager(std::string fqrn);
35  private:
36  static const char *kTemplateIdentFqrn;
37  static const char *kTemplateIdentOrg;
38 };
39 
48  public:
49  explicit OptionsManager(OptionsTemplateManager *opt_templ_mgr_param)
50  : taint_environment_(true) {
51  if (opt_templ_mgr_param != NULL) {
52  opt_templ_mgr_ = opt_templ_mgr_param;
53  } else {
54  opt_templ_mgr_ = new OptionsTemplateManager();
55  }
56  }
57 
58  OptionsManager(const OptionsManager& opt_mgr) {
59  config_ = opt_mgr.config_;
60  protected_parameters_ = opt_mgr.protected_parameters_;
61  templatable_values_ = opt_mgr.templatable_values_;
62  taint_environment_ = opt_mgr.taint_environment_;
63 
64  opt_templ_mgr_ = new OptionsTemplateManager(*(opt_mgr.opt_templ_mgr_));
65  }
66 
67  virtual ~OptionsManager() {
68  delete opt_templ_mgr_;
69  }
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(
162  const std::string &key_prefix,
163  bool strip_prefix);
164 
173  std::string Dump();
174 
175  bool HasConfigRepository(const std::string &fqrn, std::string *config_path);
176 
181  void ProtectParameter(const std::string &param);
182 
186  void SetValue(const std::string &key, const std::string &value);
187 
192  void SetValueFromTalk(const std::string &key, const std::string &value);
193 
197  void UnsetValue(const std::string &key);
198 
199  void set_taint_environment(bool value) { taint_environment_ = value; }
200 
201  protected:
206  struct ConfigValue {
207  std::string value;
208  std::string source;
209  };
210 
211  std::string TrimParameter(const std::string &parameter);
212  std::string SanitizeParameterAssignment(std::string *line,
213  std::vector <std::string> *tokens);
214  void PopulateParameter(const std::string &param, const ConfigValue val);
215  void ParseValue(const std::string param, ConfigValue *val);
216  void UpdateEnvironment(
217  const std::string &param, ConfigValue val);
218  std::map<std::string, ConfigValue> config_;
219  std::map<std::string, std::string> protected_parameters_;
220  std::map<std::string, std::string> templatable_values_;
221 
228 
229  private:
230  // NOLINTNEXTLINE(bugprone-unhandled-self-assignment,cert-oop54-cpp)
231  OptionsManager & operator= (const OptionsManager & /* other */) {
232  assert(false);
233  }
234 }; // class OptionManager
235 
236 
253  public:
255  OptionsTemplateManager *opt_templ_mgr_param = NULL)
256  : OptionsManager(opt_templ_mgr_param) { }
257  virtual void ParsePath(
258  const std::string &config_file,
259  const bool external __attribute__((unused))) {
260  (void) TryParsePath(config_file);
261  }
262  // Libcvmfs returns success or failure, the fuse module fails silently
263  bool TryParsePath(const std::string &config_file);
264 }; // class SimpleOptionsManager
265 
266 
274  public:
276  OptionsTemplateManager *opt_templ_mgr_param = NULL)
277  : OptionsManager(opt_templ_mgr_param) { }
278  void ParsePath(const std::string &config_file, const bool external);
279 }; // class BashOptionsManager
280 
281 
282 
283 #ifdef CVMFS_NAMESPACE_GUARD
284 } // namespace CVMFS_NAMESPACE_GUARD
285 #endif
286 
287 #endif // CVMFS_OPTIONS_H_
static const char * kTemplateIdentOrg
Definition: options.h:37
static const char * kTemplateIdentFqrn
Definition: options.h:36
OptionsManager(OptionsTemplateManager *opt_templ_mgr_param)
Definition: options.h:49
void set_taint_environment(bool value)
Definition: options.h:199
std::map< std::string, std::string > protected_parameters_
Definition: options.h:219
std::map< std::string, std::string > templatable_values_
Definition: options.h:220
OptionsTemplateManager * opt_templ_mgr_
Definition: options.h:222
BashOptionsManager(OptionsTemplateManager *opt_templ_mgr_param=NULL)
Definition: options.h:275
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:218
SimpleOptionsParser(OptionsTemplateManager *opt_templ_mgr_param=NULL)
Definition: options.h:254
std::map< std::string, std::string > templates_
Definition: options.h:29
virtual void ParsePath(const std::string &config_file, const bool external __attribute__((unused)))
Definition: options.h:257
OptionsManager(const OptionsManager &opt_mgr)
Definition: options.h:58
bool taint_environment_
Definition: options.h:227
virtual ~OptionsManager()
Definition: options.h:67