summaryrefslogtreecommitdiffstats
blob: 72cdd4ce1eafffb5fc2c26d7ab003fa7addd27c1 (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
#include <iostream>

#include "Swiften/Parser/PresenceParser.h"

namespace Swift {

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

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

}