summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Kaluza <hanzz.k@gmail.com>2011-04-12 11:36:52 (GMT)
committerRemko Tronçon <git@el-tramo.be>2011-04-18 19:11:42 (GMT)
commite0578b8fc582d431cce61ecac833ecf7031f6e75 (patch)
treec03e5bbe9419c5e6aed19e22f06491801f9659c1 /Swiften/Parser/PayloadParsers/RosterItemExchangeParser.cpp
parent92af1a97f318f7f623df3183e90e7e828fa2eeb9 (diff)
downloadswift-e0578b8fc582d431cce61ecac833ecf7031f6e75.zip
swift-e0578b8fc582d431cce61ecac833ecf7031f6e75.tar.bz2
Added Roster Item Exchange XEP support.
License: This patch is BSD-licensed, see http://www.opensource.org/licenses/bsd-license.php
Diffstat (limited to 'Swiften/Parser/PayloadParsers/RosterItemExchangeParser.cpp')
-rw-r--r--Swiften/Parser/PayloadParsers/RosterItemExchangeParser.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/Swiften/Parser/PayloadParsers/RosterItemExchangeParser.cpp b/Swiften/Parser/PayloadParsers/RosterItemExchangeParser.cpp
new file mode 100644
index 0000000..7d59cc3
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/RosterItemExchangeParser.cpp
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2011 Jan Kaluza
+ * Licensed under the Simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt 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_.jid = JID(attributes.getAttribute("jid"));
+ currentItem_.name = attributes.getAttribute("name");
+
+ std::string action = attributes.getAttribute("action");
+ if (action == "add") {
+ currentItem_.action = RosterItemExchangePayload::Add;
+ }
+ else if (action == "modify") {
+ currentItem_.action = RosterItemExchangePayload::Modify;
+ }
+ else if (action == "delete") {
+ currentItem_.action = RosterItemExchangePayload::Delete;
+ }
+ else {
+ // Add is default action according to XEP
+ currentItem_.action = RosterItemExchangePayload::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_.groups.push_back(currentText_);
+ }
+ }
+}
+
+void RosterItemExchangeParser::handleCharacterData(const std::string& data) {
+ currentText_ += data;
+}
+
+}