Class Configuration.

Inherits Garbage

The Configuration class contains all configuration variables.

Some configuration variables are set at compile time and are available via compiledIn(). These include the path to the configuration file.

Others are available by calling text(), scalar() or toggle() for the relevant variable.

As a matter of policy, we check the configuration completely at startup. Configuration knows the type and name of all legal variables, so it can log errors as appropriate. Other classes must perform supplementary sanity checking, if possible at startup. (For example, if one variable setting makes another variable meaningless, the responsible class should check that and give an error message.)

The configuration file contains an arbitrary number of single-line variable assignments, each of which specifies an integer, a toggle, or a string.

Comments extend from a '#' sign until the end of the line. In quoted strings '#' may be used.

During initialization, create a number of Configuration::EString, Configuration::Scalar or Configuration::Toggle objects naming the variables. When all configuration variable objects have been created, call report(), and all errors are reported via the log server. Most syntax errors prevent the server(s) from starting up.

Note that if you don't call report(), a typo may result in a variable silently being reverted to default.

Configuration::Configuration()

Constructs an empty Configuration containing no variables.

Reimplements Garbage::Garbage().

static void Configuration::add( const EString & l )

Adds l to the list of unparsed variable lines, provided it's vaguely sensible.

static List<Text> * Configuration::addressVariables()

Returns a list of the variables that refer to addresses. This function is a little slow. It never returns 0.

static const char * Configuration::compiledIn( CompileTimeSetting setting )

Returns the compile-time setting.

static EString Configuration::configFile()

Returns the fully-qualified name of the configuration file (e.g. /usr/local/archiveopteryx/archiveopteryx.conf) based on the compiledIn() value for the configuration directory.

Merely a convenience.

static EString Configuration::hostname()

Returns the configured hostname (or our best guess, if no hostname has been specified in the configuration).

static void Configuration::log( const EString & m, Log::Severity s )

Logs m as a message of severity s, but not yet. report() does it later, when the log subsystem is ready.

static const char * Configuration::name( Scalar v )

Returns the variable name of configuration variable v.

static const char * Configuration::name( Text v )

Returns the variable name of configuration variable v.

static const char * Configuration::name( Toggle v )

Returns the variable name of configuration variable v.

static EString Configuration::osHostname()

Returns the best hostname we can find based on the operating system's functions.

static void Configuration::parseScalar( uint n, const EString & line )

Parses line as a scalar and stores at Configuration::Scalar n. If there are any errors, the name of n is used for reporting.

static void Configuration::parseText( uint n, const EString & line )

Parses line as a text and stores at Configuration::Text n. If there are any errors, the name of n is used for reporting.

static void Configuration::parseToggle( uint n, const EString & line )

Parses line as a toggle and stores at Configuration::Toggle n. If there are any errors, the name of n is used for reporting.

static bool Configuration::present( Scalar s )

Returns true of scalar variable s has been configured, and false if the default value is to be used.

static bool Configuration::present( Text t )

Returns true of text variable t has been configured, and false if the default value is to be used.

static bool Configuration::present( Toggle t )

Returns true of toggle t has been configured, and false if the default value is to be used.

static void Configuration::read( const EString & file, bool allowFailure )

Reads file, adding to the previous configuration data held by the object. In case of error, file is not read and an error is logged. Unknown configuration variables are logged and ignored.

If allowFailure is true, and the specified file cannot be read, it is not treated as an error.

static void Configuration::report()

Reports all errors seen so far. Most functions do not report errors themselves, because the Logger may not have read its configuration data yet by the time most of this code runs, and because some errors aren't detectable at once.

When this function is called, all log lines that haven't been tied to variables are logged as erroneous.

static uint Configuration::scalar( Scalar s )

Returns the configured value of the scalar variable s, or its default value if it hasn't been configured.

static void Configuration::setup( const EString & global, bool allowFailure )

Creates a new Configuration from file global.

If global does not contain a textual variable called "hostname", this function tries to find a suitable default, and logs a disaster if nothing is satisfactory.

If global is an empty string, the function returns without trying to parse a configuration file. This experimental measure is meant to help lib/installer.

If allowFailure is true, a non-existent configuration file is tolerated silently. Another installer-helping measure.

static EString Configuration::text( Text t )

Returns the configured value of the text variable t, or its default value if it hasn't been configured.

static bool Configuration::toggle( Toggle t )

Returns the configured value of the toggle t, or its default value if it hasn't been configured.

This web page based on source code belonging to The Archiveopteryx Developers. All rights reserved.