From 389f066d9e2d4b5444f53fe418274812d0340c10 2012-11-30 16:08:38 From: HanzZ Date: 2012-11-30 16:08:38 Subject: [PATCH] Send proper identity in disco#info response with adhoc command node --- diff --git a/src/discoinforesponder.cpp b/src/discoinforesponder.cpp index 0620b8c58ffc92d49c1553749cd78c7bfa9e5b7d..2ca5746c50befbfeddc0dfbea311dc0909a7a001 100644 --- a/src/discoinforesponder.cpp +++ b/src/discoinforesponder.cpp @@ -94,18 +94,32 @@ void DiscoInfoResponder::clearRooms() { m_rooms.clear(); } -bool DiscoInfoResponder::handleGetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr info) { - if (!info->getNode().empty()) { - sendError(from, id, ErrorPayload::ItemNotFound, ErrorPayload::Cancel); - return true; - } - +void DiscoInfoResponder::addAdHocCommand(const std::string &node, const std::string &name) { + m_commands[node] = node; +} +bool DiscoInfoResponder::handleGetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr info) { // disco#info for transport if (to.getNode().empty()) { - boost::shared_ptr res(new DiscoInfo(m_transportInfo)); - res->setNode(info->getNode()); - sendResponse(from, id, res); + // Adhoc command + if (m_commands.find(info->getNode()) != m_commands.end()) { + boost::shared_ptr res(new DiscoInfo()); + res->addFeature("http://jabber.org/protocol/commands"); + res->addFeature("jabber:x:data"); + res->addIdentity(DiscoInfo::Identity(m_commands[info->getNode()], "automation", "command-node")); + res->setNode(info->getNode()); + sendResponse(from, to, id, res); + } + else { + if (!info->getNode().empty()) { + sendError(from, id, ErrorPayload::ItemNotFound, ErrorPayload::Cancel); + return true; + } + + boost::shared_ptr res(new DiscoInfo(m_transportInfo)); + res->setNode(info->getNode()); + sendResponse(from, id, res); + } } // disco#info for room else if (m_rooms.find(to.toBare().toString()) != m_rooms.end()) { diff --git a/src/discoinforesponder.h b/src/discoinforesponder.h index fadf05861fed4dd581083b2e24d7b9e5e0ecbd4a..a3109222d2c9d38b5aa7bdd13131358c73a77616 100644 --- a/src/discoinforesponder.h +++ b/src/discoinforesponder.h @@ -41,6 +41,8 @@ class DiscoInfoResponder : public Swift::GetResponder { void addRoom(const std::string &jid, const std::string &name); void clearRooms(); + void addAdHocCommand(const std::string &node, const std::string &name); + boost::signal onBuddyCapsInfoChanged; Swift::CapsInfo &getBuddyCapsInfo() { @@ -55,6 +57,7 @@ class DiscoInfoResponder : public Swift::GetResponder { Config *m_config; Swift::CapsInfo m_capsInfo; std::map m_rooms; + std::map m_commands; }; } \ No newline at end of file diff --git a/src/discoitemsresponder.cpp b/src/discoitemsresponder.cpp index acec58224994d5fe7f31a4f919681db79cb85592..72ac83906dd1bcfb6d1b88f0a318b54a00488719 100644 --- a/src/discoitemsresponder.cpp +++ b/src/discoitemsresponder.cpp @@ -51,6 +51,7 @@ DiscoItemsResponder::~DiscoItemsResponder() { void DiscoItemsResponder::addAdHocCommand(const std::string &node, const std::string &name) { m_commands->addItem(DiscoItems::Item(name, m_component->getJID(), node)); + m_discoInfoResponder->addAdHocCommand(node, name); } void DiscoItemsResponder::addRoom(const std::string &node, const std::string &name) { diff --git a/src/tests/settingsadhoccommand.cpp b/src/tests/settingsadhoccommand.cpp index e3e14d9cd61fb9ce964beb456a40ce0cce7ed1ae..3e9602be2e2b266e854d3ad70e9a81d8ceb9eb9a 100644 --- a/src/tests/settingsadhoccommand.cpp +++ b/src/tests/settingsadhoccommand.cpp @@ -26,6 +26,7 @@ using namespace Transport; class SettingsAdHocCommandTest : public CPPUNIT_NS :: TestFixture, public BasicTest { CPPUNIT_TEST_SUITE(SettingsAdHocCommandTest); CPPUNIT_TEST(getItems); + CPPUNIT_TEST(getInfo); CPPUNIT_TEST(execute); CPPUNIT_TEST(executeBadSessionID); CPPUNIT_TEST(executeNotRegistered); @@ -70,6 +71,22 @@ class SettingsAdHocCommandTest : public CPPUNIT_NS :: TestFixture, public BasicT CPPUNIT_ASSERT_EQUAL(std::string("settings"), getStanza(received[0])->getPayload()->getItems()[0].getNode()); } + void getInfo() { + boost::shared_ptr payload(new Swift::DiscoInfo()); + payload->setNode("settings"); + boost::shared_ptr iq = Swift::IQ::createRequest(Swift::IQ::Get, Swift::JID("localhost"), "id", payload); + iq->setFrom("user@localhost"); + injectIQ(iq); + loop->processEvents(); + + CPPUNIT_ASSERT_EQUAL(1, (int) received.size()); + CPPUNIT_ASSERT(dynamic_cast(getStanza(received[0]))); + CPPUNIT_ASSERT_EQUAL(Swift::IQ::Result, dynamic_cast(getStanza(received[0]))->getType()); + CPPUNIT_ASSERT(getStanza(received[0])->getPayload()); + CPPUNIT_ASSERT_EQUAL(std::string("automation"), getStanza(received[0])->getPayload()->getIdentities()[0].getCategory()); + CPPUNIT_ASSERT_EQUAL(std::string("command-node"), getStanza(received[0])->getPayload()->getIdentities()[0].getType()); + } + void executeNotRegistered() { boost::shared_ptr payload(new Swift::Command("settings")); boost::shared_ptr iq = Swift::IQ::createRequest(Swift::IQ::Set, Swift::JID("localhost"), "id", payload);