]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Add stuff so that modules can hook users by altering a pointer in the User class...
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Mon, 24 Mar 2008 15:13:17 +0000 (15:13 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Mon, 24 Mar 2008 15:13:17 +0000 (15:13 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@9187 e03df62e-2008-0410-955e-edbf42e46eb7

include/modules.h
include/users.h
src/cull_list.cpp
src/modules.cpp
src/modules/extra/m_ssl_gnutls.cpp
src/modules/extra/m_ssl_openssl.cpp
src/socket.cpp
src/usermanager.cpp
src/userprocess.cpp
src/users.cpp

index 693fd41fb38a9b5fa2c00d849635e76575246f9a..de0e0d7feb8fe2298313d18925901a66ce8b3232 100644 (file)
@@ -401,7 +401,7 @@ enum Implementation
        I_OnRawSocketAccept, I_OnRawSocketClose, I_OnRawSocketWrite, I_OnRawSocketRead, I_OnChangeLocalUserGECOS, I_OnUserRegister,
        I_OnChannelPreDelete, I_OnChannelDelete, I_OnPostOper, I_OnSyncOtherMetaData, I_OnSetAway, I_OnCancelAway, I_OnUserList,
        I_OnPostCommand, I_OnPostJoin, I_OnWhoisLine, I_OnBuildExemptList, I_OnRawSocketConnect, I_OnGarbageCollect, I_OnBufferFlushed,
-       I_OnText, I_OnReadConfig, I_OnDownloadFile, I_OnPassCompare, I_OnRunTestSuite, I_OnNamesListItem, I_OnNumeric,
+       I_OnText, I_OnReadConfig, I_OnDownloadFile, I_OnPassCompare, I_OnRunTestSuite, I_OnNamesListItem, I_OnNumeric, I_OnHookUserIO,
        I_END
 };
 
@@ -1245,6 +1245,8 @@ class CoreExport Module : public Extensible
         */
        virtual int OnDelBan(User* source, Channel* channel,const std::string &banmask);
 
+       virtual void OnHookUserIO(User* user);
+
        /** Called immediately after any  connection is accepted. This is intended for raw socket
         * processing (e.g. modules which wrap the tcp connection within another library) and provides
         * no information relating to a user record as the connection has not been assigned yet.
index 07843b7c09a34560b693af905a5fd18e34fc675f..74b55202d5db4375a67119711245e07923bb1b94 100644 (file)
@@ -464,6 +464,10 @@ class CoreExport User : public connection
        bool* AllowedChanModes;
 
  public:
+       /** Module responsible for raw i/o
+        */
+       Module* io;
+
        /** Contains a pointer to the connect class a user is on from - this will be NULL for remote connections.
         * The pointer is guarenteed to *always* be valid. :)
         */
index 224591b6f82f5610f19439745781b41d47f4e722..f7f163298cb81680efa5258dc845f9f07f52cd1e 100644 (file)
@@ -80,11 +80,11 @@ int CullList::Apply()
 
                if (IS_LOCAL(u))
                {
-                       if (ServerInstance->Config->GetIOHook(u->GetPort()))
+                       if (u->io)
                        {
                                try
                                {
-                                       ServerInstance->Config->GetIOHook(u->GetPort())->OnRawSocketClose(u->GetFd());
+                                       u->io->OnRawSocketClose(u->GetFd());
                                }
                                catch (CoreException& modexcept)
                                {
index 6a870361bb17002e1177357754ca62c6ab8cd235..82dbea185e16c4968f19aa7aa67ceab425b684f7 100644 (file)
@@ -195,6 +195,7 @@ void                Module::OnText(User*, void*, int, const std::string&, char, CUList&) { }
 void           Module::OnRunTestSuite() { }
 void           Module::OnNamesListItem(User*, User*, Channel*, std::string&, std::string&) { }
 int            Module::OnNumeric(User*, unsigned int, const std::string&) { return 0; }
+void           Module::OnHookUserIO(User*) { }
 
 ModuleManager::ModuleManager(InspIRCd* Ins) : ModCount(0), Instance(Ins)
 {
index 78d9c785a4691e528692e3c110ed79eaa476140a..f3af386aea579689b0cc5f730c8dcaf393906beb 100644 (file)
@@ -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;
index 610565002002dafc4e49e9c8cab0c7ac442e8826..ba32c40134e96452a95c55e748ca4eb35a6887dc 100644 (file)
@@ -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 &param)
@@ -320,6 +329,8 @@ class ModuleSSLOpenSSL : public Module
                                delete tofree;
                                user->Shrink("ssl_cert");
                        }
+
+                       user->io = NULL;
                }
        }
 
index e045df1f99610a38db7b6df0f3af34d94a25033b..2089fffbdf2ba041aedf286314f5c328061c43c6 100644 (file)
@@ -116,17 +116,6 @@ void ListenSocket::HandleEvent(EventType, int)
 
                ServerInstance->SE->NonBlocking(incomingSockfd);
 
-               if (ServerInstance->Config->GetIOHook(in_port))
-               {
-                       try
-                       {
-                               ServerInstance->Config->GetIOHook(in_port)->OnRawSocketAccept(incomingSockfd, buf, in_port);
-                       }
-                       catch (CoreException& modexcept)
-                       {
-                               ServerInstance->Logs->Log("SOCKET", DEBUG,"%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
-                       }
-               }
                ServerInstance->stats->statsAccept++;
                ServerInstance->Users->AddClient(ServerInstance, incomingSockfd, in_port, false, this->family, client);
        }
index 6145c887b5595a731b48f191ef009da2ee042e44..b518685faf6b2f19165b858cdb5956e9394997b5 100644 (file)
@@ -35,19 +35,35 @@ void UserManager::AddClient(InspIRCd* Instance, int socket, int port, bool iscac
                return;
        }
 
-       Instance->Logs->Log("USERS", DEBUG,"New user fd: %d", socket);
-
-       int j = 0;
-
-       this->unregistered_count++;
-
        char ipaddr[MAXBUF];
 #ifdef IPV6
        if (socketfamily == AF_INET6)
                inet_ntop(AF_INET6, &((const sockaddr_in6*)ip)->sin6_addr, ipaddr, sizeof(ipaddr));
        else
 #endif
-       inet_ntop(AF_INET, &((const sockaddr_in*)ip)->sin_addr, ipaddr, sizeof(ipaddr));
+               inet_ntop(AF_INET, &((const sockaddr_in*)ip)->sin_addr, ipaddr, sizeof(ipaddr));
+
+
+       /* Give each of the modules an attempt to hook the user for I/O */
+       FOREACH_MOD_I(Instance, I_OnHookUserIO, OnHookUserIO(New));
+
+       if (New->io)
+       {
+               try
+               {
+                       New->io->OnRawSocketAccept(socket, ipaddr, port);
+               }
+               catch (CoreException& modexcept)
+               {
+                       ServerInstance->Logs->Log("SOCKET", DEBUG,"%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
+               }
+       }
+
+       Instance->Logs->Log("USERS", DEBUG,"New user fd: %d", socket);
+
+       int j = 0;
+
+       this->unregistered_count++;
 
        (*(this->clientlist))[New->uuid] = New;
 
index 62cd452cd182aee2e67e743897d3a8b7f7b115bc..c2de4dc2b1d895cab85720d657945f9d50aa7223 100644 (file)
@@ -46,14 +46,14 @@ void ProcessUserHandler::Call(User* cu)
 
        char* ReadBuffer = Server->GetReadBuffer();
 
-       if (Server->Config->GetIOHook(cu->GetPort()))
+       if (cu->io)
        {
                int result2 = 0;
                int MOD_RESULT = 0;
 
                try
                {
-                       MOD_RESULT = Server->Config->GetIOHook(cu->GetPort())->OnRawSocketRead(cu->GetFd(),ReadBuffer,Server->Config->NetBufferSize,result2);
+                       MOD_RESULT = cu->io->OnRawSocketRead(cu->GetFd(),ReadBuffer,Server->Config->NetBufferSize,result2);
                }
                catch (CoreException& modexcept)
                {
index 46665396f0300297613ac61fc3e95b5f8fd009cf..f8a95af49a195197042218fb16176f955030c39d 100644 (file)
@@ -193,6 +193,7 @@ User::User(InspIRCd* Instance, const std::string &uid) : ServerInstance(Instance
        Visibility = NULL;
        ip = NULL;
        MyClass = NULL;
+       io = NULL;
        AllowedUserModes = NULL;
        AllowedChanModes = NULL;
        AllowedOperCommands = NULL;
@@ -1165,14 +1166,14 @@ void User::Write(std::string text)
                return;
        }
 
-       if (ServerInstance->Config->GetIOHook(this->GetPort()))
+       if (this->io)
        {
                /* XXX: The lack of buffering here is NOT a bug, modules implementing this interface have to
                 * implement their own buffering mechanisms
                 */
                try
                {
-                       ServerInstance->Config->GetIOHook(this->GetPort())->OnRawSocketWrite(this->fd, text.data(), text.length());
+                       this->io->OnRawSocketWrite(this->fd, text.data(), text.length());
                }
                catch (CoreException& modexcept)
                {