]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_httpd.cpp
Make the build reproducible by removing time related macros.
[user/henk/code/inspircd.git] / src / modules / m_httpd.cpp
index 0dd028924882a13a7ac1ec63eb31262489e44490..35ae9abe5cecd8b7ba010e86a5e53e9e27919917 100644 (file)
@@ -29,9 +29,9 @@
 class ModuleHttpServer;
 
 static ModuleHttpServer* HttpModule;
-static bool claimed;
 static insp::intrusive_list<HttpServerSocket> sockets;
 static Events::ModuleEventProvider* aclevprov;
+static Events::ModuleEventProvider* reqevprov;
 
 /** HTTP socket states
  */
@@ -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()
@@ -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)
                {
@@ -323,15 +331,14 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru
        {
                InternalState = HTTP_SERVE_SEND_DATA;
 
-               claimed = false;
                ModResult MOD_RESULT;
-               HTTPRequest acl((Module*)HttpModule, "httpd_acl", request_type, uri, &headers, this, ip, postdata);
+               HTTPRequest acl(request_type, uri, &headers, this, ip, postdata);
                FIRST_MOD_RESULT_CUSTOM(*aclevprov, HTTPACLEventListener, OnHTTPACLCheck, MOD_RESULT, (acl));
                if (MOD_RESULT != MOD_RES_DENY)
                {
-                       HTTPRequest url((Module*)HttpModule, "httpd_url", request_type, uri, &headers, this, ip, postdata);
-                       url.Send();
-                       if (!claimed)
+                       HTTPRequest url(request_type, uri, &headers, this, ip, postdata);
+                       FIRST_MOD_RESULT_CUSTOM(*reqevprov, HTTPRequestEventListener, OnHTTPRequest, MOD_RESULT, (url));
+                       if (MOD_RESULT == MOD_RES_PASSTHRU)
                        {
                                SendHTTPError(404);
                        }
@@ -365,7 +372,6 @@ class HTTPdAPIImpl : public HTTPdAPIBase
 
        void SendResponse(HTTPDocumentResponse& resp) CXX11_OVERRIDE
        {
-               claimed = true;
                resp.src.sock->Page(resp.document, resp.responsecode, &resp.headers);
        }
 };
@@ -375,13 +381,16 @@ class ModuleHttpServer : public Module
        HTTPdAPIImpl APIImpl;
        unsigned int timeoutsec;
        Events::ModuleEventProvider acleventprov;
+       Events::ModuleEventProvider reqeventprov;
 
  public:
        ModuleHttpServer()
                : APIImpl(this)
                , acleventprov(this, "event/http-acl")
+               , reqeventprov(this, "event/http-request")
        {
                aclevprov = &acleventprov;
+               reqevprov = &reqeventprov;
        }
 
        void init() CXX11_OVERRIDE
@@ -406,6 +415,20 @@ class ModuleHttpServer : public Module
                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)