- data << "<inspircdstats>";
-
- data << "<server><name>" << ServerInstance->Config->ServerName << "</name><gecos>" << ServerInstance->Config->ServerDesc << "</gecos></server>";
-
- data << "<general>";
- data << "<usercount>" << ServerInstance->Users->clientlist->size() << "</usercount>";
- data << "<channelcount>" << ServerInstance->chanlist->size() << "</channelcount>";
- 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>";
-
- time_t current_time = 0;
- current_time = ServerInstance->Time();
- time_t server_uptime = current_time - ServerInstance->startup_time;
- struct tm* stime;
- stime = gmtime(&server_uptime);
- data << "<uptime><days>" << stime->tm_yday << "</days><hours>" << stime->tm_hour << "</hours><mins>" << stime->tm_min << "</mins><secs>" << stime->tm_sec << "</secs></uptime>";
-
-
- data << "</general>";
- data << "<modulelist>";
- 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)
- {
- 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>";
- data << "<channellist>";
-
- for (chan_hash::const_iterator a = ServerInstance->chanlist->begin(); a != ServerInstance->chanlist->end(); ++a)
- {
- Channel* c = a->second;
-
- data << "<channel>";
- data << "<usercount>" << c->GetUsers()->size() << "</usercount><channelname>" << c->name << "</channelname>";
- data << "<channelops>" << c->GetOppedUsers()->size() << "</channelops>";
- data << "<channelhalfops>" << c->GetHalfoppedUsers()->size() << "</channelhalfops>";
- data << "<channelvoices>" << c->GetVoicedUsers()->size() << "</channelvoices>";
- data << "<channeltopic>" << c->topic << "</channeltopic>";
- data << "<channelmodes>" << c->ChanModes(false) << "</channelmodes>";
- CUList* ulist = c->GetUsers();
-
- for (CUList::iterator x = ulist->begin(); x != ulist->end(); ++x)
- {
- data << "<channelmember><uid>" << x->first->uuid << "</uid><privs>" << c->GetAllPrefixChars(x->first) << "</privs></channelmember>";
- }
- data << "</channel>";
- }
-
- data << "</channellist><userlist>";
-
- for (user_hash::const_iterator a = ServerInstance->Users->clientlist->begin(); a != ServerInstance->Users->clientlist->end(); ++a)
- {
- User* u = a->second;
-
- data << "<user>";
- data << "<nickname>" << u->nick << "</nickname><uuid>" << u->uuid << "</uuid><realhost>" << u->host << "</realhost><displayhost>" << u->dhost << "</displayhost>";
- data << "<gecos>" << u->fullname << "</gecos><server>" << u->server << "</server><away>" << u->awaymsg << "</away><opertype>" << u->oper << "</opertype><modes>";
- std::string modes;
- for (unsigned char n = 'A'; n <= 'z'; ++n)
- if (u->IsModeSet(n))
- modes += n;
-
- data << modes << "</modes>";
- data << "</user>";
- }
-
- data << "</userlist><serverlist>";
-
- ProtoServerList sl;
- ServerInstance->PI->GetServerList(sl);
-
- for (ProtoServerList::iterator b = sl.begin(); b != sl.end(); ++b)
- {
- data << "<server>";
- data << "<servername>" << b->servername << "</servername>";
- data << "<parentname>" << b->parentname << "</parentname>";
- data << "<usercount>" << b->usercount << "</usercount>";
- data << "<opercount>" << b->opercount << "</opercount>";
- data << "<lagmillisecs>" << b->latencyms << "</lagmillisecs>";
- data << "</server>";
- }
- data << "</serverlist>";
-
- data << "</inspircdstats>";
-
- /* Send the document back to m_httpd */
- 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();
+ Membership* memb = x->second;
+ data << "<channelmember><uid>" << memb->user->uuid << "</uid><privs>"
+ << Sanitize(memb->GetAllPrefixChars()) << "</privs><modes>"
+ << memb->modes << "</modes>";
+ DumpMeta(data, memb);
+ data << "</channelmember>";
+ }
+
+ DumpMeta(data, c);
+
+ data << "</channel>";
+ }
+
+ return data << "</channellist>";
+ }
+
+ std::ostream& DumpUser(std::ostream& data, User* u)
+ {
+ data << "<user>";
+ data << "<nickname>" << u->nick << "</nickname><uuid>" << u->uuid << "</uuid><realhost>"
+ << u->GetRealHost() << "</realhost><displayhost>" << u->GetDisplayedHost() << "</displayhost><realname>"
+ << Sanitize(u->GetRealName()) << "</realname><server>" << u->server->GetName() << "</server><signon>"
+ << u->signon << "</signon><age>" << u->age << "</age>";
+
+ if (u->IsAway())
+ data << "<away>" << Sanitize(u->awaymsg) << "</away><awaytime>" << u->awaytime << "</awaytime>";
+
+ if (u->IsOper())
+ data << "<opertype>" << Sanitize(u->oper->name) << "</opertype>";
+
+ data << "<modes>" << u->GetModeLetters().substr(1) << "</modes><ident>" << Sanitize(u->ident) << "</ident>";
+
+ LocalUser* lu = IS_LOCAL(u);
+ if (lu)
+ data << "<local/><port>" << lu->server_sa.port() << "</port><servaddr>"
+ << lu->server_sa.str() << "</servaddr><connectclass>"
+ << lu->GetClass()->GetName() << "</connectclass><lastmsg>"
+ << lu->idle_lastmsg << "</lastmsg>";
+
+ data << "<ipaddress>" << u->GetIPString() << "</ipaddress>";
+
+ DumpMeta(data, u);
+
+ data << "</user>";
+ return data;
+ }
+
+ std::ostream& Users(std::ostream& data)
+ {
+ data << "<userlist>";
+ const user_hash& users = ServerInstance->Users->GetUsers();
+ for (user_hash::const_iterator i = users.begin(); i != users.end(); ++i)
+ {
+ User* u = i->second;
+
+ if (u->registered != REG_ALL)
+ continue;
+
+ DumpUser(data, u);
+ }
+ return data << "</userlist>";
+ }
+
+ std::ostream& Servers(std::ostream& data)
+ {
+ data << "<serverlist>";
+
+ ProtocolInterface::ServerList sl;
+ ServerInstance->PI->GetServerList(sl);
+
+ for (ProtocolInterface::ServerList::const_iterator b = sl.begin(); b != sl.end(); ++b)
+ {
+ data << "<server>";
+ data << "<servername>" << b->servername << "</servername>";
+ data << "<parentname>" << b->parentname << "</parentname>";
+ data << "<description>" << Sanitize(b->description) << "</description>";
+ data << "<usercount>" << b->usercount << "</usercount>";
+// This is currently not implemented, so, commented out.
+// data << "<opercount>" << b->opercount << "</opercount>";
+ data << "<lagmillisecs>" << b->latencyms << "</lagmillisecs>";
+ data << "</server>";
+ }
+
+ return data << "</serverlist>";
+ }
+
+ std::ostream& Commands(std::ostream& data)
+ {
+ data << "<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>";
+ }
+ return data << "</commandlist>";
+ }
+
+ enum OrderBy
+ {
+ OB_NICK,
+ OB_LASTMSG,
+
+ OB_NONE
+ };
+
+ struct UserSorter
+ {
+ OrderBy order;
+ bool desc;
+
+ UserSorter(OrderBy Order, bool Desc = false) : order(Order), desc(Desc) {}
+
+ template <typename T>
+ inline bool Compare(const T& a, const T& b)
+ {
+ return desc ? a > b : a < b;
+ }
+
+ bool operator()(User* u1, User* u2)
+ {
+ switch (order) {
+ case OB_LASTMSG:
+ return Compare(IS_LOCAL(u1)->idle_lastmsg, IS_LOCAL(u2)->idle_lastmsg);
+ break;
+ case OB_NICK:
+ return Compare(u1->nick, u2->nick);
+ break;
+ default:
+ case OB_NONE:
+ return false;
+ break;