bool XMPPAccountHandler::send(const Packet* pPacket) { UT_return_val_if_fail(pPacket, false); const std::string resource = getProperty("resource"); // make to-be-send-stream once std::string data; _createPacketStream(data, pPacket); // XMPP doesn't like binary strings, base64 encode them guint8* base64data = gsf_base64_encode_simple(reinterpret_cast<guint8*>(&data[0]), data.size()); UT_return_val_if_fail(base64data, false); for (std::vector<BuddyPtr>::iterator it = getBuddies().begin(); it != getBuddies().end(); it++) { XMPPBuddyPtr pBuddy = boost::static_pointer_cast<XMPPBuddy>(*it); UT_continue_if_fail(pBuddy); if (!_send(reinterpret_cast<char*>(base64data), pBuddy)) { UT_DEBUGMSG(("Error while sending message to '%s'\n", pBuddy->getAddress().c_str())); } } g_free(base64data); return true; }
XMPPBuddyPtr XMPPAccountHandler::_getBuddy(const std::string& from_address) { for (std::vector<BuddyPtr>::iterator it = getBuddies().begin(); it != getBuddies().end(); it++) { XMPPBuddyPtr pBuddy = boost::static_pointer_cast<XMPPBuddy>(*it); UT_continue_if_fail(pBuddy); if (pBuddy->getAddress() == from_address) return pBuddy; } return XMPPBuddyPtr(); }
TelepathyBuddyPtr TelepathyAccountHandler::_getBuddy(TelepathyBuddyPtr pBuddy) { UT_return_val_if_fail(pBuddy, TelepathyBuddyPtr()); for (std::vector<BuddyPtr>::iterator it = getBuddies().begin(); it != getBuddies().end(); it++) { TelepathyBuddyPtr pB = boost::static_pointer_cast<TelepathyBuddy>(*it); UT_continue_if_fail(pB); if (pBuddy->equals(pB)) return pB; } return TelepathyBuddyPtr(); }
void AccountHandler::signal(const Event& event, BuddyPtr pSource) { UT_DEBUGMSG(("AccountHandler::signal()\n")); // we will not forward an event over this account that came from another // account: if you do that, then you very easily get packets running around // forever. if (pSource && pSource->getHandler() != this) return; // broadcast this event over our network (if applicable for each message type) const std::vector<BuddyPtr> vRecipients = (event.isBroadcast() ? getBuddies() : event.getRecipients()); for (std::vector<BuddyPtr>::const_iterator cit = vRecipients.begin(); cit != vRecipients.end(); cit++) { BuddyPtr pRecipient = *cit; UT_continue_if_fail(pRecipient); if (!pSource || (pSource != pRecipient)) { send(&event, pRecipient); } else { // the event originated from this buddy, so make sure not to send it // back to him, as it would result in a broadcast storm and // kill the network really fast } } }
void SlackRosterManager::sendOnlineBuddies() { std::string onlineBuddies = "Online users: "; Swift::StatusShow s; std::string statusMessage; const RosterManager::BuddiesMap &roster = getBuddies(); for(RosterManager::BuddiesMap::const_iterator bt = roster.begin(); bt != roster.end(); bt++) { Buddy *b = (*bt).second; if (!b) { continue; } if (!(b->getStatus(s, statusMessage))) { continue; } if (s.getType() == Swift::StatusShow::None) { continue; } onlineBuddies += b->getAlias() + ", "; } if (m_onlineBuddies != onlineBuddies) { m_onlineBuddies = onlineBuddies; SlackSession *session = static_cast<SlackUser *>(m_user)->getSession(); if (session) { session->setPurpose(m_onlineBuddies); } } m_onlineBuddiesTimer->start(); }
std::vector<TelepathyBuddyPtr> TelepathyAccountHandler::_getBuddies(const std::vector<std::string>& vAcl) { std::vector<TelepathyBuddyPtr> result; for (std::vector<std::string>::const_iterator cit = vAcl.begin(); cit != vAcl.end(); cit++ /*, i++*/) { for (std::vector<BuddyPtr>::iterator it = getBuddies().begin(); it != getBuddies().end(); it++) { TelepathyBuddyPtr pBuddy = boost::static_pointer_cast<TelepathyBuddy>(*it); UT_continue_if_fail(pBuddy); if (pBuddy->getDescriptor(false).utf8_str() == (*cit)) { result.push_back(pBuddy); break; } } } return result; }