]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Add Inspircd::AddServices
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>
Sun, 15 Nov 2009 18:26:53 +0000 (18:26 +0000)
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>
Sun, 15 Nov 2009 18:26:53 +0000 (18:26 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@12135 e03df62e-2008-0410-955e-edbf42e46eb7

21 files changed:
include/base.h
include/ctables.h
include/extensible.h
include/inspircd.h
include/mode.h
src/base.cpp
src/command_parse.cpp
src/commands/cmd_commands.cpp
src/commands/cmd_server.cpp
src/commands/cmd_who.cpp
src/commands/cmd_whowas.cpp
src/inspstring.cpp
src/mode.cpp
src/modules.cpp
src/modules/m_check.cpp
src/modules/m_customtitle.cpp
src/modules/m_httpd_stats.cpp
src/modules/m_sasl.cpp
src/modules/m_spanningtree/main.cpp
src/modules/m_spanningtree/netburst.cpp
src/stats.cpp

index bc096b85bdd9e54ee629df5e94c245638f048d5e..8324d63472c628c225a2957f5ebcdd8021c2b3af 100644 (file)
@@ -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
index 68244932da1bf1d2f360f988f4a9103cbd08a97e..991ad1cc2927742b66e3a39324050235c35019d9 100644 (file)
@@ -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)
        {
        }
index 487b67408e7b5b741db37e5a7afca3cd6141f8e1..ae78c0a0d0151a70774cba1a8c48a9e0ece1b53a 100644 (file)
@@ -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
index 0bbf3fb037c2965882e2a04275ce7891874bd17c..52035ce492975ecc3a76f1e5370a7d05a39fef95 100644 (file)
@@ -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);
        }
 };
 
index a633cebcac9a807a9c03c91fef867f9b2d109f9f..f2b58a309207d46a3106598dd7eda0f656879a0a 100644 (file)
@@ -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
index 8e81f7b73d09b83a16ef730339edf989c94850d6..3ff3d5281334a2b71871295bde327c451a8431b4 100644 (file)
@@ -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);
index 86f801d3e3c3e4023d7f25d2f66235679ede9069..d7a4eede78901fe0dc0fa629c73eca431358345b 100644 (file)
@@ -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;
index 63b4b24fb68fe5ce83633aa1605ef4337af8db84..cc662f3b684369a55e5c3abc59aa073eb5e0b8eb 100644 (file)
@@ -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);
index e5a7622b87185dad4bc90751171c0024d4decfce..c6e7d988844818ab22fbf291d49140254cb0adbe 100644 (file)
@@ -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;
 }
index da797201ba3967dad7af03ca6c3309577b7d8fb6..b5ace291b7e6e39c2981bd7890483e83b9da25e7 100644 (file)
@@ -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)
index 34e7e74e06f5fc3ef756e441003251d9a07e0ed4..21c30d742e457c3b714104e3eb0cb17b1b521636 100644 (file)
@@ -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;
        }
 
index ff9c1875f2e6809080a8bf9f68c396c203b825ed..4f4cbd8ad226ad4200ec1d427122cf9ffe5b9af3 100644 (file)
@@ -13,7 +13,7 @@
 
 /* $Core */
 
-#include "inspstring.h"
+#include "inspircd.h"
 
 /*
  * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
index e9635364e0769ac56cd8e83307ca42eab0b09f6e..441ca520df6b04ab46cd165ec9668b683121bf91 100644 (file)
@@ -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)
 {
 }
 
index a2c4aa6ea5b8f78fcedc7d2e1768104cfd4b2366..d86dc62705ce6c33e500683c9fc5c1999c88024c 100644 (file)
@@ -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");
        }
 }
 
index 0a0ecab2bdcf12fc01cff4f85482c15cf00e247f..a907b06e8cf45b27db11b644b9fbd8d7cfb24f32 100644 (file)
@@ -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);
index c89535a3cbfbdd18d255004841f8ec62549a8e37..8814e8cf6959aeea8e2e6aab076a8bfb39d1f176 100644 (file)
@@ -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);
 
index 36deda11b5bb98e4e8a13ae7e3dbc18fb9d5b484..e34c4b43f178701c89d9bdf76a401490a1399c8b 100644 (file)
@@ -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>";
        }
index add530ff1a665263727fc98338cefcd9bd183318..298544edce84a228365acacaa03cc36efde7f3e2 100644 (file)
@@ -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!");
        }
index 386c95dfc06b9552e3c386945b9ae2b71d1d0f1d..fe2cfe9b62f98a8e5a074d5acaa47d4de2d5ea25 100644 (file)
@@ -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
index 52ce5897dfe501db56cf89c31b57842823fa2a33..61a5f66d23ab92a79240f2e285f4a43377ffeba8 100644 (file)
@@ -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));
index e8173e655df340d693aa9fbba2ac051eaaa130d4..01d8b9611beff05f6bd62bf95b22cbee043098c6 100644 (file)
@@ -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;