summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2010-05-22 20:45:53 (GMT)
committerKevin Smith <git@kismith.co.uk>2010-05-23 08:15:20 (GMT)
commita68530cbbfeb17e01fd684b1ef41b960bc173f66 (patch)
tree98b5cd195f04d781164cf1394cee9092bb7b2497 /Swiften/Parser
parentc9659b556b932e2f887cf1d8ab6c5a0bead835eb (diff)
downloadswift-contrib-a68530cbbfeb17e01fd684b1ef41b960bc173f66.zip
swift-contrib-a68530cbbfeb17e01fd684b1ef41b960bc173f66.tar.bz2
Implement XEP-0045 joining, and appropriate error handling.
Resolves: #211
Diffstat (limited to 'Swiften/Parser')
-rw-r--r--Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp2
-rw-r--r--Swiften/Parser/PayloadParsers/MUCUserPayloadParser.cpp94
-rw-r--r--Swiften/Parser/PayloadParsers/MUCUserPayloadParser.h31
-rw-r--r--Swiften/Parser/PayloadParsers/MUCUserPayloadParserFactory.h17
-rw-r--r--Swiften/Parser/SConscript1
5 files changed, 145 insertions, 0 deletions
diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
index 8c570cb..1a45ed2 100644
--- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
+++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
@@ -28,6 +28,7 @@
#include "Swiften/Parser/PayloadParsers/RawXMLPayloadParserFactory.h"
#include "Swiften/Parser/PayloadParsers/PrivateStorageParserFactory.h"
#include "Swiften/Parser/PayloadParsers/DelayParserFactory.h"
+#include "Swiften/Parser/PayloadParsers/MUCUserPayloadParserFactory.h"
using namespace boost;
@@ -53,6 +54,7 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() {
factories_.push_back(shared_ptr<PayloadParserFactory>(new PrivateStorageParserFactory(this)));
factories_.push_back(shared_ptr<PayloadParserFactory>(new ChatStateParserFactory()));
factories_.push_back(shared_ptr<PayloadParserFactory>(new DelayParserFactory()));
+ factories_.push_back(shared_ptr<PayloadParserFactory>(new MUCUserPayloadParserFactory()));
foreach(shared_ptr<PayloadParserFactory> factory, factories_) {
addFactory(factory.get());
}
diff --git a/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.cpp b/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.cpp
new file mode 100644
index 0000000..5bb0e68
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.cpp
@@ -0,0 +1,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*/) {
+
+}
+
+}
diff --git a/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.h b/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.h
new file mode 100644
index 0000000..01c7de1
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2010 Kevin Smith
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <boost/optional.hpp>
+
+#include "Swiften/Elements/MUCUserPayload.h"
+#include "Swiften/Parser/GenericPayloadParser.h"
+
+namespace Swift {
+ class MUCUserPayloadParser : public GenericPayloadParser<MUCUserPayload> {
+ public:
+ MUCUserPayloadParser();
+
+ virtual void handleStartElement(const String& element, const String&, const AttributeMap& attributes);
+ virtual void handleEndElement(const String& element, const String&);
+ virtual void handleCharacterData(const String& data);
+ MUCOccupant::Role parseRole(const String& itemString) const;
+ MUCOccupant::Affiliation parseAffiliation(const String& statusString) const;
+ private:
+ enum Level {
+ TopLevel = 0,
+ ItemLevel = 1
+ };
+ int level;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/MUCUserPayloadParserFactory.h b/Swiften/Parser/PayloadParsers/MUCUserPayloadParserFactory.h
new file mode 100644
index 0000000..3946ece
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/MUCUserPayloadParserFactory.h
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2010 Kevin Smith
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include "Swiften/Parser/GenericPayloadParserFactory.h"
+#include "Swiften/Parser/PayloadParsers/MUCUserPayloadParser.h"
+
+namespace Swift {
+ class MUCUserPayloadParserFactory : public GenericPayloadParserFactory<MUCUserPayloadParser> {
+ public:
+ MUCUserPayloadParserFactory() : GenericPayloadParserFactory<MUCUserPayloadParser>("x", "http://jabber.org/protocol/muc#user") {}
+ };
+}
diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript
index 77f50be..430d827 100644
--- a/Swiften/Parser/SConscript
+++ b/Swiften/Parser/SConscript
@@ -37,6 +37,7 @@ sources = [
"PayloadParsers/VCardParser.cpp",
"PayloadParsers/VCardUpdateParser.cpp",
"PayloadParsers/DelayParser.cpp",
+ "PayloadParsers/MUCUserPayloadParser.cpp",
"PlatformXMLParserFactory.cpp",
"PresenceParser.cpp",
"SerializingParser.cpp",