diff options
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers')
113 files changed, 2073 insertions, 389 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/BlockSerializer.h b/Swiften/Serializer/PayloadSerializers/BlockSerializer.h new file mode 100644 index 0000000..345463c --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/BlockSerializer.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Base/foreach.h> + +namespace Swift { + template<typename BLOCK_ELEMENT> + class BlockSerializer : public GenericPayloadSerializer<BLOCK_ELEMENT> { + public: + BlockSerializer(std::string tag) : GenericPayloadSerializer<BLOCK_ELEMENT>(), tag(tag) { + } + + virtual std::string serializePayload(boost::shared_ptr<BLOCK_ELEMENT> payload) const { + XMLElement element(tag, "urn:xmpp:blocking"); + foreach (const JID& jid, payload->getItems()) { + boost::shared_ptr<XMLElement> item = boost::make_shared<XMLElement>("item"); + item->setAttribute("jid", jid); + } + return element.serialize(); + } + + private: + std::string tag; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/BodySerializer.h b/Swiften/Serializer/PayloadSerializers/BodySerializer.h index 6fc6e6d..99df0f5 100644 --- a/Swiften/Serializer/PayloadSerializers/BodySerializer.h +++ b/Swiften/Serializer/PayloadSerializers/BodySerializer.h @@ -4,12 +4,11 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_BodySerializer_H -#define SWIFTEN_BodySerializer_H +#pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" -#include "Swiften/Elements/Body.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> +#include <Swiften/Elements/Body.h> namespace Swift { class BodySerializer : public GenericPayloadSerializer<Body> { @@ -22,5 +21,3 @@ namespace Swift { } }; } - -#endif diff --git a/Swiften/Serializer/PayloadSerializers/BytestreamsSerializer.cpp b/Swiften/Serializer/PayloadSerializers/BytestreamsSerializer.cpp index f9b89f3..beb84dd 100644 --- a/Swiften/Serializer/PayloadSerializers/BytestreamsSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/BytestreamsSerializer.cpp @@ -4,14 +4,14 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/BytestreamsSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/BytestreamsSerializer.h> #include <boost/shared_ptr.hpp> #include <boost/lexical_cast.hpp> -#include "Swiften/Base/foreach.h" -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/PayloadSerializerCollection.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/PayloadSerializerCollection.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/BytestreamsSerializer.h b/Swiften/Serializer/PayloadSerializers/BytestreamsSerializer.h index d9b14db..0e58eb0 100644 --- a/Swiften/Serializer/PayloadSerializers/BytestreamsSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/BytestreamsSerializer.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/Bytestreams.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/Bytestreams.h> namespace Swift { class PayloadSerializerCollection; diff --git a/Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.cpp b/Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.cpp index ced0d62..2466958 100644 --- a/Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.cpp @@ -4,11 +4,11 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Serializer/XML/XMLElement.h" +#include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.h b/Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.h index de0a871..2587ee0 100644 --- a/Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.h @@ -4,11 +4,10 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_CapsInfoSerializer_H -#define SWIFTEN_CapsInfoSerializer_H +#pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/CapsInfo.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/CapsInfo.h> namespace Swift { class CapsInfoSerializer : public GenericPayloadSerializer<CapsInfo> { @@ -18,5 +17,3 @@ namespace Swift { virtual std::string serializePayload(boost::shared_ptr<CapsInfo>) const; }; } - -#endif diff --git a/Swiften/Serializer/PayloadSerializers/ChatStateSerializer.cpp b/Swiften/Serializer/PayloadSerializers/ChatStateSerializer.cpp index 3e877eb..ee468bb 100644 --- a/Swiften/Serializer/PayloadSerializers/ChatStateSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/ChatStateSerializer.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/ChatStateSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/ChatStateSerializer.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/ChatStateSerializer.h b/Swiften/Serializer/PayloadSerializers/ChatStateSerializer.h index a786901..d71873d 100644 --- a/Swiften/Serializer/PayloadSerializers/ChatStateSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/ChatStateSerializer.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/ChatState.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/ChatState.h> namespace Swift { class ChatStateSerializer : public GenericPayloadSerializer<ChatState> { diff --git a/Swiften/Serializer/PayloadSerializers/CommandSerializer.cpp b/Swiften/Serializer/PayloadSerializers/CommandSerializer.cpp index 0fa45ce..2fb86b0 100644 --- a/Swiften/Serializer/PayloadSerializers/CommandSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/CommandSerializer.cpp @@ -4,16 +4,15 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/CommandSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/CommandSerializer.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" -#include "Swiften/Serializer/PayloadSerializers/FormSerializer.h" +#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/PayloadSerializers/FormSerializer.h> namespace Swift { @@ -21,7 +20,7 @@ CommandSerializer::CommandSerializer() { } std::string CommandSerializer::serializePayload(boost::shared_ptr<Command> command) const { - XMLElement commandElement("command", "http://jabber.org/protocol/comands"); + XMLElement commandElement("command", "http://jabber.org/protocol/commands"); commandElement.setAttribute("node", command->getNode()); if (!command->getSessionID().empty()) { diff --git a/Swiften/Serializer/PayloadSerializers/CommandSerializer.h b/Swiften/Serializer/PayloadSerializers/CommandSerializer.h index b1db825..03b6aa0 100644 --- a/Swiften/Serializer/PayloadSerializers/CommandSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/CommandSerializer.h @@ -6,12 +6,10 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/Command.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/Command.h> namespace Swift { - class PayloadSerializerCollection; - class CommandSerializer : public GenericPayloadSerializer<Command> { public: CommandSerializer(); diff --git a/Swiften/Serializer/PayloadSerializers/DelaySerializer.cpp b/Swiften/Serializer/PayloadSerializers/DelaySerializer.cpp index 4922042..6148632 100644 --- a/Swiften/Serializer/PayloadSerializers/DelaySerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/DelaySerializer.cpp @@ -4,12 +4,14 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/DelaySerializer.h" +#include <Swiften/Serializer/PayloadSerializers/DelaySerializer.h> #include <boost/shared_ptr.hpp> +#include <boost/date_time/posix_time/posix_time.hpp> #include <Swiften/Base/String.h> -#include "Swiften/Serializer/XML/XMLElement.h" +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Base/DateTime.h> namespace Swift { @@ -21,16 +23,8 @@ std::string DelaySerializer::serializePayload(boost::shared_ptr<Delay> delay) c if (delay->getFrom()) { delayElement.setAttribute("from", delay->getFrom()->toString()); } - std::string stampString = boostPTimeToXEP0082(delay->getStamp()); - delayElement.setAttribute("stamp", stampString); + delayElement.setAttribute("stamp", dateTimeToString(delay->getStamp())); return delayElement.serialize(); } -std::string DelaySerializer::boostPTimeToXEP0082(const boost::posix_time::ptime& time) { - std::string stampString = std::string(boost::posix_time::to_iso_extended_string(time)); - String::replaceAll(stampString, ',', "."); - stampString += "Z"; - return stampString; -} - } diff --git a/Swiften/Serializer/PayloadSerializers/DelaySerializer.h b/Swiften/Serializer/PayloadSerializers/DelaySerializer.h index c37dc02..06c7665 100644 --- a/Swiften/Serializer/PayloadSerializers/DelaySerializer.h +++ b/Swiften/Serializer/PayloadSerializers/DelaySerializer.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/Delay.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/Delay.h> namespace Swift { class DelaySerializer : public GenericPayloadSerializer<Delay> { @@ -15,7 +15,6 @@ namespace Swift { DelaySerializer(); virtual std::string serializePayload(boost::shared_ptr<Delay>) const; - static std::string boostPTimeToXEP0082(const boost::posix_time::ptime& time); }; } diff --git a/Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.cpp b/Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.cpp index 65b0a38..e2c6f59 100644 --- a/Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.cpp @@ -4,14 +4,14 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Base/foreach.h" -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/XML/XMLRawTextNode.h" -#include "Swiften/Serializer/PayloadSerializers/FormSerializer.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> +#include <Swiften/Serializer/PayloadSerializers/FormSerializer.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h b/Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h index 46e7ce2..3e028e1 100644 --- a/Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h @@ -4,11 +4,10 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_DiscoInfoSerializer_H -#define SWIFTEN_DiscoInfoSerializer_H +#pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/DiscoInfo.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/DiscoInfo.h> namespace Swift { class DiscoInfoSerializer : public GenericPayloadSerializer<DiscoInfo> { @@ -18,5 +17,3 @@ namespace Swift { virtual std::string serializePayload(boost::shared_ptr<DiscoInfo>) const; }; } - -#endif diff --git a/Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.cpp b/Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.cpp index cb1b7c1..dd52b70 100644 --- a/Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.cpp @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Base/foreach.h" -#include "Swiften/Serializer/XML/XMLElement.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.h b/Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.h index 3b00a17..a8785c2 100644 --- a/Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/DiscoItems.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/DiscoItems.h> namespace Swift { class DiscoItemsSerializer : public GenericPayloadSerializer<DiscoItems> { diff --git a/Swiften/Serializer/PayloadSerializers/ErrorSerializer.cpp b/Swiften/Serializer/PayloadSerializers/ErrorSerializer.cpp index 15d13d7..e3bfd54 100644 --- a/Swiften/Serializer/PayloadSerializers/ErrorSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/ErrorSerializer.cpp @@ -4,8 +4,8 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/ErrorSerializer.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" +#include <Swiften/Serializer/PayloadSerializers/ErrorSerializer.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/ErrorSerializer.h b/Swiften/Serializer/PayloadSerializers/ErrorSerializer.h index 7fc4dad..d06efc8 100644 --- a/Swiften/Serializer/PayloadSerializers/ErrorSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/ErrorSerializer.h @@ -4,11 +4,10 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_ErrorSerializer_H -#define SWIFTEN_ErrorSerializer_H +#pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/ErrorPayload.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/ErrorPayload.h> namespace Swift { class ErrorSerializer : public GenericPayloadSerializer<ErrorPayload> { @@ -18,5 +17,3 @@ namespace Swift { virtual std::string serializePayload(boost::shared_ptr<ErrorPayload> error) const; }; } - -#endif diff --git a/Swiften/Serializer/PayloadSerializers/FormSerializer.cpp b/Swiften/Serializer/PayloadSerializers/FormSerializer.cpp index 53b4241..7a6bb79 100644 --- a/Swiften/Serializer/PayloadSerializers/FormSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/FormSerializer.cpp @@ -4,16 +4,17 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/FormSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/FormSerializer.h> #include <boost/shared_ptr.hpp> #include <iostream> #include <string> -#include "Swiften/Base/String.h" -#include "Swiften/Base/foreach.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" -#include "Swiften/Serializer/XML/XMLRawTextNode.h" +#include <Swiften/Base/String.h> +#include <Swiften/Base/Algorithm.h> +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> using namespace Swift; @@ -129,14 +130,6 @@ boost::shared_ptr<XMLElement> FormSerializer::fieldToXML(boost::shared_ptr<FormF fieldType = "text-multi"; multiLineify(boost::dynamic_pointer_cast<TextMultiFormField>(field)->getValue(), "value", fieldElement); } - else if (boost::dynamic_pointer_cast<UntypedFormField>(field)) { - std::vector<std::string> lines = boost::dynamic_pointer_cast<UntypedFormField>(field)->getValue(); - foreach(const std::string& line, lines) { - boost::shared_ptr<XMLElement> valueElement(new XMLElement("value")); - valueElement->addNode(XMLTextNode::create(line)); - fieldElement->addNode(valueElement); - } - } else { assert(false); } @@ -162,7 +155,7 @@ boost::shared_ptr<XMLElement> FormSerializer::fieldToXML(boost::shared_ptr<FormF void FormSerializer::multiLineify(const std::string& text, const std::string& elementName, boost::shared_ptr<XMLElement> element) const { std::string unRdText(text); - unRdText.erase(std::remove(unRdText.begin(), unRdText.end(), '\r'), unRdText.end()); + erase(unRdText, '\r'); std::vector<std::string> lines = String::split(unRdText, '\n'); foreach (std::string line, lines) { boost::shared_ptr<XMLElement> lineElement(new XMLElement(elementName)); diff --git a/Swiften/Serializer/PayloadSerializers/FormSerializer.h b/Swiften/Serializer/PayloadSerializers/FormSerializer.h index 86c8dee..43db9e8 100644 --- a/Swiften/Serializer/PayloadSerializers/FormSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/FormSerializer.h @@ -6,10 +6,10 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/Form.h" -#include "Swiften/Elements/FormField.h" -#include "Swiften/Serializer/XML/XMLElement.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/Form.h> +#include <Swiften/Elements/FormField.h> +#include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { class FormSerializer : public GenericPayloadSerializer<Form> { diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp index 1bbcbf2..f3e22d2 100644 --- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp +++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp @@ -4,42 +4,61 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h" -#include "Swiften/Base/foreach.h" -#include "Swiften/Serializer/PayloadSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/IBBSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/BodySerializer.h" -#include "Swiften/Serializer/PayloadSerializers/SubjectSerializer.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/MUCUserPayloadSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.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/DiscoItemsSerializer.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/StreamInitiationSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/BytestreamsSerializer.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" -#include "Swiften/Serializer/PayloadSerializers/DelaySerializer.h" -#include "Swiften/Serializer/PayloadSerializers/FormSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/CommandSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/InBandRegistrationPayloadSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/NicknameSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h> +#include <Swiften/Base/foreach.h> +#include <Swiften/Elements/BlockPayload.h> +#include <Swiften/Elements/UnblockPayload.h> +#include <Swiften/Elements/BlockListPayload.h> +#include <Swiften/Serializer/PayloadSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/IBBSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/BodySerializer.h> +#include <Swiften/Serializer/PayloadSerializers/BlockSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/SubjectSerializer.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/RosterItemExchangeSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/MUCUserPayloadSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/MUCAdminPayloadSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/MUCDestroyPayloadSerializer.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/DiscoItemsSerializer.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/StreamInitiationSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/BytestreamsSerializer.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> +#include <Swiften/Serializer/PayloadSerializers/DelaySerializer.h> +#include <Swiften/Serializer/PayloadSerializers/FormSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/CommandSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/InBandRegistrationPayloadSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/NicknameSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/ReplaceSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/LastSerializer.h> + +#include <Swiften/Serializer/PayloadSerializers/StreamInitiationFileInfoSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/JingleContentPayloadSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/JingleFileTransferDescriptionSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/JingleFileTransferHashSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/JingleFileTransferReceivedSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/JingleIBBTransportPayloadSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/JingleS5BTransportPayloadSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/JinglePayloadSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/S5BProxyRequestSerializer.h> namespace Swift { @@ -51,15 +70,21 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() { serializers_.push_back(new PrioritySerializer()); serializers_.push_back(new ErrorSerializer()); serializers_.push_back(new RosterSerializer()); + serializers_.push_back(new RosterItemExchangeSerializer()); serializers_.push_back(new MUCPayloadSerializer()); - serializers_.push_back(new MUCUserPayloadSerializer()); + serializers_.push_back(new MUCDestroyPayloadSerializer()); + serializers_.push_back(new MUCAdminPayloadSerializer()); serializers_.push_back(new MUCOwnerPayloadSerializer(this)); + serializers_.push_back(new MUCUserPayloadSerializer(this)); serializers_.push_back(new SoftwareVersionSerializer()); serializers_.push_back(new StatusSerializer()); serializers_.push_back(new StatusShowSerializer()); serializers_.push_back(new DiscoInfoSerializer()); serializers_.push_back(new DiscoItemsSerializer()); serializers_.push_back(new CapsInfoSerializer()); + serializers_.push_back(new BlockSerializer<BlockPayload>("block")); + serializers_.push_back(new BlockSerializer<UnblockPayload>("unblock")); + serializers_.push_back(new BlockSerializer<BlockListPayload>("blocklist")); serializers_.push_back(new ResourceBindSerializer()); serializers_.push_back(new StartSessionSerializer()); serializers_.push_back(new SecurityLabelSerializer()); @@ -77,6 +102,19 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() { serializers_.push_back(new InBandRegistrationPayloadSerializer()); serializers_.push_back(new NicknameSerializer()); serializers_.push_back(new SearchPayloadSerializer()); + serializers_.push_back(new ReplaceSerializer()); + serializers_.push_back(new LastSerializer()); + + serializers_.push_back(new StreamInitiationFileInfoSerializer()); + serializers_.push_back(new JingleContentPayloadSerializer()); + serializers_.push_back(new JingleFileTransferDescriptionSerializer()); + serializers_.push_back(new JingleFileTransferHashSerializer()); + serializers_.push_back(new JingleFileTransferReceivedSerializer()); + serializers_.push_back(new JingleIBBTransportPayloadSerializer()); + serializers_.push_back(new JingleS5BTransportPayloadSerializer()); + serializers_.push_back(new JinglePayloadSerializer(this)); + serializers_.push_back(new S5BProxyRequestSerializer()); + foreach(PayloadSerializer* serializer, serializers_) { addSerializer(serializer); } diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h index bf86f27..bfe7d76 100644 --- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h +++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h @@ -4,12 +4,11 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_FULLPAYLOADSERIALIZERCOLLECTION_H -#define SWIFTEN_FULLPAYLOADSERIALIZERCOLLECTION_H +#pragma once #include <vector> -#include "Swiften/Serializer/PayloadSerializerCollection.h" +#include <Swiften/Serializer/PayloadSerializerCollection.h> namespace Swift { class FullPayloadSerializerCollection : public PayloadSerializerCollection { @@ -21,5 +20,3 @@ namespace Swift { std::vector<PayloadSerializer*> serializers_; }; } - -#endif diff --git a/Swiften/Serializer/PayloadSerializers/IBBSerializer.cpp b/Swiften/Serializer/PayloadSerializers/IBBSerializer.cpp index 7ac4103..f3dad80 100644 --- a/Swiften/Serializer/PayloadSerializers/IBBSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/IBBSerializer.cpp @@ -4,16 +4,15 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/IBBSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/IBBSerializer.h> #include <boost/shared_ptr.hpp> #include <boost/lexical_cast.hpp> -#include "Swiften/Base/foreach.h" -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" -#include "Swiften/Serializer/PayloadSerializerCollection.h" -#include "Swiften/StringCodecs/Base64.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> +#include <Swiften/StringCodecs/Base64.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/IBBSerializer.h b/Swiften/Serializer/PayloadSerializers/IBBSerializer.h index d750f6f..229f131 100644 --- a/Swiften/Serializer/PayloadSerializers/IBBSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/IBBSerializer.h @@ -6,12 +6,10 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/IBB.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/IBB.h> namespace Swift { - class PayloadSerializerCollection; - class IBBSerializer : public GenericPayloadSerializer<IBB> { public: IBBSerializer(); diff --git a/Swiften/Serializer/PayloadSerializers/InBandRegistrationPayloadSerializer.cpp b/Swiften/Serializer/PayloadSerializers/InBandRegistrationPayloadSerializer.cpp index e4ae11f..12b1bb5 100644 --- a/Swiften/Serializer/PayloadSerializers/InBandRegistrationPayloadSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/InBandRegistrationPayloadSerializer.cpp @@ -4,14 +4,14 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/InBandRegistrationPayloadSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/InBandRegistrationPayloadSerializer.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Base/foreach.h" -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/XML/XMLRawTextNode.h" -#include "Swiften/Serializer/PayloadSerializers/FormSerializer.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> +#include <Swiften/Serializer/PayloadSerializers/FormSerializer.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/InBandRegistrationPayloadSerializer.h b/Swiften/Serializer/PayloadSerializers/InBandRegistrationPayloadSerializer.h index 45d49ea..3b88590 100644 --- a/Swiften/Serializer/PayloadSerializers/InBandRegistrationPayloadSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/InBandRegistrationPayloadSerializer.h @@ -7,12 +7,10 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/InBandRegistrationPayload.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/InBandRegistrationPayload.h> namespace Swift { - class PayloadSerializerCollection; - class InBandRegistrationPayloadSerializer : public GenericPayloadSerializer<InBandRegistrationPayload> { public: InBandRegistrationPayloadSerializer(); diff --git a/Swiften/Serializer/PayloadSerializers/JingleContentPayloadSerializer.cpp b/Swiften/Serializer/PayloadSerializers/JingleContentPayloadSerializer.cpp new file mode 100644 index 0000000..90bd940 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/JingleContentPayloadSerializer.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2011 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Serializer/PayloadSerializers/JingleContentPayloadSerializer.h> + +#include <boost/shared_ptr.hpp> +#include <boost/smart_ptr/make_shared.hpp> +#include <boost/smart_ptr/intrusive_ptr.hpp> + +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLNode.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> + +#include <Swiften/Serializer/PayloadSerializers/JingleFileTransferDescriptionSerializer.h> + +#include <Swiften/Serializer/PayloadSerializers/JingleIBBTransportPayloadSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/JingleS5BTransportPayloadSerializer.h> + +#include "Swiften/FileTransfer/JingleTransport.h" + +namespace Swift { + +JingleContentPayloadSerializer::JingleContentPayloadSerializer() { +} + +std::string JingleContentPayloadSerializer::serializePayload(boost::shared_ptr<JingleContentPayload> payload) const { + XMLElement payloadXML("content"); + payloadXML.setAttribute("creator", creatorToString(payload->getCreator())); + payloadXML.setAttribute("name", payload->getName()); + + if (!payload->getDescriptions().empty()) { + // JingleFileTransferDescription + JingleFileTransferDescriptionSerializer ftSerializer; + JingleFileTransferDescription::ref filetransfer; + + foreach(JingleDescription::ref desc, payload->getDescriptions()) { + if ((filetransfer = boost::dynamic_pointer_cast<JingleFileTransferDescription>(desc))) { + payloadXML.addNode(boost::make_shared<XMLRawTextNode>(ftSerializer.serializePayload(filetransfer))); + } + } + } + + if (!payload->getTransports().empty()) { + // JingleIBBTransportPayload + JingleIBBTransportPayloadSerializer ibbSerializer; + JingleIBBTransportPayload::ref ibb; + + // JingleS5BTransportPayload + JingleS5BTransportPayloadSerializer s5bSerializer; + JingleS5BTransportPayload::ref s5b; + + foreach(JingleTransportPayload::ref transport, payload->getTransports()) { + if ((ibb = boost::dynamic_pointer_cast<JingleIBBTransportPayload>(transport))) { + payloadXML.addNode(boost::make_shared<XMLRawTextNode>(ibbSerializer.serializePayload(ibb))); + } else if ((s5b = boost::dynamic_pointer_cast<JingleS5BTransportPayload>(transport))) { + payloadXML.addNode(boost::make_shared<XMLRawTextNode>(s5bSerializer.serializePayload(s5b))); + } + } + } + return payloadXML.serialize(); +} + +std::string JingleContentPayloadSerializer::creatorToString(JingleContentPayload::Creator creator) const { + switch(creator) { + case JingleContentPayload::InitiatorCreator: + return "initiator"; + case JingleContentPayload::ResponderCreator: + return "responder"; + case JingleContentPayload::UnknownCreator: + std::cerr << "Serializing unknown creator value." << std::endl; + return "ERROR ERROR ERROR"; + } + assert(false); +} +} diff --git a/Swiften/Serializer/PayloadSerializers/JingleContentPayloadSerializer.h b/Swiften/Serializer/PayloadSerializers/JingleContentPayloadSerializer.h new file mode 100644 index 0000000..2de0064 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/JingleContentPayloadSerializer.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2011 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + + +#pragma once + +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/JingleContentPayload.h> + +namespace Swift { + class PayloadSerializerCollection; + + class JingleContentPayloadSerializer : public GenericPayloadSerializer<JingleContentPayload> { + public: + JingleContentPayloadSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<JingleContentPayload>) const; + + private: + std::string creatorToString(JingleContentPayload::Creator creator) const; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/JingleFileTransferDescriptionSerializer.cpp b/Swiften/Serializer/PayloadSerializers/JingleFileTransferDescriptionSerializer.cpp new file mode 100644 index 0000000..16337ff --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/JingleFileTransferDescriptionSerializer.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2011 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Serializer/PayloadSerializers/JingleFileTransferDescriptionSerializer.h> + +#include <boost/shared_ptr.hpp> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLNode.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> + +#include <Swiften/Serializer/PayloadSerializers/StreamInitiationFileInfoSerializer.h> + +namespace Swift { + +JingleFileTransferDescriptionSerializer::JingleFileTransferDescriptionSerializer() { +} + +std::string JingleFileTransferDescriptionSerializer::serializePayload(boost::shared_ptr<JingleFileTransferDescription> payload) const { + XMLElement description("description", "urn:xmpp:jingle:apps:file-transfer:3"); + StreamInitiationFileInfoSerializer fileInfoSerializer; + if (!payload->getOffers().empty()) { + boost::shared_ptr<XMLElement> offers = boost::make_shared<XMLElement>("offer"); + foreach(const StreamInitiationFileInfo &fileInfo, payload->getOffers()) { + boost::shared_ptr<XMLRawTextNode> fileInfoXML = boost::make_shared<XMLRawTextNode>(fileInfoSerializer.serialize(boost::make_shared<StreamInitiationFileInfo>(fileInfo))); + offers->addNode(fileInfoXML); + } + description.addNode(offers); + } + if (!payload->getRequests().empty()) { + boost::shared_ptr<XMLElement> requests = boost::make_shared<XMLElement>("request"); + foreach(const StreamInitiationFileInfo &fileInfo, payload->getRequests()) { + boost::shared_ptr<XMLRawTextNode> fileInfoXML = boost::make_shared<XMLRawTextNode>(fileInfoSerializer.serialize(boost::make_shared<StreamInitiationFileInfo>(fileInfo))); + requests->addNode(fileInfoXML); + } + description.addNode(requests); + } + return description.serialize(); +} + +} diff --git a/Swiften/Serializer/PayloadSerializers/JingleFileTransferDescriptionSerializer.h b/Swiften/Serializer/PayloadSerializers/JingleFileTransferDescriptionSerializer.h new file mode 100644 index 0000000..5131435 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/JingleFileTransferDescriptionSerializer.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2011 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + + +#pragma once + +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/JingleFileTransferDescription.h> + + + +namespace Swift { + class PayloadSerializerCollection; + class XMLElement; + + class JingleFileTransferDescriptionSerializer : public GenericPayloadSerializer<JingleFileTransferDescription> { + public: + JingleFileTransferDescriptionSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<JingleFileTransferDescription>) const; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/JingleFileTransferHashSerializer.cpp b/Swiften/Serializer/PayloadSerializers/JingleFileTransferHashSerializer.cpp new file mode 100644 index 0000000..2bd3afa --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/JingleFileTransferHashSerializer.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2011 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Serializer/PayloadSerializers/JingleFileTransferHashSerializer.h> + +#include <string> +#include <map> + +#include <boost/shared_ptr.hpp> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLNode.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> + + +namespace Swift { + +JingleFileTransferHashSerializer::JingleFileTransferHashSerializer() { +} + +std::string JingleFileTransferHashSerializer::serializePayload(boost::shared_ptr<JingleFileTransferHash> payload) const { + // code for version urn:xmpp:jingle:apps:file-transfer:2 + //XMLElement hash("hash", "urn:xmpp:jingle:apps:file-transfer:info:2", payload->getHash()); + + // code for version urn:xmpp:jingle:apps:file-transfer:3 + XMLElement checksum("checksum", "urn:xmpp:jingle:apps:file-transfer:3"); + boost::shared_ptr<XMLElement> file = boost::make_shared<XMLElement>("file"); + checksum.addNode(file); + boost::shared_ptr<XMLElement> hashes = boost::make_shared<XMLElement>("hashes", "urn:xmpp:hashes:0"); + file->addNode(hashes); + foreach(const JingleFileTransferHash::HashesMap::value_type& pair, payload->getHashes()) { + boost::shared_ptr<XMLElement> hash = boost::make_shared<XMLElement>("hash", "", pair.second); + hash->setAttribute("algo", pair.first); + hashes->addNode(hash); + } + + return checksum.serialize(); +} + +} diff --git a/Swiften/Serializer/PayloadSerializers/JingleFileTransferHashSerializer.h b/Swiften/Serializer/PayloadSerializers/JingleFileTransferHashSerializer.h new file mode 100644 index 0000000..7fa6ac5 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/JingleFileTransferHashSerializer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2011 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + + +#pragma once + +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/JingleFileTransferHash.h> + +namespace Swift { + class PayloadSerializerCollection; + class XMLElement; + + class JingleFileTransferHashSerializer : public GenericPayloadSerializer<JingleFileTransferHash> { + public: + JingleFileTransferHashSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<JingleFileTransferHash>) const; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/JingleFileTransferReceivedSerializer.cpp b/Swiften/Serializer/PayloadSerializers/JingleFileTransferReceivedSerializer.cpp new file mode 100644 index 0000000..40be70e --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/JingleFileTransferReceivedSerializer.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2011 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Serializer/PayloadSerializers/JingleFileTransferReceivedSerializer.h> + +#include <boost/shared_ptr.hpp> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLNode.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> + +#include <Swiften/Serializer/XML/XMLRawTextNode.h> + +namespace Swift { + +JingleFileTransferReceivedSerializer::JingleFileTransferReceivedSerializer() { +} + +std::string JingleFileTransferReceivedSerializer::serializePayload(boost::shared_ptr<JingleFileTransferReceived> payload) const { + XMLElement receivedElement("received", "urn:xmpp:jingle:apps:file-transfer:3"); + XMLElement::ref fileElement = boost::make_shared<XMLElement>("file", "http://jabber.org/protocol/si/profile/file-transfer"); + fileElement->setAttribute("hash", payload->getFileInfo().getHash()); + if (payload->getFileInfo().getAlgo() != "md5") { + fileElement->setAttribute("algo", payload->getFileInfo().getAlgo()); + } + receivedElement.addNode(fileElement); + return receivedElement.serialize(); +} + +} diff --git a/Swiften/Serializer/PayloadSerializers/JingleFileTransferReceivedSerializer.h b/Swiften/Serializer/PayloadSerializers/JingleFileTransferReceivedSerializer.h new file mode 100644 index 0000000..4151dd0 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/JingleFileTransferReceivedSerializer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2011 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + + +#pragma once + +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/JingleFileTransferReceived.h> + +namespace Swift { + class PayloadSerializerCollection; + class XMLElement; + + class JingleFileTransferReceivedSerializer : public GenericPayloadSerializer<JingleFileTransferReceived> { + public: + JingleFileTransferReceivedSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<JingleFileTransferReceived>) const; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/JingleIBBTransportPayloadSerializer.cpp b/Swiften/Serializer/PayloadSerializers/JingleIBBTransportPayloadSerializer.cpp new file mode 100644 index 0000000..029a5b4 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/JingleIBBTransportPayloadSerializer.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2011 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Serializer/PayloadSerializers/JingleIBBTransportPayloadSerializer.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/Serializer/XML/XMLNode.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> + +namespace Swift { + +JingleIBBTransportPayloadSerializer::JingleIBBTransportPayloadSerializer() { +} + +std::string JingleIBBTransportPayloadSerializer::serializePayload(boost::shared_ptr<JingleIBBTransportPayload> payload) const { + XMLElement payloadXML("transport", "urn:xmpp:jingle:transports:ibb:1"); + payloadXML.setAttribute("block-size", boost::lexical_cast<std::string>(payload->getBlockSize())); + payloadXML.setAttribute("sid", payload->getSessionID()); + + return payloadXML.serialize(); +} + +} diff --git a/Swiften/Serializer/PayloadSerializers/JingleIBBTransportPayloadSerializer.h b/Swiften/Serializer/PayloadSerializers/JingleIBBTransportPayloadSerializer.h new file mode 100644 index 0000000..ac9cba9 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/JingleIBBTransportPayloadSerializer.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2011 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + + +#pragma once + +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/JingleIBBTransportPayload.h> + + + +namespace Swift { + class PayloadSerializerCollection; + class XMLElement; + + class JingleIBBTransportPayloadSerializer : public GenericPayloadSerializer<JingleIBBTransportPayload> { + public: + JingleIBBTransportPayloadSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<JingleIBBTransportPayload>) const; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/JinglePayloadSerializer.cpp b/Swiften/Serializer/PayloadSerializers/JinglePayloadSerializer.cpp new file mode 100644 index 0000000..25d35ff --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/JinglePayloadSerializer.cpp @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2011 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Serializer/PayloadSerializers/JinglePayloadSerializer.h> + +#include <boost/shared_ptr.hpp> +#include <boost/smart_ptr/make_shared.hpp> +#include <boost/smart_ptr/intrusive_ptr.hpp> + +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLNode.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> +#include <Swiften/Serializer/PayloadSerializers/JingleContentPayloadSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/JingleFileTransferHashSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/JingleFileTransferReceivedSerializer.h> + +#include <Swiften/Serializer/PayloadSerializerCollection.h> + +#include <Swiften/Elements/JinglePayload.h> +#include <Swiften/Elements/JingleContentPayload.h> +#include <Swiften/Elements/JingleIBBTransportPayload.h> +#include <Swiften/Elements/JingleFileTransferDescription.h> +#include <Swiften/Elements/JingleFileTransferHash.h> +#include <Swiften/Elements/JingleFileTransferReceived.h> + +namespace Swift { + +JinglePayloadSerializer::JinglePayloadSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +std::string JinglePayloadSerializer::serializePayload(boost::shared_ptr<JinglePayload> payload) const { + XMLElement jinglePayload("jingle", "urn:xmpp:jingle:1"); + jinglePayload.setAttribute("action", actionToString(payload->getAction())); + jinglePayload.setAttribute("initiator", payload->getInitiator()); + jinglePayload.setAttribute("sid", payload->getSessionID()); + + if (!payload->getPayloads().empty()) { + foreach(boost::shared_ptr<Payload> subPayload, payload->getPayloads()) { + PayloadSerializer* serializer = serializers->getPayloadSerializer(subPayload); + if (serializer) { + jinglePayload.addNode(boost::shared_ptr<XMLRawTextNode>(new XMLRawTextNode(serializer->serialize(subPayload)))); + } + } + } + + if (payload->getReason().is_initialized()) { + boost::shared_ptr<XMLElement> reason = boost::make_shared<XMLElement>("reason"); + reason->addNode(boost::make_shared<XMLElement>(reasonTypeToString(payload->getReason()->type))); + if (!payload->getReason()->text.empty()) { + reason->addNode(boost::make_shared<XMLElement>("desc", "", payload->getReason()->text)); + } + jinglePayload.addNode(reason); + } + + return jinglePayload.serialize(); +} + +std::string JinglePayloadSerializer::actionToString(JinglePayload::Action action) const { + switch(action) { + case JinglePayload::ContentAccept: + return "content-accept"; + case JinglePayload::ContentAdd: + return "content-add"; + case JinglePayload::ContentModify: + return "content-modify"; + case JinglePayload::ContentReject: + return "content-reject"; + case JinglePayload::ContentRemove: + return "content-remove"; + case JinglePayload::DescriptionInfo: + return "description-info"; + case JinglePayload::SecurityInfo: + return "security-info"; + case JinglePayload::SessionAccept: + return "session-accept"; + case JinglePayload::SessionInfo: + return "session-info"; + case JinglePayload::SessionInitiate: + return "session-initiate"; + case JinglePayload::SessionTerminate: + return "session-terminate"; + case JinglePayload::TransportAccept: + return "transport-accept"; + case JinglePayload::TransportInfo: + return "transport-info"; + case JinglePayload::TransportReject: + return "transport-reject"; + case JinglePayload::TransportReplace: + return "transport-replace"; + case JinglePayload::UnknownAction: + std::cerr << "Serializing unknown action value." << std::endl; + return ""; + } + assert(false); +} + +std::string JinglePayloadSerializer::reasonTypeToString(JinglePayload::Reason::Type type) const { + switch(type) { + case JinglePayload::Reason::UnknownType: + std::cerr << "Unknown jingle reason type!" << std::endl; + return ""; + case JinglePayload::Reason::AlternativeSession: + return "alternative-session"; + case JinglePayload::Reason::Busy: + return "busy"; + case JinglePayload::Reason::Cancel: + return "cancel"; + case JinglePayload::Reason::ConnectivityError: + return "connectivity-error"; + case JinglePayload::Reason::Decline: + return "decline"; + case JinglePayload::Reason::Expired: + return "expired"; + case JinglePayload::Reason::FailedApplication: + return "failed-application"; + case JinglePayload::Reason::FailedTransport: + return "failed-transport"; + case JinglePayload::Reason::GeneralError: + return "general-error"; + case JinglePayload::Reason::Gone: + return "gone"; + case JinglePayload::Reason::IncompatibleParameters: + return "incompatible-parameters"; + case JinglePayload::Reason::MediaError: + return "media-error"; + case JinglePayload::Reason::SecurityError: + return "security-error"; + case JinglePayload::Reason::Success: + return "success"; + case JinglePayload::Reason::Timeout: + return "timeout"; + case JinglePayload::Reason::UnsupportedApplications: + return "unsupported-applications"; + case JinglePayload::Reason::UnsupportedTransports: + return "unsupported-transports"; + } + assert(false); +} + +} diff --git a/Swiften/Serializer/PayloadSerializers/JinglePayloadSerializer.h b/Swiften/Serializer/PayloadSerializers/JinglePayloadSerializer.h new file mode 100644 index 0000000..ccdb6d0 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/JinglePayloadSerializer.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2011 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + + +#pragma once + +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/JinglePayload.h> + +namespace Swift { + class PayloadSerializerCollection; + class XMLElement; + + class JinglePayloadSerializer : public GenericPayloadSerializer<JinglePayload> { + public: + JinglePayloadSerializer(PayloadSerializerCollection*); + + virtual std::string serializePayload(boost::shared_ptr<JinglePayload>) const; + + private: + std::string actionToString(JinglePayload::Action action) const; + std::string reasonTypeToString(JinglePayload::Reason::Type type) const; + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/JingleS5BTransportPayloadSerializer.cpp b/Swiften/Serializer/PayloadSerializers/JingleS5BTransportPayloadSerializer.cpp new file mode 100644 index 0000000..c5b40d5 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/JingleS5BTransportPayloadSerializer.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2011 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Serializer/PayloadSerializers/JingleS5BTransportPayloadSerializer.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/Serializer/XML/XMLNode.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> +#include <Swiften/Base/Log.h> + +namespace Swift { + +JingleS5BTransportPayloadSerializer::JingleS5BTransportPayloadSerializer() { +} + +std::string JingleS5BTransportPayloadSerializer::serializePayload(boost::shared_ptr<JingleS5BTransportPayload> payload) const { + XMLElement payloadXML("transport", "urn:xmpp:jingle:transports:s5b:1"); + payloadXML.setAttribute("sid", payload->getSessionID()); + payloadXML.setAttribute("mode", modeToString(payload->getMode())); + + foreach(JingleS5BTransportPayload::Candidate candidate, payload->getCandidates()) { + boost::shared_ptr<XMLElement> candidateXML = boost::make_shared<XMLElement>("candidate"); + candidateXML->setAttribute("cid", candidate.cid); + candidateXML->setAttribute("host", candidate.hostPort.getAddress().toString()); + candidateXML->setAttribute("jid", candidate.jid.toString()); + candidateXML->setAttribute("port", boost::lexical_cast<std::string>(candidate.hostPort.getPort())); + candidateXML->setAttribute("priority", boost::lexical_cast<std::string>(candidate.priority)); + candidateXML->setAttribute("type", typeToString(candidate.type)); + payloadXML.addNode(candidateXML); + } + + if (payload->hasCandidateError()) { + payloadXML.addNode(boost::make_shared<XMLElement>("candidate-error")); + } + if (payload->hasProxyError()) { + payloadXML.addNode(boost::make_shared<XMLElement>("proxy-error")); + } + + if (!payload->getActivated().empty()) { + boost::shared_ptr<XMLElement> activatedXML = boost::make_shared<XMLElement>("activated"); + activatedXML->setAttribute("cid", payload->getActivated()); + payloadXML.addNode(activatedXML); + } + if (!payload->getCandidateUsed().empty()) { + boost::shared_ptr<XMLElement> candusedXML = boost::make_shared<XMLElement>("candidate-used"); + candusedXML->setAttribute("cid", payload->getCandidateUsed()); + payloadXML.addNode(candusedXML); + } + + return payloadXML.serialize(); +} + +std::string JingleS5BTransportPayloadSerializer::modeToString(JingleS5BTransportPayload::Mode mode) const { + switch(mode) { + case JingleS5BTransportPayload::TCPMode: + return "tcp"; + case JingleS5BTransportPayload::UDPMode: + return "udp"; + } + assert(false); +} + +std::string JingleS5BTransportPayloadSerializer::typeToString(JingleS5BTransportPayload::Candidate::Type type) const { + switch(type) { + case JingleS5BTransportPayload::Candidate::AssistedType: + return "assisted"; + case JingleS5BTransportPayload::Candidate::DirectType: + return "direct"; + case JingleS5BTransportPayload::Candidate::ProxyType: + return "proxy"; + case JingleS5BTransportPayload::Candidate::TunnelType: + return "tunnel"; + } + assert(false); +} + +} diff --git a/Swiften/Serializer/PayloadSerializers/JingleS5BTransportPayloadSerializer.h b/Swiften/Serializer/PayloadSerializers/JingleS5BTransportPayloadSerializer.h new file mode 100644 index 0000000..210688d --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/JingleS5BTransportPayloadSerializer.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2011 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + + +#pragma once + +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/JingleS5BTransportPayload.h> + +namespace Swift { + class PayloadSerializerCollection; + class XMLElement; + + class JingleS5BTransportPayloadSerializer : public GenericPayloadSerializer<JingleS5BTransportPayload> { + public: + JingleS5BTransportPayloadSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<JingleS5BTransportPayload>) const; + + private: + std::string modeToString(JingleS5BTransportPayload::Mode) const; + std::string typeToString(JingleS5BTransportPayload::Candidate::Type) const; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/LastSerializer.h b/Swiften/Serializer/PayloadSerializers/LastSerializer.h new file mode 100644 index 0000000..e91d702 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/LastSerializer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/lexical_cast.hpp> + +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/Last.h> + +namespace Swift { + class LastSerializer : public GenericPayloadSerializer<Last> { + public: + LastSerializer() : GenericPayloadSerializer<Last>() {} + + virtual std::string serializePayload(boost::shared_ptr<Last> last) const { + return "<query xmlns='jabber:iq:last' seconds='" + boost::lexical_cast<std::string>(last->getSeconds()) + "'/>"; + } + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/MUCAdminPayloadSerializer.cpp b/Swiften/Serializer/PayloadSerializers/MUCAdminPayloadSerializer.cpp new file mode 100644 index 0000000..8758722 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/MUCAdminPayloadSerializer.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Serializer/PayloadSerializers/MUCAdminPayloadSerializer.h> + +#include <sstream> + +#include <boost/shared_ptr.hpp> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> +#include <Swiften/Serializer/PayloadSerializers/MUCItemSerializer.h> + + +namespace Swift { + +MUCAdminPayloadSerializer::MUCAdminPayloadSerializer() : GenericPayloadSerializer<MUCAdminPayload>() { +} + +std::string MUCAdminPayloadSerializer::serializePayload(boost::shared_ptr<MUCAdminPayload> payload) const { + XMLElement mucElement("query", "http://jabber.org/protocol/muc#admin"); + foreach (const MUCItem& item, payload->getItems()) { + mucElement.addNode(MUCItemSerializer::itemToElement(item)); + } + return mucElement.serialize(); +} + + +} diff --git a/Swiften/Serializer/PayloadSerializers/MUCAdminPayloadSerializer.h b/Swiften/Serializer/PayloadSerializers/MUCAdminPayloadSerializer.h new file mode 100644 index 0000000..e288cd7 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/MUCAdminPayloadSerializer.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/MUCAdminPayload.h> + +namespace Swift { + class MUCAdminPayloadSerializer : public GenericPayloadSerializer<MUCAdminPayload> { + public: + MUCAdminPayloadSerializer(); + std::string affiliationToString(MUCOccupant::Affiliation affiliation) const; + std::string roleToString(MUCOccupant::Role role) const; + + virtual std::string serializePayload(boost::shared_ptr<MUCAdminPayload> version) const; + }; +} + diff --git a/Swiften/Serializer/PayloadSerializers/MUCDestroyPayloadSerializer.cpp b/Swiften/Serializer/PayloadSerializers/MUCDestroyPayloadSerializer.cpp new file mode 100644 index 0000000..e78a381 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/MUCDestroyPayloadSerializer.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Serializer/PayloadSerializers/MUCDestroyPayloadSerializer.h> + +#include <boost/shared_ptr.hpp> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> + +namespace Swift { + +MUCDestroyPayloadSerializer::MUCDestroyPayloadSerializer() : GenericPayloadSerializer<MUCDestroyPayload>() { +} + +std::string MUCDestroyPayloadSerializer::serializePayload(boost::shared_ptr<MUCDestroyPayload> payload) const { + XMLElement mucElement("destroy", ""); + if (!payload->getReason().empty()) { + XMLElement::ref reason = boost::make_shared<XMLElement>("reason", ""); + reason->addNode(boost::make_shared<XMLTextNode>(payload->getReason())); + mucElement.addNode(reason); + } + if (payload->getNewVenue().isValid()) { + mucElement.setAttribute("jid", payload->getNewVenue().toString()); + } + return mucElement.serialize(); +} + + + + +} diff --git a/Swiften/Serializer/PayloadSerializers/MUCDestroyPayloadSerializer.h b/Swiften/Serializer/PayloadSerializers/MUCDestroyPayloadSerializer.h new file mode 100644 index 0000000..419a683 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/MUCDestroyPayloadSerializer.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/MUCDestroyPayload.h> + +namespace Swift { + class PayloadSerializerCollection; + class MUCDestroyPayloadSerializer : public GenericPayloadSerializer<MUCDestroyPayload> { + public: + MUCDestroyPayloadSerializer(); + virtual std::string serializePayload(boost::shared_ptr<MUCDestroyPayload> version) const; + }; +} + diff --git a/Swiften/Serializer/PayloadSerializers/MUCItemSerializer.h b/Swiften/Serializer/PayloadSerializers/MUCItemSerializer.h new file mode 100644 index 0000000..7cb662c --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/MUCItemSerializer.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/MUCItem.h> +#include <boost/smart_ptr/make_shared.hpp> + +namespace Swift { + class MUCItemSerializer { + public: + static std::string affiliationToString(MUCOccupant::Affiliation affiliation) { + std::string result; + switch (affiliation) { + case MUCOccupant::Owner: result = "owner"; break; + case MUCOccupant::Admin: result = "admin"; break; + case MUCOccupant::Member: result = "member"; break; + case MUCOccupant::Outcast: result = "outcast"; break; + case MUCOccupant::NoAffiliation: result = "none"; break; + default: assert(false); + } + return result; + } + + static std::string roleToString(MUCOccupant::Role role) { + std::string result; + switch (role) { + case MUCOccupant::Moderator: result = "moderator"; break; + case MUCOccupant::NoRole: result = "none"; break; + case MUCOccupant::Participant: result = "participant"; break; + case MUCOccupant::Visitor: result = "visitor"; break; + default: assert(false); + } + return result; + + } + + static boost::shared_ptr<XMLElement> itemToElement(const MUCItem& item) { + boost::shared_ptr<XMLElement> itemElement(new XMLElement("item")); + if (item.affiliation) { + itemElement->setAttribute("affiliation", affiliationToString(item.affiliation.get())); + } + if (item.role) { + itemElement->setAttribute("role", roleToString(item.role.get())); + } + if (item.realJID) { + itemElement->setAttribute("jid", item.realJID.get()); + } + if (item.nick) { + itemElement->setAttribute("nick", item.nick.get()); + } + if (item.actor) { + boost::shared_ptr<XMLElement> actorElement(new XMLElement("actor")); + actorElement->setAttribute("jid", item.actor->toString()); + itemElement->addNode(actorElement); + } + if (item.reason) { + boost::shared_ptr<XMLElement> reasonElement(new XMLElement("reason")); + reasonElement->addNode(boost::make_shared<XMLTextNode>(*item.reason)); + itemElement->addNode(reasonElement); + } + return itemElement; + } + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.cpp b/Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.cpp index db28514..f86b59e 100644 --- a/Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.cpp @@ -4,11 +4,11 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.h> -#include "Swiften/Serializer/PayloadSerializerCollection.h" -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/XML/XMLRawTextNode.h" +#include <Swiften/Serializer/PayloadSerializerCollection.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.h b/Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.h index 4808744..5e6913a 100644 --- a/Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/MUCOwnerPayload.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/MUCOwnerPayload.h> namespace Swift { class PayloadSerializerCollection; diff --git a/Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.cpp b/Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.cpp index d7e1613..7080e14 100644 --- a/Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.cpp @@ -4,9 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.h> -#include "Swiften/Serializer/XML/XMLElement.h" +#include <boost/lexical_cast.hpp> +#include <boost/date_time/posix_time/posix_time.hpp> + +#include <Swiften/Serializer/XML/XMLElement.h> #include <Swiften/Base/String.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.h b/Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.h index 7038e6e..4bf8d22 100644 --- a/Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/MUCPayload.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/MUCPayload.h> namespace Swift { class MUCPayloadSerializer : public GenericPayloadSerializer<MUCPayload> { diff --git a/Swiften/Serializer/PayloadSerializers/MUCUserPayloadSerializer.cpp b/Swiften/Serializer/PayloadSerializers/MUCUserPayloadSerializer.cpp index 50746a9..96fba90 100644 --- a/Swiften/Serializer/PayloadSerializers/MUCUserPayloadSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/MUCUserPayloadSerializer.cpp @@ -4,24 +4,26 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/MUCUserPayloadSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/MUCUserPayloadSerializer.h> #include <sstream> #include <boost/shared_ptr.hpp> -#include "Swiften/Base/foreach.h" -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" - +#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/PayloadSerializers/MUCItemSerializer.h> +#include <Swiften/Serializer/PayloadSerializerCollection.h> namespace Swift { -MUCUserPayloadSerializer::MUCUserPayloadSerializer() : GenericPayloadSerializer<MUCUserPayload>() { +MUCUserPayloadSerializer::MUCUserPayloadSerializer(PayloadSerializerCollection* serializers) : GenericPayloadSerializer<MUCUserPayload>(), serializers(serializers) { } std::string MUCUserPayloadSerializer::serializePayload(boost::shared_ptr<MUCUserPayload> payload) const { - XMLElement mucElement("x", "http://jabber.org/protocol/muc"); + XMLElement mucElement("x", "http://jabber.org/protocol/muc#user"); foreach (const MUCUserPayload::StatusCode statusCode, payload->getStatusCodes()) { boost::shared_ptr<XMLElement> statusElement(new XMLElement("status")); std::ostringstream code; @@ -29,46 +31,20 @@ std::string MUCUserPayloadSerializer::serializePayload(boost::shared_ptr<MUCUser statusElement->setAttribute("code", code.str()); mucElement.addNode(statusElement); } - foreach (const MUCUserPayload::Item item, payload->getItems()) { - boost::shared_ptr<XMLElement> itemElement(new XMLElement("item")); - itemElement->setAttribute("affiliation", affiliationToString(item.affiliation)); - itemElement->setAttribute("role", roleToString(item.role)); - if (item.realJID) { - itemElement->setAttribute("jid", item.realJID.get()); - } - if (item.nick) { - itemElement->setAttribute("nick", item.nick.get()); + foreach (const MUCItem& item, payload->getItems()) { + mucElement.addNode(MUCItemSerializer::itemToElement(item)); + } + boost::shared_ptr<Payload> childPayload = payload->getPayload(); + if (childPayload) { + PayloadSerializer* serializer = serializers->getPayloadSerializer(childPayload); + if (serializer) { + mucElement.addNode(boost::shared_ptr<XMLRawTextNode>(new XMLRawTextNode(serializer->serialize(childPayload)))); } - mucElement.addNode(itemElement); } return mucElement.serialize(); } -std::string MUCUserPayloadSerializer::affiliationToString(MUCOccupant::Affiliation affiliation) const { - std::string result; - switch (affiliation) { - case MUCOccupant::Owner: result = "owner"; break; - case MUCOccupant::Admin: result = "admin"; break; - case MUCOccupant::Member: result = "member"; break; - case MUCOccupant::Outcast: result = "outcast"; break; - case MUCOccupant::NoAffiliation: result = "none"; break; - default: assert(false); - } - return result; -} - -std::string MUCUserPayloadSerializer::roleToString(MUCOccupant::Role role) const { - std::string result; - switch (role) { - case MUCOccupant::Moderator: result = "moderator"; break; - case MUCOccupant::NoRole: result = "none"; break; - case MUCOccupant::Participant: result = "participant"; break; - case MUCOccupant::Visitor: result = "visitor"; break; - default: assert(false); - } - return result; -} } diff --git a/Swiften/Serializer/PayloadSerializers/MUCUserPayloadSerializer.h b/Swiften/Serializer/PayloadSerializers/MUCUserPayloadSerializer.h index 54e6aff..8c237e0 100644 --- a/Swiften/Serializer/PayloadSerializers/MUCUserPayloadSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/MUCUserPayloadSerializer.h @@ -6,17 +6,18 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/MUCUserPayload.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/MUCUserPayload.h> namespace Swift { + class PayloadSerializerCollection; class MUCUserPayloadSerializer : public GenericPayloadSerializer<MUCUserPayload> { public: - MUCUserPayloadSerializer(); - std::string affiliationToString(MUCOccupant::Affiliation affiliation) const; - std::string roleToString(MUCOccupant::Role role) const; + MUCUserPayloadSerializer(PayloadSerializerCollection* serializers); virtual std::string serializePayload(boost::shared_ptr<MUCUserPayload> version) const; + private: + PayloadSerializerCollection* serializers; }; } diff --git a/Swiften/Serializer/PayloadSerializers/NicknameSerializer.cpp b/Swiften/Serializer/PayloadSerializers/NicknameSerializer.cpp index 23d2c25..38a5db5 100644 --- a/Swiften/Serializer/PayloadSerializers/NicknameSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/NicknameSerializer.cpp @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/NicknameSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/NicknameSerializer.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/NicknameSerializer.h b/Swiften/Serializer/PayloadSerializers/NicknameSerializer.h index e07767b..382ec11 100644 --- a/Swiften/Serializer/PayloadSerializers/NicknameSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/NicknameSerializer.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/Nickname.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/Nickname.h> namespace Swift { class NicknameSerializer : public GenericPayloadSerializer<Nickname> { diff --git a/Swiften/Serializer/PayloadSerializers/PrioritySerializer.h b/Swiften/Serializer/PayloadSerializers/PrioritySerializer.h index cc96ce7..5a2ef27 100644 --- a/Swiften/Serializer/PayloadSerializers/PrioritySerializer.h +++ b/Swiften/Serializer/PayloadSerializers/PrioritySerializer.h @@ -4,13 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_PrioritySerializer_H -#define SWIFTEN_PrioritySerializer_H +#pragma once #include <boost/lexical_cast.hpp> -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/Priority.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/Priority.h> namespace Swift { class PrioritySerializer : public GenericPayloadSerializer<Priority> { @@ -22,5 +21,3 @@ namespace Swift { } }; } - -#endif diff --git a/Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.cpp index 6e1d74d..6cb226c 100644 --- a/Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.cpp @@ -4,15 +4,15 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.h" +#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" +#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 { diff --git a/Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.h b/Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.h index 7b46136..3548cac 100644 --- a/Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/PrivateStorage.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PrivateStorage.h> namespace Swift { class PayloadSerializerCollection; diff --git a/Swiften/Serializer/PayloadSerializers/RawXMLPayloadSerializer.h b/Swiften/Serializer/PayloadSerializers/RawXMLPayloadSerializer.h index 6874569..02a5564 100644 --- a/Swiften/Serializer/PayloadSerializers/RawXMLPayloadSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/RawXMLPayloadSerializer.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/RawXMLPayload.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/RawXMLPayload.h> namespace Swift { class RawXMLPayloadSerializer : public GenericPayloadSerializer<RawXMLPayload> { diff --git a/Swiften/Serializer/PayloadSerializers/ReplaceSerializer.h b/Swiften/Serializer/PayloadSerializers/ReplaceSerializer.h new file mode 100644 index 0000000..88ad2b3 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/ReplaceSerializer.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2011 Vlad Voicu + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> +#include <Swiften/Elements/Replace.h> + +namespace Swift { + class ReplaceSerializer : public GenericPayloadSerializer<Replace> { + public: + ReplaceSerializer() : GenericPayloadSerializer<Replace>() {} + + virtual std::string serializePayload(boost::shared_ptr<Replace> replace) const { + return "<replace id = '" + replace->getID() + "' xmlns='http://swift.im/protocol/replace'/>"; + } + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.cpp b/Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.cpp index cfb3a90..af0c609 100644 --- a/Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.cpp @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h b/Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h index d259555..133e45e 100644 --- a/Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h @@ -4,11 +4,10 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_ResourceBindSerializer_H -#define SWIFTEN_ResourceBindSerializer_H +#pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/ResourceBind.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/ResourceBind.h> namespace Swift { class ResourceBindSerializer : public GenericPayloadSerializer<ResourceBind> { @@ -18,5 +17,3 @@ namespace Swift { virtual std::string serializePayload(boost::shared_ptr<ResourceBind>) const; }; } - -#endif diff --git a/Swiften/Serializer/PayloadSerializers/RosterItemExchangeSerializer.cpp b/Swiften/Serializer/PayloadSerializers/RosterItemExchangeSerializer.cpp new file mode 100644 index 0000000..b60db12 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/RosterItemExchangeSerializer.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2011 Jan Kaluza + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Serializer/PayloadSerializers/RosterItemExchangeSerializer.h> + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> +#include <Swiften/Serializer/XML/XMLElement.h> + +namespace Swift { + +RosterItemExchangeSerializer::RosterItemExchangeSerializer() : GenericPayloadSerializer<RosterItemExchangePayload>() { +} + +std::string RosterItemExchangeSerializer::serializePayload(boost::shared_ptr<RosterItemExchangePayload> roster) const { + XMLElement queryElement("x", "http://jabber.org/protocol/rosterx"); + foreach(const RosterItemExchangePayload::Item& item, roster->getItems()) { + boost::shared_ptr<XMLElement> itemElement(new XMLElement("item")); + itemElement->setAttribute("jid", item.getJID()); + itemElement->setAttribute("name", item.getName()); + + switch (item.getAction()) { + case RosterItemExchangePayload::Item::Add: itemElement->setAttribute("action", "add"); break; + case RosterItemExchangePayload::Item::Modify: itemElement->setAttribute("action", "modify"); break; + case RosterItemExchangePayload::Item::Delete: itemElement->setAttribute("action", "delete"); break; + } + + foreach(const std::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/RosterItemExchangeSerializer.h b/Swiften/Serializer/PayloadSerializers/RosterItemExchangeSerializer.h new file mode 100644 index 0000000..f246f9e --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/RosterItemExchangeSerializer.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2011 Jan Kaluza + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/RosterItemExchangePayload.h> + +namespace Swift { + class RosterItemExchangeSerializer : public GenericPayloadSerializer<RosterItemExchangePayload> { + public: + RosterItemExchangeSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<RosterItemExchangePayload>) const; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/RosterSerializer.cpp b/Swiften/Serializer/PayloadSerializers/RosterSerializer.cpp index 40faf73..84f36d2 100644 --- a/Swiften/Serializer/PayloadSerializers/RosterSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/RosterSerializer.cpp @@ -4,14 +4,14 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/RosterSerializer.h" +#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/XMLRawTextNode.h" -#include "Swiften/Serializer/XML/XMLElement.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> +#include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { @@ -20,6 +20,9 @@ RosterSerializer::RosterSerializer() : GenericPayloadSerializer<RosterPayload>() std::string RosterSerializer::serializePayload(boost::shared_ptr<RosterPayload> roster) const { XMLElement queryElement("query", "jabber:iq:roster"); + if (roster->getVersion()) { + queryElement.setAttribute("ver", *roster->getVersion()); + } foreach(const RosterItemPayload& item, roster->getItems()) { boost::shared_ptr<XMLElement> itemElement(new XMLElement("item")); itemElement->setAttribute("jid", item.getJID()); diff --git a/Swiften/Serializer/PayloadSerializers/RosterSerializer.h b/Swiften/Serializer/PayloadSerializers/RosterSerializer.h index 49e194b..52fdb2a 100644 --- a/Swiften/Serializer/PayloadSerializers/RosterSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/RosterSerializer.h @@ -4,11 +4,10 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_RosterSerializer_H -#define SWIFTEN_RosterSerializer_H +#pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/RosterPayload.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/RosterPayload.h> namespace Swift { class RosterSerializer : public GenericPayloadSerializer<RosterPayload> { @@ -18,5 +17,3 @@ namespace Swift { virtual std::string serializePayload(boost::shared_ptr<RosterPayload>) const; }; } - -#endif diff --git a/Swiften/Serializer/PayloadSerializers/S5BProxyRequestSerializer.h b/Swiften/Serializer/PayloadSerializers/S5BProxyRequestSerializer.h new file mode 100644 index 0000000..b523588 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/S5BProxyRequestSerializer.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2011 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + + +#pragma once + +#include <boost/lexical_cast.hpp> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Elements/S5BProxyRequest.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> + +namespace Swift { + class PayloadSerializerCollection; + + class S5BProxyRequestSerializer : public GenericPayloadSerializer<S5BProxyRequest> { + public: + virtual std::string serializePayload(boost::shared_ptr<S5BProxyRequest> s5bProxyRequest) const { + XMLElement queryElement("query", "http://jabber.org/protocol/bytestreams"); + if (s5bProxyRequest && s5bProxyRequest->getStreamHost()) { + boost::shared_ptr<XMLElement> streamHost = boost::make_shared<XMLElement>("streamhost"); + streamHost->setAttribute("host", s5bProxyRequest->getStreamHost().get().addressPort.getAddress().toString()); + streamHost->setAttribute("port", boost::lexical_cast<std::string>(s5bProxyRequest->getStreamHost().get().addressPort.getPort())); + streamHost->setAttribute("jid", s5bProxyRequest->getStreamHost().get().jid.toString()); + queryElement.addNode(streamHost); + } else if (s5bProxyRequest && s5bProxyRequest->getActivate()) { + queryElement.setAttribute("sid", s5bProxyRequest->getSID()); + boost::shared_ptr<XMLElement> activate = boost::make_shared<XMLElement>("activate", "", s5bProxyRequest->getActivate().get().toString()); + queryElement.addNode(activate); + } + return queryElement.serialize(); + } + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.cpp b/Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.cpp index a7a9fda..a5cd634 100644 --- a/Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.cpp @@ -4,14 +4,14 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Base/foreach.h" -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/XML/XMLRawTextNode.h" -#include "Swiften/Serializer/PayloadSerializers/FormSerializer.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> +#include <Swiften/Serializer/PayloadSerializers/FormSerializer.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.h b/Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.h index 2d8ec85..e4dbff8 100644 --- a/Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.h @@ -7,8 +7,8 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/SearchPayload.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/SearchPayload.h> namespace Swift { class PayloadSerializerCollection; diff --git a/Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.cpp b/Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.cpp index b9ec55e..51079ee 100644 --- a/Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.cpp @@ -4,11 +4,11 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#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" +#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 { diff --git a/Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h b/Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h index a02aeb9..a1915c7 100644 --- a/Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h @@ -4,11 +4,10 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_SecurityLabelSerializer_H -#define SWIFTEN_SecurityLabelSerializer_H +#pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/SecurityLabel.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/SecurityLabel.h> namespace Swift { class SecurityLabelSerializer : public GenericPayloadSerializer<SecurityLabel> { @@ -18,5 +17,3 @@ namespace Swift { virtual std::string serializePayload(boost::shared_ptr<SecurityLabel> version) const; }; } - -#endif diff --git a/Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.cpp b/Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.cpp index 7424c98..1078292 100644 --- a/Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.cpp @@ -4,11 +4,11 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#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" +#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 { diff --git a/Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.h b/Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.h index 88a1541..02104df 100644 --- a/Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.h @@ -4,11 +4,10 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_SecurityLabelsCatalogSerializer_H -#define SWIFTEN_SecurityLabelsCatalogSerializer_H +#pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/SecurityLabelsCatalog.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/SecurityLabelsCatalog.h> namespace Swift { class SecurityLabelsCatalogSerializer : public GenericPayloadSerializer<SecurityLabelsCatalog> { @@ -18,5 +17,3 @@ namespace Swift { virtual std::string serializePayload(boost::shared_ptr<SecurityLabelsCatalog> version) const; }; } - -#endif diff --git a/Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.cpp b/Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.cpp index b2eb1ed..e117167 100644 --- a/Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h b/Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h index 72f4afd..98fa243 100644 --- a/Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h @@ -4,11 +4,10 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_SoftwareVersionSerializer_H -#define SWIFTEN_SoftwareVersionSerializer_H +#pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/SoftwareVersion.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/SoftwareVersion.h> namespace Swift { class SoftwareVersionSerializer : public GenericPayloadSerializer<SoftwareVersion> { @@ -18,5 +17,3 @@ namespace Swift { virtual std::string serializePayload(boost::shared_ptr<SoftwareVersion> version) const; }; } - -#endif diff --git a/Swiften/Serializer/PayloadSerializers/StartSessionSerializer.h b/Swiften/Serializer/PayloadSerializers/StartSessionSerializer.h index dd9ba97..2082f4b 100644 --- a/Swiften/Serializer/PayloadSerializers/StartSessionSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/StartSessionSerializer.h @@ -4,13 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_StartSessionSerializer_H -#define SWIFTEN_StartSessionSerializer_H +#pragma once #include <boost/lexical_cast.hpp> -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/StartSession.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/StartSession.h> namespace Swift { class StartSessionSerializer : public GenericPayloadSerializer<StartSession> { @@ -22,5 +21,3 @@ namespace Swift { } }; } - -#endif diff --git a/Swiften/Serializer/PayloadSerializers/StatusSerializer.h b/Swiften/Serializer/PayloadSerializers/StatusSerializer.h index 565d554..a8de26f 100644 --- a/Swiften/Serializer/PayloadSerializers/StatusSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/StatusSerializer.h @@ -4,13 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_StatusSerializer_H -#define SWIFTEN_StatusSerializer_H +#pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" -#include "Swiften/Elements/Status.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> { @@ -24,5 +23,3 @@ namespace Swift { } }; } - -#endif diff --git a/Swiften/Serializer/PayloadSerializers/StatusShowSerializer.h b/Swiften/Serializer/PayloadSerializers/StatusShowSerializer.h index e797e81..e65c1b6 100644 --- a/Swiften/Serializer/PayloadSerializers/StatusShowSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/StatusShowSerializer.h @@ -4,11 +4,10 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_StatusShowSerializer_H -#define SWIFTEN_StatusShowSerializer_H +#pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/StatusShow.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/StatusShow.h> namespace Swift { class StatusShowSerializer : public GenericPayloadSerializer<StatusShow> { @@ -35,5 +34,3 @@ namespace Swift { } }; } - -#endif diff --git a/Swiften/Serializer/PayloadSerializers/StorageSerializer.cpp b/Swiften/Serializer/PayloadSerializers/StorageSerializer.cpp index 049c797..30adf26 100644 --- a/Swiften/Serializer/PayloadSerializers/StorageSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/StorageSerializer.cpp @@ -4,13 +4,13 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/StorageSerializer.h" +#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" +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/StorageSerializer.h b/Swiften/Serializer/PayloadSerializers/StorageSerializer.h index bc682a6..6f4f03b 100644 --- a/Swiften/Serializer/PayloadSerializers/StorageSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/StorageSerializer.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/Storage.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/Storage.h> namespace Swift { class StorageSerializer : public GenericPayloadSerializer<Storage> { diff --git a/Swiften/Serializer/PayloadSerializers/StreamInitiationFileInfoSerializer.cpp b/Swiften/Serializer/PayloadSerializers/StreamInitiationFileInfoSerializer.cpp new file mode 100644 index 0000000..7b0cad8 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/StreamInitiationFileInfoSerializer.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2011 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Serializer/PayloadSerializers/StreamInitiationFileInfoSerializer.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> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> + + + +namespace Swift { + +StreamInitiationFileInfoSerializer::StreamInitiationFileInfoSerializer() { +} + +std::string StreamInitiationFileInfoSerializer::serializePayload(boost::shared_ptr<StreamInitiationFileInfo> fileInfo) const { + XMLElement fileElement("file", "http://jabber.org/protocol/si/profile/file-transfer"); + + if (fileInfo->getDate() != stringToDateTime("")) { + fileElement.setAttribute("date", dateTimeToString(fileInfo->getDate())); + } + fileElement.setAttribute("hash", fileInfo->getHash()); + if (fileInfo->getAlgo() != "md5") { + fileElement.setAttribute("algo", fileInfo->getAlgo()); + } + if (!fileInfo->getName().empty()) { + fileElement.setAttribute("name", fileInfo->getName()); + } + if (fileInfo->getSize() != 0) { + fileElement.setAttribute("size", boost::lexical_cast<std::string>(fileInfo->getSize())); + } + if (!fileInfo->getDescription().empty()) { + boost::shared_ptr<XMLElement> desc = boost::make_shared<XMLElement>("desc", "", fileInfo->getDescription()); + fileElement.addNode(desc); + } + if (fileInfo->getSupportsRangeRequests()) { + boost::shared_ptr<XMLElement> range = boost::make_shared<XMLElement>("range"); + if (fileInfo->getRangeOffset() != 0) { + range->setAttribute("offset", boost::lexical_cast<std::string>(fileInfo->getRangeOffset())); + } + fileElement.addNode(range); + } + return fileElement.serialize(); +} + +} diff --git a/Swiften/Serializer/PayloadSerializers/StreamInitiationFileInfoSerializer.h b/Swiften/Serializer/PayloadSerializers/StreamInitiationFileInfoSerializer.h new file mode 100644 index 0000000..4ac0a0d --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/StreamInitiationFileInfoSerializer.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2011 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + + +#pragma once + +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/StreamInitiationFileInfo.h> + +#include <Swiften/Serializer/XML/XMLElement.h> + +namespace Swift { + class PayloadSerializerCollection; + + class StreamInitiationFileInfoSerializer : public GenericPayloadSerializer<StreamInitiationFileInfo> { + public: + StreamInitiationFileInfoSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<StreamInitiationFileInfo>) const; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/StreamInitiationSerializer.cpp b/Swiften/Serializer/PayloadSerializers/StreamInitiationSerializer.cpp index 70fb2ac..9ccfab2 100644 --- a/Swiften/Serializer/PayloadSerializers/StreamInitiationSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/StreamInitiationSerializer.cpp @@ -4,17 +4,16 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/StreamInitiationSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/StreamInitiationSerializer.h> #include <boost/shared_ptr.hpp> #include <boost/lexical_cast.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" -#include "Swiften/Serializer/PayloadSerializers/FormSerializer.h" +#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/PayloadSerializers/FormSerializer.h> #define FILE_TRANSFER_NS "http://jabber.org/protocol/si/profile/file-transfer" @@ -37,19 +36,19 @@ std::string StreamInitiationSerializer::serializePayload(boost::shared_ptr<Strea if (streamInitiation->getFileInfo()) { StreamInitiationFileInfo file = *streamInitiation->getFileInfo(); boost::shared_ptr<XMLElement> fileElement(new XMLElement("file", "http://jabber.org/protocol/si/profile/file-transfer")); - fileElement->setAttribute("name", file.name); - if (file.size != -1) { - fileElement->setAttribute("size", boost::lexical_cast<std::string>(file.size)); + fileElement->setAttribute("name", file.getName()); + if (file.getSize() != 0) { + fileElement->setAttribute("size", boost::lexical_cast<std::string>(file.getSize())); } - if (!file.description.empty()) { + if (!file.getDescription().empty()) { boost::shared_ptr<XMLElement> descElement(new XMLElement("desc")); - descElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(file.description))); + descElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(file.getDescription()))); fileElement->addNode(descElement); } siElement.addNode(fileElement); } - boost::shared_ptr<XMLElement> featureElement(new XMLElement("feature", "http://jabber.org/protocol/feature-neg")); + boost::shared_ptr<XMLElement> featureElement(new XMLElement("feature", FEATURE_NEG_NS)); if (streamInitiation->getProvidedMethods().size() > 0) { Form::ref form(new Form(Form::FormType)); ListSingleFormField::ref field = ListSingleFormField::create(); diff --git a/Swiften/Serializer/PayloadSerializers/StreamInitiationSerializer.h b/Swiften/Serializer/PayloadSerializers/StreamInitiationSerializer.h index 0b51519..76f0f45 100644 --- a/Swiften/Serializer/PayloadSerializers/StreamInitiationSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/StreamInitiationSerializer.h @@ -6,12 +6,10 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/StreamInitiation.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/StreamInitiation.h> namespace Swift { - class PayloadSerializerCollection; - class StreamInitiationSerializer : public GenericPayloadSerializer<StreamInitiation> { public: StreamInitiationSerializer(); diff --git a/Swiften/Serializer/PayloadSerializers/SubjectSerializer.h b/Swiften/Serializer/PayloadSerializers/SubjectSerializer.h index cf78ddd..fe82499 100644 --- a/Swiften/Serializer/PayloadSerializers/SubjectSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/SubjectSerializer.h @@ -6,9 +6,9 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" -#include "Swiften/Elements/Subject.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> +#include <Swiften/Elements/Subject.h> namespace Swift { class SubjectSerializer : public GenericPayloadSerializer<Subject> { diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/CapsInfoSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/CapsInfoSerializerTest.cpp index 2604331..270d165 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/CapsInfoSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/CapsInfoSerializerTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/DiscoInfoSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/DiscoInfoSerializerTest.cpp index 3875efd..32f5f49 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/DiscoInfoSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/DiscoInfoSerializerTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp index dd06244..27d4ac5 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/ErrorSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/ErrorSerializer.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp index e4a6661..29e7e59 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/FormSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/FormSerializer.h> using namespace Swift; @@ -96,13 +96,6 @@ class FormSerializerTest : public CppUnit::TestFixture { field->setDescription("Tell all your friends about your new bot!"); form->addField(field); - std::vector<std::string> values2; - values2.push_back("foo"); - values2.push_back("bar"); - field = UntypedFormField::create(values2); - field->setName("fum"); - form->addField(field); - CPPUNIT_ASSERT_EQUAL(std::string( "<x type=\"form\" xmlns=\"jabber:x:data\">" "<field type=\"hidden\" var=\"FORM_TYPE\">" @@ -139,10 +132,6 @@ class FormSerializerTest : public CppUnit::TestFixture { "<value>foo@bar.com</value>" "<value>baz@fum.org</value>" "</field>" - "<field var=\"fum\">" - "<value>foo</value>" - "<value>bar</value>" - "</field>" "</x>"), testling.serialize(form)); } }; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/InBandRegistrationPayloadSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/InBandRegistrationPayloadSerializerTest.cpp index 7020537..df43e69 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/InBandRegistrationPayloadSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/InBandRegistrationPayloadSerializerTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/InBandRegistrationPayloadSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/InBandRegistrationPayloadSerializer.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/JingleSerializersTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/JingleSerializersTest.cpp new file mode 100644 index 0000000..e3ec8fc --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/JingleSerializersTest.cpp @@ -0,0 +1,512 @@ +/* + * Copyright (c) 2011 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <boost/shared_ptr.hpp> +#include <boost/smart_ptr/make_shared.hpp> + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include <Swiften/Serializer/PayloadSerializers/JingleFileTransferDescriptionSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/StreamInitiationFileInfoSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/JinglePayloadSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h> +#include <Swiften/Elements/JingleFileTransferDescription.h> +#include <Swiften/Elements/StreamInitiationFileInfo.h> +#include <Swiften/Elements/JingleIBBTransportPayload.h> +#include <Swiften/Elements/JingleS5BTransportPayload.h> +#include <Swiften/Elements/JingleFileTransferHash.h> +#include <Swiften/Elements/JinglePayload.h> +#include <Swiften/Elements/JingleFileTransferReceived.h> +#include <Swiften/Base/DateTime.h> + +using namespace Swift; + +class JingleSerializersTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(JingleSerializersTest); + CPPUNIT_TEST(testSerialize_StreamInitiationFileInfo); + CPPUNIT_TEST(testSerialize_StreamInitiationFileInfoRange); + + CPPUNIT_TEST(testSerialize_Xep0261_Example1); + CPPUNIT_TEST(testSerialize_Xep0261_Example9); + CPPUNIT_TEST(testSerialize_Xep0261_Example13); + + CPPUNIT_TEST(testSerialize_Xep0234_Example1); + CPPUNIT_TEST(testSerialize_Xep0234_Example3); + CPPUNIT_TEST(testSerialize_Xep0234_Example5); + CPPUNIT_TEST(testSerialize_Xep0234_Example8); + CPPUNIT_TEST(testSerialize_Xep0234_Example10); + CPPUNIT_TEST(testSerialize_Xep0234_Example13); + + CPPUNIT_TEST(testSerialize_Xep0260_Example1); + + CPPUNIT_TEST_SUITE_END(); + + boost::shared_ptr<JinglePayloadSerializer> createTestling() { + return boost::make_shared<JinglePayloadSerializer>(&collection); + } + + + public: + void testSerialize_StreamInitiationFileInfo() { + std::string expected = "<file" + " date=\"1969-07-21T02:56:15Z\"" + " hash=\"552da749930852c69ae5d2141d3766b1\"" + " name=\"test.txt\"" + " size=\"1022\"" + " xmlns=\"http://jabber.org/protocol/si/profile/file-transfer\">" + "<desc>This is a test. If this were a real file...</desc>" + "<range/>" + "</file>"; + + StreamInitiationFileInfo::ref fileInfo = boost::make_shared<StreamInitiationFileInfo>(); + fileInfo->setDate(stringToDateTime("1969-07-21T02:56:15Z")); + fileInfo->setHash("552da749930852c69ae5d2141d3766b1"); + fileInfo->setSize(1022); + fileInfo->setName("test.txt"); + fileInfo->setDescription("This is a test. If this were a real file..."); + fileInfo->setSupportsRangeRequests(true); + + boost::shared_ptr<StreamInitiationFileInfoSerializer> serializer = boost::make_shared<StreamInitiationFileInfoSerializer>(); + CPPUNIT_ASSERT_EQUAL(expected, serializer->serializePayload(fileInfo)); + } + + void testSerialize_StreamInitiationFileInfoRange() { + std::string expected = "<file hash=\"552da749930852c69ae5d2141d3766b1\"" + " xmlns=\"http://jabber.org/protocol/si/profile/file-transfer\">" + "<range offset=\"270336\"/>" + "</file>"; + + StreamInitiationFileInfo::ref fileInfo = boost::make_shared<StreamInitiationFileInfo>(); + fileInfo->setHash("552da749930852c69ae5d2141d3766b1"); + fileInfo->setSupportsRangeRequests(true); + fileInfo->setRangeOffset(270336); + + boost::shared_ptr<StreamInitiationFileInfoSerializer> serializer = boost::make_shared<StreamInitiationFileInfoSerializer>(); + CPPUNIT_ASSERT_EQUAL(expected, serializer->serializePayload(fileInfo)); + } + + + // IBB Transport Method Examples + + // http://xmpp.org/extensions/xep-0261.html#example-1 + void testSerialize_Xep0261_Example1() { + std::string expected = + "<jingle action=\"session-initiate\"" + " initiator=\"romeo@montague.lit/orchard\"" + " sid=\"a73sjjvkla37jfea\"" + " xmlns=\"urn:xmpp:jingle:1\">" + "<content creator=\"initiator\" name=\"ex\">" + "<transport block-size=\"4096\"" + " sid=\"ch3d9s71\"" + " xmlns=\"urn:xmpp:jingle:transports:ibb:1\"/>" + "</content>" + "</jingle>"; + + JinglePayload::ref payload = boost::make_shared<JinglePayload>(); + payload->setAction(JinglePayload::SessionInitiate); + payload->setSessionID("a73sjjvkla37jfea"); + payload->setInitiator(JID("romeo@montague.lit/orchard")); + + JingleIBBTransportPayload::ref transport = boost::make_shared<JingleIBBTransportPayload>(); + transport->setBlockSize(4096); + transport->setSessionID("ch3d9s71"); + + JingleContentPayload::ref content = boost::make_shared<JingleContentPayload>(); + content->setCreator(JingleContentPayload::InitiatorCreator); + content->setName("ex"); + content->addTransport(transport); + + payload->addPayload(content); + + CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); + } + + // http://xmpp.org/extensions/xep-0261.html#example-9 + void testSerialize_Xep0261_Example9() { + std::string expected = + "<jingle action=\"transport-info\"" + " initiator=\"romeo@montague.lit/orchard\"" + " sid=\"a73sjjvkla37jfea\"" + " xmlns=\"urn:xmpp:jingle:1\">" + "<content creator=\"initiator\" name=\"ex\">" + "<transport block-size=\"2048\"" + " sid=\"bt8a71h6\"" + " xmlns=\"urn:xmpp:jingle:transports:ibb:1\"/>" + "</content>" + "</jingle>"; + + JinglePayload::ref payload = boost::make_shared<JinglePayload>(); + payload->setAction(JinglePayload::TransportInfo); + payload->setInitiator(JID("romeo@montague.lit/orchard")); + payload->setSessionID("a73sjjvkla37jfea"); + + JingleContentPayload::ref content = boost::make_shared<JingleContentPayload>(); + content->setCreator(JingleContentPayload::InitiatorCreator); + content->setName("ex"); + + JingleIBBTransportPayload::ref transport = boost::make_shared<JingleIBBTransportPayload>(); + transport->setBlockSize(2048); + transport->setSessionID("bt8a71h6"); + + content->addTransport(transport); + payload->addPayload(content); + + CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); + } + + // http://xmpp.org/extensions/xep-0261.html#example-13 + void testSerialize_Xep0261_Example13() { + std::string expected = + "<jingle action=\"session-terminate\"" + " initiator=\"romeo@montague.lit/orchard\"" + " sid=\"a73sjjvkla37jfea\"" + " xmlns=\"urn:xmpp:jingle:1\">" + "<reason><success/></reason>" + "</jingle>"; + + JinglePayload::ref payload = boost::make_shared<JinglePayload>(); + payload->setAction(JinglePayload::SessionTerminate); + payload->setInitiator(JID("romeo@montague.lit/orchard")); + payload->setSessionID("a73sjjvkla37jfea"); + payload->setReason(JinglePayload::Reason(JinglePayload::Reason::Success)); + + CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); + } + + // http://xmpp.org/extensions/xep-0234.html#example-1 + void testSerialize_Xep0234_Example1() { + std::string expected = "<description xmlns=\"urn:xmpp:jingle:apps:file-transfer:3\">" + "<offer>" + "<file" + " date=\"1969-07-21T02:56:15Z\"" + " hash=\"552da749930852c69ae5d2141d3766b1\"" + " name=\"test.txt\"" + " size=\"1022\"" + " xmlns=\"http://jabber.org/protocol/si/profile/file-transfer\">" + "<desc>This is a test. If this were a real file...</desc>" + "<range/>" + "</file>" + "</offer>" + "</description>"; + JingleFileTransferDescription::ref desc = boost::make_shared<JingleFileTransferDescription>(); + StreamInitiationFileInfo fileInfo; + + fileInfo.setDate(stringToDateTime("1969-07-21T02:56:15Z")); + fileInfo.setHash("552da749930852c69ae5d2141d3766b1"); + fileInfo.setSize(1022); + fileInfo.setName("test.txt"); + fileInfo.setDescription("This is a test. If this were a real file..."); + fileInfo.setSupportsRangeRequests(true); + + desc->addOffer(fileInfo); + + CPPUNIT_ASSERT_EQUAL(expected, boost::make_shared<JingleFileTransferDescriptionSerializer>()->serialize(desc)); + } + + // http://xmpp.org/extensions/xep-0234.html#example-3 + void testSerialize_Xep0234_Example3() { + std::string expected = + "<jingle action=\"session-accept\"" + " initiator=\"romeo@montague.lit/orchard\"" + " sid=\"851ba2\"" + " xmlns=\"urn:xmpp:jingle:1\">" + "<content creator=\"initiator\" name=\"a-file-offer\">" + "<description xmlns=\"urn:xmpp:jingle:apps:file-transfer:3\">" + "<offer>" + "<file" + " date=\"1969-07-21T02:56:15Z\"" + " hash=\"552da749930852c69ae5d2141d3766b1\"" + " name=\"test.txt\"" + " size=\"1022\"" + " xmlns=\"http://jabber.org/protocol/si/profile/file-transfer\">" + "<desc>This is a test. If this were a real file...</desc>" + "<range/>" + "</file>" + "</offer>" + "</description>" + /*"<transport xmlns=\"urn:xmpp:jingle:transports:s5b:1\"" + " mode=\"tcp\"" + " sid=\"vj3hs98y\">" + "<candidate cid=\"ht567dq\"" + " host=\"192.169.1.10\"" + " jid=\"juliet@capulet.lit/balcony\"" + " port=\"6539\"" + " priority=\"8257636\"" + " type=\"direct\"/>" + "<candidate cid=\"hr65dqyd\"" + " host=\"134.102.201.180\"" + " jid=\"juliet@capulet.lit/balcony\"" + " port=\"16453\"" + " priority=\"7929856\"" + " type=\"assisted\"/>" + "<candidate cid=\"grt654q2\"" + " host=\"2001:638:708:30c9:219:d1ff:fea4:a17d\"" + " jid=\"juliet@capulet.lit/balcony\"" + " port=\"6539\"" + " priority=\"8257606\"" + " type=\"direct\"/>" + "</transport>"*/ + "</content>" + "</jingle>"; + + JinglePayload::ref payload = boost::make_shared<JinglePayload>(); + payload->setAction(JinglePayload::SessionAccept); + payload->setInitiator(JID("romeo@montague.lit/orchard")); + payload->setSessionID("851ba2"); + + JingleContentPayload::ref content = boost::make_shared<JingleContentPayload>(); + content->setCreator(JingleContentPayload::InitiatorCreator); + content->setName("a-file-offer"); + + JingleFileTransferDescription::ref description = boost::make_shared<JingleFileTransferDescription>(); + StreamInitiationFileInfo fileInfo; + fileInfo.setName("test.txt"); + fileInfo.setSize(1022); + fileInfo.setHash("552da749930852c69ae5d2141d3766b1"); + fileInfo.setDate(stringToDateTime("1969-07-21T02:56:15Z")); + fileInfo.setDescription("This is a test. If this were a real file..."); + fileInfo.setSupportsRangeRequests(true); + + description->addOffer(fileInfo); + content->addDescription(description); + payload->addPayload(content); + + CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); + } + + // http://xmpp.org/extensions/xep-0234.html#example-5 + void testSerialize_Xep0234_Example5() { + std::string expected = + "<jingle" + " action=\"transport-info\"" + " initiator=\"romeo@montague.lit/orchard\"" + " sid=\"a73sjjvkla37jfea\"" + " xmlns=\"urn:xmpp:jingle:1\">" + "<content creator=\"initiator\" name=\"ex\"/>" + /*"<transport" + " sid=\"vj3hs98y\"" + " xmlns=\"urn:xmpp:jingle:transports:s5b:1\">" + "<candidate-used cid=\"hr65dqyd\"/>" + "</transport>"*/ + //"</content>" + "</jingle>"; + + JinglePayload::ref payload = boost::make_shared<JinglePayload>(); + payload->setAction(JinglePayload::TransportInfo); + payload->setInitiator(JID("romeo@montague.lit/orchard")); + payload->setSessionID("a73sjjvkla37jfea"); + + JingleContentPayload::ref content = boost::make_shared<JingleContentPayload>(); + content->setCreator(JingleContentPayload::InitiatorCreator); + content->setName("ex"); + payload->addPayload(content); + + CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); + } + + // http://xmpp.org/extensions/xep-0234.html#example-8 + void testSerialize_Xep0234_Example8() { + std::string expected = + "<jingle" + " action=\"session-info\"" + " initiator=\"romeo@montague.lit/orchard\"" + " sid=\"a73sjjvkla37jfea\"" + " xmlns=\"urn:xmpp:jingle:1\">" + "<checksum xmlns=\"urn:xmpp:jingle:apps:file-transfer:3\">" + "<file>" + "<hashes xmlns=\"urn:xmpp:hashes:0\">" + "<hash algo=\"sha-1\">552da749930852c69ae5d2141d3766b1</hash>" + "</hashes>" + "</file>" + "</checksum>" + "</jingle>"; + + JinglePayload::ref payload = boost::make_shared<JinglePayload>(); + payload->setAction(JinglePayload::SessionInfo); + payload->setInitiator(JID("romeo@montague.lit/orchard")); + payload->setSessionID("a73sjjvkla37jfea"); + + JingleFileTransferHash::ref hash = boost::make_shared<JingleFileTransferHash>(); + hash->setHash("sha-1", "552da749930852c69ae5d2141d3766b1"); + + payload->addPayload(hash); + + CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); + } + + // http://xmpp.org/extensions/xep-0234.html#example-10 + void testSerialize_Xep0234_Example10() { + std::string expected = + "<jingle" + " action=\"session-initiate\"" + " initiator=\"romeo@montague.lit/orchard\"" + " sid=\"uj3b2\"" + " xmlns=\"urn:xmpp:jingle:1\">" + "<content creator=\"initiator\" name=\"a-file-request\">" + "<description" + " xmlns=\"urn:xmpp:jingle:apps:file-transfer:3\">" + "<request>" + "<file" + " hash=\"552da749930852c69ae5d2141d3766b1\"" + " xmlns=\"http://jabber.org/protocol/si/profile/file-transfer\">" + "<range offset=\"270336\"/>" + "</file>" + "</request>" + "</description>" + /*"<transport" + " mode=\"tcp\"" + " sid=\"xig361fj\"" + " xmlns=\"urn:xmpp:jingle:transports:s5b:1\">" + "<candidate" + " cid=\"ht567dq\"" + " host=\"192.169.1.10\"" + " jid=\"juliet@capulet.lit/balcony\"" + " port=\"6539\"" + " priority=\"8257636\"" + " type=\"direct\"/>" + "<candidate" + " cid=\"hr65dqyd\"" + " host=\"134.102.201.180\"" + " jid=\"juliet@capulet.lit/balcony\"" + " port=\"16453\"" + " priority=\"7929856\"" + " type=\"assisted\"/>" + "<candidate" + " cid=\"grt654q2\"" + " host=\"2001:638:708:30c9:219:d1ff:fea4:a17d\"" + " jid=\"juliet@capulet.lit/balcony\"" + " port=\"6539\"" + " priority=\"8257606\"" + " type=\"direct\"/>" + "</transport>"*/ + "</content>" + "</jingle>"; + + JinglePayload::ref payload = boost::make_shared<JinglePayload>(); + payload->setAction(JinglePayload::SessionInitiate); + payload->setInitiator(JID("romeo@montague.lit/orchard")); + payload->setSessionID("uj3b2"); + + StreamInitiationFileInfo fileInfo; + fileInfo.setHash("552da749930852c69ae5d2141d3766b1"); + fileInfo.setRangeOffset(270336); + + JingleFileTransferDescription::ref desc = boost::make_shared<JingleFileTransferDescription>(); + desc->addRequest(fileInfo); + + JingleContentPayload::ref content = boost::make_shared<JingleContentPayload>(); + content->setCreator(JingleContentPayload::InitiatorCreator); + content->setName("a-file-request"); + content->addDescription(desc); + + payload->addPayload(content); + + CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); + } + + // http://xmpp.org/extensions/xep-0234.html#example-10 + void testSerialize_Xep0234_Example13() { + std::string expected = + "<jingle" + " action=\"session-info\"" + " initiator=\"romeo@montague.lit/orchard\"" + " sid=\"a73sjjvkla37jfea\"" + " xmlns=\"urn:xmpp:jingle:1\">" + "<received xmlns=\"urn:xmpp:jingle:apps:file-transfer:3\">" + "<file" + " hash=\"a749930852c69ae5d2141d3766b1552d\"" + " xmlns=\"http://jabber.org/protocol/si/profile/file-transfer\"/>" + "</received>" + "</jingle>"; + + JinglePayload::ref payload = boost::make_shared<JinglePayload>(); + payload->setAction(JinglePayload::SessionInfo); + payload->setInitiator(JID("romeo@montague.lit/orchard")); + payload->setSessionID("a73sjjvkla37jfea"); + + JingleFileTransferReceived::ref received = boost::make_shared<JingleFileTransferReceived>(); + + StreamInitiationFileInfo fileInfo; + fileInfo.setHash("a749930852c69ae5d2141d3766b1552d"); + + received->setFileInfo(fileInfo); + payload->addPayload(received); + + CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); + } + + // http://xmpp.org/extensions/xep-0260.html#example-1 + void testSerialize_Xep0260_Example1() { + std::string expected = + "<jingle" + " action=\"session-initiate\"" + " initiator=\"romeo@montague.lit/orchard\"" + " sid=\"a73sjjvkla37jfea\"" + " xmlns=\"urn:xmpp:jingle:1\">" + "<content creator=\"initiator\" name=\"ex\">" + "<transport" + " mode=\"tcp\"" + " sid=\"vj3hs98y\"" + " xmlns=\"urn:xmpp:jingle:transports:s5b:1\">" + "<candidate cid=\"hft54dqy\"" + " host=\"192.168.4.1\"" + " jid=\"romeo@montague.lit/orchard\"" + " port=\"5086\"" + " priority=\"8257636\"" + " type=\"direct\"/>" + "<candidate cid=\"hutr46fe\"" + " host=\"24.24.24.1\"" + " jid=\"romeo@montague.lit/orchard\"" + " port=\"5087\"" + " priority=\"8258636\"" + " type=\"direct\"/>" + "</transport>" + "</content>" + "</jingle>"; + + JinglePayload::ref payload = boost::make_shared<JinglePayload>(); + payload->setAction(JinglePayload::SessionInitiate); + payload->setInitiator(JID("romeo@montague.lit/orchard")); + payload->setSessionID("a73sjjvkla37jfea"); + + JingleContentPayload::ref content = boost::make_shared<JingleContentPayload>(); + content->setCreator(JingleContentPayload::InitiatorCreator); + content->setName("ex"); + + JingleS5BTransportPayload::ref transport = boost::make_shared<JingleS5BTransportPayload>(); + transport->setMode(JingleS5BTransportPayload::TCPMode); + transport->setSessionID("vj3hs98y"); + + JingleS5BTransportPayload::Candidate candidate1; + candidate1.cid = "hft54dqy"; + candidate1.hostPort = HostAddressPort(HostAddress("192.168.4.1"), 5086); + candidate1.jid = JID("romeo@montague.lit/orchard"); + candidate1.priority = 8257636; + candidate1.type = JingleS5BTransportPayload::Candidate::DirectType; + transport->addCandidate(candidate1); + + JingleS5BTransportPayload::Candidate candidate2; + candidate2.cid = "hutr46fe"; + candidate2.hostPort = HostAddressPort(HostAddress("24.24.24.1"), 5087); + candidate2.jid = JID("romeo@montague.lit/orchard"); + candidate2.priority = 8258636; + candidate2.type = JingleS5BTransportPayload::Candidate::DirectType; + transport->addCandidate(candidate2); + + content->addTransport(transport); + + payload->addPayload(content); + + CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); + } + + private: + FullPayloadSerializerCollection collection; +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(JingleSerializersTest); + diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/MUCAdminPayloadSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/MUCAdminPayloadSerializerTest.cpp new file mode 100644 index 0000000..a8acf80 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/MUCAdminPayloadSerializerTest.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Serializer/PayloadSerializers/MUCAdminPayloadSerializer.h> + +using namespace Swift; + +class MUCAdminPayloadSerializerTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(MUCAdminPayloadSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); + + public: + MUCAdminPayloadSerializerTest() {} + + void testSerialize() { + MUCAdminPayloadSerializer testling; + boost::shared_ptr<MUCAdminPayload> admin = boost::make_shared<MUCAdminPayload>(); + MUCItem item; + item.affiliation = MUCOccupant::Owner; + item.role = MUCOccupant::Visitor; + item.reason = "malice"; + item.actor = JID("kev@tester.lit"); + admin->addItem(item); + + CPPUNIT_ASSERT_EQUAL(std::string("<query xmlns=\"http://jabber.org/protocol/muc#admin\"><item affiliation=\"owner\" role=\"visitor\"><actor jid=\"kev@tester.lit\"/><reason>malice</reason></item></query>"), testling.serialize(admin)); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(MUCAdminPayloadSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.cpp index 481d9c2..9eed97e 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.cpp @@ -4,11 +4,11 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.h> #include <cppunit/extensions/HelperMacros.h> -#include "Swiften/Serializer/PayloadSerializer.h" +#include <Swiften/Serializer/PayloadSerializer.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.h b/Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.h index 038b616..01f07e4 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.h @@ -8,9 +8,9 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/Payload.h" +#include <Swiften/Elements/Payload.h> #include <string> -#include "Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h" +#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h> namespace Swift { class PayloadsSerializer { diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/PrioritySerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/PrioritySerializerTest.cpp index c976b12..f5b8bee 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/PrioritySerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/PrioritySerializerTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/PrioritySerializer.h" +#include <Swiften/Serializer/PayloadSerializers/PrioritySerializer.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/PrivateStorageSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/PrivateStorageSerializerTest.cpp index b0f4084..23d71aa 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/PrivateStorageSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/PrivateStorageSerializerTest.cpp @@ -7,9 +7,9 @@ #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" +#include <Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.h> +#include <Swiften/Elements/PrivateStorage.h> +#include <Swiften/Elements/Storage.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/ReplaceSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/ReplaceSerializerTest.cpp new file mode 100644 index 0000000..3d054cc --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/ReplaceSerializerTest.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2011 Vlad Voicu + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include <Swiften/Serializer/PayloadSerializers/ReplaceSerializer.h> + +using namespace Swift; + +class ReplaceSerializerTest: public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(ReplaceSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); + + public: + ReplaceSerializerTest() {} + + void testSerialize() { + ReplaceSerializer testling; + boost::shared_ptr<Replace> replace(new Replace()); + replace->setID("bad1"); + CPPUNIT_ASSERT_EQUAL(std::string("<replace id = 'bad1' xmlns='http://swift.im/protocol/replace'/>"), testling.serialize(replace)); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(ReplaceSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/ResourceBindSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/ResourceBindSerializerTest.cpp index c7872fe..f8d3d30 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/ResourceBindSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/ResourceBindSerializerTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/RosterItemExchangeSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/RosterItemExchangeSerializerTest.cpp new file mode 100644 index 0000000..b6a90d9 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/RosterItemExchangeSerializerTest.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2011 Jan Kaluza + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include <Swiften/Serializer/PayloadSerializers/RosterItemExchangeSerializer.h> + +using namespace Swift; + +class RosterItemExchangeSerializerTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(RosterItemExchangeSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); + + public: + RosterItemExchangeSerializerTest() {} + + void testSerialize() { + RosterItemExchangeSerializer testling; + boost::shared_ptr<RosterItemExchangePayload> roster(new RosterItemExchangePayload()); + + RosterItemExchangePayload::Item item1; + item1.setJID("foo@bar.com"); + item1.setName("Foo @ Bar"); + item1.setAction(RosterItemExchangePayload::Item::Add); + item1.addGroup("Group 1"); + item1.addGroup("Group 2"); + roster->addItem(item1); + + RosterItemExchangePayload::Item item2; + item2.setJID("baz@blo.com"); + item2.setName("Baz"); + item2.setAction(RosterItemExchangePayload::Item::Modify); + roster->addItem(item2); + + std::string expectedResult = + "<x xmlns=\"http://jabber.org/protocol/rosterx\">" + "<item action=\"add\" jid=\"foo@bar.com\" name=\"Foo @ Bar\">" + "<group>Group 1</group>" + "<group>Group 2</group>" + "</item>" + "<item action=\"modify\" jid=\"baz@blo.com\" name=\"Baz\"/>" + "</x>"; + + CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(roster)); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(RosterItemExchangeSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/RosterSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/RosterSerializerTest.cpp index b8ceac3..9ecddc3 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/RosterSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/RosterSerializerTest.cpp @@ -7,20 +7,19 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/RosterSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/RosterSerializer.h> using namespace Swift; -class RosterSerializerTest : public CppUnit::TestFixture -{ +class RosterSerializerTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(RosterSerializerTest); CPPUNIT_TEST(testSerialize); CPPUNIT_TEST(testSerialize_ItemWithUnknownContent); + CPPUNIT_TEST(testSerialize_WithVersion); + CPPUNIT_TEST(testSerialize_WithEmptyVersion); CPPUNIT_TEST_SUITE_END(); public: - RosterSerializerTest() {} - void testSerialize() { RosterSerializer testling; boost::shared_ptr<RosterPayload> roster(new RosterPayload()); @@ -77,6 +76,26 @@ class RosterSerializerTest : public CppUnit::TestFixture CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(roster)); } + + void testSerialize_WithVersion() { + RosterSerializer testling; + boost::shared_ptr<RosterPayload> roster(new RosterPayload()); + roster->setVersion("ver20"); + + std::string expectedResult = "<query ver=\"ver20\" xmlns=\"jabber:iq:roster\"/>"; + + CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(roster)); + } + + void testSerialize_WithEmptyVersion() { + RosterSerializer testling; + boost::shared_ptr<RosterPayload> roster(new RosterPayload()); + roster->setVersion(""); + + std::string expectedResult = "<query ver=\"\" xmlns=\"jabber:iq:roster\"/>"; + + CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(roster)); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(RosterSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/SearchPayloadSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/SearchPayloadSerializerTest.cpp index e8328b8..d0dcbef 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/SearchPayloadSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/SearchPayloadSerializerTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelSerializerTest.cpp index 03bad89..0de509d 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelSerializerTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelsCatalogSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelsCatalogSerializerTest.cpp index a7bf1b9..c060e41 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelsCatalogSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelsCatalogSerializerTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/SoftwareVersionSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/SoftwareVersionSerializerTest.cpp index 6fac094..ad1e9b4 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/SoftwareVersionSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/SoftwareVersionSerializerTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/StatusSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/StatusSerializerTest.cpp index c0b1dc2..af90a0a 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/StatusSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/StatusSerializerTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/StatusSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/StatusSerializer.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/StatusShowSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/StatusShowSerializerTest.cpp index 2fee152..898c835 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/StatusShowSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/StatusShowSerializerTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/StatusShowSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/StatusShowSerializer.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/StorageSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/StorageSerializerTest.cpp index 01899a9..b963a9c 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/StorageSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/StorageSerializerTest.cpp @@ -7,8 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.h" -#include "Swiften/Elements/Storage.h" +#include <Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.h> +#include <Swiften/Elements/Storage.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/StreamInitiationSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/StreamInitiationSerializerTest.cpp index d05fdba..7b96298 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/StreamInitiationSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/StreamInitiationSerializerTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/StreamInitiationSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/StreamInitiationSerializer.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/VCardSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/VCardSerializerTest.cpp index 8a9a615..3ac1d77 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/VCardSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/VCardSerializerTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/VCardSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/VCardSerializer.h> using namespace Swift; @@ -29,7 +29,7 @@ class VCardSerializerTest : public CppUnit::TestFixture vcard->setFamilyName("Wonderland"); vcard->setSuffix("PhD"); vcard->setNickname("DreamGirl"); - vcard->setPhoto("abcdef"); + vcard->setPhoto(createByteArray("abcdef")); vcard->setPhotoType("image/png"); vcard->addUnknownContent("<BDAY>1234</BDAY><MAILER>mutt</MAILER>"); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/VCardUpdateSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/VCardUpdateSerializerTest.cpp index 6f37d61..613b465 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/VCardUpdateSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/VCardUpdateSerializerTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp b/Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp index 79e543e..17a6b49 100644 --- a/Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp @@ -4,15 +4,15 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/VCardSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/VCardSerializer.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" -#include "Swiften/Serializer/XML/XMLRawTextNode.h" -#include "Swiften/StringCodecs/Base64.h" -#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/StringCodecs/Base64.h> +#include <Swiften/Base/foreach.h> namespace Swift { @@ -87,14 +87,14 @@ std::string VCardSerializer::serializePayload(boost::shared_ptr<VCard> vcard) c nickElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(vcard->getNickname()))); queryElement.addNode(nickElement); } - if (!vcard->getPhoto().isEmpty() || !vcard->getPhotoType().empty()) { + if (!vcard->getPhoto().empty() || !vcard->getPhotoType().empty()) { XMLElement::ref photoElement(new XMLElement("PHOTO")); if (!vcard->getPhotoType().empty()) { XMLElement::ref typeElement(new XMLElement("TYPE")); typeElement->addNode(XMLTextNode::ref(new XMLTextNode(vcard->getPhotoType()))); photoElement->addNode(typeElement); } - if (!vcard->getPhoto().isEmpty()) { + if (!vcard->getPhoto().empty()) { XMLElement::ref binvalElement(new XMLElement("BINVAL")); binvalElement->addNode(XMLTextNode::ref(new XMLTextNode(Base64::encode(vcard->getPhoto())))); photoElement->addNode(binvalElement); diff --git a/Swiften/Serializer/PayloadSerializers/VCardSerializer.h b/Swiften/Serializer/PayloadSerializers/VCardSerializer.h index 7b9a8a9..c73ff18 100644 --- a/Swiften/Serializer/PayloadSerializers/VCardSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/VCardSerializer.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/VCard.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/VCard.h> namespace Swift { class VCardSerializer : public GenericPayloadSerializer<VCard> { diff --git a/Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.cpp b/Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.cpp index e315bc3..c06262f 100644 --- a/Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.cpp @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.h b/Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.h index 46ca154..68084f0 100644 --- a/Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/VCardUpdate.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/VCardUpdate.h> namespace Swift { class VCardUpdateSerializer : public GenericPayloadSerializer<VCardUpdate> { |