summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2013-04-11 00:08:28 -0500
committerAdam <Adam@anope.org>2013-04-11 00:08:28 -0500
commit4f9b7874d6b3a41939ecc2e872ec08d03af7b5f1 (patch)
tree43162205d31b277c9ff12ee28b7e3a60d6382316 /src
parent207c46c871e85b55ae66acc456c6bc412c0c79f9 (diff)
Pass new config and the new config reader to the OnReload event, aswell as call it on module load on modules that hook to it
Diffstat (limited to 'src')
-rw-r--r--src/config.cpp3
-rw-r--r--src/configreader.cpp18
-rw-r--r--src/init.cpp8
-rw-r--r--src/modulemanager.cpp18
4 files changed, 35 insertions, 12 deletions
diff --git a/src/config.cpp b/src/config.cpp
index 2637964fa..bc01a1589 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -142,6 +142,9 @@ ServerConfig::ServerConfig()
if (this->SessionIPv4CIDR > 32 || this->SessionIPv6CIDR > 128)
throw ConfigException("Session CIDR value out of range");
+ ConfigReader reader(this);
+ FOREACH_MOD(I_OnReload, OnReload(this, reader));
+
#ifndef _WIN32
if (!this->User.empty())
{
diff --git a/src/configreader.cpp b/src/configreader.cpp
index 64b4addf4..ca5a64a60 100644
--- a/src/configreader.cpp
+++ b/src/configreader.cpp
@@ -27,11 +27,15 @@
#include "services.h"
#include "config.h"
-ConfigReader::ConfigReader() : error(CONF_NO_ERROR)
+ConfigReader::ConfigReader() : conf(Config), error(CONF_NO_ERROR)
{
}
-ConfigReader::ConfigReader(const Anope::string &filename) : error(CONF_NO_ERROR)
+ConfigReader::ConfigReader(const Anope::string &filename) : conf(Config), error(CONF_NO_ERROR)
+{
+}
+
+ConfigReader::ConfigReader(ServerConfig *c) : conf(c), error(CONF_NO_ERROR)
{
}
@@ -44,7 +48,7 @@ Anope::string ConfigReader::ReadValue(const Anope::string &tag, const Anope::str
/* Don't need to strlcpy() tag and name anymore, ReadConf() takes const char* */
Anope::string result;
- if (!Config->ConfValue(Config->config_data, tag, name, default_value, index, result, allow_linefeeds))
+ if (!conf->ConfValue(conf->config_data, tag, name, default_value, index, result, allow_linefeeds))
this->error = CONF_VALUE_NOT_FOUND;
return result;
@@ -57,7 +61,7 @@ Anope::string ConfigReader::ReadValue(const Anope::string &tag, const Anope::str
bool ConfigReader::ReadFlag(const Anope::string &tag, const Anope::string &name, const Anope::string &default_value, int index)
{
- return Config->ConfValueBool(Config->config_data, tag, name, default_value, index);
+ return conf->ConfValueBool(conf->config_data, tag, name, default_value, index);
}
bool ConfigReader::ReadFlag(const Anope::string &tag, const Anope::string &name, int index)
@@ -69,7 +73,7 @@ int ConfigReader::ReadInteger(const Anope::string &tag, const Anope::string &nam
{
int result;
- if (!Config->ConfValueInteger(Config->config_data, tag, name, default_value, index, result))
+ if (!conf->ConfValueInteger(conf->config_data, tag, name, default_value, index, result))
{
this->error = CONF_VALUE_NOT_FOUND;
return 0;
@@ -98,12 +102,12 @@ long ConfigReader::GetError()
int ConfigReader::Enumerate(const Anope::string &tag) const
{
- return Config->ConfValueEnum(Config->config_data, tag);
+ return conf->ConfValueEnum(conf->config_data, tag);
}
int ConfigReader::EnumerateValues(const Anope::string &tag, int index)
{
- return Config->ConfVarEnum(Config->config_data, tag, index);
+ return conf->ConfVarEnum(conf->config_data, tag, index);
}
bool ConfigReader::Verify()
diff --git a/src/init.cpp b/src/init.cpp
index 96686589a..b0812fedc 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -118,16 +118,14 @@ void Anope::HandleSignal()
{
Anope::SaveDatabases();
- ServerConfig *old_config = Config;
try
{
- Config = new ServerConfig();
- FOREACH_MOD(I_OnReload, OnReload());
- delete old_config;
+ ServerConfig *new_config = new ServerConfig();
+ delete Config;
+ Config = new_config;
}
catch (const ConfigException &ex)
{
- Config = old_config;
Log() << "Error reloading configuration file: " << ex.GetReason();
}
break;
diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp
index a6fa1fffd..f27561fa6 100644
--- a/src/modulemanager.cpp
+++ b/src/modulemanager.cpp
@@ -11,6 +11,7 @@
#include "modules.h"
#include "users.h"
#include "regchannel.h"
+#include "config.h"
#include <sys/types.h>
#include <sys/stat.h>
@@ -225,7 +226,24 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u)
else
Log(LOG_DEBUG_2) << "Module " << modname << " is compiled against current version of Anope " << Anope::VersionShort();
+ /* If the module is hooked to the reload event it wants to initialize its config here */
+ if (std::find(EventHandlers[I_OnReload].begin(), EventHandlers[I_OnReload].end(), m) != EventHandlers[I_OnReload].end())
+ {
+ ConfigReader reader;
+ try
+ {
+ m->OnReload(Config, reader);
+ }
+ catch (const ConfigException &ex)
+ {
+ Log() << "Module " << modname << " couldn't load due to configuration problems: " << ex.GetReason();
+ DeleteModule(m);
+ return MOD_ERR_EXCEPTION;
+ }
+ }
+
Log(LOG_DEBUG) << "Module " << modname << " loaded.";
+
FOREACH_MOD(I_OnModuleLoad, OnModuleLoad(u, m));
return MOD_ERR_OK;