blob: e5cb2f2bb430fbcc9d70169890e2372ece0c7047 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
/*
* Copyright (c) 2010 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swiften/Serializer/PayloadSerializers/RosterSerializer.h>
#include <boost/shared_ptr.hpp>
#include <boost/smart_ptr/make_shared.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 {
RosterSerializer::RosterSerializer() : GenericPayloadSerializer<RosterPayload>() {
}
std::string RosterSerializer::serializePayload(boost::shared_ptr<RosterPayload> roster) const {
XMLElement queryElement("query", "jabber:iq:roster");
if (roster->getVersion()) {
queryElement.setAttribute("ver", *roster->getVersion());
}
foreach(const RosterItemPayload& item, roster->getItems()) {
boost::shared_ptr<XMLElement> itemElement(new XMLElement("item"));
itemElement->setAttribute("jid", item.getJID());
itemElement->setAttribute("name", item.getName());
switch (item.getSubscription()) {
case RosterItemPayload::To: itemElement->setAttribute("subscription", "to"); break;
case RosterItemPayload::From: itemElement->setAttribute("subscription", "from"); break;
case RosterItemPayload::Both: itemElement->setAttribute("subscription", "both"); break;
case RosterItemPayload::Remove: itemElement->setAttribute("subscription", "remove"); break;
case RosterItemPayload::None: itemElement->setAttribute("subscription", "none"); break;
}
if (item.getSubscriptionRequested()) {
itemElement->setAttribute("ask", "subscribe");
}
foreach(const std::string& group, item.getGroups()) {
boost::shared_ptr<XMLElement> groupElement(new XMLElement("group"));
groupElement->addNode(boost::make_shared<XMLTextNode>(group));
itemElement->addNode(groupElement);
}
if (!item.getUnknownContent().empty()) {
itemElement->addNode(boost::make_shared<XMLRawTextNode>(item.getUnknownContent()));
}
queryElement.addNode(itemElement);
}
return queryElement.serialize();
}
}
|