diff options
author | Remko Tronçon <git@el-tramo.be> | 2013-08-25 16:39:06 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2013-08-27 19:47:48 (GMT) |
commit | 1bb607f96e79845ce30dd5590b0d53cc394ac150 (patch) | |
tree | 6156622ddd1b3238aec73536e0dc25b632965a71 /Swiften | |
parent | c4431ee90f3f1daac0a12b35bfa3378d5c570eaa (diff) | |
download | swift-1bb607f96e79845ce30dd5590b0d53cc394ac150.zip swift-1bb607f96e79845ce30dd5590b0d53cc394ac150.tar.bz2 |
PubSub implementation & Sluift refactoring.
Change-Id: I04ff7111b73565c00bff6db183451774a633344f
Diffstat (limited to 'Swiften')
273 files changed, 10711 insertions, 22 deletions
diff --git a/Swiften/Client/Client.cpp b/Swiften/Client/Client.cpp index da497bc..f158370 100644 --- a/Swiften/Client/Client.cpp +++ b/Swiften/Client/Client.cpp @@ -14,6 +14,7 @@ #include <Swiften/Presence/DirectedPresenceSender.h> #include <Swiften/MUC/MUCRegistry.h> #include <Swiften/MUC/MUCManager.h> +#include <Swiften/PubSub/PubSubManagerImpl.h> #include <Swiften/Client/MemoryStorages.h> #include <Swiften/VCards/VCardManager.h> #include <Swiften/VCards/VCardManager.h> @@ -76,9 +77,12 @@ Client::Client(const JID& jid, const SafeString& password, NetworkFactories* net #ifdef SWIFT_EXPERIMENTAL_WB whiteboardSessionManager = new WhiteboardSessionManager(getIQRouter(), getStanzaChannel(), presenceOracle, getEntityCapsProvider()); #endif + + pubsubManager = new PubSubManagerImpl(getStanzaChannel(), getIQRouter()); } Client::~Client() { + delete pubsubManager; delete whiteboardSessionManager; delete fileTransferManager; diff --git a/Swiften/Client/Client.h b/Swiften/Client/Client.h index f192539..9253074 100644 --- a/Swiften/Client/Client.h +++ b/Swiften/Client/Client.h @@ -38,6 +38,7 @@ namespace Swift { class FileTransferManager; class WhiteboardSessionManager; class ClientBlockListManager; + class PubSubManager; /** * Provides the core functionality for writing XMPP client software. @@ -158,6 +159,11 @@ namespace Swift { void setAlwaysTrustCertificates(); WhiteboardSessionManager* getWhiteboardSessionManager() const; + + PubSubManager* getPubSubManager() const { + return pubsubManager; + } + public: /** @@ -195,5 +201,6 @@ namespace Swift { BlindCertificateTrustChecker* blindCertificateTrustChecker; WhiteboardSessionManager* whiteboardSessionManager; ClientBlockListManager* blockListManager; + PubSubManager* pubsubManager; }; } diff --git a/Swiften/Client/ClientXMLTracer.cpp b/Swiften/Client/ClientXMLTracer.cpp index d2b5446..b413f40 100644 --- a/Swiften/Client/ClientXMLTracer.cpp +++ b/Swiften/Client/ClientXMLTracer.cpp @@ -9,10 +9,16 @@ #include <iostream> #include <boost/bind.hpp> +#include <Swiften/Base/Platform.h> + namespace Swift { ClientXMLTracer::ClientXMLTracer(CoreClient* client, bool bosh) : bosh(bosh) { +#ifdef SWIFTEN_PLATFORM_WIN32 + beautifier = new XMLBeautifier(true, false); +#else beautifier = new XMLBeautifier(true, true); +#endif client->onDataRead.connect(boost::bind(&ClientXMLTracer::printData, this, '<', _1)); client->onDataWritten.connect(boost::bind(&ClientXMLTracer::printData, this, '>', _1)); } diff --git a/Swiften/Elements/ContainerPayload.h b/Swiften/Elements/ContainerPayload.h new file mode 100644 index 0000000..e2a4682 --- /dev/null +++ b/Swiften/Elements/ContainerPayload.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <boost/shared_ptr.hpp> +#include <vector> + +namespace Swift { + template<typename T> + class SWIFTEN_API ContainerPayload : public Payload { + public: + ContainerPayload() {} + ContainerPayload(boost::shared_ptr<T> payload) : payload(payload) {} + + void setPayload(boost::shared_ptr<T> payload) { + this->payload = payload; + } + + boost::shared_ptr<T> getPayload() const { + return payload; + } + + private: + boost::shared_ptr<T> payload; + }; +} diff --git a/Swiften/Elements/Form.h b/Swiften/Elements/Form.h index bd4a2aa..76ed674 100644 --- a/Swiften/Elements/Form.h +++ b/Swiften/Elements/Form.h @@ -35,6 +35,7 @@ namespace Swift { */ void addField(boost::shared_ptr<FormField> field) {assert(field); fields_.push_back(field); } const std::vector<boost::shared_ptr<FormField> >& getFields() const { return fields_; } + void clearFields() { fields_.clear(); } void setTitle(const std::string& title) { title_ = title; } const std::string& getTitle() const { return title_; } @@ -50,9 +51,12 @@ namespace Swift { void addReportedField(FormField::ref field); const std::vector<FormField::ref>& getReportedFields() const; + void clearReportedFields() { reportedFields_.clear(); } void addItem(const FormItem& item); const std::vector<FormItem>& getItems() const; + void clearItems() { items_.clear(); } + private: std::vector<boost::shared_ptr<FormField> > fields_; std::vector<boost::shared_ptr<FormField> > reportedFields_; diff --git a/Swiften/Elements/FormField.cpp b/Swiften/Elements/FormField.cpp index 27ced82..e9e4f77 100644 --- a/Swiften/Elements/FormField.cpp +++ b/Swiften/Elements/FormField.cpp @@ -27,7 +27,6 @@ void FormField::setTextMultiValue(const std::string& value) { } void FormField::setBoolValue(bool b) { - assert(type == BooleanType || type == UnknownType); values.clear(); values.push_back(b ? "1" : "0"); } diff --git a/Swiften/Elements/FormField.h b/Swiften/Elements/FormField.h index 26e70bb..f0bebd9 100644 --- a/Swiften/Elements/FormField.h +++ b/Swiften/Elements/FormField.h @@ -63,6 +63,10 @@ namespace Swift { return options; } + void clearOptions() { + options.clear(); + } + const std::vector<std::string>& getValues() const { return values; } diff --git a/Swiften/Elements/PubSub.cpp b/Swiften/Elements/PubSub.cpp new file mode 100644 index 0000000..30a6376 --- /dev/null +++ b/Swiften/Elements/PubSub.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSub.h> + +using namespace Swift; + +PubSub::PubSub() { +} + +PubSub::~PubSub() { +} diff --git a/Swiften/Elements/PubSub.h b/Swiften/Elements/PubSub.h new file mode 100644 index 0000000..cd8bf43 --- /dev/null +++ b/Swiften/Elements/PubSub.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/ContainerPayload.h> + +#include <Swiften/Elements/PubSubPayload.h> + +namespace Swift { + class SWIFTEN_API PubSub : public ContainerPayload<PubSubPayload> { + public: + PubSub(); + virtual ~PubSub(); + }; +} diff --git a/Swiften/Elements/PubSubAffiliation.cpp b/Swiften/Elements/PubSubAffiliation.cpp new file mode 100644 index 0000000..0b04494 --- /dev/null +++ b/Swiften/Elements/PubSubAffiliation.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubAffiliation.h> + +using namespace Swift; + +PubSubAffiliation::PubSubAffiliation() : type(None) { +} + +PubSubAffiliation::~PubSubAffiliation() { +} diff --git a/Swiften/Elements/PubSubAffiliation.h b/Swiften/Elements/PubSubAffiliation.h new file mode 100644 index 0000000..2ea9376 --- /dev/null +++ b/Swiften/Elements/PubSubAffiliation.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <string> + + + +namespace Swift { + class SWIFTEN_API PubSubAffiliation : public Payload { + public: + enum Type { + None, + Member, + Outcast, + Owner, + Publisher, + PublishOnly + }; + + PubSubAffiliation(); + PubSubAffiliation(const std::string& node) : node(node), type(None) {} + virtual ~PubSubAffiliation(); + + const std::string& getNode() const { + return node; + } + + void setNode(const std::string& value) { + this->node = value ; + } + + Type getType() const { + return type; + } + + void setType(Type value) { + this->type = value ; + } + + + private: + std::string node; + Type type; + }; +} diff --git a/Swiften/Elements/PubSubAffiliations.cpp b/Swiften/Elements/PubSubAffiliations.cpp new file mode 100644 index 0000000..a53215d --- /dev/null +++ b/Swiften/Elements/PubSubAffiliations.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubAffiliations.h> + +using namespace Swift; + +PubSubAffiliations::PubSubAffiliations() { +} + +PubSubAffiliations::~PubSubAffiliations() { +} diff --git a/Swiften/Elements/PubSubAffiliations.h b/Swiften/Elements/PubSubAffiliations.h new file mode 100644 index 0000000..6a413fe --- /dev/null +++ b/Swiften/Elements/PubSubAffiliations.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <boost/optional.hpp> +#include <boost/shared_ptr.hpp> +#include <vector> +#include <string> + +#include <Swiften/Elements/PubSubAffiliation.h> +#include <Swiften/Elements/PubSubPayload.h> + +namespace Swift { + class SWIFTEN_API PubSubAffiliations : public PubSubPayload { + public: + + PubSubAffiliations(); + + virtual ~PubSubAffiliations(); + + const boost::optional< std::string >& getNode() const { + return node; + } + + void setNode(const boost::optional< std::string >& value) { + this->node = value ; + } + + const std::vector< boost::shared_ptr<PubSubAffiliation> >& getAffiliations() const { + return affiliations; + } + + void setAffiliations(const std::vector< boost::shared_ptr<PubSubAffiliation> >& value) { + this->affiliations = value ; + } + + void addAffiliation(boost::shared_ptr<PubSubAffiliation> value) { + this->affiliations.push_back(value); + } + + + private: + boost::optional< std::string > node; + std::vector< boost::shared_ptr<PubSubAffiliation> > affiliations; + }; +} diff --git a/Swiften/Elements/PubSubConfigure.cpp b/Swiften/Elements/PubSubConfigure.cpp new file mode 100644 index 0000000..b1a6cb3 --- /dev/null +++ b/Swiften/Elements/PubSubConfigure.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubConfigure.h> + +using namespace Swift; + +PubSubConfigure::PubSubConfigure() { +} + +PubSubConfigure::~PubSubConfigure() { +} diff --git a/Swiften/Elements/PubSubConfigure.h b/Swiften/Elements/PubSubConfigure.h new file mode 100644 index 0000000..ed91832 --- /dev/null +++ b/Swiften/Elements/PubSubConfigure.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <boost/shared_ptr.hpp> + +#include <Swiften/Elements/Form.h> + +namespace Swift { + class SWIFTEN_API PubSubConfigure : public Payload { + public: + + PubSubConfigure(); + + virtual ~PubSubConfigure(); + + boost::shared_ptr<Form> getData() const { + return data; + } + + void setData(boost::shared_ptr<Form> value) { + this->data = value ; + } + + + private: + boost::shared_ptr<Form> data; + }; +} diff --git a/Swiften/Elements/PubSubCreate.cpp b/Swiften/Elements/PubSubCreate.cpp new file mode 100644 index 0000000..9c60de3 --- /dev/null +++ b/Swiften/Elements/PubSubCreate.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubCreate.h> + +using namespace Swift; + +PubSubCreate::PubSubCreate() { +} + +PubSubCreate::~PubSubCreate() { +} diff --git a/Swiften/Elements/PubSubCreate.h b/Swiften/Elements/PubSubCreate.h new file mode 100644 index 0000000..4e4eb92 --- /dev/null +++ b/Swiften/Elements/PubSubCreate.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <boost/shared_ptr.hpp> +#include <string> + +#include <Swiften/Elements/PubSubConfigure.h> +#include <Swiften/Elements/PubSubPayload.h> + +namespace Swift { + class SWIFTEN_API PubSubCreate : public PubSubPayload { + public: + + PubSubCreate(); + PubSubCreate(const std::string& node) : node(node) {} + virtual ~PubSubCreate(); + + const std::string& getNode() const { + return node; + } + + void setNode(const std::string& value) { + this->node = value ; + } + + boost::shared_ptr<PubSubConfigure> getConfigure() const { + return configure; + } + + void setConfigure(boost::shared_ptr<PubSubConfigure> value) { + this->configure = value ; + } + + + private: + std::string node; + boost::shared_ptr<PubSubConfigure> configure; + }; +} diff --git a/Swiften/Elements/PubSubDefault.cpp b/Swiften/Elements/PubSubDefault.cpp new file mode 100644 index 0000000..923d0ad --- /dev/null +++ b/Swiften/Elements/PubSubDefault.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubDefault.h> + +using namespace Swift; + +PubSubDefault::PubSubDefault() : type(None) { +} + +PubSubDefault::~PubSubDefault() { +} diff --git a/Swiften/Elements/PubSubDefault.h b/Swiften/Elements/PubSubDefault.h new file mode 100644 index 0000000..08326e7 --- /dev/null +++ b/Swiften/Elements/PubSubDefault.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <boost/optional.hpp> +#include <string> + +#include <Swiften/Elements/PubSubPayload.h> + +namespace Swift { + class SWIFTEN_API PubSubDefault : public PubSubPayload { + public: + enum Type { + None, + Collection, + Leaf + }; + + PubSubDefault(); + + virtual ~PubSubDefault(); + + const boost::optional< std::string >& getNode() const { + return node; + } + + void setNode(const boost::optional< std::string >& value) { + this->node = value ; + } + + Type getType() const { + return type; + } + + void setType(Type value) { + this->type = value ; + } + + + private: + boost::optional< std::string > node; + Type type; + }; +} diff --git a/Swiften/Elements/PubSubError.cpp b/Swiften/Elements/PubSubError.cpp new file mode 100644 index 0000000..db07972 --- /dev/null +++ b/Swiften/Elements/PubSubError.cpp @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubError.h> + +using namespace Swift; + +PubSubError::~PubSubError() { +} diff --git a/Swiften/Elements/PubSubError.h b/Swiften/Elements/PubSubError.h new file mode 100644 index 0000000..3748e44 --- /dev/null +++ b/Swiften/Elements/PubSubError.h @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Elements/Payload.h> + +namespace Swift { + class SWIFTEN_API PubSubError : public Payload { + public: + enum Type { + UnknownType = 0, + ClosedNode, + ConfigurationRequired, + InvalidJID, + InvalidOptions, + InvalidPayload, + InvalidSubscriptionID, + ItemForbidden, + ItemRequired, + JIDRequired, + MaximumItemsExceeded, + MaximumNodesExceeded, + NodeIDRequired, + NotInRosterGroup, + NotSubscribed, + PayloadTooBig, + PayloadRequired, + PendingSubscription, + PresenceSubscriptionRequired, + SubscriptionIDRequired, + TooManySubscriptions, + Unsupported, + UnsupportedAccessModel + }; + + enum UnsupportedFeatureType { + UnknownUnsupportedFeatureType = 0, + AccessAuthorize, + AccessOpen, + AccessPresence, + AccessRoster, + AccessWhitelist, + AutoCreate, + AutoSubscribe, + Collections, + ConfigNode, + CreateAndConfigure, + CreateNodes, + DeleteItems, + DeleteNodes, + FilteredNotifications, + GetPending, + InstantNodes, + ItemIDs, + LastPublished, + LeasedSubscription, + ManageSubscriptions, + MemberAffiliation, + MetaData, + ModifyAffiliations, + MultiCollection, + MultiSubscribe, + OutcastAffiliation, + PersistentItems, + PresenceNotifications, + PresenceSubscribe, + Publish, + PublishOptions, + PublishOnlyAffiliation, + PublisherAffiliation, + PurgeNodes, + RetractItems, + RetrieveAffiliations, + RetrieveDefault, + RetrieveItems, + RetrieveSubscriptions, + Subscribe, + SubscriptionOptions, + SubscriptionNotifications + }; + + PubSubError(Type type = UnknownType) : type(type), unsupportedType(UnknownUnsupportedFeatureType) { + } + + virtual ~PubSubError(); + + Type getType() const { + return type; + } + + void setType(Type type) { + this->type = type; + } + + UnsupportedFeatureType getUnsupportedFeatureType() const { + return unsupportedType; + } + + void setUnsupportedFeatureType(UnsupportedFeatureType unsupportedType) { + this->unsupportedType = unsupportedType; + } + + private: + Type type; + UnsupportedFeatureType unsupportedType; + }; +} diff --git a/Swiften/Elements/PubSubEvent.cpp b/Swiften/Elements/PubSubEvent.cpp new file mode 100644 index 0000000..1b63134 --- /dev/null +++ b/Swiften/Elements/PubSubEvent.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubEvent.h> + +using namespace Swift; + +PubSubEvent::PubSubEvent() { +} + +PubSubEvent::~PubSubEvent() { +} diff --git a/Swiften/Elements/PubSubEvent.h b/Swiften/Elements/PubSubEvent.h new file mode 100644 index 0000000..9ef6d89 --- /dev/null +++ b/Swiften/Elements/PubSubEvent.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <boost/shared_ptr.hpp> + +#include <Swiften/Elements/ContainerPayload.h> +#include <Swiften/Elements/PubSubEventPayload.h> + +namespace Swift { + class SWIFTEN_API PubSubEvent : public ContainerPayload<PubSubEventPayload> { + public: + PubSubEvent(); + virtual ~PubSubEvent(); + }; +} diff --git a/Swiften/Elements/PubSubEventAssociate.cpp b/Swiften/Elements/PubSubEventAssociate.cpp new file mode 100644 index 0000000..cb81b46 --- /dev/null +++ b/Swiften/Elements/PubSubEventAssociate.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubEventAssociate.h> + +using namespace Swift; + +PubSubEventAssociate::PubSubEventAssociate() { +} + +PubSubEventAssociate::~PubSubEventAssociate() { +} diff --git a/Swiften/Elements/PubSubEventAssociate.h b/Swiften/Elements/PubSubEventAssociate.h new file mode 100644 index 0000000..a752345 --- /dev/null +++ b/Swiften/Elements/PubSubEventAssociate.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <string> + + + +namespace Swift { + class SWIFTEN_API PubSubEventAssociate : public Payload { + public: + + PubSubEventAssociate(); + + virtual ~PubSubEventAssociate(); + + const std::string& getNode() const { + return node; + } + + void setNode(const std::string& value) { + this->node = value ; + } + + + private: + std::string node; + }; +} diff --git a/Swiften/Elements/PubSubEventCollection.cpp b/Swiften/Elements/PubSubEventCollection.cpp new file mode 100644 index 0000000..a8b2a56 --- /dev/null +++ b/Swiften/Elements/PubSubEventCollection.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubEventCollection.h> + +using namespace Swift; + +PubSubEventCollection::PubSubEventCollection() { +} + +PubSubEventCollection::~PubSubEventCollection() { +} diff --git a/Swiften/Elements/PubSubEventCollection.h b/Swiften/Elements/PubSubEventCollection.h new file mode 100644 index 0000000..e4498aa --- /dev/null +++ b/Swiften/Elements/PubSubEventCollection.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <boost/optional.hpp> +#include <boost/shared_ptr.hpp> +#include <string> + +#include <Swiften/Elements/PubSubEventDisassociate.h> +#include <Swiften/Elements/PubSubEventAssociate.h> +#include <Swiften/Elements/PubSubEventPayload.h> + +namespace Swift { + class SWIFTEN_API PubSubEventCollection : public PubSubEventPayload { + public: + + PubSubEventCollection(); + + virtual ~PubSubEventCollection(); + + const boost::optional< std::string >& getNode() const { + return node; + } + + void setNode(const boost::optional< std::string >& value) { + this->node = value ; + } + + boost::shared_ptr<PubSubEventDisassociate> getDisassociate() const { + return disassociate; + } + + void setDisassociate(boost::shared_ptr<PubSubEventDisassociate> value) { + this->disassociate = value ; + } + + boost::shared_ptr<PubSubEventAssociate> getAssociate() const { + return associate; + } + + void setAssociate(boost::shared_ptr<PubSubEventAssociate> value) { + this->associate = value ; + } + + + private: + boost::optional< std::string > node; + boost::shared_ptr<PubSubEventDisassociate> disassociate; + boost::shared_ptr<PubSubEventAssociate> associate; + }; +} diff --git a/Swiften/Elements/PubSubEventConfiguration.cpp b/Swiften/Elements/PubSubEventConfiguration.cpp new file mode 100644 index 0000000..93ce6a3 --- /dev/null +++ b/Swiften/Elements/PubSubEventConfiguration.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubEventConfiguration.h> + +using namespace Swift; + +PubSubEventConfiguration::PubSubEventConfiguration() { +} + +PubSubEventConfiguration::~PubSubEventConfiguration() { +} diff --git a/Swiften/Elements/PubSubEventConfiguration.h b/Swiften/Elements/PubSubEventConfiguration.h new file mode 100644 index 0000000..7ebfce1 --- /dev/null +++ b/Swiften/Elements/PubSubEventConfiguration.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <boost/shared_ptr.hpp> +#include <string> + +#include <Swiften/Elements/Form.h> +#include <Swiften/Elements/PubSubEventPayload.h> + +namespace Swift { + class SWIFTEN_API PubSubEventConfiguration : public PubSubEventPayload { + public: + + PubSubEventConfiguration(); + + virtual ~PubSubEventConfiguration(); + + const std::string& getNode() const { + return node; + } + + void setNode(const std::string& value) { + this->node = value ; + } + + boost::shared_ptr<Form> getData() const { + return data; + } + + void setData(boost::shared_ptr<Form> value) { + this->data = value ; + } + + + private: + std::string node; + boost::shared_ptr<Form> data; + }; +} diff --git a/Swiften/Elements/PubSubEventDelete.cpp b/Swiften/Elements/PubSubEventDelete.cpp new file mode 100644 index 0000000..85bbf2e --- /dev/null +++ b/Swiften/Elements/PubSubEventDelete.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubEventDelete.h> + +using namespace Swift; + +PubSubEventDelete::PubSubEventDelete() { +} + +PubSubEventDelete::~PubSubEventDelete() { +} diff --git a/Swiften/Elements/PubSubEventDelete.h b/Swiften/Elements/PubSubEventDelete.h new file mode 100644 index 0000000..fecfb0e --- /dev/null +++ b/Swiften/Elements/PubSubEventDelete.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <boost/shared_ptr.hpp> +#include <string> + +#include <Swiften/Elements/PubSubEventRedirect.h> +#include <Swiften/Elements/PubSubEventPayload.h> + +namespace Swift { + class SWIFTEN_API PubSubEventDelete : public PubSubEventPayload { + public: + + PubSubEventDelete(); + + virtual ~PubSubEventDelete(); + + const std::string& getNode() const { + return node; + } + + void setNode(const std::string& value) { + this->node = value ; + } + + boost::shared_ptr<PubSubEventRedirect> getRedirects() const { + return redirects; + } + + void setRedirects(boost::shared_ptr<PubSubEventRedirect> value) { + this->redirects = value ; + } + + + private: + std::string node; + boost::shared_ptr<PubSubEventRedirect> redirects; + }; +} diff --git a/Swiften/Elements/PubSubEventDisassociate.cpp b/Swiften/Elements/PubSubEventDisassociate.cpp new file mode 100644 index 0000000..55e1c4e --- /dev/null +++ b/Swiften/Elements/PubSubEventDisassociate.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubEventDisassociate.h> + +using namespace Swift; + +PubSubEventDisassociate::PubSubEventDisassociate() { +} + +PubSubEventDisassociate::~PubSubEventDisassociate() { +} diff --git a/Swiften/Elements/PubSubEventDisassociate.h b/Swiften/Elements/PubSubEventDisassociate.h new file mode 100644 index 0000000..cad9843 --- /dev/null +++ b/Swiften/Elements/PubSubEventDisassociate.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <string> + + + +namespace Swift { + class SWIFTEN_API PubSubEventDisassociate : public Payload { + public: + + PubSubEventDisassociate(); + + virtual ~PubSubEventDisassociate(); + + const std::string& getNode() const { + return node; + } + + void setNode(const std::string& value) { + this->node = value ; + } + + + private: + std::string node; + }; +} diff --git a/Swiften/Elements/PubSubEventItem.cpp b/Swiften/Elements/PubSubEventItem.cpp new file mode 100644 index 0000000..6bb3823 --- /dev/null +++ b/Swiften/Elements/PubSubEventItem.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubEventItem.h> + +using namespace Swift; + +PubSubEventItem::PubSubEventItem() { +} + +PubSubEventItem::~PubSubEventItem() { +} diff --git a/Swiften/Elements/PubSubEventItem.h b/Swiften/Elements/PubSubEventItem.h new file mode 100644 index 0000000..25ebc82 --- /dev/null +++ b/Swiften/Elements/PubSubEventItem.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <boost/optional.hpp> +#include <boost/shared_ptr.hpp> +#include <vector> +#include <string> + +#include <Swiften/Elements/Payload.h> + +namespace Swift { + class SWIFTEN_API PubSubEventItem : public Payload { + public: + + PubSubEventItem(); + + virtual ~PubSubEventItem(); + + const boost::optional< std::string >& getNode() const { + return node; + } + + void setNode(const boost::optional< std::string >& value) { + this->node = value ; + } + + const boost::optional< std::string >& getPublisher() const { + return publisher; + } + + void setPublisher(const boost::optional< std::string >& value) { + this->publisher = value ; + } + + const std::vector< boost::shared_ptr<Payload> >& getData() const { + return data; + } + + void setData(const std::vector< boost::shared_ptr<Payload> >& value) { + this->data = value ; + } + + void addData(boost::shared_ptr<Payload> value) { + this->data.push_back(value); + } + + const boost::optional< std::string >& getID() const { + return id; + } + + void setID(const boost::optional< std::string >& value) { + this->id = value ; + } + + + private: + boost::optional< std::string > node; + boost::optional< std::string > publisher; + std::vector< boost::shared_ptr<Payload> > data; + boost::optional< std::string > id; + }; +} diff --git a/Swiften/Elements/PubSubEventItems.cpp b/Swiften/Elements/PubSubEventItems.cpp new file mode 100644 index 0000000..01f3429 --- /dev/null +++ b/Swiften/Elements/PubSubEventItems.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubEventItems.h> + +using namespace Swift; + +PubSubEventItems::PubSubEventItems() { +} + +PubSubEventItems::~PubSubEventItems() { +} diff --git a/Swiften/Elements/PubSubEventItems.h b/Swiften/Elements/PubSubEventItems.h new file mode 100644 index 0000000..a121728 --- /dev/null +++ b/Swiften/Elements/PubSubEventItems.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <boost/shared_ptr.hpp> +#include <vector> +#include <string> + +#include <Swiften/Elements/PubSubEventItem.h> +#include <Swiften/Elements/PubSubEventRetract.h> +#include <Swiften/Elements/PubSubEventPayload.h> + +namespace Swift { + class SWIFTEN_API PubSubEventItems : public PubSubEventPayload { + public: + + PubSubEventItems(); + + virtual ~PubSubEventItems(); + + const std::string& getNode() const { + return node; + } + + void setNode(const std::string& value) { + this->node = value ; + } + + const std::vector< boost::shared_ptr<PubSubEventItem> >& getItems() const { + return items; + } + + void setItems(const std::vector< boost::shared_ptr<PubSubEventItem> >& value) { + this->items = value ; + } + + void addItem(boost::shared_ptr<PubSubEventItem> value) { + this->items.push_back(value); + } + + const std::vector< boost::shared_ptr<PubSubEventRetract> >& getRetracts() const { + return retracts; + } + + void setRetracts(const std::vector< boost::shared_ptr<PubSubEventRetract> >& value) { + this->retracts = value ; + } + + void addRetract(boost::shared_ptr<PubSubEventRetract> value) { + this->retracts.push_back(value); + } + + + private: + std::string node; + std::vector< boost::shared_ptr<PubSubEventItem> > items; + std::vector< boost::shared_ptr<PubSubEventRetract> > retracts; + }; +} diff --git a/Swiften/Elements/PubSubEventPayload.cpp b/Swiften/Elements/PubSubEventPayload.cpp new file mode 100644 index 0000000..0019942 --- /dev/null +++ b/Swiften/Elements/PubSubEventPayload.cpp @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubEventPayload.h> + +using namespace Swift; + +PubSubEventPayload::~PubSubEventPayload() { +} diff --git a/Swiften/Elements/PubSubEventPayload.h b/Swiften/Elements/PubSubEventPayload.h new file mode 100644 index 0000000..81fb9a8 --- /dev/null +++ b/Swiften/Elements/PubSubEventPayload.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> + +namespace Swift { + class SWIFTEN_API PubSubEventPayload : public Payload { + public: + virtual ~PubSubEventPayload(); + }; +} diff --git a/Swiften/Elements/PubSubEventPurge.cpp b/Swiften/Elements/PubSubEventPurge.cpp new file mode 100644 index 0000000..3fd77ed --- /dev/null +++ b/Swiften/Elements/PubSubEventPurge.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubEventPurge.h> + +using namespace Swift; + +PubSubEventPurge::PubSubEventPurge() { +} + +PubSubEventPurge::~PubSubEventPurge() { +} diff --git a/Swiften/Elements/PubSubEventPurge.h b/Swiften/Elements/PubSubEventPurge.h new file mode 100644 index 0000000..5f04049 --- /dev/null +++ b/Swiften/Elements/PubSubEventPurge.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <string> + +#include <Swiften/Elements/PubSubEventPayload.h> + +namespace Swift { + class SWIFTEN_API PubSubEventPurge : public PubSubEventPayload { + public: + + PubSubEventPurge(); + + virtual ~PubSubEventPurge(); + + const std::string& getNode() const { + return node; + } + + void setNode(const std::string& value) { + this->node = value ; + } + + + private: + std::string node; + }; +} diff --git a/Swiften/Elements/PubSubEventRedirect.cpp b/Swiften/Elements/PubSubEventRedirect.cpp new file mode 100644 index 0000000..adde8bc --- /dev/null +++ b/Swiften/Elements/PubSubEventRedirect.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubEventRedirect.h> + +using namespace Swift; + +PubSubEventRedirect::PubSubEventRedirect() { +} + +PubSubEventRedirect::~PubSubEventRedirect() { +} diff --git a/Swiften/Elements/PubSubEventRedirect.h b/Swiften/Elements/PubSubEventRedirect.h new file mode 100644 index 0000000..918c7f4 --- /dev/null +++ b/Swiften/Elements/PubSubEventRedirect.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <string> + + + +namespace Swift { + class SWIFTEN_API PubSubEventRedirect : public Payload { + public: + + PubSubEventRedirect(); + + virtual ~PubSubEventRedirect(); + + const std::string& getURI() const { + return uri; + } + + void setURI(const std::string& value) { + this->uri = value ; + } + + + private: + std::string uri; + }; +} diff --git a/Swiften/Elements/PubSubEventRetract.cpp b/Swiften/Elements/PubSubEventRetract.cpp new file mode 100644 index 0000000..bb3ebb1 --- /dev/null +++ b/Swiften/Elements/PubSubEventRetract.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubEventRetract.h> + +using namespace Swift; + +PubSubEventRetract::PubSubEventRetract() { +} + +PubSubEventRetract::~PubSubEventRetract() { +} diff --git a/Swiften/Elements/PubSubEventRetract.h b/Swiften/Elements/PubSubEventRetract.h new file mode 100644 index 0000000..3c2d9c4 --- /dev/null +++ b/Swiften/Elements/PubSubEventRetract.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <string> + + + +namespace Swift { + class SWIFTEN_API PubSubEventRetract : public Payload { + public: + + PubSubEventRetract(); + + virtual ~PubSubEventRetract(); + + const std::string& getID() const { + return id; + } + + void setID(const std::string& value) { + this->id = value ; + } + + + private: + std::string id; + }; +} diff --git a/Swiften/Elements/PubSubEventSubscription.cpp b/Swiften/Elements/PubSubEventSubscription.cpp new file mode 100644 index 0000000..fb069f9 --- /dev/null +++ b/Swiften/Elements/PubSubEventSubscription.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubEventSubscription.h> + +using namespace Swift; + +PubSubEventSubscription::PubSubEventSubscription() : subscription(None) { +} + +PubSubEventSubscription::~PubSubEventSubscription() { +} diff --git a/Swiften/Elements/PubSubEventSubscription.h b/Swiften/Elements/PubSubEventSubscription.h new file mode 100644 index 0000000..b74d4f5 --- /dev/null +++ b/Swiften/Elements/PubSubEventSubscription.h @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <boost/optional.hpp> +#include <string> +#include <boost/date_time/posix_time/posix_time_types.hpp> + +#include <Swiften/JID/JID.h> +#include <Swiften/Elements/PubSubEventPayload.h> + +namespace Swift { + class SWIFTEN_API PubSubEventSubscription : public PubSubEventPayload { + public: + enum SubscriptionType { + None, + Pending, + Subscribed, + Unconfigured + }; + + PubSubEventSubscription(); + + virtual ~PubSubEventSubscription(); + + const std::string& getNode() const { + return node; + } + + void setNode(const std::string& value) { + this->node = value ; + } + + const JID& getJID() const { + return jid; + } + + void setJID(const JID& value) { + this->jid = value ; + } + + SubscriptionType getSubscription() const { + return subscription; + } + + void setSubscription(SubscriptionType value) { + this->subscription = value ; + } + + const boost::optional< std::string >& getSubscriptionID() const { + return subscriptionID; + } + + void setSubscriptionID(const boost::optional< std::string >& value) { + this->subscriptionID = value ; + } + + const boost::posix_time::ptime& getExpiry() const { + return expiry; + } + + void setExpiry(const boost::posix_time::ptime& value) { + this->expiry = value ; + } + + + private: + std::string node; + JID jid; + SubscriptionType subscription; + boost::optional< std::string > subscriptionID; + boost::posix_time::ptime expiry; + }; +} diff --git a/Swiften/Elements/PubSubItem.cpp b/Swiften/Elements/PubSubItem.cpp new file mode 100644 index 0000000..ae6206f --- /dev/null +++ b/Swiften/Elements/PubSubItem.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubItem.h> + +using namespace Swift; + +PubSubItem::PubSubItem() { +} + +PubSubItem::~PubSubItem() { +} diff --git a/Swiften/Elements/PubSubItem.h b/Swiften/Elements/PubSubItem.h new file mode 100644 index 0000000..93ff03a --- /dev/null +++ b/Swiften/Elements/PubSubItem.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <boost/shared_ptr.hpp> +#include <vector> +#include <string> + +#include <Swiften/Elements/Payload.h> + +namespace Swift { + class SWIFTEN_API PubSubItem : public Payload { + public: + + PubSubItem(); + + virtual ~PubSubItem(); + + const std::vector< boost::shared_ptr<Payload> >& getData() const { + return data; + } + + void setData(const std::vector< boost::shared_ptr<Payload> >& value) { + this->data = value ; + } + + void addData(boost::shared_ptr<Payload> value) { + this->data.push_back(value); + } + + const std::string& getID() const { + return id; + } + + void setID(const std::string& value) { + this->id = value ; + } + + + private: + std::vector< boost::shared_ptr<Payload> > data; + std::string id; + }; +} diff --git a/Swiften/Elements/PubSubItems.cpp b/Swiften/Elements/PubSubItems.cpp new file mode 100644 index 0000000..f235e11 --- /dev/null +++ b/Swiften/Elements/PubSubItems.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubItems.h> + +using namespace Swift; + +PubSubItems::PubSubItems() { +} + +PubSubItems::~PubSubItems() { +} diff --git a/Swiften/Elements/PubSubItems.h b/Swiften/Elements/PubSubItems.h new file mode 100644 index 0000000..7cd279b --- /dev/null +++ b/Swiften/Elements/PubSubItems.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <boost/optional.hpp> +#include <boost/shared_ptr.hpp> +#include <vector> +#include <string> + +#include <Swiften/Elements/PubSubItem.h> +#include <Swiften/Elements/PubSubPayload.h> + +namespace Swift { + class SWIFTEN_API PubSubItems : public PubSubPayload { + public: + + PubSubItems(); + PubSubItems(const std::string& node) : node(node) {} + virtual ~PubSubItems(); + + const std::string& getNode() const { + return node; + } + + void setNode(const std::string& value) { + this->node = value ; + } + + const std::vector< boost::shared_ptr<PubSubItem> >& getItems() const { + return items; + } + + void setItems(const std::vector< boost::shared_ptr<PubSubItem> >& value) { + this->items = value ; + } + + void addItem(boost::shared_ptr<PubSubItem> value) { + this->items.push_back(value); + } + + const boost::optional< unsigned int >& getMaximumItems() const { + return maximumItems; + } + + void setMaximumItems(const boost::optional< unsigned int >& value) { + this->maximumItems = value ; + } + + const boost::optional< std::string >& getSubscriptionID() const { + return subscriptionID; + } + + void setSubscriptionID(const boost::optional< std::string >& value) { + this->subscriptionID = value ; + } + + + private: + std::string node; + std::vector< boost::shared_ptr<PubSubItem> > items; + boost::optional< unsigned int > maximumItems; + boost::optional< std::string > subscriptionID; + }; +} diff --git a/Swiften/Elements/PubSubOptions.cpp b/Swiften/Elements/PubSubOptions.cpp new file mode 100644 index 0000000..22c4054 --- /dev/null +++ b/Swiften/Elements/PubSubOptions.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubOptions.h> + +using namespace Swift; + +PubSubOptions::PubSubOptions() { +} + +PubSubOptions::~PubSubOptions() { +} diff --git a/Swiften/Elements/PubSubOptions.h b/Swiften/Elements/PubSubOptions.h new file mode 100644 index 0000000..0e9483e --- /dev/null +++ b/Swiften/Elements/PubSubOptions.h @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <boost/optional.hpp> +#include <boost/shared_ptr.hpp> +#include <string> + +#include <Swiften/Elements/Form.h> +#include <Swiften/Elements/PubSubPayload.h> +#include <Swiften/JID/JID.h> + +namespace Swift { + class SWIFTEN_API PubSubOptions : public PubSubPayload { + public: + + PubSubOptions(); + + virtual ~PubSubOptions(); + + const std::string& getNode() const { + return node; + } + + void setNode(const std::string& value) { + this->node = value ; + } + + const JID& getJID() const { + return jid; + } + + void setJID(const JID& value) { + this->jid = value ; + } + + boost::shared_ptr<Form> getData() const { + return data; + } + + void setData(boost::shared_ptr<Form> value) { + this->data = value ; + } + + const boost::optional< std::string >& getSubscriptionID() const { + return subscriptionID; + } + + void setSubscriptionID(const boost::optional< std::string >& value) { + this->subscriptionID = value ; + } + + + private: + std::string node; + JID jid; + boost::shared_ptr<Form> data; + boost::optional< std::string > subscriptionID; + }; +} diff --git a/Swiften/Elements/PubSubOwnerAffiliation.cpp b/Swiften/Elements/PubSubOwnerAffiliation.cpp new file mode 100644 index 0000000..8dc8be6 --- /dev/null +++ b/Swiften/Elements/PubSubOwnerAffiliation.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubOwnerAffiliation.h> + +using namespace Swift; + +PubSubOwnerAffiliation::PubSubOwnerAffiliation() : type(None) { +} + +PubSubOwnerAffiliation::~PubSubOwnerAffiliation() { +} diff --git a/Swiften/Elements/PubSubOwnerAffiliation.h b/Swiften/Elements/PubSubOwnerAffiliation.h new file mode 100644 index 0000000..68851d3 --- /dev/null +++ b/Swiften/Elements/PubSubOwnerAffiliation.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> + + +#include <Swiften/JID/JID.h> + +namespace Swift { + class SWIFTEN_API PubSubOwnerAffiliation : public Payload { + public: + enum Type { + None, + Member, + Outcast, + Owner, + Publisher, + PublishOnly + }; + + PubSubOwnerAffiliation(); + + virtual ~PubSubOwnerAffiliation(); + + const JID& getJID() const { + return jid; + } + + void setJID(const JID& value) { + this->jid = value ; + } + + Type getType() const { + return type; + } + + void setType(Type value) { + this->type = value ; + } + + + private: + JID jid; + Type type; + }; +} diff --git a/Swiften/Elements/PubSubOwnerAffiliations.cpp b/Swiften/Elements/PubSubOwnerAffiliations.cpp new file mode 100644 index 0000000..b87a78a --- /dev/null +++ b/Swiften/Elements/PubSubOwnerAffiliations.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubOwnerAffiliations.h> + +using namespace Swift; + +PubSubOwnerAffiliations::PubSubOwnerAffiliations() { +} + +PubSubOwnerAffiliations::~PubSubOwnerAffiliations() { +} diff --git a/Swiften/Elements/PubSubOwnerAffiliations.h b/Swiften/Elements/PubSubOwnerAffiliations.h new file mode 100644 index 0000000..75578df --- /dev/null +++ b/Swiften/Elements/PubSubOwnerAffiliations.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <boost/shared_ptr.hpp> +#include <vector> +#include <string> + +#include <Swiften/Elements/PubSubOwnerPayload.h> +#include <Swiften/Elements/PubSubOwnerAffiliation.h> + +namespace Swift { + class SWIFTEN_API PubSubOwnerAffiliations : public PubSubOwnerPayload { + public: + + PubSubOwnerAffiliations(); + + virtual ~PubSubOwnerAffiliations(); + + const std::string& getNode() const { + return node; + } + + void setNode(const std::string& value) { + this->node = value ; + } + + const std::vector< boost::shared_ptr<PubSubOwnerAffiliation> >& getAffiliations() const { + return affiliations; + } + + void setAffiliations(const std::vector< boost::shared_ptr<PubSubOwnerAffiliation> >& value) { + this->affiliations = value ; + } + + void addAffiliation(boost::shared_ptr<PubSubOwnerAffiliation> value) { + this->affiliations.push_back(value); + } + + + private: + std::string node; + std::vector< boost::shared_ptr<PubSubOwnerAffiliation> > affiliations; + }; +} diff --git a/Swiften/Elements/PubSubOwnerConfigure.cpp b/Swiften/Elements/PubSubOwnerConfigure.cpp new file mode 100644 index 0000000..8db923d --- /dev/null +++ b/Swiften/Elements/PubSubOwnerConfigure.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubOwnerConfigure.h> + +using namespace Swift; + +PubSubOwnerConfigure::PubSubOwnerConfigure() { +} + +PubSubOwnerConfigure::~PubSubOwnerConfigure() { +} diff --git a/Swiften/Elements/PubSubOwnerConfigure.h b/Swiften/Elements/PubSubOwnerConfigure.h new file mode 100644 index 0000000..d882ec4 --- /dev/null +++ b/Swiften/Elements/PubSubOwnerConfigure.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <boost/optional.hpp> +#include <boost/shared_ptr.hpp> +#include <string> + +#include <Swiften/Elements/PubSubOwnerPayload.h> +#include <Swiften/Elements/Form.h> + +namespace Swift { + class SWIFTEN_API PubSubOwnerConfigure : public PubSubOwnerPayload { + public: + + PubSubOwnerConfigure(); + PubSubOwnerConfigure(const std::string& node) : node(node) {} + virtual ~PubSubOwnerConfigure(); + + const boost::optional< std::string >& getNode() const { + return node; + } + + void setNode(const boost::optional< std::string >& value) { + this->node = value ; + } + + boost::shared_ptr<Form> getData() const { + return data; + } + + void setData(boost::shared_ptr<Form> value) { + this->data = value ; + } + + + private: + boost::optional< std::string > node; + boost::shared_ptr<Form> data; + }; +} diff --git a/Swiften/Elements/PubSubOwnerDefault.cpp b/Swiften/Elements/PubSubOwnerDefault.cpp new file mode 100644 index 0000000..ebb51a7 --- /dev/null +++ b/Swiften/Elements/PubSubOwnerDefault.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubOwnerDefault.h> + +using namespace Swift; + +PubSubOwnerDefault::PubSubOwnerDefault() { +} + +PubSubOwnerDefault::~PubSubOwnerDefault() { +} diff --git a/Swiften/Elements/PubSubOwnerDefault.h b/Swiften/Elements/PubSubOwnerDefault.h new file mode 100644 index 0000000..1dbd3a2 --- /dev/null +++ b/Swiften/Elements/PubSubOwnerDefault.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <boost/shared_ptr.hpp> + +#include <Swiften/Elements/PubSubOwnerPayload.h> +#include <Swiften/Elements/Form.h> + +namespace Swift { + class SWIFTEN_API PubSubOwnerDefault : public PubSubOwnerPayload { + public: + + PubSubOwnerDefault(); + + virtual ~PubSubOwnerDefault(); + + boost::shared_ptr<Form> getData() const { + return data; + } + + void setData(boost::shared_ptr<Form> value) { + this->data = value ; + } + + + private: + boost::shared_ptr<Form> data; + }; +} diff --git a/Swiften/Elements/PubSubOwnerDelete.cpp b/Swiften/Elements/PubSubOwnerDelete.cpp new file mode 100644 index 0000000..a785424 --- /dev/null +++ b/Swiften/Elements/PubSubOwnerDelete.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubOwnerDelete.h> + +using namespace Swift; + +PubSubOwnerDelete::PubSubOwnerDelete() { +} + +PubSubOwnerDelete::~PubSubOwnerDelete() { +} diff --git a/Swiften/Elements/PubSubOwnerDelete.h b/Swiften/Elements/PubSubOwnerDelete.h new file mode 100644 index 0000000..c6bb3e9 --- /dev/null +++ b/Swiften/Elements/PubSubOwnerDelete.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <boost/shared_ptr.hpp> +#include <string> + +#include <Swiften/Elements/PubSubOwnerPayload.h> +#include <Swiften/Elements/PubSubOwnerRedirect.h> + +namespace Swift { + class SWIFTEN_API PubSubOwnerDelete : public PubSubOwnerPayload { + public: + + PubSubOwnerDelete(); + PubSubOwnerDelete(const std::string& node) : node(node) {} + virtual ~PubSubOwnerDelete(); + + const std::string& getNode() const { + return node; + } + + void setNode(const std::string& value) { + this->node = value ; + } + + boost::shared_ptr<PubSubOwnerRedirect> getRedirect() const { + return redirect; + } + + void setRedirect(boost::shared_ptr<PubSubOwnerRedirect> value) { + this->redirect = value ; + } + + + private: + std::string node; + boost::shared_ptr<PubSubOwnerRedirect> redirect; + }; +} diff --git a/Swiften/Elements/PubSubOwnerPayload.cpp b/Swiften/Elements/PubSubOwnerPayload.cpp new file mode 100644 index 0000000..92c1dd2 --- /dev/null +++ b/Swiften/Elements/PubSubOwnerPayload.cpp @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubOwnerPayload.h> + +using namespace Swift; + +PubSubOwnerPayload::~PubSubOwnerPayload() { +} diff --git a/Swiften/Elements/PubSubOwnerPayload.h b/Swiften/Elements/PubSubOwnerPayload.h new file mode 100644 index 0000000..a2ddaaa --- /dev/null +++ b/Swiften/Elements/PubSubOwnerPayload.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> + +namespace Swift { + class SWIFTEN_API PubSubOwnerPayload : public Payload { + public: + virtual ~PubSubOwnerPayload(); + }; +} diff --git a/Swiften/Elements/PubSubOwnerPubSub.cpp b/Swiften/Elements/PubSubOwnerPubSub.cpp new file mode 100644 index 0000000..022452d --- /dev/null +++ b/Swiften/Elements/PubSubOwnerPubSub.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubOwnerPubSub.h> + +using namespace Swift; + +PubSubOwnerPubSub::PubSubOwnerPubSub() { +} + +PubSubOwnerPubSub::~PubSubOwnerPubSub() { +} diff --git a/Swiften/Elements/PubSubOwnerPubSub.h b/Swiften/Elements/PubSubOwnerPubSub.h new file mode 100644 index 0000000..dd72abe --- /dev/null +++ b/Swiften/Elements/PubSubOwnerPubSub.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/ContainerPayload.h> + +#include <Swiften/Elements/PubSubOwnerPayload.h> + +namespace Swift { + class SWIFTEN_API PubSubOwnerPubSub : public ContainerPayload<PubSubOwnerPayload> { + public: + PubSubOwnerPubSub(); + virtual ~PubSubOwnerPubSub(); + }; +} diff --git a/Swiften/Elements/PubSubOwnerPurge.cpp b/Swiften/Elements/PubSubOwnerPurge.cpp new file mode 100644 index 0000000..d0ac57d --- /dev/null +++ b/Swiften/Elements/PubSubOwnerPurge.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubOwnerPurge.h> + +using namespace Swift; + +PubSubOwnerPurge::PubSubOwnerPurge() { +} + +PubSubOwnerPurge::~PubSubOwnerPurge() { +} diff --git a/Swiften/Elements/PubSubOwnerPurge.h b/Swiften/Elements/PubSubOwnerPurge.h new file mode 100644 index 0000000..fc410f8 --- /dev/null +++ b/Swiften/Elements/PubSubOwnerPurge.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <string> + +#include <Swiften/Elements/PubSubOwnerPayload.h> + +namespace Swift { + class SWIFTEN_API PubSubOwnerPurge : public PubSubOwnerPayload { + public: + + PubSubOwnerPurge(); + + virtual ~PubSubOwnerPurge(); + + const std::string& getNode() const { + return node; + } + + void setNode(const std::string& value) { + this->node = value ; + } + + + private: + std::string node; + }; +} diff --git a/Swiften/Elements/PubSubOwnerRedirect.cpp b/Swiften/Elements/PubSubOwnerRedirect.cpp new file mode 100644 index 0000000..164c216 --- /dev/null +++ b/Swiften/Elements/PubSubOwnerRedirect.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubOwnerRedirect.h> + +using namespace Swift; + +PubSubOwnerRedirect::PubSubOwnerRedirect() { +} + +PubSubOwnerRedirect::~PubSubOwnerRedirect() { +} diff --git a/Swiften/Elements/PubSubOwnerRedirect.h b/Swiften/Elements/PubSubOwnerRedirect.h new file mode 100644 index 0000000..61db1d1 --- /dev/null +++ b/Swiften/Elements/PubSubOwnerRedirect.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <string> + + + +namespace Swift { + class SWIFTEN_API PubSubOwnerRedirect : public Payload { + public: + + PubSubOwnerRedirect(); + + virtual ~PubSubOwnerRedirect(); + + const std::string& getURI() const { + return uri; + } + + void setURI(const std::string& value) { + this->uri = value ; + } + + + private: + std::string uri; + }; +} diff --git a/Swiften/Elements/PubSubOwnerSubscription.cpp b/Swiften/Elements/PubSubOwnerSubscription.cpp new file mode 100644 index 0000000..3334e36 --- /dev/null +++ b/Swiften/Elements/PubSubOwnerSubscription.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubOwnerSubscription.h> + +using namespace Swift; + +PubSubOwnerSubscription::PubSubOwnerSubscription() : subscription(None) { +} + +PubSubOwnerSubscription::~PubSubOwnerSubscription() { +} diff --git a/Swiften/Elements/PubSubOwnerSubscription.h b/Swiften/Elements/PubSubOwnerSubscription.h new file mode 100644 index 0000000..1c302df --- /dev/null +++ b/Swiften/Elements/PubSubOwnerSubscription.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> + + +#include <Swiften/JID/JID.h> + +namespace Swift { + class SWIFTEN_API PubSubOwnerSubscription : public Payload { + public: + enum SubscriptionType { + None, + Pending, + Subscribed, + Unconfigured + }; + + PubSubOwnerSubscription(); + + virtual ~PubSubOwnerSubscription(); + + const JID& getJID() const { + return jid; + } + + void setJID(const JID& value) { + this->jid = value ; + } + + SubscriptionType getSubscription() const { + return subscription; + } + + void setSubscription(SubscriptionType value) { + this->subscription = value ; + } + + + private: + JID jid; + SubscriptionType subscription; + }; +} diff --git a/Swiften/Elements/PubSubOwnerSubscriptions.cpp b/Swiften/Elements/PubSubOwnerSubscriptions.cpp new file mode 100644 index 0000000..a4deb59 --- /dev/null +++ b/Swiften/Elements/PubSubOwnerSubscriptions.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubOwnerSubscriptions.h> + +using namespace Swift; + +PubSubOwnerSubscriptions::PubSubOwnerSubscriptions() { +} + +PubSubOwnerSubscriptions::~PubSubOwnerSubscriptions() { +} diff --git a/Swiften/Elements/PubSubOwnerSubscriptions.h b/Swiften/Elements/PubSubOwnerSubscriptions.h new file mode 100644 index 0000000..08a2f5c --- /dev/null +++ b/Swiften/Elements/PubSubOwnerSubscriptions.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <boost/shared_ptr.hpp> +#include <vector> +#include <string> + +#include <Swiften/Elements/PubSubOwnerPayload.h> +#include <Swiften/Elements/PubSubOwnerSubscription.h> + +namespace Swift { + class SWIFTEN_API PubSubOwnerSubscriptions : public PubSubOwnerPayload { + public: + + PubSubOwnerSubscriptions(); + + virtual ~PubSubOwnerSubscriptions(); + + const std::string& getNode() const { + return node; + } + + void setNode(const std::string& value) { + this->node = value ; + } + + const std::vector< boost::shared_ptr<PubSubOwnerSubscription> >& getSubscriptions() const { + return subscriptions; + } + + void setSubscriptions(const std::vector< boost::shared_ptr<PubSubOwnerSubscription> >& value) { + this->subscriptions = value ; + } + + void addSubscription(boost::shared_ptr<PubSubOwnerSubscription> value) { + this->subscriptions.push_back(value); + } + + + private: + std::string node; + std::vector< boost::shared_ptr<PubSubOwnerSubscription> > subscriptions; + }; +} diff --git a/Swiften/Elements/PubSubPayload.cpp b/Swiften/Elements/PubSubPayload.cpp new file mode 100644 index 0000000..b529959 --- /dev/null +++ b/Swiften/Elements/PubSubPayload.cpp @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubPayload.h> + +using namespace Swift; + +PubSubPayload::~PubSubPayload() { +} diff --git a/Swiften/Elements/PubSubPayload.h b/Swiften/Elements/PubSubPayload.h new file mode 100644 index 0000000..476939b --- /dev/null +++ b/Swiften/Elements/PubSubPayload.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> + +namespace Swift { + class SWIFTEN_API PubSubPayload : public Payload { + public: + virtual ~PubSubPayload(); + }; +} diff --git a/Swiften/Elements/PubSubPublish.cpp b/Swiften/Elements/PubSubPublish.cpp new file mode 100644 index 0000000..2ee3880 --- /dev/null +++ b/Swiften/Elements/PubSubPublish.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubPublish.h> + +using namespace Swift; + +PubSubPublish::PubSubPublish() { +} + +PubSubPublish::~PubSubPublish() { +} diff --git a/Swiften/Elements/PubSubPublish.h b/Swiften/Elements/PubSubPublish.h new file mode 100644 index 0000000..1d99420 --- /dev/null +++ b/Swiften/Elements/PubSubPublish.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <boost/shared_ptr.hpp> +#include <vector> +#include <string> + +#include <Swiften/Elements/PubSubItem.h> +#include <Swiften/Elements/PubSubPayload.h> + +namespace Swift { + class SWIFTEN_API PubSubPublish : public PubSubPayload { + public: + + PubSubPublish(); + + virtual ~PubSubPublish(); + + const std::string& getNode() const { + return node; + } + + void setNode(const std::string& value) { + this->node = value ; + } + + const std::vector< boost::shared_ptr<PubSubItem> >& getItems() const { + return items; + } + + void setItems(const std::vector< boost::shared_ptr<PubSubItem> >& value) { + this->items = value ; + } + + void addItem(boost::shared_ptr<PubSubItem> value) { + this->items.push_back(value); + } + + + private: + std::string node; + std::vector< boost::shared_ptr<PubSubItem> > items; + }; +} diff --git a/Swiften/Elements/PubSubRetract.cpp b/Swiften/Elements/PubSubRetract.cpp new file mode 100644 index 0000000..7e3676e --- /dev/null +++ b/Swiften/Elements/PubSubRetract.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubRetract.h> + +using namespace Swift; + +PubSubRetract::PubSubRetract() { +} + +PubSubRetract::~PubSubRetract() { +} diff --git a/Swiften/Elements/PubSubRetract.h b/Swiften/Elements/PubSubRetract.h new file mode 100644 index 0000000..e55897b --- /dev/null +++ b/Swiften/Elements/PubSubRetract.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <boost/shared_ptr.hpp> +#include <vector> +#include <string> + +#include <Swiften/Elements/PubSubItem.h> +#include <Swiften/Elements/PubSubPayload.h> + +namespace Swift { + class SWIFTEN_API PubSubRetract : public PubSubPayload { + public: + + PubSubRetract(); + + virtual ~PubSubRetract(); + + const std::string& getNode() const { + return node; + } + + void setNode(const std::string& value) { + this->node = value ; + } + + const std::vector< boost::shared_ptr<PubSubItem> >& getItems() const { + return items; + } + + void setItems(const std::vector< boost::shared_ptr<PubSubItem> >& value) { + this->items = value ; + } + + void addItem(boost::shared_ptr<PubSubItem> value) { + this->items.push_back(value); + } + + bool isNotify() const { + return notify; + } + + void setNotify(bool value) { + this->notify = value ; + } + + + private: + std::string node; + std::vector< boost::shared_ptr<PubSubItem> > items; + bool notify; + }; +} diff --git a/Swiften/Elements/PubSubSubscribe.cpp b/Swiften/Elements/PubSubSubscribe.cpp new file mode 100644 index 0000000..4720321 --- /dev/null +++ b/Swiften/Elements/PubSubSubscribe.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubSubscribe.h> + +using namespace Swift; + +PubSubSubscribe::PubSubSubscribe() { +} + +PubSubSubscribe::~PubSubSubscribe() { +} diff --git a/Swiften/Elements/PubSubSubscribe.h b/Swiften/Elements/PubSubSubscribe.h new file mode 100644 index 0000000..e2cc4ae --- /dev/null +++ b/Swiften/Elements/PubSubSubscribe.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <boost/optional.hpp> +#include <boost/shared_ptr.hpp> +#include <string> + +#include <Swiften/Elements/PubSubOptions.h> +#include <Swiften/Elements/PubSubPayload.h> +#include <Swiften/JID/JID.h> + +namespace Swift { + class SWIFTEN_API PubSubSubscribe : public PubSubPayload { + public: + + PubSubSubscribe(); + + virtual ~PubSubSubscribe(); + + const boost::optional< std::string >& getNode() const { + return node; + } + + void setNode(const boost::optional< std::string >& value) { + this->node = value ; + } + + const JID& getJID() const { + return jid; + } + + void setJID(const JID& value) { + this->jid = value ; + } + + boost::shared_ptr<PubSubOptions> getOptions() const { + return options; + } + + void setOptions(boost::shared_ptr<PubSubOptions> value) { + this->options = value ; + } + + + private: + boost::optional< std::string > node; + JID jid; + boost::shared_ptr<PubSubOptions> options; + }; +} diff --git a/Swiften/Elements/PubSubSubscribeOptions.cpp b/Swiften/Elements/PubSubSubscribeOptions.cpp new file mode 100644 index 0000000..8770620 --- /dev/null +++ b/Swiften/Elements/PubSubSubscribeOptions.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubSubscribeOptions.h> + +using namespace Swift; + +PubSubSubscribeOptions::PubSubSubscribeOptions() { +} + +PubSubSubscribeOptions::~PubSubSubscribeOptions() { +} diff --git a/Swiften/Elements/PubSubSubscribeOptions.h b/Swiften/Elements/PubSubSubscribeOptions.h new file mode 100644 index 0000000..6612d82 --- /dev/null +++ b/Swiften/Elements/PubSubSubscribeOptions.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> + + + + +namespace Swift { + class SWIFTEN_API PubSubSubscribeOptions : public Payload { + public: + + PubSubSubscribeOptions(); + + virtual ~PubSubSubscribeOptions(); + + bool isRequired() const { + return required; + } + + void setRequired(bool value) { + this->required = value ; + } + + + private: + bool required; + }; +} diff --git a/Swiften/Elements/PubSubSubscription.cpp b/Swiften/Elements/PubSubSubscription.cpp new file mode 100644 index 0000000..a25fc06 --- /dev/null +++ b/Swiften/Elements/PubSubSubscription.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubSubscription.h> + +using namespace Swift; + +PubSubSubscription::PubSubSubscription() : subscription(None) { +} + +PubSubSubscription::~PubSubSubscription() { +} diff --git a/Swiften/Elements/PubSubSubscription.h b/Swiften/Elements/PubSubSubscription.h new file mode 100644 index 0000000..977cd55 --- /dev/null +++ b/Swiften/Elements/PubSubSubscription.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <boost/optional.hpp> +#include <boost/shared_ptr.hpp> +#include <string> + +#include <Swiften/Elements/PubSubSubscribeOptions.h> +#include <Swiften/Elements/PubSubPayload.h> +#include <Swiften/JID/JID.h> + +namespace Swift { + class SWIFTEN_API PubSubSubscription : public PubSubPayload { + public: + enum SubscriptionType { + None, + Pending, + Subscribed, + Unconfigured + }; + + PubSubSubscription(); + + virtual ~PubSubSubscription(); + + const boost::optional< std::string >& getNode() const { + return node; + } + + void setNode(const boost::optional< std::string >& value) { + this->node = value ; + } + + const boost::optional< std::string >& getSubscriptionID() const { + return subscriptionID; + } + + void setSubscriptionID(const boost::optional< std::string >& value) { + this->subscriptionID = value ; + } + + const JID& getJID() const { + return jid; + } + + void setJID(const JID& value) { + this->jid = value ; + } + + boost::shared_ptr<PubSubSubscribeOptions> getOptions() const { + return options; + } + + void setOptions(boost::shared_ptr<PubSubSubscribeOptions> value) { + this->options = value ; + } + + SubscriptionType getSubscription() const { + return subscription; + } + + void setSubscription(SubscriptionType value) { + this->subscription = value ; + } + + + private: + boost::optional< std::string > node; + boost::optional< std::string > subscriptionID; + JID jid; + boost::shared_ptr<PubSubSubscribeOptions> options; + SubscriptionType subscription; + }; +} diff --git a/Swiften/Elements/PubSubSubscriptions.cpp b/Swiften/Elements/PubSubSubscriptions.cpp new file mode 100644 index 0000000..626e122 --- /dev/null +++ b/Swiften/Elements/PubSubSubscriptions.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubSubscriptions.h> + +using namespace Swift; + +PubSubSubscriptions::PubSubSubscriptions() { +} + +PubSubSubscriptions::~PubSubSubscriptions() { +} diff --git a/Swiften/Elements/PubSubSubscriptions.h b/Swiften/Elements/PubSubSubscriptions.h new file mode 100644 index 0000000..c7c19c5 --- /dev/null +++ b/Swiften/Elements/PubSubSubscriptions.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <boost/optional.hpp> +#include <boost/shared_ptr.hpp> +#include <vector> +#include <string> + +#include <Swiften/Elements/PubSubSubscription.h> +#include <Swiften/Elements/PubSubPayload.h> + +namespace Swift { + class SWIFTEN_API PubSubSubscriptions : public PubSubPayload { + public: + + PubSubSubscriptions(); + PubSubSubscriptions(const std::string& node) : node(node) {} + virtual ~PubSubSubscriptions(); + + const boost::optional< std::string >& getNode() const { + return node; + } + + void setNode(const boost::optional< std::string >& value) { + this->node = value ; + } + + const std::vector< boost::shared_ptr<PubSubSubscription> >& getSubscriptions() const { + return subscriptions; + } + + void setSubscriptions(const std::vector< boost::shared_ptr<PubSubSubscription> >& value) { + this->subscriptions = value ; + } + + void addSubscription(boost::shared_ptr<PubSubSubscription> value) { + this->subscriptions.push_back(value); + } + + + private: + boost::optional< std::string > node; + std::vector< boost::shared_ptr<PubSubSubscription> > subscriptions; + }; +} diff --git a/Swiften/Elements/PubSubUnsubscribe.cpp b/Swiften/Elements/PubSubUnsubscribe.cpp new file mode 100644 index 0000000..a4b8318 --- /dev/null +++ b/Swiften/Elements/PubSubUnsubscribe.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/PubSubUnsubscribe.h> + +using namespace Swift; + +PubSubUnsubscribe::PubSubUnsubscribe() { +} + +PubSubUnsubscribe::~PubSubUnsubscribe() { +} diff --git a/Swiften/Elements/PubSubUnsubscribe.h b/Swiften/Elements/PubSubUnsubscribe.h new file mode 100644 index 0000000..3969376 --- /dev/null +++ b/Swiften/Elements/PubSubUnsubscribe.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <boost/optional.hpp> +#include <string> + +#include <Swiften/Elements/PubSubPayload.h> +#include <Swiften/JID/JID.h> + +namespace Swift { + class SWIFTEN_API PubSubUnsubscribe : public PubSubPayload { + public: + + PubSubUnsubscribe(); + + virtual ~PubSubUnsubscribe(); + + const boost::optional< std::string >& getNode() const { + return node; + } + + void setNode(const boost::optional< std::string >& value) { + this->node = value ; + } + + const JID& getJID() const { + return jid; + } + + void setJID(const JID& value) { + this->jid = value ; + } + + const boost::optional< std::string >& getSubscriptionID() const { + return subscriptionID; + } + + void setSubscriptionID(const boost::optional< std::string >& value) { + this->subscriptionID = value ; + } + + + private: + boost::optional< std::string > node; + JID jid; + boost::optional< std::string > subscriptionID; + }; +} diff --git a/Swiften/Elements/UserLocation.cpp b/Swiften/Elements/UserLocation.cpp new file mode 100644 index 0000000..f22973e --- /dev/null +++ b/Swiften/Elements/UserLocation.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Elements/UserLocation.h> + +using namespace Swift; + +UserLocation::UserLocation() { +} + +UserLocation::~UserLocation() { +} diff --git a/Swiften/Elements/UserLocation.h b/Swiften/Elements/UserLocation.h new file mode 100644 index 0000000..2355838 --- /dev/null +++ b/Swiften/Elements/UserLocation.h @@ -0,0 +1,227 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> +#include <boost/optional.hpp> +#include <string> +#include <boost/date_time/posix_time/posix_time_types.hpp> + + + +namespace Swift { + class SWIFTEN_API UserLocation : public Payload { + public: + + UserLocation(); + + virtual ~UserLocation(); + + const boost::optional< std::string >& getArea() const { + return area; + } + + void setArea(const boost::optional< std::string >& value) { + this->area = value ; + } + + const boost::optional< float >& getAltitude() const { + return altitude; + } + + void setAltitude(const boost::optional< float >& value) { + this->altitude = value ; + } + + const boost::optional< std::string >& getLocality() const { + return locality; + } + + void setLocality(const boost::optional< std::string >& value) { + this->locality = value ; + } + + const boost::optional< float >& getLatitude() const { + return latitude; + } + + void setLatitude(const boost::optional< float >& value) { + this->latitude = value ; + } + + const boost::optional< float >& getAccuracy() const { + return accuracy; + } + + void setAccuracy(const boost::optional< float >& value) { + this->accuracy = value ; + } + + const boost::optional< std::string >& getDescription() const { + return description; + } + + void setDescription(const boost::optional< std::string >& value) { + this->description = value ; + } + + const boost::optional< std::string >& getCountryCode() const { + return countryCode; + } + + void setCountryCode(const boost::optional< std::string >& value) { + this->countryCode = value ; + } + + const boost::optional< boost::posix_time::ptime >& getTimestamp() const { + return timestamp; + } + + void setTimestamp(const boost::optional< boost::posix_time::ptime >& value) { + this->timestamp = value ; + } + + const boost::optional< std::string >& getFloor() const { + return floor; + } + + void setFloor(const boost::optional< std::string >& value) { + this->floor = value ; + } + + const boost::optional< std::string >& getBuilding() const { + return building; + } + + void setBuilding(const boost::optional< std::string >& value) { + this->building = value ; + } + + const boost::optional< std::string >& getRoom() const { + return room; + } + + void setRoom(const boost::optional< std::string >& value) { + this->room = value ; + } + + const boost::optional< std::string >& getCountry() const { + return country; + } + + void setCountry(const boost::optional< std::string >& value) { + this->country = value ; + } + + const boost::optional< std::string >& getRegion() const { + return region; + } + + void setRegion(const boost::optional< std::string >& value) { + this->region = value ; + } + + const boost::optional< std::string >& getURI() const { + return uri; + } + + void setURI(const boost::optional< std::string >& value) { + this->uri = value ; + } + + const boost::optional< float >& getLongitude() const { + return longitude; + } + + void setLongitude(const boost::optional< float >& value) { + this->longitude = value ; + } + + const boost::optional< float >& getError() const { + return error; + } + + void setError(const boost::optional< float >& value) { + this->error = value ; + } + + const boost::optional< std::string >& getPostalCode() const { + return postalCode; + } + + void setPostalCode(const boost::optional< std::string >& value) { + this->postalCode = value ; + } + + const boost::optional< float >& getBearing() const { + return bearing; + } + + void setBearing(const boost::optional< float >& value) { + this->bearing = value ; + } + + const boost::optional< std::string >& getText() const { + return text; + } + + void setText(const boost::optional< std::string >& value) { + this->text = value ; + } + + const boost::optional< std::string >& getDatum() const { + return datum; + } + + void setDatum(const boost::optional< std::string >& value) { + this->datum = value ; + } + + const boost::optional< std::string >& getStreet() const { + return street; + } + + void setStreet(const boost::optional< std::string >& value) { + this->street = value ; + } + + const boost::optional< float >& getSpeed() const { + return speed; + } + + void setSpeed(const boost::optional< float >& value) { + this->speed = value ; + } + + + private: + boost::optional< std::string > area; + boost::optional< float > altitude; + boost::optional< std::string > locality; + boost::optional< float > latitude; + boost::optional< float > accuracy; + boost::optional< std::string > description; + boost::optional< std::string > countryCode; + boost::optional< boost::posix_time::ptime > timestamp; + boost::optional< std::string > floor; + boost::optional< std::string > building; + boost::optional< std::string > room; + boost::optional< std::string > country; + boost::optional< std::string > region; + boost::optional< std::string > uri; + boost::optional< float > longitude; + boost::optional< float > error; + boost::optional< std::string > postalCode; + boost::optional< float > bearing; + boost::optional< std::string > text; + boost::optional< std::string > datum; + boost::optional< std::string > street; + boost::optional< float > speed; + }; +} diff --git a/Swiften/JID/JID.cpp b/Swiften/JID/JID.cpp index e1502f1..0f2d8d1 100644 --- a/Swiften/JID/JID.cpp +++ b/Swiften/JID/JID.cpp @@ -18,6 +18,7 @@ #include <boost/assign/list_of.hpp> #include <boost/algorithm/string/find_format.hpp> #include <boost/algorithm/string/finder.hpp> +#include <boost/optional.hpp> #include <iostream> #include <sstream> @@ -317,4 +318,9 @@ std::ostream& operator<<(std::ostream& os, const JID& j) { return os; } +boost::optional<JID> JID::parse(const std::string& s) { + JID jid(s); + return jid.isValid() ? jid : boost::optional<JID>(); +} + } diff --git a/Swiften/JID/JID.h b/Swiften/JID/JID.h index eac1e2a..126a7b1 100644 --- a/Swiften/JID/JID.h +++ b/Swiften/JID/JID.h @@ -10,7 +10,7 @@ #include <iosfwd> #include <Swiften/Base/API.h> - +#include <boost/optional/optional_fwd.hpp> namespace Swift { class IDNConverter; @@ -160,6 +160,11 @@ namespace Swift { return a.compare(b, Swift::JID::WithResource) != 0; } + /** + * Returns an empty optional if the JID is invalid, and an + * optional with a value if the JID is valid. + */ + static boost::optional<JID> parse(const std::string&); /** * If Swiften was compiled with SWIFTEN_JID_NO_DEFAULT_IDN_CONVERTER (not default), use this method at diff --git a/Swiften/Parser/GenericPayloadParserFactory2.h b/Swiften/Parser/GenericPayloadParserFactory2.h new file mode 100644 index 0000000..f24b64e --- /dev/null +++ b/Swiften/Parser/GenericPayloadParserFactory2.h @@ -0,0 +1,39 @@ +/* + * 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 <Swiften/Parser/PayloadParserFactory.h> +#include <string> + +namespace Swift { + class PayloadParserFactoryCollection; + + /** + * A generic class for PayloadParserFactories that parse a specific payload (given as the template parameter of the class). + */ + template<typename PARSER_TYPE> + class GenericPayloadParserFactory2 : public PayloadParserFactory { + public: + /** + * Construct a parser factory that can parse the given top-level tag in the given namespace. + */ + GenericPayloadParserFactory2(const std::string& tag, const std::string& xmlns, PayloadParserFactoryCollection* parsers) : tag_(tag), xmlns_(xmlns), parsers_(parsers) {} + + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { + return (tag_.empty() ? true : element == tag_) && (xmlns_.empty() ? true : xmlns_ == ns); + } + + virtual PayloadParser* createPayloadParser() { + return new PARSER_TYPE(parsers_); + } + + private: + std::string tag_; + std::string xmlns_; + PayloadParserFactoryCollection* parsers_; + }; +} diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp index 1797e45..3ec5a7a 100644 --- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp +++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2012 Remko Tronçon + * Copyright (c) 2010-2013 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ @@ -10,6 +10,8 @@ #include <Swiften/Elements/UnblockPayload.h> #include <Swiften/Elements/BlockListPayload.h> #include <Swiften/Parser/GenericPayloadParser.h> +#include <Swiften/Parser/GenericPayloadParserFactory.h> +#include <Swiften/Parser/GenericPayloadParserFactory2.h> #include <Swiften/Parser/PayloadParserFactory.h> #include <Swiften/Parser/PayloadParsers/ErrorParser.h> #include <Swiften/Parser/PayloadParsers/ErrorParserFactory.h> @@ -68,6 +70,11 @@ #include <Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParserFactory.h> #include <Swiften/Parser/PayloadParsers/WhiteboardParser.h> #include <Swiften/Parser/PayloadParsers/IdleParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubEventParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h> +#include <Swiften/Parser/PayloadParsers/UserLocationParser.h> using namespace boost; @@ -127,9 +134,14 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() { factories_.push_back(boost::make_shared<GenericPayloadParserFactory<JingleFileTransferHashParser> >("checksum")); factories_.push_back(boost::make_shared<GenericPayloadParserFactory<S5BProxyRequestParser> >("query", "http://jabber.org/protocol/bytestreams")); factories_.push_back(boost::make_shared<GenericPayloadParserFactory<WhiteboardParser> >("wb", "http://swift.im/whiteboard")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<UserLocationParser> >("geoloc", "http://jabber.org/protocol/geoloc")); factories_.push_back(boost::make_shared<DeliveryReceiptParserFactory>()); factories_.push_back(boost::make_shared<DeliveryReceiptRequestParserFactory>()); factories_.push_back(boost::make_shared<GenericPayloadParserFactory<IdleParser> >("idle", "urn:xmpp:idle:1")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<PubSubParser> >("pubsub", "http://jabber.org/protocol/pubsub", this)); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<PubSubOwnerPubSubParser> >("pubsub", "http://jabber.org/protocol/pubsub#owner", this)); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<PubSubEventParser> >("event", "http://jabber.org/protocol/pubsub#event", this)); + factories_.push_back(boost::make_shared<PubSubErrorParserFactory>()); foreach(shared_ptr<PayloadParserFactory> factory, factories_) { addFactory(factory.get()); diff --git a/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.cpp b/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.cpp new file mode 100644 index 0000000..05fa119 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubAffiliationParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/EnumParser.h> + +using namespace Swift; + +PubSubAffiliationParser::PubSubAffiliationParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubAffiliationParser::~PubSubAffiliationParser() { +} + +void PubSubAffiliationParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("affiliation")) { + if (boost::optional<PubSubAffiliation::Type> value = EnumParser<PubSubAffiliation::Type>()(PubSubAffiliation::None, "none")(PubSubAffiliation::Member, "member")(PubSubAffiliation::Outcast, "outcast")(PubSubAffiliation::Owner, "owner")(PubSubAffiliation::Publisher, "publisher")(PubSubAffiliation::PublishOnly, "publish-only").parse(*attributeValue)) { + getPayloadInternal()->setType(*value); + } + } + } + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubAffiliationParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } +} + +void PubSubAffiliationParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.h b/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.h new file mode 100644 index 0000000..43c619d --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubAffiliation.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubAffiliationParser : public GenericPayloadParser<PubSubAffiliation> { + public: + PubSubAffiliationParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubAffiliationParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.cpp new file mode 100644 index 0000000..b75e339 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/PubSubAffiliationParser.h> + +using namespace Swift; + +PubSubAffiliationsParser::PubSubAffiliationsParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubAffiliationsParser::~PubSubAffiliationsParser() { +} + +void PubSubAffiliationsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } + + if (level == 1) { + if (element == "affiliation" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubAffiliationParser>(parsers); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubAffiliationsParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + if (element == "affiliation" && ns == "http://jabber.org/protocol/pubsub") { + getPayloadInternal()->addAffiliation(boost::dynamic_pointer_cast<PubSubAffiliation>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } +} + +void PubSubAffiliationsParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.h b/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.h new file mode 100644 index 0000000..646e7a8 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubAffiliations.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubAffiliationsParser : public GenericPayloadParser<PubSubAffiliations> { + public: + PubSubAffiliationsParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubAffiliationsParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubConfigureParser.cpp b/Swiften/Parser/PayloadParsers/PubSubConfigureParser.cpp new file mode 100644 index 0000000..773c1c7 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubConfigureParser.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubConfigureParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/FormParser.h> + +using namespace Swift; + +PubSubConfigureParser::PubSubConfigureParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubConfigureParser::~PubSubConfigureParser() { +} + +void PubSubConfigureParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + + + if (level == 1) { + if (element == "x" && ns == "jabber:x:data") { + currentPayloadParser = boost::make_shared<FormParser>(); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubConfigureParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + if (element == "x" && ns == "jabber:x:data") { + getPayloadInternal()->setData(boost::dynamic_pointer_cast<Form>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } +} + +void PubSubConfigureParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubConfigureParser.h b/Swiften/Parser/PayloadParsers/PubSubConfigureParser.h new file mode 100644 index 0000000..8300140 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubConfigureParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubConfigure.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubConfigureParser : public GenericPayloadParser<PubSubConfigure> { + public: + PubSubConfigureParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubConfigureParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubCreateParser.cpp b/Swiften/Parser/PayloadParsers/PubSubCreateParser.cpp new file mode 100644 index 0000000..47f35c9 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubCreateParser.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubCreateParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> + + +using namespace Swift; + +PubSubCreateParser::PubSubCreateParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubCreateParser::~PubSubCreateParser() { +} + +void PubSubCreateParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubCreateParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } +} + +void PubSubCreateParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubCreateParser.h b/Swiften/Parser/PayloadParsers/PubSubCreateParser.h new file mode 100644 index 0000000..865b8ec --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubCreateParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubCreate.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubCreateParser : public GenericPayloadParser<PubSubCreate> { + public: + PubSubCreateParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubCreateParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubDefaultParser.cpp b/Swiften/Parser/PayloadParsers/PubSubDefaultParser.cpp new file mode 100644 index 0000000..7a370cd --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubDefaultParser.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubDefaultParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/EnumParser.h> + +using namespace Swift; + +PubSubDefaultParser::PubSubDefaultParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubDefaultParser::~PubSubDefaultParser() { +} + +void PubSubDefaultParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("type")) { + if (boost::optional<PubSubDefault::Type> value = EnumParser<PubSubDefault::Type>()(PubSubDefault::None, "none")(PubSubDefault::Collection, "collection")(PubSubDefault::Leaf, "leaf").parse(*attributeValue)) { + getPayloadInternal()->setType(*value); + } + } + } + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubDefaultParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } +} + +void PubSubDefaultParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubDefaultParser.h b/Swiften/Parser/PayloadParsers/PubSubDefaultParser.h new file mode 100644 index 0000000..7bd8d66 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubDefaultParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubDefault.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubDefaultParser : public GenericPayloadParser<PubSubDefault> { + public: + PubSubDefaultParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubDefaultParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubErrorParser.cpp b/Swiften/Parser/PayloadParsers/PubSubErrorParser.cpp new file mode 100644 index 0000000..9752cd2 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubErrorParser.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Parser/PayloadParsers/PubSubErrorParser.h> + +using namespace Swift; + +PubSubErrorParser::PubSubErrorParser() : level(0) { + typeParser + (PubSubError::ClosedNode, "closed-node") + (PubSubError::ConfigurationRequired, "configuration-required") + (PubSubError::InvalidJID, "invalid-jid") + (PubSubError::InvalidOptions, "invalid-options") + (PubSubError::InvalidPayload, "invalid-payload") + (PubSubError::InvalidSubscriptionID, "invalid-subid") + (PubSubError::ItemForbidden, "item-forbidden") + (PubSubError::ItemRequired, "item-required") + (PubSubError::JIDRequired, "jid-required") + (PubSubError::MaximumItemsExceeded, "max-items-exceeded") + (PubSubError::MaximumNodesExceeded, "max-nodes-exceeded") + (PubSubError::NodeIDRequired, "nodeid-required") + (PubSubError::NotInRosterGroup, "not-in-roster-group") + (PubSubError::NotSubscribed, "not-subscribed") + (PubSubError::PayloadTooBig, "payload-too-big") + (PubSubError::PayloadRequired, "payload-required") + (PubSubError::PendingSubscription, "pending-subscription") + (PubSubError::PresenceSubscriptionRequired, "presence-subscription-required") + (PubSubError::SubscriptionIDRequired, "subid-required") + (PubSubError::TooManySubscriptions, "too-many-subscriptions") + (PubSubError::Unsupported, "unsupported") + (PubSubError::UnsupportedAccessModel, "unsupported-access-model"); + unsupportedTypeParser + (PubSubError::AccessAuthorize, "access-authorize") + (PubSubError::AccessOpen, "access-open") + (PubSubError::AccessPresence, "access-presence") + (PubSubError::AccessRoster, "access-roster") + (PubSubError::AccessWhitelist, "access-whitelist") + (PubSubError::AutoCreate, "auto-create") + (PubSubError::AutoSubscribe, "auto-subscribe") + (PubSubError::Collections, "collections") + (PubSubError::ConfigNode, "config-node") + (PubSubError::CreateAndConfigure, "create-and-configure") + (PubSubError::CreateNodes, "create-nodes") + (PubSubError::DeleteItems, "delete-items") + (PubSubError::DeleteNodes, "delete-nodes") + (PubSubError::FilteredNotifications, "filtered-notifications") + (PubSubError::GetPending, "get-pending") + (PubSubError::InstantNodes, "instant-nodes") + (PubSubError::ItemIDs, "item-ids") + (PubSubError::LastPublished, "last-published") + (PubSubError::LeasedSubscription, "leased-subscription") + (PubSubError::ManageSubscriptions, "manage-subscriptions") + (PubSubError::MemberAffiliation, "member-affiliation") + (PubSubError::MetaData, "meta-data") + (PubSubError::ModifyAffiliations, "modify-affiliations") + (PubSubError::MultiCollection, "multi-collection") + (PubSubError::MultiSubscribe, "multi-subscribe") + (PubSubError::OutcastAffiliation, "outcast-affiliation") + (PubSubError::PersistentItems, "persistent-items") + (PubSubError::PresenceNotifications, "presence-notifications") + (PubSubError::PresenceSubscribe, "presence-subscribe") + (PubSubError::Publish, "publish") + (PubSubError::PublishOptions, "publish-options") + (PubSubError::PublishOnlyAffiliation, "publish-only-affiliation") + (PubSubError::PublisherAffiliation, "publisher-affiliation") + (PubSubError::PurgeNodes, "purge-nodes") + (PubSubError::RetractItems, "retract-items") + (PubSubError::RetrieveAffiliations, "retrieve-affiliations") + (PubSubError::RetrieveDefault, "retrieve-default") + (PubSubError::RetrieveItems, "retrieve-items") + (PubSubError::RetrieveSubscriptions, "retrieve-subscriptions") + (PubSubError::Subscribe, "subscribe") + (PubSubError::SubscriptionOptions, "subscription-options") + (PubSubError::SubscriptionNotifications, "subscription-notifications"); +} + +PubSubErrorParser::~PubSubErrorParser() { +} + +void PubSubErrorParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { + if (level == 1) { + if (boost::optional<PubSubError::Type> type = typeParser.parse(element)) { + getPayloadInternal()->setType(*type); + if (type == PubSubError::Unsupported) { + if (boost::optional<std::string> feature = attributes.getAttributeValue("feature")) { + if (boost::optional<PubSubError::UnsupportedFeatureType> unsupportedType = unsupportedTypeParser.parse(*feature)) { + getPayloadInternal()->setUnsupportedFeatureType(*unsupportedType); + } + } + } + } + } + ++level; +} + +void PubSubErrorParser::handleEndElement(const std::string&, const std::string&) { + --level; +} + +void PubSubErrorParser::handleCharacterData(const std::string&) { +} diff --git a/Swiften/Parser/PayloadParsers/PubSubErrorParser.h b/Swiften/Parser/PayloadParsers/PubSubErrorParser.h new file mode 100644 index 0000000..eb7dcfe --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubErrorParser.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubError.h> +#include <Swiften/Parser/GenericPayloadParser.h> +#include <Swiften/Parser/EnumParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubErrorParser : public GenericPayloadParser<PubSubError> { + public: + PubSubErrorParser(); + virtual ~PubSubErrorParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + int level; + EnumParser<PubSubError::Type> typeParser; + EnumParser<PubSubError::UnsupportedFeatureType> unsupportedTypeParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.cpp b/Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.cpp new file mode 100644 index 0000000..10dfd63 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.cpp @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h> + +using namespace Swift; + +PubSubErrorParserFactory::~PubSubErrorParserFactory() { +} diff --git a/Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h b/Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h new file mode 100644 index 0000000..e2386da --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/PubSubErrorParser.h> + +namespace Swift { + class PubSubErrorParserFactory : public PayloadParserFactory { + public: + PubSubErrorParserFactory() { + } + ~PubSubErrorParserFactory(); + + virtual bool canParse(const std::string&, const std::string& ns, const AttributeMap&) const { + return ns == "http://jabber.org/protocol/pubsub#errors"; + } + + virtual PayloadParser* createPayloadParser() { + return new PubSubErrorParser(); + } + }; +} + + diff --git a/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.cpp new file mode 100644 index 0000000..f187be8 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> + + +using namespace Swift; + +PubSubEventAssociateParser::PubSubEventAssociateParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubEventAssociateParser::~PubSubEventAssociateParser() { +} + +void PubSubEventAssociateParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubEventAssociateParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } +} + +void PubSubEventAssociateParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.h b/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.h new file mode 100644 index 0000000..000edf2 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubEventAssociate.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubEventAssociateParser : public GenericPayloadParser<PubSubEventAssociate> { + public: + PubSubEventAssociateParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventAssociateParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.cpp new file mode 100644 index 0000000..08b9c65 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.h> + +using namespace Swift; + +PubSubEventCollectionParser::PubSubEventCollectionParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubEventCollectionParser::~PubSubEventCollectionParser() { +} + +void PubSubEventCollectionParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } + + if (level == 1) { + if (element == "disassociate" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = boost::make_shared<PubSubEventDisassociateParser>(parsers); + } + if (element == "associate" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = boost::make_shared<PubSubEventAssociateParser>(parsers); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubEventCollectionParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + if (element == "disassociate" && ns == "http://jabber.org/protocol/pubsub#event") { + getPayloadInternal()->setDisassociate(boost::dynamic_pointer_cast<PubSubEventDisassociate>(currentPayloadParser->getPayload())); + } + if (element == "associate" && ns == "http://jabber.org/protocol/pubsub#event") { + getPayloadInternal()->setAssociate(boost::dynamic_pointer_cast<PubSubEventAssociate>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } +} + +void PubSubEventCollectionParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.h b/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.h new file mode 100644 index 0000000..aad97d2 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubEventCollection.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubEventCollectionParser : public GenericPayloadParser<PubSubEventCollection> { + public: + PubSubEventCollectionParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventCollectionParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.cpp new file mode 100644 index 0000000..f905299 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/FormParser.h> + +using namespace Swift; + +PubSubEventConfigurationParser::PubSubEventConfigurationParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubEventConfigurationParser::~PubSubEventConfigurationParser() { +} + +void PubSubEventConfigurationParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } + + if (level == 1) { + if (element == "x" && ns == "jabber:x:data") { + currentPayloadParser = boost::make_shared<FormParser>(); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubEventConfigurationParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + if (element == "x" && ns == "jabber:x:data") { + getPayloadInternal()->setData(boost::dynamic_pointer_cast<Form>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } +} + +void PubSubEventConfigurationParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.h b/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.h new file mode 100644 index 0000000..7189460 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubEventConfiguration.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubEventConfigurationParser : public GenericPayloadParser<PubSubEventConfiguration> { + public: + PubSubEventConfigurationParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventConfigurationParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.cpp new file mode 100644 index 0000000..03c7423 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.h> + +using namespace Swift; + +PubSubEventDeleteParser::PubSubEventDeleteParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubEventDeleteParser::~PubSubEventDeleteParser() { +} + +void PubSubEventDeleteParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } + + if (level == 1) { + if (element == "redirect" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = boost::make_shared<PubSubEventRedirectParser>(parsers); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubEventDeleteParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + if (element == "redirect" && ns == "http://jabber.org/protocol/pubsub#event") { + getPayloadInternal()->setRedirects(boost::dynamic_pointer_cast<PubSubEventRedirect>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } +} + +void PubSubEventDeleteParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.h b/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.h new file mode 100644 index 0000000..36f8e0b --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubEventDelete.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubEventDeleteParser : public GenericPayloadParser<PubSubEventDelete> { + public: + PubSubEventDeleteParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventDeleteParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.cpp new file mode 100644 index 0000000..287ac35 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> + + +using namespace Swift; + +PubSubEventDisassociateParser::PubSubEventDisassociateParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubEventDisassociateParser::~PubSubEventDisassociateParser() { +} + +void PubSubEventDisassociateParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubEventDisassociateParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } +} + +void PubSubEventDisassociateParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.h b/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.h new file mode 100644 index 0000000..9015100 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubEventDisassociate.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubEventDisassociateParser : public GenericPayloadParser<PubSubEventDisassociate> { + public: + PubSubEventDisassociateParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventDisassociateParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventItemParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventItemParser.cpp new file mode 100644 index 0000000..8903545 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventItemParser.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubEventItemParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> + + +using namespace Swift; + +PubSubEventItemParser::PubSubEventItemParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubEventItemParser::~PubSubEventItemParser() { +} + +void PubSubEventItemParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("publisher")) { + getPayloadInternal()->setPublisher(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("id")) { + getPayloadInternal()->setID(*attributeValue); + } + } + + if (level == 1) { + if (PayloadParserFactory* factory = parsers->getPayloadParserFactory(element, ns, attributes)) { + currentPayloadParser.reset(factory->createPayloadParser()); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubEventItemParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + getPayloadInternal()->addData(currentPayloadParser->getPayload()); + currentPayloadParser.reset(); + } + } +} + +void PubSubEventItemParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventItemParser.h b/Swiften/Parser/PayloadParsers/PubSubEventItemParser.h new file mode 100644 index 0000000..6c16043 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventItemParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubEventItem.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubEventItemParser : public GenericPayloadParser<PubSubEventItem> { + public: + PubSubEventItemParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventItemParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.cpp new file mode 100644 index 0000000..fa155e9 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubEventItemsParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/PubSubEventRetractParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubEventItemParser.h> + +using namespace Swift; + +PubSubEventItemsParser::PubSubEventItemsParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubEventItemsParser::~PubSubEventItemsParser() { +} + +void PubSubEventItemsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } + + if (level == 1) { + if (element == "item" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = boost::make_shared<PubSubEventItemParser>(parsers); + } + if (element == "retract" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = boost::make_shared<PubSubEventRetractParser>(parsers); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubEventItemsParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + if (element == "item" && ns == "http://jabber.org/protocol/pubsub#event") { + getPayloadInternal()->addItem(boost::dynamic_pointer_cast<PubSubEventItem>(currentPayloadParser->getPayload())); + } + if (element == "retract" && ns == "http://jabber.org/protocol/pubsub#event") { + getPayloadInternal()->addRetract(boost::dynamic_pointer_cast<PubSubEventRetract>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } +} + +void PubSubEventItemsParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.h b/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.h new file mode 100644 index 0000000..60ecb25 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubEventItems.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubEventItemsParser : public GenericPayloadParser<PubSubEventItems> { + public: + PubSubEventItemsParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventItemsParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventParser.cpp new file mode 100644 index 0000000..c4406a9 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventParser.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubEventParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/PubSubEventItemsParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.h> + +using namespace Swift; + +PubSubEventParser::PubSubEventParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubEventParser::~PubSubEventParser() { +} + +void PubSubEventParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + + + if (level == 1) { + if (element == "items" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = boost::make_shared<PubSubEventItemsParser>(parsers); + } + if (element == "collection" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = boost::make_shared<PubSubEventCollectionParser>(parsers); + } + if (element == "purge" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = boost::make_shared<PubSubEventPurgeParser>(parsers); + } + if (element == "configuration" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = boost::make_shared<PubSubEventConfigurationParser>(parsers); + } + if (element == "delete" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = boost::make_shared<PubSubEventDeleteParser>(parsers); + } + if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = boost::make_shared<PubSubEventSubscriptionParser>(parsers); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubEventParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + if (currentPayloadParser) { + getPayloadInternal()->setPayload(boost::dynamic_pointer_cast<PubSubEventPayload>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } +} + +void PubSubEventParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventParser.h b/Swiften/Parser/PayloadParsers/PubSubEventParser.h new file mode 100644 index 0000000..1042e75 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubEvent.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubEventParser : public GenericPayloadParser<PubSubEvent> { + public: + PubSubEventParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.cpp new file mode 100644 index 0000000..14d1e96 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> + + +using namespace Swift; + +PubSubEventPurgeParser::PubSubEventPurgeParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubEventPurgeParser::~PubSubEventPurgeParser() { +} + +void PubSubEventPurgeParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubEventPurgeParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } +} + +void PubSubEventPurgeParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.h b/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.h new file mode 100644 index 0000000..740bff3 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubEventPurge.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubEventPurgeParser : public GenericPayloadParser<PubSubEventPurge> { + public: + PubSubEventPurgeParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventPurgeParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.cpp new file mode 100644 index 0000000..f053117 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> + + +using namespace Swift; + +PubSubEventRedirectParser::PubSubEventRedirectParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubEventRedirectParser::~PubSubEventRedirectParser() { +} + +void PubSubEventRedirectParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("uri")) { + getPayloadInternal()->setURI(*attributeValue); + } + } + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubEventRedirectParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } +} + +void PubSubEventRedirectParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.h b/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.h new file mode 100644 index 0000000..33880ed --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubEventRedirect.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubEventRedirectParser : public GenericPayloadParser<PubSubEventRedirect> { + public: + PubSubEventRedirectParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventRedirectParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.cpp new file mode 100644 index 0000000..da3dea3 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubEventRetractParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> + + +using namespace Swift; + +PubSubEventRetractParser::PubSubEventRetractParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubEventRetractParser::~PubSubEventRetractParser() { +} + +void PubSubEventRetractParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("id")) { + getPayloadInternal()->setID(*attributeValue); + } + } + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubEventRetractParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } +} + +void PubSubEventRetractParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.h b/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.h new file mode 100644 index 0000000..115bb7a --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubEventRetract.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubEventRetractParser : public GenericPayloadParser<PubSubEventRetract> { + public: + PubSubEventRetractParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventRetractParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.cpp new file mode 100644 index 0000000..3367202 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Base/DateTime.h> +#include <Swiften/Parser/EnumParser.h> + +using namespace Swift; + +PubSubEventSubscriptionParser::PubSubEventSubscriptionParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubEventSubscriptionParser::~PubSubEventSubscriptionParser() { +} + +void PubSubEventSubscriptionParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { + if (boost::optional<JID> jid = JID::parse(*attributeValue)) { + getPayloadInternal()->setJID(*jid); + } + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subscription")) { + if (boost::optional<PubSubEventSubscription::SubscriptionType> value = EnumParser<PubSubEventSubscription::SubscriptionType>()(PubSubEventSubscription::None, "none")(PubSubEventSubscription::Pending, "pending")(PubSubEventSubscription::Subscribed, "subscribed")(PubSubEventSubscription::Unconfigured, "unconfigured").parse(*attributeValue)) { + getPayloadInternal()->setSubscription(*value); + } + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) { + getPayloadInternal()->setSubscriptionID(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("expiry")) { + getPayloadInternal()->setExpiry(stringToDateTime(*attributeValue)); + } + } + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubEventSubscriptionParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } +} + +void PubSubEventSubscriptionParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.h b/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.h new file mode 100644 index 0000000..1469920 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubEventSubscription.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubEventSubscriptionParser : public GenericPayloadParser<PubSubEventSubscription> { + public: + PubSubEventSubscriptionParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventSubscriptionParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubItemParser.cpp b/Swiften/Parser/PayloadParsers/PubSubItemParser.cpp new file mode 100644 index 0000000..2e7d01a --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubItemParser.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubItemParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> + + +using namespace Swift; + +PubSubItemParser::PubSubItemParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubItemParser::~PubSubItemParser() { +} + +void PubSubItemParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("id")) { + getPayloadInternal()->setID(*attributeValue); + } + } + + if (level == 1) { + if (PayloadParserFactory* factory = parsers->getPayloadParserFactory(element, ns, attributes)) { + currentPayloadParser.reset(factory->createPayloadParser()); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubItemParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + getPayloadInternal()->addData(currentPayloadParser->getPayload()); + currentPayloadParser.reset(); + } + } +} + +void PubSubItemParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubItemParser.h b/Swiften/Parser/PayloadParsers/PubSubItemParser.h new file mode 100644 index 0000000..4f02211 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubItemParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubItem.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubItemParser : public GenericPayloadParser<PubSubItem> { + public: + PubSubItemParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubItemParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubItemsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubItemsParser.cpp new file mode 100644 index 0000000..615f05d --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubItemsParser.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubItemsParser.h> + +#include <boost/optional.hpp> +#include <boost/lexical_cast.hpp> + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/PubSubItemParser.h> + +using namespace Swift; + +PubSubItemsParser::PubSubItemsParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubItemsParser::~PubSubItemsParser() { +} + +void PubSubItemsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("max_items")) { + try { + getPayloadInternal()->setMaximumItems(boost::lexical_cast<unsigned int>(*attributeValue)); + } + catch (boost::bad_lexical_cast&) { + } + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) { + getPayloadInternal()->setSubscriptionID(*attributeValue); + } + } + + if (level == 1) { + if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubItemParser>(parsers); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubItemsParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { + getPayloadInternal()->addItem(boost::dynamic_pointer_cast<PubSubItem>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } +} + +void PubSubItemsParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubItemsParser.h b/Swiften/Parser/PayloadParsers/PubSubItemsParser.h new file mode 100644 index 0000000..895863f --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubItemsParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubItems.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubItemsParser : public GenericPayloadParser<PubSubItems> { + public: + PubSubItemsParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubItemsParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOptionsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOptionsParser.cpp new file mode 100644 index 0000000..3bf4998 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOptionsParser.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubOptionsParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/FormParser.h> + +using namespace Swift; + +PubSubOptionsParser::PubSubOptionsParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubOptionsParser::~PubSubOptionsParser() { +} + +void PubSubOptionsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { + if (boost::optional<JID> jid = JID::parse(*attributeValue)) { + getPayloadInternal()->setJID(*jid); + } + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) { + getPayloadInternal()->setSubscriptionID(*attributeValue); + } + } + + if (level == 1) { + if (element == "x" && ns == "jabber:x:data") { + currentPayloadParser = boost::make_shared<FormParser>(); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubOptionsParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + if (element == "x" && ns == "jabber:x:data") { + getPayloadInternal()->setData(boost::dynamic_pointer_cast<Form>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } +} + +void PubSubOptionsParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOptionsParser.h b/Swiften/Parser/PayloadParsers/PubSubOptionsParser.h new file mode 100644 index 0000000..3c8754b --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOptionsParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubOptions.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubOptionsParser : public GenericPayloadParser<PubSubOptions> { + public: + PubSubOptionsParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOptionsParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.cpp new file mode 100644 index 0000000..a648862 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/EnumParser.h> + +using namespace Swift; + +PubSubOwnerAffiliationParser::PubSubOwnerAffiliationParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubOwnerAffiliationParser::~PubSubOwnerAffiliationParser() { +} + +void PubSubOwnerAffiliationParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { + if (boost::optional<JID> jid = JID::parse(*attributeValue)) { + getPayloadInternal()->setJID(*jid); + } + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("affiliation")) { + if (boost::optional<PubSubOwnerAffiliation::Type> value = EnumParser<PubSubOwnerAffiliation::Type>()(PubSubOwnerAffiliation::None, "none")(PubSubOwnerAffiliation::Member, "member")(PubSubOwnerAffiliation::Outcast, "outcast")(PubSubOwnerAffiliation::Owner, "owner")(PubSubOwnerAffiliation::Publisher, "publisher")(PubSubOwnerAffiliation::PublishOnly, "publish-only").parse(*attributeValue)) { + getPayloadInternal()->setType(*value); + } + } + } + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubOwnerAffiliationParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } +} + +void PubSubOwnerAffiliationParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.h new file mode 100644 index 0000000..ae54b5f --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubOwnerAffiliation.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubOwnerAffiliationParser : public GenericPayloadParser<PubSubOwnerAffiliation> { + public: + PubSubOwnerAffiliationParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerAffiliationParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.cpp new file mode 100644 index 0000000..b824279 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.h> + +using namespace Swift; + +PubSubOwnerAffiliationsParser::PubSubOwnerAffiliationsParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubOwnerAffiliationsParser::~PubSubOwnerAffiliationsParser() { +} + +void PubSubOwnerAffiliationsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } + + if (level == 1) { + if (element == "affiliation" && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser = boost::make_shared<PubSubOwnerAffiliationParser>(parsers); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubOwnerAffiliationsParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + if (element == "affiliation" && ns == "http://jabber.org/protocol/pubsub#owner") { + getPayloadInternal()->addAffiliation(boost::dynamic_pointer_cast<PubSubOwnerAffiliation>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } +} + +void PubSubOwnerAffiliationsParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.h new file mode 100644 index 0000000..755d58c --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubOwnerAffiliations.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubOwnerAffiliationsParser : public GenericPayloadParser<PubSubOwnerAffiliations> { + public: + PubSubOwnerAffiliationsParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerAffiliationsParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.cpp new file mode 100644 index 0000000..43d262f --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/FormParser.h> + +using namespace Swift; + +PubSubOwnerConfigureParser::PubSubOwnerConfigureParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubOwnerConfigureParser::~PubSubOwnerConfigureParser() { +} + +void PubSubOwnerConfigureParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } + + if (level == 1) { + if (element == "x" && ns == "jabber:x:data") { + currentPayloadParser = boost::make_shared<FormParser>(); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubOwnerConfigureParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + if (element == "x" && ns == "jabber:x:data") { + getPayloadInternal()->setData(boost::dynamic_pointer_cast<Form>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } +} + +void PubSubOwnerConfigureParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.h new file mode 100644 index 0000000..f9a8553 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubOwnerConfigure.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubOwnerConfigureParser : public GenericPayloadParser<PubSubOwnerConfigure> { + public: + PubSubOwnerConfigureParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerConfigureParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.cpp new file mode 100644 index 0000000..4c284bf --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/FormParser.h> + +using namespace Swift; + +PubSubOwnerDefaultParser::PubSubOwnerDefaultParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubOwnerDefaultParser::~PubSubOwnerDefaultParser() { +} + +void PubSubOwnerDefaultParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + + + if (level == 1) { + if (element == "x" && ns == "jabber:x:data") { + currentPayloadParser = boost::make_shared<FormParser>(); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubOwnerDefaultParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + if (element == "x" && ns == "jabber:x:data") { + getPayloadInternal()->setData(boost::dynamic_pointer_cast<Form>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } +} + +void PubSubOwnerDefaultParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.h new file mode 100644 index 0000000..5207bc5 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubOwnerDefault.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubOwnerDefaultParser : public GenericPayloadParser<PubSubOwnerDefault> { + public: + PubSubOwnerDefaultParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerDefaultParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.cpp new file mode 100644 index 0000000..a2b7a9d --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.h> + +using namespace Swift; + +PubSubOwnerDeleteParser::PubSubOwnerDeleteParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubOwnerDeleteParser::~PubSubOwnerDeleteParser() { +} + +void PubSubOwnerDeleteParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } + + if (level == 1) { + if (element == "redirect" && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser = boost::make_shared<PubSubOwnerRedirectParser>(parsers); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubOwnerDeleteParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + if (element == "redirect" && ns == "http://jabber.org/protocol/pubsub#owner") { + getPayloadInternal()->setRedirect(boost::dynamic_pointer_cast<PubSubOwnerRedirect>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } +} + +void PubSubOwnerDeleteParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.h new file mode 100644 index 0000000..c171ab8 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubOwnerDelete.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubOwnerDeleteParser : public GenericPayloadParser<PubSubOwnerDelete> { + public: + PubSubOwnerDeleteParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerDeleteParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.cpp new file mode 100644 index 0000000..5262997 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.h> + +using namespace Swift; + +PubSubOwnerPubSubParser::PubSubOwnerPubSubParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubOwnerPubSubParser::~PubSubOwnerPubSubParser() { +} + +void PubSubOwnerPubSubParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + + + if (level == 1) { + if (element == "configure" && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser = boost::make_shared<PubSubOwnerConfigureParser>(parsers); + } + if (element == "subscriptions" && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser = boost::make_shared<PubSubOwnerSubscriptionsParser>(parsers); + } + if (element == "default" && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser = boost::make_shared<PubSubOwnerDefaultParser>(parsers); + } + if (element == "purge" && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser = boost::make_shared<PubSubOwnerPurgeParser>(parsers); + } + if (element == "affiliations" && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser = boost::make_shared<PubSubOwnerAffiliationsParser>(parsers); + } + if (element == "delete" && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser = boost::make_shared<PubSubOwnerDeleteParser>(parsers); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubOwnerPubSubParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + if (currentPayloadParser) { + getPayloadInternal()->setPayload(boost::dynamic_pointer_cast<PubSubOwnerPayload>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } +} + +void PubSubOwnerPubSubParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.h new file mode 100644 index 0000000..25fee8a --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubOwnerPubSub.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubOwnerPubSubParser : public GenericPayloadParser<PubSubOwnerPubSub> { + public: + PubSubOwnerPubSubParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerPubSubParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.cpp new file mode 100644 index 0000000..ebea0a7 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> + + +using namespace Swift; + +PubSubOwnerPurgeParser::PubSubOwnerPurgeParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubOwnerPurgeParser::~PubSubOwnerPurgeParser() { +} + +void PubSubOwnerPurgeParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubOwnerPurgeParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } +} + +void PubSubOwnerPurgeParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.h new file mode 100644 index 0000000..0b85d3d --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubOwnerPurge.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubOwnerPurgeParser : public GenericPayloadParser<PubSubOwnerPurge> { + public: + PubSubOwnerPurgeParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerPurgeParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.cpp new file mode 100644 index 0000000..bc54e86 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> + + +using namespace Swift; + +PubSubOwnerRedirectParser::PubSubOwnerRedirectParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubOwnerRedirectParser::~PubSubOwnerRedirectParser() { +} + +void PubSubOwnerRedirectParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("uri")) { + getPayloadInternal()->setURI(*attributeValue); + } + } + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubOwnerRedirectParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } +} + +void PubSubOwnerRedirectParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.h new file mode 100644 index 0000000..9a97d74 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubOwnerRedirect.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubOwnerRedirectParser : public GenericPayloadParser<PubSubOwnerRedirect> { + public: + PubSubOwnerRedirectParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerRedirectParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.cpp new file mode 100644 index 0000000..7c91526 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/EnumParser.h> + +using namespace Swift; + +PubSubOwnerSubscriptionParser::PubSubOwnerSubscriptionParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubOwnerSubscriptionParser::~PubSubOwnerSubscriptionParser() { +} + +void PubSubOwnerSubscriptionParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { + if (boost::optional<JID> jid = JID::parse(*attributeValue)) { + getPayloadInternal()->setJID(*jid); + } + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subscription")) { + if (boost::optional<PubSubOwnerSubscription::SubscriptionType> value = EnumParser<PubSubOwnerSubscription::SubscriptionType>()(PubSubOwnerSubscription::None, "none")(PubSubOwnerSubscription::Pending, "pending")(PubSubOwnerSubscription::Subscribed, "subscribed")(PubSubOwnerSubscription::Unconfigured, "unconfigured").parse(*attributeValue)) { + getPayloadInternal()->setSubscription(*value); + } + } + } + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubOwnerSubscriptionParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } +} + +void PubSubOwnerSubscriptionParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.h new file mode 100644 index 0000000..8ef8d5b --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubOwnerSubscription.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubOwnerSubscriptionParser : public GenericPayloadParser<PubSubOwnerSubscription> { + public: + PubSubOwnerSubscriptionParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerSubscriptionParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.cpp new file mode 100644 index 0000000..ebe90d8 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.h> + +using namespace Swift; + +PubSubOwnerSubscriptionsParser::PubSubOwnerSubscriptionsParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubOwnerSubscriptionsParser::~PubSubOwnerSubscriptionsParser() { +} + +void PubSubOwnerSubscriptionsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } + + if (level == 1) { + if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser = boost::make_shared<PubSubOwnerSubscriptionParser>(parsers); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubOwnerSubscriptionsParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub#owner") { + getPayloadInternal()->addSubscription(boost::dynamic_pointer_cast<PubSubOwnerSubscription>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } +} + +void PubSubOwnerSubscriptionsParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.h new file mode 100644 index 0000000..a5459a9 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubOwnerSubscriptions.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubOwnerSubscriptionsParser : public GenericPayloadParser<PubSubOwnerSubscriptions> { + public: + PubSubOwnerSubscriptionsParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerSubscriptionsParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubParser.cpp b/Swiften/Parser/PayloadParsers/PubSubParser.cpp new file mode 100644 index 0000000..5b1462b --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubParser.cpp @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubConfigureParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubDefaultParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubCreateParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubOptionsParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubPublishParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubOptionsParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubSubscribeParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubItemsParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubRetractParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.h> + +using namespace Swift; + +PubSubParser::PubSubParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubParser::~PubSubParser() { +} + +void PubSubParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 1) { + if (element == "items" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubItemsParser>(parsers); + } + if (element == "create" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubCreateParser>(parsers); + } + if (element == "publish" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubPublishParser>(parsers); + } + if (element == "affiliations" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubAffiliationsParser>(parsers); + } + if (element == "retract" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubRetractParser>(parsers); + } + if (element == "options" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubOptionsParser>(parsers); + } + if (element == "configure" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubConfigureParser>(parsers); + } + if (element == "default" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubDefaultParser>(parsers); + } + if (element == "subscriptions" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubSubscriptionsParser>(parsers); + } + if (element == "subscribe" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubSubscribeParser>(parsers); + } + if (element == "unsubscribe" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubUnsubscribeParser>(parsers); + } + if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubSubscriptionParser>(parsers); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + if (currentPayloadParser) { + if (element == "options" && ns == "http://jabber.org/protocol/pubsub") { + optionsPayload = boost::dynamic_pointer_cast<PubSubOptions>(currentPayloadParser->getPayload()); + } + else if (element == "configure" && ns == "http://jabber.org/protocol/pubsub") { + configurePayload = boost::dynamic_pointer_cast<PubSubConfigure>(currentPayloadParser->getPayload()); + } + else { + getPayloadInternal()->setPayload(boost::dynamic_pointer_cast<PubSubPayload>(currentPayloadParser->getPayload())); + } + } + currentPayloadParser.reset(); + } + + if (level == 0) { + if (boost::shared_ptr<PubSubCreate> create = boost::dynamic_pointer_cast<PubSubCreate>(getPayloadInternal()->getPayload())) { + if (configurePayload) { + create->setConfigure(configurePayload); + } + } + if (boost::shared_ptr<PubSubSubscribe> subscribe = boost::dynamic_pointer_cast<PubSubSubscribe>(getPayloadInternal()->getPayload())) { + if (optionsPayload) { + subscribe->setOptions(optionsPayload); + } + } + } + } +} + +void PubSubParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubParser.h b/Swiften/Parser/PayloadParsers/PubSubParser.h new file mode 100644 index 0000000..0618361 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubParser.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSub.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + class PubSubOptions; + class PubSubConfigure; + + class SWIFTEN_API PubSubParser : public GenericPayloadParser<PubSub> { + public: + PubSubParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + boost::shared_ptr<PubSubConfigure> configurePayload; + boost::shared_ptr<PubSubOptions> optionsPayload; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubPublishParser.cpp b/Swiften/Parser/PayloadParsers/PubSubPublishParser.cpp new file mode 100644 index 0000000..ca358c3 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubPublishParser.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubPublishParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/PubSubItemParser.h> + +using namespace Swift; + +PubSubPublishParser::PubSubPublishParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubPublishParser::~PubSubPublishParser() { +} + +void PubSubPublishParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } + + if (level == 1) { + if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubItemParser>(parsers); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubPublishParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { + getPayloadInternal()->addItem(boost::dynamic_pointer_cast<PubSubItem>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } +} + +void PubSubPublishParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubPublishParser.h b/Swiften/Parser/PayloadParsers/PubSubPublishParser.h new file mode 100644 index 0000000..3d64e9d --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubPublishParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubPublish.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubPublishParser : public GenericPayloadParser<PubSubPublish> { + public: + PubSubPublishParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubPublishParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubRetractParser.cpp b/Swiften/Parser/PayloadParsers/PubSubRetractParser.cpp new file mode 100644 index 0000000..f4a42d0 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubRetractParser.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubRetractParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/PubSubItemParser.h> + +using namespace Swift; + +PubSubRetractParser::PubSubRetractParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubRetractParser::~PubSubRetractParser() { +} + +void PubSubRetractParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("notify")) { + getPayloadInternal()->setNotify(*attributeValue == "true" ? true : false); + } + } + + if (level == 1) { + if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubItemParser>(parsers); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubRetractParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { + getPayloadInternal()->addItem(boost::dynamic_pointer_cast<PubSubItem>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } +} + +void PubSubRetractParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubRetractParser.h b/Swiften/Parser/PayloadParsers/PubSubRetractParser.h new file mode 100644 index 0000000..2b5e633 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubRetractParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubRetract.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubRetractParser : public GenericPayloadParser<PubSubRetract> { + public: + PubSubRetractParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubRetractParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.cpp new file mode 100644 index 0000000..caed681 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> + + +using namespace Swift; + +PubSubSubscribeOptionsParser::PubSubSubscribeOptionsParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubSubscribeOptionsParser::~PubSubSubscribeOptionsParser() { +} + +void PubSubSubscribeOptionsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubSubscribeOptionsParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + if (element == "required") { + getPayloadInternal()->setRequired(true); + } + currentPayloadParser.reset(); + } + } +} + +void PubSubSubscribeOptionsParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.h b/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.h new file mode 100644 index 0000000..c9ac1ca --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubSubscribeOptions.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubSubscribeOptionsParser : public GenericPayloadParser<PubSubSubscribeOptions> { + public: + PubSubSubscribeOptionsParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubSubscribeOptionsParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.cpp b/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.cpp new file mode 100644 index 0000000..093c2c4 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubSubscribeParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> + + +using namespace Swift; + +PubSubSubscribeParser::PubSubSubscribeParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubSubscribeParser::~PubSubSubscribeParser() { +} + +void PubSubSubscribeParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { + if (boost::optional<JID> jid = JID::parse(*attributeValue)) { + getPayloadInternal()->setJID(*jid); + } + } + } + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubSubscribeParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } +} + +void PubSubSubscribeParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.h b/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.h new file mode 100644 index 0000000..f0ad09d --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubSubscribe.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubSubscribeParser : public GenericPayloadParser<PubSubSubscribe> { + public: + PubSubSubscribeParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubSubscribeParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.cpp b/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.cpp new file mode 100644 index 0000000..be06ec8 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/EnumParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.h> + +using namespace Swift; + +PubSubSubscriptionParser::PubSubSubscriptionParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubSubscriptionParser::~PubSubSubscriptionParser() { +} + +void PubSubSubscriptionParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) { + getPayloadInternal()->setSubscriptionID(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { + if (boost::optional<JID> jid = JID::parse(*attributeValue)) { + getPayloadInternal()->setJID(*jid); + } + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subscription")) { + if (boost::optional<PubSubSubscription::SubscriptionType> value = EnumParser<PubSubSubscription::SubscriptionType>()(PubSubSubscription::None, "none")(PubSubSubscription::Pending, "pending")(PubSubSubscription::Subscribed, "subscribed")(PubSubSubscription::Unconfigured, "unconfigured").parse(*attributeValue)) { + getPayloadInternal()->setSubscription(*value); + } + } + } + + if (level == 1) { + if (element == "subscribe-options" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubSubscribeOptionsParser>(parsers); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubSubscriptionParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + if (element == "subscribe-options" && ns == "http://jabber.org/protocol/pubsub") { + getPayloadInternal()->setOptions(boost::dynamic_pointer_cast<PubSubSubscribeOptions>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } +} + +void PubSubSubscriptionParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.h b/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.h new file mode 100644 index 0000000..49290c2 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubSubscription.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubSubscriptionParser : public GenericPayloadParser<PubSubSubscription> { + public: + PubSubSubscriptionParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubSubscriptionParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.cpp new file mode 100644 index 0000000..3ac3ca0 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.h> + +using namespace Swift; + +PubSubSubscriptionsParser::PubSubSubscriptionsParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubSubscriptionsParser::~PubSubSubscriptionsParser() { +} + +void PubSubSubscriptionsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } + + if (level == 1) { + if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubSubscriptionParser>(parsers); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubSubscriptionsParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub") { + getPayloadInternal()->addSubscription(boost::dynamic_pointer_cast<PubSubSubscription>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } +} + +void PubSubSubscriptionsParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.h b/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.h new file mode 100644 index 0000000..b08db93 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubSubscriptions.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubSubscriptionsParser : public GenericPayloadParser<PubSubSubscriptions> { + public: + PubSubSubscriptionsParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubSubscriptionsParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.cpp b/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.cpp new file mode 100644 index 0000000..53b4fae --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> + + +using namespace Swift; + +PubSubUnsubscribeParser::PubSubUnsubscribeParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +PubSubUnsubscribeParser::~PubSubUnsubscribeParser() { +} + +void PubSubUnsubscribeParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { + if (boost::optional<JID> jid = JID::parse(*attributeValue)) { + getPayloadInternal()->setJID(*jid); + } + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) { + getPayloadInternal()->setSubscriptionID(*attributeValue); + } + } + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void PubSubUnsubscribeParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } +} + +void PubSubUnsubscribeParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.h b/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.h new file mode 100644 index 0000000..a9e5ed0 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/PubSubUnsubscribe.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubUnsubscribeParser : public GenericPayloadParser<PubSubUnsubscribe> { + public: + PubSubUnsubscribeParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubUnsubscribeParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h b/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h index 213cd06..b328670 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h +++ b/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h @@ -1,13 +1,11 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2013 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once -#include <cppunit/extensions/HelperMacros.h> - #include <Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h> #include <Swiften/Parser/XMLParser.h> #include <Swiften/Parser/XMLParserClient.h> @@ -32,9 +30,9 @@ namespace Swift { virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { if (level == 0) { - CPPUNIT_ASSERT(!payloadParser.get()); + assert(!payloadParser.get()); PayloadParserFactory* payloadParserFactory = factories.getPayloadParserFactory(element, ns, attributes); - CPPUNIT_ASSERT(payloadParserFactory); + assert(payloadParserFactory); payloadParser.reset(payloadParserFactory->createPayloadParser()); } payloadParser->handleStartElement(element, ns, attributes); diff --git a/Swiften/Parser/PayloadParsers/UserLocationParser.cpp b/Swiften/Parser/PayloadParsers/UserLocationParser.cpp new file mode 100644 index 0000000..d3aac69 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UserLocationParser.cpp @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Parser/PayloadParsers/UserLocationParser.h> + +#include <boost/lexical_cast.hpp> + +#include <Swiften/Base/DateTime.h> + +using namespace Swift; + +UserLocationParser::UserLocationParser() : level(0) { +} + +UserLocationParser::~UserLocationParser() { +} + +void UserLocationParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { + if (level == 1) { + currentText = ""; + } + ++level; +} + +void UserLocationParser::handleEndElement(const std::string& element, const std::string&) { + --level; + if (level == 1) { + try { + if (element == "accuracy") { + getPayloadInternal()->setAccuracy(boost::lexical_cast<float>(currentText)); + } + else if (element == "alt") { + getPayloadInternal()->setAltitude(boost::lexical_cast<float>(currentText)); + } + else if (element == "area") { + getPayloadInternal()->setArea(currentText); + } + else if (element == "bearing") { + getPayloadInternal()->setBearing(boost::lexical_cast<float>(currentText)); + } + else if (element == "building") { + getPayloadInternal()->setBuilding(currentText); + } + else if (element == "country") { + getPayloadInternal()->setCountry(currentText); + } + else if (element == "countrycode") { + getPayloadInternal()->setCountryCode(currentText); + } + else if (element == "datum") { + getPayloadInternal()->setDatum(currentText); + } + else if (element == "description") { + getPayloadInternal()->setDescription(currentText); + } + else if (element == "error") { + getPayloadInternal()->setError(boost::lexical_cast<float>(currentText)); + } + else if (element == "floor") { + getPayloadInternal()->setFloor(currentText); + } + else if (element == "lat") { + getPayloadInternal()->setLatitude(boost::lexical_cast<float>(currentText)); + } + else if (element == "locality") { + getPayloadInternal()->setLocality(currentText); + } + else if (element == "lon") { + getPayloadInternal()->setLongitude(boost::lexical_cast<float>(currentText)); + } + else if (element == "postalcode") { + getPayloadInternal()->setPostalCode(currentText); + } + else if (element == "region") { + getPayloadInternal()->setRegion(currentText); + } + else if (element == "room") { + getPayloadInternal()->setRoom(currentText); + } + else if (element == "speed") { + getPayloadInternal()->setSpeed(boost::lexical_cast<float>(currentText)); + } + else if (element == "street") { + getPayloadInternal()->setStreet(currentText); + } + else if (element == "text") { + getPayloadInternal()->setText(currentText); + } + else if (element == "timestamp") { + getPayloadInternal()->setTimestamp(stringToDateTime(currentText)); + } + else if (element == "uri") { + getPayloadInternal()->setURI(currentText); + } + } + catch (const boost::bad_lexical_cast&) { + } + } +} + +void UserLocationParser::handleCharacterData(const std::string& data) { + currentText += data; +} diff --git a/Swiften/Parser/PayloadParsers/UserLocationParser.h b/Swiften/Parser/PayloadParsers/UserLocationParser.h new file mode 100644 index 0000000..eb6e668 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UserLocationParser.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> +#include <string> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Parser/GenericPayloadParser.h> +#include <Swiften/Elements/UserLocation.h> + +namespace Swift { + class SWIFTEN_API UserLocationParser : public GenericPayloadParser<UserLocation> { + public: + UserLocationParser(); + virtual ~UserLocationParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + int level; + std::string currentText; + }; +} diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript index 068cbd7..0a6972e 100644 --- a/Swiften/Parser/SConscript +++ b/Swiften/Parser/SConscript @@ -73,7 +73,9 @@ sources = [ "PayloadParsers/S5BProxyRequestParser.cpp", "PayloadParsers/DeliveryReceiptParser.cpp", "PayloadParsers/DeliveryReceiptRequestParser.cpp", + "PayloadParsers/UserLocationParser.cpp", "PayloadParsers/WhiteboardParser.cpp", + "PayloadParsers/PubSubErrorParserFactory.cpp", "PlatformXMLParserFactory.cpp", "PresenceParser.cpp", "SerializingParser.cpp", diff --git a/Swiften/PubSub/PubSubManager.cpp b/Swiften/PubSub/PubSubManager.cpp new file mode 100644 index 0000000..8899b1e --- /dev/null +++ b/Swiften/PubSub/PubSubManager.cpp @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/PubSub/PubSubManager.h> + +using namespace Swift; + +PubSubManager::~PubSubManager() { +} diff --git a/Swiften/PubSub/PubSubManager.h b/Swiften/PubSub/PubSubManager.h new file mode 100644 index 0000000..2f3c84d --- /dev/null +++ b/Swiften/PubSub/PubSubManager.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Base/boost_bsignals.h> +#include <Swiften/Queries/PubSubRequest.h> +#include <Swiften/PubSub/PubSubUtil.h> +#include <Swiften/Elements/PubSub.h> +#include <Swiften/Elements/PubSubOwnerPubSub.h> +#include <Swiften/Elements/PubSubCreate.h> +#include <Swiften/Elements/PubSubSubscribe.h> +#include <Swiften/Elements/PubSubAffiliations.h> +#include <Swiften/Elements/PubSubDefault.h> +#include <Swiften/Elements/PubSubItems.h> +#include <Swiften/Elements/PubSubPublish.h> +#include <Swiften/Elements/PubSubRetract.h> +#include <Swiften/Elements/PubSubSubscription.h> +#include <Swiften/Elements/PubSubSubscriptions.h> +#include <Swiften/Elements/PubSubUnsubscribe.h> +#include <Swiften/Elements/PubSubOwnerAffiliations.h> +#include <Swiften/Elements/PubSubOwnerConfigure.h> +#include <Swiften/Elements/PubSubOwnerDefault.h> +#include <Swiften/Elements/PubSubOwnerDelete.h> +#include <Swiften/Elements/PubSubOwnerPurge.h> +#include <Swiften/Elements/PubSubOwnerSubscriptions.h> +#include <Swiften/Elements/IQ.h> +#include <Swiften/Elements/PubSubEventPayload.h> + +#define SWIFTEN_PUBSUBMANAGER_DECLARE_CREATE_REQUEST(payload, container, response) \ + virtual boost::shared_ptr< PubSubRequest<payload> > \ + createRequest(IQ::Type, const JID&, boost::shared_ptr<payload>) = 0; + +namespace Swift { + class JID; + + class SWIFTEN_API PubSubManager { + public: + virtual ~PubSubManager(); + + SWIFTEN_PUBSUB_FOREACH_PUBSUB_PAYLOAD_TYPE( + SWIFTEN_PUBSUBMANAGER_DECLARE_CREATE_REQUEST) + + boost::signal<void (const JID&, const boost::shared_ptr<PubSubEventPayload>)> onEvent; + }; +} diff --git a/Swiften/PubSub/PubSubManagerImpl.cpp b/Swiften/PubSub/PubSubManagerImpl.cpp new file mode 100644 index 0000000..38b02aa --- /dev/null +++ b/Swiften/PubSub/PubSubManagerImpl.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/PubSub/PubSubManagerImpl.h> + +#include <boost/bind.hpp> + +#include <Swiften/Client/StanzaChannel.h> +#include <Swiften/Elements/Message.h> +#include <Swiften/Elements/PubSubEvent.h> + +using namespace Swift; + +PubSubManagerImpl::PubSubManagerImpl(StanzaChannel* stanzaChannel, IQRouter* router) : + stanzaChannel(stanzaChannel), + router(router) { + stanzaChannel->onMessageReceived.connect(boost::bind(&PubSubManagerImpl::handleMessageRecevied, this, _1)); +} + +PubSubManagerImpl::~PubSubManagerImpl() { + stanzaChannel->onMessageReceived.disconnect(boost::bind(&PubSubManagerImpl::handleMessageRecevied, this, _1)); +} + +void PubSubManagerImpl::handleMessageRecevied(boost::shared_ptr<Message> message) { + if (boost::shared_ptr<PubSubEvent> event = message->getPayload<PubSubEvent>()) { + onEvent(message->getFrom(), event->getPayload()); + } +} diff --git a/Swiften/PubSub/PubSubManagerImpl.h b/Swiften/PubSub/PubSubManagerImpl.h new file mode 100644 index 0000000..65884c0 --- /dev/null +++ b/Swiften/PubSub/PubSubManagerImpl.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/PubSub/PubSubManager.h> + +#define SWIFTEN_PUBSUBMANAGERIMPL_DECLARE_CREATE_REQUEST(payload, container, response) \ + virtual boost::shared_ptr< PubSubRequest<payload> > \ + createRequest(IQ::Type type, const JID& receiver, boost::shared_ptr<payload> p) SWIFTEN_OVERRIDE { \ + return boost::make_shared< PubSubRequest<payload> >(type, receiver, p, router); \ + } + +namespace Swift { + class JID; + class StanzaChannel; + class Message; + + class SWIFTEN_API PubSubManagerImpl : public PubSubManager { + public: + PubSubManagerImpl(StanzaChannel* stanzaChannel, IQRouter* router); + virtual ~PubSubManagerImpl(); + + SWIFTEN_PUBSUB_FOREACH_PUBSUB_PAYLOAD_TYPE( + SWIFTEN_PUBSUBMANAGERIMPL_DECLARE_CREATE_REQUEST) + + private: + void handleMessageRecevied(boost::shared_ptr<Message>); + + private: + StanzaChannel* stanzaChannel; + IQRouter* router; + }; +} diff --git a/Swiften/PubSub/PubSubUtil.h b/Swiften/PubSub/PubSubUtil.h new file mode 100644 index 0000000..3342659 --- /dev/null +++ b/Swiften/PubSub/PubSubUtil.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#define SWIFTEN_PUBSUB_FOREACH_PUBSUB_PAYLOAD_TYPE(action) \ + action(PubSubCreate, PubSub, PubSubCreate) \ + action(PubSubAffiliations, PubSub, PubSubAffiliations) \ + action(PubSubDefault, PubSub, PubSubDefault) \ + action(PubSubItems, PubSub, PubSubItems) \ + action(PubSubOptions, PubSub, PubSubOptions) \ + action(PubSubPublish, PubSub, PubSubPublish) \ + action(PubSubRetract, PubSub, PubSubRetract) \ + action(PubSubSubscription, PubSub, PubSubSubscription) \ + action(PubSubSubscriptions, PubSub, PubSubSubscriptions) \ + action(PubSubSubscribe, PubSub, PubSubSubscription) \ + action(PubSubUnsubscribe, PubSub, PubSubUnsubscribe) \ + action(PubSubOwnerAffiliations, PubSubOwnerPubSub, PubSubOwnerAffiliations) \ + action(PubSubOwnerConfigure, PubSubOwnerPubSub, PubSubOwnerConfigure) \ + action(PubSubOwnerDefault, PubSubOwnerPubSub, PubSubOwnerDefault) \ + action(PubSubOwnerDelete, PubSubOwnerPubSub, PubSubOwnerDelete) \ + action(PubSubOwnerPurge, PubSubOwnerPubSub, PubSubOwnerPurge) \ + action(PubSubOwnerSubscriptions, PubSubOwnerPubSub, PubSubOwnerSubscriptions) + diff --git a/Swiften/QA/ScriptedTests/MultipleClients.lua b/Swiften/QA/ScriptedTests/MultipleClients.lua index ce51481..ddc7c44 100644 --- a/Swiften/QA/ScriptedTests/MultipleClients.lua +++ b/Swiften/QA/ScriptedTests/MultipleClients.lua @@ -1,5 +1,5 @@ -- --- Copyright (c) 2010 Remko Tronçon +-- Copyright (c) 2010-2013 Remko Tronçon -- Licensed under the GNU General Public License v3. -- See Documentation/Licenses/GPLv3.txt for more information. -- @@ -16,17 +16,17 @@ for i = 1, num_clients do client = sluift.new_client(jid, os.getenv("SWIFT_CLIENTTEST_PASS")) client:set_options({compress = false}) client:async_connect() - table.insert(clients, client) + clients[#clients+1] = client end print("Waiting for clients to be connected") -for i, client in ipairs(clients) do +for _, client in ipairs(clients) do client:wait_connected() client:send_presence("Hello") end print("Disconnecting clients") -for i, client in ipairs(clients) do +for _, client in ipairs(clients) do client:disconnect() end diff --git a/Swiften/QA/ScriptedTests/PubSub.lua b/Swiften/QA/ScriptedTests/PubSub.lua new file mode 100644 index 0000000..a9c0fe8 --- /dev/null +++ b/Swiften/QA/ScriptedTests/PubSub.lua @@ -0,0 +1,288 @@ + --[[ + Copyright (c) 2013 Remko Tronçon + Licensed under the GNU General Public License. + See the COPYING file for more information. +--]] + +require 'sluift' + +sluift.debug = os.getenv("SLUIFT_DEBUG") + +local publisher +local publisher_jid = os.getenv("SLUIFT_JID") +local pubsub_jid = os.getenv("SLUIFT_PUBSUB_SERVICE") or sluift.jid.to_bare(publisher_jid) +local pubsub +local node_id = os.getenv("SLUIFT_PUBSUB_NODE") or "http://swift.im/Swiften/QA/PubSub" +local node + +local subscriber +local subscriber_jid = os.getenv("SLUIFT_JID2") +local subscriber_pubsub +local subscriber_node + +local publish_item = {id = 'item_id', data = {{ _type = 'software_version', name = 'MyTest', os = 'Lua' }} } +local publish_item2 = {id = 'item_id2', data = {{ _type = 'software_version', name = 'MyTest2', os = 'Lua' }} } + +-------------------------------------------------------------------------------- +-- Helper methods +-------------------------------------------------------------------------------- + +function purge_pubsub_events(client) + client:for_each_pubsub_event({timeout = 2000}, function() end) +end + +-------------------------------------------------------------------------------- +-- 5. Entity use cases +-------------------------------------------------------------------------------- +function test_entity_use_cases() + node:delete() + + -- 5.2 List nodes + assert(node:create()) + local nodes = assert(pubsub:list_nodes()).items + local found_item = false + for _, node in ipairs(nodes) do + if node.node == node_id then found_item = true end + end + assert(found_item) + assert(node:delete()) + + + -- 5.5 Discover items of node + assert(node:create()) + assert(node:publish {items = {publish_item}}) + local items = assert(node:list_items()).items + assert(#items == 1) + assert(items[1].name == 'item_id') + assert(node:delete()) + + -- 5.6 Subscriptions + assert(node:create()) + assert(subscriber_node:subscribe({ jid = subscriber_jid })) + local service_subscriptions = assert(pubsub:get_subscriptions()) + -- FIXME: Doesn't seem to return anything on M-Link. Test this later if this is supposed to work. + --print(service_subscriptions) + local node_subscriptions = assert(node:get_subscriptions()) + --print(node_subscriptions) + assert(node:delete()) + + -- 5.7 Retrieve affiliations + --print(pubsub:get_affiliations()) -- Freezes Isode + --print(node:get_affiliations()) -- Freezes isode +end + +-------------------------------------------------------------------------------- +-- 6. Subscriber use cases +-------------------------------------------------------------------------------- + +function test_subscriber_use_cases() + node:delete() + + -- 6.1 Subscribe to a node + assert(node:create()) + local subscription = assert(subscriber_node:subscribe({ jid = subscriber_jid })) + -- TODO: Test subscription id etc. Doesn't work with M-link atm + -- TODO: Test pending subscription + -- TODO: Test configuration required + assert(node:delete()) + + -- 6.2 Unsubscribe from a node + assert(node:create()) + assert(subscriber_node:subscribe({ jid = subscriber_jid })) + assert(subscriber_node:unsubscribe({ jid = subscriber_jid })) + assert(node:delete()) + + -- 6.3 Configure subscription options + -- TODO: Not supported by M-Link? Finish it later + --assert(node:create()) + --assert(subscriber_node:subscribe({ jid = subscriber_jid })) + --local options = assert(subscriber_node:get_subscription_options({ jid = subscriber_jid })) + --print(options) + --assert(node:delete()) + + -- 6.4 Request default subscription configuration options + -- TODO: Not supported by M-Link? Finish it later + --local options = assert(subscriber_pubsub:get_default_subscription_options()) + --print(options) + --local options = assert(subscriber_node:get_default_subscription_options()) + --print(options) + + -- 6.5 Retrieve items of a node + assert(node:create()) + assert(node:publish {item = publish_item}) + local items = assert(subscriber_node:get_items()) + assert(#items == 1) + assert(items[1].id == 'item_id') + assert(items[1].data[1].name == 'MyTest') + assert(node:delete()) +end + +-------------------------------------------------------------------------------- +-- 7. Publisher use cases +-------------------------------------------------------------------------------- + +function test_publisher_use_cases() + node:delete() + + -- 7.1 Publish item to a node + assert(node:create()) + assert(subscriber_node:subscribe({ jid = subscriber_jid })) + purge_pubsub_events(subscriber) + assert(node:publish {items = {publish_item}}) + local event = assert(subscriber:get_next_event { type = 'pubsub' }) + assert(event.from == publisher_jid) + assert(event._type == 'pubsub_event_items') + assert(event.items[1].id == publish_item.id) + assert(event.items[1].data[1].os == publish_item.data[1].os) + assert(event.item.os == publish_item.data[1].os) + assert(node:delete()) + + -- 7.2 Delete item from a node + assert(node:create()) + assert(subscriber_node:subscribe({ jid = subscriber_jid })) + assert(node:publish {items = {publish_item}}) + assert(node:retract { item = 'item_id', notify = true }) + assert(node:delete()) + + -- 7.2.2.1 Delete and notify + assert(node:create()) + assert(subscriber_node:subscribe({ jid = subscriber_jid })) + assert(node:publish {items = {publish_item}}) + purge_pubsub_events(subscriber) + assert(node:retract { item = 'item_id', notify = true }) + local event = assert(subscriber:get_next_event { type = 'pubsub' }) + assert(event._type == 'pubsub_event_items') + assert(event.retracts[1].id == 'item_id') + assert(node:delete()) + + -- Publish an unknown element type + atom = [[ + <entry xmlns='http://www.w3.org/2005/Atom'> + <title>Down the Rabbit Hole</title> + <summary> + Alice was beginning to get very tired of sitting by her sister on the + bank and of having nothing to do: once or twice she had peeped into the + book her sister was reading, but it had no pictures or conversations in + it, "and what is the use of a book," thought Alice, "without pictures + or conversations?' + </summary> + <link rel='alternate' type='text/html' + href='http://www.gutenberg.org/files/11/11-h/11-h.htm#link2HCH0001'/> + <id>tag:gutenberg.org,2008:entry-1234</id> + <published>2008-06-25T18:30:02Z</published> + <updated>2008-06-25T18:30:02Z</updated> + </entry> + ]] + assert(node:create()) + assert(subscriber_node:subscribe({ jid = subscriber_jid })) + purge_pubsub_events(subscriber) + assert(node:publish { item = atom }) + local event_item = assert(subscriber:get_next_event { type = 'pubsub' }).item + assert(event_item._type == 'dom') + assert(event_item.ns == 'http://www.w3.org/2005/Atom') + assert(event_item.tag == 'entry') + assert(node:delete()) +end + +-------------------------------------------------------------------------------- +-- 8 Owner Use Cases +-------------------------------------------------------------------------------- + +function test_owner_use_cases() + node:delete() + + -- 8.1 Create a node + -- Create node with default config + assert(node:create()) + configuration = assert(node:get_configuration())['data'] + assert(node:delete()) + + -- Create node with custom config + print("Creating with configuration") + assert(node:create { configuration = { ['pubsub#access_model'] = 'whitelist' } }) + configuration = assert(node:get_configuration())['data'] + assert(configuration['pubsub#access_model']['value'] == 'whitelist') + assert(node:delete()) + + -- 8.2 Configure node + -- Set configuration + assert(node:create()) + assert(node:set_configuration {configuration = {['pubsub#access_model'] = 'whitelist'}}) + configuration = assert(node:get_configuration())['data'] + assert(configuration['pubsub#access_model']['value'] == 'whitelist') + assert(node:delete()) + + -- Untested: 8.2.5.3 Success With Notifications + + -- 8.3 Request Default Node Configuration Options + configuration = assert(pubsub:get_default_configuration())['data'] + assert(configuration['pubsub#access_model'] ~= nil) + + -- 8.4 Delete node + -- Without redirection (see above) + -- With redirection + assert(node:create()) + assert(subscriber_node:subscribe({ jid = subscriber_jid })) + purge_pubsub_events(subscriber) + assert(node:delete {redirect = 'foo@bar.com'}) + -- FIXME: M-Link doesn't send out an event. Test this later. + --local event = assert(subscriber:get_next_event { type = 'pubsub' }) + --print(event) + --assert(event._type == 'pubsub_event_items') + --assert(event.retracts[1].id == 'item_id') + + -- 8.5 Purge node items + assert(node:create()) + assert(subscriber_node:subscribe({ jid = subscriber_jid })) + -- Publishing multiple items doesn't seem to work in M-Link + --assert(node:publish {items = { publish_item, publish_item2 }}) + assert(node:publish {items = {publish_item} }) + assert(node:publish {items = {publish_item2} }) + purge_pubsub_events(subscriber) + if node:purge() then + -- Hasn't worked yet. Add more to this test later (including notifications) + else + print("Warning: Purge not supported. Skipping test") + end + assert(node:delete()) + + -- 8.6 Manage subscription requests + -- TODO + + -- 8.7 Process pending subscription requests + -- TODO + + -- ... +end + +function run_tests() + connect_options = {} + + -- Set up publisher & subscriber + publisher = sluift.new_client(publisher_jid, os.getenv("SLUIFT_PASS")) + assert(publisher:connect(connect_options)) + subscriber = sluift.new_client(subscriber_jid, os.getenv("SLUIFT_PASS2")) + assert(subscriber:connect(connect_options)) + + pubsub = publisher:pubsub(pubsub_jid) + node = pubsub:node(node_id) + + subscriber_pubsub = subscriber:pubsub(pubsub_jid) + subscriber_node = subscriber_pubsub:node(node_id) + + -- The tests + test_entity_use_cases() + test_subscriber_use_cases() + test_publisher_use_cases() + test_owner_use_cases() +end + +success, err = pcall(run_tests) + +if subscriber then subscriber:disconnect() end +if publisher then publisher:disconnect() end + +if not success then + print(err) + os.exit(-1) +end diff --git a/Swiften/QA/ScriptedTests/SendMessage.lua b/Swiften/QA/ScriptedTests/SendMessage.lua index 8c54d00..9623ef4 100644 --- a/Swiften/QA/ScriptedTests/SendMessage.lua +++ b/Swiften/QA/ScriptedTests/SendMessage.lua @@ -1,5 +1,5 @@ -- --- Copyright (c) 2010 Remko Tronçon +-- Copyright (c) 2010-2013 Remko Tronçon -- Licensed under the GNU General Public License v3. -- See Documentation/Licenses/GPLv3.txt for more information. -- @@ -23,22 +23,22 @@ client2:send_presence("I'm here") print "Checking version of client 2 from client 1" client2:set_version({name = "Sluift Test", version = "1.0"}) -client2_version = client1:get_version(client2_jid) +client2_version = client1:get_software_version {to=client2_jid} assert(client2_version["name"] == "Sluift Test") assert(client2_version["version"] == "1.0") print "Sending message from client 1 to client 2" client1:send_message(client2_jid, "Hello") -received_message = client2:for_event(function(event) - if event["type"] == "message" and event["from"] == client1_jid then - return event["body"] - end - end, 10000) +received_message = client2:for_each_message({timeout = 1000}, function(message) + if message["from"] == client1_jid then + return message["body"] + end +end) assert(received_message == "Hello") print "Retrieving the roster" roster = client1:get_roster() -tprint(roster) +sluift.tprint(roster) client1:disconnect() client2:disconnect() diff --git a/Swiften/Queries/PubSubRequest.h b/Swiften/Queries/PubSubRequest.h new file mode 100644 index 0000000..aeee3bd --- /dev/null +++ b/Swiften/Queries/PubSubRequest.h @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <Swiften/Base/boost_bsignals.h> +#include <Swiften/Queries/Request.h> +#include <Swiften/Elements/ContainerPayload.h> +#include <Swiften/PubSub/PubSubUtil.h> +#include <Swiften/Elements/PubSub.h> +#include <Swiften/Elements/PubSubOwnerPubSub.h> +#include <Swiften/Elements/PubSubCreate.h> +#include <Swiften/Elements/PubSubSubscribe.h> +#include <Swiften/Elements/PubSubAffiliations.h> +#include <Swiften/Elements/PubSubDefault.h> +#include <Swiften/Elements/PubSubItems.h> +#include <Swiften/Elements/PubSubPublish.h> +#include <Swiften/Elements/PubSubRetract.h> +#include <Swiften/Elements/PubSubSubscription.h> +#include <Swiften/Elements/PubSubSubscriptions.h> +#include <Swiften/Elements/PubSubUnsubscribe.h> +#include <Swiften/Elements/PubSubOwnerAffiliations.h> +#include <Swiften/Elements/PubSubOwnerConfigure.h> +#include <Swiften/Elements/PubSubOwnerDefault.h> +#include <Swiften/Elements/PubSubOwnerDelete.h> +#include <Swiften/Elements/PubSubOwnerPurge.h> +#include <Swiften/Elements/PubSubOwnerSubscriptions.h> + +namespace Swift { + namespace Detail { + template<typename T> + struct PubSubPayloadTraits; + +#define SWIFTEN_PUBSUB_DECLARE_PAYLOAD_TRAITS(PAYLOAD, CONTAINER, RESPONSE) \ + template<> struct PubSubPayloadTraits< PAYLOAD > { \ + typedef CONTAINER ContainerType; \ + typedef RESPONSE ResponseType; \ + }; + + SWIFTEN_PUBSUB_FOREACH_PUBSUB_PAYLOAD_TYPE( + SWIFTEN_PUBSUB_DECLARE_PAYLOAD_TRAITS) + } + + template<typename T> + class PubSubRequest : public Request { + typedef typename Detail::PubSubPayloadTraits<T>::ContainerType ContainerType; + typedef typename Detail::PubSubPayloadTraits<T>::ResponseType ResponseType; + + public: + PubSubRequest( + IQ::Type type, + const JID& receiver, + boost::shared_ptr<T> payload, + IQRouter* router) : + Request(type, receiver, router) { + boost::shared_ptr<ContainerType> wrapper = boost::make_shared<ContainerType>(); + wrapper->setPayload(payload); + setPayload(wrapper); + } + + PubSubRequest( + IQ::Type type, + const JID& sender, + const JID& receiver, + boost::shared_ptr<T> payload, + IQRouter* router) : + Request(type, sender, receiver, router) { + boost::shared_ptr<ContainerType> wrapper = boost::make_shared<ContainerType>(); + wrapper->setPayload(payload); + setPayload(wrapper); + } + + virtual void handleResponse( + boost::shared_ptr<Payload> payload, ErrorPayload::ref error) { + boost::shared_ptr<ResponseType> result; + if (boost::shared_ptr<ContainerType> container = boost::dynamic_pointer_cast<ContainerType>(payload)) { + result = boost::dynamic_pointer_cast<ResponseType>(container->getPayload()); + } + onResponse(result, error); + } + + public: + boost::signal<void (boost::shared_ptr<ResponseType>, ErrorPayload::ref)> onResponse; + }; +} diff --git a/Swiften/SConscript b/Swiften/SConscript index 3edb463..0e7bb51 100644 --- a/Swiften/SConscript +++ b/Swiften/SConscript @@ -125,6 +125,9 @@ if env["SCONS_STAGE"] == "build" : "Elements/Element.cpp", "Elements/IQ.cpp", "Elements/Payload.cpp", + "Elements/PubSubPayload.cpp", + "Elements/PubSubOwnerPayload.cpp", + "Elements/PubSubEventPayload.cpp", "Elements/RosterItemExchangePayload.cpp", "Elements/RosterPayload.cpp", "Elements/Stanza.cpp", @@ -133,6 +136,7 @@ if env["SCONS_STAGE"] == "build" : "Elements/StreamManagementEnabled.cpp", "Elements/StreamResume.cpp", "Elements/StreamResumed.cpp", + "Elements/UserLocation.cpp", "Elements/VCard.cpp", "Elements/MUCOccupant.cpp", "Entity/Entity.cpp", @@ -141,6 +145,8 @@ if env["SCONS_STAGE"] == "build" : "MUC/MUCManager.cpp", "MUC/MUCRegistry.cpp", "MUC/MUCBookmarkManager.cpp", + "PubSub/PubSubManager.cpp", + "PubSub/PubSubManagerImpl.cpp", "Queries/IQChannel.cpp", "Queries/IQHandler.cpp", "Queries/IQRouter.cpp", @@ -207,6 +213,7 @@ if env["SCONS_STAGE"] == "build" : "Serializer/PayloadSerializers/StreamInitiationFileInfoSerializer.cpp", "Serializer/PayloadSerializers/DeliveryReceiptSerializer.cpp", "Serializer/PayloadSerializers/DeliveryReceiptRequestSerializer.cpp", + "Serializer/PayloadSerializers/UserLocationSerializer.cpp", "Serializer/PayloadSerializers/WhiteboardSerializer.cpp", "Serializer/PresenceSerializer.cpp", "Serializer/StanzaSerializer.cpp", @@ -232,6 +239,28 @@ if env["SCONS_STAGE"] == "build" : "Elements/Whiteboard/WhiteboardColor.cpp", "Whiteboard/WhiteboardTransformer.cpp", ] + + elements = [ + "PubSub", "PubSubAffiliations", "PubSubAffiliation", "PubSubConfigure", "PubSubCreate", "PubSubDefault", + "PubSubItems", "PubSubItem", "PubSubOptions", "PubSubPublish", "PubSubRetract", "PubSubSubscribeOptions", + "PubSubSubscribe", "PubSubSubscriptions", "PubSubSubscription", "PubSubUnsubscribe", + + "PubSubEvent", "PubSubEventAssociate", "PubSubEventCollection", "PubSubEventConfiguration", "PubSubEventDelete", + "PubSubEventDisassociate", "PubSubEventItem", "PubSubEventItems", "PubSubEventPurge", "PubSubEventRedirect", + "PubSubEventRetract", "PubSubEventSubscription", + + "PubSubOwnerAffiliation", "PubSubOwnerAffiliations", "PubSubOwnerConfigure", "PubSubOwnerDefault", + "PubSubOwnerDelete", "PubSubOwnerPubSub", "PubSubOwnerPurge", "PubSubOwnerRedirect", + "PubSubOwnerSubscription", "PubSubOwnerSubscriptions", + + "PubSubError", + ] + for element in elements : + sources += [ + "Elements/" + element + ".cpp", + "Serializer/PayloadSerializers/" + element + "Serializer.cpp", + "Parser/PayloadParsers/" + element + "Parser.cpp", + ] SConscript(dirs = [ "Avatars", diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp index 3f45a7c..a57a74e 100644 --- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp +++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2013 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ @@ -51,7 +51,12 @@ #include <Swiften/Serializer/PayloadSerializers/ReplaceSerializer.h> #include <Swiften/Serializer/PayloadSerializers/LastSerializer.h> #include <Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/UserLocationSerializer.h> #include <Swiften/Serializer/PayloadSerializers/IdleSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubOwnerPubSubSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubEventSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubErrorSerializer.h> #include <Swiften/Serializer/PayloadSerializers/StreamInitiationFileInfoSerializer.h> #include <Swiften/Serializer/PayloadSerializers/JingleContentPayloadSerializer.h> @@ -111,6 +116,7 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() { serializers_.push_back(new ReplaceSerializer()); serializers_.push_back(new LastSerializer()); serializers_.push_back(new WhiteboardSerializer()); + serializers_.push_back(new UserLocationSerializer()); serializers_.push_back(new IdleSerializer()); serializers_.push_back(new StreamInitiationFileInfoSerializer()); @@ -124,6 +130,11 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() { serializers_.push_back(new S5BProxyRequestSerializer()); serializers_.push_back(new DeliveryReceiptSerializer()); serializers_.push_back(new DeliveryReceiptRequestSerializer()); + + serializers_.push_back(new PubSubSerializer(this)); + serializers_.push_back(new PubSubEventSerializer(this)); + serializers_.push_back(new PubSubOwnerPubSubSerializer(this)); + serializers_.push_back(new PubSubErrorSerializer()); foreach(PayloadSerializer* serializer, serializers_) { addSerializer(serializer); diff --git a/Swiften/Serializer/PayloadSerializers/PubSubAffiliationSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubAffiliationSerializer.cpp new file mode 100644 index 0000000..d5d5ead --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubAffiliationSerializer.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubAffiliationSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> + + +#include <Swiften/Serializer/PayloadSerializerCollection.h> + + +using namespace Swift; + +PubSubAffiliationSerializer::PubSubAffiliationSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubAffiliationSerializer::~PubSubAffiliationSerializer() { +} + +std::string PubSubAffiliationSerializer::serializePayload(boost::shared_ptr<PubSubAffiliation> payload) const { + if (!payload) { + return ""; + } + XMLElement element("affiliation", "http://jabber.org/protocol/pubsub"); + element.setAttribute("node", payload->getNode()); + element.setAttribute("affiliation", serializeType(payload->getType())); + return element.serialize(); +} + +std::string PubSubAffiliationSerializer::serializeType(PubSubAffiliation::Type value) { + switch (value) { + case PubSubAffiliation::None: return "none"; + case PubSubAffiliation::Member: return "member"; + case PubSubAffiliation::Outcast: return "outcast"; + case PubSubAffiliation::Owner: return "owner"; + case PubSubAffiliation::Publisher: return "publisher"; + case PubSubAffiliation::PublishOnly: return "publish-only"; + } + assert(false); + return ""; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubAffiliationSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubAffiliationSerializer.h new file mode 100644 index 0000000..f6722c8 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubAffiliationSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubAffiliation.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubAffiliationSerializer : public GenericPayloadSerializer<PubSubAffiliation> { + public: + PubSubAffiliationSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubAffiliationSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubAffiliation>) const SWIFTEN_OVERRIDE; + + private: + static std::string serializeType(PubSubAffiliation::Type); + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubAffiliationsSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubAffiliationsSerializer.cpp new file mode 100644 index 0000000..25a0786 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubAffiliationsSerializer.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubAffiliationsSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Serializer/PayloadSerializerCollection.h> +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubAffiliationSerializer.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> + +using namespace Swift; + +PubSubAffiliationsSerializer::PubSubAffiliationsSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubAffiliationsSerializer::~PubSubAffiliationsSerializer() { +} + +std::string PubSubAffiliationsSerializer::serializePayload(boost::shared_ptr<PubSubAffiliations> payload) const { + if (!payload) { + return ""; + } + XMLElement element("affiliations", "http://jabber.org/protocol/pubsub"); + if (payload->getNode()) { + element.setAttribute("node", *payload->getNode()); + } + foreach(boost::shared_ptr<PubSubAffiliation> item, payload->getAffiliations()) { + element.addNode(boost::make_shared<XMLRawTextNode>(PubSubAffiliationSerializer(serializers).serialize(item))); + } + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/PubSubAffiliationsSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubAffiliationsSerializer.h new file mode 100644 index 0000000..ba3c591 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubAffiliationsSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubAffiliations.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubAffiliationsSerializer : public GenericPayloadSerializer<PubSubAffiliations> { + public: + PubSubAffiliationsSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubAffiliationsSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubAffiliations>) const SWIFTEN_OVERRIDE; + + private: + + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubConfigureSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubConfigureSerializer.cpp new file mode 100644 index 0000000..86a1ae8 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubConfigureSerializer.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubConfigureSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Serializer/PayloadSerializerCollection.h> +#include <Swiften/Serializer/PayloadSerializers/FormSerializer.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> + +using namespace Swift; + +PubSubConfigureSerializer::PubSubConfigureSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubConfigureSerializer::~PubSubConfigureSerializer() { +} + +std::string PubSubConfigureSerializer::serializePayload(boost::shared_ptr<PubSubConfigure> payload) const { + if (!payload) { + return ""; + } + XMLElement element("configure", "http://jabber.org/protocol/pubsub"); + element.addNode(boost::make_shared<XMLRawTextNode>(FormSerializer().serialize(payload->getData()))); + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/PubSubConfigureSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubConfigureSerializer.h new file mode 100644 index 0000000..093fd35 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubConfigureSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubConfigure.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubConfigureSerializer : public GenericPayloadSerializer<PubSubConfigure> { + public: + PubSubConfigureSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubConfigureSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubConfigure>) const SWIFTEN_OVERRIDE; + + private: + + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubCreateSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubCreateSerializer.cpp new file mode 100644 index 0000000..73b2703 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubCreateSerializer.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubCreateSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> + + +#include <Swiften/Serializer/PayloadSerializerCollection.h> + + +using namespace Swift; + +PubSubCreateSerializer::PubSubCreateSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubCreateSerializer::~PubSubCreateSerializer() { +} + +std::string PubSubCreateSerializer::serializePayload(boost::shared_ptr<PubSubCreate> payload) const { + if (!payload) { + return ""; + } + XMLElement element("create", "http://jabber.org/protocol/pubsub"); + element.setAttribute("node", payload->getNode()); + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/PubSubCreateSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubCreateSerializer.h new file mode 100644 index 0000000..29c2393 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubCreateSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubCreate.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubCreateSerializer : public GenericPayloadSerializer<PubSubCreate> { + public: + PubSubCreateSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubCreateSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubCreate>) const SWIFTEN_OVERRIDE; + + private: + + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubDefaultSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubDefaultSerializer.cpp new file mode 100644 index 0000000..d395c80 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubDefaultSerializer.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubDefaultSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> + + +#include <Swiften/Serializer/PayloadSerializerCollection.h> + + +using namespace Swift; + +PubSubDefaultSerializer::PubSubDefaultSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubDefaultSerializer::~PubSubDefaultSerializer() { +} + +std::string PubSubDefaultSerializer::serializePayload(boost::shared_ptr<PubSubDefault> payload) const { + if (!payload) { + return ""; + } + XMLElement element("default", "http://jabber.org/protocol/pubsub"); + if (payload->getNode()) { + element.setAttribute("node", *payload->getNode()); + } + element.setAttribute("type", serializeType(payload->getType())); + return element.serialize(); +} + +std::string PubSubDefaultSerializer::serializeType(PubSubDefault::Type value) { + switch (value) { + case PubSubDefault::None: return "none"; + case PubSubDefault::Collection: return "collection"; + case PubSubDefault::Leaf: return "leaf"; + } + assert(false); + return ""; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubDefaultSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubDefaultSerializer.h new file mode 100644 index 0000000..e7b8a6f --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubDefaultSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubDefault.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubDefaultSerializer : public GenericPayloadSerializer<PubSubDefault> { + public: + PubSubDefaultSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubDefaultSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubDefault>) const SWIFTEN_OVERRIDE; + + private: + static std::string serializeType(PubSubDefault::Type); + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubErrorSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubErrorSerializer.cpp new file mode 100644 index 0000000..a25b71e --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubErrorSerializer.cpp @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Serializer/PayloadSerializers/PubSubErrorSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> + +#include <Swiften/Serializer/PayloadSerializerCollection.h> + +using namespace Swift; + +PubSubErrorSerializer::PubSubErrorSerializer() { +} + +PubSubErrorSerializer::~PubSubErrorSerializer() { +} + +std::string PubSubErrorSerializer::serializePayload(boost::shared_ptr<PubSubError> payload) const { + if (payload->getType() == PubSubError::UnknownType) { + return ""; + } + XMLElement element(serializeType(payload->getType()), "http://jabber.org/protocol/pubsub#errors"); + if (payload->getType() == PubSubError::Unsupported) { + if (payload->getUnsupportedFeatureType() != PubSubError::UnknownUnsupportedFeatureType) { + element.setAttribute("feature", serializeUnsupportedFeatureType(payload->getUnsupportedFeatureType())); + } + } + return element.serialize(); +} + +std::string PubSubErrorSerializer::serializeType(PubSubError::Type value) { + switch (value) { + case PubSubError::UnknownType: assert(false); return ""; + case PubSubError::ClosedNode: return "closed-node"; + case PubSubError::ConfigurationRequired: return "configuration-required"; + case PubSubError::InvalidJID: return "invalid-jid"; + case PubSubError::InvalidOptions: return "invalid-options"; + case PubSubError::InvalidPayload: return "invalid-payload"; + case PubSubError::InvalidSubscriptionID: return "invalid-subid"; + case PubSubError::ItemForbidden: return "item-forbidden"; + case PubSubError::ItemRequired: return "item-required"; + case PubSubError::JIDRequired: return "jid-required"; + case PubSubError::MaximumItemsExceeded: return "max-items-exceeded"; + case PubSubError::MaximumNodesExceeded: return "max-nodes-exceeded"; + case PubSubError::NodeIDRequired: return "nodeid-required"; + case PubSubError::NotInRosterGroup: return "not-in-roster-group"; + case PubSubError::NotSubscribed: return "not-subscribed"; + case PubSubError::PayloadTooBig: return "payload-too-big"; + case PubSubError::PayloadRequired: return "payload-required"; + case PubSubError::PendingSubscription: return "pending-subscription"; + case PubSubError::PresenceSubscriptionRequired: return "presence-subscription-required"; + case PubSubError::SubscriptionIDRequired: return "subid-required"; + case PubSubError::TooManySubscriptions: return "too-many-subscriptions"; + case PubSubError::Unsupported: return "unsupported"; + case PubSubError::UnsupportedAccessModel: return "unsupported-access-model"; + } + assert(false); + return ""; +} + +std::string PubSubErrorSerializer::serializeUnsupportedFeatureType(PubSubError::UnsupportedFeatureType value) { + switch (value) { + case PubSubError::UnknownUnsupportedFeatureType: assert(false); return ""; + case PubSubError::AccessAuthorize: return "access-authorize"; + case PubSubError::AccessOpen: return "access-open"; + case PubSubError::AccessPresence: return "access-presence"; + case PubSubError::AccessRoster: return "access-roster"; + case PubSubError::AccessWhitelist: return "access-whitelist"; + case PubSubError::AutoCreate: return "auto-create"; + case PubSubError::AutoSubscribe: return "auto-subscribe"; + case PubSubError::Collections: return "collections"; + case PubSubError::ConfigNode: return "config-node"; + case PubSubError::CreateAndConfigure: return "create-and-configure"; + case PubSubError::CreateNodes: return "create-nodes"; + case PubSubError::DeleteItems: return "delete-items"; + case PubSubError::DeleteNodes: return "delete-nodes"; + case PubSubError::FilteredNotifications: return "filtered-notifications"; + case PubSubError::GetPending: return "get-pending"; + case PubSubError::InstantNodes: return "instant-nodes"; + case PubSubError::ItemIDs: return "item-ids"; + case PubSubError::LastPublished: return "last-published"; + case PubSubError::LeasedSubscription: return "leased-subscription"; + case PubSubError::ManageSubscriptions: return "manage-subscriptions"; + case PubSubError::MemberAffiliation: return "member-affiliation"; + case PubSubError::MetaData: return "meta-data"; + case PubSubError::ModifyAffiliations: return "modify-affiliations"; + case PubSubError::MultiCollection: return "multi-collection"; + case PubSubError::MultiSubscribe: return "multi-subscribe"; + case PubSubError::OutcastAffiliation: return "outcast-affiliation"; + case PubSubError::PersistentItems: return "persistent-items"; + case PubSubError::PresenceNotifications: return "presence-notifications"; + case PubSubError::PresenceSubscribe: return "presence-subscribe"; + case PubSubError::Publish: return "publish"; + case PubSubError::PublishOptions: return "publish-options"; + case PubSubError::PublishOnlyAffiliation: return "publish-only-affiliation"; + case PubSubError::PublisherAffiliation: return "publisher-affiliation"; + case PubSubError::PurgeNodes: return "purge-nodes"; + case PubSubError::RetractItems: return "retract-items"; + case PubSubError::RetrieveAffiliations: return "retrieve-affiliations"; + case PubSubError::RetrieveDefault: return "retrieve-default"; + case PubSubError::RetrieveItems: return "retrieve-items"; + case PubSubError::RetrieveSubscriptions: return "retrieve-subscriptions"; + case PubSubError::Subscribe: return "subscribe"; + case PubSubError::SubscriptionOptions: return "subscription-options"; + case PubSubError::SubscriptionNotifications: return "subscription-notifications"; + } + assert(false); + return ""; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubErrorSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubErrorSerializer.h new file mode 100644 index 0000000..3ee09ce --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubErrorSerializer.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubError.h> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubErrorSerializer : public GenericPayloadSerializer<PubSubError> { + public: + PubSubErrorSerializer(); + virtual ~PubSubErrorSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubError>) const SWIFTEN_OVERRIDE; + + private: + static std::string serializeType(PubSubError::Type); + static std::string serializeUnsupportedFeatureType(PubSubError::UnsupportedFeatureType); + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubEventAssociateSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubEventAssociateSerializer.cpp new file mode 100644 index 0000000..1baf7e4 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubEventAssociateSerializer.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubEventAssociateSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> + + +#include <Swiften/Serializer/PayloadSerializerCollection.h> + + +using namespace Swift; + +PubSubEventAssociateSerializer::PubSubEventAssociateSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubEventAssociateSerializer::~PubSubEventAssociateSerializer() { +} + +std::string PubSubEventAssociateSerializer::serializePayload(boost::shared_ptr<PubSubEventAssociate> payload) const { + if (!payload) { + return ""; + } + XMLElement element("associate", "http://jabber.org/protocol/pubsub#event"); + element.setAttribute("node", payload->getNode()); + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/PubSubEventAssociateSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubEventAssociateSerializer.h new file mode 100644 index 0000000..60cf9c7 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubEventAssociateSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubEventAssociate.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubEventAssociateSerializer : public GenericPayloadSerializer<PubSubEventAssociate> { + public: + PubSubEventAssociateSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubEventAssociateSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubEventAssociate>) const SWIFTEN_OVERRIDE; + + private: + + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubEventCollectionSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubEventCollectionSerializer.cpp new file mode 100644 index 0000000..b44acaa --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubEventCollectionSerializer.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubEventCollectionSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Serializer/PayloadSerializerCollection.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubEventAssociateSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubEventDisassociateSerializer.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> + +using namespace Swift; + +PubSubEventCollectionSerializer::PubSubEventCollectionSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubEventCollectionSerializer::~PubSubEventCollectionSerializer() { +} + +std::string PubSubEventCollectionSerializer::serializePayload(boost::shared_ptr<PubSubEventCollection> payload) const { + if (!payload) { + return ""; + } + XMLElement element("collection", "http://jabber.org/protocol/pubsub#event"); + if (payload->getNode()) { + element.setAttribute("node", *payload->getNode()); + } + element.addNode(boost::make_shared<XMLRawTextNode>(PubSubEventDisassociateSerializer(serializers).serialize(payload->getDisassociate()))); + element.addNode(boost::make_shared<XMLRawTextNode>(PubSubEventAssociateSerializer(serializers).serialize(payload->getAssociate()))); + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/PubSubEventCollectionSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubEventCollectionSerializer.h new file mode 100644 index 0000000..ac5e7c4 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubEventCollectionSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubEventCollection.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubEventCollectionSerializer : public GenericPayloadSerializer<PubSubEventCollection> { + public: + PubSubEventCollectionSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubEventCollectionSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubEventCollection>) const SWIFTEN_OVERRIDE; + + private: + + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubEventConfigurationSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubEventConfigurationSerializer.cpp new file mode 100644 index 0000000..f478e4f --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubEventConfigurationSerializer.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubEventConfigurationSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Serializer/PayloadSerializerCollection.h> +#include <Swiften/Serializer/PayloadSerializers/FormSerializer.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> + +using namespace Swift; + +PubSubEventConfigurationSerializer::PubSubEventConfigurationSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubEventConfigurationSerializer::~PubSubEventConfigurationSerializer() { +} + +std::string PubSubEventConfigurationSerializer::serializePayload(boost::shared_ptr<PubSubEventConfiguration> payload) const { + if (!payload) { + return ""; + } + XMLElement element("configuration", "http://jabber.org/protocol/pubsub#event"); + element.setAttribute("node", payload->getNode()); + element.addNode(boost::make_shared<XMLRawTextNode>(FormSerializer().serialize(payload->getData()))); + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/PubSubEventConfigurationSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubEventConfigurationSerializer.h new file mode 100644 index 0000000..6a73496 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubEventConfigurationSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubEventConfiguration.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubEventConfigurationSerializer : public GenericPayloadSerializer<PubSubEventConfiguration> { + public: + PubSubEventConfigurationSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubEventConfigurationSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubEventConfiguration>) const SWIFTEN_OVERRIDE; + + private: + + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubEventDeleteSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubEventDeleteSerializer.cpp new file mode 100644 index 0000000..b45adb8 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubEventDeleteSerializer.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubEventDeleteSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Serializer/PayloadSerializerCollection.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubEventRedirectSerializer.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> + +using namespace Swift; + +PubSubEventDeleteSerializer::PubSubEventDeleteSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubEventDeleteSerializer::~PubSubEventDeleteSerializer() { +} + +std::string PubSubEventDeleteSerializer::serializePayload(boost::shared_ptr<PubSubEventDelete> payload) const { + if (!payload) { + return ""; + } + XMLElement element("delete", "http://jabber.org/protocol/pubsub#event"); + element.setAttribute("node", payload->getNode()); + element.addNode(boost::make_shared<XMLRawTextNode>(PubSubEventRedirectSerializer(serializers).serialize(payload->getRedirects()))); + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/PubSubEventDeleteSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubEventDeleteSerializer.h new file mode 100644 index 0000000..10de3c3 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubEventDeleteSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubEventDelete.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubEventDeleteSerializer : public GenericPayloadSerializer<PubSubEventDelete> { + public: + PubSubEventDeleteSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubEventDeleteSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubEventDelete>) const SWIFTEN_OVERRIDE; + + private: + + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubEventDisassociateSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubEventDisassociateSerializer.cpp new file mode 100644 index 0000000..60cc562 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubEventDisassociateSerializer.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubEventDisassociateSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> + + +#include <Swiften/Serializer/PayloadSerializerCollection.h> + + +using namespace Swift; + +PubSubEventDisassociateSerializer::PubSubEventDisassociateSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubEventDisassociateSerializer::~PubSubEventDisassociateSerializer() { +} + +std::string PubSubEventDisassociateSerializer::serializePayload(boost::shared_ptr<PubSubEventDisassociate> payload) const { + if (!payload) { + return ""; + } + XMLElement element("disassociate", "http://jabber.org/protocol/pubsub#event"); + element.setAttribute("node", payload->getNode()); + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/PubSubEventDisassociateSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubEventDisassociateSerializer.h new file mode 100644 index 0000000..c7187c7 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubEventDisassociateSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubEventDisassociate.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubEventDisassociateSerializer : public GenericPayloadSerializer<PubSubEventDisassociate> { + public: + PubSubEventDisassociateSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubEventDisassociateSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubEventDisassociate>) const SWIFTEN_OVERRIDE; + + private: + + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubEventItemSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubEventItemSerializer.cpp new file mode 100644 index 0000000..2b8b08e --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubEventItemSerializer.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubEventItemSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Serializer/PayloadSerializerCollection.h> +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> + +using namespace Swift; + +PubSubEventItemSerializer::PubSubEventItemSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubEventItemSerializer::~PubSubEventItemSerializer() { +} + +std::string PubSubEventItemSerializer::serializePayload(boost::shared_ptr<PubSubEventItem> payload) const { + if (!payload) { + return ""; + } + XMLElement element("item", "http://jabber.org/protocol/pubsub#event"); + if (payload->getNode()) { + element.setAttribute("node", *payload->getNode()); + } + if (payload->getPublisher()) { + element.setAttribute("publisher", *payload->getPublisher()); + } + foreach(boost::shared_ptr<Payload> item, payload->getData()) { + element.addNode(boost::make_shared<XMLRawTextNode>(serializers->getPayloadSerializer(item)->serialize(item))); + } + if (payload->getID()) { + element.setAttribute("id", *payload->getID()); + } + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/PubSubEventItemSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubEventItemSerializer.h new file mode 100644 index 0000000..93fa5b0 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubEventItemSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubEventItem.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubEventItemSerializer : public GenericPayloadSerializer<PubSubEventItem> { + public: + PubSubEventItemSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubEventItemSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubEventItem>) const SWIFTEN_OVERRIDE; + + private: + + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubEventItemsSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubEventItemsSerializer.cpp new file mode 100644 index 0000000..099aa4b --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubEventItemsSerializer.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubEventItemsSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Serializer/PayloadSerializerCollection.h> +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubEventRetractSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubEventItemSerializer.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> + +using namespace Swift; + +PubSubEventItemsSerializer::PubSubEventItemsSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubEventItemsSerializer::~PubSubEventItemsSerializer() { +} + +std::string PubSubEventItemsSerializer::serializePayload(boost::shared_ptr<PubSubEventItems> payload) const { + if (!payload) { + return ""; + } + XMLElement element("items", "http://jabber.org/protocol/pubsub#event"); + element.setAttribute("node", payload->getNode()); + foreach(boost::shared_ptr<PubSubEventItem> item, payload->getItems()) { + element.addNode(boost::make_shared<XMLRawTextNode>(PubSubEventItemSerializer(serializers).serialize(item))); + } + foreach(boost::shared_ptr<PubSubEventRetract> item, payload->getRetracts()) { + element.addNode(boost::make_shared<XMLRawTextNode>(PubSubEventRetractSerializer(serializers).serialize(item))); + } + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/PubSubEventItemsSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubEventItemsSerializer.h new file mode 100644 index 0000000..6e60ee4 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubEventItemsSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubEventItems.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubEventItemsSerializer : public GenericPayloadSerializer<PubSubEventItems> { + public: + PubSubEventItemsSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubEventItemsSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubEventItems>) const SWIFTEN_OVERRIDE; + + private: + + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubEventPurgeSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubEventPurgeSerializer.cpp new file mode 100644 index 0000000..1387848 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubEventPurgeSerializer.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubEventPurgeSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> + + +#include <Swiften/Serializer/PayloadSerializerCollection.h> + + +using namespace Swift; + +PubSubEventPurgeSerializer::PubSubEventPurgeSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubEventPurgeSerializer::~PubSubEventPurgeSerializer() { +} + +std::string PubSubEventPurgeSerializer::serializePayload(boost::shared_ptr<PubSubEventPurge> payload) const { + if (!payload) { + return ""; + } + XMLElement element("purge", "http://jabber.org/protocol/pubsub#event"); + element.setAttribute("node", payload->getNode()); + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/PubSubEventPurgeSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubEventPurgeSerializer.h new file mode 100644 index 0000000..ab2d1d8 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubEventPurgeSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubEventPurge.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubEventPurgeSerializer : public GenericPayloadSerializer<PubSubEventPurge> { + public: + PubSubEventPurgeSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubEventPurgeSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubEventPurge>) const SWIFTEN_OVERRIDE; + + private: + + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubEventRedirectSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubEventRedirectSerializer.cpp new file mode 100644 index 0000000..7134e58 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubEventRedirectSerializer.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubEventRedirectSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> + + +#include <Swiften/Serializer/PayloadSerializerCollection.h> + + +using namespace Swift; + +PubSubEventRedirectSerializer::PubSubEventRedirectSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubEventRedirectSerializer::~PubSubEventRedirectSerializer() { +} + +std::string PubSubEventRedirectSerializer::serializePayload(boost::shared_ptr<PubSubEventRedirect> payload) const { + if (!payload) { + return ""; + } + XMLElement element("redirect", "http://jabber.org/protocol/pubsub#event"); + element.setAttribute("uri", payload->getURI()); + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/PubSubEventRedirectSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubEventRedirectSerializer.h new file mode 100644 index 0000000..751ff19 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubEventRedirectSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubEventRedirect.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubEventRedirectSerializer : public GenericPayloadSerializer<PubSubEventRedirect> { + public: + PubSubEventRedirectSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubEventRedirectSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubEventRedirect>) const SWIFTEN_OVERRIDE; + + private: + + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubEventRetractSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubEventRetractSerializer.cpp new file mode 100644 index 0000000..17d1a0f --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubEventRetractSerializer.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubEventRetractSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> + + +#include <Swiften/Serializer/PayloadSerializerCollection.h> + + +using namespace Swift; + +PubSubEventRetractSerializer::PubSubEventRetractSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubEventRetractSerializer::~PubSubEventRetractSerializer() { +} + +std::string PubSubEventRetractSerializer::serializePayload(boost::shared_ptr<PubSubEventRetract> payload) const { + if (!payload) { + return ""; + } + XMLElement element("retract", "http://jabber.org/protocol/pubsub#event"); + element.setAttribute("id", payload->getID()); + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/PubSubEventRetractSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubEventRetractSerializer.h new file mode 100644 index 0000000..0d73ec8 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubEventRetractSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubEventRetract.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubEventRetractSerializer : public GenericPayloadSerializer<PubSubEventRetract> { + public: + PubSubEventRetractSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubEventRetractSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubEventRetract>) const SWIFTEN_OVERRIDE; + + private: + + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubEventSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubEventSerializer.cpp new file mode 100644 index 0000000..da813cd --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubEventSerializer.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubEventSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Serializer/PayloadSerializerCollection.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubEventConfigurationSerializer.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubEventSubscriptionSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubEventPurgeSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubEventCollectionSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubEventDeleteSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubEventItemsSerializer.h> +#include <Swiften/Base/foreach.h> + +using namespace Swift; + +PubSubEventSerializer::PubSubEventSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { + pubsubSerializers.push_back(boost::make_shared<PubSubEventSubscriptionSerializer>(serializers)); + pubsubSerializers.push_back(boost::make_shared<PubSubEventPurgeSerializer>(serializers)); + pubsubSerializers.push_back(boost::make_shared<PubSubEventCollectionSerializer>(serializers)); + pubsubSerializers.push_back(boost::make_shared<PubSubEventDeleteSerializer>(serializers)); + pubsubSerializers.push_back(boost::make_shared<PubSubEventItemsSerializer>(serializers)); + pubsubSerializers.push_back(boost::make_shared<PubSubEventConfigurationSerializer>(serializers)); +} + +PubSubEventSerializer::~PubSubEventSerializer() { +} + +std::string PubSubEventSerializer::serializePayload(boost::shared_ptr<PubSubEvent> payload) const { + if (!payload) { + return ""; + } + XMLElement element("event", "http://jabber.org/protocol/pubsub#event"); + boost::shared_ptr<PubSubEventPayload> p = payload->getPayload(); + foreach(boost::shared_ptr<PayloadSerializer> serializer, pubsubSerializers) { + if (serializer->canSerialize(p)) { + element.addNode(boost::make_shared<XMLRawTextNode>(serializer->serialize(p))); + } + } + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/PubSubEventSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubEventSerializer.h new file mode 100644 index 0000000..85b5b90 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubEventSerializer.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubEvent.h> +#include <boost/shared_ptr.hpp> +#include <vector> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubEventSerializer : public GenericPayloadSerializer<PubSubEvent> { + public: + PubSubEventSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubEventSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubEvent>) const SWIFTEN_OVERRIDE; + + private: + + + private: + PayloadSerializerCollection* serializers; + std::vector< boost::shared_ptr<PayloadSerializer> > pubsubSerializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubEventSubscriptionSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubEventSubscriptionSerializer.cpp new file mode 100644 index 0000000..9b0a334 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubEventSubscriptionSerializer.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubEventSubscriptionSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> + + +#include <Swiften/Serializer/PayloadSerializerCollection.h> +#include <Swiften/Base/DateTime.h> + +using namespace Swift; + +PubSubEventSubscriptionSerializer::PubSubEventSubscriptionSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubEventSubscriptionSerializer::~PubSubEventSubscriptionSerializer() { +} + +std::string PubSubEventSubscriptionSerializer::serializePayload(boost::shared_ptr<PubSubEventSubscription> payload) const { + if (!payload) { + return ""; + } + XMLElement element("subscription", "http://jabber.org/protocol/pubsub#event"); + element.setAttribute("node", payload->getNode()); + element.setAttribute("jid", payload->getJID()); + element.setAttribute("subscription", serializeSubscriptionType(payload->getSubscription())); + if (payload->getSubscriptionID()) { + element.setAttribute("subid", *payload->getSubscriptionID()); + } + element.setAttribute("expiry", dateTimeToString(payload->getExpiry())); + return element.serialize(); +} + +std::string PubSubEventSubscriptionSerializer::serializeSubscriptionType(PubSubEventSubscription::SubscriptionType value) { + switch (value) { + case PubSubEventSubscription::None: return "none"; + case PubSubEventSubscription::Pending: return "pending"; + case PubSubEventSubscription::Subscribed: return "subscribed"; + case PubSubEventSubscription::Unconfigured: return "unconfigured"; + } + assert(false); + return ""; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubEventSubscriptionSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubEventSubscriptionSerializer.h new file mode 100644 index 0000000..3b613bd --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubEventSubscriptionSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubEventSubscription.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubEventSubscriptionSerializer : public GenericPayloadSerializer<PubSubEventSubscription> { + public: + PubSubEventSubscriptionSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubEventSubscriptionSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubEventSubscription>) const SWIFTEN_OVERRIDE; + + private: + static std::string serializeSubscriptionType(PubSubEventSubscription::SubscriptionType); + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubItemSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubItemSerializer.cpp new file mode 100644 index 0000000..5a82b42 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubItemSerializer.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubItemSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Serializer/PayloadSerializerCollection.h> +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> + +using namespace Swift; + +PubSubItemSerializer::PubSubItemSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubItemSerializer::~PubSubItemSerializer() { +} + +std::string PubSubItemSerializer::serializePayload(boost::shared_ptr<PubSubItem> payload) const { + if (!payload) { + return ""; + } + XMLElement element("item", "http://jabber.org/protocol/pubsub"); + foreach(boost::shared_ptr<Payload> item, payload->getData()) { + element.addNode(boost::make_shared<XMLRawTextNode>(serializers->getPayloadSerializer(item)->serialize(item))); + } + element.setAttribute("id", payload->getID()); + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/PubSubItemSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubItemSerializer.h new file mode 100644 index 0000000..56f186d --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubItemSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubItem.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubItemSerializer : public GenericPayloadSerializer<PubSubItem> { + public: + PubSubItemSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubItemSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubItem>) const SWIFTEN_OVERRIDE; + + private: + + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubItemsSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubItemsSerializer.cpp new file mode 100644 index 0000000..6bffa6a --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubItemsSerializer.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubItemsSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <boost/lexical_cast.hpp> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Serializer/PayloadSerializerCollection.h> +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubItemSerializer.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> + +using namespace Swift; + +PubSubItemsSerializer::PubSubItemsSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubItemsSerializer::~PubSubItemsSerializer() { +} + +std::string PubSubItemsSerializer::serializePayload(boost::shared_ptr<PubSubItems> payload) const { + if (!payload) { + return ""; + } + XMLElement element("items", "http://jabber.org/protocol/pubsub"); + element.setAttribute("node", payload->getNode()); + foreach(boost::shared_ptr<PubSubItem> item, payload->getItems()) { + element.addNode(boost::make_shared<XMLRawTextNode>(PubSubItemSerializer(serializers).serialize(item))); + } + if (payload->getMaximumItems()) { + element.setAttribute("max_items", boost::lexical_cast<std::string>(*payload->getMaximumItems())); + } + if (payload->getSubscriptionID()) { + element.setAttribute("subid", *payload->getSubscriptionID()); + } + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/PubSubItemsSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubItemsSerializer.h new file mode 100644 index 0000000..050e156 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubItemsSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubItems.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubItemsSerializer : public GenericPayloadSerializer<PubSubItems> { + public: + PubSubItemsSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubItemsSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubItems>) const SWIFTEN_OVERRIDE; + + private: + + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubOptionsSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubOptionsSerializer.cpp new file mode 100644 index 0000000..db983b9 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubOptionsSerializer.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubOptionsSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Serializer/PayloadSerializerCollection.h> +#include <Swiften/Serializer/PayloadSerializers/FormSerializer.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> + +using namespace Swift; + +PubSubOptionsSerializer::PubSubOptionsSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubOptionsSerializer::~PubSubOptionsSerializer() { +} + +std::string PubSubOptionsSerializer::serializePayload(boost::shared_ptr<PubSubOptions> payload) const { + if (!payload) { + return ""; + } + XMLElement element("options", "http://jabber.org/protocol/pubsub"); + element.setAttribute("node", payload->getNode()); + element.setAttribute("jid", payload->getJID()); + element.addNode(boost::make_shared<XMLRawTextNode>(FormSerializer().serialize(payload->getData()))); + if (payload->getSubscriptionID()) { + element.setAttribute("subid", *payload->getSubscriptionID()); + } + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/PubSubOptionsSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubOptionsSerializer.h new file mode 100644 index 0000000..258f1f2 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubOptionsSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubOptions.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubOptionsSerializer : public GenericPayloadSerializer<PubSubOptions> { + public: + PubSubOptionsSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubOptionsSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubOptions>) const SWIFTEN_OVERRIDE; + + private: + + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubOwnerAffiliationSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubOwnerAffiliationSerializer.cpp new file mode 100644 index 0000000..3699b8e --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubOwnerAffiliationSerializer.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubOwnerAffiliationSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> + + +#include <Swiften/Serializer/PayloadSerializerCollection.h> + + +using namespace Swift; + +PubSubOwnerAffiliationSerializer::PubSubOwnerAffiliationSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubOwnerAffiliationSerializer::~PubSubOwnerAffiliationSerializer() { +} + +std::string PubSubOwnerAffiliationSerializer::serializePayload(boost::shared_ptr<PubSubOwnerAffiliation> payload) const { + if (!payload) { + return ""; + } + XMLElement element("affiliation", "http://jabber.org/protocol/pubsub#owner"); + element.setAttribute("jid", payload->getJID()); + element.setAttribute("affiliation", serializeType(payload->getType())); + return element.serialize(); +} + +std::string PubSubOwnerAffiliationSerializer::serializeType(PubSubOwnerAffiliation::Type value) { + switch (value) { + case PubSubOwnerAffiliation::None: return "none"; + case PubSubOwnerAffiliation::Member: return "member"; + case PubSubOwnerAffiliation::Outcast: return "outcast"; + case PubSubOwnerAffiliation::Owner: return "owner"; + case PubSubOwnerAffiliation::Publisher: return "publisher"; + case PubSubOwnerAffiliation::PublishOnly: return "publish-only"; + } + assert(false); + return ""; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubOwnerAffiliationSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubOwnerAffiliationSerializer.h new file mode 100644 index 0000000..acea723 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubOwnerAffiliationSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubOwnerAffiliation.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubOwnerAffiliationSerializer : public GenericPayloadSerializer<PubSubOwnerAffiliation> { + public: + PubSubOwnerAffiliationSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubOwnerAffiliationSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubOwnerAffiliation>) const SWIFTEN_OVERRIDE; + + private: + static std::string serializeType(PubSubOwnerAffiliation::Type); + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubOwnerAffiliationsSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubOwnerAffiliationsSerializer.cpp new file mode 100644 index 0000000..c393bfb --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubOwnerAffiliationsSerializer.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubOwnerAffiliationsSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Serializer/PayloadSerializerCollection.h> +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubOwnerAffiliationSerializer.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> + +using namespace Swift; + +PubSubOwnerAffiliationsSerializer::PubSubOwnerAffiliationsSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubOwnerAffiliationsSerializer::~PubSubOwnerAffiliationsSerializer() { +} + +std::string PubSubOwnerAffiliationsSerializer::serializePayload(boost::shared_ptr<PubSubOwnerAffiliations> payload) const { + if (!payload) { + return ""; + } + XMLElement element("affiliations", "http://jabber.org/protocol/pubsub#owner"); + element.setAttribute("node", payload->getNode()); + foreach(boost::shared_ptr<PubSubOwnerAffiliation> item, payload->getAffiliations()) { + element.addNode(boost::make_shared<XMLRawTextNode>(PubSubOwnerAffiliationSerializer(serializers).serialize(item))); + } + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/PubSubOwnerAffiliationsSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubOwnerAffiliationsSerializer.h new file mode 100644 index 0000000..3d20042 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubOwnerAffiliationsSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubOwnerAffiliations.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubOwnerAffiliationsSerializer : public GenericPayloadSerializer<PubSubOwnerAffiliations> { + public: + PubSubOwnerAffiliationsSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubOwnerAffiliationsSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubOwnerAffiliations>) const SWIFTEN_OVERRIDE; + + private: + + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubOwnerConfigureSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubOwnerConfigureSerializer.cpp new file mode 100644 index 0000000..154a370 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubOwnerConfigureSerializer.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubOwnerConfigureSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Serializer/PayloadSerializerCollection.h> +#include <Swiften/Serializer/PayloadSerializers/FormSerializer.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> + +using namespace Swift; + +PubSubOwnerConfigureSerializer::PubSubOwnerConfigureSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubOwnerConfigureSerializer::~PubSubOwnerConfigureSerializer() { +} + +std::string PubSubOwnerConfigureSerializer::serializePayload(boost::shared_ptr<PubSubOwnerConfigure> payload) const { + if (!payload) { + return ""; + } + XMLElement element("configure", "http://jabber.org/protocol/pubsub#owner"); + if (payload->getNode()) { + element.setAttribute("node", *payload->getNode()); + } + element.addNode(boost::make_shared<XMLRawTextNode>(FormSerializer().serialize(payload->getData()))); + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/PubSubOwnerConfigureSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubOwnerConfigureSerializer.h new file mode 100644 index 0000000..41f2a9d --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubOwnerConfigureSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubOwnerConfigure.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubOwnerConfigureSerializer : public GenericPayloadSerializer<PubSubOwnerConfigure> { + public: + PubSubOwnerConfigureSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubOwnerConfigureSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubOwnerConfigure>) const SWIFTEN_OVERRIDE; + + private: + + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubOwnerDefaultSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubOwnerDefaultSerializer.cpp new file mode 100644 index 0000000..7ce2e71 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubOwnerDefaultSerializer.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubOwnerDefaultSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Serializer/PayloadSerializerCollection.h> +#include <Swiften/Serializer/PayloadSerializers/FormSerializer.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> + +using namespace Swift; + +PubSubOwnerDefaultSerializer::PubSubOwnerDefaultSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubOwnerDefaultSerializer::~PubSubOwnerDefaultSerializer() { +} + +std::string PubSubOwnerDefaultSerializer::serializePayload(boost::shared_ptr<PubSubOwnerDefault> payload) const { + if (!payload) { + return ""; + } + XMLElement element("default", "http://jabber.org/protocol/pubsub#owner"); + element.addNode(boost::make_shared<XMLRawTextNode>(FormSerializer().serialize(payload->getData()))); + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/PubSubOwnerDefaultSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubOwnerDefaultSerializer.h new file mode 100644 index 0000000..02aefe8 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubOwnerDefaultSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubOwnerDefault.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubOwnerDefaultSerializer : public GenericPayloadSerializer<PubSubOwnerDefault> { + public: + PubSubOwnerDefaultSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubOwnerDefaultSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubOwnerDefault>) const SWIFTEN_OVERRIDE; + + private: + + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubOwnerDeleteSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubOwnerDeleteSerializer.cpp new file mode 100644 index 0000000..010645c --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubOwnerDeleteSerializer.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubOwnerDeleteSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Serializer/PayloadSerializerCollection.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubOwnerRedirectSerializer.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> + +using namespace Swift; + +PubSubOwnerDeleteSerializer::PubSubOwnerDeleteSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubOwnerDeleteSerializer::~PubSubOwnerDeleteSerializer() { +} + +std::string PubSubOwnerDeleteSerializer::serializePayload(boost::shared_ptr<PubSubOwnerDelete> payload) const { + if (!payload) { + return ""; + } + XMLElement element("delete", "http://jabber.org/protocol/pubsub#owner"); + element.setAttribute("node", payload->getNode()); + element.addNode(boost::make_shared<XMLRawTextNode>(PubSubOwnerRedirectSerializer(serializers).serialize(payload->getRedirect()))); + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/PubSubOwnerDeleteSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubOwnerDeleteSerializer.h new file mode 100644 index 0000000..d537a4f --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubOwnerDeleteSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubOwnerDelete.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubOwnerDeleteSerializer : public GenericPayloadSerializer<PubSubOwnerDelete> { + public: + PubSubOwnerDeleteSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubOwnerDeleteSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubOwnerDelete>) const SWIFTEN_OVERRIDE; + + private: + + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubOwnerPubSubSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubOwnerPubSubSerializer.cpp new file mode 100644 index 0000000..de7d5a5 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubOwnerPubSubSerializer.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubOwnerPubSubSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Serializer/PayloadSerializerCollection.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubOwnerDeleteSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubOwnerSubscriptionsSerializer.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubOwnerDefaultSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubOwnerPurgeSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubOwnerAffiliationsSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubOwnerConfigureSerializer.h> +#include <Swiften/Base/foreach.h> + +using namespace Swift; + +PubSubOwnerPubSubSerializer::PubSubOwnerPubSubSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { + pubsubSerializers.push_back(boost::make_shared<PubSubOwnerConfigureSerializer>(serializers)); + pubsubSerializers.push_back(boost::make_shared<PubSubOwnerSubscriptionsSerializer>(serializers)); + pubsubSerializers.push_back(boost::make_shared<PubSubOwnerDefaultSerializer>(serializers)); + pubsubSerializers.push_back(boost::make_shared<PubSubOwnerPurgeSerializer>(serializers)); + pubsubSerializers.push_back(boost::make_shared<PubSubOwnerAffiliationsSerializer>(serializers)); + pubsubSerializers.push_back(boost::make_shared<PubSubOwnerDeleteSerializer>(serializers)); +} + +PubSubOwnerPubSubSerializer::~PubSubOwnerPubSubSerializer() { +} + +std::string PubSubOwnerPubSubSerializer::serializePayload(boost::shared_ptr<PubSubOwnerPubSub> payload) const { + if (!payload) { + return ""; + } + XMLElement element("pubsub", "http://jabber.org/protocol/pubsub#owner"); + boost::shared_ptr<PubSubOwnerPayload> p = payload->getPayload(); + foreach(boost::shared_ptr<PayloadSerializer> serializer, pubsubSerializers) { + if (serializer->canSerialize(p)) { + element.addNode(boost::make_shared<XMLRawTextNode>(serializer->serialize(p))); + } + } + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/PubSubOwnerPubSubSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubOwnerPubSubSerializer.h new file mode 100644 index 0000000..9f5732b --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubOwnerPubSubSerializer.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubOwnerPubSub.h> +#include <boost/shared_ptr.hpp> +#include <vector> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubOwnerPubSubSerializer : public GenericPayloadSerializer<PubSubOwnerPubSub> { + public: + PubSubOwnerPubSubSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubOwnerPubSubSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubOwnerPubSub>) const SWIFTEN_OVERRIDE; + + private: + + + private: + PayloadSerializerCollection* serializers; + std::vector< boost::shared_ptr<PayloadSerializer> > pubsubSerializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubOwnerPurgeSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubOwnerPurgeSerializer.cpp new file mode 100644 index 0000000..591cdf9 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubOwnerPurgeSerializer.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubOwnerPurgeSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> + + +#include <Swiften/Serializer/PayloadSerializerCollection.h> + + +using namespace Swift; + +PubSubOwnerPurgeSerializer::PubSubOwnerPurgeSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubOwnerPurgeSerializer::~PubSubOwnerPurgeSerializer() { +} + +std::string PubSubOwnerPurgeSerializer::serializePayload(boost::shared_ptr<PubSubOwnerPurge> payload) const { + if (!payload) { + return ""; + } + XMLElement element("purge", "http://jabber.org/protocol/pubsub#owner"); + element.setAttribute("node", payload->getNode()); + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/PubSubOwnerPurgeSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubOwnerPurgeSerializer.h new file mode 100644 index 0000000..51a086f --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubOwnerPurgeSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubOwnerPurge.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubOwnerPurgeSerializer : public GenericPayloadSerializer<PubSubOwnerPurge> { + public: + PubSubOwnerPurgeSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubOwnerPurgeSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubOwnerPurge>) const SWIFTEN_OVERRIDE; + + private: + + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubOwnerRedirectSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubOwnerRedirectSerializer.cpp new file mode 100644 index 0000000..ea7d721 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubOwnerRedirectSerializer.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubOwnerRedirectSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> + + +#include <Swiften/Serializer/PayloadSerializerCollection.h> + + +using namespace Swift; + +PubSubOwnerRedirectSerializer::PubSubOwnerRedirectSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubOwnerRedirectSerializer::~PubSubOwnerRedirectSerializer() { +} + +std::string PubSubOwnerRedirectSerializer::serializePayload(boost::shared_ptr<PubSubOwnerRedirect> payload) const { + if (!payload) { + return ""; + } + XMLElement element("redirect", "http://jabber.org/protocol/pubsub#owner"); + element.setAttribute("uri", payload->getURI()); + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/PubSubOwnerRedirectSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubOwnerRedirectSerializer.h new file mode 100644 index 0000000..e5d5af5 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubOwnerRedirectSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubOwnerRedirect.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubOwnerRedirectSerializer : public GenericPayloadSerializer<PubSubOwnerRedirect> { + public: + PubSubOwnerRedirectSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubOwnerRedirectSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubOwnerRedirect>) const SWIFTEN_OVERRIDE; + + private: + + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubOwnerSubscriptionSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubOwnerSubscriptionSerializer.cpp new file mode 100644 index 0000000..91bc00b --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubOwnerSubscriptionSerializer.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubOwnerSubscriptionSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> + + +#include <Swiften/Serializer/PayloadSerializerCollection.h> + + +using namespace Swift; + +PubSubOwnerSubscriptionSerializer::PubSubOwnerSubscriptionSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubOwnerSubscriptionSerializer::~PubSubOwnerSubscriptionSerializer() { +} + +std::string PubSubOwnerSubscriptionSerializer::serializePayload(boost::shared_ptr<PubSubOwnerSubscription> payload) const { + if (!payload) { + return ""; + } + XMLElement element("subscription", "http://jabber.org/protocol/pubsub#owner"); + element.setAttribute("jid", payload->getJID()); + element.setAttribute("subscription", serializeSubscriptionType(payload->getSubscription())); + return element.serialize(); +} + +std::string PubSubOwnerSubscriptionSerializer::serializeSubscriptionType(PubSubOwnerSubscription::SubscriptionType value) { + switch (value) { + case PubSubOwnerSubscription::None: return "none"; + case PubSubOwnerSubscription::Pending: return "pending"; + case PubSubOwnerSubscription::Subscribed: return "subscribed"; + case PubSubOwnerSubscription::Unconfigured: return "unconfigured"; + } + assert(false); + return ""; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubOwnerSubscriptionSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubOwnerSubscriptionSerializer.h new file mode 100644 index 0000000..4cecca7 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubOwnerSubscriptionSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubOwnerSubscription.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubOwnerSubscriptionSerializer : public GenericPayloadSerializer<PubSubOwnerSubscription> { + public: + PubSubOwnerSubscriptionSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubOwnerSubscriptionSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubOwnerSubscription>) const SWIFTEN_OVERRIDE; + + private: + static std::string serializeSubscriptionType(PubSubOwnerSubscription::SubscriptionType); + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubOwnerSubscriptionsSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubOwnerSubscriptionsSerializer.cpp new file mode 100644 index 0000000..c265662 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubOwnerSubscriptionsSerializer.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubOwnerSubscriptionsSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Serializer/PayloadSerializerCollection.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubOwnerSubscriptionSerializer.h> +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> + +using namespace Swift; + +PubSubOwnerSubscriptionsSerializer::PubSubOwnerSubscriptionsSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubOwnerSubscriptionsSerializer::~PubSubOwnerSubscriptionsSerializer() { +} + +std::string PubSubOwnerSubscriptionsSerializer::serializePayload(boost::shared_ptr<PubSubOwnerSubscriptions> payload) const { + if (!payload) { + return ""; + } + XMLElement element("subscriptions", "http://jabber.org/protocol/pubsub#owner"); + element.setAttribute("node", payload->getNode()); + foreach(boost::shared_ptr<PubSubOwnerSubscription> item, payload->getSubscriptions()) { + element.addNode(boost::make_shared<XMLRawTextNode>(PubSubOwnerSubscriptionSerializer(serializers).serialize(item))); + } + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/PubSubOwnerSubscriptionsSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubOwnerSubscriptionsSerializer.h new file mode 100644 index 0000000..d77bc99 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubOwnerSubscriptionsSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubOwnerSubscriptions.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubOwnerSubscriptionsSerializer : public GenericPayloadSerializer<PubSubOwnerSubscriptions> { + public: + PubSubOwnerSubscriptionsSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubOwnerSubscriptionsSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubOwnerSubscriptions>) const SWIFTEN_OVERRIDE; + + private: + + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubPublishSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubPublishSerializer.cpp new file mode 100644 index 0000000..5a150e0 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubPublishSerializer.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubPublishSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Serializer/PayloadSerializerCollection.h> +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubItemSerializer.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> + +using namespace Swift; + +PubSubPublishSerializer::PubSubPublishSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubPublishSerializer::~PubSubPublishSerializer() { +} + +std::string PubSubPublishSerializer::serializePayload(boost::shared_ptr<PubSubPublish> payload) const { + if (!payload) { + return ""; + } + XMLElement element("publish", "http://jabber.org/protocol/pubsub"); + element.setAttribute("node", payload->getNode()); + foreach(boost::shared_ptr<PubSubItem> item, payload->getItems()) { + element.addNode(boost::make_shared<XMLRawTextNode>(PubSubItemSerializer(serializers).serialize(item))); + } + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/PubSubPublishSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubPublishSerializer.h new file mode 100644 index 0000000..9d53141 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubPublishSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubPublish.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubPublishSerializer : public GenericPayloadSerializer<PubSubPublish> { + public: + PubSubPublishSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubPublishSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubPublish>) const SWIFTEN_OVERRIDE; + + private: + + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubRetractSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubRetractSerializer.cpp new file mode 100644 index 0000000..3f1434b --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubRetractSerializer.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubRetractSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Serializer/PayloadSerializerCollection.h> +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubItemSerializer.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> + +using namespace Swift; + +PubSubRetractSerializer::PubSubRetractSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubRetractSerializer::~PubSubRetractSerializer() { +} + +std::string PubSubRetractSerializer::serializePayload(boost::shared_ptr<PubSubRetract> payload) const { + if (!payload) { + return ""; + } + XMLElement element("retract", "http://jabber.org/protocol/pubsub"); + element.setAttribute("node", payload->getNode()); + foreach(boost::shared_ptr<PubSubItem> item, payload->getItems()) { + element.addNode(boost::make_shared<XMLRawTextNode>(PubSubItemSerializer(serializers).serialize(item))); + } + element.setAttribute("notify", payload->isNotify() ? "true" : "false"); + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/PubSubRetractSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubRetractSerializer.h new file mode 100644 index 0000000..47a01af --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubRetractSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubRetract.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubRetractSerializer : public GenericPayloadSerializer<PubSubRetract> { + public: + PubSubRetractSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubRetractSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubRetract>) const SWIFTEN_OVERRIDE; + + private: + + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubSerializer.cpp new file mode 100644 index 0000000..0e61331 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubSerializer.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Serializer/PayloadSerializerCollection.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubConfigureSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubAffiliationsSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubCreateSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubDefaultSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubItemsSerializer.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubSubscriptionSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubUnsubscribeSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubPublishSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubOptionsSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubSubscribeSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubRetractSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubSubscriptionsSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubOptionsSerializer.h> +#include <Swiften/Base/foreach.h> + +using namespace Swift; + +PubSubSerializer::PubSubSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { + pubsubSerializers.push_back(boost::make_shared<PubSubItemsSerializer>(serializers)); + pubsubSerializers.push_back(boost::make_shared<PubSubCreateSerializer>(serializers)); + pubsubSerializers.push_back(boost::make_shared<PubSubPublishSerializer>(serializers)); + pubsubSerializers.push_back(boost::make_shared<PubSubOptionsSerializer>(serializers)); + pubsubSerializers.push_back(boost::make_shared<PubSubAffiliationsSerializer>(serializers)); + pubsubSerializers.push_back(boost::make_shared<PubSubRetractSerializer>(serializers)); + pubsubSerializers.push_back(boost::make_shared<PubSubDefaultSerializer>(serializers)); + pubsubSerializers.push_back(boost::make_shared<PubSubSubscriptionsSerializer>(serializers)); + pubsubSerializers.push_back(boost::make_shared<PubSubSubscribeSerializer>(serializers)); + pubsubSerializers.push_back(boost::make_shared<PubSubUnsubscribeSerializer>(serializers)); + pubsubSerializers.push_back(boost::make_shared<PubSubSubscriptionSerializer>(serializers)); +} + +PubSubSerializer::~PubSubSerializer() { +} + +std::string PubSubSerializer::serializePayload(boost::shared_ptr<PubSub> payload) const { + if (!payload) { + return ""; + } + XMLElement element("pubsub", "http://jabber.org/protocol/pubsub"); + boost::shared_ptr<PubSubPayload> p = payload->getPayload(); + foreach(boost::shared_ptr<PayloadSerializer> serializer, pubsubSerializers) { + if (serializer->canSerialize(p)) { + element.addNode(boost::make_shared<XMLRawTextNode>(serializer->serialize(p))); + if (boost::shared_ptr<PubSubCreate> create = boost::dynamic_pointer_cast<PubSubCreate>(p)) { + element.addNode(boost::make_shared<XMLRawTextNode>(boost::make_shared<PubSubConfigureSerializer>(serializers)->serialize(create->getConfigure()))); + } + if (boost::shared_ptr<PubSubSubscribe> subscribe = boost::dynamic_pointer_cast<PubSubSubscribe>(p)) { + element.addNode(boost::make_shared<XMLRawTextNode>(boost::make_shared<PubSubConfigureSerializer>(serializers)->serialize(subscribe->getOptions()))); + } + } + } + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/PubSubSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubSerializer.h new file mode 100644 index 0000000..7665800 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubSerializer.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSub.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubSerializer : public GenericPayloadSerializer<PubSub> { + public: + PubSubSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSub>) const SWIFTEN_OVERRIDE; + + private: + std::vector< boost::shared_ptr<PayloadSerializer> > pubsubSerializers; + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubSubscribeOptionsSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubSubscribeOptionsSerializer.cpp new file mode 100644 index 0000000..7a55228 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubSubscribeOptionsSerializer.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubSubscribeOptionsSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Serializer/PayloadSerializerCollection.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> + +using namespace Swift; + +PubSubSubscribeOptionsSerializer::PubSubSubscribeOptionsSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubSubscribeOptionsSerializer::~PubSubSubscribeOptionsSerializer() { +} + +std::string PubSubSubscribeOptionsSerializer::serializePayload(boost::shared_ptr<PubSubSubscribeOptions> payload) const { + if (!payload) { + return ""; + } + XMLElement element("subscribe-options", "http://jabber.org/protocol/pubsub"); + element.addNode(payload->isRequired() ? boost::make_shared<XMLElement>("required", "") : boost::shared_ptr<XMLElement>()); + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/PubSubSubscribeOptionsSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubSubscribeOptionsSerializer.h new file mode 100644 index 0000000..6ffaac7 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubSubscribeOptionsSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubSubscribeOptions.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubSubscribeOptionsSerializer : public GenericPayloadSerializer<PubSubSubscribeOptions> { + public: + PubSubSubscribeOptionsSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubSubscribeOptionsSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubSubscribeOptions>) const SWIFTEN_OVERRIDE; + + private: + + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubSubscribeSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubSubscribeSerializer.cpp new file mode 100644 index 0000000..83a73af --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubSubscribeSerializer.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubSubscribeSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> + + +#include <Swiften/Serializer/PayloadSerializerCollection.h> + + +using namespace Swift; + +PubSubSubscribeSerializer::PubSubSubscribeSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubSubscribeSerializer::~PubSubSubscribeSerializer() { +} + +std::string PubSubSubscribeSerializer::serializePayload(boost::shared_ptr<PubSubSubscribe> payload) const { + if (!payload) { + return ""; + } + XMLElement element("subscribe", "http://jabber.org/protocol/pubsub"); + if (payload->getNode()) { + element.setAttribute("node", *payload->getNode()); + } + element.setAttribute("jid", payload->getJID()); + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/PubSubSubscribeSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubSubscribeSerializer.h new file mode 100644 index 0000000..b730a4d --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubSubscribeSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubSubscribe.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubSubscribeSerializer : public GenericPayloadSerializer<PubSubSubscribe> { + public: + PubSubSubscribeSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubSubscribeSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubSubscribe>) const SWIFTEN_OVERRIDE; + + private: + + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubSubscriptionSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubSubscriptionSerializer.cpp new file mode 100644 index 0000000..8a54afa --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubSubscriptionSerializer.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubSubscriptionSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Serializer/PayloadSerializerCollection.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubSubscribeOptionsSerializer.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> + +using namespace Swift; + +PubSubSubscriptionSerializer::PubSubSubscriptionSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubSubscriptionSerializer::~PubSubSubscriptionSerializer() { +} + +std::string PubSubSubscriptionSerializer::serializePayload(boost::shared_ptr<PubSubSubscription> payload) const { + if (!payload) { + return ""; + } + XMLElement element("subscription", "http://jabber.org/protocol/pubsub"); + if (payload->getNode()) { + element.setAttribute("node", *payload->getNode()); + } + if (payload->getSubscriptionID()) { + element.setAttribute("subid", *payload->getSubscriptionID()); + } + element.setAttribute("jid", payload->getJID()); + element.addNode(boost::make_shared<XMLRawTextNode>(PubSubSubscribeOptionsSerializer(serializers).serialize(payload->getOptions()))); + element.setAttribute("subscription", serializeSubscriptionType(payload->getSubscription())); + return element.serialize(); +} + +std::string PubSubSubscriptionSerializer::serializeSubscriptionType(PubSubSubscription::SubscriptionType value) { + switch (value) { + case PubSubSubscription::None: return "none"; + case PubSubSubscription::Pending: return "pending"; + case PubSubSubscription::Subscribed: return "subscribed"; + case PubSubSubscription::Unconfigured: return "unconfigured"; + } + assert(false); + return ""; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubSubscriptionSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubSubscriptionSerializer.h new file mode 100644 index 0000000..d03bb69 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubSubscriptionSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubSubscription.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubSubscriptionSerializer : public GenericPayloadSerializer<PubSubSubscription> { + public: + PubSubSubscriptionSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubSubscriptionSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubSubscription>) const SWIFTEN_OVERRIDE; + + private: + static std::string serializeSubscriptionType(PubSubSubscription::SubscriptionType); + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubSubscriptionsSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubSubscriptionsSerializer.cpp new file mode 100644 index 0000000..74f1123 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubSubscriptionsSerializer.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubSubscriptionsSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Serializer/PayloadSerializerCollection.h> +#include <Swiften/Serializer/PayloadSerializers/PubSubSubscriptionSerializer.h> +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> + +using namespace Swift; + +PubSubSubscriptionsSerializer::PubSubSubscriptionsSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubSubscriptionsSerializer::~PubSubSubscriptionsSerializer() { +} + +std::string PubSubSubscriptionsSerializer::serializePayload(boost::shared_ptr<PubSubSubscriptions> payload) const { + if (!payload) { + return ""; + } + XMLElement element("subscriptions", "http://jabber.org/protocol/pubsub"); + if (payload->getNode()) { + element.setAttribute("node", *payload->getNode()); + } + foreach(boost::shared_ptr<PubSubSubscription> item, payload->getSubscriptions()) { + element.addNode(boost::make_shared<XMLRawTextNode>(PubSubSubscriptionSerializer(serializers).serialize(item))); + } + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/PubSubSubscriptionsSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubSubscriptionsSerializer.h new file mode 100644 index 0000000..2b5d8fa --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubSubscriptionsSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubSubscriptions.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubSubscriptionsSerializer : public GenericPayloadSerializer<PubSubSubscriptions> { + public: + PubSubSubscriptionsSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubSubscriptionsSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubSubscriptions>) const SWIFTEN_OVERRIDE; + + private: + + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/PubSubUnsubscribeSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubUnsubscribeSerializer.cpp new file mode 100644 index 0000000..e0d6cd3 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubUnsubscribeSerializer.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Serializer/PayloadSerializers/PubSubUnsubscribeSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> + + +#include <Swiften/Serializer/PayloadSerializerCollection.h> + + +using namespace Swift; + +PubSubUnsubscribeSerializer::PubSubUnsubscribeSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +PubSubUnsubscribeSerializer::~PubSubUnsubscribeSerializer() { +} + +std::string PubSubUnsubscribeSerializer::serializePayload(boost::shared_ptr<PubSubUnsubscribe> payload) const { + if (!payload) { + return ""; + } + XMLElement element("unsubscribe", "http://jabber.org/protocol/pubsub"); + if (payload->getNode()) { + element.setAttribute("node", *payload->getNode()); + } + element.setAttribute("jid", payload->getJID()); + if (payload->getSubscriptionID()) { + element.setAttribute("subid", *payload->getSubscriptionID()); + } + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/PubSubUnsubscribeSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubUnsubscribeSerializer.h new file mode 100644 index 0000000..b4f6f62 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PubSubUnsubscribeSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PubSubUnsubscribe.h> +#include <boost/shared_ptr.hpp> + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API PubSubUnsubscribeSerializer : public GenericPayloadSerializer<PubSubUnsubscribe> { + public: + PubSubUnsubscribeSerializer(PayloadSerializerCollection* serializers); + virtual ~PubSubUnsubscribeSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<PubSubUnsubscribe>) const SWIFTEN_OVERRIDE; + + private: + + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/UserLocationSerializer.cpp b/Swiften/Serializer/PayloadSerializers/UserLocationSerializer.cpp new file mode 100644 index 0000000..373276b --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UserLocationSerializer.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Serializer/PayloadSerializers/UserLocationSerializer.h> + +#include <boost/shared_ptr.hpp> +#include <boost/smart_ptr/make_shared.hpp> +#include <boost/lexical_cast.hpp> + +#include <Swiften/Base/foreach.h> +#include <Swiften/Base/DateTime.h> +#include <Swiften/Serializer/XML/XMLElement.h> + +namespace Swift { + +UserLocationSerializer::UserLocationSerializer() { +} + +std::string UserLocationSerializer::serializePayload( + boost::shared_ptr<UserLocation> payload) const { + XMLElement result("geoloc", "http://jabber.org/protocol/geoloc"); + if (boost::optional<std::string> value = payload->getArea()) { + result.addNode(boost::make_shared<XMLElement>("area", "", *value)); + } + else if (boost::optional<float> value = payload->getAltitude()) { + result.addNode(boost::make_shared<XMLElement>("alt", "", boost::lexical_cast<std::string>(*value))); + } + else if (boost::optional<std::string> value = payload->getLocality()) { + result.addNode(boost::make_shared<XMLElement>("locality", "", *value)); + } + else if (boost::optional<float> value = payload->getLatitude()) { + result.addNode(boost::make_shared<XMLElement>("lat", "", boost::lexical_cast<std::string>(*value))); + } + else if (boost::optional<float> value = payload->getAccuracy()) { + result.addNode(boost::make_shared<XMLElement>("lon", "", boost::lexical_cast<std::string>(*value))); + } + else if (boost::optional<std::string> value = payload->getDescription()) { + result.addNode(boost::make_shared<XMLElement>("description", "", *value)); + } + else if (boost::optional<std::string> value = payload->getCountryCode()) { + result.addNode(boost::make_shared<XMLElement>("countrycode", "", *value)); + } + else if (boost::optional<boost::posix_time::ptime> value = payload->getTimestamp()) { + result.addNode(boost::make_shared<XMLElement>("timestamp", "", dateTimeToString(*value))); + } + else if (boost::optional<std::string> value = payload->getFloor()) { + result.addNode(boost::make_shared<XMLElement>("floor", "", *value)); + } + else if (boost::optional<std::string> value = payload->getBuilding()) { + result.addNode(boost::make_shared<XMLElement>("building", "", *value)); + } + else if (boost::optional<std::string> value = payload->getRoom()) { + result.addNode(boost::make_shared<XMLElement>("room", "", *value)); + } + else if (boost::optional<std::string> value = payload->getCountry()) { + result.addNode(boost::make_shared<XMLElement>("country", "", *value)); + } + else if (boost::optional<std::string> value = payload->getRegion()) { + result.addNode(boost::make_shared<XMLElement>("region", "", *value)); + } + else if (boost::optional<std::string> value = payload->getURI()) { + result.addNode(boost::make_shared<XMLElement>("uri", "", *value)); + } + else if (boost::optional<float> value = payload->getLongitude()) { + result.addNode(boost::make_shared<XMLElement>("lon", "", boost::lexical_cast<std::string>(*value))); + } + else if (boost::optional<float> value = payload->getError()) { + result.addNode(boost::make_shared<XMLElement>("error", "", boost::lexical_cast<std::string>(*value))); + } + else if (boost::optional<std::string> value = payload->getPostalCode()) { + result.addNode(boost::make_shared<XMLElement>("postalcode", "", *value)); + } + else if (boost::optional<float> value = payload->getBearing()) { + result.addNode(boost::make_shared<XMLElement>("bearing", "", boost::lexical_cast<std::string>(*value))); + } + else if (boost::optional<std::string> value = payload->getText()) { + result.addNode(boost::make_shared<XMLElement>("text", "", *value)); + } + else if (boost::optional<std::string> value = payload->getDatum()) { + result.addNode(boost::make_shared<XMLElement>("datum", "", *value)); + } + else if (boost::optional<std::string> value = payload->getStreet()) { + result.addNode(boost::make_shared<XMLElement>("street", "", *value)); + } + else if (boost::optional<float> value = payload->getSpeed()) { + result.addNode(boost::make_shared<XMLElement>("speed", "", boost::lexical_cast<std::string>(*value))); + } + return result.serialize(); +} + +} diff --git a/Swiften/Serializer/PayloadSerializers/UserLocationSerializer.h b/Swiften/Serializer/PayloadSerializers/UserLocationSerializer.h new file mode 100644 index 0000000..28a5fe8 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UserLocationSerializer.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * 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/UserLocation.h> + +namespace Swift { + class UserLocationSerializer : public GenericPayloadSerializer<UserLocation> { + public: + UserLocationSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<UserLocation>) const; + }; +} diff --git a/Swiften/Serializer/XML/XMLElement.cpp b/Swiften/Serializer/XML/XMLElement.cpp index d39ec39..42b602a 100644 --- a/Swiften/Serializer/XML/XMLElement.cpp +++ b/Swiften/Serializer/XML/XMLElement.cpp @@ -52,7 +52,9 @@ void XMLElement::setAttribute(const std::string& attribute, const std::string& v } void XMLElement::addNode(boost::shared_ptr<XMLNode> node) { - childNodes_.push_back(node); + if (node) { + childNodes_.push_back(node); + } } } |