The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

ConfigReader Class Reference

Allows reading of values from configuration files This class allows a module to read from either the main configuration file (inspircd.conf) or from a module-specified configuration file. More...

#include <modules.h>

Inheritance diagram for ConfigReader:

Inheritance graph
[legend]
Collaboration diagram for ConfigReader:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ConfigReader (InspIRCd *Instance)
 Default constructor.
 ConfigReader (InspIRCd *Instance, const std::string &filename)
 Overloaded constructor.
 ~ConfigReader ()
 Default destructor.
std::string ReadValue (const std::string &tag, const std::string &name, int index, bool allow_linefeeds=false)
 Retrieves a value from the config file.
std::string ReadValue (const std::string &tag, const std::string &name, const std::string &default_value, int index, bool allow_linefeeds=false)
 Retrieves a value from the config file.
bool ReadFlag (const std::string &tag, const std::string &name, int index)
 Retrieves a boolean value from the config file.
bool ReadFlag (const std::string &tag, const std::string &name, const std::string &default_value, int index)
 Retrieves a boolean value from the config file.
int ReadInteger (const std::string &tag, const std::string &name, int index, bool need_positive)
 Retrieves an integer value from the config file.
int ReadInteger (const std::string &tag, const std::string &name, const std::string &default_value, int index, bool need_positive)
 Retrieves an integer value from the config file.
long GetError ()
 Returns the last error to occur.
int Enumerate (const std::string &tag)
 Counts the number of times a given tag appears in the config file.
bool Verify ()
 Returns true if a config file is valid.
void DumpErrors (bool bail, User *user)
 Dumps the list of errors in a config file to an output location.
int EnumerateValues (const std::string &tag, int index)
 Returns the number of items within a tag.

Protected Attributes

InspIRCdServerInstance
ConfigDataHashdata
 The contents of the configuration file This protected member should never be accessed by a module (and cannot be accessed unless the core is changed).
std::ostringstream * errorlog
 Used to store errors.
bool privatehash
 If we're using our own config data hash or not.
bool readerror
 True if an error occured reading the config file.
long error
 Error code.

Detailed Description

Allows reading of values from configuration files This class allows a module to read from either the main configuration file (inspircd.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 1410 of file modules.h.


Constructor & Destructor Documentation

ConfigReader::ConfigReader InspIRCd Instance  ) 
 

Default constructor.

This constructor initialises the ConfigReader class to read the inspircd.conf file as specified when running ./configure.

Definition at line 810 of file modules.cpp.

References CONF_NO_ERROR, InspIRCd::Config, ServerConfig::config_data, data, error, errorlog, privatehash, and ServerInstance.

ConfigReader::ConfigReader InspIRCd Instance,
const std::string filename
 

Overloaded constructor.

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

Definition at line 829 of file modules.cpp.

References ServerConfig::ClearStack(), CONF_FILE_NOT_FOUND, CONF_NO_ERROR, InspIRCd::Config, data, ServerConfig::DoInclude(), error, errorlog, privatehash, readerror, and ServerInstance.

ConfigReader::~ConfigReader  ) 
 

Default destructor.

This method destroys the ConfigReader class.

Definition at line 820 of file modules.cpp.

References data, errorlog, and privatehash.


Member Function Documentation

void ConfigReader::DumpErrors bool  bail,
User user
 

Dumps the list of errors in a config file to an output location.

If bail is true, then the program will abort. If bail is false and user points to a valid user record, the error report will be spooled to the given user by means of NOTICE. if bool is false AND user is false, the error report will be spooled to all opers by means of a NOTICE to all opers.

Definition at line 904 of file modules.cpp.

References InspIRCd::Config, ServerConfig::ReportConfigError(), ServerInstance, and User::uuid.

int ConfigReader::Enumerate const std::string tag  ) 
 

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 910 of file modules.cpp.

References InspIRCd::Config, ServerConfig::ConfValueEnum(), and ServerInstance.

Referenced by BufferedSocket::BindAddr(), ListModeBase::DoRehash(), CommandTitle::Handle(), ModuleSQLite3::HostInConf(), ModulePgSQL::HostInConf(), HostInConf(), ModuleMsSQL::HostInConf(), ModuleSSLOpenSSL::OnRehash(), ModuleSSLGnuTLS::OnRehash(), ModulePermanentChannels::OnRehash(), ModuleOperjoin::OnRehash(), ModuleHostChange::OnRehash(), ModuleGeoIP::OnRehash(), ModuleChanLog::OnRehash(), ModuleCgiIRC::OnRehash(), ModuleSQLOper::OperUser(), ModuleSQLite3::ReadConf(), ModulePgSQL::ReadConf(), ModuleMsSQL::ReadConf(), ModuleHelpop::ReadConfig(), and ModuleFilter::ReadFilters().

int ConfigReader::EnumerateValues const std::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 915 of file modules.cpp.

References InspIRCd::Config, ServerConfig::ConfVarEnum(), and ServerInstance.

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 897 of file modules.cpp.

References error.

Referenced by ModuleWaitPong::OnRehash(), ModuleCgiIRC::OnRehash(), and ModuleBlockAmsg::OnRehash().

bool ConfigReader::ReadFlag const std::string tag,
const std::string name,
const std::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 862 of file modules.cpp.

References InspIRCd::Config, ServerConfig::ConfValueBool(), and ServerInstance.

bool ConfigReader::ReadFlag const std::string tag,
const std::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 867 of file modules.cpp.

Referenced by CloakUser::DoRehash(), ModulePgSQL::HostInConf(), HostInConf(), LoadDatabases(), ModuleChanProtect::LoadSettings(), ModuleShowwhois::ModuleShowwhois(), InvisibleMode::OnModeChange(), ModuleOperSSLCert::OnPreCommand(), ModuleSQLAuth::OnRehash(), ModuleShun::OnRehash(), ModuleRLine::OnRehash(), ModuleRemove::OnRehash(), ModuleRegexPOSIX::OnRehash(), ModuleOverride::OnRehash(), ModuleOperjoin::OnRehash(), ModuleLDAPAuth::OnRehash(), ModuleHideChans::OnRehash(), ModuleGeoIP::OnRehash(), ModuleWaitPong::OnRehash(), ModuleCgiIRC::OnRehash(), ModuleCallerID::OnRehash(), ModuleAuditorium::OnRehash(), ModuleDenyChannels::OnUserPreJoin(), ModuleDCCAllow::OnUserPreNotice(), ModuleIdent::OnUserRegister(), ModulePgSQL::ReadConf(), and SpanningTreeUtilities::ReadConfiguration().

int ConfigReader::ReadInteger const std::string tag,
const std::string name,
const std::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 873 of file modules.cpp.

References CONF_INT_NEGATIVE, CONF_VALUE_NOT_FOUND, InspIRCd::Config, ServerConfig::ConfValueInteger(), error, and ServerInstance.

int ConfigReader::ReadInteger const std::string tag,
const std::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 892 of file modules.cpp.

Referenced by ListModeBase::DoRehash(), CloakUser::DoRehash(), ModuleSQLite3::HostInConf(), ModulePgSQL::HostInConf(), HostInConf(), ModuleMsSQL::HostInConf(), ModuleConnFlood::InitConf(), LoadDatabases(), ModuleOperLevels::OnKill(), Modulewatch::OnRehash(), ModuleSSLGnuTLS::OnRehash(), ModuleSilence::OnRehash(), ModuleSecureList::OnRehash(), ModuleSafeList::OnRehash(), ModuleIdent::OnRehash(), ModuleConnectBan::OnRehash(), ModuleCallerID::OnRehash(), ModuleBlockAmsg::OnRehash(), ModuleSQLite3::ReadConf(), ModulePgSQL::ReadConf(), ModuleMsSQL::ReadConf(), ModuleDNSBL::ReadConf(), ModuleBlockCAPS::ReadConf(), and SpanningTreeUtilities::ReadConfiguration().

std::string ConfigReader::ReadValue const std::string tag,
const std::string name,
const std::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 845 of file modules.cpp.

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

std::string ConfigReader::ReadValue const std::string tag,
const std::string name,
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.

Definition at line 857 of file modules.cpp.

Referenced by BufferedSocket::BindAddr(), ListModeBase::DoRehash(), CloakUser::DoRehash(), CommandVhost::Handle(), CommandDccallow::Handle(), CommandTitle::Handle(), ModuleSQLite3::HostInConf(), ModulePgSQL::HostInConf(), HostInConf(), ModuleMsSQL::HostInConf(), ModuleConnFlood::InitConf(), LoadDatabases(), ModuleOpermotd::LoadOperMOTD(), ModuleChanProtect::LoadSettings(), ModuleOperPrefixMode::ModuleOperPrefixMode(), ModuleRandQuote::ModuleRandQuote(), ModuleOperLevels::OnKill(), InvisibleMode::OnModeChange(), ModuleSWhois::OnPostCommand(), ModuleModesOnOper::OnPostOper(), ModuleOperSSLCert::OnPreCommand(), ModuleSSLOpenSSL::OnRehash(), ModuleSSLGnuTLS::OnRehash(), ModuleSQLOper::OnRehash(), ModuleSQLAuth::OnRehash(), ModuleShun::OnRehash(), ModuleSetHost::OnRehash(), ModuleSecureList::OnRehash(), ModuleRLine::OnRehash(), ModulePermanentChannels::OnRehash(), ModuleOverride::OnRehash(), ModuleOperjoin::OnRehash(), ModuleMapHide::OnRehash(), ModuleLDAPAuth::OnRehash(), ModuleHostChange::OnRehash(), ModuleGeoIP::OnRehash(), FilterBase::OnRehash(), ModuleDenyChannels::OnRehash(), ModuleDeaf::OnRehash(), ModuleConnectBan::OnRehash(), ModuleConnJoin::OnRehash(), ModuleChgHost::OnRehash(), ModuleChanLog::OnRehash(), ModuleCgiIRC::OnRehash(), ModuleCensor::OnRehash(), ModuleBlockAmsg::OnRehash(), ModuleModesOnConnect::OnUserConnect(), ModuleDenyChannels::OnUserPreJoin(), ModuleDCCAllow::OnUserPreNotice(), ModuleIdent::OnUserRegister(), LogManager::OpenFileLogs(), ModuleSQLOper::OperUser(), ModuleSQLite3::ReadConf(), ModulePgSQL::ReadConf(), ModuleMsSQL::ReadConf(), ModuleDNSBL::ReadConf(), ModuleBlockCAPS::ReadConf(), ModuleSQLLog::ReadConfig(), ModuleRestrictChans::ReadConfig(), ModuleHelpop::ReadConfig(), SpanningTreeUtilities::ReadConfiguration(), ModuleDCCAllow::ReadFileConf(), and ModuleFilter::ReadFilters().

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 920 of file modules.cpp.

References readerror.


Member Data Documentation

ConfigDataHash* ConfigReader::data [protected]
 

The contents of the configuration file This protected member should never be accessed by a module (and cannot be accessed unless the core is changed).

It will contain a pointer to the configuration file data with unneeded data (such as comments) stripped from it.

Definition at line 1419 of file modules.h.

Referenced by ConfigReader(), and ~ConfigReader().

long ConfigReader::error [protected]
 

Error code.

Definition at line 1431 of file modules.h.

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

std::ostringstream* ConfigReader::errorlog [protected]
 

Used to store errors.

Definition at line 1422 of file modules.h.

Referenced by ConfigReader(), and ~ConfigReader().

bool ConfigReader::privatehash [protected]
 

If we're using our own config data hash or not.

Definition at line 1425 of file modules.h.

Referenced by ConfigReader(), and ~ConfigReader().

bool ConfigReader::readerror [protected]
 

True if an error occured reading the config file.

Definition at line 1428 of file modules.h.

Referenced by ConfigReader(), and Verify().

InspIRCd* ConfigReader::ServerInstance [protected]
 

Definition at line 1413 of file modules.h.

Referenced by ConfigReader(), DumpErrors(), Enumerate(), EnumerateValues(), ReadFlag(), ReadInteger(), and ReadValue().


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