diff options
-rw-r--r-- | include/modules/httpd.h | 15 | ||||
-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 |
4 files changed, 41 insertions, 14 deletions
diff --git a/include/modules/httpd.h b/include/modules/httpd.h index 5e3e780dc..60032cb16 100644 --- a/include/modules/httpd.h +++ b/include/modules/httpd.h @@ -108,7 +108,7 @@ class HttpServerSocket; /** This class represents a HTTP request. */ -class HTTPRequest : public Event +class HTTPRequest { protected: std::string type; @@ -137,7 +137,7 @@ class HTTPRequest : public Event */ HTTPRequest(Module* me, const std::string &eventid, const std::string &request_type, const std::string &uri, HTTPHeaders* hdr, HttpServerSocket* socket, const std::string &ip, const std::string &pdata) - : Event(me, eventid), type(request_type), document(uri), ipaddr(ip), postdata(pdata), headers(hdr), sock(socket) + : type(request_type), document(uri), ipaddr(ip), postdata(pdata), headers(hdr), sock(socket) { } @@ -249,3 +249,14 @@ class HTTPACLEventListener : public Events::ModuleEventListener virtual ModResult OnHTTPACLCheck(HTTPRequest& req) = 0; }; + +class HTTPRequestEventListener : public Events::ModuleEventListener +{ + public: + HTTPRequestEventListener(Module* mod) + : ModuleEventListener(mod, "event/http-request") + { + } + + virtual ModResult OnHTTPRequest(HTTPRequest& req) = 0; +}; 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 |