From f9911dde529adf3dc03f4f14bbd70756ac2f665c Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sun, 2 Mar 2025 14:51:02 +0000 Subject: Return references instead of pointers from the config system. We used to return NULL from these methods but now we return an empty block so this can never actually be null now. --- modules/database/db_atheme.cpp | 18 +++++++++--------- modules/database/db_flatfile.cpp | 18 +++++++++--------- modules/database/db_old.cpp | 2 +- modules/database/db_redis.cpp | 6 +++--- modules/database/db_sql.cpp | 10 +++++----- modules/database/db_sql_live.cpp | 10 +++++----- 6 files changed, 32 insertions(+), 32 deletions(-) (limited to 'modules/database') diff --git a/modules/database/db_atheme.cpp b/modules/database/db_atheme.cpp index 2e25b694e..4599a7469 100644 --- a/modules/database/db_atheme.cpp +++ b/modules/database/db_atheme.cpp @@ -500,7 +500,7 @@ private: else { // Generate a new password as we can't use the old one. - auto maxpasslen = Config->GetModule("nickserv")->Get("maxpasslen", "50"); + auto maxpasslen = Config->GetModule("nickserv").Get("maxpasslen", "50"); Anope::Encrypt(Anope::Random(maxpasslen), nc->pass); Log(this) << "Unable to convert the password for " << nc->display << " as Anope does not support the format!"; } @@ -1076,8 +1076,8 @@ private: if (!data->kill) return true; // Don't apply this. - auto kill = Config->GetModule("nickserv")->Get("kill", "60s"); - auto killquick = Config->GetModule("nickserv")->Get("killquick", "20s"); + auto kill = Config->GetModule("nickserv").Get("kill", "60s"); + auto killquick = Config->GetModule("nickserv").Get("killquick", "20s"); auto secs = Anope::Convert(value, kill); if (secs >= kill) nc->Extend("KILLPROTECT"); @@ -1295,7 +1295,7 @@ private: // If an Atheme account was awaiting confirmation but Anope is not // configured to use confirmation then autoconfirm it. - const auto &nsregister = Config->GetModule("ns_register")->Get("registration"); + const auto &nsregister = Config->GetModule("ns_register").Get("registration"); if (nsregister.equals_ci("none")) nc->Shrink("UNCONFIRMED"); @@ -1453,14 +1453,14 @@ public: { } - void OnReload(Configuration::Conf *conf) override + void OnReload(Configuration::Conf &conf) override { flags.clear(); for (int i = 0; i < Config->CountBlock("privilege"); ++i) { - Configuration::Block *priv = Config->GetBlock("privilege", i); - const Anope::string &name = priv->Get("name"); - const Anope::string &value = priv->Get("flag"); + Configuration::Block &priv = Config->GetBlock("privilege", i); + const Anope::string &name = priv.Get("name"); + const Anope::string &value = priv.Get("flag"); if (!name.empty() && !value.empty()) flags[name] = value[0]; } @@ -1468,7 +1468,7 @@ public: EventReturn OnLoadDatabase() override { - const auto dbname = Anope::ExpandData(Config->GetModule(this)->Get("database", "atheme.db")); + const auto dbname = Anope::ExpandData(Config->GetModule(this).Get("database", "atheme.db")); std::ifstream fd(dbname.str()); if (!fd.is_open()) { diff --git a/modules/database/db_flatfile.cpp b/modules/database/db_flatfile.cpp index 9f2559c9e..4a1e8830d 100644 --- a/modules/database/db_flatfile.cpp +++ b/modules/database/db_flatfile.cpp @@ -109,7 +109,7 @@ class DBFlatFile final last_day = tm->tm_mday; std::set dbs; - dbs.insert(Config->GetModule(this)->Get("database", "anope.db")); + dbs.insert(Config->GetModule(this).Get("database", "anope.db")); for (const auto &type_order : Serialize::Type::GetTypeOrder()) { @@ -135,7 +135,7 @@ class DBFlatFile final Anope::string err = Anope::LastError(); Log(this) << "Unable to back up database " << db << " (" << err << ")!"; - if (!Config->GetModule(this)->Get("nobackupokay")) + if (!Config->GetModule(this).Get("nobackupokay")) { Anope::Quitting = true; Anope::QuitReason = "Unable to back up database " + db + " (" + err + ")"; @@ -146,7 +146,7 @@ class DBFlatFile final backups[db].push_back(newname); - unsigned keepbackups = Config->GetModule(this)->Get("keepbackups"); + unsigned keepbackups = Config->GetModule(this).Get("keepbackups"); if (keepbackups > 0 && backups[db].size() > keepbackups) { unlink(backups[db].front().c_str()); @@ -200,7 +200,7 @@ public: Log(this) << "Error saving databases: " << buf; - if (!Config->GetModule(this)->Get("nobackupokay")) + if (!Config->GetModule(this).Get("nobackupokay")) Anope::Quitting = true; } @@ -208,7 +208,7 @@ public: { std::set tried_dbs; - const auto db_name = Anope::ExpandData(Config->GetModule(this)->Get("database", "anope.db")); + const auto db_name = Anope::ExpandData(Config->GetModule(this).Get("database", "anope.db")); std::fstream fd(db_name.c_str(), std::ios_base::in | std::ios_base::binary); if (!fd.is_open()) @@ -263,7 +263,7 @@ public: int i = -1; #ifndef _WIN32 - if (!Anope::Quitting && Config->GetModule(this)->Get("fork")) + if (!Anope::Quitting && Config->GetModule(this).Get("fork")) { i = fork(); if (i > 0) @@ -290,7 +290,7 @@ public: if (s_type->GetOwner()) db_name = Anope::ExpandData("module_" + s_type->GetOwner()->name + ".db"); else - db_name = Anope::ExpandData(Config->GetModule(this)->Get("database", "anope.db")); + db_name = Anope::ExpandData(Config->GetModule(this).Get("database", "anope.db")); std::fstream *fs = databases[s_type->GetOwner()] = new std::fstream((db_name + ".tmp").c_str(), std::ios_base::out | std::ios_base::trunc | std::ios_base::binary); @@ -319,7 +319,7 @@ public: for (auto &[mod, f] : databases) { - const auto db_name = Anope::ExpandData((mod ? (mod->name + ".db") : Config->GetModule(this)->Get("database", "anope.db"))); + const auto db_name = Anope::ExpandData((mod ? (mod->name + ".db") : Config->GetModule(this).Get("database", "anope.db"))); if (!f->is_open() || !f->good()) { @@ -363,7 +363,7 @@ public: if (stype->GetOwner()) db_name = Anope::ExpandData("module_" + stype->GetOwner()->name + ".db"); else - db_name = Anope::ExpandData(Config->GetModule(this)->Get("database", "anope.db")); + db_name = Anope::ExpandData(Config->GetModule(this).Get("database", "anope.db")); std::fstream fd(db_name.c_str(), std::ios_base::in | std::ios_base::binary); if (!fd.is_open()) diff --git a/modules/database/db_old.cpp b/modules/database/db_old.cpp index 814740a23..611da4406 100644 --- a/modules/database/db_old.cpp +++ b/modules/database/db_old.cpp @@ -1296,7 +1296,7 @@ public: { - hashm = Config->GetModule(this)->Get("hash"); + hashm = Config->GetModule(this).Get("hash"); if (hashm != "md5" && hashm != "oldmd5" && hashm != "sha1" && hashm != "plain" && hashm != "sha256") throw ModuleException("Invalid hash method"); diff --git a/modules/database/db_redis.cpp b/modules/database/db_redis.cpp index a4826349b..832e22590 100644 --- a/modules/database/db_redis.cpp +++ b/modules/database/db_redis.cpp @@ -171,10 +171,10 @@ public: this->updated_items.clear(); } - void OnReload(Configuration::Conf *conf) override + void OnReload(Configuration::Conf &conf) override { - Configuration::Block *block = conf->GetModule(this); - this->redis = ServiceReference("Redis::Provider", block->Get("engine", "redis/main")); + Configuration::Block &block = conf.GetModule(this); + this->redis = ServiceReference("Redis::Provider", block.Get("engine", "redis/main")); } EventReturn OnLoadDatabase() override diff --git a/modules/database/db_sql.cpp b/modules/database/db_sql.cpp index bfcd59a3d..4b120f3b0 100644 --- a/modules/database/db_sql.cpp +++ b/modules/database/db_sql.cpp @@ -158,12 +158,12 @@ public: this->imported = true; } - void OnReload(Configuration::Conf *conf) override + void OnReload(Configuration::Conf &conf) override { - Configuration::Block *block = conf->GetModule(this); - this->sql = ServiceReference("SQL::Provider", block->Get("engine")); - this->prefix = block->Get("prefix", "anope_db_"); - this->import = block->Get("import"); + Configuration::Block &block = conf.GetModule(this); + this->sql = ServiceReference("SQL::Provider", block.Get("engine")); + this->prefix = block.Get("prefix", "anope_db_"); + this->import = block.Get("import"); } void OnPostInit() override diff --git a/modules/database/db_sql_live.cpp b/modules/database/db_sql_live.cpp index e0f3adb08..afd884913 100644 --- a/modules/database/db_sql_live.cpp +++ b/modules/database/db_sql_live.cpp @@ -37,7 +37,7 @@ private: } else { - if (Anope::CurTime - Config->GetBlock("options")->Get("updatetimeout", "2m") > lastwarn) + if (Anope::CurTime - Config->GetBlock("options").Get("updatetimeout", "2m") > lastwarn) { Log() << "Unable to locate SQL reference, going to readonly..."; Anope::ReadOnly = this->ro = true; @@ -138,11 +138,11 @@ public: init = false; } - void OnReload(Configuration::Conf *conf) override + void OnReload(Configuration::Conf &conf) override { - Configuration::Block *block = conf->GetModule(this); - this->SQL = ServiceReference("SQL::Provider", block->Get("engine")); - this->prefix = block->Get("prefix", "anope_db_"); + Configuration::Block &block = conf.GetModule(this); + this->SQL = ServiceReference("SQL::Provider", block.Get("engine")); + this->prefix = block.Get("prefix", "anope_db_"); } void OnSerializableConstruct(Serializable *obj) override -- cgit