sbuild  1.7.2
config.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_CONFIG_H
20 #define SBUILD_CHROOT_CONFIG_H
21 
22 #include <sbuild/chroot/chroot.h>
23 #include <sbuild/custom-error.h>
24 
25 #include <map>
26 #include <ostream>
27 #include <vector>
28 #include <string>
29 
30 namespace sbuild
31 {
32  namespace chroot
33  {
34 
44  class config
45  {
46  public:
48  typedef std::vector<chroot::chroot::ptr> chroot_list;
50  typedef std::map<std::string, std::string> string_map;
52  typedef std::map<std::string, chroot::chroot::ptr> chroot_map;
54  typedef std::map<std::string, chroot_map> chroot_namespace_map;
55 
57  static const std::string namespace_separator;
58 
61  {
72  };
73 
76 
78  typedef std::shared_ptr<config> ptr;
79 
81  config ();
82 
91  config (const std::string& chroot_namespace,
92  const std::string& file);
93 
95  virtual ~config ();
96 
106  void
107  add (const std::string& chroot_namespace,
108  const std::string& location);
109 
110  private:
119  void
120  add_config_file (const std::string& chroot_namespace,
121  const std::string& file);
122 
131  void
132  add_config_directory (const std::string& chroot_namespace,
133  const std::string& dir);
134 
135  protected:
147  void
148  add (const std::string& chroot_namespace,
150  const keyfile& kconfig);
151 
152  public:
160  chroot_list
161  get_chroots (const std::string& chroot_namespace) const;
162 
163  protected:
171  chroot_map&
172  find_namespace (const std::string& chroot_namespace);
173 
181  chroot_map const&
182  find_namespace (const std::string& chroot_namespace) const;
183 
184  public:
192  static void
193  get_namespace(const std::string& name,
194  std::string& chroot_namespace,
195  std::string& chroot_name);
196 
204  const chroot::chroot::ptr
205  find_chroot (const std::string& name) const;
206 
215  const chroot::chroot::ptr
216  find_chroot (const std::string& namespace_hint,
217  const std::string& name) const;
218 
226  const chroot::chroot::ptr
227  find_chroot_in_namespace (const std::string& chroot_namespace,
228  const std::string& name) const;
229 
238  const chroot::chroot::ptr
239  find_alias (const std::string& namespace_hint,
240  const std::string& name) const;
241 
250  std::string
251  lookup_alias (const std::string& namespace_hint,
252  const std::string& name) const;
253 
263  get_chroot_list (const std::string& chroot_namespace) const;
264 
274  get_alias_list (const std::string& chroot_namespace) const;
275 
282  void
283  print_chroot_list_simple (std::ostream& stream) const;
284 
297  chroot_map
298  validate_chroots (const std::string& namespace_hint,
299  const string_list& chroots) const;
300 
301  private:
311  void
312  load_data (const std::string& chroot_namespace,
313  const std::string& file);
314 
315  protected:
324  virtual void
325  parse_data (const std::string& chroot_namespace,
326  std::istream& stream);
327 
336  virtual void
337  load_keyfile (const std::string& chroot_namespace,
338  keyfile& kconfig);
339 
341  chroot_namespace_map namespaces;
343  string_map aliases;
344  };
345 
346  }
347 }
348 
349 #endif /* SBUILD_CHROOT_CONFIG_H */
350 
351 /*
352  * Local Variables:
353  * mode:C++
354  * End:
355  */
File is not a regular file.
Definition: config.h:66
std::map< std::string, std::string > string_map
A map between key-value string pairs.
Definition: config.h:50
void add_config_file(const std::string &chroot_namespace, const std::string &file)
Add a configuration file.
Definition: config.cc:125
Debian source builder components.
Definition: ctty.cc:31
static void get_namespace(const std::string &name, std::string &chroot_namespace, std::string &chroot_name)
Split a chroot name into a namespace and name.
Definition: config.cc:655
chroot_map & find_namespace(const std::string &chroot_namespace)
Find a chroot namespace.
Definition: config.cc:307
custom_error< error_code > error
Exception type.
Definition: config.h:75
void print_chroot_list_simple(std::ostream &stream) const
Print a single line of all the available chroots to the specified stream.
Definition: config.cc:467
virtual void load_keyfile(const std::string &chroot_namespace, keyfile &kconfig)
Load a keyfile.
Definition: config.cc:588
void add_config_directory(const std::string &chroot_namespace, const std::string &dir)
Add a configuration directory.
Definition: config.cc:138
static const std::string namespace_separator
Namespace separating character.
Definition: config.h:57
chroot_namespace_map namespaces
A list of chroots (name->chroot mapping).
Definition: config.h:341
Alias already associated with chroot.
Definition: config.h:62
File is not owned by user root.
Definition: config.h:68
virtual void parse_data(const std::string &chroot_namespace, std::istream &stream)
Parse a loaded configuration file.
Definition: config.cc:577
string_map aliases
A list of aliases (alias->name mapping).
Definition: config.h:343
chroot_map validate_chroots(const std::string &namespace_hint, const string_list &chroots) const
Check that all the chroots specified exist.
Definition: config.cc:501
std::shared_ptr< config > ptr
A shared_ptr to a config object.
Definition: config.h:78
Common chroot data.
Definition: chroot.h:50
std::map< std::string, chroot::chroot::ptr > chroot_map
A map between a chroot name and a chroot object.
Definition: config.h:52
virtual ~config()
The destructor.
Definition: config.cc:107
Chroots not found.
Definition: config.h:64
string_list get_alias_list(const std::string &chroot_namespace) const
Get the names (including aliases) of all the available chroots, sorted in alphabetical order...
Definition: config.cc:443
chroot_list get_chroots(const std::string &chroot_namespace) const
Get a list of available chroots.
Definition: config.cc:293
error_code
Error codes.
Definition: config.h:60
Chroot not found.
Definition: config.h:63
const chroot::chroot::ptr find_chroot_in_namespace(const std::string &chroot_namespace, const std::string &name) const
Find a chroot by its name in a specific namespace.
Definition: config.cc:357
std::vector< chroot::chroot::ptr > chroot_list
A list of chroots.
Definition: config.h:48
std::vector< std::string > string_list
A string vector.
Definition: types.h:38
Failed to open file.
Definition: config.h:67
Custom error.
Definition: custom-error.h:31
const chroot::chroot::ptr find_chroot(const std::string &name) const
Find a chroot by its name.
Definition: config.cc:329
std::shared_ptr< chroot > ptr
A shared_ptr to a chroot object.
Definition: chroot.h:103
File has write permissions for others.
Definition: config.h:69
Configuration file parser.
Definition: keyfile.h:46
const chroot::chroot::ptr find_alias(const std::string &namespace_hint, const std::string &name) const
Find a chroot by its name or an alias.
Definition: config.cc:376
std::map< std::string, chroot_map > chroot_namespace_map
A map between a chroot namespace and a chroot map object.
Definition: config.h:54
Chroot configuration.
Definition: config.h:44
Invalid name.
Definition: config.h:70
std::string lookup_alias(const std::string &namespace_hint, const std::string &name) const
Find the chroot name referred to by an alias.
Definition: config.cc:401
No such namespace.
Definition: config.h:71
string_list get_chroot_list(const std::string &chroot_namespace) const
Get the names (including aliases) of all the available chroots, sorted in alphabetical order...
Definition: config.cc:429
void add(const std::string &chroot_namespace, const std::string &location)
Add a configuration file or directory.
Definition: config.cc:112
config()
The constructor.
Definition: config.cc:86
void load_data(const std::string &chroot_namespace, const std::string &file)
Load a configuration file.
Definition: config.cc:525
A chroot or alias already exists with this name.
Definition: config.h:65