]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Pass an interface to the OnSync hooks
authorattilamolnar <attilamolnar@hush.com>
Mon, 2 Sep 2013 11:41:16 +0000 (13:41 +0200)
committerattilamolnar <attilamolnar@hush.com>
Fri, 13 Sep 2013 10:15:44 +0000 (12:15 +0200)
Remove Module::ProtoSendMetaData()

include/modules.h
include/protocol.h
include/typedefs.h
src/modules.cpp
src/modules/m_filter.cpp
src/modules/m_spanningtree/main.cpp
src/modules/m_spanningtree/main.h
src/modules/m_spanningtree/netburst.cpp
src/modules/m_spanningtree/protocolinterface.cpp
src/modules/m_spanningtree/protocolinterface.h
src/modules/m_spanningtree/treesocket.h

index e04ee01ff500173b332703ad3a4809f97cf499f3..931d85032f512354264d3bdd11757b7be85456a2 100644 (file)
@@ -623,43 +623,32 @@ class CoreExport Module : public classbase, public usecountbase
 
        /** Allows modules to synchronize data which relates to users during a netburst.
         * When this function is called, it will be called from the module which implements
-        * the linking protocol. This currently is m_spanningtree.so. A pointer to this module
-        * is given in Module* proto, so that you may call its methods such as ProtoSendMode
-        * (see below). This function will be called for every user visible on your side
-        * of the burst, allowing you to for example set modes, etc. Do not use this call to
-        * synchronize data which you have stored using class Extensible -- There is a specialist
-        * function OnSyncUserMetaData and OnSyncChannelMetaData for this!
+        * the linking protocol. This currently is m_spanningtree.so.
+        * This function will be called for every user visible on your side
+        * of the burst, allowing you to for example set modes, etc.
         * @param user The user being syncronized
-        * @param proto A pointer to the module handling network protocol
-        * @param opaque An opaque pointer set by the protocol module, should not be modified!
+        * @param server The target of the burst
         */
-       virtual void OnSyncUser(User* user, Module* proto, void* opaque);
+       virtual void OnSyncUser(User* user, ProtocolServer& server);
 
        /** Allows modules to synchronize data which relates to channels during a netburst.
         * When this function is called, it will be called from the module which implements
-        * the linking protocol. This currently is m_spanningtree.so. A pointer to this module
-        * is given in Module* proto, so that you may call its methods such as ProtoSendMode
-        * (see below). This function will be called for every user visible on your side
-        * of the burst, allowing you to for example set modes, etc.
+        * the linking protocol. This currently is m_spanningtree.so.
+        * This function will be called for every channel visible on your side of the burst,
+        * allowing you to for example set modes, etc.
         *
         * @param chan The channel being syncronized
-        * @param proto A pointer to the module handling network protocol
-        * @param opaque An opaque pointer set by the protocol module, should not be modified!
+        * @param server The target of the burst
         */
-       virtual void OnSyncChannel(Channel* chan, Module* proto, void* opaque);
+       virtual void OnSyncChannel(Channel* chan, ProtocolServer& server);
 
-       /* Allows modules to syncronize metadata not related to users or channels, over the network during a netburst.
-        * Whenever the linking module wants to send out data, but doesnt know what the data
-        * represents (e.g. it is Extensible metadata, added to a User or Channel by a module) then
-        * this method is called. You should use the ProtoSendMetaData function after you've
-        * correctly decided how the data should be represented, to send the metadata on its way if
-        * if it belongs to your module.
-        * @param proto A pointer to the module handling network protocol
-        * @param opaque An opaque pointer set by the protocol module, should not be modified!
-        * @param displayable If this value is true, the data is going to be displayed to a user,
-        * and not sent across the network. Use this to determine wether or not to show sensitive data.
+       /** Allows modules to syncronize metadata not related to users or channels, over the network during a netburst.
+        * When the linking module has finished sending all data it wanted to send during a netburst, then
+        * this method is called. You should use the SendMetaData() function after you've
+        * correctly decided how the data should be represented, to send the data.
+        * @param server The target of the burst
         */
-       virtual void OnSyncNetwork(Module* proto, void* opaque);
+       virtual void OnSyncNetwork(ProtocolServer& server);
 
        /** Allows module data, sent via ProtoSendMetaData, to be decoded again by a receiving module.
         * Please see src/modules/m_swhois.cpp for a working example of how to use this method call.
@@ -669,21 +658,6 @@ class CoreExport Module : public classbase, public usecountbase
         */
        virtual void OnDecodeMetaData(Extensible* target, const std::string &extname, const std::string &extdata);
 
-       /** Implemented by modules which provide the ability to link servers.
-        * These modules will implement this method, which allows metadata (extra data added to
-        * user and channel records using class Extensible, Extensible::Extend, etc) to be sent
-        * to other servers on a netburst and decoded at the other end by the same module on a
-        * different server.
-        *
-        * More documentation to follow soon. Please see src/modules/m_swhois.cpp for example of
-        * how to use this function.
-        * @param opaque An opaque pointer set by the protocol module, should not be modified!
-        * @param target The Channel* or User* that metadata should be sent for
-        * @param extname The extension name to send metadata for
-        * @param extdata Encoded data for this extension name, which will be encoded at the oppsite end by an identical module using OnDecodeMetaData
-        */
-       virtual void ProtoSendMetaData(void* opaque, Extensible* target, const std::string &extname, const std::string &extdata);
-
        /** Called whenever a user's hostname is changed.
         * This event triggers after the host has been set.
         * @param user The user whos host is being changed
index bffc4a5e91edc24c073bb0924f7ca977e0dbaa52..b077a4f4766190f04c74d890eb891fe650b924c2 100644 (file)
@@ -26,9 +26,21 @@ class User;
 
 typedef std::vector<std::string> parameterlist;
 
+class ProtocolServer
+{
+ public:
+       /** Send metadata related to this server to the target server
+        * @param key The 'key' of the data
+        * @param data The string representation of the data
+        */
+       virtual void SendMetaData(const std::string& key, const std::string& data) = 0;
+};
+
 class CoreExport ProtocolInterface
 {
  public:
+       typedef ProtocolServer Server;
+
        class ServerInfo
        {
         public:
index 98ea4a0b922b12ce755fb4626ee0c6d23cef07d9..37e6daaf0b27aef3a35a2cb77ad51127eeec7614 100644 (file)
@@ -36,6 +36,7 @@ class LocalUser;
 class Membership;
 class Module;
 class OperInfo;
+class ProtocolServer;
 class RemoteUser;
 class ServerConfig;
 class ServerLimits;
index 388a579050281169c6d9deae313aab9a2d28ad26..487bc4ea0cca85d6cae87b12beacf3f9cdd64a4a 100644 (file)
@@ -134,11 +134,10 @@ void              Module::OnUserMessage(User*, void*, int, const std::string&, char, const C
 void           Module::OnUserInvite(User*, User*, Channel*, time_t) { DetachEvent(I_OnUserInvite); }
 void           Module::OnPostTopicChange(User*, Channel*, const std::string&) { DetachEvent(I_OnPostTopicChange); }
 void           Module::OnGetServerDescription(const std::string&, std::string&) { DetachEvent(I_OnGetServerDescription); }
-void           Module::OnSyncUser(User*, Module*, void*) { DetachEvent(I_OnSyncUser); }
-void           Module::OnSyncChannel(Channel*, Module*, void*) { DetachEvent(I_OnSyncChannel); }
-void           Module::OnSyncNetwork(Module*, void*) { DetachEvent(I_OnSyncNetwork); }
+void           Module::OnSyncUser(User*, ProtocolInterface::Server&) { DetachEvent(I_OnSyncUser); }
+void           Module::OnSyncChannel(Channel*, ProtocolInterface::Server&) { DetachEvent(I_OnSyncChannel); }
+void           Module::OnSyncNetwork(ProtocolInterface::Server&) { DetachEvent(I_OnSyncNetwork); }
 void           Module::OnDecodeMetaData(Extensible*, const std::string&, const std::string&) { DetachEvent(I_OnDecodeMetaData); }
-void           Module::ProtoSendMetaData(void*, Extensible*, const std::string&, const std::string&) { }
 void           Module::OnChangeHost(User*, const std::string&) { DetachEvent(I_OnChangeHost); }
 void           Module::OnChangeName(User*, const std::string&) { DetachEvent(I_OnChangeName); }
 void           Module::OnChangeIdent(User*, const std::string&) { DetachEvent(I_OnChangeIdent); }
index 5198cac1843b51704181895d72d75b0757335bdf..c0ed4d9cbff2289f0227685dea2d4e2b9aca52ae 100644 (file)
@@ -186,7 +186,7 @@ class ModuleFilter : public Module
        Version GetVersion() CXX11_OVERRIDE;
        std::string EncodeFilter(FilterResult* filter);
        FilterResult DecodeFilter(const std::string &data);
-       void OnSyncNetwork(Module* proto, void* opaque) CXX11_OVERRIDE;
+       void OnSyncNetwork(ProtocolInterface::Server& server) CXX11_OVERRIDE;
        void OnDecodeMetaData(Extensible* target, const std::string &extname, const std::string &extdata) CXX11_OVERRIDE;
        ModResult OnStats(char symbol, User* user, string_list &results) CXX11_OVERRIDE;
        ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line) CXX11_OVERRIDE;
@@ -532,11 +532,11 @@ FilterResult ModuleFilter::DecodeFilter(const std::string &data)
        return res;
 }
 
-void ModuleFilter::OnSyncNetwork(Module* proto, void* opaque)
+void ModuleFilter::OnSyncNetwork(ProtocolInterface::Server& server)
 {
        for (std::vector<ImplFilter>::iterator i = filters.begin(); i != filters.end(); ++i)
        {
-               proto->ProtoSendMetaData(opaque, NULL, "filter", EncodeFilter(&(*i)));
+               server.SendMetaData("filter", EncodeFilter(&(*i)));
        }
 }
 
index f92c09b888d678242fdebf9b64a95dbdaa9acfb4..b3cc78118037d35ca730b8d35ad81cad653e9aee 100644 (file)
@@ -718,19 +718,6 @@ ModResult ModuleSpanningTree::OnSetAway(User* user, const std::string &awaymsg)
        return MOD_RES_PASSTHRU;
 }
 
-void ModuleSpanningTree::ProtoSendMetaData(void* opaque, Extensible* target, const std::string &extname, const std::string &extdata)
-{
-       TreeSocket* s = static_cast<TreeSocket*>(opaque);
-       User* u = dynamic_cast<User*>(target);
-       Channel* c = dynamic_cast<Channel*>(target);
-       if (u)
-               s->WriteLine(":"+ServerInstance->Config->GetSID()+" METADATA "+u->uuid+" "+extname+" :"+extdata);
-       else if (c)
-               s->WriteLine(":"+ServerInstance->Config->GetSID()+" METADATA "+c->name+" "+ConvToStr(c->age)+" "+extname+" :"+extdata);
-       else if (!target)
-               s->WriteLine(":"+ServerInstance->Config->GetSID()+" METADATA * "+extname+" :"+extdata);
-}
-
 CullResult ModuleSpanningTree::cull()
 {
        if (Utils)
index 737b7d5762d9e14f835b8b15452302478b4f295d..c275207bfdf3ccc073d16e0d8d7a68d8da8535f0 100644 (file)
@@ -158,7 +158,6 @@ class ModuleSpanningTree : public Module
        void OnDelLine(User *u, XLine *x) CXX11_OVERRIDE;
        ModResult OnStats(char statschar, User* user, string_list &results) CXX11_OVERRIDE;
        ModResult OnSetAway(User* user, const std::string &awaymsg) CXX11_OVERRIDE;
-       void ProtoSendMetaData(void* opaque, Extensible* target, const std::string &extname, const std::string &extdata);
        void OnLoadModule(Module* mod) CXX11_OVERRIDE;
        void OnUnloadModule(Module* mod) CXX11_OVERRIDE;
        ModResult OnAcceptConnection(int newsock, ListenSocket* from, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server) CXX11_OVERRIDE;
index 9ca5b04d402579e9de52174537a6c9b3732c4330..0464590e885dfa503e1eb07afc9b136b01edd013 100644 (file)
@@ -27,6 +27,7 @@
 #include "treeserver.h"
 #include "main.h"
 #include "commands.h"
+#include "protocolinterface.h"
 
 /**
  * Creates FMODE messages, used only when syncing channels
@@ -89,6 +90,12 @@ class FModeBuilder : public CmdBuilder
        }
 };
 
+struct TreeSocket::BurstState
+{
+       SpanningTreeProtocolInterface::Server server;
+       BurstState(TreeSocket* sock) : server(sock) { }
+};
+
 /** This function is called when we want to send a netburst to a local
  * server. There is a set order we must do this, because for example
  * users require their servers to exist, and channels require their
@@ -106,14 +113,16 @@ void TreeSocket::DoBurst(TreeServer* s)
        this->WriteLine(":" + ServerInstance->Config->GetSID() + " VERSION :"+ServerInstance->GetVersionString());
        /* Send server tree */
        this->SendServers(Utils->TreeRoot, s);
+
+       BurstState bs(this);
        /* Send users and their oper status */
-       this->SendUsers();
+       this->SendUsers(bs);
 
        for (chan_hash::const_iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); ++i)
-               SyncChannel(i->second);
+               SyncChannel(i->second, bs);
 
        this->SendXLines();
-       FOREACH_MOD(OnSyncNetwork, (Utils->Creator,(void*)this));
+       FOREACH_MOD(OnSyncNetwork, (bs.server));
        this->WriteLine(":" + ServerInstance->Config->GetSID() + " ENDBURST");
        ServerInstance->SNO->WriteToSnoMask('l',"Finished bursting to \2"+ s->GetName()+"\2.");
 }
@@ -229,7 +238,7 @@ void TreeSocket::SendListModes(Channel* chan)
 }
 
 /** Send channel topic, modes and metadata */
-void TreeSocket::SyncChannel(Channel* chan)
+void TreeSocket::SyncChannel(Channel* chan, BurstState& bs)
 {
        SendFJoins(chan);
 
@@ -245,15 +254,22 @@ void TreeSocket::SyncChannel(Channel* chan)
                ExtensionItem* item = i->first;
                std::string value = item->serialize(FORMAT_NETWORK, chan, i->second);
                if (!value.empty())
-                       Utils->Creator->ProtoSendMetaData(this, chan, item->name, value);
+                       this->WriteLine(CommandMetadata::Builder(chan, item->name, value));
        }
 
-       FOREACH_MOD(OnSyncChannel, (chan, Utils->Creator, this));
+       FOREACH_MOD(OnSyncChannel, (chan, bs.server));
+}
+
+void TreeSocket::SyncChannel(Channel* chan)
+{
+       BurstState bs(this);
+       SyncChannel(chan, bs);
 }
 
 /** send all users and their oper state/modes */
-void TreeSocket::SendUsers()
+void TreeSocket::SendUsers(BurstState& bs)
 {
+       ProtocolInterface::Server& piserver = bs.server;
        for (user_hash::iterator u = ServerInstance->Users->clientlist->begin(); u != ServerInstance->Users->clientlist->end(); u++)
        {
                User* user = u->second;
@@ -274,10 +290,10 @@ void TreeSocket::SendUsers()
                        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->name, value);
+                               this->WriteLine(CommandMetadata::Builder(user, item->name, value));
                }
 
-               FOREACH_MOD(OnSyncUser, (user, Utils->Creator, this));
+               FOREACH_MOD(OnSyncUser, (user, piserver));
        }
 }
 
index cc015ff4a81de3242e11e63d5f2b70eda91c80f7..a6c826c7bf0c763cdc4006206099c01658e789d6 100644 (file)
@@ -71,6 +71,11 @@ void SpanningTreeProtocolInterface::SendMetaData(const std::string& key, const s
        CommandMetadata::Builder(key, data).Broadcast();
 }
 
+void SpanningTreeProtocolInterface::Server::SendMetaData(const std::string& key, const std::string& data)
+{
+       sock->WriteLine(CommandMetadata::Builder(key, data));
+}
+
 void SpanningTreeProtocolInterface::SendTopic(Channel* channel, std::string &topic)
 {
        CommandFTopic::Builder(ServerInstance->FakeClient, channel).Broadcast();
index 4ba7a54d4eec6a6a26848169cfdfba7bcc6c7b46..8b9eeb6a869f6b4fa870d65798bff36ebcf302ef 100644 (file)
 class SpanningTreeProtocolInterface : public ProtocolInterface
 {
  public:
+       class Server : public ProtocolInterface::Server
+       {
+               TreeSocket* const sock;
+
+        public:
+               Server(TreeSocket* s) : sock(s) { }
+               void SendMetaData(const std::string& key, const std::string& data) CXX11_OVERRIDE;
+       };
+
        bool SendEncapsulatedData(const parameterlist &encap);
        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;
index 8c87c4df6dab1960de949aef43fcd06f8fe68dc4..097f60fbb95a0c9ca93fedfaa9280a834a52be24 100644 (file)
@@ -89,6 +89,8 @@ struct CapabData
  */
 class TreeSocket : public BufferedSocket
 {
+       class BurstState;
+
        std::string linkID;                     /* Description for this link */
        ServerState LinkState;                  /* Link state */
        CapabData* capab;                       /* Link setup data (held until burst is sent) */
@@ -106,6 +108,12 @@ class TreeSocket : public BufferedSocket
         */
        void SendListModes(Channel* chan);
 
+       /** Send all known information about a channel */
+       void SyncChannel(Channel* chan, BurstState& bs);
+
+       /** Send all users and their oper state, away state and metadata */
+       void SendUsers(BurstState& bs);
+
  public:
        const time_t age;
 
@@ -224,9 +232,6 @@ class TreeSocket : public BufferedSocket
        /** Send all known information about a channel */
        void SyncChannel(Channel* chan);
 
-       /** send all users and their oper state/modes */
-       void SendUsers();
-
        /** This function is called when we want to send a netburst to a local
         * server. There is a set order we must do this, because for example
         * users require their servers to exist, and channels require their