std::string sendAdminMessage(const std::string &cmd) { Swift::Message::ref msg = SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Message>(new Swift::Message()); msg->setFrom(Swift::JID("me@localhost")); msg->setTo(Swift::JID("localhost")); msg->setBody(cmd); admin->handleMessageReceived(msg); return msg->getBody().get_value_or(""); }
void handleSwiftMessageReceived(const std::string &user, Swift::Message::ref message) { message->setTo(user); std::string xml = safeByteArrayToString(serializer->serializeElement(message)); sendRawXML(xml); }
void AdminInterface::handleMessageReceived(Swift::Message::ref message) { if (!message->getTo().getNode().empty()) return; if (message->getFrom().toBare().toString() != CONFIG_STRING(m_component->getConfig(), "service.admin_jid")) { LOG4CXX_WARN(logger, "Message not from admin user, but from " << message->getFrom().toBare().toString()); return; } // Ignore empty messages if (message->getBody().empty()) { return; } LOG4CXX_INFO(logger, "Message from admin received"); message->setTo(message->getFrom()); message->setFrom(m_component->getJID()); if (message->getBody() == "status") { int users = m_userManager->getUserCount(); int backends = m_server->getBackendCount(); message->setBody("Running (" + boost::lexical_cast<std::string>(users) + " users connected using " + boost::lexical_cast<std::string>(backends) + " backends)"); } else if (message->getBody() == "online_users") { std::string lst; const std::map<std::string, User *> &users = m_userManager->getUsers(); if (users.size() == 0) lst = "0"; for (std::map<std::string, User *>::const_iterator it = users.begin(); it != users.end(); it ++) { lst += (*it).first + "\n"; } message->setBody(lst); } else if (message->getBody() == "online_users_count") { int users = m_userManager->getUserCount(); message->setBody(boost::lexical_cast<std::string>(users)); } else if (message->getBody() == "reload") { bool done = m_component->getConfig()->reload(); if (done) { message->setBody("Config reloaded"); } else { message->setBody("Error during config reload"); } } else if (message->getBody() == "online_users_per_backend") { std::string lst; int id = 1; const std::list <NetworkPluginServer::Backend *> &backends = m_server->getBackends(); for (std::list <NetworkPluginServer::Backend *>::const_iterator b = backends.begin(); b != backends.end(); b++) { NetworkPluginServer::Backend *backend = *b; lst += "Backend " + boost::lexical_cast<std::string>(id) + " (ID=" + backend->id + ")"; lst += backend->acceptUsers ? "" : " - not-accepting"; lst += backend->longRun ? " - long-running" : ""; lst += ":\n"; if (backend->users.size() == 0) { lst += " waiting for users\n"; } else { time_t now = time(NULL); for (std::list<User *>::const_iterator u = backend->users.begin(); u != backend->users.end(); u++) { User *user = *u; lst += " " + user->getJID().toBare().toString(); lst += " - non-active for " + boost::lexical_cast<std::string>(now - user->getLastActivity()) + " seconds"; lst += "\n"; } } id++; } message->setBody(lst); } else if (message->getBody().find("has_online_user") == 0) { User *user = m_userManager->getUser(getArg(message->getBody())); std::cout << getArg(message->getBody()) << "\n"; message->setBody(boost::lexical_cast<std::string>(user != NULL)); } else if (message->getBody() == "backends_count") { int backends = m_server->getBackendCount(); message->setBody(boost::lexical_cast<std::string>(backends)); } else if (message->getBody() == "res_memory") { double shared = 0; double rss = 0; #ifndef WIN32 process_mem_usage(shared, rss); #endif const std::list <NetworkPluginServer::Backend *> &backends = m_server->getBackends(); BOOST_FOREACH(NetworkPluginServer::Backend * backend, backends) { rss += backend->res; } message->setBody(boost::lexical_cast<std::string>(rss)); }