diff options
author | Attila Molnar <attilamolnar@hush.com> | 2015-02-11 17:13:08 +0100 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2015-02-11 17:13:08 +0100 |
commit | 1e8e379dce7a3311eff7161269593f1655f577eb (patch) | |
tree | 60be2453fd5faed5c6eee447a186bc70bf543cc8 /src/modules | |
parent | 96dd0a52d93219a214130c18fe34bb81ce5acdbd (diff) |
Convert the HTTPd request event to use the new cross-module event system
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/m_httpd.cpp | 8 | ||||
-rw-r--r-- | src/modules/m_httpd_config.cpp | 16 | ||||
-rw-r--r-- | src/modules/m_httpd_stats.cpp | 16 |
3 files changed, 28 insertions, 12 deletions
diff --git a/src/modules/m_httpd.cpp b/src/modules/m_httpd.cpp index 0dd028924..3558b0a2b 100644 --- a/src/modules/m_httpd.cpp +++ b/src/modules/m_httpd.cpp @@ -32,6 +32,7 @@ static ModuleHttpServer* HttpModule; static bool claimed; static insp::intrusive_list<HttpServerSocket> sockets; static Events::ModuleEventProvider* aclevprov; +static Events::ModuleEventProvider* reqevprov; /** HTTP socket states */ @@ -330,8 +331,8 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru if (MOD_RESULT != MOD_RES_DENY) { HTTPRequest url((Module*)HttpModule, "httpd_url", request_type, uri, &headers, this, ip, postdata); - url.Send(); - if (!claimed) + FIRST_MOD_RESULT_CUSTOM(*reqevprov, HTTPRequestEventListener, OnHTTPRequest, MOD_RESULT, (url)); + if (MOD_RESULT == MOD_RES_PASSTHRU) { SendHTTPError(404); } @@ -375,13 +376,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 diff --git a/src/modules/m_httpd_config.cpp b/src/modules/m_httpd_config.cpp index 3c4680799..6fd7f4050 100644 --- a/src/modules/m_httpd_config.cpp +++ b/src/modules/m_httpd_config.cpp @@ -21,13 +21,14 @@ #include "inspircd.h" #include "modules/httpd.h" -class ModuleHttpConfig : public Module +class ModuleHttpConfig : public Module, public HTTPRequestEventListener { HTTPdAPI API; public: ModuleHttpConfig() - : API(this) + : HTTPRequestEventListener(this) + , API(this) { } @@ -65,14 +66,12 @@ class ModuleHttpConfig : public Module return ret; } - void OnEvent(Event& event) CXX11_OVERRIDE + ModResult HandleRequest(HTTPRequest* http) { std::stringstream data(""); - if (event.id == "httpd_url") { ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Handling httpd event"); - HTTPRequest* http = (HTTPRequest*)&event; if ((http->GetURI() == "/config") || (http->GetURI() == "/config/")) { @@ -96,8 +95,15 @@ class ModuleHttpConfig : public Module response.headers.SetHeader("X-Powered-By", MODNAME); response.headers.SetHeader("Content-Type", "text/html"); API->SendResponse(response); + return MOD_RES_DENY; // Handled } } + return MOD_RES_PASSTHRU; + } + + ModResult OnHTTPRequest(HTTPRequest& req) CXX11_OVERRIDE + { + return HandleRequest(&req); } Version GetVersion() CXX11_OVERRIDE diff --git a/src/modules/m_httpd_stats.cpp b/src/modules/m_httpd_stats.cpp index 30eacd7a7..983566e55 100644 --- a/src/modules/m_httpd_stats.cpp +++ b/src/modules/m_httpd_stats.cpp @@ -25,14 +25,15 @@ #include "modules/httpd.h" #include "xline.h" -class ModuleHttpStats : public Module +class ModuleHttpStats : public Module, public HTTPRequestEventListener { static const insp::flat_map<char, char const*>& entities; HTTPdAPI API; public: ModuleHttpStats() - : API(this) + : HTTPRequestEventListener(this) + , API(this) { } @@ -87,14 +88,12 @@ class ModuleHttpStats : public Module data << "</metadata>"; } - void OnEvent(Event& event) CXX11_OVERRIDE + ModResult HandleRequest(HTTPRequest* http) { std::stringstream data(""); - if (event.id == "httpd_url") { ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Handling httpd event"); - HTTPRequest* http = (HTTPRequest*)&event; if ((http->GetURI() == "/stats") || (http->GetURI() == "/stats/")) { @@ -231,8 +230,15 @@ class ModuleHttpStats : public Module response.headers.SetHeader("X-Powered-By", MODNAME); response.headers.SetHeader("Content-Type", "text/xml"); API->SendResponse(response); + return MOD_RES_DENY; // Handled } } + return MOD_RES_PASSTHRU; + } + + ModResult OnHTTPRequest(HTTPRequest& req) CXX11_OVERRIDE + { + return HandleRequest(&req); } Version GetVersion() CXX11_OVERRIDE |