diff options
author | Jan Kaluza <hanzz.k@gmail.com> | 2011-04-12 11:36:52 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2011-04-18 19:11:42 (GMT) |
commit | e0578b8fc582d431cce61ecac833ecf7031f6e75 (patch) | |
tree | c03e5bbe9419c5e6aed19e22f06491801f9659c1 /Swiften/Serializer/PayloadSerializers/RosterItemExchangeSerializer.cpp | |
parent | 92af1a97f318f7f623df3183e90e7e828fa2eeb9 (diff) | |
download | swift-contrib-e0578b8fc582d431cce61ecac833ecf7031f6e75.zip swift-contrib-e0578b8fc582d431cce61ecac833ecf7031f6e75.tar.bz2 |
Added Roster Item Exchange XEP support.
License: This patch is BSD-licensed, see http://www.opensource.org/licenses/bsd-license.php
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers/RosterItemExchangeSerializer.cpp')
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/RosterItemExchangeSerializer.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/RosterItemExchangeSerializer.cpp b/Swiften/Serializer/PayloadSerializers/RosterItemExchangeSerializer.cpp new file mode 100644 index 0000000..76c742c --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/RosterItemExchangeSerializer.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2011 Jan Kaluza + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include "Swiften/Serializer/PayloadSerializers/RosterItemExchangeSerializer.h" + +#include <boost/shared_ptr.hpp> + +#include "Swiften/Base/foreach.h" +#include "Swiften/Serializer/XML/XMLTextNode.h" +#include "Swiften/Serializer/XML/XMLRawTextNode.h" +#include "Swiften/Serializer/XML/XMLElement.h" + +namespace Swift { + +RosterItemExchangeSerializer::RosterItemExchangeSerializer() : GenericPayloadSerializer<RosterItemExchangePayload>() { +} + +std::string RosterItemExchangeSerializer::serializePayload(boost::shared_ptr<RosterItemExchangePayload> roster) const { + 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; + } + + foreach(const std::string& group, item.groups) { + boost::shared_ptr<XMLElement> groupElement(new XMLElement("group")); + groupElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(group))); + itemElement->addNode(groupElement); + } + + queryElement.addNode(itemElement); + } + + return queryElement.serialize(); +} + +} |