diff --git a/src/config.cpp b/src/config.cpp index d2ed9a584..87f8e7732 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -23,30 +23,27 @@ #include #include -using Configuration::File; -using Configuration::Conf; -using Configuration::Block; +Configuration::File ServicesConf("anope.conf", false); // Configuration file name -File ServicesConf("anope.conf", false); // Configuration file name -Conf *Config = NULL; +Configuration::Conf *Config = NULL; -Block Block::EmptyBlock(""); +Configuration::Block Configuration::Block::EmptyBlock(""); -Block::Block(const Anope::string &n) : name(n), linenum(-1) +Configuration::Block::Block(const Anope::string &n) : name(n), linenum(-1) { } -const Anope::string &Block::GetName() const +const Anope::string &Configuration::Block::GetName() const { return name; } -int Block::CountBlock(const Anope::string &bname) const +int Configuration::Block::CountBlock(const Anope::string &bname) const { return blocks.count(bname); } -const Block &Block::GetBlock(const Anope::string &bname, int num) const +const Configuration::Block &Configuration::Block::GetBlock(const Anope::string &bname, int num) const { std::pair it = blocks.equal_range(bname); @@ -56,7 +53,7 @@ const Block &Block::GetBlock(const Anope::string &bname, int num) const return EmptyBlock; } -Block *Block::GetMutableBlock(const Anope::string &bname, int num) +Configuration::Block *Configuration::Block::GetMutableBlock(const Anope::string &bname, int num) { std::pair it = blocks.equal_range(bname); @@ -66,18 +63,18 @@ Block *Block::GetMutableBlock(const Anope::string &bname, int num) return NULL; } -bool Block::Set(const Anope::string &tag, const Anope::string &value) +bool Configuration::Block::Set(const Anope::string &tag, const Anope::string &value) { items[tag] = value; return true; } -const Block::item_map &Block::GetItems() const +const Configuration::Block::item_map &Configuration::Block::GetItems() const { return items; } -template<> const Anope::string Block::Get(const Anope::string &tag, const Anope::string &def) const +template<> const Anope::string Configuration::Block::Get(const Anope::string &tag, const Anope::string &def) const { auto it = items.find(tag); if (it != items.end()) @@ -86,12 +83,12 @@ template<> const Anope::string Block::Get(const Anope::string &tag, const Anope: return def; } -template<> time_t Block::Get(const Anope::string &tag, const Anope::string &def) const +template<> time_t Configuration::Block::Get(const Anope::string &tag, const Anope::string &def) const { return Anope::DoTime(Get(tag, def)); } -template<> bool Block::Get(const Anope::string &tag, const Anope::string &def) const +template<> bool Configuration::Block::Get(const Anope::string &tag, const Anope::string &def) const { const Anope::string &str = Get(tag, def); return !str.empty() && !str.equals_ci("no") && !str.equals_ci("off") && !str.equals_ci("false") && !str.equals_ci("0"); @@ -121,7 +118,7 @@ template static void ValidateNotZero(const Anope::string &block, con throw ConfigException("The value for <" + block + ":" + name + "> cannot be zero!"); } -Conf::Conf() : Block("") +Configuration::Conf::Conf() : Configuration::Block("") { ReadTimeout = 0; DefPrivmsg = false; @@ -130,12 +127,12 @@ Conf::Conf() : Block("") for (int i = 0; i < this->CountBlock("include"); ++i) { - const Block &include = this->GetBlock("include", i); + const auto &include = this->GetBlock("include", i); const Anope::string &type = include.Get("type"), &file = include.Get("name"); - File f(file, type == "executable"); + Configuration::File f(file, type == "executable"); this->LoadConf(f); } @@ -167,7 +164,7 @@ Conf::Conf() : Block("") } } - const Block &serverinfo = this->GetBlock("serverinfo"), &options = this->GetBlock("options"), + const auto &serverinfo = this->GetBlock("serverinfo"), &options = this->GetBlock("options"), &mail = this->GetBlock("mail"), &networkinfo = this->GetBlock("networkinfo"); const Anope::string &servername = serverinfo.Get("name"); @@ -210,7 +207,7 @@ Conf::Conf() : Block("") for (int i = 0; i < this->CountBlock("uplink"); ++i) { - const Block &uplink = this->GetBlock("uplink", i); + const auto &uplink = this->GetBlock("uplink", i); int protocol; const Anope::string &protocolstr = uplink.Get("protocol", "ipv4"); @@ -243,7 +240,7 @@ Conf::Conf() : Block("") for (int i = 0; i < this->CountBlock("module"); ++i) { - const Block &module = this->GetBlock("module", i); + const auto &module = this->GetBlock("module", i); const Anope::string &modname = module.Get("name"); @@ -254,7 +251,7 @@ Conf::Conf() : Block("") for (int i = 0; i < this->CountBlock("opertype"); ++i) { - const Block &opertype = this->GetBlock("opertype", i); + const auto &opertype = this->GetBlock("opertype", i); const Anope::string &oname = opertype.Get("name"), &modes = opertype.Get("modes"), @@ -297,7 +294,7 @@ Conf::Conf() : Block("") for (int i = 0; i < this->CountBlock("oper"); ++i) { - const Block &oper = this->GetBlock("oper", i); + const auto &oper = this->GetBlock("oper", i); const Anope::string &nname = oper.Get("name"), &type = oper.Get("type"), @@ -335,7 +332,7 @@ Conf::Conf() : Block("") bi->conf = false; for (int i = 0; i < this->CountBlock("service"); ++i) { - const Block &service = this->GetBlock("service", i); + const auto &service = this->GetBlock("service", i); const Anope::string &nick = service.Get("nick"), &user = service.Get("user", nick.lower()), @@ -426,7 +423,7 @@ Conf::Conf() : Block("") for (int i = 0; i < this->CountBlock("log"); ++i) { - const Block &log = this->GetBlock("log", i); + const auto &log = this->GetBlock("log", i); int logage = log.Get("logage"); bool rawio = log.Get("rawio"); @@ -452,7 +449,7 @@ Conf::Conf() : Block("") bi->commands.clear(); for (int i = 0; i < this->CountBlock("command"); ++i) { - const Block &command = this->GetBlock("command", i); + const auto &command = this->GetBlock("command", i); const Anope::string &service = command.Get("service"), &nname = command.Get("name"), @@ -477,7 +474,7 @@ Conf::Conf() : Block("") PrivilegeManager::ClearPrivileges(); for (int i = 0; i < this->CountBlock("privilege"); ++i) { - const Block &privilege = this->GetBlock("privilege", i); + const auto &privilege = this->GetBlock("privilege", i); const Anope::string &nname = privilege.Get("name"), &desc = privilege.Get("desc"); @@ -488,7 +485,7 @@ Conf::Conf() : Block("") for (int i = 0; i < this->CountBlock("fantasy"); ++i) { - const Block &fantasy = this->GetBlock("fantasy", i); + const auto &fantasy = this->GetBlock("fantasy", i); const Anope::string &nname = fantasy.Get("name"), &service = fantasy.Get("command"), @@ -509,7 +506,7 @@ Conf::Conf() : Block("") for (int i = 0; i < this->CountBlock("command_group"); ++i) { - const Block &command_group = this->GetBlock("command_group", i); + const auto &command_group = this->GetBlock("command_group", i); const Anope::string &nname = command_group.Get("name"), &description = command_group.Get("description"); @@ -566,7 +563,7 @@ Conf::Conf() : Block("") Anope::CaseMapRebuild(); } -Conf::~Conf() +Configuration::Conf::~Conf() { for (const auto *opertype : MyOperTypes) delete opertype; @@ -575,7 +572,7 @@ Conf::~Conf() delete oper; } -void Conf::Post(Conf *old) +void Configuration::Conf::Post(Configuration::Conf *old) { /* Apply module changes */ for (const auto &mod : old->ModulesAutoLoad) @@ -641,26 +638,26 @@ Anope::string Configuration::Uplink::str() const } -Block &Conf::GetModule(const Module *m) +Configuration::Block &Configuration::Conf::GetModule(const Module *m) { if (!m) - return Block::EmptyBlock; + return Configuration::Block::EmptyBlock; return GetModule(m->name); } -Block &Conf::GetModule(const Anope::string &mname) +Configuration::Block &Configuration::Conf::GetModule(const Anope::string &mname) { auto it = modules.find(mname); if (it != modules.end()) return *it->second; - Block *&block = modules[mname]; + auto *&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; + auto &b = iters.first->second; if (b.Get("name") == mname) { @@ -670,70 +667,70 @@ Block &Conf::GetModule(const Anope::string &mname) } if (!block) - block = &Block::EmptyBlock; + block = &Configuration::Block::EmptyBlock; return GetModule(mname); } -BotInfo *Conf::GetClient(const Anope::string &cname) +BotInfo *Configuration::Conf::GetClient(const Anope::string &cname) { auto it = bots.find(cname); if (it != bots.end()) return BotInfo::Find(!it->second.empty() ? it->second : cname, true); - Block &block = GetModule(cname.lower()); + auto &block = GetModule(cname.lower()); const Anope::string &client = block.Get("client"); bots[cname] = client; return GetClient(cname); } -const Block &Conf::GetCommand(CommandSource &source) +const Configuration::Block &Configuration::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; + auto &b = iters.first->second; if (b.Get("name") == source.command) return b; } - return Block::EmptyBlock; + return Configuration::Block::EmptyBlock; } -File::File(const Anope::string &n, bool e) : name(n), executable(e) +Configuration::File::File(const Anope::string &n, bool e) : name(n), executable(e) { } -File::~File() +Configuration::File::~File() { this->Close(); } -const Anope::string &File::GetName() const +const Anope::string &Configuration::File::GetName() const { return this->name; } -Anope::string File::GetPath() const +Anope::string Configuration::File::GetPath() const { return this->executable ? this->name : Anope::ExpandConfig(this->name); } -bool File::IsOpen() const +bool Configuration::File::IsOpen() const { return this->fp != NULL; } -bool File::Open() +bool Configuration::File::Open() { this->Close(); this->fp = (this->executable ? popen(GetPath().c_str(), "r") : fopen(GetPath().c_str(), "r")); return this->fp != NULL; } -void File::Close() +void Configuration::File::Close() { if (this->fp != NULL) { @@ -745,12 +742,12 @@ void File::Close() } } -bool File::End() const +bool Configuration::File::End() const { return !this->IsOpen() || feof(this->fp); } -Anope::string File::Read() +Anope::string Configuration::File::Read() { Anope::string ret; char buf[1024]; @@ -772,19 +769,19 @@ Anope::string File::Read() return ret; } -void Conf::LoadConf(File &file) +void Configuration::Conf::LoadConf(Configuration::File &file) { if (file.GetName().empty()) return; if (!file.Open()) { - throw ConfigException(Anope::Format("File %s could not be opened: %s.", + throw ConfigException(Anope::Format("Configuration::File %s could not be opened: %s.", file.GetPath().c_str(), strerror(errno))); } Anope::string itemname, wordbuffer; - std::stack block_stack; + std::stack block_stack; int linenumber = 0; bool in_word = false, in_quote = false, in_comment = false; @@ -893,7 +890,7 @@ void Conf::LoadConf(File &file) continue; } - Block *b = block_stack.empty() ? this : block_stack.top(); + auto *b = block_stack.empty() ? this : block_stack.top(); auto it = b->blocks.emplace(wordbuffer, Configuration::Block(wordbuffer)); b = &it->second; b->linenum = linenumber; @@ -945,7 +942,7 @@ void Conf::LoadConf(File &file) throw ConfigException("Stray ';' outside of block: " + file.GetName() + ":" + Anope::ToString(linenumber)); } - Block *b = block_stack.top(); + auto *b = block_stack.top(); if (b) { Log(LOG_DEBUG) << "ln " << linenumber << " EOL: s='" << b->name << "' '" << itemname << "' set to '" << wordbuffer << "'"; @@ -987,7 +984,7 @@ void Conf::LoadConf(File &file) } } -Anope::string Conf::ReplaceVars(const Anope::string &str, const File &file, int linenumber) +Anope::string Configuration::Conf::ReplaceVars(const Anope::string &str, const Configuration::File &file, int linenumber) { Anope::string ret; for (auto it = str.begin(); it != str.end(); ) diff --git a/src/messages.cpp b/src/messages.cpp index 5ac024f2c..13ceaef0d 100644 --- a/src/messages.cpp +++ b/src/messages.cpp @@ -24,14 +24,12 @@ #include "channels.h" #include "numeric.h" -using namespace Message; - -void Away::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) +void Message::Away::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) { source.GetUser()->SetAway(params.empty() ? "" : params[0]); } -void Capab::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) +void Message::Capab::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) { if (params.size() == 1) { @@ -47,26 +45,26 @@ void Capab::Run(MessageSource &source, const std::vector ¶ms, } } -void Error::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) +void Message::Error::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) { Anope::QuitReason = "Received an error from the uplink: " + params.back(); Anope::Quitting = true; Log(LOG_TERMINAL) << Anope::QuitReason; } -Ignore::Ignore(Module *creator, const Anope::string &mname) +Message::Ignore::Ignore(Module *creator, const Anope::string &mname) : IRCDMessage(creator, mname, 0) { SetFlag(FLAG_SOFT_LIMIT); } -void Ignore::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) +void Message::Ignore::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) { Log(LOG_DEBUG_3) << "Intentionally ignoring " << name << " message"; } -void Invite::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) +void Message::Invite::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) { User *targ = User::Find(params[0]); Channel *c = Channel::Find(params[1]); @@ -77,7 +75,7 @@ void Invite::Run(MessageSource &source, const std::vector ¶ms FOREACH_MOD(OnInvite, (source.GetUser(), c, targ)); } -void Join::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) +void Message::Join::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) { User *user = source.GetUser(); const Anope::string &channels = params[0]; @@ -111,7 +109,7 @@ void Join::Run(MessageSource &source, const std::vector ¶ms, } } -void Join::SJoin(MessageSource &source, const Anope::string &chan, time_t ts, const Anope::string &modes, const std::vector &modeparams, const std::list &users) +void Message::Join::SJoin(MessageSource &source, const Anope::string &chan, time_t ts, const Anope::string &modes, const std::vector &modeparams, const std::list &users) { bool created; Channel *c = Channel::FindOrCreate(chan, created, ts ? ts : Anope::CurTime); @@ -177,7 +175,7 @@ void Join::SJoin(MessageSource &source, const Anope::string &chan, time_t ts, co } } -void Kick::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) +void Message::Kick::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) { const Anope::string &channel = params[0]; const Anope::string &users = params[1]; @@ -194,7 +192,7 @@ void Kick::Run(MessageSource &source, const std::vector ¶ms, c->KickInternal(source, user, reason); } -void Kill::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) +void Message::Kill::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) { User *u = User::Find(params[0]); BotInfo *bi; @@ -237,7 +235,7 @@ void Message::Mode::Run(MessageSource &source, const std::vector } /* XXX We should cache the file somewhere not open/read/close it on every request */ -void MOTD::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) +void Message::MOTD::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) { Server *s = Server::Find(params[0]); if (s != Me) @@ -257,7 +255,7 @@ void MOTD::Run(MessageSource &source, const std::vector ¶ms, IRCD->SendNumeric(RPL_ENDOFMOTD, source.GetSource(), "End of /MOTD command."); } -void Notice::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) +void Message::Notice::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) { Anope::string message = params[1]; @@ -273,7 +271,7 @@ void Notice::Run(MessageSource &source, const std::vector ¶ms } } -void Part::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) +void Message::Part::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) { User *u = source.GetUser(); const Anope::string &reason = params.size() > 1 ? params[1] : ""; @@ -295,12 +293,12 @@ void Part::Run(MessageSource &source, const std::vector ¶ms, } } -void Ping::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) +void Message::Ping::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) { IRCD->SendPong(params.size() > 1 ? params[1] : Me->GetSID(), params[0]); } -void Privmsg::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) +void Message::Privmsg::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) { const Anope::string &receiver = params[0]; Anope::string message = params[1]; @@ -358,7 +356,7 @@ void Privmsg::Run(MessageSource &source, const std::vector ¶m return; } -void Quit::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) +void Message::Quit::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) { const Anope::string &reason = params[0]; User *user = source.GetUser(); @@ -368,7 +366,7 @@ void Quit::Run(MessageSource &source, const std::vector ¶ms, user->Quit(reason); } -void SQuit::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) +void Message::SQuit::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) { Server *s = Server::Find(params[0]); @@ -389,7 +387,7 @@ void SQuit::Run(MessageSource &source, const std::vector ¶ms, s->Delete(s->GetName() + " " + s->GetUplink()->GetName()); } -void Stats::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) +void Message::Stats::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) { User *u = source.GetUser(); @@ -439,7 +437,7 @@ void Stats::Run(MessageSource &source, const std::vector ¶ms, return; } -void Time::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) +void Message::Time::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) { const auto *tm = localtime(&Anope::CurTime); char timebuf[64]; @@ -448,7 +446,7 @@ void Time::Run(MessageSource &source, const std::vector ¶ms, IRCD->SendNumeric(RPL_TIME, source.GetSource(), Me->GetName(), timestr); } -void Topic::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) +void Message::Topic::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) { Channel *c = Channel::Find(params[0]); if (c) @@ -457,14 +455,14 @@ void Topic::Run(MessageSource &source, const std::vector ¶ms, return; } -void Version::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) +void Message::Version::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) { Module *enc = ModuleManager::FindFirstOf(ENCRYPTION); IRCD->SendNumeric(RPL_VERSION, source.GetSource(), "Anope-" + Anope::Version(), Me->GetName(), Anope::Format("%s -(%s) -- %s", IRCD->GetProtocolName().c_str(), enc ? enc->name.c_str() : "(none)", Anope::VersionBuildString().c_str())); } -void Whois::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) +void Message::Whois::Run(MessageSource &source, const std::vector ¶ms, const Anope::map &tags) { User *u = User::Find(params[0]); diff --git a/src/serialize.cpp b/src/serialize.cpp index fc6b0048e..ef3bfb418 100644 --- a/src/serialize.cpp +++ b/src/serialize.cpp @@ -22,10 +22,10 @@ #include "xline.h" #include "access.h" -using namespace Serialize; +std::vector Serialize::Type::TypeOrder; + +std::map Serialize::Type::Types; -std::vector Type::TypeOrder; -std::map Serialize::Type::Types; std::list *Serializable::SerializableItems; void Serialize::RegisterTypes() @@ -62,7 +62,7 @@ void Serialize::CheckTypes() Serializable::Serializable(const Anope::string &serialize_type) : s_name(serialize_type) - , s_type(Type::Find(serialize_type)) + , s_type(Serialize::Type::Find(serialize_type)) { if (SerializableItems == NULL) SerializableItems = new std::list(); @@ -145,7 +145,7 @@ void Serialize::Data::SetType(const Anope::string &key, Serialize::DataType dt) this->types[key] = dt; } -Type::Type(const Anope::string &n, Module *o) +Serialize::Type::Type(const Anope::string &n, Module *o) : name(n) , owner(o) { @@ -166,7 +166,7 @@ Type::Type(const Anope::string &n, Module *o) } } -Type::~Type() +Serialize::Type::~Type() { auto it = std::find(TypeOrder.begin(), TypeOrder.end(), this->name); if (it != TypeOrder.end()) @@ -187,7 +187,7 @@ Type::~Type() } } -void Type::Create() +void Serialize::Type::Create() { if (created) return; @@ -196,17 +196,17 @@ void Type::Create() created = true; } -void Type::Check() +void Serialize::Type::Check() { FOREACH_MOD(OnSerializeTypeCheck, (this)); } -void Type::UpdateTimestamp() +void Serialize::Type::UpdateTimestamp() { this->timestamp = Anope::CurTime; } -Type *Serialize::Type::Find(const Anope::string &name) +Serialize::Type *Serialize::Type::Find(const Anope::string &name) { auto it = Types.find(name); if (it != Types.end())