diff options
author | Remko Tronçon <git@el-tramo.be> | 2010-03-28 15:46:49 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2010-03-28 15:46:49 (GMT) |
commit | f53a1ef582494458301b97bf6e546be52d7ff7e8 (patch) | |
tree | 7571b5cbcbd8a8f1dd1c966c9045b6cb69f0e295 /Swiften/Serializer/PayloadSerializers | |
parent | 638345680d72ca6acaf123f2c8c1c391f696e371 (diff) | |
download | swift-f53a1ef582494458301b97bf6e546be52d7ff7e8.zip swift-f53a1ef582494458301b97bf6e546be52d7ff7e8.tar.bz2 |
Moving submodule contents back.
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers')
52 files changed, 1467 insertions, 0 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/BodySerializer.h b/Swiften/Serializer/PayloadSerializers/BodySerializer.h new file mode 100644 index 0000000..7fba561 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/BodySerializer.h @@ -0,0 +1,20 @@ +#ifndef SWIFTEN_BodySerializer_H +#define SWIFTEN_BodySerializer_H + +#include "Swiften/Serializer/GenericPayloadSerializer.h" +#include "Swiften/Serializer/XML/XMLTextNode.h" +#include "Swiften/Elements/Body.h" + +namespace Swift { + class BodySerializer : public GenericPayloadSerializer<Body> { + public: + BodySerializer() : GenericPayloadSerializer<Body>() {} + + virtual String serializePayload(boost::shared_ptr<Body> body) const { + XMLTextNode textNode(body->getText()); + return "<body>" + textNode.serialize() + "</body>"; + } + }; +} + +#endif diff --git a/Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.cpp b/Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.cpp new file mode 100644 index 0000000..fbb72af --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.cpp @@ -0,0 +1,20 @@ +#include "Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.h" + +#include <boost/shared_ptr.hpp> + +#include "Swiften/Serializer/XML/XMLElement.h" + +namespace Swift { + +CapsInfoSerializer::CapsInfoSerializer() : GenericPayloadSerializer<CapsInfo>() { +} + +String CapsInfoSerializer::serializePayload(boost::shared_ptr<CapsInfo> capsInfo) const { + XMLElement capsElement("c", "http://jabber.org/protocol/caps"); + capsElement.setAttribute("node", capsInfo->getNode()); + capsElement.setAttribute("hash", capsInfo->getHash()); + capsElement.setAttribute("ver", capsInfo->getVersion()); + return capsElement.serialize(); +} + +} diff --git a/Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.h b/Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.h new file mode 100644 index 0000000..cb4fa33 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.h @@ -0,0 +1,16 @@ +#ifndef SWIFTEN_CapsInfoSerializer_H +#define SWIFTEN_CapsInfoSerializer_H + +#include "Swiften/Serializer/GenericPayloadSerializer.h" +#include "Swiften/Elements/CapsInfo.h" + +namespace Swift { + class CapsInfoSerializer : public GenericPayloadSerializer<CapsInfo> { + public: + CapsInfoSerializer(); + + virtual String serializePayload(boost::shared_ptr<CapsInfo>) const; + }; +} + +#endif diff --git a/Swiften/Serializer/PayloadSerializers/ChatStateSerializer.cpp b/Swiften/Serializer/PayloadSerializers/ChatStateSerializer.cpp new file mode 100644 index 0000000..0507092 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/ChatStateSerializer.cpp @@ -0,0 +1,22 @@ +#include "Swiften/Serializer/PayloadSerializers/ChatStateSerializer.h" + +namespace Swift { + +ChatStateSerializer::ChatStateSerializer() : GenericPayloadSerializer<ChatState>() { +} + +String ChatStateSerializer::serializePayload(boost::shared_ptr<ChatState> chatState) const { + String result("<"); + switch (chatState->getChatState()) { + case ChatState::Active: result += "active"; break; + case ChatState::Composing: result += "composing"; break; + case ChatState::Paused: result += "paused"; break; + case ChatState::Inactive: result += "inactive"; break; + case ChatState::Gone: result += "gone"; break; + default: result += "gone"; break; + } + result += " xmlns=\"http://jabber.org/protocol/chatstates\"/>"; + return result; +} + +} diff --git a/Swiften/Serializer/PayloadSerializers/ChatStateSerializer.h b/Swiften/Serializer/PayloadSerializers/ChatStateSerializer.h new file mode 100644 index 0000000..e99b8b6 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/ChatStateSerializer.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Swiften/Serializer/GenericPayloadSerializer.h" +#include "Swiften/Elements/ChatState.h" + +namespace Swift { + class ChatStateSerializer : public GenericPayloadSerializer<ChatState> { + public: + ChatStateSerializer(); + + virtual String serializePayload(boost::shared_ptr<ChatState> error) const; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.cpp b/Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.cpp new file mode 100644 index 0000000..4c39574 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.cpp @@ -0,0 +1,36 @@ +#include "Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h" + +#include <boost/shared_ptr.hpp> + +#include "Swiften/Base/foreach.h" +#include "Swiften/Serializer/XML/XMLElement.h" + +namespace Swift { + +DiscoInfoSerializer::DiscoInfoSerializer() : GenericPayloadSerializer<DiscoInfo>() { +} + +String DiscoInfoSerializer::serializePayload(boost::shared_ptr<DiscoInfo> discoInfo) const { + XMLElement queryElement("query", "http://jabber.org/protocol/disco#info"); + if (!discoInfo->getNode().isEmpty()) { + queryElement.setAttribute("node", discoInfo->getNode()); + } + foreach(const DiscoInfo::Identity& identity, discoInfo->getIdentities()) { + boost::shared_ptr<XMLElement> identityElement(new XMLElement("identity")); + if (!identity.getLanguage().isEmpty()) { + identityElement->setAttribute("xml:lang", identity.getLanguage()); + } + identityElement->setAttribute("category", identity.getCategory()); + identityElement->setAttribute("name", identity.getName()); + identityElement->setAttribute("type", identity.getType()); + queryElement.addNode(identityElement); + } + foreach(const String& feature, discoInfo->getFeatures()) { + boost::shared_ptr<XMLElement> featureElement(new XMLElement("feature")); + featureElement->setAttribute("var", feature); + queryElement.addNode(featureElement); + } + return queryElement.serialize(); +} + +} diff --git a/Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h b/Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h new file mode 100644 index 0000000..929a455 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h @@ -0,0 +1,16 @@ +#ifndef SWIFTEN_DiscoInfoSerializer_H +#define SWIFTEN_DiscoInfoSerializer_H + +#include "Swiften/Serializer/GenericPayloadSerializer.h" +#include "Swiften/Elements/DiscoInfo.h" + +namespace Swift { + class DiscoInfoSerializer : public GenericPayloadSerializer<DiscoInfo> { + public: + DiscoInfoSerializer(); + + virtual String serializePayload(boost::shared_ptr<DiscoInfo>) const; + }; +} + +#endif diff --git a/Swiften/Serializer/PayloadSerializers/ErrorSerializer.cpp b/Swiften/Serializer/PayloadSerializers/ErrorSerializer.cpp new file mode 100644 index 0000000..f5ce478 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/ErrorSerializer.cpp @@ -0,0 +1,56 @@ +#include "Swiften/Serializer/PayloadSerializers/ErrorSerializer.h" +#include "Swiften/Serializer/XML/XMLTextNode.h" + +namespace Swift { + +ErrorSerializer::ErrorSerializer() : GenericPayloadSerializer<ErrorPayload>() { +} + +String ErrorSerializer::serializePayload(boost::shared_ptr<ErrorPayload> error) const { + String result("<error type=\""); + switch (error->getType()) { + case ErrorPayload::Continue: result += "continue"; break; + case ErrorPayload::Modify: result += "modify"; break; + case ErrorPayload::Auth: result += "auth"; break; + case ErrorPayload::Wait: result += "wait"; break; + default: result += "cancel"; break; + } + result += "\">"; + + String conditionElement; + switch (error->getCondition()) { + case ErrorPayload::BadRequest: conditionElement = "bad-request"; break; + case ErrorPayload::Conflict: conditionElement = "conflict"; break; + case ErrorPayload::FeatureNotImplemented: conditionElement = "feature-not-implemented"; break; + case ErrorPayload::Forbidden: conditionElement = "forbidden"; break; + case ErrorPayload::Gone: conditionElement = "gone"; break; + case ErrorPayload::InternalServerError: conditionElement = "internal-server-error"; break; + case ErrorPayload::ItemNotFound: conditionElement = "item-not-found"; break; + case ErrorPayload::JIDMalformed: conditionElement = "jid-malformed"; break; + case ErrorPayload::NotAcceptable: conditionElement = "not-acceptable"; break; + case ErrorPayload::NotAllowed: conditionElement = "not-allowed"; break; + case ErrorPayload::NotAuthorized: conditionElement = "not-authorized"; break; + case ErrorPayload::PaymentRequired: conditionElement = "payment-required"; break; + case ErrorPayload::RecipientUnavailable: conditionElement = "recipient-unavailable"; break; + case ErrorPayload::Redirect: conditionElement = "redirect"; break; + case ErrorPayload::RegistrationRequired: conditionElement = "registration-required"; break; + case ErrorPayload::RemoteServerNotFound: conditionElement = "remote-server-not-found"; break; + case ErrorPayload::RemoteServerTimeout: conditionElement = "remote-server-timeout"; break; + case ErrorPayload::ResourceConstraint: conditionElement = "resource-constraint"; break; + case ErrorPayload::ServiceUnavailable: conditionElement = "service-unavailable"; break; + case ErrorPayload::SubscriptionRequired: conditionElement = "subscription-required"; break; + case ErrorPayload::UnexpectedRequest: conditionElement = "unexpected-request"; break; + default: conditionElement = "undefined-condition"; break; + } + result += "<" + conditionElement + " xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/>"; + + if (!error->getText().isEmpty()) { + XMLTextNode textNode(error->getText()); + result += "<text xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\">" + textNode.serialize() + "</text>"; + } + + result += "</error>"; + return result; +} + +} diff --git a/Swiften/Serializer/PayloadSerializers/ErrorSerializer.h b/Swiften/Serializer/PayloadSerializers/ErrorSerializer.h new file mode 100644 index 0000000..931596f --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/ErrorSerializer.h @@ -0,0 +1,16 @@ +#ifndef SWIFTEN_ErrorSerializer_H +#define SWIFTEN_ErrorSerializer_H + +#include "Swiften/Serializer/GenericPayloadSerializer.h" +#include "Swiften/Elements/ErrorPayload.h" + +namespace Swift { + class ErrorSerializer : public GenericPayloadSerializer<ErrorPayload> { + public: + ErrorSerializer(); + + virtual String serializePayload(boost::shared_ptr<ErrorPayload> error) const; + }; +} + +#endif diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp new file mode 100644 index 0000000..accf6c6 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp @@ -0,0 +1,61 @@ +#include "Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h" +#include "Swiften/Base/foreach.h" +#include "Swiften/Serializer/PayloadSerializer.h" +#include "Swiften/Serializer/PayloadSerializers/BodySerializer.h" +#include "Swiften/Serializer/PayloadSerializers/ChatStateSerializer.h" +#include "Swiften/Serializer/PayloadSerializers/PrioritySerializer.h" +#include "Swiften/Serializer/PayloadSerializers/ErrorSerializer.h" +#include "Swiften/Serializer/PayloadSerializers/RosterSerializer.h" +#include "Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.h" +#include "Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h" +#include "Swiften/Serializer/PayloadSerializers/StatusSerializer.h" +#include "Swiften/Serializer/PayloadSerializers/StatusShowSerializer.h" +#include "Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h" +#include "Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.h" +#include "Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h" +#include "Swiften/Serializer/PayloadSerializers/StartSessionSerializer.h" +#include "Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h" +#include "Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.h" +#include "Swiften/Serializer/PayloadSerializers/VCardSerializer.h" +#include "Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.h" +#include "Swiften/Serializer/PayloadSerializers/RawXMLPayloadSerializer.h" +#include "Swiften/Serializer/PayloadSerializers/StorageSerializer.h" +#include "Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.h" + +namespace Swift { + +FullPayloadSerializerCollection::FullPayloadSerializerCollection() { + serializers_.push_back(new BodySerializer()); + serializers_.push_back(new ChatStateSerializer()); + serializers_.push_back(new PrioritySerializer()); + serializers_.push_back(new ErrorSerializer()); + serializers_.push_back(new RosterSerializer()); + serializers_.push_back(new MUCPayloadSerializer()); + serializers_.push_back(new SoftwareVersionSerializer()); + serializers_.push_back(new StatusSerializer()); + serializers_.push_back(new StatusShowSerializer()); + serializers_.push_back(new DiscoInfoSerializer()); + serializers_.push_back(new CapsInfoSerializer()); + serializers_.push_back(new ResourceBindSerializer()); + serializers_.push_back(new StartSessionSerializer()); + serializers_.push_back(new SecurityLabelSerializer()); + serializers_.push_back(new SecurityLabelsCatalogSerializer()); + serializers_.push_back(new VCardSerializer()); + serializers_.push_back(new VCardUpdateSerializer()); + serializers_.push_back(new RawXMLPayloadSerializer()); + serializers_.push_back(new StorageSerializer()); + serializers_.push_back(new PrivateStorageSerializer(this)); + foreach(PayloadSerializer* serializer, serializers_) { + addSerializer(serializer); + } +} + +FullPayloadSerializerCollection::~FullPayloadSerializerCollection() { + foreach(PayloadSerializer* serializer, serializers_) { + removeSerializer(serializer); + delete serializer; + } + serializers_.clear(); +} + +} diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h new file mode 100644 index 0000000..e1655b5 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h @@ -0,0 +1,19 @@ +#ifndef SWIFTEN_FULLPAYLOADSERIALIZERCOLLECTION_H +#define SWIFTEN_FULLPAYLOADSERIALIZERCOLLECTION_H + +#include <vector> + +#include "Swiften/Serializer/PayloadSerializerCollection.h" + +namespace Swift { + class FullPayloadSerializerCollection : public PayloadSerializerCollection { + public: + FullPayloadSerializerCollection(); + ~FullPayloadSerializerCollection(); + + private: + std::vector<PayloadSerializer*> serializers_; + }; +} + +#endif diff --git a/Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.cpp b/Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.cpp new file mode 100644 index 0000000..9c701cc --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.cpp @@ -0,0 +1,13 @@ +#include "Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.h" + +namespace Swift { + +MUCPayloadSerializer::MUCPayloadSerializer() : GenericPayloadSerializer<MUCPayload>() { +} + +String MUCPayloadSerializer::serializePayload(boost::shared_ptr<MUCPayload>) const { + String result("<x xmlns='http://jabber.org/protocol/muc'/>"); + return result; +} + +} diff --git a/Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.h b/Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.h new file mode 100644 index 0000000..504c969 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.h @@ -0,0 +1,16 @@ +#ifndef SWIFTEN_MUCPayloadSerializer_H +#define SWIFTEN_MUCPayloadSerializer_H + +#include "Swiften/Serializer/GenericPayloadSerializer.h" +#include "Swiften/Elements/MUCPayload.h" + +namespace Swift { + class MUCPayloadSerializer : public GenericPayloadSerializer<MUCPayload> { + public: + MUCPayloadSerializer(); + + virtual String serializePayload(boost::shared_ptr<MUCPayload> version) const; + }; +} + +#endif diff --git a/Swiften/Serializer/PayloadSerializers/PrioritySerializer.h b/Swiften/Serializer/PayloadSerializers/PrioritySerializer.h new file mode 100644 index 0000000..f132b6e --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PrioritySerializer.h @@ -0,0 +1,20 @@ +#ifndef SWIFTEN_PrioritySerializer_H +#define SWIFTEN_PrioritySerializer_H + +#include <boost/lexical_cast.hpp> + +#include "Swiften/Serializer/GenericPayloadSerializer.h" +#include "Swiften/Elements/Priority.h" + +namespace Swift { + class PrioritySerializer : public GenericPayloadSerializer<Priority> { + public: + PrioritySerializer() : GenericPayloadSerializer<Priority>() {} + + virtual String serializePayload(boost::shared_ptr<Priority> priority) const { + return "<priority>" + boost::lexical_cast<std::string>(priority->getPriority()) + "</priority>"; + } + }; +} + +#endif diff --git a/Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.cpp new file mode 100644 index 0000000..999252c --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.cpp @@ -0,0 +1,28 @@ +#include "Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.h" + +#include <boost/shared_ptr.hpp> + +#include "Swiften/Base/foreach.h" +#include "Swiften/Serializer/XML/XMLElement.h" +#include "Swiften/Serializer/XML/XMLTextNode.h" +#include "Swiften/Serializer/XML/XMLRawTextNode.h" +#include "Swiften/Serializer/PayloadSerializerCollection.h" + +namespace Swift { + +PrivateStorageSerializer::PrivateStorageSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +String PrivateStorageSerializer::serializePayload(boost::shared_ptr<PrivateStorage> storage) const { + XMLElement storageElement("query", "jabber:iq:private"); + boost::shared_ptr<Payload> payload = storage->getPayload(); + if (payload) { + PayloadSerializer* serializer = serializers->getPayloadSerializer(payload); + if (serializer) { + storageElement.addNode(boost::shared_ptr<XMLRawTextNode>(new XMLRawTextNode(serializer->serialize(payload)))); + } + } + return storageElement.serialize(); +} + +} diff --git a/Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.h b/Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.h new file mode 100644 index 0000000..c655634 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.h @@ -0,0 +1,18 @@ +#pragma once + +#include "Swiften/Serializer/GenericPayloadSerializer.h" +#include "Swiften/Elements/PrivateStorage.h" + +namespace Swift { + class PayloadSerializerCollection; + + class PrivateStorageSerializer : public GenericPayloadSerializer<PrivateStorage> { + public: + PrivateStorageSerializer(PayloadSerializerCollection* serializers); + + virtual String serializePayload(boost::shared_ptr<PrivateStorage>) const; + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/RawXMLPayloadSerializer.h b/Swiften/Serializer/PayloadSerializers/RawXMLPayloadSerializer.h new file mode 100644 index 0000000..f980174 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/RawXMLPayloadSerializer.h @@ -0,0 +1,15 @@ +#pragma once + +#include "Swiften/Serializer/GenericPayloadSerializer.h" +#include "Swiften/Elements/RawXMLPayload.h" + +namespace Swift { + class RawXMLPayloadSerializer : public GenericPayloadSerializer<RawXMLPayload> { + public: + RawXMLPayloadSerializer() : GenericPayloadSerializer<RawXMLPayload>() {} + + virtual String serializePayload(boost::shared_ptr<RawXMLPayload> p) const { + return p->getRawXML(); + } + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.cpp b/Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.cpp new file mode 100644 index 0000000..93ab136 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.cpp @@ -0,0 +1,28 @@ +#include "Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h" + +#include <boost/shared_ptr.hpp> + +#include "Swiften/Serializer/XML/XMLElement.h" +#include "Swiften/Serializer/XML/XMLTextNode.h" + +namespace Swift { + +ResourceBindSerializer::ResourceBindSerializer() : GenericPayloadSerializer<ResourceBind>() { +} + +String ResourceBindSerializer::serializePayload(boost::shared_ptr<ResourceBind> resourceBind) const { + XMLElement bindElement("bind", "urn:ietf:params:xml:ns:xmpp-bind"); + if (resourceBind->getJID().isValid()) { + boost::shared_ptr<XMLElement> jidNode(new XMLElement("jid")); + jidNode->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(resourceBind->getJID().toString()))); + bindElement.addNode(jidNode); + } + else if (!resourceBind->getResource().isEmpty()) { + boost::shared_ptr<XMLElement> resourceNode(new XMLElement("resource")); + resourceNode->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(resourceBind->getResource()))); + bindElement.addNode(resourceNode); + } + return bindElement.serialize(); +} + +} diff --git a/Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h b/Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h new file mode 100644 index 0000000..61cf539 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h @@ -0,0 +1,16 @@ +#ifndef SWIFTEN_ResourceBindSerializer_H +#define SWIFTEN_ResourceBindSerializer_H + +#include "Swiften/Serializer/GenericPayloadSerializer.h" +#include "Swiften/Elements/ResourceBind.h" + +namespace Swift { + class ResourceBindSerializer : public GenericPayloadSerializer<ResourceBind> { + public: + ResourceBindSerializer(); + + virtual String serializePayload(boost::shared_ptr<ResourceBind>) const; + }; +} + +#endif diff --git a/Swiften/Serializer/PayloadSerializers/RosterSerializer.cpp b/Swiften/Serializer/PayloadSerializers/RosterSerializer.cpp new file mode 100644 index 0000000..6329f86 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/RosterSerializer.cpp @@ -0,0 +1,45 @@ +#include "Swiften/Serializer/PayloadSerializers/RosterSerializer.h" + +#include <boost/shared_ptr.hpp> + +#include "Swiften/Base/foreach.h" +#include "Swiften/Serializer/XML/XMLTextNode.h" +#include "Swiften/Serializer/XML/XMLElement.h" + +namespace Swift { + +RosterSerializer::RosterSerializer() : GenericPayloadSerializer<RosterPayload>() { +} + +String RosterSerializer::serializePayload(boost::shared_ptr<RosterPayload> roster) const { + XMLElement queryElement("query", "jabber:iq:roster"); + foreach(const RosterItemPayload& item, roster->getItems()) { + boost::shared_ptr<XMLElement> itemElement(new XMLElement("item")); + itemElement->setAttribute("jid", item.getJID()); + itemElement->setAttribute("name", item.getName()); + + switch (item.getSubscription()) { + case RosterItemPayload::To: itemElement->setAttribute("subscription", "to"); break; + case RosterItemPayload::From: itemElement->setAttribute("subscription", "from"); break; + case RosterItemPayload::Both: itemElement->setAttribute("subscription", "both"); break; + case RosterItemPayload::Remove: itemElement->setAttribute("subscription", "remove"); break; + case RosterItemPayload::None: itemElement->setAttribute("subscription", "none"); break; + } + + if (item.getSubscriptionRequested()) { + itemElement->setAttribute("ask", "subscribe"); + } + + foreach(const String& group, item.getGroups()) { + boost::shared_ptr<XMLElement> groupElement(new XMLElement("group")); + groupElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(group))); + itemElement->addNode(groupElement); + } + + queryElement.addNode(itemElement); + } + + return queryElement.serialize(); +} + +} diff --git a/Swiften/Serializer/PayloadSerializers/RosterSerializer.h b/Swiften/Serializer/PayloadSerializers/RosterSerializer.h new file mode 100644 index 0000000..fb6a713 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/RosterSerializer.h @@ -0,0 +1,16 @@ +#ifndef SWIFTEN_RosterSerializer_H +#define SWIFTEN_RosterSerializer_H + +#include "Swiften/Serializer/GenericPayloadSerializer.h" +#include "Swiften/Elements/RosterPayload.h" + +namespace Swift { + class RosterSerializer : public GenericPayloadSerializer<RosterPayload> { + public: + RosterSerializer(); + + virtual String serializePayload(boost::shared_ptr<RosterPayload>) const; + }; +} + +#endif diff --git a/Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.cpp b/Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.cpp new file mode 100644 index 0000000..dcce4dc --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.cpp @@ -0,0 +1,38 @@ +#include "Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h" +#include "Swiften/Base/foreach.h" +#include "Swiften/Serializer/XML/XMLRawTextNode.h" +#include "Swiften/Serializer/XML/XMLTextNode.h" +#include "Swiften/Serializer/XML/XMLElement.h" + +namespace Swift { + +SecurityLabelSerializer::SecurityLabelSerializer() : GenericPayloadSerializer<SecurityLabel>() { +} + +String SecurityLabelSerializer::serializePayload(boost::shared_ptr<SecurityLabel> label) const { + XMLElement element("securitylabel", "urn:xmpp:sec-label:0"); + if (!label->getDisplayMarking().isEmpty()) { + boost::shared_ptr<XMLElement> displayMarking(new XMLElement("displaymarking")); + if (!label->getForegroundColor().isEmpty()) { + displayMarking->setAttribute("fgcolor", label->getForegroundColor()); + } + if (!label->getBackgroundColor().isEmpty()) { + displayMarking->setAttribute("bgcolor", label->getBackgroundColor()); + } + displayMarking->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(label->getDisplayMarking()))); + element.addNode(displayMarking); + } + + boost::shared_ptr<XMLElement> labelElement(new XMLElement("label")); + labelElement->addNode(boost::shared_ptr<XMLRawTextNode>(new XMLRawTextNode(label->getLabel()))); + element.addNode(labelElement); + + foreach(const String& equivalentLabel, label->getEquivalentLabels()) { + boost::shared_ptr<XMLElement> equivalentLabelElement(new XMLElement("equivalentlabel")); + equivalentLabelElement->addNode(boost::shared_ptr<XMLRawTextNode>(new XMLRawTextNode(equivalentLabel))); + element.addNode(equivalentLabelElement); + } + return element.serialize(); +} + +} diff --git a/Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h b/Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h new file mode 100644 index 0000000..b0b0804 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h @@ -0,0 +1,16 @@ +#ifndef SWIFTEN_SecurityLabelSerializer_H +#define SWIFTEN_SecurityLabelSerializer_H + +#include "Swiften/Serializer/GenericPayloadSerializer.h" +#include "Swiften/Elements/SecurityLabel.h" + +namespace Swift { + class SecurityLabelSerializer : public GenericPayloadSerializer<SecurityLabel> { + public: + SecurityLabelSerializer(); + + virtual String serializePayload(boost::shared_ptr<SecurityLabel> version) const; + }; +} + +#endif diff --git a/Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.cpp b/Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.cpp new file mode 100644 index 0000000..bc6a41f --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.cpp @@ -0,0 +1,30 @@ +#include "Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.h" +#include "Swiften/Base/foreach.h" +#include "Swiften/Serializer/XML/XMLElement.h" +#include "Swiften/Serializer/XML/XMLRawTextNode.h" +#include "Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h" + +namespace Swift { + +SecurityLabelsCatalogSerializer::SecurityLabelsCatalogSerializer() : GenericPayloadSerializer<SecurityLabelsCatalog>() { +} + +String SecurityLabelsCatalogSerializer::serializePayload(boost::shared_ptr<SecurityLabelsCatalog> catalog) const { + XMLElement element("catalog", "urn:xmpp:sec-label:catalog:0"); + if (!catalog->getName().isEmpty()) { + element.setAttribute("name", catalog->getName()); + } + if (catalog->getTo().isValid()) { + element.setAttribute("to", catalog->getTo()); + } + if (!catalog->getDescription().isEmpty()) { + element.setAttribute("desc", catalog->getDescription()); + } + foreach (const SecurityLabel& label, catalog->getLabels()) { + String serializedLabel = SecurityLabelSerializer().serialize(boost::shared_ptr<SecurityLabel>(new SecurityLabel(label))); + element.addNode(boost::shared_ptr<XMLRawTextNode>(new XMLRawTextNode(serializedLabel))); + } + return element.serialize(); +} + +} diff --git a/Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.h b/Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.h new file mode 100644 index 0000000..d086c79 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.h @@ -0,0 +1,16 @@ +#ifndef SWIFTEN_SecurityLabelsCatalogSerializer_H +#define SWIFTEN_SecurityLabelsCatalogSerializer_H + +#include "Swiften/Serializer/GenericPayloadSerializer.h" +#include "Swiften/Elements/SecurityLabelsCatalog.h" + +namespace Swift { + class SecurityLabelsCatalogSerializer : public GenericPayloadSerializer<SecurityLabelsCatalog> { + public: + SecurityLabelsCatalogSerializer(); + + virtual String serializePayload(boost::shared_ptr<SecurityLabelsCatalog> version) const; + }; +} + +#endif diff --git a/Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.cpp b/Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.cpp new file mode 100644 index 0000000..71ad9a2 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.cpp @@ -0,0 +1,23 @@ +#include "Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h" + +namespace Swift { + +SoftwareVersionSerializer::SoftwareVersionSerializer() : GenericPayloadSerializer<SoftwareVersion>() { +} + +String SoftwareVersionSerializer::serializePayload(boost::shared_ptr<SoftwareVersion> version) const { + String result("<query xmlns=\"jabber:iq:version\">"); + if (!version->getName().isEmpty()) { + result += "<name>" + version->getName() + "</name>"; + } + if (!version->getVersion().isEmpty()) { + result += "<version>" + version->getVersion() + "</version>"; + } + if (!version->getOS().isEmpty()) { + result += "<os>" + version->getOS() + "</os>"; + } + result += "</query>"; + return result; +} + +} diff --git a/Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h b/Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h new file mode 100644 index 0000000..50242f2 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h @@ -0,0 +1,16 @@ +#ifndef SWIFTEN_SoftwareVersionSerializer_H +#define SWIFTEN_SoftwareVersionSerializer_H + +#include "Swiften/Serializer/GenericPayloadSerializer.h" +#include "Swiften/Elements/SoftwareVersion.h" + +namespace Swift { + class SoftwareVersionSerializer : public GenericPayloadSerializer<SoftwareVersion> { + public: + SoftwareVersionSerializer(); + + virtual String serializePayload(boost::shared_ptr<SoftwareVersion> version) const; + }; +} + +#endif diff --git a/Swiften/Serializer/PayloadSerializers/StartSessionSerializer.h b/Swiften/Serializer/PayloadSerializers/StartSessionSerializer.h new file mode 100644 index 0000000..df35054 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/StartSessionSerializer.h @@ -0,0 +1,20 @@ +#ifndef SWIFTEN_StartSessionSerializer_H +#define SWIFTEN_StartSessionSerializer_H + +#include <boost/lexical_cast.hpp> + +#include "Swiften/Serializer/GenericPayloadSerializer.h" +#include "Swiften/Elements/StartSession.h" + +namespace Swift { + class StartSessionSerializer : public GenericPayloadSerializer<StartSession> { + public: + StartSessionSerializer() : GenericPayloadSerializer<StartSession>() {} + + virtual String serializePayload(boost::shared_ptr<StartSession>) const { + return XMLElement("session", "urn:ietf:params:xml:ns:xmpp-session").serialize(); + } + }; +} + +#endif diff --git a/Swiften/Serializer/PayloadSerializers/StatusSerializer.h b/Swiften/Serializer/PayloadSerializers/StatusSerializer.h new file mode 100644 index 0000000..dc5f6d1 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/StatusSerializer.h @@ -0,0 +1,22 @@ +#ifndef SWIFTEN_StatusSerializer_H +#define SWIFTEN_StatusSerializer_H + +#include "Swiften/Serializer/GenericPayloadSerializer.h" +#include "Swiften/Serializer/XML/XMLElement.h" +#include "Swiften/Serializer/XML/XMLTextNode.h" +#include "Swiften/Elements/Status.h" + +namespace Swift { + class StatusSerializer : public GenericPayloadSerializer<Status> { + public: + StatusSerializer() : GenericPayloadSerializer<Status>() {} + + virtual String serializePayload(boost::shared_ptr<Status> status) const { + XMLElement element("status"); + element.addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(status->getText()))); + return element.serialize(); + } + }; +} + +#endif diff --git a/Swiften/Serializer/PayloadSerializers/StatusShowSerializer.h b/Swiften/Serializer/PayloadSerializers/StatusShowSerializer.h new file mode 100644 index 0000000..f66c09c --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/StatusShowSerializer.h @@ -0,0 +1,33 @@ +#ifndef SWIFTEN_StatusShowSerializer_H +#define SWIFTEN_StatusShowSerializer_H + +#include "Swiften/Serializer/GenericPayloadSerializer.h" +#include "Swiften/Elements/StatusShow.h" + +namespace Swift { + class StatusShowSerializer : public GenericPayloadSerializer<StatusShow> { + public: + StatusShowSerializer() : GenericPayloadSerializer<StatusShow>() {} + + virtual String serializePayload(boost::shared_ptr<StatusShow> statusShow) const { + if (statusShow->getType () == StatusShow::Online || statusShow->getType() == StatusShow::None) { + return ""; + } + else { + String result("<show>"); + switch (statusShow->getType()) { + case StatusShow::Away: result += "away"; break; + case StatusShow::XA: result += "xa"; break; + case StatusShow::FFC: result += "chat"; break; + case StatusShow::DND: result += "dnd"; break; + case StatusShow::Online: assert(false); break; + case StatusShow::None: assert(false); break; + } + result += "</show>"; + return result; + } + } + }; +} + +#endif diff --git a/Swiften/Serializer/PayloadSerializers/StorageSerializer.cpp b/Swiften/Serializer/PayloadSerializers/StorageSerializer.cpp new file mode 100644 index 0000000..4268381 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/StorageSerializer.cpp @@ -0,0 +1,36 @@ +#include "Swiften/Serializer/PayloadSerializers/StorageSerializer.h" + +#include <boost/shared_ptr.hpp> + +#include "Swiften/Base/foreach.h" +#include "Swiften/Serializer/XML/XMLElement.h" +#include "Swiften/Serializer/XML/XMLTextNode.h" + +namespace Swift { + +StorageSerializer::StorageSerializer() : GenericPayloadSerializer<Storage>() { +} + +String StorageSerializer::serializePayload(boost::shared_ptr<Storage> storage) const { + XMLElement storageElement("storage", "storage:bookmarks"); + foreach(const Storage::Conference& conference, storage->getConferences()) { + boost::shared_ptr<XMLElement> conferenceElement(new XMLElement("conference")); + conferenceElement->setAttribute("name", conference.name); + conferenceElement->setAttribute("jid", conference.jid); + conferenceElement->setAttribute("autojoin", conference.autoJoin ? "1" : "0"); + if (!conference.nick.isEmpty()) { + boost::shared_ptr<XMLElement> nickElement(new XMLElement("nick")); + nickElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(conference.nick))); + conferenceElement->addNode(nickElement); + } + if (!conference.password.isEmpty()) { + boost::shared_ptr<XMLElement> passwordElement(new XMLElement("password")); + passwordElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(conference.password))); + conferenceElement->addNode(passwordElement); + } + storageElement.addNode(conferenceElement); + } + return storageElement.serialize(); +} + +} diff --git a/Swiften/Serializer/PayloadSerializers/StorageSerializer.h b/Swiften/Serializer/PayloadSerializers/StorageSerializer.h new file mode 100644 index 0000000..e657376 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/StorageSerializer.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Swiften/Serializer/GenericPayloadSerializer.h" +#include "Swiften/Elements/Storage.h" + +namespace Swift { + class StorageSerializer : public GenericPayloadSerializer<Storage> { + public: + StorageSerializer(); + + virtual String serializePayload(boost::shared_ptr<Storage>) const; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/CapsInfoSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/CapsInfoSerializerTest.cpp new file mode 100644 index 0000000..650a7ee --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/CapsInfoSerializerTest.cpp @@ -0,0 +1,25 @@ +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include "Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.h" + +using namespace Swift; + +class CapsInfoSerializerTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(CapsInfoSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); + + public: + CapsInfoSerializerTest() {} + + void testSerialize() { + CapsInfoSerializer testling; + boost::shared_ptr<CapsInfo> priority(new CapsInfo("http://swift.im", "myversion", "sha-1")); + + CPPUNIT_ASSERT_EQUAL(String("<c hash=\"sha-1\" node=\"http://swift.im\" ver=\"myversion\" xmlns=\"http://jabber.org/protocol/caps\"/>"), testling.serialize(priority)); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(CapsInfoSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/DiscoInfoSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/DiscoInfoSerializerTest.cpp new file mode 100644 index 0000000..d3e247f --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/DiscoInfoSerializerTest.cpp @@ -0,0 +1,38 @@ +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include "Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h" + +using namespace Swift; + +class DiscoInfoSerializerTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(DiscoInfoSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); + + public: + DiscoInfoSerializerTest() {} + + void testSerialize() { + DiscoInfoSerializer testling; + boost::shared_ptr<DiscoInfo> discoInfo(new DiscoInfo()); + discoInfo->addIdentity(DiscoInfo::Identity("Swift", "client", "pc")); + discoInfo->addIdentity(DiscoInfo::Identity("Vlug", "client", "pc", "nl")); + discoInfo->addFeature("http://jabber.org/protocol/caps"); + discoInfo->addFeature("http://jabber.org/protocol/disco#info"); + discoInfo->setNode("http://swift.im#bla"); + + String expectedResult = + "<query node=\"http://swift.im#bla\" xmlns=\"http://jabber.org/protocol/disco#info\">" + "<identity category=\"client\" name=\"Swift\" type=\"pc\"/>" + "<identity category=\"client\" name=\"Vlug\" type=\"pc\" xml:lang=\"nl\"/>" + "<feature var=\"http://jabber.org/protocol/caps\"/>" + "<feature var=\"http://jabber.org/protocol/disco#info\"/>" + "</query>"; + + CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(discoInfo)); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(DiscoInfoSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp new file mode 100644 index 0000000..ecd904a --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp @@ -0,0 +1,25 @@ +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include "Swiften/Serializer/PayloadSerializers/ErrorSerializer.h" + +using namespace Swift; + +class ErrorSerializerTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(ErrorSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); + + public: + ErrorSerializerTest() {} + + void testSerialize() { + ErrorSerializer testling; + boost::shared_ptr<ErrorPayload> error(new ErrorPayload(ErrorPayload::BadRequest, ErrorPayload::Cancel, "My Error")); + + CPPUNIT_ASSERT_EQUAL(String("<error type=\"cancel\"><bad-request xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/><text xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\">My Error</text></error>"), testling.serialize(error)); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(ErrorSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.cpp new file mode 100644 index 0000000..23ff4a0 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.cpp @@ -0,0 +1,21 @@ +#include "Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.h" + +#include <cppunit/extensions/HelperMacros.h> + +#include "Swiften/Serializer/PayloadSerializer.h" + +namespace Swift { + +String PayloadsSerializer::serialize(boost::shared_ptr<Payload> payload) { + PayloadSerializer* serializer = serializers.getPayloadSerializer(payload); + if (serializer) { + return serializer->serialize(payload); + } + else { + CPPUNIT_ASSERT(false); + return ""; + } +} + + +} diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.h b/Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.h new file mode 100644 index 0000000..9fca334 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.h @@ -0,0 +1,17 @@ +#pragma once + +#include <boost/shared_ptr.hpp> + +#include "Swiften/Elements/Payload.h" +#include "Swiften/Base/String.h" +#include "Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h" + +namespace Swift { + class PayloadsSerializer { + public: + String serialize(boost::shared_ptr<Payload> payload); + + private: + FullPayloadSerializerCollection serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/PrioritySerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/PrioritySerializerTest.cpp new file mode 100644 index 0000000..5f6432b --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/PrioritySerializerTest.cpp @@ -0,0 +1,25 @@ +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include "Swiften/Serializer/PayloadSerializers/PrioritySerializer.h" + +using namespace Swift; + +class PrioritySerializerTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(PrioritySerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); + + public: + PrioritySerializerTest() {} + + void testSerialize() { + PrioritySerializer testling; + boost::shared_ptr<Priority> priority(new Priority(-113)); + + CPPUNIT_ASSERT_EQUAL(String("<priority>-113</priority>"), testling.serialize(priority)); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(PrioritySerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/PrivateStorageSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/PrivateStorageSerializerTest.cpp new file mode 100644 index 0000000..7f0d5c9 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/PrivateStorageSerializerTest.cpp @@ -0,0 +1,44 @@ +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include "Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.h" +#include "Swiften/Elements/PrivateStorage.h" +#include "Swiften/Elements/Storage.h" + +using namespace Swift; + +class PrivateStorageSerializerTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(PrivateStorageSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); + + public: + PrivateStorageSerializerTest() {} + + void testSerialize() { + PayloadsSerializer serializer; + + boost::shared_ptr<PrivateStorage> privateStorage(new PrivateStorage()); + boost::shared_ptr<Storage> storage(new Storage()); + Storage::Conference conference; + conference.name = "Swift"; + conference.jid = JID("swift@rooms.swift.im"); + conference.nick = "Alice"; + storage->addConference(conference); + privateStorage->setPayload(storage); + + CPPUNIT_ASSERT_EQUAL(String( + "<query xmlns=\"jabber:iq:private\">" + "<storage xmlns=\"storage:bookmarks\">" + "<conference " + "autojoin=\"0\" " + "jid=\"swift@rooms.swift.im\" " + "name=\"Swift\">" + "<nick>Alice</nick>" + "</conference>" + "</storage>" + "</query>"), serializer.serialize(privateStorage)); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(PrivateStorageSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/ResourceBindSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/ResourceBindSerializerTest.cpp new file mode 100644 index 0000000..ff09966 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/ResourceBindSerializerTest.cpp @@ -0,0 +1,49 @@ +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include "Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h" + +using namespace Swift; + +class ResourceBindSerializerTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(ResourceBindSerializerTest); + CPPUNIT_TEST(testSerialize_JID); + CPPUNIT_TEST(testSerialize_Resource); + CPPUNIT_TEST(testSerialize_Empty); + CPPUNIT_TEST_SUITE_END(); + + public: + ResourceBindSerializerTest() {} + + void testSerialize_JID() { + ResourceBindSerializer testling; + boost::shared_ptr<ResourceBind> resourceBind(new ResourceBind()); + resourceBind->setJID(JID("somenode@example.com/someresource")); + + CPPUNIT_ASSERT_EQUAL(String( + "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\">" + "<jid>somenode@example.com/someresource</jid>" + "</bind>"), testling.serialize(resourceBind)); + } + + void testSerialize_Resource() { + ResourceBindSerializer testling; + boost::shared_ptr<ResourceBind> resourceBind(new ResourceBind()); + resourceBind->setResource("someresource"); + + CPPUNIT_ASSERT_EQUAL(String( + "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\">" + "<resource>someresource</resource>" + "</bind>"), testling.serialize(resourceBind)); + } + + void testSerialize_Empty() { + ResourceBindSerializer testling; + boost::shared_ptr<ResourceBind> resourceBind(new ResourceBind()); + + CPPUNIT_ASSERT_EQUAL(String("<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\"/>"), testling.serialize(resourceBind)); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(ResourceBindSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/RosterSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/RosterSerializerTest.cpp new file mode 100644 index 0000000..81fdc09 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/RosterSerializerTest.cpp @@ -0,0 +1,48 @@ +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include "Swiften/Serializer/PayloadSerializers/RosterSerializer.h" + +using namespace Swift; + +class RosterSerializerTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(RosterSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); + + public: + RosterSerializerTest() {} + + void testSerialize() { + RosterSerializer testling; + boost::shared_ptr<RosterPayload> roster(new RosterPayload()); + + RosterItemPayload item1; + item1.setJID(JID("foo@bar.com")); + item1.setName("Foo @ Bar"); + item1.setSubscription(RosterItemPayload::From); + item1.addGroup("Group 1"); + item1.addGroup("Group 2"); + item1.setSubscriptionRequested(); + roster->addItem(item1); + + RosterItemPayload item2; + item2.setJID(JID("baz@blo.com")); + item2.setName("Baz"); + roster->addItem(item2); + + String expectedResult = + "<query xmlns=\"jabber:iq:roster\">" + "<item ask=\"subscribe\" jid=\"foo@bar.com\" name=\"Foo @ Bar\" subscription=\"from\">" + "<group>Group 1</group>" + "<group>Group 2</group>" + "</item>" + "<item jid=\"baz@blo.com\" name=\"Baz\" subscription=\"none\"/>" + "</query>"; + + CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(roster)); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(RosterSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelSerializerTest.cpp new file mode 100644 index 0000000..e75695f --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelSerializerTest.cpp @@ -0,0 +1,54 @@ +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include "Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h" + +using namespace Swift; + +class SecurityLabelSerializerTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(SecurityLabelSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST(testSerialize_EmptyLabel); + CPPUNIT_TEST_SUITE_END(); + + public: + void testSerialize() { + SecurityLabelSerializer testling; + boost::shared_ptr<SecurityLabel> securityLabel(new SecurityLabel()); + securityLabel->setDisplayMarking("SECRET"); + securityLabel->setForegroundColor("black"); + securityLabel->setBackgroundColor("red"); + securityLabel->setLabel("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel>"); + securityLabel->addEquivalentLabel("<icismlabel xmlns=\"http://example.gov/IC-ISM/0\" classification=\"S\" ownerProducer=\"USA\" disseminationControls=\"FOUO\"/>"); + securityLabel->addEquivalentLabel("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MRUCAgD9DA9BcXVhIChvYnNvbGV0ZSk=</esssecuritylabel>"); + + CPPUNIT_ASSERT_EQUAL(String( + "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" + "<displaymarking bgcolor=\"red\" fgcolor=\"black\">SECRET</displaymarking>" + "<label>" + "<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel>" + "</label>" + "<equivalentlabel>" + "<icismlabel xmlns=\"http://example.gov/IC-ISM/0\" classification=\"S\" ownerProducer=\"USA\" disseminationControls=\"FOUO\"/>" + "</equivalentlabel>" + "<equivalentlabel>" + "<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MRUCAgD9DA9BcXVhIChvYnNvbGV0ZSk=</esssecuritylabel>" + "</equivalentlabel>" + "</securitylabel>"), testling.serialize(securityLabel)); + } + + void testSerialize_EmptyLabel() { + SecurityLabelSerializer testling; + boost::shared_ptr<SecurityLabel> securityLabel(new SecurityLabel()); + securityLabel->setDisplayMarking("SECRET"); + securityLabel->setLabel(""); + + CPPUNIT_ASSERT_EQUAL(String( + "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" + "<displaymarking>SECRET</displaymarking>" + "<label></label>" + "</securitylabel>"), testling.serialize(securityLabel)); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(SecurityLabelSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelsCatalogSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelsCatalogSerializerTest.cpp new file mode 100644 index 0000000..3055aca --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelsCatalogSerializerTest.cpp @@ -0,0 +1,52 @@ +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include "Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.h" + +using namespace Swift; + +class SecurityLabelsCatalogSerializerTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(SecurityLabelsCatalogSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); + + public: + SecurityLabelsCatalogSerializerTest() {} + + void testSerialize() { + SecurityLabelsCatalogSerializer testling; + boost::shared_ptr<SecurityLabelsCatalog> catalog(new SecurityLabelsCatalog()); + catalog->setTo(JID("example.com")); + catalog->setName("Default"); + catalog->setDescription("an example set of labels"); + + SecurityLabel securityLabel1; + securityLabel1.setDisplayMarking("SECRET"); + securityLabel1.setForegroundColor("black"); + securityLabel1.setBackgroundColor("red"); + securityLabel1.setLabel("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel>"); + catalog->addLabel(securityLabel1); + + SecurityLabel securityLabel2; + securityLabel2.setDisplayMarking("CONFIDENTIAL"); + securityLabel2.setForegroundColor("black"); + securityLabel2.setBackgroundColor("navy"); + securityLabel2.setLabel("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQMGASk=</esssecuritylabel>"); + catalog->addLabel(securityLabel2); + + CPPUNIT_ASSERT_EQUAL(String( + "<catalog desc=\"an example set of labels\" name=\"Default\" to=\"example.com\" xmlns=\"urn:xmpp:sec-label:catalog:0\">" + "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" + "<displaymarking bgcolor=\"red\" fgcolor=\"black\">SECRET</displaymarking>" + "<label><esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel></label>" + "</securitylabel>" + "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" + "<displaymarking bgcolor=\"navy\" fgcolor=\"black\">CONFIDENTIAL</displaymarking>" + "<label><esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQMGASk=</esssecuritylabel></label>" + "</securitylabel>" + "</catalog>"), testling.serialize(catalog)); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(SecurityLabelsCatalogSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/SoftwareVersionSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/SoftwareVersionSerializerTest.cpp new file mode 100644 index 0000000..fd5dba5 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/SoftwareVersionSerializerTest.cpp @@ -0,0 +1,25 @@ +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include "Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h" + +using namespace Swift; + +class SoftwareVersionSerializerTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(SoftwareVersionSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); + + public: + SoftwareVersionSerializerTest() {} + + void testSerialize() { + SoftwareVersionSerializer testling; + boost::shared_ptr<SoftwareVersion> softwareVersion(new SoftwareVersion("Swift", "0.1", "Mac OS X")); + + CPPUNIT_ASSERT_EQUAL(String("<query xmlns=\"jabber:iq:version\"><name>Swift</name><version>0.1</version><os>Mac OS X</os></query>"), testling.serialize(softwareVersion)); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(SoftwareVersionSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/StatusSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/StatusSerializerTest.cpp new file mode 100644 index 0000000..6dedacd --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/StatusSerializerTest.cpp @@ -0,0 +1,25 @@ +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include "Swiften/Serializer/PayloadSerializers/StatusSerializer.h" + +using namespace Swift; + +class StatusSerializerTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(StatusSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); + + public: + StatusSerializerTest() {} + + void testSerialize() { + StatusSerializer testling; + boost::shared_ptr<Status> status(new Status("I am away")); + + CPPUNIT_ASSERT_EQUAL(String("<status>I am away</status>"), testling.serialize(status)); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(StatusSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/StatusShowSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/StatusShowSerializerTest.cpp new file mode 100644 index 0000000..42e1c7c --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/StatusShowSerializerTest.cpp @@ -0,0 +1,58 @@ +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include "Swiften/Serializer/PayloadSerializers/StatusShowSerializer.h" + +using namespace Swift; + +class StatusShowSerializerTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(StatusShowSerializerTest); + CPPUNIT_TEST(testSerialize_Online); + CPPUNIT_TEST(testSerialize_Away); + CPPUNIT_TEST(testSerialize_FFC); + CPPUNIT_TEST(testSerialize_XA); + CPPUNIT_TEST(testSerialize_DND); + CPPUNIT_TEST_SUITE_END(); + + public: + StatusShowSerializerTest() {} + + void testSerialize_Online() { + StatusShowSerializer testling; + boost::shared_ptr<StatusShow> statusShow(new StatusShow(StatusShow::Online)); + CPPUNIT_ASSERT_EQUAL(String(""), testling.serialize(statusShow)); + } + + void testSerialize_Away() { + StatusShowSerializer testling; + boost::shared_ptr<StatusShow> statusShow(new StatusShow(StatusShow::Away)); + CPPUNIT_ASSERT_EQUAL(String("<show>away</show>"), testling.serialize(statusShow)); + } + + void testSerialize_FFC() { + StatusShowSerializer testling; + boost::shared_ptr<StatusShow> statusShow(new StatusShow(StatusShow::FFC)); + CPPUNIT_ASSERT_EQUAL(String("<show>chat</show>"), testling.serialize(statusShow)); + } + + void testSerialize_XA() { + StatusShowSerializer testling; + boost::shared_ptr<StatusShow> statusShow(new StatusShow(StatusShow::XA)); + CPPUNIT_ASSERT_EQUAL(String("<show>xa</show>"), testling.serialize(statusShow)); + } + + void testSerialize_DND() { + StatusShowSerializer testling; + boost::shared_ptr<StatusShow> statusShow(new StatusShow(StatusShow::DND)); + CPPUNIT_ASSERT_EQUAL(String("<show>dnd</show>"), testling.serialize(statusShow)); + } + + void testSerialize_None() { + StatusShowSerializer testling; + boost::shared_ptr<StatusShow> statusShow(new StatusShow(StatusShow::None)); + CPPUNIT_ASSERT_EQUAL(String(""), testling.serialize(statusShow)); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(StatusShowSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/StorageSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/StorageSerializerTest.cpp new file mode 100644 index 0000000..daf43c5 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/StorageSerializerTest.cpp @@ -0,0 +1,60 @@ +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include "Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.h" +#include "Swiften/Elements/Storage.h" + +using namespace Swift; + +class StorageSerializerTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(StorageSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST(testSerialize_NoNickOrPassword); + CPPUNIT_TEST_SUITE_END(); + + public: + StorageSerializerTest() {} + + void testSerialize() { + PayloadsSerializer serializer; + boost::shared_ptr<Storage> storage(new Storage()); + Storage::Conference conference; + conference.name = "Council of Oberon"; + conference.autoJoin = true; + conference.jid = JID("council@conference.underhill.org"); + conference.nick = "Puck"; + conference.password = "MyPass"; + storage->addConference(conference); + + CPPUNIT_ASSERT_EQUAL(String( + "<storage xmlns=\"storage:bookmarks\">" + "<conference " + "autojoin=\"1\" " + "jid=\"council@conference.underhill.org\" " + "name=\"Council of Oberon\">" + "<nick>Puck</nick>" + "<password>MyPass</password>" + "</conference>" + "</storage>"), serializer.serialize(storage)); + } + + void testSerialize_NoNickOrPassword() { + PayloadsSerializer serializer; + boost::shared_ptr<Storage> storage(new Storage()); + Storage::Conference conference; + conference.name = "Council of Oberon"; + conference.autoJoin = true; + conference.jid = JID("council@conference.underhill.org"); + storage->addConference(conference); + + CPPUNIT_ASSERT_EQUAL(String( + "<storage xmlns=\"storage:bookmarks\">" + "<conference " + "autojoin=\"1\" " + "jid=\"council@conference.underhill.org\" " + "name=\"Council of Oberon\"/>" + "</storage>"), serializer.serialize(storage)); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(StorageSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/VCardUpdateSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/VCardUpdateSerializerTest.cpp new file mode 100644 index 0000000..23988d7 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/VCardUpdateSerializerTest.cpp @@ -0,0 +1,31 @@ +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include "Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.h" + +using namespace Swift; + +class VCardUpdateSerializerTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(VCardUpdateSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); + + public: + VCardUpdateSerializerTest() {} + + void testSerialize() { + VCardUpdateSerializer testling; + boost::shared_ptr<VCardUpdate> update(new VCardUpdate()); + update->setPhotoHash("sha1-hash-of-image"); + + String expectedResult = + "<x xmlns=\"vcard-temp:x:update\">" + "<photo>sha1-hash-of-image</photo>" + "</x>"; + + CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(update)); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(VCardUpdateSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp b/Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp new file mode 100644 index 0000000..fbb0274 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp @@ -0,0 +1,50 @@ +#include "Swiften/Serializer/PayloadSerializers/VCardSerializer.h" + +#include <boost/shared_ptr.hpp> + +#include "Swiften/Serializer/XML/XMLElement.h" +#include "Swiften/Serializer/XML/XMLTextNode.h" + +namespace Swift { + +VCardSerializer::VCardSerializer() : GenericPayloadSerializer<VCard>() { +} + +String VCardSerializer::serializePayload(boost::shared_ptr<VCard> vcard) const { + XMLElement queryElement("vCard", "vcard-temp"); + if (!vcard->getFullName().isEmpty()) { + boost::shared_ptr<XMLElement> fullNameElement(new XMLElement("FN")); + fullNameElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(vcard->getFullName()))); + queryElement.addNode(fullNameElement); + } + if (!vcard->getGivenName().isEmpty() || !vcard->getFamilyName().isEmpty()) { + boost::shared_ptr<XMLElement> nameElement(new XMLElement("N")); + if (!vcard->getFamilyName().isEmpty()) { + boost::shared_ptr<XMLElement> familyNameElement(new XMLElement("FAMILY")); + familyNameElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(vcard->getFamilyName()))); + nameElement->addNode(familyNameElement); + } + if (!vcard->getGivenName().isEmpty()) { + boost::shared_ptr<XMLElement> givenNameElement(new XMLElement("GIVEN")); + givenNameElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(vcard->getGivenName()))); + nameElement->addNode(givenNameElement); + } + queryElement.addNode(nameElement); + } + if (!vcard->getEMail().isEmpty()) { + boost::shared_ptr<XMLElement> emailElement(new XMLElement("EMAIL")); + boost::shared_ptr<XMLElement> userIDElement(new XMLElement("USERID")); + userIDElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(vcard->getEMail()))); + emailElement->addNode(userIDElement); + queryElement.addNode(emailElement); + } + if (!vcard->getNickname().isEmpty()) { + boost::shared_ptr<XMLElement> nickElement(new XMLElement("NICKNAME")); + nickElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(vcard->getNickname()))); + queryElement.addNode(nickElement); + } + // TODO + return queryElement.serialize(); +} + +} diff --git a/Swiften/Serializer/PayloadSerializers/VCardSerializer.h b/Swiften/Serializer/PayloadSerializers/VCardSerializer.h new file mode 100644 index 0000000..baf5947 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/VCardSerializer.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Swiften/Serializer/GenericPayloadSerializer.h" +#include "Swiften/Elements/VCard.h" + +namespace Swift { + class VCardSerializer : public GenericPayloadSerializer<VCard> { + public: + VCardSerializer(); + + virtual String serializePayload(boost::shared_ptr<VCard>) const; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.cpp b/Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.cpp new file mode 100644 index 0000000..540b48d --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.cpp @@ -0,0 +1,21 @@ +#include "Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.h" + +#include <boost/shared_ptr.hpp> + +#include "Swiften/Serializer/XML/XMLElement.h" +#include "Swiften/Serializer/XML/XMLTextNode.h" + +namespace Swift { + +VCardUpdateSerializer::VCardUpdateSerializer() : GenericPayloadSerializer<VCardUpdate>() { +} + +String VCardUpdateSerializer::serializePayload(boost::shared_ptr<VCardUpdate> vcardUpdate) const { + XMLElement updateElement("x", "vcard-temp:x:update"); + boost::shared_ptr<XMLElement> photoElement(new XMLElement("photo")); + photoElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(vcardUpdate->getPhotoHash()))); + updateElement.addNode(photoElement); + return updateElement.serialize(); +} + +} diff --git a/Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.h b/Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.h new file mode 100644 index 0000000..e1373a9 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Swiften/Serializer/GenericPayloadSerializer.h" +#include "Swiften/Elements/VCardUpdate.h" + +namespace Swift { + class VCardUpdateSerializer : public GenericPayloadSerializer<VCardUpdate> { + public: + VCardUpdateSerializer(); + + virtual String serializePayload(boost::shared_ptr<VCardUpdate>) const; + }; +} |