From 5c1ec7985808aba408bec724f5b90fed0dbcb7ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Tue, 20 Sep 2011 20:49:30 +0200 Subject: Added XEP-191 parserialements. diff --git a/Swiften/Elements/BlockListPayload.h b/Swiften/Elements/BlockListPayload.h new file mode 100644 index 0000000..25cb602 --- /dev/null +++ b/Swiften/Elements/BlockListPayload.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include + +#include +#include + +namespace Swift { + class BlockListPayload : public Payload { + public: + BlockListPayload() { + } + + void addItem(const JID& item) { + items.push_back(item); + } + + const std::vector& getItems() const { + return items; + } + + private: + std::vector items; + }; +} diff --git a/Swiften/Elements/BlockPayload.h b/Swiften/Elements/BlockPayload.h new file mode 100644 index 0000000..6dd5170 --- /dev/null +++ b/Swiften/Elements/BlockPayload.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include + +#include +#include + +namespace Swift { + class BlockPayload : public Payload { + public: + BlockPayload() { + } + + void addItem(const JID& jid) { + items.push_back(jid); + } + + const std::vector& getItems() const { + return items; + } + + private: + std::vector items; + }; +} diff --git a/Swiften/Elements/UnblockPayload.h b/Swiften/Elements/UnblockPayload.h new file mode 100644 index 0000000..b6593ab --- /dev/null +++ b/Swiften/Elements/UnblockPayload.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include + +#include +#include + +namespace Swift { + class UnblockPayload : public Payload { + public: + UnblockPayload() { + } + + void addItem(const JID& item) { + items.push_back(item); + } + + const std::vector& getItems() const { + return items; + } + + private: + std::vector items; + }; +} diff --git a/Swiften/Parser/PayloadParsers/BlockParser.h b/Swiften/Parser/PayloadParsers/BlockParser.h new file mode 100644 index 0000000..cd727ad --- /dev/null +++ b/Swiften/Parser/PayloadParsers/BlockParser.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include +#include + +namespace Swift { + template + class BlockParser : public GenericPayloadParser { + public: + BlockParser() : GenericPayloadParser() { + } + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { + if (level == 1 && element == "item") { + JID jid(attributes.getAttribute("jid")); + if (jid.isValid()) { + GenericPayloadParser::getPayloadInternal()->addItem(jid); + } + } + ++level; + } + + virtual void handleEndElement(const std::string&, const std::string&) { + --level; + } + + virtual void handleCharacterData(const std::string&) { + } + + private: + int level; + }; +} diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp index 4b143fd..e9c49ee 100644 --- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp +++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp @@ -6,11 +6,15 @@ #include #include +#include +#include +#include #include #include #include #include #include +#include #include #include #include @@ -68,6 +72,9 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() { factories_.push_back(shared_ptr(new GenericPayloadParserFactory("c", "http://jabber.org/protocol/caps"))); factories_.push_back(shared_ptr(new GenericPayloadParserFactory("bind", "urn:ietf:params:xml:ns:xmpp-bind"))); factories_.push_back(shared_ptr(new GenericPayloadParserFactory("session", "urn:ietf:params:xml:ns:xmpp-session"))); + factories_.push_back(shared_ptr(new GenericPayloadParserFactory >("block", "urn:xmpp:blocking"))); + factories_.push_back(shared_ptr(new GenericPayloadParserFactory >("blocklist", "urn:xmpp:blocking"))); + factories_.push_back(shared_ptr(new GenericPayloadParserFactory >("unblock", "urn:xmpp:blocking"))); factories_.push_back(shared_ptr(new SecurityLabelParserFactory())); factories_.push_back(shared_ptr(new SecurityLabelsCatalogParserFactory())); factories_.push_back(shared_ptr(new FormParserFactory())); diff --git a/Swiften/Serializer/PayloadSerializers/BlockSerializer.h b/Swiften/Serializer/PayloadSerializers/BlockSerializer.h new file mode 100644 index 0000000..345463c --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/BlockSerializer.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include + +#include +#include +#include + +namespace Swift { + template + class BlockSerializer : public GenericPayloadSerializer { + public: + BlockSerializer(std::string tag) : GenericPayloadSerializer(), tag(tag) { + } + + virtual std::string serializePayload(boost::shared_ptr payload) const { + XMLElement element(tag, "urn:xmpp:blocking"); + foreach (const JID& jid, payload->getItems()) { + boost::shared_ptr item = boost::make_shared("item"); + item->setAttribute("jid", jid); + } + return element.serialize(); + } + + private: + std::string tag; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp index 14e3b46..0746c37 100644 --- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp +++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp @@ -6,9 +6,13 @@ #include #include +#include +#include +#include #include #include #include +#include #include #include #include @@ -64,6 +68,9 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() { serializers_.push_back(new DiscoInfoSerializer()); serializers_.push_back(new DiscoItemsSerializer()); serializers_.push_back(new CapsInfoSerializer()); + serializers_.push_back(new BlockSerializer("block")); + serializers_.push_back(new BlockSerializer("unblock")); + serializers_.push_back(new BlockSerializer("blocklist")); serializers_.push_back(new ResourceBindSerializer()); serializers_.push_back(new StartSessionSerializer()); serializers_.push_back(new SecurityLabelSerializer()); -- cgit v0.10.2-6-g49f6