summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/modules.h58
-rw-r--r--include/protocol.h12
-rw-r--r--include/typedefs.h1
-rw-r--r--src/modules.cpp7
-rw-r--r--src/modules/m_filter.cpp6
-rw-r--r--src/modules/m_spanningtree/main.cpp13
-rw-r--r--src/modules/m_spanningtree/main.h1
-rw-r--r--src/modules/m_spanningtree/netburst.cpp34
-rw-r--r--src/modules/m_spanningtree/protocolinterface.cpp5
-rw-r--r--src/modules/m_spanningtree/protocolinterface.h9
-rw-r--r--src/modules/m_spanningtree/treesocket.h11
11 files changed, 82 insertions, 75 deletions
diff --git a/include/modules.h b/include/modules.h
index e04ee01ff..931d85032 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -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
diff --git a/include/protocol.h b/include/protocol.h
index bffc4a5e9..b077a4f47 100644
--- a/include/protocol.h
+++ b/include/protocol.h
@@ -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:
diff --git a/include/typedefs.h b/include/typedefs.h
index 98ea4a0b9..37e6daaf0 100644
--- a/include/typedefs.h
+++ b/include/typedefs.h
@@ -36,6 +36,7 @@ class LocalUser;
class Membership;
class Module;
class OperInfo;
+class ProtocolServer;
class RemoteUser;
class ServerConfig;
class ServerLimits;
diff --git a/src/modules.cpp b/src/modules.cpp
index 388a57905..487bc4ea0 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -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); }
diff --git a/src/modules/m_filter.cpp b/src/modules/m_filter.cpp
index 5198cac18..c0ed4d9cb 100644
--- a/src/modules/m_filter.cpp
+++ b/src/modules/m_filter.cpp
@@ -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)));
}
}
diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp
index f92c09b88..b3cc78118 100644
--- a/src/modules/m_spanningtree/main.cpp
+++ b/src/modules/m_spanningtree/main.cpp
@@ -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)
diff --git a/src/modules/m_spanningtree/main.h b/src/modules/m_spanningtree/main.h
index 737b7d576..c275207bf 100644
--- a/src/modules/m_spanningtree/main.h
+++ b/src/modules/m_spanningtree/main.h
@@ -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;
diff --git a/src/modules/m_spanningtree/netburst.cpp b/src/modules/m_spanningtree/netburst.cpp
index 9ca5b04d4..0464590e8 100644
--- a/src/modules/m_spanningtree/netburst.cpp
+++ b/src/modules/m_spanningtree/netburst.cpp
@@ -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));
}
}
diff --git a/src/modules/m_spanningtree/protocolinterface.cpp b/src/modules/m_spanningtree/protocolinterface.cpp
index cc015ff4a..a6c826c7b 100644
--- a/src/modules/m_spanningtree/protocolinterface.cpp
+++ b/src/modules/m_spanningtree/protocolinterface.cpp
@@ -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();
diff --git a/src/modules/m_spanningtree/protocolinterface.h b/src/modules/m_spanningtree/protocolinterface.h
index 4ba7a54d4..8b9eeb6a8 100644
--- a/src/modules/m_spanningtree/protocolinterface.h
+++ b/src/modules/m_spanningtree/protocolinterface.h
@@ -22,6 +22,15 @@
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;
diff --git a/src/modules/m_spanningtree/treesocket.h b/src/modules/m_spanningtree/treesocket.h
index 8c87c4df6..097f60fbb 100644
--- a/src/modules/m_spanningtree/treesocket.h
+++ b/src/modules/m_spanningtree/treesocket.h
@@ -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