+
+ ModResult HandleRequest(HTTPRequest* http)
+ {
+ std::string uri = http->GetURI();
+
+ if (uri != "/stats" && uri.substr(0, 7) != "/stats/")
+ return MOD_RES_PASSTHRU;
+
+ if (uri[uri.size() - 1] == '/')
+ uri.erase(uri.size() - 1, 1);
+
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Handling httpd event");
+
+ bool found = true;
+ std::stringstream data;
+ data << "<inspircdstats>";
+
+ if (uri == "/stats")
+ {
+ data << Stats::ServerInfo << Stats::General
+ << Stats::XLines << Stats::Modules
+ << Stats::Channels << Stats::Users
+ << Stats::Servers << Stats::Commands;
+ }
+ else if (uri == "/stats/general")
+ {
+ data << Stats::General;
+ }
+ else if (uri == "/stats/users")
+ {
+ data << Stats::Users;
+ }
+ else
+ {
+ found = false;
+ }
+
+ if (found)
+ {
+ data << "</inspircdstats>";
+ }
+ else
+ {
+ data.clear();
+ data.str(std::string());
+ }
+
+ /* Send the document back to m_httpd */
+ HTTPDocumentResponse response(this, *http, &data, found ? 200 : 404);
+ response.headers.SetHeader("X-Powered-By", MODNAME);
+ response.headers.SetHeader("Content-Type", "text/xml");
+ API->SendResponse(response);
+ return MOD_RES_DENY; // Handled
+ }
+
+ ModResult OnHTTPRequest(HTTPRequest& req) CXX11_OVERRIDE