Public Member Functions | Protected Attributes

ConfigReader Class Reference

#include <config.h>

Public Member Functions

 ConfigReader ()
 ConfigReader (const Anope::string &)
 ~ConfigReader ()
Anope::string ReadValue (const Anope::string &, const Anope::string &, int, bool=false)
Anope::string ReadValue (const Anope::string &, const Anope::string &, const Anope::string &, int, bool=false)
bool ReadFlag (const Anope::string &, const Anope::string &, int)
bool ReadFlag (const Anope::string &, const Anope::string &, const Anope::string &, int)
int ReadInteger (const Anope::string &, const Anope::string &, int, bool)
int ReadInteger (const Anope::string &, const Anope::string &, const Anope::string &, int, bool)
long GetError ()
int Enumerate (const Anope::string &) const
bool Verify ()
int EnumerateValues (const Anope::string &, int)

Protected Attributes

bool readerror
long error

Detailed Description

Allows reading of values from configuration files This class allows a module to read from either the main configuration file (services.conf) or from a module-specified configuration file. It may either be instantiated with one parameter or none. Constructing the class using one parameter allows you to specify a path to your own configuration file, otherwise, inspircd.conf is read.

Definition at line 720 of file config.h.


Constructor & Destructor Documentation

ConfigReader::ConfigReader (  ) 

Default constructor. This constructor initialises the ConfigReader class to read the configuration file(s).

Definition at line 30 of file configreader.cpp.

ConfigReader::ConfigReader ( const Anope::string filename  ) 

Overloaded constructor. This constructor initialises the ConfigReader class to read a user-specified config file

Definition at line 34 of file configreader.cpp.

ConfigReader::~ConfigReader (  ) 

Default destructor. This method destroys the ConfigReader class.

Definition at line 38 of file configreader.cpp.


Member Function Documentation

int ConfigReader::Enumerate ( const Anope::string tag  )  const

Counts the number of times a given tag appears in the config file. This method counts the number of times a tag appears in a config file, for use where there are several tags of the same kind, e.g. with opers and connect types. It can be used with the index value of ConfigReader::ReadValue to loop through all copies of a multiple instance tag.

Definition at line 99 of file configreader.cpp.

References Config, ServerConfig::config_data, and ServerConfig::ConfValueEnum().

Referenced by ModuleSQLite::OnReload(), ModuleRewrite::OnReload(), ModuleProxyScan::OnReload(), ModuleSQL::OnReload(), ModuleLDAP::OnReload(), HTTPD::OnReload(), ModuleDNSBL::OnReload(), NSSetMisc::OnReload(), CSSetMisc::OnReload(), CSFlags::OnReload(), and CSAccess::OnReload().

int ConfigReader::EnumerateValues ( const Anope::string tag,
int  index 
)

Returns the number of items within a tag. For example if the tag was <test tag="blah" data="foo"> then this function would return 2. Spaces and newlines both qualify as valid seperators between values.

Definition at line 104 of file configreader.cpp.

References Config, ServerConfig::config_data, and ServerConfig::ConfVarEnum().

long ConfigReader::GetError (  ) 

Returns the last error to occur. Valid errors can be found by looking in modules.h. Any nonzero value indicates an error condition. A call to GetError() resets the error flag back to 0.

Definition at line 92 of file configreader.cpp.

References error.

bool ConfigReader::ReadFlag ( const Anope::string tag,
const Anope::string name,
const Anope::string default_value,
int  index 
)

Retrieves a boolean value from the config file. This method retrieves a boolean value from the config file. Where multiple copies of the tag exist in the config file, index indicates which of the values to retrieve. The values "1", "yes" and "true" in the config file count as true to ReadFlag, and any other value counts as false. If the tag is not found, the default value is used instead.

Definition at line 58 of file configreader.cpp.

References Config, ServerConfig::config_data, and ServerConfig::ConfValueBool().

bool ConfigReader::ReadFlag ( const Anope::string tag,
const Anope::string name,
int  index 
)

Retrieves a boolean value from the config file. This method retrieves a boolean value from the config file. Where multiple copies of the tag exist in the config file, index indicates which of the values to retrieve. The values "1", "yes" and "true" in the config file count as true to ReadFlag, and any other value counts as false.

Definition at line 63 of file configreader.cpp.

Referenced by ModuleWebCPanel::ModuleWebCPanel(), SSLModule::OnPreServerConnect(), ModuleRewrite::OnReload(), ModuleProxyScan::OnReload(), HTTPD::OnReload(), ModuleDNSBL::OnReload(), DBFlatFile::OnReload(), ModuleDNS::OnReload(), OSDefcon::OnReload(), NSSet::OnReload(), HSRequest::OnReload(), and CSSet::OnReload().

int ConfigReader::ReadInteger ( const Anope::string tag,
const Anope::string name,
int  index,
bool  need_positive 
)

Retrieves an integer value from the config file. This method retrieves an integer value from the config file. Where multiple copies of the tag exist in the config file, index indicates which of the values to retrieve. Any invalid integer values in the tag will cause the objects error value to be set, and any call to GetError() will return CONF_INVALID_NUMBER to be returned. need_positive is set if the number must be non-negative. If a negative number is placed into a tag which is specified positive, 0 will be returned and GetError() will return CONF_INT_NEGATIVE. Note that need_positive is not suitable to get an unsigned int - you should cast the result to achieve that effect.

Definition at line 87 of file configreader.cpp.

Referenced by NSMaxEmail::OnReload(), ModuleProxyScan::OnReload(), ModuleSQL::OnReload(), ModuleLDAP::OnReload(), HTTPD::OnReload(), ModuleDNS::OnReload(), OSDefcon::OnReload(), CSEntryMessage::OnReload(), and CSAccess::OnReload().

int ConfigReader::ReadInteger ( const Anope::string tag,
const Anope::string name,
const Anope::string default_value,
int  index,
bool  need_positive 
)

Retrieves an integer value from the config file. This method retrieves an integer value from the config file. Where multiple copies of the tag exist in the config file, index indicates which of the values to retrieve. Any invalid integer values in the tag will cause the objects error value to be set, and any call to GetError() will return CONF_INVALID_NUMBER to be returned. needs_unsigned is set if the number must be unsigned. If a signed number is placed into a tag which is specified unsigned, 0 will be returned and GetError() will return CONF_NOT_UNSIGNED. If the tag is not found, the default value is used instead.

Definition at line 68 of file configreader.cpp.

References Config, ServerConfig::config_data, ServerConfig::ConfValueInteger(), and error.

Anope::string ConfigReader::ReadValue ( const Anope::string tag,
const Anope::string name,
const Anope::string default_value,
int  index,
bool  allow_linefeeds = false 
)

Retrieves a value from the config file. This method retrieves a value from the config file. Where multiple copies of the tag exist in the config file, index indicates which of the values to retrieve. If the tag is not found the default value is returned instead.

Definition at line 42 of file configreader.cpp.

References CONF_VALUE_NOT_FOUND, Config, ServerConfig::config_data, ServerConfig::ConfValue(), and error.

Anope::string ConfigReader::ReadValue ( const Anope::string tag,
const Anope::string name,
int  index,
bool  allow_linefeeds = false 
)
bool ConfigReader::Verify (  ) 

Returns true if a config file is valid. This method is partially implemented and will only return false if the config file does not exist or could not be opened.

Definition at line 109 of file configreader.cpp.

References readerror.


Field Documentation

long ConfigReader::error [protected]

Error code

Definition at line 728 of file config.h.

Referenced by GetError(), ReadInteger(), and ReadValue().

bool ConfigReader::readerror [protected]

True if an error occured reading the config file

Definition at line 725 of file config.h.

Referenced by Verify().


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