diff options
-rw-r--r-- | include/base.h | 35 | ||||
-rw-r--r-- | include/ctables.h | 11 | ||||
-rw-r--r-- | include/extensible.h | 4 | ||||
-rw-r--r-- | include/inspircd.h | 11 | ||||
-rw-r--r-- | include/mode.h | 8 | ||||
-rw-r--r-- | src/base.cpp | 10 | ||||
-rw-r--r-- | src/command_parse.cpp | 8 | ||||
-rw-r--r-- | src/commands/cmd_commands.cpp | 2 | ||||
-rw-r--r-- | src/commands/cmd_server.cpp | 2 | ||||
-rw-r--r-- | src/commands/cmd_who.cpp | 2 | ||||
-rw-r--r-- | src/commands/cmd_whowas.cpp | 2 | ||||
-rw-r--r-- | src/inspstring.cpp | 2 | ||||
-rw-r--r-- | src/mode.cpp | 5 | ||||
-rw-r--r-- | src/modules.cpp | 25 | ||||
-rw-r--r-- | src/modules/m_check.cpp | 6 | ||||
-rw-r--r-- | src/modules/m_customtitle.cpp | 4 | ||||
-rw-r--r-- | src/modules/m_httpd_stats.cpp | 6 | ||||
-rw-r--r-- | src/modules/m_sasl.cpp | 5 | ||||
-rw-r--r-- | src/modules/m_spanningtree/main.cpp | 2 | ||||
-rw-r--r-- | src/modules/m_spanningtree/netburst.cpp | 4 | ||||
-rw-r--r-- | src/stats.cpp | 2 |
21 files changed, 104 insertions, 52 deletions
diff --git a/include/base.h b/include/base.h index bc096b85b..8324d6347 100644 --- a/include/base.h +++ b/include/base.h @@ -36,8 +36,6 @@ class CoreExport classbase /** * Called just prior to destruction via cull list. - * - * @return true to allow the delete, or false to halt the delete */ virtual CullResult cull(); virtual ~classbase(); @@ -93,6 +91,8 @@ class CoreExport refcountbase /** Base class for use count tracking. Uses reference<>, but does not * cause object deletion when the last user is removed. + * + * Safe for use as a second parent class; will not add a second vtable. */ class CoreExport usecountbase { @@ -197,4 +197,35 @@ class CoreExport ModuleException : public CoreException typedef const reference<Module> ModuleRef; +enum ServiceType { + /** is a Command */ + SERVICE_COMMAND, + /** is a channel ModeHandler */ + SERVICE_CMODE, + /** is a user ModeHandler */ + SERVICE_UMODE, + /** is a metadata descriptor */ + SERVICE_METADATA, + /** is a data processing provider (MD5, SQL) */ + SERVICE_DATA, + /** is an I/O hook provider (SSL) */ + SERVICE_IOHOOK +}; + +/** A structure defining something that a module can provide */ +class CoreExport providerbase : public classbase +{ + public: + /** Module that is providing this service */ + ModuleRef creator; + /** Name of the service being provided */ + const std::string name; + /** Type of service (must match object type) */ + const ServiceType service; + providerbase(Module* Creator, const std::string& Name, ServiceType Type) + : creator(Creator), name(Name), service(Type) {} + virtual ~providerbase(); +}; + + #endif diff --git a/include/ctables.h b/include/ctables.h index 68244932d..991ad1cc2 100644 --- a/include/ctables.h +++ b/include/ctables.h @@ -85,16 +85,9 @@ struct RouteDescriptor /** A structure that defines a command. Every command available * in InspIRCd must be defined as derived from Command. */ -class CoreExport Command : public classbase +class CoreExport Command : public providerbase { public: - /** Command name - */ - const std::string command; - - /** Creator module - never NULL */ - ModuleRef creator; - /** User flags needed to execute the command or 0 */ char flags_needed; @@ -151,7 +144,7 @@ class CoreExport Command : public classbase * NICK, optionally PASS, and been resolved). */ Command(Module* me, const std::string &cmd, int minpara = 0, int maxpara = 0) : - command(cmd), creator(me), flags_needed(0), min_params(minpara), max_params(maxpara), + providerbase(me, cmd, SERVICE_COMMAND), flags_needed(0), min_params(minpara), max_params(maxpara), use_count(0), total_bytes(0), disabled(false), works_before_reg(false), Penalty(1) { } diff --git a/include/extensible.h b/include/extensible.h index 487b67408..ae78c0a0d 100644 --- a/include/extensible.h +++ b/include/extensible.h @@ -12,11 +12,9 @@ enum SerializeFormat /** Class represnting an extension of some object */ -class CoreExport ExtensionItem : public usecountbase +class CoreExport ExtensionItem : public providerbase, public usecountbase { public: - const std::string key; - ModuleRef owner; ExtensionItem(const std::string& key, Module* owner); virtual ~ExtensionItem(); /** Serialize this item into a string diff --git a/include/inspircd.h b/include/inspircd.h index 0bbf3fb03..52035ce49 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -594,6 +594,15 @@ class CoreExport InspIRCd */ bool AddResolver(Resolver* r, bool cached); + /** Register a service provided by a module */ + void AddService(providerbase&); + + inline void AddServices(providerbase** list, int count) + { + for(int i=0; i < count; i++) + AddService(*list[i]); + } + /** Add a command to this server's command parser * @param f A Command command handler object to add * @throw ModuleException Will throw ModuleExcption if the command already exists @@ -814,7 +823,7 @@ class CommandModule : public Module Version GetVersion() { - return Version(cmd.command, VF_VENDOR|VF_CORE); + return Version(cmd.name, VF_VENDOR|VF_CORE); } }; diff --git a/include/mode.h b/include/mode.h index a633cebca..f2b58a309 100644 --- a/include/mode.h +++ b/include/mode.h @@ -90,7 +90,7 @@ enum ParamSpec * mode is expected to have a parameter, then this is * equivalent to returning MODEACTION_DENY. */ -class CoreExport ModeHandler : public classbase +class CoreExport ModeHandler : public providerbase { protected: /** @@ -145,12 +145,6 @@ class CoreExport ModeHandler : public classbase int levelrequired; public: - /** Module that created this mode. NULL for core modes */ - ModuleRef creator; - /** Long-form name - */ - const std::string name; - /** * The constructor for ModeHandler initalizes the mode handler. * The constructor of any class you derive from ModeHandler should diff --git a/src/base.cpp b/src/base.cpp index 8e81f7b73..3ff3d5281 100644 --- a/src/base.cpp +++ b/src/base.cpp @@ -77,7 +77,11 @@ usecountbase::~usecountbase() (void*)this, usecount); } -ExtensionItem::ExtensionItem(const std::string& Key, Module* mod) : key(Key), owner(mod) +providerbase::~providerbase() +{ +} + +ExtensionItem::ExtensionItem(const std::string& Key, Module* mod) : providerbase(mod, Key, SERVICE_METADATA) { } @@ -122,7 +126,7 @@ void* ExtensionItem::unset_raw(Extensible* container) void ExtensionManager::Register(ExtensionItem* item) { - types.insert(std::make_pair(item->key, item)); + types.insert(std::make_pair(item->name, item)); } void ExtensionManager::BeginUnregister(Module* module, std::vector<reference<ExtensionItem> >& list) @@ -132,7 +136,7 @@ void ExtensionManager::BeginUnregister(Module* module, std::vector<reference<Ext { std::map<std::string, reference<ExtensionItem> >::iterator me = i++; ExtensionItem* item = me->second; - if (item->owner == module) + if (item->creator == module) { list.push_back(item); types.erase(me); diff --git a/src/command_parse.cpp b/src/command_parse.cpp index 86f801d3e..d7a4eede7 100644 --- a/src/command_parse.cpp +++ b/src/command_parse.cpp @@ -366,7 +366,7 @@ bool CommandParser::ProcessCommand(User *user, std::string &cmd) { user->WriteNumeric(ERR_NEEDMOREPARAMS, "%s %s :Not enough parameters.", user->nick.c_str(), command.c_str()); if ((ServerInstance->Config->SyntaxHints) && (user->registered == REG_ALL) && (cm->second->syntax.length())) - user->WriteNumeric(RPL_SYNTAX, "%s :SYNTAX %s %s", user->nick.c_str(), cm->second->command.c_str(), cm->second->syntax.c_str()); + user->WriteNumeric(RPL_SYNTAX, "%s :SYNTAX %s %s", user->nick.c_str(), cm->second->name.c_str(), cm->second->syntax.c_str()); return do_more; } if ((user->registered != REG_ALL) && (!cm->second->WorksBeforeReg())) @@ -397,7 +397,7 @@ bool CommandParser::ProcessCommand(User *user, std::string &cmd) void CommandParser::RemoveCommand(Command* x) { - Commandtable::iterator n = cmdlist.find(x->command); + Commandtable::iterator n = cmdlist.find(x->name); if (n != cmdlist.end() && n->second == x) cmdlist.erase(n); } @@ -420,9 +420,9 @@ bool CommandParser::ProcessBuffer(std::string &buffer,User *user) bool CommandParser::AddCommand(Command *f) { /* create the command and push it onto the table */ - if (cmdlist.find(f->command) == cmdlist.end()) + if (cmdlist.find(f->name) == cmdlist.end()) { - cmdlist[f->command] = f; + cmdlist[f->name] = f; return true; } return false; diff --git a/src/commands/cmd_commands.cpp b/src/commands/cmd_commands.cpp index 63b4b24fb..cc662f3b6 100644 --- a/src/commands/cmd_commands.cpp +++ b/src/commands/cmd_commands.cpp @@ -53,7 +53,7 @@ CmdResult CommandCommands::Handle (const std::vector<std::string>&, User *user) Module* src = i->second->creator; user->WriteNumeric(RPL_COMMANDS, "%s :%s %s %d %d", user->nick.c_str(), - i->second->command.c_str(), + i->second->name.c_str(), src ? src->ModuleSourceFile.c_str() : "<core>", i->second->min_params, i->second->Penalty); diff --git a/src/commands/cmd_server.cpp b/src/commands/cmd_server.cpp index e5a7622b8..c6e7d9888 100644 --- a/src/commands/cmd_server.cpp +++ b/src/commands/cmd_server.cpp @@ -41,7 +41,7 @@ CmdResult CommandServer::Handle (const std::vector<std::string>&, User *user) } else { - user->WriteNumeric(ERR_NOTREGISTERED, "%s :You may not register as a server (servers have seperate ports from clients, change your config)",command.c_str()); + user->WriteNumeric(ERR_NOTREGISTERED, "%s :You may not register as a server (servers have seperate ports from clients, change your config)",name.c_str()); } return CMD_FAILURE; } diff --git a/src/commands/cmd_who.cpp b/src/commands/cmd_who.cpp index da797201b..b5ace291b 100644 --- a/src/commands/cmd_who.cpp +++ b/src/commands/cmd_who.cpp @@ -109,7 +109,7 @@ bool CommandWho::whomatch(User* cuser, User* user, const char* matchtext) match = false; const Extensible::ExtensibleStore& list = user->GetExtList(); for(Extensible::ExtensibleStore::const_iterator i = list.begin(); i != list.end(); ++i) - if (InspIRCd::Match(i->first->key, matchtext)) + if (InspIRCd::Match(i->first->name, matchtext)) match = true; } else if (opt_realname) diff --git a/src/commands/cmd_whowas.cpp b/src/commands/cmd_whowas.cpp index 34e7e74e0..21c30d742 100644 --- a/src/commands/cmd_whowas.cpp +++ b/src/commands/cmd_whowas.cpp @@ -29,7 +29,7 @@ CmdResult CommandWhowas::Handle (const std::vector<std::string>& parameters, Use /* if whowas disabled in config */ if (ServerInstance->Config->WhoWasGroupSize == 0 || ServerInstance->Config->WhoWasMaxGroups == 0) { - user->WriteNumeric(421, "%s %s :This command has been disabled.",user->nick.c_str(),command.c_str()); + user->WriteNumeric(421, "%s %s :This command has been disabled.",user->nick.c_str(),name.c_str()); return CMD_FAILURE; } diff --git a/src/inspstring.cpp b/src/inspstring.cpp index ff9c1875f..4f4cbd8ad 100644 --- a/src/inspstring.cpp +++ b/src/inspstring.cpp @@ -13,7 +13,7 @@ /* $Core */ -#include "inspstring.h" +#include "inspircd.h" /* * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> diff --git a/src/mode.cpp b/src/mode.cpp index e9635364e..441ca520d 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -46,8 +46,9 @@ #include "modes/umode_s.h" ModeHandler::ModeHandler(Module* Creator, const std::string& Name, char modeletter, ParamSpec Params, ModeType type) - : m_paramtype(TR_TEXT), parameters_taken(Params), mode(modeletter), prefix(0), oper(false), - list(false), m_type(type), count(0), levelrequired(HALFOP_VALUE), creator(Creator), name(Name) + : providerbase(Creator, Name, type == MODETYPE_CHANNEL ? SERVICE_CMODE : SERVICE_UMODE), m_paramtype(TR_TEXT), + parameters_taken(Params), mode(modeletter), prefix(0), oper(false), + list(false), m_type(type), count(0), levelrequired(HALFOP_VALUE) { } diff --git a/src/modules.cpp b/src/modules.cpp index a2c4aa6ea..d86dc6270 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -469,7 +469,30 @@ void InspIRCd::AddCommand(Command *f) { if (!this->Parser->AddCommand(f)) { - throw ModuleException("Command "+std::string(f->command)+" already exists."); + throw ModuleException("Command "+std::string(f->name)+" already exists."); + } +} + +void InspIRCd::AddService(providerbase& item) +{ + switch (item.service) + { + case SERVICE_COMMAND: + if (!Parser->AddCommand(static_cast<Command*>(&item))) + throw ModuleException("Command "+std::string(item.name)+" already exists."); + return; + case SERVICE_CMODE: + case SERVICE_UMODE: + if (!Modes->AddMode(static_cast<ModeHandler*>(&item))) + throw ModuleException("Mode "+std::string(item.name)+" already exists."); + return; + case SERVICE_METADATA: + Extensions.Register(static_cast<ExtensionItem*>(&item)); + return; + case SERVICE_DATA: + case SERVICE_IOHOOK: + default: + throw ModuleException("Cannot add unknown service type"); } } diff --git a/src/modules/m_check.cpp b/src/modules/m_check.cpp index 0a0ecab2b..a907b06e8 100644 --- a/src/modules/m_check.cpp +++ b/src/modules/m_check.cpp @@ -41,9 +41,9 @@ class CommandCheck : public Command ExtensionItem* item = i->first; std::string value = item->serialize(FORMAT_USER, ext, i->second); if (!value.empty()) - user->SendText(checkstr + " meta:" + item->key + " " + value); - else if (!item->key.empty()) - dumpkeys << " " << item->key; + user->SendText(checkstr + " meta:" + item->name + " " + value); + else if (!item->name.empty()) + dumpkeys << " " << item->name; } if (!dumpkeys.str().empty()) user->SendText(checkstr + " metadata", dumpkeys); diff --git a/src/modules/m_customtitle.cpp b/src/modules/m_customtitle.cpp index c89535a3c..8814e8cf6 100644 --- a/src/modules/m_customtitle.cpp +++ b/src/modules/m_customtitle.cpp @@ -53,14 +53,14 @@ class CommandTitle : public Command ConfigReader Conf; for (int i=0; i<Conf.Enumerate("title"); i++) { - std::string name = Conf.ReadValue("title", "name", "", i); + std::string Name = Conf.ReadValue("title", "name", "", i); std::string pass = Conf.ReadValue("title", "password", "", i); std::string hash = Conf.ReadValue("title", "hash", "", i); std::string host = Conf.ReadValue("title", "host", "*@*", i); std::string title = Conf.ReadValue("title", "title", "", i); std::string vhost = Conf.ReadValue("title", "vhost", "", i); - if (!strcmp(name.c_str(),parameters[0].c_str()) && !ServerInstance->PassCompare(user, pass.c_str(), parameters[1].c_str(), hash.c_str()) && OneOfMatches(TheHost,TheIP,host.c_str()) && !title.empty()) + if (!strcmp(Name.c_str(),parameters[0].c_str()) && !ServerInstance->PassCompare(user, pass.c_str(), parameters[1].c_str(), hash.c_str()) && OneOfMatches(TheHost,TheIP,host.c_str()) && !title.empty()) { ctitle.set(user, title); diff --git a/src/modules/m_httpd_stats.cpp b/src/modules/m_httpd_stats.cpp index 36deda11b..e34c4b43f 100644 --- a/src/modules/m_httpd_stats.cpp +++ b/src/modules/m_httpd_stats.cpp @@ -75,9 +75,9 @@ class ModuleHttpStats : public Module ExtensionItem* item = i->first; std::string value = item->serialize(FORMAT_USER, ext, i->second); if (!value.empty()) - data << "<meta name=\"" << item->key << "\">" << Sanitize(value) << "</meta>"; - else if (!item->key.empty()) - data << "<meta name=\"" << item->key << "\"/>"; + data << "<meta name=\"" << item->name << "\">" << Sanitize(value) << "</meta>"; + else if (!item->name.empty()) + data << "<meta name=\"" << item->name << "\"/>"; } data << "</metadata>"; } diff --git a/src/modules/m_sasl.cpp b/src/modules/m_sasl.cpp index add530ff1..298544edc 100644 --- a/src/modules/m_sasl.cpp +++ b/src/modules/m_sasl.cpp @@ -229,10 +229,9 @@ class ModuleSASL : public Module Implementation eventlist[] = { I_OnEvent, I_OnUserRegister }; ServerInstance->Modules->Attach(eventlist, this, 2); - ServerInstance->AddCommand(&auth); - ServerInstance->AddCommand(&sasl); + providerbase* providelist[] = { &auth, &sasl, &authExt }; + ServerInstance->AddServices(providelist, 3); - ServerInstance->Extensions.Register(&authExt); if (!ServerInstance->Modules->Find("m_services_account.so") || !ServerInstance->Modules->Find("m_cap.so")) ServerInstance->Logs->Log("m_sasl", DEFAULT, "WARNING: m_services_account.so and m_cap.so are not loaded! m_sasl.so will NOT function correctly until these two modules are loaded!"); } diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp index 386c95dfc..fe2cfe9b6 100644 --- a/src/modules/m_spanningtree/main.cpp +++ b/src/modules/m_spanningtree/main.cpp @@ -615,7 +615,7 @@ void ModuleSpanningTree::OnUserConnect(LocalUser* user) ExtensionItem* item = i->first; std::string value = item->serialize(FORMAT_NETWORK, user, i->second); if (!value.empty()) - ServerInstance->PI->SendMetaData(user, item->key, value); + ServerInstance->PI->SendMetaData(user, item->name, value); } Utils->TreeRoot->SetUserCount(1); // increment by 1 diff --git a/src/modules/m_spanningtree/netburst.cpp b/src/modules/m_spanningtree/netburst.cpp index 52ce5897d..61a5f66d2 100644 --- a/src/modules/m_spanningtree/netburst.cpp +++ b/src/modules/m_spanningtree/netburst.cpp @@ -225,7 +225,7 @@ void TreeSocket::SendChannelModes(TreeServer* Current) ExtensionItem* item = i->first; std::string value = item->serialize(FORMAT_NETWORK, c->second, i->second); if (!value.empty()) - Utils->Creator->ProtoSendMetaData(this, c->second, item->key, value); + Utils->Creator->ProtoSendMetaData(this, c->second, item->name, value); } FOREACH_MOD(I_OnSyncChannel,OnSyncChannel(c->second,Utils->Creator,this)); @@ -274,7 +274,7 @@ void TreeSocket::SendUsers(TreeServer* Current) ExtensionItem* item = i->first; std::string value = item->serialize(FORMAT_NETWORK, u->second, i->second); if (!value.empty()) - Utils->Creator->ProtoSendMetaData(this, u->second, item->key, value); + Utils->Creator->ProtoSendMetaData(this, u->second, item->name, value); } FOREACH_MOD(I_OnSyncUser,OnSyncUser(u->second,Utils->Creator,this)); diff --git a/src/stats.cpp b/src/stats.cpp index e8173e655..01d8b9611 100644 --- a/src/stats.cpp +++ b/src/stats.cpp @@ -142,7 +142,7 @@ void InspIRCd::DoStats(char statschar, User* user, string_list &results) if (i->second->use_count) { /* RPL_STATSCOMMANDS */ - results.push_back(sn+" 212 "+user->nick+" "+i->second->command+" "+ConvToStr(i->second->use_count)+" "+ConvToStr(i->second->total_bytes)); + results.push_back(sn+" 212 "+user->nick+" "+i->second->name+" "+ConvToStr(i->second->use_count)+" "+ConvToStr(i->second->total_bytes)); } } break; |