diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile | 4 | ||||
-rw-r--r-- | src/configreader.cpp | 100 |
2 files changed, 102 insertions, 2 deletions
diff --git a/src/Makefile b/src/Makefile index 7973ba4d7..bde534274 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,11 +1,11 @@ OBJS = actions.o base64.o bots.o botserv.o channels.o chanserv.o commands.o compat.o \ config.o datafiles.o encrypt.o events.o hashcomp.o helpserv.o hostserv.o init.o ircd.o language.o log.o mail.o main.o \ memory.o memoserv.o messages.o misc.o modules.o news.o nickserv.o operserv.o \ - process.o send.o servers.o sessions.o slist.o sockutil.o timeout.o users.o module.o modulemanager.o + process.o send.o servers.o sessions.o slist.o sockutil.o timeout.o users.o module.o modulemanager.o configreader.o SRCS = actions.c base64.c bots.cpp botserv.c channels.c chanserv.c commands.c compat.c \ config.c datafiles.c encrypt.c events.c hashcomp.cpp helpserv.c hostserv.c init.c ircd.c language.c log.c mail.c main.c \ memory.c memoserv.c messages.c misc.c modules.c news.c nickserv.c operserv.c \ - process.c send.c servers.c sessions.c s sockutil.c timeout.c users.c module.cpp modulemanager.cpp + process.c send.c servers.c sessions.c s sockutil.c timeout.c users.c module.cpp modulemanager.cpp configreader.cpp INCLUDES = ../include/commands.h ../include/defs.h ../include/language.h \ ../include/pseudo.h ../include/sysconf.h ../include/config.h \ diff --git a/src/configreader.cpp b/src/configreader.cpp new file mode 100644 index 000000000..ba65e173b --- /dev/null +++ b/src/configreader.cpp @@ -0,0 +1,100 @@ +/* +------------------------------------+ + * | Inspire Internet Relay Chat Daemon | + * +------------------------------------+ + * + * InspIRCd: (C) 2002-2008 InspIRCd Development Team + * See: http://www.inspircd.org/wiki/index.php/Credits + * + * This program is free but copyrighted software; see + * the file COPYING for details. + * + * --------------------------------------------------- + */ + +#include "services.h" + +ConfigReader::ConfigReader() : data(&serverConfig.config_data), errorlog(new std::ostringstream(std::stringstream::in | std::stringstream::out)), privatehash(false), error(CONF_NO_ERROR) +{ +} + +ConfigReader::~ConfigReader() +{ + if (this->errorlog) + delete this->errorlog; + if(this->privatehash) + delete this->data; +} + +ConfigReader::ConfigReader(const std::string &filename) : data(new ConfigDataHash), errorlog(new std::ostringstream(std::stringstream::in | std::stringstream::out)), privatehash(true), error(CONF_NO_ERROR) +{ + serverConfig.ClearStack(); +} + +std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool allow_linefeeds) +{ + /* Don't need to strlcpy() tag and name anymore, ReadConf() takes const char* */ + std::string result; + if (!serverConfig.ConfValue(*this->data, tag, name, default_value, index, result, allow_linefeeds)) this->error = CONF_VALUE_NOT_FOUND; + return result; +} + +std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, int index, bool allow_linefeeds) +{ + return ReadValue(tag, name, "", index, allow_linefeeds); +} + +bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, const std::string &default_value, int index) +{ + return serverConfig.ConfValueBool(*this->data, tag, name, default_value, index); +} + +bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, int index) +{ + return ReadFlag(tag, name, "", index); +} + +int ConfigReader::ReadInteger(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool need_positive) +{ + int result; + if (!serverConfig.ConfValueInteger(*this->data, tag, name, default_value, index, result)) { + this->error = CONF_VALUE_NOT_FOUND; + return 0; + } + if (need_positive && result < 0) { + this->error = CONF_INT_NEGATIVE; + return 0; + } + return result; +} + +int ConfigReader::ReadInteger(const std::string &tag, const std::string &name, int index, bool need_positive) +{ + return ReadInteger(tag, name, "", index, need_positive); +} + +long ConfigReader::GetError() +{ + long olderr = this->error; + this->error = 0; + return olderr; +} + +void ConfigReader::DumpErrors(bool bail) +{ + serverConfig.ReportConfigError(this->errorlog->str(), bail); +} + +int ConfigReader::Enumerate(const std::string &tag) +{ + return serverConfig.ConfValueEnum(*this->data, tag); +} + +int ConfigReader::EnumerateValues(const std::string &tag, int index) +{ + return serverConfig.ConfVarEnum(*this->data, tag, index); +} + +bool ConfigReader::Verify() +{ + return this->readerror; +} |