From 343f12b9b2d4e519b09877f76a00f6a0714509f2 Mon Sep 17 00:00:00 2001 From: brain Date: Mon, 24 Mar 2008 15:13:17 +0000 Subject: Add stuff so that modules can hook users by altering a pointer in the User class. Note that ssl modules still bind by port, but the idea of doing this change is so we can remove that logic next git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@9187 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules/extra/m_ssl_gnutls.cpp | 27 ++++++++++++++++----------- src/modules/extra/m_ssl_openssl.cpp | 15 +++++++++++++-- 2 files changed, 29 insertions(+), 13 deletions(-) (limited to 'src/modules') diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp index 78d9c785a..f3af386ae 100644 --- a/src/modules/extra/m_ssl_gnutls.cpp +++ b/src/modules/extra/m_ssl_gnutls.cpp @@ -78,15 +78,9 @@ class CommandStartTLS : public Command if (!user->GetExt("tls")) return CMD_FAILURE; - for (size_t i = 0; i < ServerInstance->Config->ports.size(); i++) - { - if (ServerInstance->Config->ports[i]->GetDescription() == "ssl") - { - Caller->OnRawSocketAccept(user->GetFd(), user->GetIPString(), ServerInstance->Config->ports[i]->GetPort()); - user->SetSockAddr(user->GetProtocolFamily(), user->GetIPString(), ServerInstance->Config->ports[i]->GetPort()); - break; - } - } + user->io = Caller; + Caller->OnRawSocketAccept(user->GetFd(), user->GetIPString(), ServerInstance->Config->ports[i]->GetPort()); + return CMD_FAILURE; } }; @@ -142,8 +136,8 @@ class ModuleSSLGnuTLS : public Module // Void return, guess we assume success gnutls_certificate_set_dh_params(x509_cred, dh_params); Implementation eventlist[] = { I_On005Numeric, I_OnRawSocketConnect, I_OnRawSocketAccept, I_OnRawSocketClose, I_OnRawSocketRead, I_OnRawSocketWrite, I_OnCleanup, - I_OnBufferFlushed, I_OnRequest, I_OnSyncUserMetaData, I_OnDecodeMetaData, I_OnUnloadModule, I_OnRehash, I_OnWhois, I_OnPostConnect, I_OnEvent }; - ServerInstance->Modules->Attach(eventlist, this, 16); + I_OnBufferFlushed, I_OnRequest, I_OnSyncUserMetaData, I_OnDecodeMetaData, I_OnUnloadModule, I_OnRehash, I_OnWhois, I_OnPostConnect, I_OnEvent, I_OnHookUserIO }; + ServerInstance->Modules->Attach(eventlist, this, 17); starttls = new CommandStartTLS(ServerInstance, this); ServerInstance->AddCommand(starttls); @@ -303,6 +297,8 @@ class ModuleSSLGnuTLS : public Module delete tofree; user->Shrink("ssl_cert"); } + + user->io = NULL; } } @@ -331,6 +327,15 @@ class ModuleSSLGnuTLS : public Module output.append(" SSL=" + sslports); } + virtual void OnHookUserIO(User* user) + { + if (!user->io && isin(user->GetPort(), listenports)) + { + /* Hook the user with our module */ + user->io = this; + } + } + virtual const char* OnRequest(Request* request) { ISHRequest* ISR = (ISHRequest*)request; diff --git a/src/modules/extra/m_ssl_openssl.cpp b/src/modules/extra/m_ssl_openssl.cpp index 610565002..ba32c4013 100644 --- a/src/modules/extra/m_ssl_openssl.cpp +++ b/src/modules/extra/m_ssl_openssl.cpp @@ -150,8 +150,17 @@ class ModuleSSLOpenSSL : public Module // Needs the flag as it ignores a plain /rehash OnRehash(NULL,"ssl"); Implementation eventlist[] = { I_OnRawSocketConnect, I_OnRawSocketAccept, I_OnRawSocketClose, I_OnRawSocketRead, I_OnRawSocketWrite, I_OnCleanup, I_On005Numeric, - I_OnBufferFlushed, I_OnRequest, I_OnSyncUserMetaData, I_OnDecodeMetaData, I_OnUnloadModule, I_OnRehash, I_OnWhois, I_OnPostConnect }; - ServerInstance->Modules->Attach(eventlist, this, 15); + I_OnBufferFlushed, I_OnRequest, I_OnSyncUserMetaData, I_OnDecodeMetaData, I_OnUnloadModule, I_OnRehash, I_OnWhois, I_OnPostConnect, I_OnHookUserIO }; + ServerInstance->Modules->Attach(eventlist, this, 16); + } + + virtual void OnHookUserIO(User* user) + { + if (!user->io && isin(user->GetPort(), listenports)) + { + /* Hook the user with our module */ + user->io = this; + } } virtual void OnRehash(User* user, const std::string ¶m) @@ -320,6 +329,8 @@ class ModuleSSLOpenSSL : public Module delete tofree; user->Shrink("ssl_cert"); } + + user->io = NULL; } } -- cgit v1.2.3