summaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/inspsocket.cpp1
-rw-r--r--src/listensocket.cpp52
-rw-r--r--src/modules.cpp3
-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
-rw-r--r--src/socket.cpp64
-rw-r--r--src/stats.cpp6
-rw-r--r--src/usermanager.cpp2
15 files changed, 116 insertions, 237 deletions
diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp
index fc8bc142f..a37cb9ea0 100644
--- a/src/inspsocket.cpp
+++ b/src/inspsocket.cpp
@@ -395,6 +395,7 @@ void StreamSocket::DoWrite()
else if (errno == EINTR)
{
// restart interrupted syscall
+ errno = 0;
}
else
{
diff --git a/src/listensocket.cpp b/src/listensocket.cpp
index e0a18a043..8b7053d8f 100644
--- a/src/listensocket.cpp
+++ b/src/listensocket.cpp
@@ -17,30 +17,21 @@
#include "socket.h"
#include "socketengine.h"
-/* Private static member data must be declared in this manner */
-irc::sockets::sockaddrs ListenSocketBase::client;
-irc::sockets::sockaddrs ListenSocketBase::server;
-
-ListenSocketBase::ListenSocketBase(int port, const std::string &addr, const std::string &Type, const std::string &Hook)
- : type(Type), hook(Hook), bind_port(port)
+ListenSocket::ListenSocket(ConfigTag* tag, const std::string& addr, int port)
+ : bind_tag(tag)
{
irc::sockets::sockaddrs bind_to;
// canonicalize address if it is defined
if (!irc::sockets::aptosa(addr, port, &bind_to))
{
- // malformed address
- bind_addr = addr;
- bind_desc = addr + ":" + ConvToStr(port);
- this->fd = -1;
+ fd = -1;
+ return;
}
- else
- {
- irc::sockets::satoap(&bind_to, bind_addr, port);
- bind_desc = irc::sockets::satouser(&bind_to);
+ irc::sockets::satoap(&bind_to, bind_addr, bind_port);
+ bind_desc = irc::sockets::satouser(&bind_to);
- this->fd = irc::sockets::OpenTCPSocket(bind_addr);
- }
+ fd = irc::sockets::OpenTCPSocket(bind_addr);
if (this->fd > -1)
{
@@ -62,7 +53,7 @@ ListenSocketBase::ListenSocketBase(int port, const std::string &addr, const std:
}
}
-ListenSocketBase::~ListenSocketBase()
+ListenSocket::~ListenSocket()
{
if (this->GetFd() > -1)
{
@@ -75,8 +66,11 @@ ListenSocketBase::~ListenSocketBase()
}
/* Just seperated into another func for tidiness really.. */
-void ListenSocketBase::AcceptInternal()
+void ListenSocket::AcceptInternal()
{
+ irc::sockets::sockaddrs client;
+ irc::sockets::sockaddrs server;
+
ServerInstance->Logs->Log("SOCKET",DEBUG,"HandleEvent for Listensoket");
int incomingSockfd;
@@ -148,10 +142,23 @@ void ListenSocketBase::AcceptInternal()
ServerInstance->SE->NonBlocking(incomingSockfd);
ServerInstance->stats->statsAccept++;
- this->OnAcceptReady(incomingSockfd);
+
+ ModResult res;
+ FIRST_MOD_RESULT(OnAcceptConnection, res, (incomingSockfd, this, &client, &server));
+ if (res == MOD_RES_PASSTHRU)
+ {
+ std::string type = bind_tag->getString("type", "clients");
+ if (type == "clients")
+ {
+ ServerInstance->Users->AddUser(incomingSockfd, this, &client, &server);
+ res = MOD_RES_ALLOW;
+ }
+ }
+ if (res != MOD_RES_ALLOW)
+ ServerInstance->SE->Close(incomingSockfd);
}
-void ListenSocketBase::HandleEvent(EventType e, int err)
+void ListenSocket::HandleEvent(EventType e, int err)
{
switch (e)
{
@@ -166,8 +173,3 @@ void ListenSocketBase::HandleEvent(EventType e, int err)
break;
}
}
-
-void ClientListenSocket::OnAcceptReady(int nfd)
-{
- ServerInstance->Users->AddUser(nfd, this, &client, &server);
-}
diff --git a/src/modules.cpp b/src/modules.cpp
index f70c45bf2..a1c53a1e8 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -149,7 +149,8 @@ void Module::OnText(User*, void*, int, const std::string&, char, CUList&) { }
void Module::OnRunTestSuite() { }
void Module::OnNamesListItem(User*, Membership*, std::string&, std::string&) { }
ModResult Module::OnNumeric(User*, unsigned int, const std::string&) { return MOD_RES_PASSTHRU; }
-void Module::OnHookIO(StreamSocket*, ListenSocketBase*) { }
+void Module::OnHookIO(StreamSocket*, ListenSocket*) { }
+ModResult Module::OnAcceptConnection(int, ListenSocket*, irc::sockets::sockaddrs*, irc::sockets::sockaddrs*) { return MOD_RES_PASSTHRU; }
void Module::OnSendWhoLine(User*, User*, Channel*, std::string&) { }
ModResult Module::OnChannelRestrictionApply(User*, Channel*, const char*) { return MOD_RES_PASSTHRU; }
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
*/
diff --git a/src/socket.cpp b/src/socket.cpp
index 1666e3e8b..167d90b4f 100644
--- a/src/socket.cpp
+++ b/src/socket.cpp
@@ -102,11 +102,10 @@ int irc::sockets::OpenTCPSocket(const std::string& addr, int socktype)
}
}
-// XXX: it would be VERY nice to genericize this so all listen stuff (server/client) could use the one function. -- w00t
int InspIRCd::BindPorts(FailedPortList &failed_ports)
{
int bound = 0;
- std::vector<ListenSocketBase*> old_ports(ports.begin(), ports.end());
+ std::vector<ListenSocket*> old_ports(ports.begin(), ports.end());
ConfigTagList tags = ServerInstance->Config->ConfTags("bind");
for(ConfigIter i = tags.first; i != tags.second; ++i)
@@ -114,52 +113,47 @@ int InspIRCd::BindPorts(FailedPortList &failed_ports)
ConfigTag* tag = i->second;
std::string porttag = tag->getString("port");
std::string Addr = tag->getString("address");
- std::string Type = tag->getString("type");
- std::string Desc = tag->getString("ssl");
if (strncmp(Addr.c_str(), "::ffff:", 7) == 0)
this->Logs->Log("SOCKET",DEFAULT, "Using 4in6 (::ffff:) isn't recommended. You should bind IPv4 addresses directly instead.");
- if (Type.empty() || Type == "clients")
+ irc::portparser portrange(porttag, false);
+ int portno = -1;
+ while (0 != (portno = portrange.GetToken()))
{
- irc::portparser portrange(porttag, false);
- int portno = -1;
- while (0 != (portno = portrange.GetToken()))
- {
- irc::sockets::sockaddrs bindspec;
- irc::sockets::aptosa(Addr, portno, &bindspec);
- std::string bind_readable = irc::sockets::satouser(&bindspec);
+ irc::sockets::sockaddrs bindspec;
+ irc::sockets::aptosa(Addr, portno, &bindspec);
+ std::string bind_readable = irc::sockets::satouser(&bindspec);
- bool skip = false;
- for (std::vector<ListenSocketBase *>::iterator n = old_ports.begin(); n != old_ports.end(); ++n)
+ bool skip = false;
+ for (std::vector<ListenSocket*>::iterator n = old_ports.begin(); n != old_ports.end(); ++n)
+ {
+ if ((**n).bind_desc == bind_readable)
+ {
+ skip = true;
+ old_ports.erase(n);
+ break;
+ }
+ }
+ if (!skip)
+ {
+ ListenSocket *ll = new ListenSocket(tag, Addr, portno);
+ if (ll->GetFd() > -1)
{
- if ((*n)->GetBindDesc() == bind_readable)
- {
- skip = true;
- old_ports.erase(n);
- break;
- }
+ bound++;
+ ports.push_back(ll);
}
- if (!skip)
+ else
{
- ClientListenSocket *ll = new ClientListenSocket(portno, Addr, "clients", Desc.empty() ? "plaintext" : Desc);
- if (ll->GetFd() > -1)
- {
- bound++;
- ports.push_back(ll);
- }
- else
- {
- failed_ports.push_back(std::make_pair(bind_readable, strerror(errno)));
- delete ll;
- }
+ failed_ports.push_back(std::make_pair(bind_readable, strerror(errno)));
+ delete ll;
}
}
}
}
- std::vector<ListenSocketBase *>::iterator n = ports.begin();
- for (std::vector<ListenSocketBase *>::iterator o = old_ports.begin(); o != old_ports.end(); ++o)
+ std::vector<ListenSocket*>::iterator n = ports.begin();
+ for (std::vector<ListenSocket*>::iterator o = old_ports.begin(); o != old_ports.end(); ++o)
{
while (n != ports.end() && *n != *o)
n++;
@@ -170,7 +164,7 @@ int InspIRCd::BindPorts(FailedPortList &failed_ports)
}
this->Logs->Log("SOCKET",DEFAULT, "Port binding %s was removed from the config file, closing.",
- (*n)->GetBindDesc().c_str());
+ (**n).bind_desc.c_str());
delete *n;
// this keeps the iterator valid, pointing to the next element
diff --git a/src/stats.cpp b/src/stats.cpp
index a469600af..decdfe36e 100644
--- a/src/stats.cpp
+++ b/src/stats.cpp
@@ -46,12 +46,14 @@ void InspIRCd::DoStats(char statschar, User* user, string_list &results)
{
for (size_t i = 0; i < this->ports.size(); i++)
{
- std::string ip = this->ports[i]->GetIP();
+ std::string ip = this->ports[i]->bind_addr;
if (ip.empty())
ip.assign("*");
+ std::string type = ports[i]->bind_tag->getString("type", "clients");
+ std::string hook = ports[i]->bind_tag->getString("ssl", "plaintext");
results.push_back(sn+" 249 "+user->nick+" :"+ ip + ":"+ConvToStr(ports[i]->bind_port)+
- " (" + ports[i]->type + ", " + ports[i]->hook + ")");
+ " (" + type + ", " + hook + ")");
}
}
break;
diff --git a/src/usermanager.cpp b/src/usermanager.cpp
index 2d824c6b2..bc058a462 100644
--- a/src/usermanager.cpp
+++ b/src/usermanager.cpp
@@ -18,7 +18,7 @@
#include "bancache.h"
/* add a client connection to the sockets list */
-void UserManager::AddUser(int socket, ClientListenSocket* via, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server)
+void UserManager::AddUser(int socket, ListenSocket* via, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server)
{
/* NOTE: Calling this one parameter constructor for User automatically
* allocates a new UUID and places it in the hash_map.