void handleSwiftMessageReceived(const std::string &user, Swift::Message::ref message) { std::string body = message->getBody(); boost::shared_ptr<Swift::Client> client = m_users[user]; if (client) { handleMessage(user, message->getFrom().toBare().toString(), body, "", ""); } }
void Swiftob::handleMessageReceived(Swift::Message::ref message) { Swift::Message::Type type = message->getType(); if (type == Swift::Message::Error || type == Swift::Message::Headline) { std::cout << "Ignoring typed message" << std::endl; return; } std::string body = message->getBody(); std::cout << "Got message with body " << body << std::endl; if (body.size() == 0) { std::cout << "Not handling empty body" << std::endl; return; } /*Convert body into !command if it's not a MUC, and it misses the bang*/ std::string bangBody(body); if (type != Swift::Message::Groupchat && body[0] != '!') { bangBody = "!" + body; } std::cout << "After banging, body is " << bangBody << std::endl; std::pair<std::string, std::string> split = Swift::String::getSplittedAtFirst(bangBody, ' '); std::string commandName(split.first); commandName = Swift::String::getSplittedAtFirst(commandName, '!').second; /*FIXME: remove leading bang in commandName*/ if (commands_->hasCommand(commandName)) { std::cout << "Matched command " << commandName << std::endl; commands_->runCommand(commandName, split.second, message); } }
static void handleMessageReceived(Swift::Client *client, Swift::Message::ref message, const std::string &server) { std::string body = message->getBody(); boost::replace_all(body, "\n", "\n[ OK ] " + server + ": "); std::cout << "[ OK ] " << server << ": " << body << "\n"; if (--finished == 0) { exit(0); } }
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 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)); }