]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_httpd_stats.cpp
Merge pull request #1141 from SaberUK/master+windows-purge
[user/henk/code/inspircd.git] / src / modules / m_httpd_stats.cpp
index 35a4b0fb2115ee4d50bd4648e909b06f0038b3a1..62ae0c204bda86de042d7bdfc95298a6f1c22644 100644 (file)
 #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/"))
                        {
@@ -110,10 +109,12 @@ class ModuleHttpStats : public Module
                                data << "<uptime><boot_time_t>" << ServerInstance->startup_time << "</boot_time_t></uptime>";
 
                                data << "<isupport>";
-                               const std::vector<std::string>& isupport = ServerInstance->ISupport.GetLines();
-                               for (std::vector<std::string>::const_iterator it = isupport.begin(); it != isupport.end(); it++)
+                               const std::vector<Numeric::Numeric>& isupport = ServerInstance->ISupport.GetLines();
+                               for (std::vector<Numeric::Numeric>::const_iterator i = isupport.begin(); i != isupport.end(); ++i)
                                {
-                                       data << Sanitize(*it) << std::endl;
+                                       const Numeric::Numeric& num = *i;
+                                       for (std::vector<std::string>::const_iterator j = num.GetParams().begin(); j != num.GetParams().end()-1; ++j)
+                                               data << "<token>" << Sanitize(*j) << "</token>" << std::endl;
                                }
                                data << "</isupport></general><xlines>";
                                std::vector<std::string> xltypes = ServerInstance->XLines->GetAllTypes();
@@ -188,7 +189,7 @@ class ModuleHttpStats : public Module
                                                data << "<away>" << Sanitize(u->awaymsg) << "</away><awaytime>" << u->awaytime << "</awaytime>";
                                        if (u->IsOper())
                                                data << "<opertype>" << Sanitize(u->oper->name) << "</opertype>";
-                                       data << "<modes>" << u->FormatModes() << "</modes><ident>" << Sanitize(u->ident) << "</ident>";
+                                       data << "<modes>" << u->GetModeLetters().substr(1) << "</modes><ident>" << Sanitize(u->ident) << "</ident>";
                                        LocalUser* lu = IS_LOCAL(u);
                                        if (lu)
                                                data << "<port>" << lu->GetServerPort() << "</port><servaddr>"
@@ -210,7 +211,7 @@ class ModuleHttpStats : public Module
                                        data << "<server>";
                                        data << "<servername>" << b->servername << "</servername>";
                                        data << "<parentname>" << b->parentname << "</parentname>";
-                                       data << "<gecos>" << b->gecos << "</gecos>";
+                                       data << "<gecos>" << Sanitize(b->gecos) << "</gecos>";
                                        data << "<usercount>" << b->usercount << "</usercount>";
 // This is currently not implemented, so, commented out.
 //                                     data << "<opercount>" << b->opercount << "</opercount>";
@@ -218,15 +219,30 @@ class ModuleHttpStats : public Module
                                        data << "</server>";
                                }
 
-                               data << "</serverlist></inspircdstats>";
+                               data << "</serverlist><commandlist>";
+
+                               const CommandParser::CommandMap& commands = ServerInstance->Parser.GetCommands();
+                               for (CommandParser::CommandMap::const_iterator i = commands.begin(); i != commands.end(); ++i)
+                               {
+                                       data << "<command><name>" << i->second->name << "</name><usecount>" << i->second->use_count << "</usecount></command>";
+                               }
+
+                               data << "</commandlist></inspircdstats>";
 
                                /* Send the document back to m_httpd */
                                HTTPDocumentResponse response(this, *http, &data, 200);
                                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