summaryrefslogtreecommitdiff
path: root/src/modules/m_spanningtree
diff options
context:
space:
mode:
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-10-21 23:46:33 +0000
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-10-21 23:46:33 +0000
commitd221de88276b9e33a108281a9cd0a58875032fc6 (patch)
tree3032609bd5ef7f4a6a4bad5c0b2a4100432ea2df /src/modules/m_spanningtree
parentdcbb0ae938711cd49df73dc2ff6cd6289aeefb44 (diff)
Kill ListenSocketBase, use OnAcceptConnection for all new connections
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11950 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules/m_spanningtree')
-rw-r--r--src/modules/m_spanningtree/main.cpp6
-rw-r--r--src/modules/m_spanningtree/main.h1
-rw-r--r--src/modules/m_spanningtree/treesocket.h2
-rw-r--r--src/modules/m_spanningtree/treesocket1.cpp2
-rw-r--r--src/modules/m_spanningtree/utils.cpp61
-rw-r--r--src/modules/m_spanningtree/utils.h18
6 files changed, 17 insertions, 73 deletions
diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp
index a0acd9b08..624049357 100644
--- a/src/modules/m_spanningtree/main.cpp
+++ b/src/modules/m_spanningtree/main.cpp
@@ -49,7 +49,7 @@ ModuleSpanningTree::ModuleSpanningTree()
I_OnChangeHost, I_OnChangeName, I_OnChangeIdent, I_OnUserPart, I_OnUnloadModule,
I_OnUserQuit, I_OnUserPostNick, I_OnUserKick, I_OnRemoteKill, I_OnRehash, I_OnPreRehash,
I_OnOper, I_OnAddLine, I_OnDelLine, I_OnMode, I_OnLoadModule, I_OnStats,
- I_OnSetAway, I_OnPostCommand, I_OnUserConnect
+ I_OnSetAway, I_OnPostCommand, I_OnUserConnect, I_OnAcceptConnection
};
ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
@@ -768,7 +768,7 @@ void ModuleSpanningTree::OnPreRehash(User* user, const std::string &parameter)
void ModuleSpanningTree::OnRehash(User* user)
{
// Re-read config stuff
- Utils->ReadConfiguration(true);
+ Utils->ReadConfiguration();
}
void ModuleSpanningTree::OnLoadModule(Module* mod)
@@ -795,7 +795,7 @@ void ModuleSpanningTree::RedoConfig(Module* mod)
if (mod->ModuleSourceFile == "m_sha256.so" || IsBufferSocketModule)
{
- Utils->ReadConfiguration(true);
+ Utils->ReadConfiguration();
}
}
diff --git a/src/modules/m_spanningtree/main.h b/src/modules/m_spanningtree/main.h
index b9d5debb3..02513fb2e 100644
--- a/src/modules/m_spanningtree/main.h
+++ b/src/modules/m_spanningtree/main.h
@@ -190,6 +190,7 @@ class ModuleSpanningTree : public Module
void ProtoSendMetaData(void* opaque, Extensible* target, const std::string &extname, const std::string &extdata);
void OnLoadModule(Module* mod);
void OnUnloadModule(Module* mod);
+ ModResult OnAcceptConnection(int newsock, ListenSocket* from, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server);
CullResult cull();
~ModuleSpanningTree();
Version GetVersion();
diff --git a/src/modules/m_spanningtree/treesocket.h b/src/modules/m_spanningtree/treesocket.h
index b5f97c30f..8359ebf37 100644
--- a/src/modules/m_spanningtree/treesocket.h
+++ b/src/modules/m_spanningtree/treesocket.h
@@ -103,7 +103,7 @@ class TreeSocket : public BufferedSocket
* we must associate it with a socket without creating a new
* connection. This constructor is used for this purpose.
*/
- TreeSocket(SpanningTreeUtilities* Util, int newfd, ListenSocketBase* via, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server);
+ TreeSocket(SpanningTreeUtilities* Util, int newfd, ListenSocket* via, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server);
/** Get link state
*/
diff --git a/src/modules/m_spanningtree/treesocket1.cpp b/src/modules/m_spanningtree/treesocket1.cpp
index 4a0af45b8..962b63984 100644
--- a/src/modules/m_spanningtree/treesocket1.cpp
+++ b/src/modules/m_spanningtree/treesocket1.cpp
@@ -69,7 +69,7 @@ found:
* we must associate it with a socket without creating a new
* connection. This constructor is used for this purpose.
*/
-TreeSocket::TreeSocket(SpanningTreeUtilities* Util, int newfd, ListenSocketBase* via, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server)
+TreeSocket::TreeSocket(SpanningTreeUtilities* Util, int newfd, ListenSocket* via, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server)
: BufferedSocket(newfd), Utils(Util)
{
int dummy;
diff --git a/src/modules/m_spanningtree/utils.cpp b/src/modules/m_spanningtree/utils.cpp
index 10a888833..11c96bf7c 100644
--- a/src/modules/m_spanningtree/utils.cpp
+++ b/src/modules/m_spanningtree/utils.cpp
@@ -24,12 +24,15 @@
#include "resolvers.h"
/* Create server sockets off a listener. */
-void ServerSocketListener::OnAcceptReady(int newsock)
+ModResult ModuleSpanningTree::OnAcceptConnection(int newsock, ListenSocket* from, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server)
{
+ if (from->bind_tag->getString("type") != "servers")
+ return MOD_RES_PASSTHRU;
+
bool found = false;
int port;
std::string incomingip;
- irc::sockets::satoap(&client, incomingip, port);
+ irc::sockets::satoap(client, incomingip, port);
found = (std::find(Utils->ValidIPs.begin(), Utils->ValidIPs.end(), incomingip) != Utils->ValidIPs.end());
if (!found)
@@ -46,14 +49,14 @@ void ServerSocketListener::OnAcceptReady(int newsock)
if (!found)
{
ServerInstance->SNO->WriteToSnoMask('l', "Server connection from %s denied (no link blocks with that IP address)", incomingip.c_str());
- ServerInstance->SE->Close(newsock);
- return;
+ return MOD_RES_DENY;
}
}
/* we don't need to do anything with the pointer, creating it stores it in the necessary places */
- new TreeSocket(Utils, newsock, this, &client, &server);
+ new TreeSocket(Utils, newsock, from, client, server);
+ return MOD_RES_ALLOW;
}
/** Yay for fast searches!
@@ -146,17 +149,11 @@ SpanningTreeUtilities::SpanningTreeUtilities(ModuleSpanningTree* C) : Creator(C)
this->TreeRoot = new TreeServer(this, ServerInstance->Config->ServerName, ServerInstance->Config->ServerDesc, ServerInstance->Config->GetSID());
ServerUser = new FakeUser(TreeRoot->GetID());
- this->ReadConfiguration(true);
+ this->ReadConfiguration();
}
CullResult SpanningTreeUtilities::cull()
{
- for (unsigned int i = 0; i < ServerInstance->ports.size(); i++)
- {
- if (ServerInstance->ports[i]->type == "servers")
- ServerInstance->ports[i]->cull();
- }
-
while (TreeRoot->ChildCount())
{
TreeServer* child_server = TreeRoot->GetChild(0);
@@ -176,12 +173,6 @@ CullResult SpanningTreeUtilities::cull()
SpanningTreeUtilities::~SpanningTreeUtilities()
{
- for (unsigned int i = 0; i < ServerInstance->ports.size(); i++)
- {
- if (ServerInstance->ports[i]->type == "servers")
- delete ServerInstance->ports[i];
- }
-
delete TreeRoot;
}
@@ -362,42 +353,10 @@ void SpanningTreeUtilities::RefreshIPCache()
}
}
-void SpanningTreeUtilities::ReadConfiguration(bool rebind)
+void SpanningTreeUtilities::ReadConfiguration()
{
ConfigReader Conf;
- if (rebind)
- {
- ConfigTagList tags = ServerInstance->Config->ConfTags("bind");
- for(ConfigIter i = tags.first; i != tags.second; ++i)
- {
- ConfigTag* tag = i->second;
- std::string Type = tag->getString("type");
- std::string IP = tag->getString("address");
- std::string Port = tag->getString("port");
- std::string ssl = tag->getString("ssl");
- if (Type == "servers")
- {
- irc::portparser portrange(Port, false);
- int portno = -1;
-
- if (IP == "*")
- IP.clear();
-
- while ((portno = portrange.GetToken()))
- {
- ServerSocketListener *listener = new ServerSocketListener(this, portno, IP, ssl);
- if (listener->GetFd() == -1)
- {
- delete listener;
- continue;
- }
-
- ServerInstance->ports.push_back(listener);
- }
- }
- }
- }
FlatLinks = Conf.ReadFlag("security","flatlinks",0);
HideULines = Conf.ReadFlag("security","hideulines",0);
AnnounceTSChange = Conf.ReadFlag("options","announcets",0);
diff --git a/src/modules/m_spanningtree/utils.h b/src/modules/m_spanningtree/utils.h
index 2fc7304af..507cb3c7d 100644
--- a/src/modules/m_spanningtree/utils.h
+++ b/src/modules/m_spanningtree/utils.h
@@ -37,22 +37,6 @@ class SpanningTreeUtilities;
#endif
#endif
-/*
- * Initialises server connections
- */
-class ServerSocketListener : public ListenSocketBase
-{
- SpanningTreeUtilities *Utils;
-
- public:
- ServerSocketListener(SpanningTreeUtilities *u, int port, const std::string& addr, const std::string& Hook)
- : ListenSocketBase(port, addr, "servers", Hook), Utils(u)
- {
- }
-
- virtual void OnAcceptReady(int nfd);
-};
-
typedef std::map<TreeServer*,TreeServer*> TreeServerList;
/** Contains helper functions and variables for this module,
@@ -167,7 +151,7 @@ class SpanningTreeUtilities : public classbase
/** Read the spanningtree module's tags from the config file
*/
- void ReadConfiguration(bool rebind);
+ void ReadConfiguration();
/** Add a server to the server list for GetListOfServersForChannel
*/