X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_httpd.cpp;h=978a60ab76e8a959fca18f52a76f4190deb719ea;hb=feaceb2b037123c8687b3afdd80b2ffba61a5652;hp=dadd2f257e68ccee3c3f7cbccb7819ce3821c1de;hpb=de7011e54ad88656e01c92a88dd053a94b5acc6b;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_httpd.cpp b/src/modules/m_httpd.cpp index dadd2f257..978a60ab7 100644 --- a/src/modules/m_httpd.cpp +++ b/src/modules/m_httpd.cpp @@ -1,12 +1,17 @@ /* * InspIRCd -- Internet Relay Chat Daemon * + * Copyright (C) 2019 linuxdaemon + * Copyright (C) 2018 edef + * Copyright (C) 2013-2014, 2017-2019 Sadie Powell + * Copyright (C) 2012-2016 Attila Molnar + * Copyright (C) 2012, 2019 Robby + * Copyright (C) 2009 Uli Schlachter * Copyright (C) 2009 Daniel De Graaf - * Copyright (C) 2007-2008 Robin Burchell - * Copyright (C) 2008 Pippijn van Steenhoven - * Copyright (C) 2006-2008 Craig Edwards - * Copyright (C) 2007 John Brooks + * Copyright (C) 2008 Robin Burchell + * Copyright (C) 2007 John Brooks * Copyright (C) 2007 Dennis Friis + * Copyright (C) 2006, 2008, 2010 Craig Edwards * * This file is part of InspIRCd. InspIRCd is free software: you can * redistribute it and/or modify it under the terms of the GNU General Public @@ -28,14 +33,17 @@ #include "iohook.h" #include "modules/httpd.h" +#ifdef __GNUC__ +# pragma GCC diagnostic push +#endif + // Fix warnings about the use of commas at end of enumerator lists and long long -// on C++03 and warnings about shadowing in the http_parser library. +// on C++03. #if defined __clang__ # pragma clang diagnostic ignored "-Wc++11-extensions" # pragma clang diagnostic ignored "-Wc++11-long-long" #elif defined __GNUC__ # pragma GCC diagnostic ignored "-Wlong-long" -# pragma GCC diagnostic ignored "-Wshadow" # if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)) # pragma GCC diagnostic ignored "-Wpedantic" # else @@ -43,8 +51,17 @@ # endif #endif +// Fix warnings about shadowing in http_parser. +#ifdef __GNUC__ +# pragma GCC diagnostic ignored "-Wshadow" +#endif + #include +#ifdef __GNUC__ +# pragma GCC diagnostic pop +#endif + class ModuleHttpServer; static ModuleHttpServer* HttpModule; @@ -78,7 +95,7 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru { if (!messagecomplete) { - AddToCull(); + Close(); return false; } @@ -212,7 +229,7 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru // IOHook may have errored if (!getError().empty()) { - AddToCull(); + Close(); return; } } @@ -227,17 +244,29 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru sockets.erase(this); } + void Close() CXX11_OVERRIDE + { + if (waitingcull || !HasFd()) + return; + + waitingcull = true; + BufferedSocket::Close(); + ServerInstance->GlobalCulls.AddItem(this); + } + void OnError(BufferedSocketError) CXX11_OVERRIDE { - AddToCull(); + Close(); } void SendHTTPError(unsigned int response) { - HTTPHeaders empty; + static HTTPHeaders empty; std::string data = InspIRCd::Format( - "Server error %u: %s
" - "Powered by InspIRCd", response, http_status_str((http_status)response)); + "" + "

Error %u

%s


" + "Powered by InspIRCd", + response, http_status_str((http_status)response)); Page(data, response, &empty); } @@ -283,8 +312,8 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru FIRST_MOD_RESULT_CUSTOM(*aclevprov, HTTPACLEventListener, OnHTTPACLCheck, MOD_RESULT, (acl)); if (MOD_RESULT != MOD_RES_DENY) { - HTTPRequest url(method, parsed, &headers, this, ip, body); - FIRST_MOD_RESULT_CUSTOM(*reqevprov, HTTPRequestEventListener, OnHTTPRequest, MOD_RESULT, (url)); + HTTPRequest request(method, parsed, &headers, this, ip, body); + FIRST_MOD_RESULT_CUSTOM(*reqevprov, HTTPRequestEventListener, OnHTTPRequest, MOD_RESULT, (request)); if (MOD_RESULT == MOD_RES_PASSTHRU) { SendHTTPError(404); @@ -296,7 +325,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) @@ -304,20 +333,10 @@ 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& uri, HTTPRequestURI& out) + bool ParseURI(const std::string& uristr, HTTPRequestURI& out) { http_parser_url_init(&url); - if (http_parser_parse_url(uri.c_str(), uri.size(), 0, &url) != 0) + if (http_parser_parse_url(uristr.c_str(), uristr.size(), 0, &url) != 0) return false; if (url.field_set & (1 << UF_PATH)) @@ -420,7 +439,7 @@ 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(); }