]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Add ProtocolInterface::BroadcastEncap() and infrastructure for manually forwarding...
authorAttila Molnar <attilamolnar@hush.com>
Sun, 26 Jan 2014 12:12:01 +0000 (13:12 +0100)
committerAttila Molnar <attilamolnar@hush.com>
Sun, 26 Jan 2014 12:12:01 +0000 (13:12 +0100)
include/command_parse.h
include/ctables.h
include/protocol.h
src/command_parse.cpp
src/modules/m_spanningtree/encap.cpp
src/modules/m_spanningtree/protocolinterface.cpp
src/modules/m_spanningtree/protocolinterface.h

index 6682bc4fbb2bd45f579592332be1268557038e99..70544b0c8e17d1752d6f67814e5b0c2bbab10e9d 100644 (file)
@@ -49,13 +49,15 @@ class CoreExport CommandParser
         * @param commandname The command to find. This should be in uppercase.
         * @param parameters Parameter list
         * @param user The user to call the handler on behalf of
+        * @param cmd If non-NULL and the command was executed it is set to the command handler,
+        * otherwise it isn't written to.
         * @return This method will return CMD_SUCCESS if the command handler was found and called,
         * and the command completeld successfully. It will return CMD_FAILURE if the command handler was found
         * and called, but the command did not complete successfully, and it will return CMD_INVALID if the
         * command simply did not exist at all or the wrong number of parameters were given, or the user
         * was not privilaged enough to execute the command.
         */
-       CmdResult CallHandler(const std::string &commandname, const std::vector<std::string>& parameters, User *user);
+       CmdResult CallHandler(const std::string& commandname, const std::vector<std::string>& parameters, User* user, Command** cmd = NULL);
 
        /** Get the handler function for a command.
         * @param commandname The command required. Always use uppercase for this parameter.
index 81b841e81ad1f2686a97f2334a854acd10909e75..a69f5c86f65e14c3fc18ae7abdd75b4deee4905c 100644 (file)
@@ -224,8 +224,14 @@ class CoreExport CommandBase : public ServiceProvider
 class CoreExport Command : public CommandBase
 {
  public:
+       /** If true, the command will not be forwarded by the linking module even if it comes via ENCAP.
+        * Can be used to forward commands before their effects.
+        */
+       bool force_manual_route;
+
        Command(Module* me, const std::string& cmd, unsigned int minpara = 0, unsigned int maxpara = 0)
                : CommandBase(me, cmd, minpara, maxpara)
+               , force_manual_route(false)
        {
        }
 
index 4c58c78ba379ca5c0ea9e8aaf79237a02e3b01e2..01eb145f176200914e364ed9b5d14f4b9e45a96b 100644 (file)
@@ -68,6 +68,16 @@ class CoreExport ProtocolInterface
         */
        virtual bool SendEncapsulatedData(const std::string& targetmask, const std::string& cmd, const parameterlist& params, User* source = NULL) { return false; }
 
+       /** Send an ENCAP message to all servers.
+        * See the protocol documentation for the purpose of ENCAP.
+        * @param cmd The ENCAP subcommand
+        * @param params List of string parameters which are dependant on the subcommand
+        * @param source The source of the message (prefix), must be a local user or a user behind 'omit'
+        * or NULL which is equivalent to the local server
+        * @param omit If non-NULL the message won't be sent in the direction of this server, useful for forwarding messages
+        */
+       virtual void BroadcastEncap(const std::string& cmd, const parameterlist& params, User* source = NULL, User* omit = NULL) { }
+
        /** Send metadata for a channel to other linked servers.
         * @param chan The channel to send metadata for
         * @param key The 'key' of the data, e.g. "swhois" for swhois desc on a user
index 66b8dcd670294b5b09803211f0623de7c2b46c9c..7133b3f053110347f9a9b2d30debd207e73b683c 100644 (file)
@@ -118,7 +118,7 @@ Command* CommandParser::GetHandler(const std::string &commandname)
 
 // calls a handler function for a command
 
-CmdResult CommandParser::CallHandler(const std::string &commandname, const std::vector<std::string>& parameters, User *user)
+CmdResult CommandParser::CallHandler(const std::string& commandname, const std::vector<std::string>& parameters, User* user, Command** cmd)
 {
        Commandtable::iterator n = cmdlist.find(commandname);
 
@@ -150,6 +150,8 @@ CmdResult CommandParser::CallHandler(const std::string &commandname, const std::
 
                        if (bOkay)
                        {
+                               if (cmd)
+                                       *cmd = n->second;
                                return n->second->Handle(parameters,user);
                        }
                }
index 12ab2b664cf939b43019a07315ee2e0c77c34073..566f15da88d0298ee49c1b2bceda14b7ea7603ee 100644 (file)
@@ -27,8 +27,12 @@ CmdResult CommandEncap::Handle(User* user, std::vector<std::string>& params)
        if (ServerInstance->Config->GetSID() == params[0] || InspIRCd::Match(ServerInstance->Config->ServerName, params[0]))
        {
                parameterlist plist(params.begin() + 2, params.end());
-               ServerInstance->Parser->CallHandler(params[1], plist, user);
+               Command* cmd = NULL;
+               ServerInstance->Parser->CallHandler(params[1], plist, user, &cmd);
                // Discard return value, ENCAP shall succeed even if the command does not exist
+
+               if ((cmd) && (cmd->force_manual_route))
+                       return CMD_FAILURE;
        }
        return CMD_SUCCESS;
 }
index ee5e319844591cbafbf017096030cd0b67594265..192f7cff2ca2e5abae2ddee5d384b1a2e7038ff3 100644 (file)
@@ -71,6 +71,17 @@ bool SpanningTreeProtocolInterface::SendEncapsulatedData(const std::string& targ
        return true;
 }
 
+void SpanningTreeProtocolInterface::BroadcastEncap(const std::string& cmd, const parameterlist& params, User* source, User* omit)
+{
+       if (!source)
+               source = ServerInstance->FakeClient;
+
+       // If omit is non-NULL we pass the route belonging to the user to Forward(),
+       // otherwise we pass NULL, which is equivalent to Broadcast()
+       TreeServer* server = (omit ? TreeServer::Get(omit)->GetRoute() : NULL);
+       CmdBuilder(source, "ENCAP * ").push_raw(cmd).insert(params).Forward(server);
+}
+
 void SpanningTreeProtocolInterface::SendMetaData(User* u, const std::string& key, const std::string& data)
 {
        CommandMetadata::Builder(u, key, data).Broadcast();
index 04b56c1816dbb8c192e11e8e9c4b24781962838b..97648f4b46434384b88b5c6d80b7a471f44cddcc 100644 (file)
@@ -32,6 +32,7 @@ class SpanningTreeProtocolInterface : public ProtocolInterface
        };
 
        bool SendEncapsulatedData(const std::string& targetmask, const std::string& cmd, const parameterlist& params, User* source) CXX11_OVERRIDE;
+       void BroadcastEncap(const std::string& cmd, const parameterlist& params, User* source, User* omit) CXX11_OVERRIDE;
        void SendMetaData(User* user, const std::string& key, const std::string& data) CXX11_OVERRIDE;
        void SendMetaData(Channel* chan, const std::string& key, const std::string& data) CXX11_OVERRIDE;
        void SendMetaData(const std::string& key, const std::string& data) CXX11_OVERRIDE;