blob: f40547db05ece468e02b08dc32730cdad5c02b1b (
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) 2017 Tarun Gupta
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
#include <Swiften/Parser/PayloadParsers/MIXUserPreferenceParser.h>
#include <boost/optional.hpp>
#include <Swiften/Parser/PayloadParserFactory.h>
#include <Swiften/Parser/PayloadParsers/FormParser.h>
namespace Swift {
MIXUserPreferenceParser::MIXUserPreferenceParser() : level_(0) {
}
MIXUserPreferenceParser::~MIXUserPreferenceParser() {
}
void MIXUserPreferenceParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
if (level_ == 1) {
if (element == "x" && ns == "jabber:x:data") {
currentPayloadParser_ = std::make_shared<FormParser>();
}
}
if (level_ >= 1 && currentPayloadParser_) {
currentPayloadParser_->handleStartElement(element, ns, attributes);
}
++level_;
}
void MIXUserPreferenceParser::handleEndElement(const std::string& element, const std::string& ns) {
--level_;
if (currentPayloadParser_) {
if (level_ >= 1) {
currentPayloadParser_->handleEndElement(element, ns);
}
if (level_ == 1) {
if (element == "x" && ns == "jabber:x:data") {
getPayloadInternal()->setData(std::dynamic_pointer_cast<Form>(currentPayloadParser_->getPayload()));
}
currentPayloadParser_.reset();
}
}
}
void MIXUserPreferenceParser::handleCharacterData(const std::string& data) {
if (level_ > 1 && currentPayloadParser_) {
currentPayloadParser_->handleCharacterData(data);
}
}
}
|