Fix #103 - Escape also nodes for MUC rooms in Conversation

This commit is contained in:
Jan Kaluza 2016-01-27 10:54:10 +01:00
parent 1cb79aafa6
commit 9d2692c5d2
3 changed files with 32 additions and 1 deletions

View file

@ -61,6 +61,7 @@ void Conversation::destroyRoom() {
if (legacyName.find_last_of("@") != std::string::npos) {
legacyName.replace(legacyName.find_last_of("@"), 1, "%"); // OK
}
legacyName = Swift::JID::getEscapedNode(legacyName);
presence->setFrom(Swift::JID(legacyName, m_conversationManager->getComponent()->getJID().toBare(), m_nickname));
presence->setType(Swift::Presence::Unavailable);
@ -182,6 +183,7 @@ void Conversation::handleMessage(boost::shared_ptr<Swift::Message> &message, con
if (legacyName.find_last_of("@") != std::string::npos) {
legacyName.replace(legacyName.find_last_of("@"), 1, "%"); // OK
}
legacyName = Swift::JID::getEscapedNode(legacyName);
message->setFrom(Swift::JID(legacyName, m_conversationManager->getComponent()->getJID().toBare(), n));
}
}
@ -191,6 +193,7 @@ void Conversation::handleMessage(boost::shared_ptr<Swift::Message> &message, con
if (legacyName.find_last_of("@") != std::string::npos) {
legacyName.replace(legacyName.find_last_of("@"), 1, "%"); // OK
}
legacyName = Swift::JID::getEscapedNode(legacyName);
std::string n = nickname;
if (n.empty()) {
@ -251,6 +254,7 @@ Swift::Presence::ref Conversation::generatePresence(const std::string &nick, int
if (legacyName.find_last_of("@") != std::string::npos) {
legacyName.replace(legacyName.find_last_of("@"), 1, "%"); // OK
}
legacyName = Swift::JID::getEscapedNode(legacyName);
}
presence->setFrom(Swift::JID(legacyName, m_conversationManager->getComponent()->getJID().toBare(), nickname));
presence->setType(Swift::Presence::Available);

View file

@ -996,7 +996,11 @@ void NetworkPluginServer::handleRoomListPayload(const std::string &data) {
m_component->getFrontend()->clearRoomList();
for (int i = 0; i < payload.room_size() && i < payload.name_size(); i++) {
m_component->getFrontend()->addRoomToRoomList(Swift::JID::getEscapedNode(payload.room(i)) + "@" + m_component->getJID().toString(), payload.name(i));
std::string legacyName = payload.room(i);
if (legacyName.find_last_of("@") != std::string::npos) {
legacyName.replace(legacyName.find_last_of("@"), 1, "%"); // OK
}
m_component->getFrontend()->addRoomToRoomList(Swift::JID::getEscapedNode(legacyName) + "@" + m_component->getJID().toString(), payload.name(i));
}
}
#if HAVE_SWIFTEN_3

View file

@ -25,6 +25,7 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
CPPUNIT_TEST(handleChatstateMessages);
CPPUNIT_TEST(handleSubjectMessages);
CPPUNIT_TEST(handleParticipantChanged);
CPPUNIT_TEST(handleParticipantChangedEscaped);
CPPUNIT_TEST(handleParticipantChangedTwoResources);
CPPUNIT_TEST(handlePMFromXMPP);
CPPUNIT_TEST(handleGroupchatRemoved);
@ -548,6 +549,28 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
CPPUNIT_ASSERT_EQUAL(303, getStanza(received[0])->getPayload<Swift::MUCUserPayload>()->getStatusCodes()[0].code);
}
void handleParticipantChangedEscaped() {
User *user = userManager->getUser("user@localhost");
TestingConversation *conv = new TestingConversation(user->getConversationManager(), "19:70027094a9c84c518535a610766bed65@thread.skype", true);
conv->onMessageToSend.connect(boost::bind(&ConversationManagerTest::handleMessageReceived, this, _1, _2));
conv->setNickname("nickname");
conv->addJID("user@localhost/resource");
// normal presence
conv->handleParticipantChanged("anotheruser", Conversation::PARTICIPANT_FLAG_NONE, Swift::StatusShow::Away, "my status message");
loop->processEvents();
CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
CPPUNIT_ASSERT(dynamic_cast<Swift::Presence *>(getStanza(received[0])));
CPPUNIT_ASSERT_EQUAL(Swift::StatusShow::Away, dynamic_cast<Swift::Presence *>(getStanza(received[0]))->getShow());
CPPUNIT_ASSERT_EQUAL(std::string("user@localhost/resource"), dynamic_cast<Swift::Presence *>(getStanza(received[0]))->getTo().toString());
CPPUNIT_ASSERT_EQUAL(std::string("19\\3a70027094a9c84c518535a610766bed65%thread.skype@localhost/anotheruser"), dynamic_cast<Swift::Presence *>(getStanza(received[0]))->getFrom().toString());
CPPUNIT_ASSERT(getStanza(received[0])->getPayload<Swift::MUCUserPayload>());
CPPUNIT_ASSERT_EQUAL(Swift::MUCOccupant::Member, *getStanza(received[0])->getPayload<Swift::MUCUserPayload>()->getItems()[0].affiliation);
CPPUNIT_ASSERT_EQUAL(Swift::MUCOccupant::Participant, *getStanza(received[0])->getPayload<Swift::MUCUserPayload>()->getItems()[0].role);
}
void handleParticipantChangedTwoResources() {
connectSecondResource();
received2.clear();