]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Keep multiple IOHookProvider references in class ListenSocket
authorAttila Molnar <attilamolnar@hush.com>
Mon, 8 Aug 2016 13:10:43 +0000 (15:10 +0200)
committerAttila Molnar <attilamolnar@hush.com>
Mon, 8 Aug 2016 13:10:43 +0000 (15:10 +0200)
This adds the <bind:hook> config option which works together with <bind:ssl>

include/socket.h
src/listensocket.cpp
src/modules/m_httpd.cpp
src/modules/m_spanningtree/treesocket1.cpp
src/usermanager.cpp

index 52294fe719eb329018375ed4bfbd1f054cf4b077..427ee9fe7e3f7823aad489f5b253ba81523a9149 100644 (file)
@@ -141,10 +141,21 @@ class CoreExport ListenSocket : public EventHandler
        /** Human-readable bind description */
        std::string bind_desc;
 
-       /** The IOHook provider which handles connections on this socket,
-        * NULL if there is none.
+       class IOHookProvRef : public dynamic_reference_nocheck<IOHookProvider>
+       {
+        public:
+               IOHookProvRef()
+                       : dynamic_reference_nocheck<IOHookProvider>(NULL, std::string())
+               {
+               }
+       };
+
+       typedef TR1NS::array<IOHookProvRef, 2> IOHookProvList;
+
+       /** IOHook providers for handling connections on this socket,
+        * may be empty.
         */
-       dynamic_reference_nocheck<IOHookProvider> iohookprov;
+       IOHookProvList iohookprovs;
 
        /** Create a new listening socket
         */
index f560ad277e0e378853571f6f03483e9191c2f7e2..fb9f2a0eff6e313ef01caced913462fa1033d6e1 100644 (file)
@@ -19,6 +19,7 @@
 
 
 #include "inspircd.h"
+#include "iohook.h"
 
 #ifndef _WIN32
 #include <netinet/tcp.h>
@@ -26,7 +27,6 @@
 
 ListenSocket::ListenSocket(ConfigTag* tag, const irc::sockets::sockaddrs& bind_to)
        : bind_tag(tag)
-       , iohookprov(NULL, std::string())
 {
        irc::sockets::satoap(bind_to, bind_addr, bind_port);
        bind_desc = bind_to.str();
@@ -180,10 +180,21 @@ void ListenSocket::OnEventHandlerRead()
 
 void ListenSocket::ResetIOHookProvider()
 {
+       iohookprovs[0].SetProvider(bind_tag->getString("hook"));
+
+       // Check that all non-last hooks support being in the middle
+       for (IOHookProvList::iterator i = iohookprovs.begin(); i != iohookprovs.end()-1; ++i)
+       {
+               IOHookProvRef& curr = *i;
+               // Ignore if cannot be in the middle
+               if ((curr) && (!curr->IsMiddle()))
+                       curr.SetProvider(std::string());
+       }
+
        std::string provname = bind_tag->getString("ssl");
        if (!provname.empty())
                provname.insert(0, "ssl/");
 
-       // Set the new provider name, dynref handles the rest
-       iohookprov.SetProvider(provname);
+       // SSL should be the last
+       iohookprovs.back().SetProvider(provname);
 }
index 0b6b2e32b7dcd1c261cb8aa926c4b79b7fbfd2f0..64bef70d11ad3959a4323f0a1efedf5de2ab07d9 100644 (file)
@@ -78,8 +78,8 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru
        {
                ServerInstance->Timers.AddTimer(this);
 
-               if (via->iohookprov)
-                       via->iohookprov->OnAccept(this, client, server);
+               if ((!via->iohookprovs.empty()) && (via->iohookprovs.back()))
+                       via->iohookprovs.back()->OnAccept(this, client, server);
        }
 
        ~HttpServerSocket()
index 2198d6208c1f6927f2e386eae57dd25543047710..e1642a086041bb54bb9b0eb9d1e62c8287f40864 100644 (file)
@@ -60,8 +60,13 @@ TreeSocket::TreeSocket(int newfd, ListenSocket* via, irc::sockets::sockaddrs* cl
        capab = new CapabData;
        capab->capab_phase = 0;
 
-       if (via->iohookprov)
-               via->iohookprov->OnAccept(this, client, server);
+       for (ListenSocket::IOHookProvList::iterator i = via->iohookprovs.begin(); i != via->iohookprovs.end(); ++i)
+       {
+               ListenSocket::IOHookProvRef& iohookprovref = *i;
+               if (iohookprovref)
+                       iohookprovref->OnAccept(this, client, server);
+       }
+
        SendCapabilities(1);
 
        Utils->timeoutlist[this] = std::pair<std::string, int>(linkID, 30);
index fe052fcfc90f517c477772e8849f8aa15b8acb37..95deca00a9a356f01a301bc9b135f485d2084a83 100644 (file)
@@ -72,8 +72,12 @@ void UserManager::AddUser(int socket, ListenSocket* via, irc::sockets::sockaddrs
        UserIOHandler* eh = &New->eh;
 
        // If this listener has an IO hook provider set then tell it about the connection
-       if (via->iohookprov)
-               via->iohookprov->OnAccept(eh, client, server);
+       for (ListenSocket::IOHookProvList::iterator i = via->iohookprovs.begin(); i != via->iohookprovs.end(); ++i)
+       {
+               ListenSocket::IOHookProvRef& iohookprovref = *i;
+               if (iohookprovref)
+                       iohookprovref->OnAccept(eh, client, server);
+       }
 
        ServerInstance->Logs->Log("USERS", LOG_DEBUG, "New user fd: %d", socket);