From ca0889d458ab768f32f399c0afe5f4e36dcd07d9 Mon Sep 17 00:00:00 2001 From: brain Date: Sun, 18 Dec 2005 20:48:54 +0000 Subject: Added IOHookModule stuff to allow for different modules to hook different ports git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2564 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/command_parse.cpp | 1 - src/helperfuncs.cpp | 17 ++++++++--------- src/inspircd.cpp | 5 ++--- src/inspircd_io.cpp | 26 ++++++++++++++++++++++++++ src/modules.cpp | 2 -- src/modules/m_spanningtree.cpp | 2 +- src/userprocess.cpp | 6 ++---- src/users.cpp | 9 ++++----- 8 files changed, 43 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/command_parse.cpp b/src/command_parse.cpp index 02414039d..6f927e89a 100644 --- a/src/command_parse.cpp +++ b/src/command_parse.cpp @@ -68,7 +68,6 @@ extern std::vector module_sockets; extern std::vector local_users; extern int MODCOUNT; -extern Module* IOHookModule; extern InspSocket* socket_ref[65535]; extern time_t TIME; diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index e1ade25c9..037a7a3af 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -61,7 +61,6 @@ static char already_sent[65536]; extern std::vector all_opers; extern user_hash clientlist; extern chan_hash chanlist; -extern Module* IOHookModule; void log(int level,char *text, ...) { @@ -140,9 +139,9 @@ void Write(int sock,char *text, ...) chop(tb); if (fd_ref_table[sock]) { - if (IOHookModule) + if (Config->GetIOHook(fd_ref_table[sock]->port)) { - IOHookModule->OnRawSocketWrite(sock,tb,bytes); + Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes); } else { @@ -173,9 +172,9 @@ void WriteServ(int sock, char* text, ...) chop(tb); if (fd_ref_table[sock]) { - if (IOHookModule) + if (Config->GetIOHook(fd_ref_table[sock]->port)) { - IOHookModule->OnRawSocketWrite(sock,tb,bytes); + Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes); } else { @@ -206,9 +205,9 @@ void WriteFrom(int sock, userrec *user,char* text, ...) chop(tb); if (fd_ref_table[sock]) { - if (IOHookModule) + if (Config->GetIOHook(fd_ref_table[sock]->port)) { - IOHookModule->OnRawSocketWrite(sock,tb,bytes); + Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes); } else { @@ -1065,9 +1064,9 @@ void ShowMOTD(userrec *user) snprintf(mbuf,MAXBUF,":%s 376 %s :End of message of the day.\r\n", Config->ServerName, user->nick); WholeMOTD = WholeMOTD + mbuf; // only one write operation - if (IOHookModule) + if (Config->GetIOHook(user->port)) { - IOHookModule->OnRawSocketWrite(user->fd,(char*)WholeMOTD.c_str(),WholeMOTD.length()); + Config->GetIOHook(user->port)->OnRawSocketWrite(user->fd,(char*)WholeMOTD.c_str(),WholeMOTD.length()); } else { diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 4055f2a38..c370c7f84 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -74,7 +74,6 @@ extern int MODCOUNT; int openSockfd[MAXSOCKS]; sockaddr_in client,server; socklen_t length; -extern Module* IOHookModule; extern InspSocket* socket_ref[65535]; @@ -528,9 +527,9 @@ int InspIRCd::Run() */ if (incomingSockfd >= 0) { - if (IOHookModule) + if (Config->GetIOHook(in_port)) { - IOHookModule->OnRawSocketAccept(incomingSockfd, target, in_port); + Config->GetIOHook(in_port)->OnRawSocketAccept(incomingSockfd, target, in_port); } stats->statsAccept++; AddClient(incomingSockfd, target, in_port, false, target); diff --git a/src/inspircd_io.cpp b/src/inspircd_io.cpp index b1e90bfd0..aa6c8e33a 100644 --- a/src/inspircd_io.cpp +++ b/src/inspircd_io.cpp @@ -63,6 +63,32 @@ void ServerConfig::ClearStack() include_stack.clear(); } +Module* ServerConfig::GetIOHook(int port) +{ + std::map::iterator x = IOHookModule.find(port); + return (x != IOHookModule.end() ? x->second : NULL); +} + +bool ServerConfig::AddIOHook(int port, Module* iomod) +{ + if (!GetIOHook(port)) + { + IOHookModule[port] = iomod; + return true; + } + return false; +} + +bool ServerConfig::DelIOHook(int port) +{ + std::map::iterator x = IOHookModule.find(port); + if (x != IOHookModule.end()) + { + IOHookModule.erase(x); + return true; + } + return false; +} void ServerConfig::Read(bool bail, userrec* user) { diff --git a/src/modules.cpp b/src/modules.cpp index 71f8f672e..e39821a62 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -66,8 +66,6 @@ extern chan_hash chanlist; extern command_table cmdlist; ExtModeList EMode; -Module* IOHookModule = NULL; - // returns true if an extended mode character is in use bool ModeDefined(char modechar, int type) { diff --git a/src/modules/m_spanningtree.cpp b/src/modules/m_spanningtree.cpp index 0f10b2de0..33c481391 100644 --- a/src/modules/m_spanningtree.cpp +++ b/src/modules/m_spanningtree.cpp @@ -2140,7 +2140,7 @@ void ReadConfiguration(bool rebind) L.AutoConnect = Conf->ReadInteger("link","autoconnect",j,true); L.NextConnectTime = time(NULL) + L.AutoConnect; /* Bugfix by brain, do not allow people to enter bad configurations */ - if ((recvpass != "") && (sendpass != "") && (Name != "") && (Port)) + if ((L.RecvPass != "") && (L.SendPass != "") && (L.Name != "") && (L.Port)) { LinkBlocks.push_back(L); log(DEBUG,"m_spanningtree: Read server %s with host %s:%d",L.Name.c_str(),L.IPAddr.c_str(),L.Port); diff --git a/src/userprocess.cpp b/src/userprocess.cpp index a73eb7d25..31cb6b68e 100644 --- a/src/userprocess.cpp +++ b/src/userprocess.cpp @@ -77,17 +77,15 @@ char data[65536]; extern user_hash clientlist; extern chan_hash chanlist; -extern Module* IOHookModule; - void ProcessUser(userrec* cu) { int result = EAGAIN; log(DEBUG,"Processing user with fd %d",cu->fd); - if (IOHookModule) + if (Config->GetIOHook(cu->port)) { int MOD_RESULT = 0; int result2 = 0; - IOHookModule->OnRawSocketRead(cu->fd,data,65535,result2); + Config->GetIOHook(cu->port)->OnRawSocketRead(cu->fd,data,65535,result2); if (!MOD_RESULT) { result = cu->ReadData(data, 65535); diff --git a/src/users.cpp b/src/users.cpp index 18ec1c318..6388b456b 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -49,7 +49,6 @@ extern userrec* fd_ref_table[65536]; extern ServerConfig *Config; extern user_hash clientlist; extern whowas_hash whowas; -extern Module* IOHookModule; std::vector local_users; std::vector all_opers; @@ -375,9 +374,9 @@ void kill_link(userrec *user,const char* r) if (user->fd > -1) { - if (IOHookModule) + if (Config->GetIOHook(user->port)) { - IOHookModule->OnRawSocketClose(user->fd); + Config->GetIOHook(user->port)->OnRawSocketClose(user->fd); } ServerInstance->SE->DelFd(user->fd); user->CloseSocket(); @@ -438,9 +437,9 @@ void kill_link_silent(userrec *user,const char* r) if (user->fd > -1) { - if (IOHookModule) + if (Config->GetIOHook(user->port)) { - IOHookModule->OnRawSocketClose(user->fd); + Config->GetIOHook(user->port)->OnRawSocketClose(user->fd); } ServerInstance->SE->DelFd(user->fd); user->CloseSocket(); -- cgit v1.2.3