sbuild  1.7.1
userdata.h
1 /* Copyright © 2005-2013 Roger Leigh <rleigh@debian.org>
2  *
3  * schroot is free software: you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by
5  * the Free Software Foundation, either version 3 of the License, or
6  * (at your option) any later version.
7  *
8  * schroot is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see
15  * <http://www.gnu.org/licenses/>.
16  *
17  *********************************************************************/
18 
19 #ifndef SBUILD_CHROOT_FACET_USERDATA_H
20 #define SBUILD_CHROOT_FACET_USERDATA_H
21 
22 #include <sbuild/chroot/facet/facet.h>
23 #include <sbuild/custom-error.h>
24 #include <sbuild/types.h>
25 
26 namespace sbuild
27 {
28  namespace chroot
29  {
30  namespace facet
31  {
32 
39  class userdata : public facet
40  {
41  public:
44  {
50  };
51 
54 
56  typedef std::shared_ptr<userdata> ptr;
57 
59  typedef std::shared_ptr<const userdata> const_ptr;
60 
61  private:
63  userdata ();
64 
65  public:
67  virtual ~userdata ();
68 
74  static ptr
75  create ();
76 
77  virtual facet::ptr
78  clone () const;
79 
80  virtual std::string const&
81  get_name () const;
82 
83  virtual void
84  setup_env (environment& env) const;
85 
86  virtual void
87  get_details (format_detail& detail) const;
88 
89  virtual void
90  get_used_keys (string_list& used_keys) const;
91 
92  virtual void
93  get_keyfile (keyfile& keyfile) const;
94 
95  virtual void
96  set_keyfile (const keyfile& keyfile);
97 
98 
99  template <typename T>
100  bool
101  get_value (const std::string& key,
102  T& value) const
103  {
104  log_debug(DEBUG_INFO) << "Getting userdata key=" << key << std::endl;
105  const string_map::const_iterator found_item = this->data.find(key);
106  if (found_item != this->data.end())
107  {
108  try
109  {
110  parse_value(found_item->second, value);
111  return true;
112  }
113  catch (const parse_value_error& e)
114  {
115  error ep(key, PARSE_ERROR, e);
117  return false;
118  }
119  }
120  return false;
121  }
122 
128  string_map const&
129  get_data () const;
130 
139  bool
140  get_data (const std::string& key,
141  std::string& value) const;
142 
149  void
150  set_data (const string_map& data);
151 
159  void
160  set_data (const std::string& key,
161  const std::string& value);
162 
170  void
171  set_system_data (const std::string& key,
172  const std::string& value);
173 
179  void
180  remove_data (const std::string& key);
181 
187  string_set const&
188  get_user_modifiable_keys () const;
189 
195  void
196  set_user_modifiable_keys (const string_set& keys);
197 
203  string_set const&
204  get_root_modifiable_keys () const;
205 
211  void
212  set_root_modifiable_keys (const string_set& keys);
213 
221  void
222  set_user_data(const string_map& data);
223 
231  void
232  set_root_data(const string_map& data);
233 
239  void
241 
242  private:
250  void
251  set_data(const string_map& data,
252  const string_set& allowed_keys,
253  bool root);
254 
263  };
264 
265  }
266  }
267 }
268 
269 #endif /* SBUILD_CHROOT_FACET_USERDATA_H */
270 
271 /*
272  * Local Variables:
273  * mode:C++
274  * End:
275  */