diff options
Diffstat (limited to 'Swiften')
7 files changed, 86 insertions, 45 deletions
diff --git a/Swiften/Elements/RosterItemExchangePayload.cpp b/Swiften/Elements/RosterItemExchangePayload.cpp index 846e184..f4f3a57 100644 --- a/Swiften/Elements/RosterItemExchangePayload.cpp +++ b/Swiften/Elements/RosterItemExchangePayload.cpp @@ -9,6 +9,9 @@ namespace Swift { +RosterItemExchangePayload::Item::Item() { +} + RosterItemExchangePayload::RosterItemExchangePayload() { } diff --git a/Swiften/Elements/RosterItemExchangePayload.h b/Swiften/Elements/RosterItemExchangePayload.h index f573039..d9e2912 100644 --- a/Swiften/Elements/RosterItemExchangePayload.h +++ b/Swiften/Elements/RosterItemExchangePayload.h @@ -8,7 +8,6 @@ #include <vector> #include <string> -#include <boost/optional.hpp> #include <boost/shared_ptr.hpp> #include "Swiften/Elements/Payload.h" @@ -20,13 +19,49 @@ namespace Swift { public: typedef boost::shared_ptr<RosterItemExchangePayload> ref; - enum Action { Add, Modify, Delete }; + class Item { + public: + enum Action { Add, Modify, Delete }; - struct Item { - Action action; - JID jid; - std::string name; - std::vector<std::string> groups; + Item(); + + Action getAction() const { + return action; + } + + void setAction(Action action) { + this->action = action; + } + + const JID& getJID() const { + return jid; + } + + void setJID(const JID& jid) { + this->jid = jid; + } + + const std::string& getName() const { + return name; + } + + void setName(const std::string& name) { + this->name = name; + } + + const std::vector<std::string>& getGroups() const { + return groups; + } + + void addGroup(const std::string& group) { + groups.push_back(group); + } + + private: + Action action; + JID jid; + std::string name; + std::vector<std::string> groups; }; typedef std::vector<RosterItemExchangePayload::Item> RosterItemExchangePayloadItems; diff --git a/Swiften/Parser/PayloadParsers/RosterItemExchangeParser.cpp b/Swiften/Parser/PayloadParsers/RosterItemExchangeParser.cpp index 7d59cc3..ff2a73b 100644 --- a/Swiften/Parser/PayloadParsers/RosterItemExchangeParser.cpp +++ b/Swiften/Parser/PayloadParsers/RosterItemExchangeParser.cpp @@ -19,22 +19,22 @@ void RosterItemExchangeParser::handleStartElement(const std::string& element, co currentItem_ = RosterItemExchangePayload::Item(); - currentItem_.jid = JID(attributes.getAttribute("jid")); - currentItem_.name = attributes.getAttribute("name"); + currentItem_.setJID(JID(attributes.getAttribute("jid"))); + currentItem_.setName(attributes.getAttribute("name")); std::string action = attributes.getAttribute("action"); if (action == "add") { - currentItem_.action = RosterItemExchangePayload::Add; + currentItem_.setAction(RosterItemExchangePayload::Item::Add); } else if (action == "modify") { - currentItem_.action = RosterItemExchangePayload::Modify; + currentItem_.setAction(RosterItemExchangePayload::Item::Modify); } else if (action == "delete") { - currentItem_.action = RosterItemExchangePayload::Delete; + currentItem_.setAction(RosterItemExchangePayload::Item::Delete); } else { // Add is default action according to XEP - currentItem_.action = RosterItemExchangePayload::Add; + currentItem_.setAction(RosterItemExchangePayload::Item::Add); } } } @@ -56,7 +56,7 @@ void RosterItemExchangeParser::handleEndElement(const std::string& element, cons } else if (level_ == ItemLevel) { if (element == "group") { - currentItem_.groups.push_back(currentText_); + currentItem_.addGroup(currentText_); } } } diff --git a/Swiften/Parser/PayloadParsers/UnitTest/RosterItemExchangeParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/RosterItemExchangeParserTest.cpp index ceba45f..9533e15 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/RosterItemExchangeParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/RosterItemExchangeParserTest.cpp @@ -35,17 +35,17 @@ class RosterItemExchangeParserTest : public CppUnit::TestFixture CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), items.size()); - CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com"), items[0].jid); - CPPUNIT_ASSERT_EQUAL(std::string("Foo @ Bar"), items[0].name); - CPPUNIT_ASSERT_EQUAL(RosterItemExchangePayload::Add, items[0].action); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), items[0].groups.size()); - CPPUNIT_ASSERT_EQUAL(std::string("Group 1"), items[0].groups[0]); - CPPUNIT_ASSERT_EQUAL(std::string("Group 2"), items[0].groups[1]); - - CPPUNIT_ASSERT_EQUAL(JID("baz@blo.com"), items[1].jid); - CPPUNIT_ASSERT_EQUAL(std::string("Baz"), items[1].name); - CPPUNIT_ASSERT_EQUAL(RosterItemExchangePayload::Modify, items[1].action); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), items[1].groups.size()); + CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com"), items[0].getJID()); + CPPUNIT_ASSERT_EQUAL(std::string("Foo @ Bar"), items[0].getName()); + CPPUNIT_ASSERT_EQUAL(RosterItemExchangePayload::Item::Add, items[0].getAction()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), items[0].getGroups().size()); + CPPUNIT_ASSERT_EQUAL(std::string("Group 1"), items[0].getGroups()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("Group 2"), items[0].getGroups()[1]); + + CPPUNIT_ASSERT_EQUAL(JID("baz@blo.com"), items[1].getJID()); + CPPUNIT_ASSERT_EQUAL(std::string("Baz"), items[1].getName()); + CPPUNIT_ASSERT_EQUAL(RosterItemExchangePayload::Item::Modify, items[1].getAction()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), items[1].getGroups().size()); } }; diff --git a/Swiften/Roster/SetRosterRequest.h b/Swiften/Roster/SetRosterRequest.h index 2066089..606b431 100644 --- a/Swiften/Roster/SetRosterRequest.h +++ b/Swiften/Roster/SetRosterRequest.h @@ -18,12 +18,16 @@ namespace Swift { public: typedef boost::shared_ptr<SetRosterRequest> ref; - static ref create(RosterPayload::ref payload, IQRouter* router, const JID& to = JID()) { - return ref(new SetRosterRequest(payload, router, to)); + static ref create(RosterPayload::ref payload, IQRouter* router) { + return ref(new SetRosterRequest(JID(), payload, router)); + } + + static ref create(RosterPayload::ref payload, const JID& to, IQRouter* router) { + return ref(new SetRosterRequest(to, payload, router)); } private: - SetRosterRequest(boost::shared_ptr<RosterPayload> payload, IQRouter* router, const JID& to) : Request(IQ::Set, to, boost::shared_ptr<RosterPayload>(payload), router) { + SetRosterRequest(const JID& to, boost::shared_ptr<RosterPayload> payload, IQRouter* router) : Request(IQ::Set, to, boost::shared_ptr<RosterPayload>(payload), router) { } virtual void handleResponse(boost::shared_ptr<Payload> /*payload*/, ErrorPayload::ref error) { diff --git a/Swiften/Serializer/PayloadSerializers/RosterItemExchangeSerializer.cpp b/Swiften/Serializer/PayloadSerializers/RosterItemExchangeSerializer.cpp index 76c742c..c9ed6ea 100644 --- a/Swiften/Serializer/PayloadSerializers/RosterItemExchangeSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/RosterItemExchangeSerializer.cpp @@ -22,17 +22,16 @@ std::string RosterItemExchangeSerializer::serializePayload(boost::shared_ptr<Ros XMLElement queryElement("x", "http://jabber.org/protocol/rosterx"); foreach(const RosterItemExchangePayload::Item& item, roster->getItems()) { boost::shared_ptr<XMLElement> itemElement(new XMLElement("item")); - itemElement->setAttribute("jid", item.jid); - itemElement->setAttribute("name", item.name); - - switch (item.action) { - case RosterItemExchangePayload::Add: itemElement->setAttribute("action", "add"); break; - case RosterItemExchangePayload::Modify: itemElement->setAttribute("action", "modify"); break; - case RosterItemExchangePayload::Delete: itemElement->setAttribute("action", "delete"); break; - default: itemElement->setAttribute("action", "add"); break; + itemElement->setAttribute("jid", item.getJID()); + itemElement->setAttribute("name", item.getName()); + + switch (item.getAction()) { + case RosterItemExchangePayload::Item::Add: itemElement->setAttribute("action", "add"); break; + case RosterItemExchangePayload::Item::Modify: itemElement->setAttribute("action", "modify"); break; + case RosterItemExchangePayload::Item::Delete: itemElement->setAttribute("action", "delete"); break; } - foreach(const std::string& group, item.groups) { + foreach(const std::string& group, item.getGroups()) { boost::shared_ptr<XMLElement> groupElement(new XMLElement("group")); groupElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(group))); itemElement->addNode(groupElement); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/RosterItemExchangeSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/RosterItemExchangeSerializerTest.cpp index 0fb44c9..f4de783 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/RosterItemExchangeSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/RosterItemExchangeSerializerTest.cpp @@ -25,17 +25,17 @@ class RosterItemExchangeSerializerTest : public CppUnit::TestFixture boost::shared_ptr<RosterItemExchangePayload> roster(new RosterItemExchangePayload()); RosterItemExchangePayload::Item item1; - item1.jid = JID("foo@bar.com"); - item1.name = "Foo @ Bar"; - item1.action = RosterItemExchangePayload::Add; - item1.groups.push_back("Group 1"); - item1.groups.push_back("Group 2"); + item1.setJID("foo@bar.com"); + item1.setName("Foo @ Bar"); + item1.setAction(RosterItemExchangePayload::Item::Add); + item1.addGroup("Group 1"); + item1.addGroup("Group 2"); roster->addItem(item1); RosterItemExchangePayload::Item item2; - item2.jid = JID("baz@blo.com"); - item2.name = "Baz"; - item2.action = RosterItemExchangePayload::Modify; + item2.setJID("baz@blo.com"); + item2.setName("Baz"); + item2.setAction(RosterItemExchangePayload::Item::Modify); roster->addItem(item2); std::string expectedResult = |