sbuild  1.7.1
Public Member Functions | Private Attributes | Friends | List of all members
sbuild::environment Class Reference

Container of environment variables. More...

#include <environment.h>

+ Inheritance diagram for sbuild::environment:
+ Collaboration diagram for sbuild::environment:

Public Member Functions

 environment ()
 The constructor.
 
 environment (char **environment)
 The constructor. More...
 
 ~environment ()
 The destructor.
 
void set_filter (const regex &filter)
 Set environment filter. More...
 
regex const & get_filter () const
 Get environment filter. More...
 
void add (char **environment)
 Add environment variables. More...
 
void add (const environment &environment)
 Add environment variables. More...
 
void add (const value_type &value)
 Add environment variable. More...
 
void add (const std::string &name, const std::string &value)
 Add environment variable. More...
 
template<typename T >
void add (const std::string &name, T const &value)
 Add environment variable. More...
 
void add (const std::string &value)
 Add environment variable. More...
 
void remove (char **environment)
 Remove environment variables. More...
 
void remove (const environment &environment)
 Remove environment variables. More...
 
void remove (const std::string &value)
 Remove environment variable. More...
 
void remove (const value_type &value)
 Remove environment variable. More...
 
template<typename T >
bool get (const std::string &name, T &value) const
 Get the value of an environment variable. More...
 
char ** get_strv () const
 Get the evironment variables as a string vector. More...
 
template<typename T >
environmentoperator+= (T const &rhs)
 Add variables to the environment. More...
 
template<typename T >
environmentoperator-= (T const &rhs)
 Remove variables from the environment. More...
 

Private Attributes

regex filter
 Filter regex.
 

Friends

template<typename T >
environment operator+ (const environment &lhs, T const &rhs)
 Add variables to the environment. More...
 
template<typename T >
environment operator- (const environment &lhs, T const &rhs)
 Remove variables from the environment. More...
 
template<class charT , class traits >
std::basic_ostream< charT,
traits > & 
operator<< (std::basic_ostream< charT, traits > &stream, const environment &rhs)
 Output the environment to an ostream. More...
 

Additional Inherited Members

- Public Attributes inherited from std::map< K, T >
keys
 STL member.
 
elements
 STL member.
 

Detailed Description

Container of environment variables.

Constructor & Destructor Documentation

sbuild::environment::environment ( char **  environment)

The constructor.

Parameters
environmentthe environment to set.

References add().

Member Function Documentation

void sbuild::environment::add ( char **  environment)
void sbuild::environment::add ( const environment environment)

Add environment variables.

Any existing variables sharing the name of a new value will be replaced.

Parameters
environmentthe environment variables to add.

References add().

void sbuild::environment::add ( const value_type &  value)

Add environment variable.

Any existing variable sharing the name will be replaced.

Parameters
valuethe environment variable to add.

References sbuild::DEBUG_INFO, sbuild::DEBUG_NOTICE, filter, sbuild::log_debug(), and sbuild::regex_search().

void sbuild::environment::add ( const std::string &  name,
const std::string &  value 
)
inline

Add environment variable.

Any existing variable sharing the name will be replaced.

Parameters
namethe environment variable name
valuethe environment variable value to add.

References add().

template<typename T >
void sbuild::environment::add ( const std::string &  name,
T const &  value 
)
inline

Add environment variable.

Any existing variable sharing the name will be replaced.

Parameters
namethe environment variable name
valuethe environment variable value to add.

References add().

void sbuild::environment::add ( const std::string &  value)

Add environment variable.

Any existing variable sharing the name will be replaced.

Parameters
valuethe environment variable to add. This is a string in the form key=value.

References add().

template<typename T >
bool sbuild::environment::get ( const std::string &  name,
T &  value 
) const
inline

Get the value of an environment variable.

Parameters
namethe name of the environment variable.
valuethe variable to store the value in on success.
Returns
true on success, false if the variable does not exist, or there is a parse error.

References sbuild::DEBUG_INFO, sbuild::DEBUG_NOTICE, sbuild::log_debug(), sbuild::log_warning(), and sbuild::parse_value().

Referenced by sbuild::session::get_login_directories(), sbuild::session::get_user_command(), and sbuild::chroot::facet::userdata::setup_env().

+ Here is the caller graph for this function:

regex const & sbuild::environment::get_filter ( ) const

Get environment filter.

Returns
the filter regex.

References filter.

char ** sbuild::environment::get_strv ( ) const

Get the evironment variables as a string vector.

This form is suitable for use as an envp argument with execve, for example.

Returns
a newly-allocated string vector. This is allocated with new, and should be freed with strv_delete().

Referenced by sbuild::exec().

+ Here is the caller graph for this function:

template<typename T >
environment& sbuild::environment::operator+= ( T const &  rhs)
inline

Add variables to the environment.

Parameters
rhsthe values to add.
Returns
the modified environment.

References add().

template<typename T >
environment& sbuild::environment::operator-= ( T const &  rhs)
inline

Remove variables from the environment.

Parameters
rhsthe values to remove.
Returns
the modified environment.
void sbuild::environment::remove ( char **  environment)

Remove environment variables.

Any variables sharing the names of a specified value will be removed.

Parameters
environmentthe environment variables to remove. This is a null-terminated array of pointers to char.

Referenced by sbuild::auth::auth::get_complete_environment().

+ Here is the caller graph for this function:

void sbuild::environment::remove ( const environment environment)

Remove environment variables.

Any variables sharing the names of a specified value will be removed.

Parameters
environmentthe environment variables to remove.
void sbuild::environment::remove ( const std::string &  value)

Remove environment variable.

Any variable sharing the name of the specified value will be removed.

Parameters
valuethe environment variable to remove.
void sbuild::environment::remove ( const value_type &  value)

Remove environment variable.

Any variable sharing the name of the specified value will be removed.

Parameters
valuethe environment variable to remove.
void sbuild::environment::set_filter ( const regex filter)

Set environment filter.

If the environment variable name matches the regex when add() is called, addition will be .

The default filter is to allow all strings.

If the regex contains errors, an exception will be thrown.

Parameters
filterthe filter regex.

References filter.

Referenced by sbuild::session::run_child().

+ Here is the caller graph for this function:

Friends And Related Function Documentation

template<typename T >
environment operator+ ( const environment lhs,
T const &  rhs 
)
friend

Add variables to the environment.

Parameters
lhsthe environment to add to.
rhsthe values to add.
Returns
the new environment.
template<typename T >
environment operator- ( const environment lhs,
T const &  rhs 
)
friend

Remove variables from the environment.

Parameters
lhsthe environment to remove from.
rhsthe values to remove.
Returns
the new environment.
template<class charT , class traits >
std::basic_ostream<charT,traits>& operator<< ( std::basic_ostream< charT, traits > &  stream,
const environment rhs 
)
friend

Output the environment to an ostream.

Parameters
streamthe stream to output to.
rhsthe environment to output.
Returns
the stream.

The documentation for this class was generated from the following files: