summaryrefslogtreecommitdiffstats
blob: 0235a12d6591b063316926c793337514573b3b82 (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 <boost/optional.hpp>

#include <Swiften/Base/Log.h>

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 {
            SWIFT_LOG(error) << "Unknown Presence type: " << *type << std::endl;
            getStanzaGeneric()->setType(Presence::Available);
        }
    }
    else {
        getStanzaGeneric()->setType(Presence::Available);
    }
}

}