X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_httpd.cpp;h=330e98c6a9739877f85589f211d097db65feb8ab;hb=3151d60c1ecc9462e4c335282ee6c31672f45111;hp=bdb1d50fcb296b99742036eb460c6a370f61c999;hpb=45d5e5c7526a00784d2366bd1a2ca7d0c5384027;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_httpd.cpp b/src/modules/m_httpd.cpp index bdb1d50fc..330e98c6a 100644 --- a/src/modules/m_httpd.cpp +++ b/src/modules/m_httpd.cpp @@ -3,9 +3,9 @@ * * Copyright (C) 2019 linuxdaemon * Copyright (C) 2018 edef - * Copyright (C) 2013-2014, 2017-2019 Sadie Powell + * Copyright (C) 2013-2014, 2017-2020 Sadie Powell * Copyright (C) 2012-2016 Attila Molnar - * Copyright (C) 2012, 2019 Robby + * Copyright (C) 2012 Robby * Copyright (C) 2009 Uli Schlachter * Copyright (C) 2009 Daniel De Graaf * Copyright (C) 2008 Robin Burchell @@ -95,7 +95,8 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru { if (!messagecomplete) { - AddToCull(); + ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "HTTP socket %d timed out", GetFd()); + Close(); return false; } @@ -229,7 +230,9 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru // IOHook may have errored if (!getError().empty()) { - AddToCull(); + ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "HTTP socket %d encountered a hook error: %s", + GetFd(), getError().c_str()); + Close(); return; } } @@ -244,9 +247,21 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru sockets.erase(this); } - void OnError(BufferedSocketError) CXX11_OVERRIDE + void Close() CXX11_OVERRIDE { - AddToCull(); + if (waitingcull || !HasFd()) + return; + + waitingcull = true; + BufferedSocket::Close(); + ServerInstance->GlobalCulls.AddItem(this); + } + + void OnError(BufferedSocketError err) CXX11_OVERRIDE + { + ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "HTTP socket %d encountered an error: %d - %s", + GetFd(), err, getError().c_str()); + Close(); } void SendHTTPError(unsigned int response) @@ -274,7 +289,7 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru else rheaders.RemoveHeader("Content-Type"); - /* Supporting Connection: keep-alive causes a whole world of hurt syncronizing timeouts, + /* Supporting Connection: keep-alive causes a whole world of hurt synchronizing timeouts, * so remove it, its not essential for what we need. */ rheaders.SetHeader("Connection", "Close"); @@ -315,7 +330,7 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru { SendHeaders(s.length(), response, *hheaders); WriteData(s); - Close(true); + BufferedSocket::Close(true); } void Page(std::stringstream* n, unsigned int response, HTTPHeaders* hheaders) @@ -323,16 +338,6 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru Page(n->str(), response, hheaders); } - void AddToCull() - { - if (waitingcull) - return; - - waitingcull = true; - Close(); - ServerInstance->GlobalCulls.AddItem(this); - } - bool ParseURI(const std::string& uristr, HTTPRequestURI& out) { http_parser_url_init(&url); @@ -439,14 +444,14 @@ class ModuleHttpServer : public Module for (insp::intrusive_list::const_iterator i = sockets.begin(); i != sockets.end(); ++i) { HttpServerSocket* sock = *i; - sock->AddToCull(); + sock->Close(); } return Module::cull(); } Version GetVersion() CXX11_OVERRIDE { - return Version("Provides HTTP serving facilities to modules", VF_VENDOR); + return Version("Allows the server administrator to serve various useful resources over HTTP.", VF_VENDOR); } };