blob: f99f5926ce4979cf5158652f4483bf4d1393bf83 (
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
|
/*
* Copyright (c) 2011 Jan Kaluza
* Licensed under the Simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
/*
* Copyright (c) 2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swiften/Parser/PayloadParsers/RosterItemExchangeParser.h>
#include <Swiften/Parser/SerializingParser.h>
namespace Swift {
RosterItemExchangeParser::RosterItemExchangeParser() : level_(TopLevel), inItem_(false) {
}
void RosterItemExchangeParser::handleStartElement(const std::string& element, const std::string& /*ns*/, const AttributeMap& attributes) {
if (level_ == PayloadLevel) {
if (element == "item") {
inItem_ = true;
currentItem_ = RosterItemExchangePayload::Item();
currentItem_.setJID(JID(attributes.getAttribute("jid")));
currentItem_.setName(attributes.getAttribute("name"));
std::string action = attributes.getAttribute("action");
if (action == "add") {
currentItem_.setAction(RosterItemExchangePayload::Item::Add);
}
else if (action == "modify") {
currentItem_.setAction(RosterItemExchangePayload::Item::Modify);
}
else if (action == "delete") {
currentItem_.setAction(RosterItemExchangePayload::Item::Delete);
}
else {
// Add is default action according to XEP
currentItem_.setAction(RosterItemExchangePayload::Item::Add);
}
}
}
else if (level_ == ItemLevel) {
if (element == "group") {
currentText_ = "";
}
}
++level_;
}
void RosterItemExchangeParser::handleEndElement(const std::string& element, const std::string& /*ns*/) {
--level_;
if (level_ == PayloadLevel) {
if (inItem_) {
getPayloadInternal()->addItem(currentItem_);
inItem_ = false;
}
}
else if (level_ == ItemLevel) {
if (element == "group") {
currentItem_.addGroup(currentText_);
}
}
}
void RosterItemExchangeParser::handleCharacterData(const std::string& data) {
currentText_ += data;
}
}
|