sbuild::chroot_config Class Reference

Chroot configuration. More...

#include <sbuild-chroot-config.h>

Inheritance diagram for sbuild::chroot_config:

Inheritance graph
[legend]
Collaboration diagram for sbuild::chroot_config:

Collaboration graph
[legend]
List of all members.

Public Types

enum  error_code {
  ALIAS_EXIST, CHROOT_NOTFOUND, CHROOT_EXIST, DIR_OPEN,
  FILE_NOTREG, FILE_OPEN, FILE_OWNER, FILE_PERMS,
  FILE_STAT
}
 Error codes. More...
typedef std::vector< chroot::ptrchroot_list
 A list of chroots.
typedef std::map< std::string,
std::string > 
string_map
 A map between key-value string pairs.
typedef std::map< std::string,
chroot::ptr
chroot_map
 A map between a chroot name and a chroot object.
typedef custom_error< error_codeerror
 Exception type.
typedef std::tr1::shared_ptr<
chroot_config
ptr
 A shared_ptr to a chroot_config object.

Public Member Functions

 chroot_config ()
 The constructor.
 chroot_config (std::string const &file, bool active)
 The constructor.
virtual ~chroot_config ()
 The destructor.
void add (std::string const &location, bool active)
 Add a configuration file or directory.
chroot_list get_chroots () const
 Get a list of available chroots.
const chroot::ptr find_chroot (std::string const &name) const
 Find a chroot by its name.
const chroot::ptr find_alias (std::string const &name) const
 Find a chroot by its name or an alias.
string_list get_chroot_list () const
 Get the names (including aliases) of all the available chroots, sorted in alphabetical order.
void print_chroot_list (std::ostream &stream) const
 Print all the available chroots to the specified stream.
void print_chroot_list_simple (std::ostream &stream) const
 Print a single line of all the available chroots to the specified stream.
void print_chroot_info (string_list const &chroots, std::ostream &stream) const
 Print information about the specified chroots to the specified stream.
void print_chroot_location (string_list const &chroots, std::ostream &stream) const
 Print location information about the specified chroots to the specified stream.
void print_chroot_config (string_list const &chroots, std::ostream &stream) const
 Print configuration of the specified chroots to the specified stream.
string_list validate_chroots (string_list const &chroots) const
 Check that all the chroots specified exist.

Protected Member Functions

void add (chroot::ptr &chroot, keyfile const &kconfig)
 Add a chroot.
virtual void parse_data (std::istream &stream, bool active)
 Parse a loaded configuration file.
virtual void load_keyfile (keyfile &kconfig, bool active)
 Load a keyfile.

Protected Attributes

chroot_map chroots
 A list of chroots (name->chroot mapping).
string_map aliases
 A list of aliases (alias->name mapping).

Private Member Functions

void add_config_file (std::string const &file, bool active)
 Add a configuration file.
void add_config_directory (std::string const &dir, bool active)
 Add a configuration directory.
void load_data (std::string const &file, bool active)
 Load a configuration file.

Detailed Description

Chroot configuration.

This class holds the configuration details from the configuration file. Conceptually, it's an opaque container of chroot objects.

Methods are provided to query the available chroots and find specific chroots.

Definition at line 43 of file sbuild-chroot-config.h.


Member Typedef Documentation

typedef std::vector<chroot::ptr> sbuild::chroot_config::chroot_list

A list of chroots.

Definition at line 47 of file sbuild-chroot-config.h.

typedef std::map<std::string, std::string> sbuild::chroot_config::string_map

A map between key-value string pairs.

Definition at line 49 of file sbuild-chroot-config.h.

typedef std::map<std::string, chroot::ptr> sbuild::chroot_config::chroot_map

A map between a chroot name and a chroot object.

Definition at line 51 of file sbuild-chroot-config.h.

typedef custom_error<error_code> sbuild::chroot_config::error

Exception type.

Definition at line 68 of file sbuild-chroot-config.h.

typedef std::tr1::shared_ptr<chroot_config> sbuild::chroot_config::ptr

A shared_ptr to a chroot_config object.

Definition at line 71 of file sbuild-chroot-config.h.


Member Enumeration Documentation

enum sbuild::chroot_config::error_code

Error codes.

Enumerator:
ALIAS_EXIST  Alias already associated with chroot.
CHROOT_NOTFOUND  No such chroot.
CHROOT_EXIST  A chroot or alias already exists by this name.
DIR_OPEN  Failed to open directory.
FILE_NOTREG  File is not a regular file.
FILE_OPEN  Failed to open file.
FILE_OWNER  File is not owned by user root.
FILE_PERMS  File has write permissions for others.
FILE_STAT  Failed to stat file.

Definition at line 54 of file sbuild-chroot-config.h.


Constructor & Destructor Documentation

chroot_config::chroot_config (  ) 

The constructor.

Reimplemented in dchroot::chroot_config, and dchroot_dsa::chroot_config.

Definition at line 85 of file sbuild-chroot-config.cc.

chroot_config::chroot_config ( std::string const &  file,
bool  active 
)

The constructor.

Parameters:
file initialise using a configuration file or a whole directory containing configuration files.
active true if the chroots in the configuration file are active sessions, otherwise false.

Reimplemented in dchroot::chroot_config, and dchroot_dsa::chroot_config.

Definition at line 90 of file sbuild-chroot-config.cc.

References add().

Here is the call graph for this function:

chroot_config::~chroot_config (  )  [virtual]

The destructor.

Reimplemented in dchroot::chroot_config, and dchroot_dsa::chroot_config.

Definition at line 97 of file sbuild-chroot-config.cc.


Member Function Documentation

void chroot_config::add ( std::string const &  location,
bool  active 
)

Add a configuration file or directory.

The configuration file or directory specified will be loaded.

Parameters:
location initialise using a configuration file or a whole directory containing configuration files.
active true if the chroots in the configuration file are active sessions, otherwise false.

Definition at line 102 of file sbuild-chroot-config.cc.

References add_config_directory(), and add_config_file().

Referenced by chroot_config(), and load_keyfile().

Here is the call graph for this function:

Here is the caller graph for this function:

void chroot_config::add_config_file ( std::string const &  file,
bool  active 
) [private]

Add a configuration file.

The configuration file specified will be loaded.

Parameters:
file the file to load.
active true if the chroots in the configuration file are active sessions, otherwise false.

Definition at line 113 of file sbuild-chroot-config.cc.

References sbuild::DEBUG_NOTICE, load_data(), and sbuild::log_debug().

Referenced by add().

Here is the call graph for this function:

Here is the caller graph for this function:

void chroot_config::add_config_directory ( std::string const &  dir,
bool  active 
) [private]

Add a configuration directory.

The configuration files in the directory specified will all be loaded.

Parameters:
dir the directory containing the files to load.
active true if the chroots in the configuration file are active sessions, otherwise false.
Todo:
Use dirstream instead of the POSIX directory functions.

Definition at line 122 of file sbuild-chroot-config.cc.

References sbuild::DEBUG_NOTICE, DIR_OPEN, FILE_NOTREG, FILE_STAT, load_data(), sbuild::log_debug(), and sbuild::log_exception_warning().

Referenced by add().

Here is the call graph for this function:

Here is the caller graph for this function:

void chroot_config::add ( chroot::ptr chroot,
keyfile const &  kconfig 
) [protected]

Add a chroot.

The lists of chroots and aliases will be updated. If a chroot or alias by the same name exists, the chroot will not be added, and a warning will be logged. Af any of the aliases already exist, a warning will be logged, and the alias will not be added.

Parameters:
chroot the chroot to add.
kconfig the chroot configuration.

Definition at line 165 of file sbuild-chroot-config.cc.

References _, ALIAS_EXIST, aliases, CHROOT_EXIST, chroots, sbuild::keyfile::get_line(), sbuild::log_exception_warning(), sbuild::keyfile::PASSTHROUGH_G, sbuild::keyfile::PASSTHROUGH_GK, sbuild::keyfile::PASSTHROUGH_LG, sbuild::keyfile::PASSTHROUGH_LGK, and sbuild::error_base::set_reason().

Here is the call graph for this function:

chroot_config::chroot_list chroot_config::get_chroots (  )  const

Get a list of available chroots.

Returns:
a list of available chroots. The list will be empty if no chroots are available.

Definition at line 248 of file sbuild-chroot-config.cc.

References chroot_alphasort(), and chroots.

Here is the call graph for this function:

const sbuild::chroot::ptr chroot_config::find_chroot ( std::string const &  name  )  const

Find a chroot by its name.

Parameters:
name the chroot name
Returns:
the chroot if found, otherwise 0.

Definition at line 263 of file sbuild-chroot-config.cc.

References chroots.

Referenced by find_alias().

Here is the caller graph for this function:

const sbuild::chroot::ptr chroot_config::find_alias ( std::string const &  name  )  const

Find a chroot by its name or an alias.

Parameters:
name the chroot name or alias.
Returns:
the chroot if found, otherwise 0.

Definition at line 277 of file sbuild-chroot-config.cc.

References aliases, and find_chroot().

Referenced by print_chroot_config(), print_chroot_info(), print_chroot_location(), and validate_chroots().

Here is the call graph for this function:

Here is the caller graph for this function:

string_list chroot_config::get_chroot_list (  )  const

Get the names (including aliases) of all the available chroots, sorted in alphabetical order.

Returns:
the list. The list will be empty if no chroots are available.

Definition at line 291 of file sbuild-chroot-config.cc.

References aliases.

Referenced by print_chroot_list().

Here is the caller graph for this function:

void chroot_config::print_chroot_list ( std::ostream &  stream  )  const

Print all the available chroots to the specified stream.

Parameters:
stream the stream to output to.

Definition at line 306 of file sbuild-chroot-config.cc.

References chroots, and get_chroot_list().

Here is the call graph for this function:

void chroot_config::print_chroot_list_simple ( std::ostream &  stream  )  const

Print a single line of all the available chroots to the specified stream.

Parameters:
stream the stream to output to.

Definition at line 318 of file sbuild-chroot-config.cc.

References _, aliases, and chroots.

void chroot_config::print_chroot_info ( string_list const &  chroots,
std::ostream &  stream 
) const

Print information about the specified chroots to the specified stream.

Parameters:
chroots a list of chroots to print.
stream the stream to output to.

Definition at line 350 of file sbuild-chroot-config.cc.

References CHROOT_NOTFOUND, find_alias(), and sbuild::log_exception_error().

Here is the call graph for this function:

void chroot_config::print_chroot_location ( string_list const &  chroots,
std::ostream &  stream 
) const

Print location information about the specified chroots to the specified stream.

Parameters:
chroots a list of chroots to print.
stream the stream to output to.

Definition at line 373 of file sbuild-chroot-config.cc.

References CHROOT_NOTFOUND, find_alias(), and sbuild::log_exception_error().

Here is the call graph for this function:

void chroot_config::print_chroot_config ( string_list const &  chroots,
std::ostream &  stream 
) const

Print configuration of the specified chroots to the specified stream.

Parameters:
chroots a list of chroots to print.
stream the stream to output to.

Definition at line 396 of file sbuild-chroot-config.cc.

References CHROOT_NOTFOUND, find_alias(), and sbuild::log_exception_error().

Here is the call graph for this function:

string_list chroot_config::validate_chroots ( string_list const &  chroots  )  const

Check that all the chroots specified exist.

Parameters:
chroots a list of chroots to validate.
Returns:
a list of invalid chroots. The list will be empty if all chroots are valid.

Definition at line 424 of file sbuild-chroot-config.cc.

References find_alias().

Here is the call graph for this function:

void chroot_config::load_data ( std::string const &  file,
bool  active 
) [private]

Load a configuration file.

If there are problems with the configuration file, an error will be thrown. The file must be owned by root, not writable by other, and be a regular file.

Parameters:
file the file to load.
active true if the chroots in the configuration file are active sessions, otherwise false.

Definition at line 441 of file sbuild-chroot-config.cc.

References sbuild::DEBUG_NOTICE, FILE_NOTREG, FILE_OPEN, FILE_OWNER, FILE_PERMS, FILE_STAT, sbuild::lock::LOCK_SHARED, sbuild::log_debug(), parse_data(), sbuild::file_lock::set_lock(), and sbuild::file_lock::unset_lock().

Referenced by add_config_directory(), and add_config_file().

Here is the call graph for this function:

Here is the caller graph for this function:

void chroot_config::parse_data ( std::istream &  stream,
bool  active 
) [protected, virtual]

Parse a loaded configuration file.

If there are problems with the configuration file, an error will be thrown.

Parameters:
stream the data stream to parse.
active true if the chroots in the configuration file are active sessions, otherwise false.

Reimplemented in dchroot::chroot_config, and dchroot_dsa::chroot_config.

Definition at line 501 of file sbuild-chroot-config.cc.

References load_keyfile().

Referenced by load_data().

Here is the call graph for this function:

Here is the caller graph for this function:

void chroot_config::load_keyfile ( keyfile kconfig,
bool  active 
) [protected, virtual]

Load a keyfile.

If there are problems with the configuration file, an error will be thrown.

Parameters:
kconfig the chroot configuration.
active true if the chroots in the configuration file are active sessions, otherwise false.

Definition at line 511 of file sbuild-chroot-config.cc.

References add(), sbuild::chroot_source::clone_source(), sbuild::chroot::create(), sbuild::chroot::get_active(), sbuild::keyfile::get_groups(), sbuild::keyfile::get_value(), and sbuild::keyfile::set_value().

Referenced by parse_data(), dchroot::chroot_config::parse_data(), and dchroot_dsa::chroot_config::parse_data().

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

chroot_map sbuild::chroot_config::chroots [protected]

A list of chroots (name->chroot mapping).

Definition at line 283 of file sbuild-chroot-config.h.

Referenced by add(), find_chroot(), get_chroots(), print_chroot_list(), and print_chroot_list_simple().

string_map sbuild::chroot_config::aliases [protected]

A list of aliases (alias->name mapping).

Definition at line 285 of file sbuild-chroot-config.h.

Referenced by add(), find_alias(), get_chroot_list(), dchroot::chroot_config::parse_data(), and print_chroot_list_simple().


The documentation for this class was generated from the following files:
Generated on Sat Jan 27 16:13:16 2007 for schroot by  doxygen 1.5.1