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

#include <Swiften/Parser/PresenceParser.h>

#include <iostream>

#include <boost/optional.hpp>

namespace Swift {

PresenceParser::PresenceParser(PayloadParserFactoryCollection* factories) :
        GenericStanzaParser<Presence>(factories) {
}

void PresenceParser::handleStanzaAttributes(const AttributeMap& attributes) {
    boost::optional<std::string> type = attributes.getAttributeValue("type");
    if (type) {
        if (*type == "unavailable") {
            getStanzaGeneric()->setType(Presence::Unavailable);
        }
        else if (*type == "probe") {
            getStanzaGeneric()->setType(Presence::Probe);
        }
        else if (*type == "subscribe") {
            getStanzaGeneric()->setType(Presence::Subscribe);
        }
        else if (*type == "subscribed") {
            getStanzaGeneric()->setType(Presence::Subscribed);
        }
        else if (*type == "unsubscribe") {
            getStanzaGeneric()->setType(Presence::Unsubscribe);
        }
        else if (*type == "unsubscribed") {
            getStanzaGeneric()->setType(Presence::Unsubscribed);
        }
        else if (*type == "error") {
            getStanzaGeneric()->setType(Presence::Error);
        }
        else {
            std::cerr << "Unknown Presence type: " << *type << std::endl;
            getStanzaGeneric()->setType(Presence::Available);
        }
    }
    else {
        getStanzaGeneric()->setType(Presence::Available);
    }
}

}