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. --- src/command.cpp | 2 +- src/config.cpp | 227 +++++++++++++++++++++++++------------------------- src/init.cpp | 36 ++++---- src/language.cpp | 2 +- src/mail.cpp | 26 +++--- src/main.cpp | 4 +- src/messages.cpp | 6 +- src/misc.cpp | 2 +- src/modulemanager.cpp | 2 +- src/protocol.cpp | 18 ++-- src/uplink.cpp | 6 +- src/users.cpp | 6 +- src/xline.cpp | 4 +- 13 files changed, 170 insertions(+), 171 deletions(-) (limited to 'src') diff --git a/src/command.cpp b/src/command.cpp index d5bbca2dd..080e6471d 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -222,7 +222,7 @@ namespace void HandleUnknownCommand(CommandSource& source, const Anope::string &message) { // Try to find a similar command. - size_t distance = Config->GetBlock("options")->Get("didyoumeandifference", "4"); + size_t distance = Config->GetBlock("options").Get("didyoumeandifference", "4"); Anope::string similar; auto umessage = message.upper(); for (const auto &[command, info] : source.service->commands) diff --git a/src/config.cpp b/src/config.cpp index 47ce6feaa..33d7a8de8 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -43,14 +43,14 @@ int Block::CountBlock(const Anope::string &bname) const return blocks.count(bname); } -const Block *Block::GetBlock(const Anope::string &bname, int num) const +const Block &Block::GetBlock(const Anope::string &bname, int num) const { std::pair it = blocks.equal_range(bname); for (int i = 0; it.first != it.second; ++it.first, ++i) if (i == num) - return &it.first->second; - return &EmptyBlock; + return it.first->second; + return EmptyBlock; } Block *Block::GetMutableBlock(const Anope::string &bname, int num) @@ -127,16 +127,16 @@ Conf::Conf() : Block("") for (int i = 0; i < this->CountBlock("include"); ++i) { - const Block *include = this->GetBlock("include", i); + const Block &include = this->GetBlock("include", i); - const Anope::string &type = include->Get("type"), - &file = include->Get("name"); + const Anope::string &type = include.Get("type"), + &file = include.Get("name"); File f(file, type == "executable"); this->LoadConf(f); } - FOREACH_MOD(OnReload, (this)); + FOREACH_MOD(OnReload, (*this)); /* Check for modified values that aren't allowed to be modified */ if (Config) @@ -159,58 +159,58 @@ Conf::Conf() : Block("") for (const auto &tag : noreload) { - if (this->GetBlock(tag.block)->Get(tag.name) != Config->GetBlock(tag.block)->Get(tag.name)) + if (this->GetBlock(tag.block).Get(tag.name) != Config->GetBlock(tag.block).Get(tag.name)) throw ConfigException("<" + tag.block + ":" + tag.name + "> can not be modified once set"); } } - const Block *serverinfo = this->GetBlock("serverinfo"), *options = this->GetBlock("options"), - *mail = this->GetBlock("mail"), *networkinfo = this->GetBlock("networkinfo"); + const Block &serverinfo = this->GetBlock("serverinfo"), &options = this->GetBlock("options"), + &mail = this->GetBlock("mail"), &networkinfo = this->GetBlock("networkinfo"); - const Anope::string &servername = serverinfo->Get("name"); + const Anope::string &servername = serverinfo.Get("name"); ValidateNotEmptyOrSpaces("serverinfo", "name", servername); if (servername.find(' ') != Anope::string::npos || servername.find('.') == Anope::string::npos) throw ConfigException("serverinfo:name is not a valid server name"); - ValidateNotEmpty("serverinfo", "description", serverinfo->Get("description")); - ValidateNotEmpty("serverinfo", "pid", serverinfo->Get("pid")); - ValidateNotEmpty("serverinfo", "motd", serverinfo->Get("motd")); + ValidateNotEmpty("serverinfo", "description", serverinfo.Get("description")); + ValidateNotEmpty("serverinfo", "pid", serverinfo.Get("pid")); + ValidateNotEmpty("serverinfo", "motd", serverinfo.Get("motd")); - ValidateNotZero("options", "readtimeout", options->Get("readtimeout")); + ValidateNotZero("options", "readtimeout", options.Get("readtimeout")); - ValidateNotZero("networkinfo", "nicklen", networkinfo->Get("nicklen", "1")); - ValidateNotZero("networkinfo", "userlen", networkinfo->Get("userlen", "1")); - ValidateNotZero("networkinfo", "hostlen", networkinfo->Get("hostlen", "1")); - ValidateNotZero("networkinfo", "chanlen", networkinfo->Get("chanlen", "1")); + ValidateNotZero("networkinfo", "nicklen", networkinfo.Get("nicklen", "1")); + ValidateNotZero("networkinfo", "userlen", networkinfo.Get("userlen", "1")); + ValidateNotZero("networkinfo", "hostlen", networkinfo.Get("hostlen", "1")); + ValidateNotZero("networkinfo", "chanlen", networkinfo.Get("chanlen", "1")); - spacesepstream(options->Get("ulineservers")).GetTokens(this->Ulines); + spacesepstream(options.Get("ulineservers")).GetTokens(this->Ulines); - if (mail->Get("usemail")) + if (mail.Get("usemail")) { Anope::string check[] = { "sendfrom", "registration_subject", "registration_message", "emailchange_subject", "emailchange_message", "memo_subject", "memo_message" }; for (const auto &field : check) - ValidateNotEmpty("mail", field, mail->Get(field)); + ValidateNotEmpty("mail", field, mail.Get(field)); } - this->ReadTimeout = options->Get("readtimeout"); - this->ServiceAlias = options->Get("servicealias"); + this->ReadTimeout = options.Get("readtimeout"); + this->ServiceAlias = options.Get("servicealias"); { std::vector defaults; - spacesepstream(this->GetModule("nickserv")->Get("defaults")).GetTokens(defaults); + spacesepstream(this->GetModule("nickserv").Get("defaults")).GetTokens(defaults); this->DefPrivmsg = std::find(defaults.begin(), defaults.end(), "msg") != defaults.end(); } - this->DefLanguage = options->Get("defaultlanguage"); - this->TimeoutCheck = options->Get("timeoutcheck"); - this->NickChars = networkinfo->Get("nick_chars"); + this->DefLanguage = options.Get("defaultlanguage"); + this->TimeoutCheck = options.Get("timeoutcheck"); + this->NickChars = networkinfo.Get("nick_chars"); for (int i = 0; i < this->CountBlock("uplink"); ++i) { - const Block *uplink = this->GetBlock("uplink", i); + const Block &uplink = this->GetBlock("uplink", i); int protocol; - const Anope::string &protocolstr = uplink->Get("protocol", "ipv4"); + const Anope::string &protocolstr = uplink.Get("protocol", "ipv4"); if (protocolstr == "ipv4") protocol = AF_INET; else if (protocolstr == "ipv6") @@ -220,17 +220,17 @@ Conf::Conf() : Block("") else throw ConfigException("uplink:protocol must be set to ipv4, ipv6, or unix"); - const Anope::string &host = uplink->Get("host"); + const Anope::string &host = uplink.Get("host"); ValidateNotEmptyOrSpaces("uplink", "host", host); int port = 0; if (protocol != AF_UNIX) { - port = uplink->Get("port"); + port = uplink.Get("port"); ValidateNotZero("uplink", "port", port); } - const Anope::string &password = uplink->Get("password"); + const Anope::string &password = uplink.Get("password"); ValidateNotEmptyOrSpaces("uplink", "password", password); if (password[0] == ':') throw ConfigException("uplink:password is not valid"); @@ -240,9 +240,9 @@ Conf::Conf() : Block("") for (int i = 0; i < this->CountBlock("module"); ++i) { - const Block *module = this->GetBlock("module", i); + const Block &module = this->GetBlock("module", i); - const Anope::string &modname = module->Get("name"); + const Anope::string &modname = module.Get("name"); ValidateNotEmptyOrSpaces("module", "name", modname); @@ -251,13 +251,13 @@ Conf::Conf() : Block("") for (int i = 0; i < this->CountBlock("opertype"); ++i) { - const Block *opertype = this->GetBlock("opertype", i); + const Block &opertype = this->GetBlock("opertype", i); - const Anope::string &oname = opertype->Get("name"), - &modes = opertype->Get("modes"), - &inherits = opertype->Get("inherits"), - &commands = opertype->Get("commands"), - &privs = opertype->Get("privs"); + const Anope::string &oname = opertype.Get("name"), + &modes = opertype.Get("modes"), + &inherits = opertype.Get("inherits"), + &commands = opertype.Get("commands"), + &privs = opertype.Get("privs"); ValidateNotEmpty("opertype", "name", oname); @@ -294,15 +294,15 @@ Conf::Conf() : Block("") for (int i = 0; i < this->CountBlock("oper"); ++i) { - const Block *oper = this->GetBlock("oper", i); + const Block &oper = this->GetBlock("oper", i); - const Anope::string &nname = oper->Get("name"), - &type = oper->Get("type"), - &password = oper->Get("password"), - &certfp = oper->Get("certfp"), - &host = oper->Get("host"), - &vhost = oper->Get("vhost"); - bool require_oper = oper->Get("require_oper"); + const Anope::string &nname = oper.Get("name"), + &type = oper.Get("type"), + &password = oper.Get("password"), + &certfp = oper.Get("certfp"), + &host = oper.Get("host"), + &vhost = oper.Get("vhost"); + bool require_oper = oper.Get("require_oper"); ValidateNotEmptyOrSpaces("oper", "name", nname); ValidateNotEmpty("oper", "type", type); @@ -330,15 +330,15 @@ Conf::Conf() : Block("") bi->conf = false; for (int i = 0; i < this->CountBlock("service"); ++i) { - const Block *service = this->GetBlock("service", i); + const Block &service = this->GetBlock("service", i); - const Anope::string &nick = service->Get("nick"), - &user = service->Get("user"), - &host = service->Get("host"), - &gecos = service->Get("gecos"), - &modes = service->Get("modes"), - &channels = service->Get("channels"), - &alias = service->Get("alias", nick.upper()); + const Anope::string &nick = service.Get("nick"), + &user = service.Get("user"), + &host = service.Get("host"), + &gecos = service.Get("gecos"), + &modes = service.Get("modes"), + &channels = service.Get("channels"), + &alias = service.Get("alias", nick.upper()); ValidateNotEmptyOrSpaces("service", "nick", nick); ValidateNotEmptyOrSpaces("service", "user", user); @@ -396,7 +396,6 @@ Conf::Conf() : Block("") { size_t ch = oldchannel.find('#'); Anope::string chname = oldchannel.substr(ch != Anope::string::npos ? ch : 0); - bool found = false; for (const auto &botchannel : bi->botchannels) { @@ -421,24 +420,24 @@ Conf::Conf() : Block("") for (int i = 0; i < this->CountBlock("log"); ++i) { - const Block *log = this->GetBlock("log", i); + const Block &log = this->GetBlock("log", i); - int logage = log->Get("logage"); - bool rawio = log->Get("rawio"); - bool debug = log->Get("debug"); + int logage = log.Get("logage"); + bool rawio = log.Get("rawio"); + bool debug = log.Get("debug"); LogInfo l(logage, rawio, debug); - l.bot = BotInfo::Find(log->Get("bot", "Global"), true); - spacesepstream(log->Get("target")).GetTokens(l.targets); - spacesepstream(log->Get("source")).GetTokens(l.sources); - spacesepstream(log->Get("admin")).GetTokens(l.admin); - spacesepstream(log->Get("override")).GetTokens(l.override); - spacesepstream(log->Get("commands")).GetTokens(l.commands); - spacesepstream(log->Get("servers")).GetTokens(l.servers); - spacesepstream(log->Get("channels")).GetTokens(l.channels); - spacesepstream(log->Get("users")).GetTokens(l.users); - spacesepstream(log->Get("other")).GetTokens(l.normal); + l.bot = BotInfo::Find(log.Get("bot", "Global"), true); + spacesepstream(log.Get("target")).GetTokens(l.targets); + spacesepstream(log.Get("source")).GetTokens(l.sources); + spacesepstream(log.Get("admin")).GetTokens(l.admin); + spacesepstream(log.Get("override")).GetTokens(l.override); + spacesepstream(log.Get("commands")).GetTokens(l.commands); + spacesepstream(log.Get("servers")).GetTokens(l.servers); + spacesepstream(log.Get("channels")).GetTokens(l.channels); + spacesepstream(log.Get("users")).GetTokens(l.users); + spacesepstream(log.Get("other")).GetTokens(l.normal); this->LogInfos.push_back(l); } @@ -447,14 +446,14 @@ Conf::Conf() : Block("") bi->commands.clear(); for (int i = 0; i < this->CountBlock("command"); ++i) { - const Block *command = this->GetBlock("command", i); + const Block &command = this->GetBlock("command", i); - const Anope::string &service = command->Get("service"), - &nname = command->Get("name"), - &cmd = command->Get("command"), - &permission = command->Get("permission"), - &group = command->Get("group"); - bool hide = command->Get("hide"); + const Anope::string &service = command.Get("service"), + &nname = command.Get("name"), + &cmd = command.Get("command"), + &permission = command.Get("permission"), + &group = command.Get("group"); + bool hide = command.Get("hide"); ValidateNotEmptyOrSpaces("command", "service", service); ValidateNotEmpty("command", "name", nname); @@ -472,25 +471,25 @@ Conf::Conf() : Block("") PrivilegeManager::ClearPrivileges(); for (int i = 0; i < this->CountBlock("privilege"); ++i) { - const Block *privilege = this->GetBlock("privilege", i); + const Block &privilege = this->GetBlock("privilege", i); - const Anope::string &nname = privilege->Get("name"), - &desc = privilege->Get("desc"); - int rank = privilege->Get("rank"); + const Anope::string &nname = privilege.Get("name"), + &desc = privilege.Get("desc"); + int rank = privilege.Get("rank"); PrivilegeManager::AddPrivilege(Privilege(nname, desc, rank)); } for (int i = 0; i < this->CountBlock("fantasy"); ++i) { - const Block *fantasy = this->GetBlock("fantasy", i); + const Block &fantasy = this->GetBlock("fantasy", i); - const Anope::string &nname = fantasy->Get("name"), - &service = fantasy->Get("command"), - &permission = fantasy->Get("permission"), - &group = fantasy->Get("group"); - bool hide = fantasy->Get("hide"), - prepend_channel = fantasy->Get("prepend_channel", "yes"); + const Anope::string &nname = fantasy.Get("name"), + &service = fantasy.Get("command"), + &permission = fantasy.Get("permission"), + &group = fantasy.Get("group"); + bool hide = fantasy.Get("hide"), + prepend_channel = fantasy.Get("prepend_channel", "yes"); ValidateNotEmpty("fantasy", "name", nname); ValidateNotEmptyOrSpaces("fantasy", "command", service); @@ -505,10 +504,10 @@ Conf::Conf() : Block("") for (int i = 0; i < this->CountBlock("command_group"); ++i) { - const Block *command_group = this->GetBlock("command_group", i); + const Block &command_group = this->GetBlock("command_group", i); - const Anope::string &nname = command_group->Get("name"), - &description = command_group->Get("description"); + const Anope::string &nname = command_group.Get("name"), + &description = command_group.Get("description"); CommandGroup gr; gr.name = nname; @@ -544,19 +543,19 @@ Conf::Conf() : Block("") Log() << "Tied oper " << na->nc->display << " to type " << o->ot->GetName(); } - if (options->Get("casemap", "ascii") == "ascii") + if (options.Get("casemap", "ascii") == "ascii") Anope::casemap = std::locale(std::locale(), new Anope::ascii_ctype()); - else if (options->Get("casemap") == "rfc1459") + else if (options.Get("casemap") == "rfc1459") Anope::casemap = std::locale(std::locale(), new Anope::rfc1459_ctype()); else { try { - Anope::casemap = std::locale(options->Get("casemap").c_str()); + Anope::casemap = std::locale(options.Get("casemap").c_str()); } catch (const std::runtime_error &) { - Log() << "Unknown casemap " << options->Get("casemap") << " - casemap not changed"; + Log() << "Unknown casemap " << options.Get("casemap") << " - casemap not changed"; } } Anope::CaseMapRebuild(); @@ -620,30 +619,30 @@ void Conf::Post(Conf *old) } } -Block *Conf::GetModule(const Module *m) +Block &Conf::GetModule(const Module *m) { if (!m) - return &Block::EmptyBlock; + return Block::EmptyBlock; return GetModule(m->name); } -Block *Conf::GetModule(const Anope::string &mname) +Block &Conf::GetModule(const Anope::string &mname) { std::map::iterator it = modules.find(mname); if (it != modules.end()) - return it->second; + return *it->second; Block *&block = modules[mname]; /* Search for the block */ for (std::pair iters = blocks.equal_range("module"); iters.first != iters.second; ++iters.first) { - Block *b = &iters.first->second; + Block &b = iters.first->second; - if (b->Get("name") == mname) + if (b.Get("name") == mname) { - block = b; + block = &b; break; } } @@ -660,25 +659,25 @@ BotInfo *Conf::GetClient(const Anope::string &cname) if (it != bots.end()) return BotInfo::Find(!it->second.empty() ? it->second : cname, true); - Block *block = GetModule(cname.lower()); - const Anope::string &client = block->Get("client"); + Block &block = GetModule(cname.lower()); + const Anope::string &client = block.Get("client"); bots[cname] = client; return GetClient(cname); } -const Block *Conf::GetCommand(CommandSource &source) +const Block &Conf::GetCommand(CommandSource &source) { const Anope::string &block_name = source.c ? "fantasy" : "command"; for (std::pair iters = blocks.equal_range(block_name); iters.first != iters.second; ++iters.first) { - Block *b = &iters.first->second; + Block &b = iters.first->second; - if (b->Get("name") == source.command) + if (b.Get("name") == source.command) return b; } - return &Block::EmptyBlock; + return Block::EmptyBlock; } File::File(const Anope::string &n, bool e) : name(n), executable(e) @@ -929,12 +928,12 @@ void Conf::LoadConf(File &file) /* Check defines */ for (int i = 0; i < this->CountBlock("define"); ++i) { - const Block *define = this->GetBlock("define", i); + const Block &define = this->GetBlock("define", i); - const Anope::string &dname = define->Get("name"); + const Anope::string &dname = define.Get("name"); - if (dname == wordbuffer && define != b) - wordbuffer = define->Get("value"); + if (dname == wordbuffer && &define != b) + wordbuffer = define.Get("value"); } if (b) diff --git a/src/init.cpp b/src/init.cpp index 0508ab94f..4befb9ea1 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -215,7 +215,7 @@ static void InitSignals() static void remove_pidfile() { - auto pidfile = Anope::ExpandData(Config->GetBlock("serverinfo")->Get("pid")); + auto pidfile = Anope::ExpandData(Config->GetBlock("serverinfo").Get("pid")); if (!pidfile.empty()) remove(pidfile.c_str()); } @@ -224,7 +224,7 @@ static void remove_pidfile() static void write_pidfile() { - auto pidfile = Anope::ExpandData(Config->GetBlock("serverinfo")->Get("pid")); + auto pidfile = Anope::ExpandData(Config->GetBlock("serverinfo").Get("pid")); if (Anope::NoPID || pidfile.empty()) return; @@ -242,25 +242,25 @@ static void write_pidfile() static void setuidgid() { #ifndef _WIN32 - Configuration::Block *options = Config->GetBlock("options"); + Configuration::Block &options = Config->GetBlock("options"); uid_t uid = -1; gid_t gid = -1; - if (!options->Get("user").empty()) + if (!options.Get("user").empty()) { errno = 0; - struct passwd *u = getpwnam(options->Get("user").c_str()); + struct passwd *u = getpwnam(options.Get("user").c_str()); if (u == NULL) - Log() << "Unable to setuid to " << options->Get("user") << ": " << Anope::LastError(); + Log() << "Unable to setuid to " << options.Get("user") << ": " << Anope::LastError(); else uid = u->pw_uid; } - if (!options->Get("group").empty()) + if (!options.Get("group").empty()) { errno = 0; - struct group *g = getgrnam(options->Get("group").c_str()); + struct group *g = getgrnam(options.Get("group").c_str()); if (g == NULL) - Log() << "Unable to setgid to " << options->Get("group") << ": " << Anope::LastError(); + Log() << "Unable to setgid to " << options.Get("group") << ": " << Anope::LastError(); else gid = g->gr_gid; } @@ -278,16 +278,16 @@ static void setuidgid() if (static_cast(gid) != -1) { if (setgid(gid) == -1) - Log() << "Unable to setgid to " << options->Get("group") << ": " << Anope::LastError(); + Log() << "Unable to setgid to " << options.Get("group") << ": " << Anope::LastError(); else - Log() << "Successfully set group to " << options->Get("group"); + Log() << "Successfully set group to " << options.Get("group"); } if (static_cast(uid) != -1) { if (setuid(uid) == -1) - Log() << "Unable to setuid to " << options->Get("user") << ": " << Anope::LastError(); + Log() << "Unable to setuid to " << options.Get("user") << ": " << Anope::LastError(); else - Log() << "Successfully set user to " << options->Get("user"); + Log() << "Successfully set user to " << options.Get("user"); } #endif } @@ -493,8 +493,8 @@ bool Anope::Init(int ac, char **av) } /* Create me */ - Configuration::Block *block = Config->GetBlock("serverinfo"); - Me = new Server(NULL, block->Get("name"), 0, block->Get("description"), block->Get("id")); + Configuration::Block &block = Config->GetBlock("serverinfo"); + Me = new Server(NULL, block.Get("name"), 0, block.Get("description"), block.Get("id")); for (const auto &[_, bi] : *BotListByNick) { bi->server = Me; @@ -512,15 +512,15 @@ bool Anope::Init(int ac, char **av) /* load modules */ Log() << "Loading modules..."; for (int i = 0; i < Config->CountBlock("module"); ++i) - ModuleManager::LoadModule(Config->GetBlock("module", i)->Get("name"), NULL); + ModuleManager::LoadModule(Config->GetBlock("module", i).Get("name"), NULL); #ifndef _WIN32 /* If we're root, issue a warning now */ if (!getuid() && !getgid()) { /* If we are configured to setuid later, don't issue a warning */ - Configuration::Block *options = Config->GetBlock("options"); - if (options->Get("user").empty()) + Configuration::Block &options = Config->GetBlock("options"); + if (options.Get("user").empty()) { std::cerr << "WARNING: You are currently running Anope as the root superuser. Anope does not" << std::endl; std::cerr << " require root privileges to run, and it is discouraged that you run Anope" << std::endl; diff --git a/src/language.cpp b/src/language.cpp index 8d449d362..440461133 100644 --- a/src/language.cpp +++ b/src/language.cpp @@ -36,7 +36,7 @@ void Language::InitLanguages() setlocale(LC_ALL, ""); - spacesepstream sep(Config->GetBlock("options")->Get("languages")); + spacesepstream sep(Config->GetBlock("options").Get("languages")); Anope::string language; while (sep.GetToken(language)) { diff --git a/src/mail.cpp b/src/mail.cpp index f3adab44c..9fb7aedff 100644 --- a/src/mail.cpp +++ b/src/mail.cpp @@ -15,14 +15,14 @@ Mail::Message::Message(const Anope::string &sf, const Anope::string &mailto, const Anope::string &a, const Anope::string &s, const Anope::string &m) : Thread() - , sendmail_path(Config->GetBlock("mail")->Get("sendmailpath", "/usr/sbin/sendmail -it")) + , sendmail_path(Config->GetBlock("mail").Get("sendmailpath", "/usr/sbin/sendmail -it")) , send_from(sf) , mail_to(mailto) , addr(a) , subject(s) , message(m) - , content_type(Config->GetBlock("mail")->Get("content_type", "text/plain; charset=UTF-8")) - , dont_quote_addresses(Config->GetBlock("mail")->Get("dontquoteaddresses")) + , content_type(Config->GetBlock("mail").Get("content_type", "text/plain; charset=UTF-8")) + , dont_quote_addresses(Config->GetBlock("mail").Get("dontquoteaddresses")) { } @@ -72,32 +72,32 @@ bool Mail::Send(User *u, NickCore *nc, BotInfo *service, const Anope::string &su if (!nc || !service || subject.empty() || message.empty()) return false; - Configuration::Block *b = Config->GetBlock("mail"); + Configuration::Block &b = Config->GetBlock("mail"); if (!u) { - if (!b->Get("usemail") || b->Get("sendfrom").empty()) + if (!b.Get("usemail") || b.Get("sendfrom").empty()) return false; else if (nc->email.empty()) return false; nc->lastmail = Anope::CurTime; - Thread *t = new Mail::Message(b->Get("sendfrom"), nc->display, nc->email, subject, message); + Thread *t = new Mail::Message(b.Get("sendfrom"), nc->display, nc->email, subject, message); t->Start(); return true; } else { - if (!b->Get("usemail") || b->Get("sendfrom").empty()) + if (!b.Get("usemail") || b.Get("sendfrom").empty()) u->SendMessage(service, _("Services have been configured to not send mail.")); - else if (Anope::CurTime - u->lastmail < b->Get("delay")) - u->SendMessage(service, _("Please wait \002%lu\002 seconds and retry."), (unsigned long)b->Get("delay") - (Anope::CurTime - u->lastmail)); + else if (Anope::CurTime - u->lastmail < b.Get("delay")) + u->SendMessage(service, _("Please wait \002%lu\002 seconds and retry."), (unsigned long)b.Get("delay") - (Anope::CurTime - u->lastmail)); else if (nc->email.empty()) u->SendMessage(service, _("Email for \002%s\002 is invalid."), nc->display.c_str()); else { u->lastmail = nc->lastmail = Anope::CurTime; - Thread *t = new Mail::Message(b->Get("sendfrom"), nc->display, nc->email, subject, message); + Thread *t = new Mail::Message(b.Get("sendfrom"), nc->display, nc->email, subject, message); t->Start(); return true; } @@ -108,12 +108,12 @@ bool Mail::Send(User *u, NickCore *nc, BotInfo *service, const Anope::string &su bool Mail::Send(NickCore *nc, const Anope::string &subject, const Anope::string &message) { - Configuration::Block *b = Config->GetBlock("mail"); - if (!b->Get("usemail") || b->Get("sendfrom").empty() || !nc || nc->email.empty() || subject.empty() || message.empty()) + Configuration::Block &b = Config->GetBlock("mail"); + if (!b.Get("usemail") || b.Get("sendfrom").empty() || !nc || nc->email.empty() || subject.empty() || message.empty()) return false; nc->lastmail = Anope::CurTime; - Thread *t = new Mail::Message(b->Get("sendfrom"), nc->display, nc->email, subject, message); + Thread *t = new Mail::Message(b.Get("sendfrom"), nc->display, nc->email, subject, message); t->Start(); return true; diff --git a/src/main.cpp b/src/main.cpp index f53b0ba0f..32329043e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -167,8 +167,8 @@ int main(int ac, char **av, char **envp) /* Set up timers */ time_t last_check = Anope::CurTime; - UpdateTimer updateTimer(Config->GetBlock("options")->Get("updatetimeout", "2m")); - ExpireTimer expireTimer(Config->GetBlock("options")->Get("expiretimeout", "30m")); + UpdateTimer updateTimer(Config->GetBlock("options").Get("updatetimeout", "2m")); + ExpireTimer expireTimer(Config->GetBlock("options").Get("expiretimeout", "30m")); /*** Main loop. ***/ while (!Anope::Quitting) diff --git a/src/messages.cpp b/src/messages.cpp index ddc6ec380..391b3d330 100644 --- a/src/messages.cpp +++ b/src/messages.cpp @@ -237,7 +237,7 @@ void MOTD::Run(MessageSource &source, const std::vector ¶ms, if (s != Me) return; - auto motdfile = Anope::ExpandConfig(Config->GetBlock("serverinfo")->Get("motd")); + auto motdfile = Anope::ExpandConfig(Config->GetBlock("serverinfo").Get("motd")); std::ifstream stream(motdfile.str()); if (!stream.is_open()) { @@ -405,7 +405,7 @@ void Stats::Run(MessageSource &source, const std::vector ¶ms, case 'o': case 'O': /* Check whether the user is an operator */ - if (!u->HasMode("OPER") && Config->GetBlock("options")->Get("hidestatso")) + if (!u->HasMode("OPER") && Config->GetBlock("options").Get("hidestatso")) IRCD->SendNumeric(RPL_STATSLINKINFO, source.GetSource(), params[0][0], "End of /STATS report."); else { @@ -473,7 +473,7 @@ void Whois::Run(MessageSource &source, const std::vector ¶ms, IRCD->SendNumeric(RPL_WHOISUSER, source.GetSource(), u->nick, u->GetIdent(), u->host, '*', u->realname); if (bi) IRCD->SendNumeric(RPL_WHOISREGNICK, source.GetSource(), bi->nick, "is a registered nick"); - IRCD->SendNumeric(RPL_WHOISSERVER, source.GetSource(), u->nick, Me->GetName(), Config->GetBlock("serverinfo")->Get("description")); + IRCD->SendNumeric(RPL_WHOISSERVER, source.GetSource(), u->nick, Me->GetName(), Config->GetBlock("serverinfo").Get("description")); if (bi) IRCD->SendNumeric(RPL_WHOISIDLE, source.GetSource(), bi->nick, Anope::CurTime - bi->lastmsg, bi->signon, "seconds idle, signon time"); IRCD->SendNumeric(RPL_WHOISOPERATOR, source.GetSource(), u->nick, "is a Network Service"); diff --git a/src/misc.cpp b/src/misc.cpp index 2c1950ba6..6f0d95833 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -391,7 +391,7 @@ bool Anope::Match(const Anope::string &str, const Anope::string &mask, bool case if (r == NULL || r->GetExpression() != stripped_mask) { - ServiceReference provider("Regex", Config->GetBlock("options")->Get("regexengine")); + ServiceReference provider("Regex", Config->GetBlock("options").Get("regexengine")); if (provider) { try diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp index 07dea3228..11a00e363 100644 --- a/src/modulemanager.cpp +++ b/src/modulemanager.cpp @@ -242,7 +242,7 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u) /* Initialize config */ try { - m->OnReload(Config); + m->OnReload(*Config); } catch (const ModuleException &ex) { diff --git a/src/protocol.cpp b/src/protocol.cpp index c66f87653..a45985a0d 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -25,10 +25,10 @@ IRCDProto *IRCD = NULL; IRCDProto::IRCDProto(Module *creator, const Anope::string &p) : Service(creator, "IRCDProto", creator->name) , proto_name(p) - , MaxChannel(Config->GetBlock("networkinfo")->Get("chanlen", "32")) - , MaxHost(Config->GetBlock("networkinfo")->Get("hostlen", "64")) - , MaxNick(Config->GetBlock("networkinfo")->Get("nicklen", "31")) - , MaxUser(Config->GetBlock("networkinfo")->Get("userlen", "10")) + , MaxChannel(Config->GetBlock("networkinfo").Get("chanlen", "32")) + , MaxHost(Config->GetBlock("networkinfo").Get("hostlen", "64")) + , MaxNick(Config->GetBlock("networkinfo").Get("nicklen", "31")) + , MaxUser(Config->GetBlock("networkinfo").Get("userlen", "10")) { if (IRCD == NULL) IRCD = this; @@ -76,7 +76,7 @@ Anope::string IRCDProto::SID_Retrieve() if (!IRCD || !IRCD->RequiresID) return ""; - static Anope::string current_sid = Config->GetBlock("serverinfo")->Get("id"); + static Anope::string current_sid = Config->GetBlock("serverinfo").Get("id"); if (current_sid.empty()) current_sid = "00A"; @@ -289,8 +289,8 @@ bool IRCDProto::IsHostValid(const Anope::string &host) if (host.empty() || host.length() > IRCD->MaxHost) return false; - const Anope::string &vhostdisablebe = Config->GetBlock("networkinfo")->Get("disallow_start_or_end"), - vhostchars = Config->GetBlock("networkinfo")->Get("vhost_chars"); + const Anope::string &vhostdisablebe = Config->GetBlock("networkinfo").Get("disallow_start_or_end"), + vhostchars = Config->GetBlock("networkinfo").Get("vhost_chars"); if (vhostdisablebe.find_first_of(host[0]) != Anope::string::npos) return false; @@ -306,7 +306,7 @@ bool IRCDProto::IsHostValid(const Anope::string &host) return false; } - return dots > 0 || Config->GetBlock("networkinfo")->Get("allow_undotted_vhosts"); + return dots > 0 || Config->GetBlock("networkinfo").Get("allow_undotted_vhosts"); } void IRCDProto::SendOper(User *u) @@ -317,7 +317,7 @@ void IRCDProto::SendOper(User *u) size_t IRCDProto::GetMaxListFor(Channel *c, ChannelMode *cm) { - return c->HasMode("LBAN") ? 0 : Config->GetBlock("networkinfo")->Get("modelistsize", "100"); + return c->HasMode("LBAN") ? 0 : Config->GetBlock("networkinfo").Get("modelistsize", "100"); } Anope::string IRCDProto::NormalizeMask(const Anope::string &mask) diff --git a/src/uplink.cpp b/src/uplink.cpp index c032d6118..100217291 100644 --- a/src/uplink.cpp +++ b/src/uplink.cpp @@ -53,8 +53,8 @@ void Uplink::Connect() Configuration::Uplink &u = Config->Uplinks[Anope::CurrentUplink]; new UplinkSocket(); - if (!Config->GetBlock("serverinfo")->Get("localhost").empty()) - UplinkSock->Bind(Config->GetBlock("serverinfo")->Get("localhost")); + if (!Config->GetBlock("serverinfo").Get("localhost").empty()) + UplinkSock->Bind(Config->GetBlock("serverinfo").Get("localhost")); FOREACH_MOD(OnPreServerConnect, ()); Anope::string ip = Anope::Resolve(u.host, u.protocol); Log(LOG_TERMINAL) << "Attempting to connect to uplink #" << (Anope::CurrentUplink + 1) << " " << u.host << " (" << ip << '/' << u.port << ") with protocol " << IRCD->GetProtocolName(); @@ -164,7 +164,7 @@ UplinkSocket::~UplinkSocket() } else if (!Anope::Quitting) { - time_t retry = Config->GetBlock("options")->Get("retrywait"); + time_t retry = Config->GetBlock("options").Get("retrywait"); Log() << "Disconnected, retrying in " << retry << " seconds"; new ReconnectTimer(retry); diff --git a/src/users.cpp b/src/users.cpp index f6a4adb37..8f8e9570d 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -835,14 +835,14 @@ Anope::string User::Mask() const bool User::BadPassword() { - if (!Config->GetBlock("options")->Get("badpasslimit")) + if (!Config->GetBlock("options").Get("badpasslimit")) return false; - if (Config->GetBlock("options")->Get("badpasstimeout") > 0 && this->invalid_pw_time > 0 && this->invalid_pw_time < Anope::CurTime - Config->GetBlock("options")->Get("badpasstimeout")) + if (Config->GetBlock("options").Get("badpasstimeout") > 0 && this->invalid_pw_time > 0 && this->invalid_pw_time < Anope::CurTime - Config->GetBlock("options").Get("badpasstimeout")) this->invalid_pw_count = 0; ++this->invalid_pw_count; this->invalid_pw_time = Anope::CurTime; - if (this->invalid_pw_count >= Config->GetBlock("options")->Get("badpasslimit")) + if (this->invalid_pw_count >= Config->GetBlock("options").Get("badpasslimit")) { this->Kill(Me, "Too many invalid passwords"); return true; diff --git a/src/xline.cpp b/src/xline.cpp index cdfc2d7c4..9e8dd41bf 100644 --- a/src/xline.cpp +++ b/src/xline.cpp @@ -25,11 +25,11 @@ Serialize::Checker > XLineManage void XLine::Init() { - if (this->mask.length() >= 2 && this->mask[0] == '/' && this->mask[this->mask.length() - 1] == '/' && !Config->GetBlock("options")->Get("regexengine").empty()) + if (this->mask.length() >= 2 && this->mask[0] == '/' && this->mask[this->mask.length() - 1] == '/' && !Config->GetBlock("options").Get("regexengine").empty()) { Anope::string stripped_mask = this->mask.substr(1, this->mask.length() - 2); - ServiceReference provider("Regex", Config->GetBlock("options")->Get("regexengine")); + ServiceReference provider("Regex", Config->GetBlock("options").Get("regexengine")); if (provider) { try -- cgit