aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/m_httpd.cpp
diff options
context:
space:
mode:
authorGravatar Sadie Powell2019-07-16 15:11:21 +0100
committerGravatar Sadie Powell2019-07-16 16:48:18 +0100
commitcd8b456f979733525941284639d8bf899173b429 (patch)
treef1d26962e61c74c5acb076662a909beafbe8e5fd /src/modules/m_httpd.cpp
parentReplace socketengine_{pthread,win32} with C++11 threads. (diff)
parentssl_gnutls: remove PackageInfo directives for EOL Debian versions. (diff)
downloadinspircd++-cd8b456f979733525941284639d8bf899173b429.tar.gz
inspircd++-cd8b456f979733525941284639d8bf899173b429.tar.bz2
inspircd++-cd8b456f979733525941284639d8bf899173b429.zip
Merge branch 'insp3' into master.
Diffstat (limited to 'src/modules/m_httpd.cpp')
-rw-r--r--src/modules/m_httpd.cpp46
1 files changed, 33 insertions, 13 deletions
diff --git a/src/modules/m_httpd.cpp b/src/modules/m_httpd.cpp
index 7164da8a7..04eeb81d9 100644
--- a/src/modules/m_httpd.cpp
+++ b/src/modules/m_httpd.cpp
@@ -28,6 +28,10 @@
#include "iohook.h"
#include "modules/httpd.h"
+#ifdef __GNUC__
+# pragma GCC diagnostic push
+#endif
+
// Fix warnings about shadowing in http_parser.
#ifdef __GNUC__
# pragma GCC diagnostic ignored "-Wshadow"
@@ -35,6 +39,10 @@
#include <http_parser.c>
+#ifdef __GNUC__
+# pragma GCC diagnostic pop
+#endif
+
class ModuleHttpServer;
static ModuleHttpServer* HttpModule;
@@ -47,7 +55,8 @@ static http_parser_settings parser_settings;
*/
class HttpServerSocket : public BufferedSocket, public Timer, public insp::intrusive_list_node<HttpServerSocket>
{
- friend ModuleHttpServer;
+ private:
+ friend class ModuleHttpServer;
http_parser parser;
http_parser_url url;
@@ -61,11 +70,17 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru
/** True if this object is in the cull list
*/
bool waitingcull;
+ bool messagecomplete;
bool Tick(time_t currtime) override
{
- AddToCull();
- return false;
+ if (!messagecomplete)
+ {
+ AddToCull();
+ return false;
+ }
+
+ return true;
}
template<int (HttpServerSocket::*f)()>
@@ -175,6 +190,7 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru
int OnMessageComplete()
{
+ messagecomplete = true;
ServeData();
return 0;
}
@@ -186,6 +202,7 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru
, ip(IP)
, status_code(0)
, waitingcull(false)
+ , messagecomplete(false)
{
if ((!via->iohookprovs.empty()) && (via->iohookprovs.back()))
{
@@ -220,9 +237,7 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru
"<html><head></head><body>Server error %u: %s<br>"
"<small>Powered by <a href='https://www.inspircd.org'>InspIRCd</a></small></body></html>", response, http_status_str((http_status)response));
- SendHeaders(data.length(), response, empty);
- WriteData(data);
- Close();
+ Page(data, response, &empty);
}
void SendHeaders(unsigned long size, unsigned int response, HTTPHeaders &rheaders)
@@ -266,8 +281,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);
@@ -275,11 +290,16 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru
}
}
+ void Page(const std::string& s, unsigned int response, HTTPHeaders* hheaders)
+ {
+ SendHeaders(s.length(), response, *hheaders);
+ WriteData(s);
+ Close(true);
+ }
+
void Page(std::stringstream* n, unsigned int response, HTTPHeaders* hheaders)
{
- SendHeaders(n->str().length(), response, *hheaders);
- WriteData(n->str());
- Close();
+ Page(n->str(), response, hheaders);
}
void AddToCull()
@@ -292,10 +312,10 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru
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))