]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_httpd_stats.cpp
Extra debug
[user/henk/code/inspircd.git] / src / modules / m_httpd_stats.cpp
index 4139d7a2051d62abc17e45a5c01c2b7054431a05..157f772c113fa453dce821e3e9f72e8afcd3fff7 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
  * See: http://www.inspircd.org/wiki/index.php/Credits
  *
  * This program is free but copyrighted software; see
  */
 
 #include "inspircd.h"
-#include "users.h"
-#include "channels.h"
-#include "configreader.h"
-#include "modules.h"
-#include "inspsocket.h"
 #include "httpd.h"
 
 /* $ModDesc: Provides statistics over HTTP via m_httpd.so */
+/* $ModDep: httpd.h */
 
 typedef std::map<irc::string,int> StatsHash;
 typedef StatsHash::iterator StatsIter;
@@ -50,6 +46,8 @@ class ModuleHttpStats : public Module
        {
                ReadConfig();
                this->changed = true;
+               Implementation eventlist[] = { I_OnEvent, I_OnRequest, I_OnChannelDelete, I_OnUserJoin, I_OnUserPart, I_OnUserQuit };
+               ServerInstance->Modules->Attach(eventlist, this, 6);
        }
 
        void InsertOrder(irc::string channel, int count)
@@ -75,7 +73,7 @@ class ModuleHttpStats : public Module
                so->clear();
                for (StatsIter a = sh->begin(); a != sh->end(); a++)
                        InsertOrder(a->first, a->second);
-               for (user_hash::iterator u = ServerInstance->clientlist->begin(); u != ServerInstance->clientlist->end(); u++)
+               for (user_hash::iterator u = ServerInstance->Users->clientlist->begin(); u != ServerInstance->Users->clientlist->end(); u++)
                {
                        StatsHash::iterator n = Servers->find(u->second->server);
                        if (n != Servers->end())
@@ -105,9 +103,9 @@ class ModuleHttpStats : public Module
                                data << "<server><name>" << ServerInstance->Config->ServerName << "</name><gecos>" << ServerInstance->Config->ServerDesc << "</gecos></server>";
 
                                data << "<general>";
-                               data << "<usercount>" << ServerInstance->clientlist->size() << "</usercount>";
+                               data << "<usercount>" << ServerInstance->Users->clientlist->size() << "</usercount>";
                                data << "<channelcount>" << ServerInstance->chanlist->size() << "</channelcount>";
-                               data << "<opercount>" << ServerInstance->all_opers.size() << "</opercount>";
+                               data << "<opercount>" << ServerInstance->Users->all_opers.size() << "</opercount>";
                                data << "<socketcount>" << (ServerInstance->SE->GetMaxFds() - ServerInstance->SE->GetRemainingFds()) << "</socketcount><socketmax>" << ServerInstance->SE->GetMaxFds() <<
                                        "</socketmax><socketengine>" << ServerInstance->SE->GetName() << "</socketengine>";
 
@@ -121,14 +119,12 @@ class ModuleHttpStats : public Module
 
                                data << "</general>";
                                data << "<modulelist>";
-                               for (int i = 0; i <= ServerInstance->GetModuleCount(); i++)
+                               std::vector<std::string> module_names = ServerInstance->Modules->GetAllModuleNames(0);
+                               for (std::vector<std::string>::iterator i = module_names.begin(); i != module_names.end(); ++i)
                                {
-                                       if (!ServerInstance->Config->module_names[i].empty())
-                                       {
-                                               Version v = ServerInstance->modules[i]->GetVersion();
-                                               data << "<module><name>" << ServerInstance->Config->module_names[i] << "</name><version>" << 
-                                                       v.Major << "." <<  v.Minor << "." << v.Revision << "." << v.Build << "</version></module>";
-                                       }
+                                       Module* m = ServerInstance->Modules->Find(i->c_str());
+                                       Version v = m->GetVersion();
+                                       data << "<module><name>" << *i << "</name><version>" << v.Major << "." <<  v.Minor << "." << v.Revision << "." << v.Build << "</version></module>";
                                }
                                data << "</modulelist>";
 
@@ -141,7 +137,7 @@ class ModuleHttpStats : public Module
 
                                for (SortedIter a = so->begin(); a != so->end(); a++)
                                {
-                                       chanrec* c = ServerInstance->FindChan(a->second.c_str());
+                                       Channel* c = ServerInstance->FindChan(a->second.c_str());
                                        if (c && !c->IsModeSet('s') && !c->IsModeSet('p'))
                                        {
                                                data << "<channel>";
@@ -171,14 +167,16 @@ class ModuleHttpStats : public Module
                                data << "</inspircdstats>";
 
                                /* Send the document back to m_httpd */
-                               HTTPDocument response(http->sock, &data, 200, "X-Powered-By: m_http_stats.so\r\nContent-Type: text/xml\r\n");
+                               HTTPDocument response(http->sock, &data, 200);
+                               response.headers.SetHeader("X-Powered-By", "m_httpd_stats.so");
+                               response.headers.SetHeader("Content-Type", "text/xml");
                                Request req((char*)&response, (Module*)this, event->GetSource());
                                req.Send();
                        }
                }
        }
 
-       void OnChannelDelete(chanrec* chan)
+       void OnChannelDelete(Channel* chan)
        {
                StatsIter a = sh->find(chan->name);
                if (a != sh->end())
@@ -188,7 +186,7 @@ class ModuleHttpStats : public Module
                this->changed = true;
        }
 
-       void OnUserJoin(userrec* user, chanrec* channel, bool &silent)
+       void OnUserJoin(User* user, Channel* channel, bool sync, bool &silent)
        {
                StatsIter a = sh->find(channel->name);
                if (a != sh->end())
@@ -203,7 +201,7 @@ class ModuleHttpStats : public Module
                this->changed = true;
        }
 
-       void OnUserPart(userrec* user, chanrec* channel, const std::string &partmessage, bool &silent)
+       void OnUserPart(User* user, Channel* channel, const std::string &partmessage, bool &silent)
        {
                StatsIter a = sh->find(channel->name);
                if (a != sh->end())
@@ -213,11 +211,11 @@ class ModuleHttpStats : public Module
                this->changed = true;
        }
 
-       void OnUserQuit(userrec* user, const std::string &message, const std::string &oper_message)
+       void OnUserQuit(User* user, const std::string &message, const std::string &oper_message)
        {
                for (UCListIter v = user->chans.begin(); v != user->chans.end(); v++)
                {
-                       chanrec* c = v->first;
+                       Channel* c = v->first;
                        StatsIter a = sh->find(c->name);
                        if (a != sh->end())
                        {
@@ -227,15 +225,11 @@ class ModuleHttpStats : public Module
                this->changed = true;
        }
 
-       char* OnRequest(Request* request)
+       const char* OnRequest(Request* request)
        {
                return NULL;
        }
 
-       void Implements(char* List)
-       {
-               List[I_OnEvent] = List[I_OnRequest] = List[I_OnChannelDelete] = List[I_OnUserJoin] = List[I_OnUserPart] = List[I_OnUserQuit] = 1;
-       }
 
        virtual ~ModuleHttpStats()
        {
@@ -245,7 +239,7 @@ class ModuleHttpStats : public Module
 
        virtual Version GetVersion()
        {
-               return Version(1, 1, 0, 0, VF_VENDOR, API_VERSION);
+               return Version(1, 2, 0, 0, VF_VENDOR, API_VERSION);
        }
 };