blob: 00a5d4fa0133ee3475a8adfd0743947cc77371aa (
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
|
/*
* Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swiften/Parser/PayloadParsers/MUCUserPayloadParser.h>
#include <boost/lexical_cast.hpp>
#include <Swiften/Base/foreach.h>
#include <Swiften/Elements/MUCOccupant.h>
#include <Swiften/Parser/PayloadParserFactory.h>
#include <Swiften/Parser/PayloadParserFactoryCollection.h>
#include <Swiften/Parser/Tree/TreeReparser.h>
namespace Swift {
void MUCUserPayloadParser::handleTree(ParserElement::ref root) {
foreach (ParserElement::ref child, root->getAllChildren()) {
if (child->getName() == "item" && child->getNamespace() == root->getNamespace()) {
MUCItem item = MUCItemParser::itemFromTree(child);
getPayloadInternal()->addItem(item);
}
else if (child->getName() == "password" && child->getNamespace() == root->getNamespace()) {
getPayloadInternal()->setPassword(child->getText());
}
else if (child->getName() == "invite" && child->getNamespace() == root->getNamespace()) {
MUCUserPayload::Invite invite;
std::string to = child->getAttributes().getAttribute("to");
if (!to.empty()) {
invite.to = to;
}
std::string from = child->getAttributes().getAttribute("from");
if (!from.empty()) {
invite.from = from;
}
ParserElement::ref reason = child->getChild("reason", root->getNamespace());
if (reason) {
invite.reason = reason->getText();
}
getPayloadInternal()->setInvite(invite);
}
else if (child->getName() == "status" && child->getNamespace() == root->getNamespace()) {
MUCUserPayload::StatusCode status;
try {
status.code = boost::lexical_cast<int>(child->getAttributes().getAttribute("code").c_str());
getPayloadInternal()->addStatusCode(status);
} catch (boost::bad_lexical_cast&) {
}
}
else {
getPayloadInternal()->setPayload(TreeReparser::parseTree(child, factories));
}
}
}
}
|