summaryrefslogtreecommitdiff
path: root/src/modules
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
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')
-rw-r--r--src/modules/extra/m_ssl_gnutls.cpp12
-rw-r--r--src/modules/extra/m_ssl_openssl.cpp12
-rw-r--r--src/modules/m_httpd.cpp111
-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
9 files changed, 52 insertions, 173 deletions
diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp
index 29e439ed3..25b47c2fe 100644
--- a/src/modules/extra/m_ssl_gnutls.cpp
+++ b/src/modules/extra/m_ssl_gnutls.cpp
@@ -173,14 +173,14 @@ class ModuleSSLGnuTLS : public Module
for (size_t i = 0; i < ServerInstance->ports.size(); i++)
{
- ListenSocketBase* port = ServerInstance->ports[i];
- if (port->hook != "gnutls")
+ ListenSocket* port = ServerInstance->ports[i];
+ if (port->bind_tag->getString("ssl") != "gnutls")
continue;
- const std::string& portid = port->GetBindDesc();
+ const std::string& portid = port->bind_desc;
ServerInstance->Logs->Log("m_ssl_gnutls", DEFAULT, "m_ssl_gnutls.so: Enabling SSL for port %s", portid.c_str());
- if (port->type == "clients" && port->GetIP() != "127.0.0.1")
+ if (port->bind_tag->getString("type", "clients") == "clients" && port->bind_addr != "127.0.0.1")
sslports.append(portid).append(";");
}
@@ -321,9 +321,9 @@ class ModuleSSLGnuTLS : public Module
output.append(" STARTTLS");
}
- void OnHookIO(StreamSocket* user, ListenSocketBase* lsb)
+ void OnHookIO(StreamSocket* user, ListenSocket* lsb)
{
- if (!user->GetIOHook() && lsb->hook == "gnutls")
+ if (!user->GetIOHook() && lsb->bind_tag->getString("ssl") == "gnutls")
{
/* Hook the user with our module */
user->AddIOHook(this);
diff --git a/src/modules/extra/m_ssl_openssl.cpp b/src/modules/extra/m_ssl_openssl.cpp
index 0c01e4d08..25d1cd9dd 100644
--- a/src/modules/extra/m_ssl_openssl.cpp
+++ b/src/modules/extra/m_ssl_openssl.cpp
@@ -131,9 +131,9 @@ class ModuleSSLOpenSSL : public Module
ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
}
- void OnHookIO(StreamSocket* user, ListenSocketBase* lsb)
+ void OnHookIO(StreamSocket* user, ListenSocket* lsb)
{
- if (!user->GetIOHook() && lsb->hook == "openssl")
+ if (!user->GetIOHook() && lsb->bind_tag->getString("ssl") == "openssl")
{
/* Hook the user with our module */
user->AddIOHook(this);
@@ -148,13 +148,13 @@ class ModuleSSLOpenSSL : public Module
for (size_t i = 0; i < ServerInstance->ports.size(); i++)
{
- ListenSocketBase* port = ServerInstance->ports[i];
- if (port->hook != "openssl")
+ ListenSocket* port = ServerInstance->ports[i];
+ if (port->bind_tag->getString("ssl") != "openssl")
continue;
- std::string portid = port->GetBindDesc();
+ std::string portid = port->bind_desc;
ServerInstance->Logs->Log("m_ssl_openssl", DEFAULT, "m_ssl_openssl.so: Enabling SSL for port %s", portid.c_str());
- if (port->type == "clients" && port->GetIP() != "127.0.0.1")
+ if (port->bind_tag->getString("type", "clients") == "clients" && port->bind_addr != "127.0.0.1")
sslports.append(portid).append(";");
}
diff --git a/src/modules/m_httpd.cpp b/src/modules/m_httpd.cpp
index 76e89666a..7fc342e04 100644
--- a/src/modules/m_httpd.cpp
+++ b/src/modules/m_httpd.cpp
@@ -35,7 +35,6 @@ enum HttpState
*/
class HttpServerSocket : public BufferedSocket
{
- FileReader* index;
HttpState InternalState;
std::string ip;
@@ -49,15 +48,14 @@ class HttpServerSocket : public BufferedSocket
public:
- HttpServerSocket(int newfd, const char* IP, FileReader* ind)
- : BufferedSocket(newfd), index(ind), ip(IP), postsize(0)
+ HttpServerSocket(int newfd, const std::string& IP, ListenSocket* via, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server)
+ : BufferedSocket(newfd), ip(IP), postsize(0)
{
InternalState = HTTP_SERVE_WAIT_REQUEST;
- }
- FileReader* GetIndex()
- {
- return index;
+ FOREACH_MOD(I_OnHookIO, OnHookIO(this, via));
+ if (GetIOHook())
+ GetIOHook()->OnStreamSocketAccept(this, client, server);
}
virtual void OnError(BufferedSocketError)
@@ -300,25 +298,16 @@ class HttpServerSocket : public BufferedSocket
{
InternalState = HTTP_SERVE_SEND_DATA;
- if ((request_type == "GET") && (uri == "/"))
- {
- HTTPHeaders empty;
- SendHeaders(index->ContentSize(), 200, empty);
- WriteData(index->Contents());
- }
- else
+ claimed = false;
+ HTTPRequest acl((Module*)HttpModule, "httpd_acl", request_type, uri, &headers, this, ip, postdata);
+ acl.Send();
+ if (!claimed)
{
- claimed = false;
- HTTPRequest acl((Module*)HttpModule, "httpd_acl", request_type, uri, &headers, this, ip, postdata);
- acl.Send();
+ HTTPRequest url((Module*)HttpModule, "httpd_url", request_type, uri, &headers, this, ip, postdata);
+ url.Send();
if (!claimed)
{
- HTTPRequest url((Module*)HttpModule, "httpd_url", request_type, uri, &headers, this, ip, postdata);
- url.Send();
- if (!claimed)
- {
- SendHTTPError(404);
- }
+ SendHTTPError(404);
}
}
}
@@ -330,71 +319,12 @@ class HttpServerSocket : public BufferedSocket
}
};
-/** Spawn HTTP sockets from a listener
- */
-class HttpListener : public ListenSocketBase
-{
- FileReader* index;
-
- public:
- HttpListener(FileReader *idx, int port, const std::string &addr)
- : ListenSocketBase(port, addr, "httpd", "plaintext")
- {
- this->index = idx;
- }
-
- ~HttpListener()
- {
- delete index;
- }
-
- virtual void OnAcceptReady(int nfd)
- {
- int port;
- std::string incomingip;
- irc::sockets::satoap(&client, incomingip, port);
- new HttpServerSocket(nfd, incomingip.c_str(), index);
- }
-};
-
class ModuleHttpServer : public Module
{
std::vector<HttpServerSocket *> httpsocks;
- std::vector<HttpListener *> httplisteners;
public:
- void ReadConfig()
- {
- int port;
- std::string host;
- std::string bindip;
- std::string indexfile;
- FileReader* index;
- HttpListener *http;
- ConfigReader c;
-
- httpsocks.clear(); // XXX this will BREAK if this module is made rehashable
- httplisteners.clear();
-
- for (int i = 0; i < c.Enumerate("http"); i++)
- {
- host = c.ReadValue("http", "host", i);
- bindip = c.ReadValue("http", "ip", i);
- port = c.ReadInteger("http", "port", i, true);
- indexfile = c.ReadValue("http", "index", i);
- index = new FileReader(indexfile);
- if (!index->Exists())
- {
- delete index;
- throw ModuleException("Can't read index file: "+indexfile);
- }
- http = new HttpListener(index, port, bindip);
- httplisteners.push_back(http);
- }
- }
-
ModuleHttpServer() {
- ReadConfig();
HttpModule = this;
}
@@ -407,15 +337,20 @@ class ModuleHttpServer : public Module
resp.src.sock->Page(resp.document, resp.responsecode, &resp.headers);
}
+ ModResult OnAcceptConnection(int nfd, ListenSocket* from, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server)
+ {
+ if (from->bind_tag->getString("type") != "httpd");
+ return MOD_RES_PASSTHRU;
+ int port;
+ std::string incomingip;
+ irc::sockets::satoap(client, incomingip, port);
+ new HttpServerSocket(nfd, incomingip, from, client, server);
+ return MOD_RES_ALLOW;
+ }
+
virtual ~ModuleHttpServer()
{
- for (size_t i = 0; i < httplisteners.size(); i++)
- {
- httplisteners[i]->cull();
- delete httplisteners[i];
- }
-
for (size_t i = 0; i < httpsocks.size(); i++)
{
httpsocks[i]->cull();
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
*/