Conversation: Use full JID escaping when \40 found in the room JID
This commit is contained in:
parent
12bb35171c
commit
10d29c265b
4 changed files with 41 additions and 4 deletions
|
@ -151,6 +151,8 @@ class Conversation {
|
|||
|
||||
void sendCachedMessages(const Swift::JID &to = Swift::JID());
|
||||
|
||||
void setMUCEscaping(bool mucEscaping);
|
||||
|
||||
private:
|
||||
Swift::Presence::ref generatePresence(const std::string &nick, int flag, int status, const std::string &statusMessage, const std::string &newname = "");
|
||||
void cacheMessage(boost::shared_ptr<Swift::Message> &message);
|
||||
|
@ -165,6 +167,7 @@ class Conversation {
|
|||
std::list<Swift::JID> m_jids;
|
||||
bool m_sentInitialPresence;
|
||||
bool m_nicknameChanged;
|
||||
bool m_mucEscaping;
|
||||
|
||||
// TODO: Move this to some extra class to cache the most used
|
||||
// rooms across different accounts. Just now if we have 10 users
|
||||
|
|
|
@ -45,6 +45,7 @@ Conversation::Conversation(ConversationManager *conversationManager, const std::
|
|||
m_jid = m_conversationManager->getUser()->getJID().toBare();
|
||||
m_sentInitialPresence = false;
|
||||
m_nicknameChanged = false;
|
||||
m_mucEscaping = false;
|
||||
|
||||
if (CONFIG_BOOL_DEFAULTED(conversationManager->getComponent()->getConfig(), "features.rawxml", false)) {
|
||||
m_sentInitialPresence = true;
|
||||
|
@ -54,11 +55,16 @@ Conversation::Conversation(ConversationManager *conversationManager, const std::
|
|||
Conversation::~Conversation() {
|
||||
}
|
||||
|
||||
void Conversation::setMUCEscaping(bool mucEscaping) {
|
||||
LOG4CXX_INFO(logger, m_jid.toString() << ": Setting MUC escaping to " << mucEscaping);
|
||||
m_mucEscaping = mucEscaping;
|
||||
}
|
||||
|
||||
void Conversation::destroyRoom() {
|
||||
if (m_muc) {
|
||||
Swift::Presence::ref presence = Swift::Presence::create();
|
||||
std::string legacyName = m_legacyName;
|
||||
if (legacyName.find_last_of("@") != std::string::npos) {
|
||||
if (!m_mucEscaping && legacyName.find_last_of("@") != std::string::npos) {
|
||||
legacyName.replace(legacyName.find_last_of("@"), 1, "%"); // OK
|
||||
}
|
||||
legacyName = Swift::JID::getEscapedNode(legacyName);
|
||||
|
@ -180,7 +186,7 @@ void Conversation::handleMessage(boost::shared_ptr<Swift::Message> &message, con
|
|||
}
|
||||
else {
|
||||
std::string legacyName = m_room;
|
||||
if (legacyName.find_last_of("@") != std::string::npos) {
|
||||
if (!m_mucEscaping && legacyName.find_last_of("@") != std::string::npos) {
|
||||
legacyName.replace(legacyName.find_last_of("@"), 1, "%"); // OK
|
||||
}
|
||||
legacyName = Swift::JID::getEscapedNode(legacyName);
|
||||
|
@ -190,7 +196,7 @@ void Conversation::handleMessage(boost::shared_ptr<Swift::Message> &message, con
|
|||
}
|
||||
else {
|
||||
std::string legacyName = m_legacyName;
|
||||
if (legacyName.find_last_of("@") != std::string::npos) {
|
||||
if (!m_mucEscaping && legacyName.find_last_of("@") != std::string::npos) {
|
||||
legacyName.replace(legacyName.find_last_of("@"), 1, "%"); // OK
|
||||
}
|
||||
legacyName = Swift::JID::getEscapedNode(legacyName);
|
||||
|
@ -251,7 +257,7 @@ Swift::Presence::ref Conversation::generatePresence(const std::string &nick, int
|
|||
Swift::Presence::ref presence = Swift::Presence::create();
|
||||
std::string legacyName = m_legacyName;
|
||||
if (m_muc) {
|
||||
if (legacyName.find_last_of("@") != std::string::npos) {
|
||||
if (!m_mucEscaping && legacyName.find_last_of("@") != std::string::npos) {
|
||||
legacyName.replace(legacyName.find_last_of("@"), 1, "%"); // OK
|
||||
}
|
||||
legacyName = Swift::JID::getEscapedNode(legacyName);
|
||||
|
|
|
@ -292,6 +292,10 @@ void User::handlePresence(Swift::Presence::ref presence, bool forceJoin) {
|
|||
conv->setNickname(presence->getTo().getResource());
|
||||
conv->addJID(presence->getFrom());
|
||||
|
||||
if (presence->getTo().toString().find("\\40") != std::string::npos) {
|
||||
conv->setMUCEscaping(true);
|
||||
}
|
||||
|
||||
onRawPresenceReceived(presence);
|
||||
onRoomJoined(presence->getFrom(), room, presence->getTo().getResource(), password);
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
|
|||
CPPUNIT_TEST(handleSubjectMessages);
|
||||
CPPUNIT_TEST(handleParticipantChanged);
|
||||
CPPUNIT_TEST(handleParticipantChangedEscaped);
|
||||
CPPUNIT_TEST(handleParticipantChangedEscaped2);
|
||||
CPPUNIT_TEST(handleParticipantChangedTwoResources);
|
||||
CPPUNIT_TEST(handlePMFromXMPP);
|
||||
CPPUNIT_TEST(handleGroupchatRemoved);
|
||||
|
@ -571,6 +572,29 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
|
|||
CPPUNIT_ASSERT_EQUAL(Swift::MUCOccupant::Participant, *getStanza(received[0])->getPayload<Swift::MUCUserPayload>()->getItems()[0].role);
|
||||
}
|
||||
|
||||
void handleParticipantChangedEscaped2() {
|
||||
User *user = userManager->getUser("user@localhost");
|
||||
TestingConversation *conv = new TestingConversation(user->getConversationManager(), "19:70027094a9c84c518535a610766bed65@thread.skype", true);
|
||||
conv->setMUCEscaping(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\\40thread.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();
|
||||
|
|
Loading…
Add table
Reference in a new issue