blob: 5bb0e688e5fca41df358de9402880c026ba789be (
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
/*
* Copyright (c) 2010 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#include "Swiften/Parser/PayloadParsers/MUCUserPayloadParser.h"
#include <boost/lexical_cast.hpp>
#include "Swiften/MUC/MUCOccupant.h"
#include <cassert>
#include <iostream>
namespace Swift {
MUCUserPayloadParser::MUCUserPayloadParser() : level(TopLevel) {
}
void MUCUserPayloadParser::handleStartElement(const String& element, const String&, const AttributeMap& attributes) {
if (level == ItemLevel) {
if (element == "item") {
MUCUserPayload::Item item;
String affiliation = attributes.getAttribute("affiliation");
String role = attributes.getAttribute("role");
String nick = attributes.getAttribute("nick");
String jid = attributes.getAttribute("jid");
item.affiliation = parseAffiliation(affiliation);
item.role = parseRole(role);
if (!jid.isEmpty()) {
item.realJID = JID(jid);
}
if (!nick.isEmpty()) {
item.nick = nick;
}
getPayloadInternal()->addItem(item);
} else if (element == "status") {
MUCUserPayload::StatusCode status;
try {
status.code = boost::lexical_cast<int>(attributes.getAttribute("code").getUTF8Data());
getPayloadInternal()->addStatusCode(status);
} catch (boost::bad_lexical_cast&) {
}
}
}
++level;
}
MUCOccupant::Role MUCUserPayloadParser::parseRole(const String& roleString) const {
if (roleString == "moderator") {
return MUCOccupant::Moderator;
}
if (roleString == "participant") {
return MUCOccupant::Participant;
}
if (roleString == "visitor") {
return MUCOccupant::Visitor;
}
if (roleString == "none") {
return MUCOccupant::NoRole;
}
return MUCOccupant::NoRole;
}
MUCOccupant::Affiliation MUCUserPayloadParser::parseAffiliation(const String& affiliationString) const {
if (affiliationString == "owner") {
return MUCOccupant::Owner;
}
if (affiliationString == "admin") {
return MUCOccupant::Admin;
}
if (affiliationString == "member") {
return MUCOccupant::Member;
}
if (affiliationString == "outcast") {
return MUCOccupant::Outcast;
}
if (affiliationString == "none") {
return MUCOccupant::NoAffiliation;
}
return MUCOccupant::NoAffiliation;
}
void MUCUserPayloadParser::handleEndElement(const String& /*element*/, const String&) {
--level;
}
void MUCUserPayloadParser::handleCharacterData(const String& /*data*/) {
}
}
|