Libtransport: Fix IQs forwarding in Raw XML mode + test it
This commit is contained in:
parent
17f3dabe14
commit
66323700f5
3 changed files with 56 additions and 18 deletions
|
@ -1080,24 +1080,24 @@ void NetworkPluginServer::handleElement(boost::shared_ptr<Swift::Element> elemen
|
|||
return;
|
||||
}
|
||||
|
||||
// TODO: FIX TO MAKE RAW XML BACKENDS WORKING AGAIN.
|
||||
// boost::shared_ptr<Swift::IQ> iq = boost::dynamic_pointer_cast<Swift::IQ>(stanza);
|
||||
// if (iq) {
|
||||
// if (m_id2resource.find(stanza->getTo().toBare().toString() + stanza->getID()) != m_id2resource.end()) {
|
||||
// iq->setTo(Swift::JID(iq->getTo().getNode(), iq->getTo().getDomain(), m_id2resource[stanza->getTo().toBare().toString() + stanza->getID()]));
|
||||
// m_id2resource.erase(stanza->getTo().toBare().toString() + stanza->getID());
|
||||
// }
|
||||
// else {
|
||||
// Swift::Presence::ref highest = m_component->getPresenceOracle()->getHighestPriorityPresence(user->getJID());
|
||||
// if (highest) {
|
||||
// iq->setTo(highest->getFrom());
|
||||
// } else {
|
||||
// iq->setTo(user->getJID());
|
||||
// }
|
||||
// }
|
||||
// m_component->getFrontend()->sendIQ(iq);
|
||||
// return;
|
||||
// }
|
||||
// TODO: Move m_id2resource in User and clean it up
|
||||
boost::shared_ptr<Swift::IQ> iq = boost::dynamic_pointer_cast<Swift::IQ>(stanza);
|
||||
if (iq) {
|
||||
if (m_id2resource.find(stanza->getTo().toBare().toString() + stanza->getID()) != m_id2resource.end()) {
|
||||
iq->setTo(Swift::JID(iq->getTo().getNode(), iq->getTo().getDomain(), m_id2resource[stanza->getTo().toBare().toString() + stanza->getID()]));
|
||||
m_id2resource.erase(stanza->getTo().toBare().toString() + stanza->getID());
|
||||
}
|
||||
else {
|
||||
Swift::Presence::ref highest = m_component->getPresenceOracle()->getHighestPriorityPresence(user->getJID());
|
||||
if (highest) {
|
||||
iq->setTo(highest->getFrom());
|
||||
} else {
|
||||
iq->setTo(user->getJID());
|
||||
}
|
||||
}
|
||||
m_component->getFrontend()->sendIQ(iq);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkPluginServer::handleRawXML(const std::string &xml) {
|
||||
|
|
|
@ -299,6 +299,7 @@ bool XMPPFrontend::handleIQ(boost::shared_ptr<Swift::IQ> iq) {
|
|||
|
||||
void XMPPFrontend::handleBackendConfigChanged() {
|
||||
if (!m_rawXML && CONFIG_BOOL_DEFAULTED(m_config, "features.rawxml", false)) {
|
||||
LOG4CXX_INFO(logger, "Enabled Raw XML mode");
|
||||
m_rawXML = true;
|
||||
m_iqRouter->addHandler(this);
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ class NetworkPluginServerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
|
|||
CPPUNIT_TEST(handleConvMessageAckPayload);
|
||||
CPPUNIT_TEST(handleRawXML);
|
||||
CPPUNIT_TEST(handleRawXMLSplit);
|
||||
CPPUNIT_TEST(handleRawXMLIQ);
|
||||
|
||||
CPPUNIT_TEST(benchmarkHandleBuddyChangedPayload);
|
||||
CPPUNIT_TEST(benchmarkSendUnavailablePresence);
|
||||
|
@ -51,12 +52,20 @@ class NetworkPluginServerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
|
|||
|
||||
public:
|
||||
NetworkPluginServer *serv;
|
||||
NetworkPluginServer::Backend backend;
|
||||
Swift::SafeByteArray protobufData;
|
||||
|
||||
void setUp (void) {
|
||||
setMeUp();
|
||||
|
||||
serv = new NetworkPluginServer(component, cfg, userManager, NULL);
|
||||
connectUser();
|
||||
User *user = userManager->getUser("user@localhost");
|
||||
user->setData(&backend);
|
||||
boost::shared_ptr<Swift::Connection> client1 = factories->getConnectionFactory()->createConnection();
|
||||
dynamic_cast<Swift::DummyConnection *>(client1.get())->onDataSent.connect(boost::bind(&NetworkPluginServerTest::handleDataSent, this, _1));
|
||||
backend.connection = client1;
|
||||
|
||||
received.clear();
|
||||
}
|
||||
|
||||
|
@ -67,6 +76,10 @@ class NetworkPluginServerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
|
|||
tearMeDown();
|
||||
}
|
||||
|
||||
void handleDataSent(const Swift::SafeByteArray &data) {
|
||||
protobufData = data;
|
||||
}
|
||||
|
||||
void handleConvMessageAckPayload() {
|
||||
handleMessageHeadline();
|
||||
received.clear();
|
||||
|
@ -311,6 +324,30 @@ class NetworkPluginServerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
|
|||
CPPUNIT_ASSERT(dynamic_cast<Swift::Presence *>(getStanza(received[0])));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("buddy1\\40domain.tld@localhost/res"), dynamic_cast<Swift::Presence *>(getStanza(received[0]))->getFrom().toString());
|
||||
}
|
||||
|
||||
void handleRawXMLIQ() {
|
||||
cfg->updateBackendConfig("[features]\nrawxml=1\n");
|
||||
User *user = userManager->getUser("user@localhost");
|
||||
std::vector<std::string> grp;
|
||||
grp.push_back("group1");
|
||||
LocalBuddy *buddy = new LocalBuddy(user->getRosterManager(), -1, "buddy1@domain.tld", "Buddy 1", grp, BUDDY_JID_ESCAPING);
|
||||
user->getRosterManager()->setBuddy(buddy);
|
||||
received.clear();
|
||||
|
||||
std::string xml = "<iq from='buddy1@domain.tld/res' to='user@localhost' type='get' id='1'/>";
|
||||
serv->handleRawXML(xml);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
|
||||
CPPUNIT_ASSERT(dynamic_cast<Swift::IQ *>(getStanza(received[0])));
|
||||
CPPUNIT_ASSERT_EQUAL(Swift::IQ::Get, dynamic_cast<Swift::IQ *>(getStanza(received[0]))->getType());
|
||||
|
||||
injectIQ(Swift::IQ::createResult(getStanza(received[0])->getFrom(), getStanza(received[0])->getTo(), getStanza(received[0])->getID()));
|
||||
loop->processEvents();
|
||||
|
||||
pbnetwork::WrapperMessage wrapper;
|
||||
wrapper.ParseFromArray(&protobufData[4], protobufData.size());
|
||||
CPPUNIT_ASSERT_EQUAL(pbnetwork::WrapperMessage_Type_TYPE_RAW_XML, wrapper.type());
|
||||
}
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION (NetworkPluginServerTest);
|
||||
|
|
Loading…
Add table
Reference in a new issue