Changeset - 389f066d9e2d
[Not reviewed]
0 4 0
HanzZ - 13 years ago 2012-11-30 16:08:38
hanzz.k@gmail.com
Send proper identity in disco#info response with adhoc command node
4 files changed with 44 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/discoinforesponder.cpp
Show inline comments
 
@@ -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<Swift::DiscoInfo> 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<Swift::DiscoInfo> info) {
 
	// disco#info for transport
 
	if (to.getNode().empty()) {
 
		boost::shared_ptr<DiscoInfo> 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<DiscoInfo> 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<DiscoInfo> 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()) {
src/discoinforesponder.h
Show inline comments
 
@@ -41,6 +41,8 @@ class DiscoInfoResponder : public Swift::GetResponder<Swift::DiscoInfo> {
 
		void addRoom(const std::string &jid, const std::string &name);
 
		void clearRooms();
 

	
 
		void addAdHocCommand(const std::string &node, const std::string &name);
 

	
 
		boost::signal<void (const Swift::CapsInfo &capsInfo)> onBuddyCapsInfoChanged;
 

	
 
		Swift::CapsInfo &getBuddyCapsInfo() {
 
@@ -55,6 +57,7 @@ class DiscoInfoResponder : public Swift::GetResponder<Swift::DiscoInfo> {
 
		Config *m_config;
 
		Swift::CapsInfo m_capsInfo;
 
		std::map<std::string, std::string> m_rooms;
 
		std::map<std::string, std::string> m_commands;
 
};
 

	
 
}
 
\ No newline at end of file
src/discoitemsresponder.cpp
Show inline comments
 
@@ -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) {
src/tests/settingsadhoccommand.cpp
Show inline comments
 
@@ -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<Swift::DiscoItems>()->getItems()[0].getNode());
 
		}
 

	
 
		void getInfo() {
 
			boost::shared_ptr<Swift::DiscoInfo> payload(new Swift::DiscoInfo());
 
			payload->setNode("settings");
 
			boost::shared_ptr<Swift::IQ> 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<Swift::IQ *>(getStanza(received[0])));
 
			CPPUNIT_ASSERT_EQUAL(Swift::IQ::Result, dynamic_cast<Swift::IQ *>(getStanza(received[0]))->getType());
 
			CPPUNIT_ASSERT(getStanza(received[0])->getPayload<Swift::DiscoInfo>());
 
			CPPUNIT_ASSERT_EQUAL(std::string("automation"), getStanza(received[0])->getPayload<Swift::DiscoInfo>()->getIdentities()[0].getCategory());
 
			CPPUNIT_ASSERT_EQUAL(std::string("command-node"), getStanza(received[0])->getPayload<Swift::DiscoInfo>()->getIdentities()[0].getType());
 
		}
 

	
 
		void executeNotRegistered() {
 
			boost::shared_ptr<Swift::Command> payload(new Swift::Command("settings"));
 
			boost::shared_ptr<Swift::IQ> iq = Swift::IQ::createRequest(Swift::IQ::Set, Swift::JID("localhost"), "id", payload);
0 comments (0 inline, 0 general)