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

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

#include <memory>

#include <boost/lexical_cast.hpp>

#include <Swiften/Base/foreach.h>
#include <Swiften/Serializer/PayloadSerializerCollection.h>
#include <Swiften/Serializer/XML/XMLElement.h>

namespace Swift {

BytestreamsSerializer::BytestreamsSerializer() {
}

std::string BytestreamsSerializer::serializePayload(std::shared_ptr<Bytestreams> bytestreams)    const {
    XMLElement queryElement("query", "http://jabber.org/protocol/bytestreams");
    queryElement.setAttribute("sid", bytestreams->getStreamID());
    foreach(const Bytestreams::StreamHost& streamHost, bytestreams->getStreamHosts()) {
        std::shared_ptr<XMLElement> streamHostElement(new XMLElement("streamhost"));
        streamHostElement->setAttribute("host", streamHost.host);
        streamHostElement->setAttribute("jid", streamHost.jid.toString());
        streamHostElement->setAttribute("port", boost::lexical_cast<std::string>(streamHost.port));
        queryElement.addNode(streamHostElement);
    }

    if (bytestreams->getUsedStreamHost()) {
        std::shared_ptr<XMLElement> streamHostElement(new XMLElement("streamhost-used"));
        streamHostElement->setAttribute("jid", *bytestreams->getUsedStreamHost());
        queryElement.addNode(streamHostElement);
    }
    return queryElement.serialize();
}

}