summaryrefslogtreecommitdiffstats
blob: a8eafef42fd15deaace3d7dbdfaf196c72e5a66d (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
/*
 * Copyright (c) 2010-2016 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */

#include <Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.h>

#include <memory>

#include <Swiften/Serializer/XML/XMLElement.h>

namespace Swift {

DiscoItemsSerializer::DiscoItemsSerializer() : GenericPayloadSerializer<DiscoItems>() {
}

std::string DiscoItemsSerializer::serializePayload(std::shared_ptr<DiscoItems> discoItems)  const {
    XMLElement queryElement("query", "http://jabber.org/protocol/disco#items");
    if (!discoItems->getNode().empty()) {
        queryElement.setAttribute("node", discoItems->getNode());
    }
    for (const auto& item : discoItems->getItems()) {
        std::shared_ptr<XMLElement> itemElement(new XMLElement("item"));
        itemElement->setAttribute("name", item.getName());
        itemElement->setAttribute("jid", item.getJID());
        if (!item.getNode().empty()) {
            itemElement->setAttribute("node", item.getNode());
        }
        queryElement.addNode(itemElement);
    }
    return queryElement.serialize();
}

}