diff options
45 files changed, 253 insertions, 375 deletions
diff --git a/include/config.h b/include/config.h index 36a4836c8..901fe0138 100644 --- a/include/config.h +++ b/include/config.h @@ -707,11 +707,12 @@ class ConfigException : public CoreException virtual ~ConfigException() throw() { } }; -#define CONF_NO_ERROR 0x000000 -#define CONF_NOT_A_NUMBER 0x000010 -#define CONF_INT_NEGATIVE 0x000080 -#define CONF_VALUE_NOT_FOUND 0x000100 -#define CONF_FILE_NOT_FOUND 0x000200 +enum +{ + CONF_NO_ERROR, + CONF_INT_NEGATIVE = 1 << 1, + CONF_VALUE_NOT_FOUND = 1 << 2 +}; /** Allows reading of values from configuration files * This class allows a module to read from either the main configuration file (services.conf) or from @@ -721,6 +722,7 @@ class ConfigException : public CoreException */ class CoreExport ConfigReader { + ServerConfig *conf; protected: /** True if an error occured reading the config file */ @@ -737,6 +739,10 @@ class CoreExport ConfigReader * This constructor initialises the ConfigReader class to read a user-specified config file */ ConfigReader(const Anope::string &); + /** Overloaded constructor + * This constructor initialises the ConfigReader class to use a user sepcific ServerConfig object, + */ + ConfigReader(ServerConfig *); /** Default destructor. * This method destroys the ConfigReader class. */ diff --git a/include/modules.h b/include/modules.h index ae7ceb651..20d27b0ab 100644 --- a/include/modules.h +++ b/include/modules.h @@ -112,6 +112,8 @@ if (true) \ else \ static_cast<void>(0) +class ConfigReader; + /** Possible return types from events. */ enum EventReturn @@ -124,7 +126,6 @@ enum EventReturn enum ModuleReturn { MOD_ERR_OK, - MOD_ERR_MEMORY, MOD_ERR_PARAMS, MOD_ERR_EXISTS, MOD_ERR_NOEXIST, @@ -285,9 +286,12 @@ class CoreExport Module : public Extensible */ virtual void OnUserKicked(Channel *c, User *target, MessageSource &source, const Anope::string &kickmsg) { } - /** Called when Services' configuration has been loaded. + /** Called when Services' configuration is being (re)loaded. + * @param conf The config that is being built now and will replace the global Config object + * @param reader A config reader for conf + * @throws A ConfigException to abort the config (re)loading process. */ - virtual void OnReload() { } + virtual void OnReload(ServerConfig *conf, ConfigReader &reader) { } /** Called before a bot is assigned to a channel. * @param sender The user assigning the bot diff --git a/modules/bs_autoassign.cpp b/modules/bs_autoassign.cpp index 13bde5ff5..134904925 100644 --- a/modules/bs_autoassign.cpp +++ b/modules/bs_autoassign.cpp @@ -19,8 +19,6 @@ class BSAutoAssign : public Module Implementation i[] = { I_OnChanRegistered, I_OnReload }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - - this->OnReload(); } void OnChanRegistered(ChannelInfo *ci) anope_override @@ -38,10 +36,9 @@ class BSAutoAssign : public Module bi->Assign(NULL, ci); } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; - this->bot = config.ReadValue("bs_autoassign", "bot", "", 0); + this->bot = reader.ReadValue("bs_autoassign", "bot", "", 0); } }; diff --git a/modules/commands/cs_access.cpp b/modules/commands/cs_access.cpp index 10a4c9885..90e17eeed 100644 --- a/modules/commands/cs_access.cpp +++ b/modules/commands/cs_access.cpp @@ -790,24 +790,21 @@ class CSAccess : public Module Implementation i[] = { I_OnReload, I_OnCreateChan, I_OnGroupCheckPriv }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - - this->OnReload(); } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { defaultLevels.clear(); - ConfigReader config; - for (int i = 0; i < config.Enumerate("privilege"); ++i) + for (int i = 0; i < reader.Enumerate("privilege"); ++i) { - const Anope::string &pname = config.ReadValue("privilege", "name", "", i); + const Anope::string &pname = reader.ReadValue("privilege", "name", "", i); Privilege *p = PrivilegeManager::FindPrivilege(pname); if (p == NULL) continue; - const Anope::string &value = config.ReadValue("privilege", "level", "", i); + const Anope::string &value = reader.ReadValue("privilege", "level", "", i); if (value.empty()) continue; else if (value.equals_ci("founder")) @@ -815,7 +812,7 @@ class CSAccess : public Module else if (value.equals_ci("disabled")) defaultLevels[p->name] = ACCESS_INVALID; else - defaultLevels[p->name] = config.ReadInteger("privilege", "level", i, false); + defaultLevels[p->name] = reader.ReadInteger("privilege", "level", i, false); } } diff --git a/modules/commands/cs_entrymsg.cpp b/modules/commands/cs_entrymsg.cpp index bb82e9b24..961cf1895 100644 --- a/modules/commands/cs_entrymsg.cpp +++ b/modules/commands/cs_entrymsg.cpp @@ -278,8 +278,6 @@ class CSEntryMessage : public Module Implementation i[] = { I_OnReload, I_OnJoinChannel }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - - this->OnReload(); } void OnJoinChannel(User *u, Channel *c) anope_override @@ -294,10 +292,9 @@ class CSEntryMessage : public Module } } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; - MaxEntries = config.ReadInteger("cs_entrymsg", "maxentries", "5", 0, true); + MaxEntries = reader.ReadInteger("cs_entrymsg", "maxentries", "5", 0, true); } }; diff --git a/modules/commands/cs_fantasy_stats.cpp b/modules/commands/cs_fantasy_stats.cpp index 591da28e9..b1b878c63 100644 --- a/modules/commands/cs_fantasy_stats.cpp +++ b/modules/commands/cs_fantasy_stats.cpp @@ -75,14 +75,12 @@ class CSStats : public Module Implementation i[] = { I_OnReload }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - this->OnReload(); } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; - prefix = config.ReadValue("chanstats", "prefix", "anope_", 0); - Anope::string engine = config.ReadValue("chanstats", "engine", "", 0); + prefix = reader.ReadValue("chanstats", "prefix", "anope_", 0); + Anope::string engine = reader.ReadValue("chanstats", "engine", "", 0); this->sql = ServiceReference<SQL::Provider>("SQL::Provider", engine); } diff --git a/modules/commands/cs_fantasy_top.cpp b/modules/commands/cs_fantasy_top.cpp index 739f21f41..4bad46e51 100644 --- a/modules/commands/cs_fantasy_top.cpp +++ b/modules/commands/cs_fantasy_top.cpp @@ -102,14 +102,12 @@ class CSTop : public Module Implementation i[] = { I_OnReload }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - this->OnReload(); } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; - prefix = config.ReadValue("chanstats", "prefix", "anope_", 0); - Anope::string engine = config.ReadValue("chanstats", "engine", "", 0); + prefix = reader.ReadValue("chanstats", "prefix", "anope_", 0); + Anope::string engine = reader.ReadValue("chanstats", "engine", "", 0); this->sql = ServiceReference<SQL::Provider>("SQL::Provider", engine); } diff --git a/modules/commands/cs_flags.cpp b/modules/commands/cs_flags.cpp index bdff5a6e5..cd1a14e83 100644 --- a/modules/commands/cs_flags.cpp +++ b/modules/commands/cs_flags.cpp @@ -394,24 +394,21 @@ class CSFlags : public Module Implementation i[] = { I_OnReload }; ModuleManager::Attach(i, this, 1); - - this->OnReload(); } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; defaultFlags.clear(); - for (int i = 0; i < config.Enumerate("privilege"); ++i) + for (int i = 0; i < reader.Enumerate("privilege"); ++i) { - const Anope::string &pname = config.ReadValue("privilege", "name", "", i); + const Anope::string &pname = reader.ReadValue("privilege", "name", "", i); Privilege *p = PrivilegeManager::FindPrivilege(pname); if (p == NULL) continue; - const Anope::string &value = config.ReadValue("privilege", "flag", "", i); + const Anope::string &value = reader.ReadValue("privilege", "flag", "", i); if (value.empty()) continue; diff --git a/modules/commands/cs_seen.cpp b/modules/commands/cs_seen.cpp index 7c88c89b8..2d45f9a15 100644 --- a/modules/commands/cs_seen.cpp +++ b/modules/commands/cs_seen.cpp @@ -335,15 +335,12 @@ class CSSeen : public Module I_OnPartChannel, I_OnUserKicked }; ModuleManager::Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation)); - - OnReload(); } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; - purgetime = Anope::DoTime(config.ReadValue("cs_seen", "purgetime", "30d", 0)); - expiretimeout = Anope::DoTime(config.ReadValue("cs_seen", "expiretimeout", "1d", 0)); + purgetime = Anope::DoTime(reader.ReadValue("cs_seen", "purgetime", "30d", 0)); + expiretimeout = Anope::DoTime(reader.ReadValue("cs_seen", "expiretimeout", "1d", 0)); if (purger.GetSecs() != expiretimeout) purger.SetSecs(expiretimeout); diff --git a/modules/commands/cs_set.cpp b/modules/commands/cs_set.cpp index 03aa6c59c..7b6df8a9b 100644 --- a/modules/commands/cs_set.cpp +++ b/modules/commands/cs_set.cpp @@ -1164,14 +1164,11 @@ class CSSet : public Module Implementation i[] = { I_OnReload, I_OnChanRegistered, I_OnCheckKick, I_OnDelChan }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - - this->OnReload(); } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; - CSDefChanstats = config.ReadFlag("chanstats", "CSDefChanstats", "0", 0); + CSDefChanstats = reader.ReadFlag("chanstats", "CSDefChanstats", "0", 0); } void OnChanRegistered(ChannelInfo *ci) anope_override diff --git a/modules/commands/cs_set_misc.cpp b/modules/commands/cs_set_misc.cpp index 93897f332..e74587be1 100644 --- a/modules/commands/cs_set_misc.cpp +++ b/modules/commands/cs_set_misc.cpp @@ -138,26 +138,21 @@ class CSSetMisc : public Module CSSetMisc(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), csmiscdata_type("CSMiscData", CSMiscData::Unserialize), commandcssetmisc(this) { - Implementation i[] = { I_OnReload, I_OnChanInfo }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - - this->OnReload(); } - void OnReload() + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; - descriptions.clear(); - for (int i = 0; i < config.Enumerate("command"); ++i) + for (int i = 0; i < reader.Enumerate("command"); ++i) { - if (config.ReadValue("command", "command", "", i) != "chanserv/set/misc") + if (reader.ReadValue("command", "command", "", i) != "chanserv/set/misc") continue; - Anope::string cname = config.ReadValue("command", "name", "", i); - Anope::string desc = config.ReadValue("command", "misc_description", "", i); + Anope::string cname = reader.ReadValue("command", "name", "", i); + Anope::string desc = reader.ReadValue("command", "misc_description", "", i); if (cname.empty() || desc.empty()) continue; diff --git a/modules/commands/cs_xop.cpp b/modules/commands/cs_xop.cpp index 1cfa033e2..32253770f 100644 --- a/modules/commands/cs_xop.cpp +++ b/modules/commands/cs_xop.cpp @@ -543,36 +543,33 @@ class CSXOP : public Module accessprovider(this), commandcsxop(this) { this->SetPermanent(true); - - this->OnReload(); } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { order.clear(); permissions.clear(); - ConfigReader config; - for (int i = 0; i < config.Enumerate("privilege"); ++i) + for (int i = 0; i < reader.Enumerate("privilege"); ++i) { - const Anope::string &pname = config.ReadValue("privilege", "name", "", i); + const Anope::string &pname = reader.ReadValue("privilege", "name", "", i); Privilege *p = PrivilegeManager::FindPrivilege(pname); if (p == NULL) continue; - const Anope::string &xop = config.ReadValue("privilege", "xop", "", i); + const Anope::string &xop = reader.ReadValue("privilege", "xop", "", i); if (xop.empty()) continue; permissions[xop].push_back(pname); } - for (int i = 0; i < config.Enumerate("command"); ++i) + for (int i = 0; i < reader.Enumerate("command"); ++i) { - const Anope::string &cname = config.ReadValue("command", "name", "", i), - &cserv = config.ReadValue("command", "command", "", i); + const Anope::string &cname = reader.ReadValue("command", "name", "", i), + &cserv = reader.ReadValue("command", "command", "", i); if (cname.empty() || cserv != "chanserv/xop") continue; diff --git a/modules/commands/hs_request.cpp b/modules/commands/hs_request.cpp index 1867dbb77..8b551f0ed 100644 --- a/modules/commands/hs_request.cpp +++ b/modules/commands/hs_request.cpp @@ -357,8 +357,6 @@ class HSRequest : public Module Implementation i[] = { I_OnReload }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - - this->OnReload(); } ~HSRequest() @@ -370,13 +368,10 @@ class HSRequest : public Module } } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; - HSRequestMemoUser = config.ReadFlag("hs_request", "memouser", "no", 0); - HSRequestMemoOper = config.ReadFlag("hs_request", "memooper", "no", 0); - - Log(LOG_DEBUG) << "[hs_request] Set config vars: MemoUser=" << HSRequestMemoUser << " MemoOper=" << HSRequestMemoOper; + HSRequestMemoUser = reader.ReadFlag("hs_request", "memouser", "no", 0); + HSRequestMemoOper = reader.ReadFlag("hs_request", "memooper", "no", 0); } }; diff --git a/modules/commands/ns_set.cpp b/modules/commands/ns_set.cpp index f8b2b7155..793b99fd1 100644 --- a/modules/commands/ns_set.cpp +++ b/modules/commands/ns_set.cpp @@ -1404,14 +1404,11 @@ class NSSet : public Module Implementation i[] = { I_OnReload, I_OnNickRegister, I_OnPreCommand }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - - this->OnReload(); } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; - NSDefChanstats = config.ReadFlag("chanstats", "NSDefChanstats", "0", 0); + NSDefChanstats = reader.ReadFlag("chanstats", "NSDefChanstats", "0", 0); } void OnNickRegister(NickAlias *na) anope_override diff --git a/modules/commands/ns_set_misc.cpp b/modules/commands/ns_set_misc.cpp index 35210abd0..5ee77a938 100644 --- a/modules/commands/ns_set_misc.cpp +++ b/modules/commands/ns_set_misc.cpp @@ -157,26 +157,21 @@ class NSSetMisc : public Module NSSetMisc(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), nsmiscdata_type("NSMiscData", NSMiscData::Unserialize), commandnssetmisc(this), commandnssasetmisc(this) { - Implementation i[] = { I_OnReload, I_OnNickInfo }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - - this->OnReload(); } - void OnReload() + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; - descriptions.clear(); - for (int i = 0; i < config.Enumerate("command"); ++i) + for (int i = 0; i < reader.Enumerate("command"); ++i) { - if (config.ReadValue("command", "command", "", i) != "nickserv/set/misc" && config.ReadValue("command", "command", "", i) != "nickserv/saset/misc") + if (reader.ReadValue("command", "command", "", i) != "nickserv/set/misc" && reader.ReadValue("command", "command", "", i) != "nickserv/saset/misc") continue; - Anope::string cname = config.ReadValue("command", "name", "", i); - Anope::string desc = config.ReadValue("command", "misc_description", "", i); + Anope::string cname = reader.ReadValue("command", "name", "", i); + Anope::string desc = reader.ReadValue("command", "misc_description", "", i); if (cname.empty() || desc.empty()) continue; diff --git a/modules/commands/os_config.cpp b/modules/commands/os_config.cpp index 540bcc3e7..0517f28d7 100644 --- a/modules/commands/os_config.cpp +++ b/modules/commands/os_config.cpp @@ -64,7 +64,7 @@ class CommandOSConfig : public Command bool allow_wild = dt & DT_ALLOW_WILD; dt &= ~(DT_ALLOW_NEWLINE | DT_ALLOW_WILD); - /* Yay for *massive* copypaste from config.cpp */ + /* Yay for *massive* copypaste from reader.cpp */ switch (dt) { case DT_NOSPACES: diff --git a/modules/commands/os_defcon.cpp b/modules/commands/os_defcon.cpp index 53148c6a8..dd45856fb 100644 --- a/modules/commands/os_defcon.cpp +++ b/modules/commands/os_defcon.cpp @@ -334,36 +334,25 @@ class OSDefcon : public Module Implementation i[] = { I_OnReload, I_OnChannelModeSet, I_OnChannelModeUnset, I_OnPreCommand, I_OnUserConnect, I_OnChannelModeAdd, I_OnChannelCreate }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - - - try - { - this->OnReload(); - } - catch (const ConfigException &ex) - { - throw ModuleException(ex.GetReason()); - } } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; DefconConfig dconfig; - dconfig.defaultlevel = config.ReadInteger("defcon", "defaultlevel", 0, 0); - dconfig.defcons[4] = config.ReadValue("defcon", "level4", 0); - dconfig.defcons[3] = config.ReadValue("defcon", "level3", 0); - dconfig.defcons[2] = config.ReadValue("defcon", "level2", 0); - dconfig.defcons[1] = config.ReadValue("defcon", "level1", 0); - dconfig.sessionlimit = config.ReadInteger("defcon", "sessionlimit", 0, 0); - dconfig.akillreason = config.ReadValue("defcon", "akillreason", 0); - dconfig.akillexpire = Anope::DoTime(config.ReadValue("defcon", "akillexpire", 0)); - dconfig.chanmodes = config.ReadValue("defcon", "chanmodes", 0); - dconfig.timeout = Anope::DoTime(config.ReadValue("defcon", "timeout", 0)); - dconfig.globalondefcon = config.ReadFlag("defcon", "globalondefcon", 0); - dconfig.message = config.ReadValue("defcon", "message", 0); - dconfig.offmessage = config.ReadValue("defcon", "offmessage", 0); + dconfig.defaultlevel = reader.ReadInteger("defcon", "defaultlevel", 0, 0); + dconfig.defcons[4] = reader.ReadValue("defcon", "level4", 0); + dconfig.defcons[3] = reader.ReadValue("defcon", "level3", 0); + dconfig.defcons[2] = reader.ReadValue("defcon", "level2", 0); + dconfig.defcons[1] = reader.ReadValue("defcon", "level1", 0); + dconfig.sessionlimit = reader.ReadInteger("defcon", "sessionlimit", 0, 0); + dconfig.akillreason = reader.ReadValue("defcon", "akillreason", 0); + dconfig.akillexpire = Anope::DoTime(reader.ReadValue("defcon", "akillexpire", 0)); + dconfig.chanmodes = reader.ReadValue("defcon", "chanmodes", 0); + dconfig.timeout = Anope::DoTime(reader.ReadValue("defcon", "timeout", 0)); + dconfig.globalondefcon = reader.ReadFlag("defcon", "globalondefcon", 0); + dconfig.message = reader.ReadValue("defcon", "message", 0); + dconfig.offmessage = reader.ReadValue("defcon", "offmessage", 0); if (dconfig.defaultlevel < 1 || dconfig.defaultlevel > 5) throw ConfigException("The value for <defcon:defaultlevel> must be between 1 and 5"); diff --git a/modules/commands/os_dns.cpp b/modules/commands/os_dns.cpp index efcff8fc5..04971e89a 100644 --- a/modules/commands/os_dns.cpp +++ b/modules/commands/os_dns.cpp @@ -670,8 +670,6 @@ class ModuleDNS : public Module Implementation i[] = { I_OnReload, I_OnNewServer, I_OnServerQuit, I_OnUserConnect, I_OnPreUserLogoff, I_OnDnsRequest }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - this->OnReload(); - for (unsigned j = 0; j < dns_servers->size(); ++j) { DNSServer *s = dns_servers->at(j); @@ -688,16 +686,15 @@ class ModuleDNS : public Module delete dns_servers->at(i - 1); } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; - this->ttl = Anope::DoTime(config.ReadValue("os_dns", "ttl", 0)); - this->user_drop_mark = config.ReadInteger("os_dns", "user_drop_mark", 0, false); - this->user_drop_time = Anope::DoTime(config.ReadValue("os_dns", "user_drop_time", 0, false)); - this->user_drop_readd_time = Anope::DoTime(config.ReadValue("os_dns", "user_drop_readd_time", 0, false)); - this->remove_split_servers = config.ReadFlag("os_dns", "remove_split_servers", 0); - this->readd_connected_servers = config.ReadFlag("os_dns", "readd_connected_servers", 0); + this->ttl = Anope::DoTime(reader.ReadValue("os_dns", "ttl", 0)); + this->user_drop_mark = reader.ReadInteger("os_dns", "user_drop_mark", 0, false); + this->user_drop_time = Anope::DoTime(reader.ReadValue("os_dns", "user_drop_time", 0, false)); + this->user_drop_readd_time = Anope::DoTime(reader.ReadValue("os_dns", "user_drop_readd_time", 0, false)); + this->remove_split_servers = reader.ReadFlag("os_dns", "remove_split_servers", 0); + this->readd_connected_servers = reader.ReadFlag("os_dns", "readd_connected_servers", 0); } void OnNewServer(Server *s) anope_override diff --git a/modules/commands/os_logsearch.cpp b/modules/commands/os_logsearch.cpp index 5a063ad53..c033c6bb5 100644 --- a/modules/commands/os_logsearch.cpp +++ b/modules/commands/os_logsearch.cpp @@ -151,17 +151,13 @@ class OSLogSearch : public Module OSLogSearch(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), commandoslogsearch(this) { - Implementation i[] = { I_OnReload }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - - OnReload(); } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; - logfile_name = config.ReadValue("logsearch", "name", "services.log", 0); + logfile_name = reader.ReadValue("logsearch", "name", "services.log", 0); } }; diff --git a/modules/commands/os_reload.cpp b/modules/commands/os_reload.cpp index 86b3a040e..fcf3868fa 100644 --- a/modules/commands/os_reload.cpp +++ b/modules/commands/os_reload.cpp @@ -24,23 +24,18 @@ class CommandOSReload : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override { - 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; source.Reply(_("Services' configuration file has been reloaded.")); } catch (const ConfigException &ex) { - Config = old_config; Log(this->owner) << "Error reloading configuration file: " << ex.GetReason(); - source.Reply(_("Error reloading configuration file: ") + ex.GetReason()); + source.Reply(_("Error reloading configuration file: %s"), ex.GetReason().c_str()); } - - return; } bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override diff --git a/modules/database/db_flatfile.cpp b/modules/database/db_flatfile.cpp index 50a513c65..dcf4a5aa4 100644 --- a/modules/database/db_flatfile.cpp +++ b/modules/database/db_flatfile.cpp @@ -169,8 +169,6 @@ class DBFlatFile : public Module, public Pipe Implementation i[] = { I_OnReload, I_OnLoadDatabase, I_OnSaveDatabase, I_OnSerializeTypeCreate }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - - OnReload(); } void OnNotify() anope_override @@ -193,11 +191,10 @@ class DBFlatFile : public Module, public Pipe Anope::Quitting = true; } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; - database_file = config.ReadValue("db_flatfile", "database", "anope.db", 0); - use_fork = config.ReadFlag("db_flatfile", "fork", "no", 0); + database_file = reader.ReadValue("db_flatfile", "database", "anope.db", 0); + use_fork = reader.ReadFlag("db_flatfile", "fork", "no", 0); } EventReturn OnLoadDatabase() anope_override diff --git a/modules/database/db_plain.cpp b/modules/database/db_plain.cpp index f2b3bffd2..11274c593 100644 --- a/modules/database/db_plain.cpp +++ b/modules/database/db_plain.cpp @@ -589,19 +589,12 @@ class DBPlain : public Module public: DBPlain(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR) { - Implementation i[] = { I_OnReload, I_OnLoadDatabase, I_OnSaveDatabase }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - OnReload(); - LastDay = 0; } - ~DBPlain() - { - } - void BackupDatabase() { /* Do not backup a database that doesn't exist */ @@ -642,11 +635,10 @@ class DBPlain : public Module } } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; - DatabaseFile = Anope::DataDir + "/" + config.ReadValue("db_plain", "database", "anope.db", 0); - BackupFile = Anope::DataDir + "/backups/" + config.ReadValue("db_plain", "database", "anope.db", 0); + DatabaseFile = Anope::DataDir + "/" + reader.ReadValue("db_plain", "database", "anope.db", 0); + BackupFile = Anope::DataDir + "/backups/" + reader.ReadValue("db_plain", "database", "anope.db", 0); } EventReturn OnLoadDatabase() anope_override diff --git a/modules/database/db_sql.cpp b/modules/database/db_sql.cpp index 74da4c44c..4025fec69 100644 --- a/modules/database/db_sql.cpp +++ b/modules/database/db_sql.cpp @@ -95,8 +95,6 @@ class DBSQL : public Module, public Pipe Implementation i[] = { I_OnReload, I_OnShutdown, I_OnRestart, I_OnLoadDatabase, I_OnSerializableConstruct, I_OnSerializableDestruct, I_OnSerializableUpdate, I_OnSerializeTypeCreate }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - this->OnReload(); - if (ModuleManager::FindModule("db_sql_live") != NULL) throw ModuleException("db_sql can not be loaded after db_sql_live"); } @@ -148,13 +146,12 @@ class DBSQL : public Module, public Pipe this->imported = true; } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; - Anope::string engine = config.ReadValue("db_sql", "engine", "", 0); + Anope::string engine = reader.ReadValue("db_sql", "engine", "", 0); this->sql = ServiceReference<Provider>("SQL::Provider", engine); - this->prefix = config.ReadValue("db_sql", "prefix", "anope_db_", 0); - this->import = config.ReadFlag("db_sql", "import", "false", 0); + this->prefix = reader.ReadValue("db_sql", "prefix", "anope_db_", 0); + this->import = reader.ReadFlag("db_sql", "import", "false", 0); } void OnShutdown() anope_override diff --git a/modules/database/db_sql_live.cpp b/modules/database/db_sql_live.cpp index ab08472d8..a26b08cf7 100644 --- a/modules/database/db_sql_live.cpp +++ b/modules/database/db_sql_live.cpp @@ -75,8 +75,6 @@ class DBMySQL : public Module, public Pipe Implementation i[] = { I_OnReload, I_OnShutdown, I_OnLoadDatabase, I_OnSerializableConstruct, I_OnSerializableDestruct, I_OnSerializeCheck, I_OnSerializableUpdate }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - OnReload(); - if (ModuleManager::FindFirstOf(DATABASE) != this) throw ModuleException("If db_sql_live is loaded it must be the first database module loaded."); } @@ -132,12 +130,11 @@ class DBMySQL : public Module, public Pipe init = false; } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; - this->engine = config.ReadValue("db_sql", "engine", "", 0); + this->engine = reader.ReadValue("db_sql", "engine", "", 0); this->SQL = ServiceReference<Provider>("SQL::Provider", this->engine); - this->prefix = config.ReadValue("db_sql", "prefix", "anope_db_", 0); + this->prefix = reader.ReadValue("db_sql", "prefix", "anope_db_", 0); } void OnSerializableConstruct(Serializable *obj) anope_override diff --git a/modules/extra/m_chanstats.cpp b/modules/extra/m_chanstats.cpp index d62befbb0..caa20aacb 100644 --- a/modules/extra/m_chanstats.cpp +++ b/modules/extra/m_chanstats.cpp @@ -347,18 +347,16 @@ class MChanstats : public Module I_OnChanDrop, I_OnReload}; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - this->OnReload(); } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; - prefix = config.ReadValue("chanstats", "prefix", "anope_", 0); - SmileysHappy = config.ReadValue("chanstats", "SmileysHappy", ":) :-) ;) :D :-D", 0); - SmileysSad = config.ReadValue("chanstats", "SmileysSad", ":( :-( ;( ;-(", 0); - SmileysOther = config.ReadValue("chanstats", "SmileysOther", ":/", 0); + prefix = reader.ReadValue("chanstats", "prefix", "anope_", 0); + SmileysHappy = reader.ReadValue("chanstats", "SmileysHappy", ":) :-) ;) :D :-D", 0); + SmileysSad = reader.ReadValue("chanstats", "SmileysSad", ":( :-( ;( ;-(", 0); + SmileysOther = reader.ReadValue("chanstats", "SmileysOther", ":/", 0); - Anope::string engine = config.ReadValue("chanstats", "engine", "", 0); + Anope::string engine = reader.ReadValue("chanstats", "engine", "", 0); this->sql = ServiceReference<SQL::Provider>("SQL::Provider", engine); if (sql) this->CheckTables(); diff --git a/modules/extra/m_dns.cpp b/modules/extra/m_dns.cpp index 3ee7aaa67..e8f3bd758 100644 --- a/modules/extra/m_dns.cpp +++ b/modules/extra/m_dns.cpp @@ -938,21 +938,18 @@ class ModuleDNS : public Module Implementation i[] = { I_OnReload, I_OnModuleUnload }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - - this->OnReload(); } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; - - nameserver = config.ReadValue("dns", "nameserver", "127.0.0.1", 0); - timeout = Anope::DoTime(config.ReadValue("dns", "timeout", "5", 0)); - ip = config.ReadValue("dns", "ip", "0.0.0.0", 0); - port = config.ReadInteger("dns", "port", "53", 0, false); - admin = config.ReadValue("dns", "admin", "admin@example.com", 0); - nameservers = config.ReadValue("dns", "nameservers", "ns1.example.com", 0); - refresh = config.ReadInteger("dns", "refresh", "3600", 0, false); + + nameserver = reader.ReadValue("dns", "nameserver", "127.0.0.1", 0); + timeout = Anope::DoTime(reader.ReadValue("dns", "timeout", "5", 0)); + ip = reader.ReadValue("dns", "ip", "0.0.0.0", 0); + port = reader.ReadInteger("dns", "port", "53", 0, false); + admin = reader.ReadValue("dns", "admin", "admin@example.com", 0); + nameservers = reader.ReadValue("dns", "nameservers", "ns1.example.com", 0); + refresh = reader.ReadInteger("dns", "refresh", "3600", 0, false); if (Anope::IsFile(nameserver)) { diff --git a/modules/extra/m_httpd.cpp b/modules/extra/m_httpd.cpp index 6972bcdf1..5e643d942 100644 --- a/modules/extra/m_httpd.cpp +++ b/modules/extra/m_httpd.cpp @@ -336,8 +336,6 @@ class HTTPD : public Module Implementation i[] = { I_OnReload }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - - this->OnReload(); } ~HTTPD() @@ -354,22 +352,21 @@ class HTTPD : public Module this->providers.clear(); } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; std::set<Anope::string> existing; - for (int i = 0, num = config.Enumerate("httpd"); i < num; ++i) + for (int i = 0, num = reader.Enumerate("httpd"); i < num; ++i) { - Anope::string hname = config.ReadValue("httpd", "name", "httpd/main", i); + Anope::string hname = reader.ReadValue("httpd", "name", "httpd/main", i); existing.insert(hname); - Anope::string ip = config.ReadValue("httpd", "ip", "", i); - int port = config.ReadInteger("httpd", "port", "8080", i, true); - int timeout = config.ReadInteger("httpd", "timeout", "30", i, true); - bool ssl = config.ReadFlag("httpd", "ssl", "no", i); - Anope::string ext_ip = config.ReadValue("httpd", "extforward_ip", "", i); - Anope::string ext_header = config.ReadValue("httpd", "extforward_header", "", i); + Anope::string ip = reader.ReadValue("httpd", "ip", "", i); + int port = reader.ReadInteger("httpd", "port", "8080", i, true); + int timeout = reader.ReadInteger("httpd", "timeout", "30", i, true); + bool ssl = reader.ReadFlag("httpd", "ssl", "no", i); + Anope::string ext_ip = reader.ReadValue("httpd", "extforward_ip", "", i); + Anope::string ext_header = reader.ReadValue("httpd", "extforward_header", "", i); if (ip.empty()) { diff --git a/modules/extra/m_ldap.cpp b/modules/extra/m_ldap.cpp index 80a6b5a9e..3200d3e38 100644 --- a/modules/extra/m_ldap.cpp +++ b/modules/extra/m_ldap.cpp @@ -409,8 +409,6 @@ class ModuleLDAP : public Module, public Pipe Implementation i[] = { I_OnReload, I_OnModuleUnload }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - - OnReload(); } ~ModuleLDAP() @@ -425,9 +423,8 @@ class ModuleLDAP : public Module, public Pipe LDAPServices.clear(); } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; int i, num; for (std::map<Anope::string, LDAPService *>::iterator it = this->LDAPServices.begin(); it != this->LDAPServices.end();) @@ -436,9 +433,9 @@ class ModuleLDAP : public Module, public Pipe LDAPService *s = it->second; ++it; - for (i = 0, num = config.Enumerate("ldap"); i < num; ++i) + for (i = 0, num = reader.Enumerate("ldap"); i < num; ++i) { - if (config.ReadValue("ldap", "name", "main", i) == cname) + if (reader.ReadValue("ldap", "name", "main", i) == cname) { break; } @@ -454,16 +451,16 @@ class ModuleLDAP : public Module, public Pipe } } - for (i = 0, num = config.Enumerate("ldap"); i < num; ++i) + for (i = 0, num = reader.Enumerate("ldap"); i < num; ++i) { - Anope::string connname = config.ReadValue("ldap", "name", "main", i); + Anope::string connname = reader.ReadValue("ldap", "name", "main", i); if (this->LDAPServices.find(connname) == this->LDAPServices.end()) { - Anope::string server = config.ReadValue("ldap", "server", "127.0.0.1", i); - int port = config.ReadInteger("ldap", "port", "389", i, true); - Anope::string admin_binddn = config.ReadValue("ldap", "admin_binddn", "", i); - Anope::string admin_password = config.ReadValue("ldap", "admin_password", "", i); + Anope::string server = reader.ReadValue("ldap", "server", "127.0.0.1", i); + int port = reader.ReadInteger("ldap", "port", "389", i, true); + Anope::string admin_binddn = reader.ReadValue("ldap", "admin_binddn", "", i); + Anope::string admin_password = reader.ReadValue("ldap", "admin_password", "", i); try { diff --git a/modules/extra/m_ldap_authentication.cpp b/modules/extra/m_ldap_authentication.cpp index cc5626cd3..f39bb43e8 100644 --- a/modules/extra/m_ldap_authentication.cpp +++ b/modules/extra/m_ldap_authentication.cpp @@ -224,22 +224,19 @@ class NSIdentifyLDAP : public Module Implementation i[] = { I_OnReload, I_OnPreCommand, I_OnCheckAuthentication, I_OnNickIdentify, I_OnNickRegister }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); ModuleManager::SetPriority(this, PRIORITY_FIRST); - - OnReload(); } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; - - basedn = config.ReadValue("m_ldap_authentication", "basedn", "", 0); - search_filter = config.ReadValue("m_ldap_authentication", "search_filter", "", 0); - object_class = config.ReadValue("m_ldap_authentication", "object_class", "", 0); - username_attribute = config.ReadValue("m_ldap_authentication", "username_attribute", "", 0); - this->password_attribute = config.ReadValue("m_ldap_authentication", "password_attribute", "", 0); - email_attribute = config.ReadValue("m_ldap_authentication", "email_attribute", "", 0); - this->disable_register_reason = config.ReadValue("m_ldap_authentication", "disable_register_reason", "", 0); - this->disable_email_reason = config.ReadValue("m_ldap_authentication", "disable_email_reason", "", 0); + + basedn = reader.ReadValue("m_ldap_authentication", "basedn", "", 0); + search_filter = reader.ReadValue("m_ldap_authentication", "search_filter", "", 0); + object_class = reader.ReadValue("m_ldap_authentication", "object_class", "", 0); + username_attribute = reader.ReadValue("m_ldap_authentication", "username_attribute", "", 0); + this->password_attribute = reader.ReadValue("m_ldap_authentication", "password_attribute", "", 0); + email_attribute = reader.ReadValue("m_ldap_authentication", "email_attribute", "", 0); + this->disable_register_reason = reader.ReadValue("m_ldap_authentication", "disable_register_reason", "", 0); + this->disable_email_reason = reader.ReadValue("m_ldap_authentication", "disable_email_reason", "", 0); if (!email_attribute.empty()) /* Don't complain to users about how they need to update their email, we will do it for them */ diff --git a/modules/extra/m_ldap_oper.cpp b/modules/extra/m_ldap_oper.cpp index f44628c63..afe3fde48 100644 --- a/modules/extra/m_ldap_oper.cpp +++ b/modules/extra/m_ldap_oper.cpp @@ -91,19 +91,15 @@ class LDAPOper : public Module Implementation i[] = { I_OnReload, I_OnNickIdentify, I_OnDelCore }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - - OnReload(); } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; - - this->binddn = config.ReadValue("m_ldap_oper", "binddn", "", 0); - this->password = config.ReadValue("m_ldap_oper", "password", "", 0); - this->basedn = config.ReadValue("m_ldap_oper", "basedn", "", 0); - this->filter = config.ReadValue("m_ldap_oper", "filter", "", 0); - opertype_attribute = config.ReadValue("m_ldap_oper", "opertype_attribute", "", 0); + this->binddn = reader.ReadValue("m_ldap_oper", "binddn", "", 0); + this->password = reader.ReadValue("m_ldap_oper", "password", "", 0); + this->basedn = reader.ReadValue("m_ldap_oper", "basedn", "", 0); + this->filter = reader.ReadValue("m_ldap_oper", "filter", "", 0); + opertype_attribute = reader.ReadValue("m_ldap_oper", "opertype_attribute", "", 0); for (std::set<Oper *>::iterator it = my_opers.begin(), it_end = my_opers.end(); it != it_end; ++it) delete *it; diff --git a/modules/extra/m_mysql.cpp b/modules/extra/m_mysql.cpp index 8eecb4a23..c41ba37a8 100644 --- a/modules/extra/m_mysql.cpp +++ b/modules/extra/m_mysql.cpp @@ -174,8 +174,6 @@ class ModuleSQL : public Module, public Pipe DThread = new DispatcherThread(); DThread->Start(); - - OnReload(); } ~ModuleSQL() @@ -190,9 +188,8 @@ class ModuleSQL : public Module, public Pipe delete DThread; } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; int i, num; for (std::map<Anope::string, MySQLService *>::iterator it = this->MySQLServices.begin(); it != this->MySQLServices.end();) @@ -201,9 +198,9 @@ class ModuleSQL : public Module, public Pipe MySQLService *s = it->second; ++it; - for (i = 0, num = config.Enumerate("mysql"); i < num; ++i) + for (i = 0, num = reader.Enumerate("mysql"); i < num; ++i) { - if (config.ReadValue("mysql", "name", "main", i) == cname) + if (reader.ReadValue("mysql", "name", "main", i) == cname) { break; } @@ -218,17 +215,17 @@ class ModuleSQL : public Module, public Pipe } } - for (i = 0, num = config.Enumerate("mysql"); i < num; ++i) + for (i = 0, num = reader.Enumerate("mysql"); i < num; ++i) { - Anope::string connname = config.ReadValue("mysql", "name", "mysql/main", i); + Anope::string connname = reader.ReadValue("mysql", "name", "mysql/main", i); if (this->MySQLServices.find(connname) == this->MySQLServices.end()) { - Anope::string database = config.ReadValue("mysql", "database", "anope", i); - Anope::string server = config.ReadValue("mysql", "server", "127.0.0.1", i); - Anope::string user = config.ReadValue("mysql", "username", "anope", i); - Anope::string password = config.ReadValue("mysql", "password", "", i); - int port = config.ReadInteger("mysql", "port", "3306", i, true); + Anope::string database = reader.ReadValue("mysql", "database", "anope", i); + Anope::string server = reader.ReadValue("mysql", "server", "127.0.0.1", i); + Anope::string user = reader.ReadValue("mysql", "username", "anope", i); + Anope::string password = reader.ReadValue("mysql", "password", "", i); + int port = reader.ReadInteger("mysql", "port", "3306", i, true); try { diff --git a/modules/extra/m_proxyscan.cpp b/modules/extra/m_proxyscan.cpp index 78f42a910..9dd3f8884 100644 --- a/modules/extra/m_proxyscan.cpp +++ b/modules/extra/m_proxyscan.cpp @@ -229,15 +229,6 @@ class ModuleProxyScan : public Module ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); this->listener = NULL; - - try - { - OnReload(); - } - catch (const ConfigException &ex) - { - throw ModuleException(ex.GetReason()); - } } ~ModuleProxyScan() @@ -262,23 +253,21 @@ class ModuleProxyScan : public Module delete this->listener; } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; - - Anope::string s_target_ip = config.ReadValue("m_proxyscan", "target_ip", "", 0); + Anope::string s_target_ip = reader.ReadValue("m_proxyscan", "target_ip", "", 0); if (s_target_ip.empty()) throw ConfigException("m_proxyscan:target_ip may not be empty"); - int s_target_port = config.ReadInteger("m_proxyscan", "target_port", "-1", 0, true); + int s_target_port = reader.ReadInteger("m_proxyscan", "target_port", "-1", 0, true); if (s_target_port <= 0) throw ConfigException("m_proxyscan:target_port may not be empty and must be a positive number"); - Anope::string s_listen_ip = config.ReadValue("m_proxyscan", "listen_ip", "", 0); + Anope::string s_listen_ip = reader.ReadValue("m_proxyscan", "listen_ip", "", 0); if (s_listen_ip.empty()) throw ConfigException("m_proxyscan:listen_ip may not be empty"); - int s_listen_port = config.ReadInteger("m_proxyscan", "listen_port", "-1", 0, true); + int s_listen_port = reader.ReadInteger("m_proxyscan", "listen_port", "-1", 0, true); if (s_listen_port <= 0) throw ConfigException("m_proxyscan:listen_port may not be empty and must be a positive number"); @@ -286,10 +275,10 @@ class ModuleProxyScan : public Module target_port = s_target_port; this->listen_ip = s_listen_ip; this->listen_port = s_listen_port; - this->con_notice = config.ReadValue("m_proxyscan", "connect_notice", "", 0); - this->con_source = config.ReadValue("m_proxyscan", "connect_source", "", 0); - add_to_akill = config.ReadFlag("m_proxyscan", "add_to_akill", "true", 0); - this->connectionTimeout.SetSecs(config.ReadInteger("m_proxyscan", "timeout", "5", 0, true)); + this->con_notice = reader.ReadValue("m_proxyscan", "connect_notice", "", 0); + this->con_source = reader.ReadValue("m_proxyscan", "connect_source", "", 0); + add_to_akill = reader.ReadFlag("m_proxyscan", "add_to_akill", "true", 0); + this->connectionTimeout.SetSecs(reader.ReadInteger("m_proxyscan", "timeout", "5", 0, true)); ProxyCheckString = Config->NetworkName + " proxy check"; delete this->listener; @@ -304,12 +293,12 @@ class ModuleProxyScan : public Module } this->proxyscans.clear(); - for (int i = 0; i < config.Enumerate("proxyscan"); ++i) + for (int i = 0; i < reader.Enumerate("proxyscan"); ++i) { ProxyCheck p; Anope::string token; - commasepstream sep(config.ReadValue("proxyscan", "type", "", i)); + commasepstream sep(reader.ReadValue("proxyscan", "type", "", i)); while (sep.GetToken(token)) { if (!token.equals_ci("HTTP") && !token.equals_ci("SOCKS5")) @@ -319,7 +308,7 @@ class ModuleProxyScan : public Module if (p.types.empty()) continue; - commasepstream sep2(config.ReadValue("proxyscan", "port", "", i)); + commasepstream sep2(reader.ReadValue("proxyscan", "port", "", i)); while (sep2.GetToken(token)) { try @@ -332,8 +321,8 @@ class ModuleProxyScan : public Module if (p.ports.empty()) continue; - p.duration = Anope::DoTime(config.ReadValue("proxyscan", "time", "4h", i)); - p.reason = config.ReadValue("proxyscan", "reason", "", i); + p.duration = Anope::DoTime(reader.ReadValue("proxyscan", "time", "4h", i)); + p.reason = reader.ReadValue("proxyscan", "reason", "", i); if (p.reason.empty()) continue; diff --git a/modules/extra/m_sql_authentication.cpp b/modules/extra/m_sql_authentication.cpp index 7fcdf4e13..027b0bbcc 100644 --- a/modules/extra/m_sql_authentication.cpp +++ b/modules/extra/m_sql_authentication.cpp @@ -85,17 +85,13 @@ class ModuleSQLAuthentication : public Module Implementation i[] = { I_OnReload, I_OnPreCommand, I_OnCheckAuthentication }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - - this->OnReload(); } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; - - this->engine = config.ReadValue("m_sql_authentication", "engine", "", 0); - this->query = config.ReadValue("m_sql_authentication", "query", "", 0); - this->disable_reason = config.ReadValue("m_sql_authentication", "disable_reason", "", 0); + this->engine = reader.ReadValue("m_sql_authentication", "engine", "", 0); + this->query = reader.ReadValue("m_sql_authentication", "query", "", 0); + this->disable_reason = reader.ReadValue("m_sql_authentication", "disable_reason", "", 0); this->SQL = ServiceReference<SQL::Provider>("SQL::Provider", this->engine); } diff --git a/modules/extra/m_sql_oper.cpp b/modules/extra/m_sql_oper.cpp index bbcd108c4..4f982e1d8 100644 --- a/modules/extra/m_sql_oper.cpp +++ b/modules/extra/m_sql_oper.cpp @@ -99,16 +99,12 @@ class ModuleSQLOper : public Module Implementation i[] = { I_OnReload, I_OnNickIdentify }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - - this->OnReload(); } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; - - this->engine = config.ReadValue("m_sql_oper", "engine", "", 0); - this->query = config.ReadValue("m_sql_oper", "query", "", 0); + this->engine = reader.ReadValue("m_sql_oper", "engine", "", 0); + this->query = reader.ReadValue("m_sql_oper", "query", "", 0); this->SQL = ServiceReference<SQL::Provider>("SQL::Provider", this->engine); } diff --git a/modules/extra/m_sqlite.cpp b/modules/extra/m_sqlite.cpp index 623e1e8b1..9626741a0 100644 --- a/modules/extra/m_sqlite.cpp +++ b/modules/extra/m_sqlite.cpp @@ -68,8 +68,6 @@ class ModuleSQLite : public Module { Implementation i[] = { I_OnReload }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - - OnReload(); } ~ModuleSQLite() @@ -79,9 +77,8 @@ class ModuleSQLite : public Module SQLiteServices.clear(); } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; int i, num; for (std::map<Anope::string, SQLiteService *>::iterator it = this->SQLiteServices.begin(); it != this->SQLiteServices.end();) @@ -90,8 +87,8 @@ class ModuleSQLite : public Module SQLiteService *s = it->second; ++it; - for (i = 0, num = config.Enumerate("sqlite"); i < num; ++i) - if (config.ReadValue("sqlite", "name", "sqlite/main", i) == cname) + for (i = 0, num = reader.Enumerate("sqlite"); i < num; ++i) + if (reader.ReadValue("sqlite", "name", "sqlite/main", i) == cname) break; if (i == num) @@ -103,13 +100,13 @@ class ModuleSQLite : public Module } } - for (i = 0, num = config.Enumerate("sqlite"); i < num; ++i) + for (i = 0, num = reader.Enumerate("sqlite"); i < num; ++i) { - Anope::string connname = config.ReadValue("sqlite", "name", "sqlite/main", i); + Anope::string connname = reader.ReadValue("sqlite", "name", "sqlite/main", i); if (this->SQLiteServices.find(connname) == this->SQLiteServices.end()) { - Anope::string database = Anope::DataDir + "/" + config.ReadValue("sqlite", "database", "anope", i); + Anope::string database = Anope::DataDir + "/" + reader.ReadValue("sqlite", "database", "anope", i); try { diff --git a/modules/extra/m_ssl.cpp b/modules/extra/m_ssl.cpp index 5ecf30cfc..c64e04af5 100644 --- a/modules/extra/m_ssl.cpp +++ b/modules/extra/m_ssl.cpp @@ -107,8 +107,6 @@ class SSLModule : public Module if (!client_ctx || !server_ctx) throw ModuleException("Error initializing SSL CTX"); - this->OnReload(); - if (Anope::IsFile(this->certfile.c_str())) { if (!SSL_CTX_use_certificate_file(client_ctx, this->certfile.c_str(), SSL_FILETYPE_PEM) || !SSL_CTX_use_certificate_file(server_ctx, this->certfile.c_str(), SSL_FILETYPE_PEM)) @@ -175,19 +173,17 @@ class SSLModule : public Module SSL_CTX_free(server_ctx); } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; - - this->certfile = config.ReadValue("ssl", "cert", "data/anope.crt", 0); - this->keyfile = config.ReadValue("ssl", "key", "data/anope.key", 0); + this->certfile = reader.ReadValue("ssl", "cert", "data/anope.crt", 0); + this->keyfile = reader.ReadValue("ssl", "key", "data/anope.key", 0); } void OnPreServerConnect() anope_override { - ConfigReader config; + ConfigReader reader; - if (config.ReadFlag("uplink", "ssl", "no", Anope::CurrentUplink)) + if (reader.ReadFlag("uplink", "ssl", "no", Anope::CurrentUplink)) { this->service.Init(UplinkSock); } diff --git a/modules/extra/m_xmlrpc.cpp b/modules/extra/m_xmlrpc.cpp index 060001940..cac848c69 100644 --- a/modules/extra/m_xmlrpc.cpp +++ b/modules/extra/m_xmlrpc.cpp @@ -161,13 +161,11 @@ class ModuleXMLRPC : public Module public: MyXMLRPCServiceInterface xmlrpcinterface; - ModuleXMLRPC(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), xmlrpcinterface(this, "xmlrpc") + ModuleXMLRPC(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), + httpref("HTTPProvider", "httpd/main"), xmlrpcinterface(this, "xmlrpc") { - OnReload(); - if (!httpref) throw ModuleException("Unable to find http reference, is m_httpd loaded?"); - httpref->RegisterPage(&xmlrpcinterface); Implementation i[] = { I_OnReload }; @@ -179,12 +177,6 @@ class ModuleXMLRPC : public Module if (httpref) httpref->UnregisterPage(&xmlrpcinterface); } - - void OnReload() anope_override - { - ConfigReader config; - httpref = ServiceReference<HTTPProvider>("HTTPProvider", "httpd/main"); - } }; MODULE_INIT(ModuleXMLRPC) diff --git a/modules/m_dnsbl.cpp b/modules/m_dnsbl.cpp index cf5a2b861..27aaff794 100644 --- a/modules/m_dnsbl.cpp +++ b/modules/m_dnsbl.cpp @@ -93,33 +93,29 @@ class ModuleDNSBL : public Module Implementation i[] = { I_OnReload, I_OnUserConnect }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - - OnReload(); } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; - - this->check_on_connect = config.ReadFlag("m_dnsbl", "check_on_connect", "no", 0); - this->check_on_netburst = config.ReadFlag("m_dnsbl", "check_on_netburst", "no", 0); - this->add_to_akill = config.ReadFlag("m_dnsbl", "add_to_akill", "yes", 0); + this->check_on_connect = reader.ReadFlag("m_dnsbl", "check_on_connect", "no", 0); + this->check_on_netburst = reader.ReadFlag("m_dnsbl", "check_on_netburst", "no", 0); + this->add_to_akill = reader.ReadFlag("m_dnsbl", "add_to_akill", "yes", 0); this->blacklists.clear(); - for (int i = 0, num = config.Enumerate("blacklist"); i < num; ++i) + for (int i = 0, num = reader.Enumerate("blacklist"); i < num; ++i) { - Anope::string bname = config.ReadValue("blacklist", "name", "", i); + Anope::string bname = reader.ReadValue("blacklist", "name", "", i); if (bname.empty()) continue; - Anope::string sbantime = config.ReadValue("blacklist", "time", "4h", i); + Anope::string sbantime = reader.ReadValue("blacklist", "time", "4h", i); time_t bantime = Anope::DoTime(sbantime); if (bantime < 0) bantime = 9000; - Anope::string reason = config.ReadValue("blacklist", "reason", "", i); + Anope::string reason = reader.ReadValue("blacklist", "reason", "", i); std::map<int, Anope::string> replies; for (int j = 0; j < 256; ++j) { - Anope::string k = config.ReadValue("blacklist", stringify(j), "", i); + Anope::string k = reader.ReadValue("blacklist", stringify(j), "", i); if (!k.empty()) replies[j] = k; } diff --git a/modules/m_helpchan.cpp b/modules/m_helpchan.cpp index e0163b925..d39b5afd9 100644 --- a/modules/m_helpchan.cpp +++ b/modules/m_helpchan.cpp @@ -14,11 +14,8 @@ class HelpChannel : public Module public: HelpChannel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) { - Implementation i[] = { I_OnChannelModeSet, I_OnReload }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - - OnReload(); } EventReturn OnChannelModeSet(Channel *c, MessageSource &setter, const Anope::string &mname, const Anope::string ¶m) anope_override @@ -34,11 +31,9 @@ class HelpChannel : public Module return EVENT_CONTINUE; } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; - - this->HelpChan = config.ReadValue("m_helpchan", "helpchannel", "", 0); + this->HelpChan = reader.ReadValue("m_helpchan", "helpchannel", "", 0); } }; diff --git a/modules/m_rewrite.cpp b/modules/m_rewrite.cpp index 1e281de94..fb7fe46ed 100644 --- a/modules/m_rewrite.cpp +++ b/modules/m_rewrite.cpp @@ -155,30 +155,26 @@ class ModuleRewrite : public Module public: ModuleRewrite(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), cmdrewrite(this) { - Implementation i[] = { I_OnReload }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - - this->OnReload(); } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; Rewrite::rewrites.clear(); - for (int i = 0; i < config.Enumerate("command"); ++i) + for (int i = 0; i < reader.Enumerate("command"); ++i) { - if (!config.ReadFlag("command", "rewrite", "no", i)) + if (!reader.ReadFlag("command", "rewrite", "no", i)) continue; Rewrite rw; - rw.client = config.ReadValue("command", "service", "", i); - rw.source_message = config.ReadValue("command", "rewrite_source", "", i), - rw.target_message = config.ReadValue("command", "rewrite_target", "", i); - rw.desc = config.ReadValue("command", "rewrite_description", "", i); + rw.client = reader.ReadValue("command", "service", "", i); + rw.source_message = reader.ReadValue("command", "rewrite_source", "", i), + rw.target_message = reader.ReadValue("command", "rewrite_target", "", i); + rw.desc = reader.ReadValue("command", "rewrite_description", "", i); if (rw.client.empty() || rw.source_message.empty() || rw.target_message.empty()) continue; diff --git a/modules/ns_maxemail.cpp b/modules/ns_maxemail.cpp index bf90374d0..530ca5fe4 100644 --- a/modules/ns_maxemail.cpp +++ b/modules/ns_maxemail.cpp @@ -56,15 +56,11 @@ class NSMaxEmail : public Module Implementation i[] = { I_OnReload, I_OnPreCommand }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - - OnReload(); } - void OnReload() anope_override + void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override { - ConfigReader config; - this->NSEmailMax = config.ReadInteger("ns_maxemail", "maxemails", "0", 0, false); - Log(LOG_DEBUG) << "[ns_maxemail] NSEmailMax set to " << NSEmailMax; + this->NSEmailMax = reader.ReadInteger("ns_maxemail", "maxemails", "0", 0, false); } EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> ¶ms) anope_override 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; |