]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_httpd.cpp
Fix a bunch more conflicting/unnamed numerics.
[user/henk/code/inspircd.git] / src / modules / m_httpd.cpp
index e09ca3fa2c03c604f644736e7c839065ff08be00..17f25203d884c87dbfba2a11d09cf865ca61c7b6 100644 (file)
@@ -76,10 +76,18 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru
                , postsize(0)
                , waitingcull(false)
        {
-               ServerInstance->Timers.AddTimer(this);
+               if ((!via->iohookprovs.empty()) && (via->iohookprovs.back()))
+               {
+                       via->iohookprovs.back()->OnAccept(this, client, server);
+                       // IOHook may have errored
+                       if (!getError().empty())
+                       {
+                               AddToCull();
+                               return;
+                       }
+               }
 
-               if (via->iohookprov)
-                       via->iohookprov->OnAccept(this, client, server);
+               ServerInstance->Timers.AddTimer(this);
        }
 
        ~HttpServerSocket()
@@ -92,7 +100,7 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru
                AddToCull();
        }
 
-       std::string Response(int response)
+       std::string Response(unsigned int response)
        {
                switch (response)
                {
@@ -183,7 +191,7 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru
                }
        }
 
-       void SendHTTPError(int response)
+       void SendHTTPError(unsigned int response)
        {
                HTTPHeaders empty;
                std::string data = "<html><head></head><body>Server error "+ConvToStr(response)+": "+Response(response)+"<br>"+
@@ -193,7 +201,7 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru
                WriteData(data);
        }
 
-       void SendHeaders(unsigned long size, int response, HTTPHeaders &rheaders)
+       void SendHeaders(unsigned long size, unsigned int response, HTTPHeaders &rheaders)
        {
 
                WriteData(http_version + " "+ConvToStr(response)+" "+Response(response)+"\r\n");
@@ -216,7 +224,7 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru
                WriteData("\r\n");
        }
 
-       void OnDataReady()
+       void OnDataReady() CXX11_OVERRIDE
        {
                if (InternalState == HTTP_SERVE_RECV_POSTDATA)
                {
@@ -337,7 +345,7 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru
                }
        }
 
-       void Page(std::stringstream* n, int response, HTTPHeaders *hheaders)
+       void Page(std::stringstream* n, unsigned int response, HTTPHeaders *hheaders)
        {
                SendHeaders(n->str().length(), response, *hheaders);
                WriteData(n->str());
@@ -393,20 +401,32 @@ class ModuleHttpServer : public Module
        void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
        {
                ConfigTag* tag = ServerInstance->Config->ConfValue("httpd");
-               timeoutsec = tag->getInt("timeout", 10, 1);
+               timeoutsec = tag->getDuration("timeout", 10, 1);
        }
 
        ModResult OnAcceptConnection(int nfd, ListenSocket* from, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server) CXX11_OVERRIDE
        {
-               if (from->bind_tag->getString("type") != "httpd")
+               if (!stdalgo::string::equalsci(from->bind_tag->getString("type"), "httpd"))
                        return MOD_RES_PASSTHRU;
-               int port;
-               std::string incomingip;
-               irc::sockets::satoap(*client, incomingip, port);
-               sockets.push_front(new HttpServerSocket(nfd, incomingip, from, client, server, timeoutsec));
+
+               sockets.push_front(new HttpServerSocket(nfd, client->addr(), from, client, server, timeoutsec));
                return MOD_RES_ALLOW;
        }
 
+       void OnUnloadModule(Module* mod) CXX11_OVERRIDE
+       {
+               for (insp::intrusive_list<HttpServerSocket>::const_iterator i = sockets.begin(); i != sockets.end(); )
+               {
+                       HttpServerSocket* sock = *i;
+                       ++i;
+                       if (sock->GetModHook(mod))
+                       {
+                               sock->cull();
+                               delete sock;
+                       }
+               }
+       }
+
        CullResult cull() CXX11_OVERRIDE
        {
                for (insp::intrusive_list<HttpServerSocket>::const_iterator i = sockets.begin(); i != sockets.end(); ++i)