summaryrefslogtreecommitdiffstats
blob: d530e49f8e54799298543bac39da83aa49fee99f (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
/*
 * Copyright (c) 2017 Tarun Gupta
 * Licensed under the simplified BSD license.
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 */

#include <Swiften/Parser/PayloadParsers/MIXUpdateSubscriptionParser.h>

#include <boost/optional.hpp>

#include <Swiften/Parser/PayloadParserFactory.h>
#include <Swiften/Parser/PayloadParsers/FormParser.h>

namespace Swift {

MIXUpdateSubscriptionParser::MIXUpdateSubscriptionParser() : level_(0) {
}

MIXUpdateSubscriptionParser::~MIXUpdateSubscriptionParser() {
}

void MIXUpdateSubscriptionParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
    if (level_ == 0) {
        if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) {
            if (boost::optional<JID> jid = JID::parse(*attributeValue)) {
                getPayloadInternal()->setJID(*jid);
            }
        }
    }

    if (level_ == 1) {
        if (element == "subscribe" && ns == "urn:xmpp:mix:0") {
            if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) {
                getPayloadInternal()->addSubscription(*attributeValue);
            }
        }
    }

    ++level_;
}

void MIXUpdateSubscriptionParser::handleEndElement(const std::string&, const std::string&) {
    --level_;
}

void MIXUpdateSubscriptionParser::handleCharacterData(const std::string&) {
}

}