diff --git a/include/transport/buddy.h b/include/transport/buddy.h index d2d264b3..5e8f1088 100644 --- a/include/transport/buddy.h +++ b/include/transport/buddy.h @@ -162,6 +162,7 @@ class Buddy { /// \param jid Jabber ID. /// \return legacy name of buddy from JID. static std::string JIDToLegacyName(const Swift::JID &jid); + static BuddyFlag buddFlagsFromJID(const Swift::JID &jid); private: void generateJID(); diff --git a/spectrum/src/sample.cfg b/spectrum/src/sample.cfg index e6d1ecc2..86ae72ad 100644 --- a/spectrum/src/sample.cfg +++ b/spectrum/src/sample.cfg @@ -28,6 +28,6 @@ protocol=any #backend_config=backend_logging.cfg # log4cxx/log4j logging configuration file for backends [database] -#type = mysql # or "none" without database backend +type = none # or "none" without database backend database = test.sql prefix=icq diff --git a/src/buddy.cpp b/src/buddy.cpp index 56b8b901..6f919429 100644 --- a/src/buddy.cpp +++ b/src/buddy.cpp @@ -50,7 +50,7 @@ long Buddy::getID() { void Buddy::setFlags(BuddyFlag flags) { m_flags = flags; - generateJID(); +// generateJID(); } BuddyFlag Buddy::getFlags() { @@ -125,10 +125,11 @@ std::string Buddy::getSafeName() { // Transport::instance()->protocol()->prepareUsername(name, purple_buddy_get_account(m_buddy)); if (getFlags() & BUDDY_JID_ESCAPING) { name = Swift::JID::getEscapedNode(name); + std::cout << "OUT '" << getName() << "' '" << name << "'\n"; } else { if (name.find_last_of("@") != std::string::npos) { - name.replace(name.find_last_of("@"), 1, "%"); + name.replace(name.find_last_of("@"), 1, "%"); // OK } } // if (name.empty()) { @@ -155,17 +156,24 @@ std::string Buddy::JIDToLegacyName(const Swift::JID &jid) { if (jid.getUnescapedNode() == jid.getNode()) { name = jid.getNode(); if (name.find_last_of("%") != std::string::npos) { - name.replace(name.find_last_of("%"), 1, "@"); + name.replace(name.find_last_of("%"), 1, "@"); // OK } } else { name = jid.getUnescapedNode(); // Psi sucks... if (name.find_last_of("\\40") != std::string::npos) { - name.replace(name.find_last_of("\\40"), 1, "@"); + name.replace(name.find_last_of("\\40"), 1, "@"); // OK } } return name; } +BuddyFlag Buddy::buddFlagsFromJID(const Swift::JID &jid) { + if (jid.getUnescapedNode() == jid.getNode()) { + return BUDDY_NO_FLAG; + } + return BUDDY_JID_ESCAPING; +} + } diff --git a/src/conversation.cpp b/src/conversation.cpp index 601ce907..e80c552d 100644 --- a/src/conversation.cpp +++ b/src/conversation.cpp @@ -59,11 +59,7 @@ void Conversation::handleMessage(boost::shared_ptr &message, con message->setFrom(buddy->getJID()); } else { - std::string name = nickname; - if (name.find_last_of("@") != std::string::npos) { - name.replace(name.find_last_of("@"), 1, "%"); - } - message->setFrom(name); + message->setFrom(Swift::JID(Swift::JID::getEscapedNode(nickname), m_conversationManager->getComponent()->getJID().toBare())); } } // PM message diff --git a/src/conversationmanager.cpp b/src/conversationmanager.cpp index e2f7f749..5b3ba62d 100644 --- a/src/conversationmanager.cpp +++ b/src/conversationmanager.cpp @@ -63,10 +63,11 @@ void ConversationManager::removeConversation(Conversation *conv) { } 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, "@"); - } +// 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()); // create conversation if it does not exist. if (!m_convs[name]) { diff --git a/src/networkpluginserver.cpp b/src/networkpluginserver.cpp index 47f31ba3..ffe2fbc3 100644 --- a/src/networkpluginserver.cpp +++ b/src/networkpluginserver.cpp @@ -90,7 +90,7 @@ class NetworkFactory : public Factory { buddy->setName(buddyInfo.legacyName); buddy->setSubscription(buddyInfo.subscription); buddy->setGroups(buddyInfo.groups); - buddy->setFlags((BuddyFlag) buddyInfo.flags); + buddy->setFlags((BuddyFlag) (buddyInfo.flags)); if (buddyInfo.settings.find("icon_hash") != buddyInfo.settings.end()) buddy->setIconHash(buddyInfo.settings.find("icon_hash")->second.s); return buddy; @@ -396,12 +396,11 @@ void NetworkPluginServer::handleAuthorizationPayload(const std::string &data) { response->setTo(user->getJID()); std::string name = payload.buddyname(); - // TODO: -// name = Swift::JID::getEscapedNode(name) + name = Swift::JID::getEscapedNode(name); - if (name.find_last_of("@") != std::string::npos) { - name.replace(name.find_last_of("@"), 1, "%"); - } +// if (name.find_last_of("@") != std::string::npos) { // OK when commented +// name.replace(name.find_last_of("@"), 1, "%"); // OK when commented +// } response->setFrom(Swift::JID(name, m_component->getJID().toString())); response->setType(Swift::Presence::Subscribe); @@ -451,6 +450,7 @@ void NetworkPluginServer::handleBuddyChangedPayload(const std::string &data) { } else { buddy = new LocalBuddy(user->getRosterManager(), -1); + buddy->setFlags(BUDDY_JID_ESCAPING); handleBuddyPayload(buddy, payload); user->getRosterManager()->setBuddy(buddy); } @@ -669,33 +669,31 @@ void NetworkPluginServer::pingTimeout() { // Some users are connected for weeks and they are blocking backend to be destroyed and its memory // to be freed. We are finding users who are inactive for more than "idle_reconnect_time" seconds and // reconnect them to long-running backend, where they can idle hapilly till the end of ages. + time_t now = time(NULL); + std::vector usersToMove; unsigned long diff = CONFIG_INT(m_config, "service.idle_reconnect_time"); - if (diff != 0) { - time_t now = time(NULL); - std::vector usersToMove; - - for (std::list::const_iterator it = m_clients.begin(); it != m_clients.end(); it++) { - // Users from long-running backends can't be moved - if ((*it)->longRun) { - continue; - } - - // Find users which are inactive for more than 'diff' - BOOST_FOREACH(User *u, (*it)->users) { - if (now - u->getLastActivity() > diff) { - usersToMove.push_back(u); - } - } + for (std::list::const_iterator it = m_clients.begin(); it != m_clients.end(); it++) { + // Users from long-running backends can't be moved + if ((*it)->longRun) { + continue; } - // Move inactive users to long-running backend. - BOOST_FOREACH(User *u, usersToMove) { - LOG4CXX_INFO(logger, "Moving user " << u->getJID().toString() << " to long-running backend"); - if (!moveToLongRunBackend(u)) - break; + // Find users which are inactive for more than 'diff' + BOOST_FOREACH(User *u, (*it)->users) { + if (now - u->getLastActivity() > diff) { + usersToMove.push_back(u); + } } } + // Move inactive users to long-running backend. + BOOST_FOREACH(User *u, usersToMove) { + LOG4CXX_INFO(logger, "Moving user " << u->getJID().toString() << " to long-running backend"); + if (!moveToLongRunBackend(u)) + break; + } + + // check ping responses std::vector toRemove; diff --git a/src/rostermanager.cpp b/src/rostermanager.cpp index bfbe27aa..8892d632 100644 --- a/src/rostermanager.cpp +++ b/src/rostermanager.cpp @@ -211,7 +211,7 @@ void RosterManager::handleRemoteRosterResponse(boost::shared_ptrgetFactory()->createBuddy(this, buddyInfo); setBuddy(buddy); @@ -299,7 +299,7 @@ void RosterManager::handleSubscription(Swift::Presence::ref presence) { buddyInfo.alias = ""; buddyInfo.legacyName = Buddy::JIDToLegacyName(presence->getTo()); buddyInfo.subscription = "both"; - buddyInfo.flags = 0; + buddyInfo.flags = Buddy::buddFlagsFromJID(presence->getTo()); LOG4CXX_INFO(logger, m_user->getJID().toString() << ": Subscription received for new buddy " << buddyInfo.legacyName << " => adding to legacy network"); buddy = m_component->getFactory()->createBuddy(this, buddyInfo); @@ -361,7 +361,7 @@ void RosterManager::handleSubscription(Swift::Presence::ref presence) { buddyInfo.alias = ""; buddyInfo.legacyName = Buddy::JIDToLegacyName(presence->getTo()); buddyInfo.subscription = "both"; - buddyInfo.flags = 0; + buddyInfo.flags = Buddy::buddFlagsFromJID(presence->getTo()); buddy = m_component->getFactory()->createBuddy(this, buddyInfo); setBuddy(buddy); diff --git a/src/rosterresponder.cpp b/src/rosterresponder.cpp index 7b739647..52876dc7 100644 --- a/src/rosterresponder.cpp +++ b/src/rosterresponder.cpp @@ -94,7 +94,7 @@ bool RosterResponder::handleSetRequest(const Swift::JID& from, const Swift::JID& buddyInfo.alias = item.getName(); buddyInfo.legacyName = Buddy::JIDToLegacyName(item.getJID()); buddyInfo.subscription = "both"; - buddyInfo.flags = 0; + buddyInfo.flags = Buddy::buddFlagsFromJID(item.getJID()); LOG4CXX_INFO(logger, from.toBare().toString() << ": Adding buddy " << buddyInfo.legacyName); buddy = user->getComponent()->getFactory()->createBuddy(user->getRosterManager(), buddyInfo); diff --git a/src/usermanager.cpp b/src/usermanager.cpp index 7074306e..69c6ef68 100644 --- a/src/usermanager.cpp +++ b/src/usermanager.cpp @@ -164,8 +164,8 @@ void UserManager::handlePresence(Swift::Presence::ref presence) { res.password = ""; res.uin = presence->getFrom().getNode(); res.jid = userkey; - if (res.uin.find_last_of("%") != std::string::npos) { - res.uin.replace(res.uin.find_last_of("%"), 1, "@"); + if (res.uin.find_last_of("%") != std::string::npos) { // OK + res.uin.replace(res.uin.find_last_of("%"), 1, "@"); // OK } if (m_storageBackend) { // store user and getUser again to get user ID. diff --git a/src/vcardresponder.cpp b/src/vcardresponder.cpp index 7528c658..594df095 100644 --- a/src/vcardresponder.cpp +++ b/src/vcardresponder.cpp @@ -96,12 +96,9 @@ bool VCardResponder::handleGetRequest(const Swift::JID& from, const Swift::JID& std::string name = to_.getUnescapedNode(); if (name.empty()) { to_ = user->getJID(); - name = to_.getUnescapedNode(); } - if (name.find_last_of("%") != std::string::npos) { - name.replace(name.find_last_of("%"), 1, "@"); - } + name = Buddy::JIDToLegacyName(to_); LOG4CXX_INFO(logger, from.toBare().toString() << ": Requested VCard of " << name);