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); } }
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 ConversationManager::handleMessageReceived(Swift::Message::ref message) { // std::string name = message->getTo().getUnescapedNode(); // if (name.find_last_of("%") != std::string::npos) { // OK when commented // name.replace(name.find_last_of("%"), 1, "@"); // OK when commented // } std::string name = Buddy::JIDToLegacyName(message->getTo()); if (name.empty()) { LOG4CXX_WARN(logger, m_user->getJID().toString() << ": Tried to create empty conversation"); return; } // create conversation if it does not exist. if (!m_convs[name]) { Conversation *conv = m_component->getFactory()->createConversation(this, name); addConversation(conv); } // if it exists and it's MUC, but this message is PM, get PM conversation or create new one. else if (m_convs[name]->isMUC() && message->getType() != Swift::Message::Groupchat) { std::string room_name = name; name = room_name + "/" + message->getTo().getResource(); if (m_convs.find(name) == m_convs.end()) { Conversation *conv = m_component->getFactory()->createConversation(this, message->getTo().getResource()); conv->setRoom(room_name); conv->setNickname(name); addConversation(conv); } } // update resource and send the message m_convs[name]->setJID(message->getFrom()); m_convs[name]->sendMessage(message); }
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(""); }
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); } }
void ConversationManager::handleMessageReceived(Swift::Message::ref message) { std::string name = message->getTo().getUnescapedNode(); if (name.find_last_of("%") != std::string::npos) { name.replace(name.find_last_of("%"), 1, "@"); } if (!m_convs[name]) { m_convs[name] = m_component->getFactory()->createConversation(this, name); } m_convs[name]->sendMessage(message); }
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)); }