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

#include <iostream>
#include <boost/optional.hpp>

#include <Swiften/Parser/PresenceParser.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 {
			std::cerr << "Unknown Presence type: " << *type << std::endl;
			getStanzaGeneric()->setType(Presence::Available);
		}
	}
	else {
		getStanzaGeneric()->setType(Presence::Available);
	}
}

}