diff options
author | attilamolnar <attilamolnar@hush.com> | 2013-05-24 19:34:25 +0200 |
---|---|---|
committer | attilamolnar <attilamolnar@hush.com> | 2013-06-07 01:00:10 +0200 |
commit | 183d7a8dc01924ac69a5d160bf1b56ccccd06a4e (patch) | |
tree | a708b167c70f4ca53d3cef2475d83a36761774de /src | |
parent | ad523652ae0ab92df728796a1f082f339f6ddbb6 (diff) |
Change the API of m_httpd to be dynamic_reference-based
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/m_httpd.cpp | 31 | ||||
-rw-r--r-- | src/modules/m_httpd_acl.cpp | 8 | ||||
-rw-r--r-- | src/modules/m_httpd_config.cpp | 9 | ||||
-rw-r--r-- | src/modules/m_httpd_stats.cpp | 7 |
4 files changed, 43 insertions, 12 deletions
diff --git a/src/modules/m_httpd.cpp b/src/modules/m_httpd.cpp index 9d437bd1c..7cbef13e2 100644 --- a/src/modules/m_httpd.cpp +++ b/src/modules/m_httpd.cpp @@ -331,24 +331,37 @@ class HttpServerSocket : public BufferedSocket } }; +class HTTPdAPIImpl : public HTTPdAPIBase +{ + public: + HTTPdAPIImpl(Module* parent) + : HTTPdAPIBase(parent) + { + } + + void SendResponse(HTTPDocumentResponse& resp) CXX11_OVERRIDE + { + claimed = true; + resp.src.sock->Page(resp.document, resp.responsecode, &resp.headers); + } +}; + class ModuleHttpServer : public Module { std::vector<HttpServerSocket *> httpsocks; + HTTPdAPIImpl APIImpl; public: - void init() CXX11_OVERRIDE + ModuleHttpServer() + : APIImpl(this) { - HttpModule = this; - ServerInstance->Modules->Attach(I_OnAcceptConnection, this); } - void OnRequest(Request& request) CXX11_OVERRIDE + void init() CXX11_OVERRIDE { - if (strcmp(request.id, "HTTP-DOC") != 0) - return; - HTTPDocumentResponse& resp = static_cast<HTTPDocumentResponse&>(request); - claimed = true; - resp.src.sock->Page(resp.document, resp.responsecode, &resp.headers); + HttpModule = this; + ServerInstance->Modules->AddService(APIImpl); + ServerInstance->Modules->Attach(I_OnAcceptConnection, this); } ModResult OnAcceptConnection(int nfd, ListenSocket* from, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server) CXX11_OVERRIDE diff --git a/src/modules/m_httpd_acl.cpp b/src/modules/m_httpd_acl.cpp index 061d56f25..676b35ca4 100644 --- a/src/modules/m_httpd_acl.cpp +++ b/src/modules/m_httpd_acl.cpp @@ -43,8 +43,14 @@ class ModuleHTTPAccessList : public Module { std::string stylesheet; std::vector<HTTPACL> acl_list; + HTTPdAPI API; public: + ModuleHTTPAccessList() + : API(this) + { + } + void OnRehash(User* user) { acl_list.clear(); @@ -105,7 +111,7 @@ class ModuleHTTPAccessList : public Module response.headers.SetHeader("X-Powered-By", "m_httpd_acl.so"); if (!extraheaderkey.empty()) response.headers.SetHeader(extraheaderkey, extraheaderval); - response.Send(); + API->SendResponse(response); } void OnEvent(Event& event) CXX11_OVERRIDE diff --git a/src/modules/m_httpd_config.cpp b/src/modules/m_httpd_config.cpp index a9fdd44fb..3396361d0 100644 --- a/src/modules/m_httpd_config.cpp +++ b/src/modules/m_httpd_config.cpp @@ -26,7 +26,14 @@ class ModuleHttpConfig : public Module { + HTTPdAPI API; + public: + ModuleHttpConfig() + : API(this) + { + } + void init() CXX11_OVERRIDE { Implementation eventlist[] = { I_OnEvent }; @@ -97,7 +104,7 @@ class ModuleHttpConfig : public Module HTTPDocumentResponse response(this, *http, &data, 200); response.headers.SetHeader("X-Powered-By", "m_httpd_config.so"); response.headers.SetHeader("Content-Type", "text/html"); - response.Send(); + API->SendResponse(response); } } } diff --git a/src/modules/m_httpd_stats.cpp b/src/modules/m_httpd_stats.cpp index 99909d97f..faf42d071 100644 --- a/src/modules/m_httpd_stats.cpp +++ b/src/modules/m_httpd_stats.cpp @@ -31,8 +31,13 @@ class ModuleHttpStats : public Module { static std::map<char, char const*> const &entities; + HTTPdAPI API; public: + ModuleHttpStats() + : API(this) + { + } void init() CXX11_OVERRIDE { @@ -233,7 +238,7 @@ class ModuleHttpStats : public Module HTTPDocumentResponse response(this, *http, &data, 200); response.headers.SetHeader("X-Powered-By", "m_httpd_stats.so"); response.headers.SetHeader("Content-Type", "text/xml"); - response.Send(); + API->SendResponse(response); } } } |