summaryrefslogtreecommitdiffstats
blob: 845ccf03f1291f095a6e6a6c8871523b7ed2dee3 (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
/*
 * Copyright (c) 2010 Remko Tronçon
 * Licensed under the GNU General Public License v3.
 * See Documentation/Licenses/GPLv3.txt for more information.
 */

#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);
	}
}

}