diff options
author | Kevin Smith <git@kismith.co.uk> | 2010-05-08 12:14:01 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2010-05-13 12:29:20 (GMT) |
commit | 705bd7256fa4812045677743fc1e939ccfd66d05 (patch) | |
tree | 84502c2c6bd6bda1bc38e7fce59cc451e05b21c4 /Swiften | |
parent | 61078c4e4fd553bf952bae5c9d44da6cb96a3a70 (diff) | |
download | swift-705bd7256fa4812045677743fc1e939ccfd66d05.zip swift-705bd7256fa4812045677743fc1e939ccfd66d05.tar.bz2 |
List MUCs available on services.
Resolves: #276
Diffstat (limited to 'Swiften')
-rw-r--r-- | Swiften/Elements/DiscoItems.h | 65 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/DiscoItemsParser.cpp | 30 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/DiscoItemsParser.h | 29 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/DiscoItemsParserFactory.h | 18 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp | 2 | ||||
-rw-r--r-- | Swiften/Parser/SConscript | 1 | ||||
-rw-r--r-- | Swiften/Queries/Requests/GetDiscoItemsRequest.h | 19 | ||||
-rw-r--r-- | Swiften/SConscript | 1 | ||||
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.cpp | 36 | ||||
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.h | 20 | ||||
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp | 2 |
11 files changed, 223 insertions, 0 deletions
diff --git a/Swiften/Elements/DiscoItems.h b/Swiften/Elements/DiscoItems.h new file mode 100644 index 0000000..400947a --- /dev/null +++ b/Swiften/Elements/DiscoItems.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2010 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <vector> +#include <algorithm> + +#include "Swiften/Elements/Payload.h" +#include "Swiften/Base/String.h" +#include "Swiften/JID/JID.h" + +namespace Swift { + class DiscoItems : public Payload { + public: + class Item { + public: + Item(const String& name, const JID& jid, const String& node="") : name_(name), jid_(jid), node_(node) { + } + + const String& getName() const { + return name_; + } + + const String& getNode() const { + return node_; + } + + const JID& getJID() const { + return jid_; + } + + private: + String name_; + JID jid_; + String node_; + }; + + DiscoItems() { + } + + const String& getNode() const { + return node_; + } + + void setNode(const String& node) { + node_ = node; + } + + const std::vector<Item>& getItems() const { + return items_; + } + + void addItem(const Item& item) { + items_.push_back(item); + } + + private: + String node_; + std::vector<Item> items_; + }; +} diff --git a/Swiften/Parser/PayloadParsers/DiscoItemsParser.cpp b/Swiften/Parser/PayloadParsers/DiscoItemsParser.cpp new file mode 100644 index 0000000..0900354 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/DiscoItemsParser.cpp @@ -0,0 +1,30 @@ +/* + * 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/DiscoItemsParser.h" + +namespace Swift { + +DiscoItemsParser::DiscoItemsParser() : level_(TopLevel) { +} + +void DiscoItemsParser::handleStartElement(const String& element, const String&, const AttributeMap& attributes) { + if (level_ == PayloadLevel) { + if (element == "item") { + getPayloadInternal()->addItem(DiscoItems::Item(attributes.getAttribute("name"), JID(attributes.getAttribute("jid")), attributes.getAttribute("node"))); + } + } + ++level_; +} + +void DiscoItemsParser::handleEndElement(const String&, const String&) { + --level_; +} + +void DiscoItemsParser::handleCharacterData(const String&) { +} + +} diff --git a/Swiften/Parser/PayloadParsers/DiscoItemsParser.h b/Swiften/Parser/PayloadParsers/DiscoItemsParser.h new file mode 100644 index 0000000..e3da34e --- /dev/null +++ b/Swiften/Parser/PayloadParsers/DiscoItemsParser.h @@ -0,0 +1,29 @@ +/* + * 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/Elements/DiscoItems.h" +#include "Swiften/Parser/GenericPayloadParser.h" + +namespace Swift { + class DiscoItemsParser : public GenericPayloadParser<DiscoItems> { + public: + DiscoItemsParser(); + + 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); + + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; + int level_; + }; +} + diff --git a/Swiften/Parser/PayloadParsers/DiscoItemsParserFactory.h b/Swiften/Parser/PayloadParsers/DiscoItemsParserFactory.h new file mode 100644 index 0000000..5b53031 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/DiscoItemsParserFactory.h @@ -0,0 +1,18 @@ +/* + * 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/DiscoItemsParser.h" + +namespace Swift { + class DiscoItemsParserFactory : public GenericPayloadParserFactory<DiscoItemsParser> { + public: + DiscoItemsParserFactory() : GenericPayloadParserFactory<DiscoItemsParser>("query", "http://jabber.org/protocol/disco#items") {} + }; +} + diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp index b0e4eb2..8c570cb 100644 --- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp +++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp @@ -20,6 +20,7 @@ #include "Swiften/Parser/PayloadParsers/SoftwareVersionParserFactory.h" #include "Swiften/Parser/PayloadParsers/StorageParserFactory.h" #include "Swiften/Parser/PayloadParsers/DiscoInfoParserFactory.h" +#include "Swiften/Parser/PayloadParsers/DiscoItemsParserFactory.h" #include "Swiften/Parser/PayloadParsers/SecurityLabelParserFactory.h" #include "Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParserFactory.h" #include "Swiften/Parser/PayloadParsers/VCardUpdateParserFactory.h" @@ -42,6 +43,7 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() { factories_.push_back(shared_ptr<PayloadParserFactory>(new StorageParserFactory())); factories_.push_back(shared_ptr<PayloadParserFactory>(new RosterParserFactory())); factories_.push_back(shared_ptr<PayloadParserFactory>(new DiscoInfoParserFactory())); + factories_.push_back(shared_ptr<PayloadParserFactory>(new DiscoItemsParserFactory())); factories_.push_back(shared_ptr<PayloadParserFactory>(new ResourceBindParserFactory())); factories_.push_back(shared_ptr<PayloadParserFactory>(new StartSessionParserFactory())); factories_.push_back(shared_ptr<PayloadParserFactory>(new SecurityLabelParserFactory())); diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript index 0d3aad2..77f50be 100644 --- a/Swiften/Parser/SConscript +++ b/Swiften/Parser/SConscript @@ -20,6 +20,7 @@ sources = [ "PayloadParsers/BodyParser.cpp", "PayloadParsers/ChatStateParser.cpp", "PayloadParsers/DiscoInfoParser.cpp", + "PayloadParsers/DiscoItemsParser.cpp", "PayloadParsers/ErrorParser.cpp", "PayloadParsers/FullPayloadParserFactoryCollection.cpp", "PayloadParsers/PriorityParser.cpp", diff --git a/Swiften/Queries/Requests/GetDiscoItemsRequest.h b/Swiften/Queries/Requests/GetDiscoItemsRequest.h new file mode 100644 index 0000000..453eab4 --- /dev/null +++ b/Swiften/Queries/Requests/GetDiscoItemsRequest.h @@ -0,0 +1,19 @@ +/* + * 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/Queries/GenericRequest.h" +#include "Swiften/Elements/DiscoItems.h" + +namespace Swift { + class GetDiscoItemsRequest : public GenericRequest<DiscoItems> { + public: + GetDiscoItemsRequest(const JID& jid, IQRouter* router) : + GenericRequest<DiscoItems>(IQ::Get, jid, boost::shared_ptr<DiscoItems>(new DiscoItems()), router) { + } + }; +} diff --git a/Swiften/SConscript b/Swiften/SConscript index 257f056..4d25dc5 100644 --- a/Swiften/SConscript +++ b/Swiften/SConscript @@ -70,6 +70,7 @@ if env["SCONS_STAGE"] == "build" : "Serializer/PayloadSerializers/CapsInfoSerializer.cpp", "Serializer/PayloadSerializers/ChatStateSerializer.cpp", "Serializer/PayloadSerializers/DiscoInfoSerializer.cpp", + "Serializer/PayloadSerializers/DiscoItemsSerializer.cpp", "Serializer/PayloadSerializers/ErrorSerializer.cpp", "Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp", "Serializer/PayloadSerializers/MUCPayloadSerializer.cpp", diff --git a/Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.cpp b/Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.cpp new file mode 100644 index 0000000..056c515 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.h" + +#include <boost/shared_ptr.hpp> + +#include "Swiften/Base/foreach.h" +#include "Swiften/Serializer/XML/XMLElement.h" + +namespace Swift { + +DiscoItemsSerializer::DiscoItemsSerializer() : GenericPayloadSerializer<DiscoItems>() { +} + +String DiscoItemsSerializer::serializePayload(boost::shared_ptr<DiscoItems> discoItems) const { + XMLElement queryElement("query", "http://jabber.org/protocol/disco#items"); + if (!discoItems->getNode().isEmpty()) { + queryElement.setAttribute("node", discoItems->getNode()); + } + foreach(const DiscoItems::Item& item, discoItems->getItems()) { + boost::shared_ptr<XMLElement> itemElement(new XMLElement("item")); + itemElement->setAttribute("name", item.getName()); + itemElement->setAttribute("jid", item.getJID()); + if (!item.getNode().isEmpty()) { + itemElement->setAttribute("node", item.getNode()); + } + queryElement.addNode(itemElement); + } + return queryElement.serialize(); +} + +} diff --git a/Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.h b/Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.h new file mode 100644 index 0000000..8116e9b --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.h @@ -0,0 +1,20 @@ +/* + * 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/Serializer/GenericPayloadSerializer.h" +#include "Swiften/Elements/DiscoItems.h" + +namespace Swift { + class DiscoItemsSerializer : public GenericPayloadSerializer<DiscoItems> { + public: + DiscoItemsSerializer(); + + virtual String serializePayload(boost::shared_ptr<DiscoItems>) const; + }; +} + diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp index 8dc9d86..caf1d9c 100644 --- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp +++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp @@ -17,6 +17,7 @@ #include "Swiften/Serializer/PayloadSerializers/StatusSerializer.h" #include "Swiften/Serializer/PayloadSerializers/StatusShowSerializer.h" #include "Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h" +#include "Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.h" #include "Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.h" #include "Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h" #include "Swiften/Serializer/PayloadSerializers/StartSessionSerializer.h" @@ -42,6 +43,7 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() { serializers_.push_back(new StatusSerializer()); serializers_.push_back(new StatusShowSerializer()); serializers_.push_back(new DiscoInfoSerializer()); + serializers_.push_back(new DiscoItemsSerializer()); serializers_.push_back(new CapsInfoSerializer()); serializers_.push_back(new ResourceBindSerializer()); serializers_.push_back(new StartSessionSerializer()); |