summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Serializer')
-rw-r--r--Swiften/Serializer/GenericStanzaSerializer.h2
-rw-r--r--Swiften/Serializer/IQSerializer.h9
-rw-r--r--Swiften/Serializer/MessageSerializer.cpp6
-rw-r--r--Swiften/Serializer/MessageSerializer.h6
-rw-r--r--Swiften/Serializer/PresenceSerializer.cpp9
-rw-r--r--Swiften/Serializer/PresenceSerializer.h7
-rw-r--r--Swiften/Serializer/StanzaSerializer.cpp11
-rw-r--r--Swiften/Serializer/StanzaSerializer.h5
-rw-r--r--Swiften/Serializer/UnitTest/XMPPSerializerTest.cpp4
-rw-r--r--Swiften/Serializer/XMPPSerializer.cpp8
-rw-r--r--Swiften/Serializer/XMPPSerializer.h2
11 files changed, 43 insertions, 26 deletions
diff --git a/Swiften/Serializer/GenericStanzaSerializer.h b/Swiften/Serializer/GenericStanzaSerializer.h
index a85d3ba..e8f3787 100644
--- a/Swiften/Serializer/GenericStanzaSerializer.h
+++ b/Swiften/Serializer/GenericStanzaSerializer.h
@@ -12,7 +12,7 @@ namespace Swift {
template<typename STANZA_TYPE>
class GenericStanzaSerializer : public StanzaSerializer {
public:
- GenericStanzaSerializer(const std::string& tag, PayloadSerializerCollection* payloadSerializers) : StanzaSerializer(tag, payloadSerializers) {}
+ GenericStanzaSerializer(const std::string& tag, PayloadSerializerCollection* payloadSerializers, const boost::optional<std::string>& explicitNS = boost::optional<std::string>()) : StanzaSerializer(tag, payloadSerializers, explicitNS) {}
virtual bool canSerialize(boost::shared_ptr<ToplevelElement> element) const {
return dynamic_cast<STANZA_TYPE*>(element.get()) != 0;
diff --git a/Swiften/Serializer/IQSerializer.h b/Swiften/Serializer/IQSerializer.h
index 76a9cb7..7ebafa0 100644
--- a/Swiften/Serializer/IQSerializer.h
+++ b/Swiften/Serializer/IQSerializer.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2014 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -10,11 +10,14 @@
#include <Swiften/Elements/IQ.h>
#include <Swiften/Serializer/XML/XMLElement.h>
+#include <boost/optional.hpp>
+
namespace Swift {
class IQSerializer : public GenericStanzaSerializer<IQ> {
public:
- IQSerializer(PayloadSerializerCollection* payloadSerializers) :
- GenericStanzaSerializer<IQ>("iq", payloadSerializers) {}
+ IQSerializer(PayloadSerializerCollection* payloadSerializers, const boost::optional<std::string>& explicitNS = boost::optional<std::string>()) :
+ GenericStanzaSerializer<IQ>("iq", payloadSerializers, explicitNS) {
+ }
private:
virtual void setStanzaSpecificAttributesGeneric(
diff --git a/Swiften/Serializer/MessageSerializer.cpp b/Swiften/Serializer/MessageSerializer.cpp
index c221680..f944f9b 100644
--- a/Swiften/Serializer/MessageSerializer.cpp
+++ b/Swiften/Serializer/MessageSerializer.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2014 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -9,8 +9,8 @@
namespace Swift {
-MessageSerializer::MessageSerializer(PayloadSerializerCollection* payloadSerializers) :
- GenericStanzaSerializer<Message>("message", payloadSerializers) {
+MessageSerializer::MessageSerializer(PayloadSerializerCollection* payloadSerializers, const boost::optional<std::string>& explicitNS) :
+ GenericStanzaSerializer<Message>("message", payloadSerializers, explicitNS) {
}
void MessageSerializer::setStanzaSpecificAttributesGeneric(
diff --git a/Swiften/Serializer/MessageSerializer.h b/Swiften/Serializer/MessageSerializer.h
index 8e9e941..dd8ca21 100644
--- a/Swiften/Serializer/MessageSerializer.h
+++ b/Swiften/Serializer/MessageSerializer.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2014 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -9,12 +9,14 @@
#include <Swiften/Serializer/GenericStanzaSerializer.h>
#include <Swiften/Elements/Message.h>
+#include <boost/optional.hpp>
+
namespace Swift {
class XMLElement;
class MessageSerializer : public GenericStanzaSerializer<Message> {
public:
- MessageSerializer(PayloadSerializerCollection* payloadSerializers);
+ MessageSerializer(PayloadSerializerCollection* payloadSerializers, const boost::optional<std::string>& explitNS = boost::optional<std::string>());
private:
void setStanzaSpecificAttributesGeneric(
diff --git a/Swiften/Serializer/PresenceSerializer.cpp b/Swiften/Serializer/PresenceSerializer.cpp
index 20eda4b..a192bb5 100644
--- a/Swiften/Serializer/PresenceSerializer.cpp
+++ b/Swiften/Serializer/PresenceSerializer.cpp
@@ -1,18 +1,19 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2014 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#include <Swiften/Serializer/PresenceSerializer.h>
#include <Swiften/Serializer/XML/XMLElement.h>
-
+#include <Swiften/Base/Log.h>
#include <boost/shared_ptr.hpp>
namespace Swift {
-PresenceSerializer::PresenceSerializer(PayloadSerializerCollection* payloadSerializers) :
- GenericStanzaSerializer<Presence>("presence", payloadSerializers) {
+PresenceSerializer::PresenceSerializer(PayloadSerializerCollection* payloadSerializers, const boost::optional<std::string>& explicitNS) :
+ GenericStanzaSerializer<Presence>("presence", payloadSerializers, explicitNS) {
+
}
void PresenceSerializer::setStanzaSpecificAttributesGeneric(
diff --git a/Swiften/Serializer/PresenceSerializer.h b/Swiften/Serializer/PresenceSerializer.h
index e5d9f30..b3ed721 100644
--- a/Swiften/Serializer/PresenceSerializer.h
+++ b/Swiften/Serializer/PresenceSerializer.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2014 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -9,10 +9,13 @@
#include <Swiften/Serializer/GenericStanzaSerializer.h>
#include <Swiften/Elements/Presence.h>
+#include <boost/optional.hpp>
+
namespace Swift {
class PresenceSerializer : public GenericStanzaSerializer<Presence> {
public:
- PresenceSerializer(PayloadSerializerCollection* payloadSerializers);
+ PresenceSerializer(PayloadSerializerCollection* payloadSerializers, const boost::optional<std::string>& explicitNS = boost::optional<std::string>());
+ ~PresenceSerializer() {}
private:
virtual void setStanzaSpecificAttributesGeneric(
diff --git a/Swiften/Serializer/StanzaSerializer.cpp b/Swiften/Serializer/StanzaSerializer.cpp
index 358e4b8..d097bbf 100644
--- a/Swiften/Serializer/StanzaSerializer.cpp
+++ b/Swiften/Serializer/StanzaSerializer.cpp
@@ -19,17 +19,22 @@
namespace Swift {
-StanzaSerializer::StanzaSerializer(const std::string& tag, PayloadSerializerCollection* payloadSerializers) : tag_(tag), payloadSerializers_(payloadSerializers) {
+StanzaSerializer::StanzaSerializer(const std::string& tag, PayloadSerializerCollection* payloadSerializers, const boost::optional<std::string>& explicitNS) : tag_(tag), payloadSerializers_(payloadSerializers), explicitDefaultNS_(explicitNS) {
}
SafeByteArray StanzaSerializer::serialize(boost::shared_ptr<ToplevelElement> element) const {
- return serialize(element, "");
+ if (explicitDefaultNS_) {
+ return serialize(element, explicitDefaultNS_.get());
+ }
+ else {
+ return serialize(element, "");
+ }
}
SafeByteArray StanzaSerializer::serialize(boost::shared_ptr<ToplevelElement> element, const std::string& xmlns) const {
boost::shared_ptr<Stanza> stanza(boost::dynamic_pointer_cast<Stanza>(element));
- XMLElement stanzaElement(tag_, xmlns);
+ XMLElement stanzaElement(tag_, explicitDefaultNS_ ? explicitDefaultNS_.get() : xmlns);
if (stanza->getFrom().isValid()) {
stanzaElement.setAttribute("from", stanza->getFrom());
}
diff --git a/Swiften/Serializer/StanzaSerializer.h b/Swiften/Serializer/StanzaSerializer.h
index 6b46670..766b58c 100644
--- a/Swiften/Serializer/StanzaSerializer.h
+++ b/Swiften/Serializer/StanzaSerializer.h
@@ -8,7 +8,9 @@
#include <Swiften/Elements/Stanza.h>
#include <Swiften/Serializer/ElementSerializer.h>
+
#include <string>
+#include <boost/optional.hpp>
namespace Swift {
class PayloadSerializerCollection;
@@ -16,7 +18,7 @@ namespace Swift {
class StanzaSerializer : public ElementSerializer {
public:
- StanzaSerializer(const std::string& tag, PayloadSerializerCollection* payloadSerializers);
+ StanzaSerializer(const std::string& tag, PayloadSerializerCollection* payloadSerializers, const boost::optional<std::string>& explicitNS = boost::optional<std::string>());
virtual SafeByteArray serialize(boost::shared_ptr<ToplevelElement> element) const;
virtual SafeByteArray serialize(boost::shared_ptr<ToplevelElement> element, const std::string& xmlns) const;
@@ -25,5 +27,6 @@ namespace Swift {
private:
std::string tag_;
PayloadSerializerCollection* payloadSerializers_;
+ boost::optional<std::string> explicitDefaultNS_;
};
}
diff --git a/Swiften/Serializer/UnitTest/XMPPSerializerTest.cpp b/Swiften/Serializer/UnitTest/XMPPSerializerTest.cpp
index c0ab841..83daf36 100644
--- a/Swiften/Serializer/UnitTest/XMPPSerializerTest.cpp
+++ b/Swiften/Serializer/UnitTest/XMPPSerializerTest.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2014 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -65,7 +65,7 @@ class XMPPSerializerTest : public CppUnit::TestFixture {
private:
XMPPSerializer* createSerializer(StreamType type) {
- return new XMPPSerializer(payloadSerializerCollection, type);
+ return new XMPPSerializer(payloadSerializerCollection, type, false);
}
private:
diff --git a/Swiften/Serializer/XMPPSerializer.cpp b/Swiften/Serializer/XMPPSerializer.cpp
index e3f43cd..1fb79e4 100644
--- a/Swiften/Serializer/XMPPSerializer.cpp
+++ b/Swiften/Serializer/XMPPSerializer.cpp
@@ -39,10 +39,10 @@
namespace Swift {
-XMPPSerializer::XMPPSerializer(PayloadSerializerCollection* payloadSerializers, StreamType type) : type_(type) {
- serializers_.push_back(boost::make_shared<PresenceSerializer>(payloadSerializers));
- serializers_.push_back(boost::make_shared<IQSerializer>(payloadSerializers));
- serializers_.push_back(boost::make_shared<MessageSerializer>(payloadSerializers));
+XMPPSerializer::XMPPSerializer(PayloadSerializerCollection* payloadSerializers, StreamType type, bool setExplictNSonTopLevelElements) : type_(type) {
+ serializers_.push_back(boost::make_shared<PresenceSerializer>(payloadSerializers, setExplictNSonTopLevelElements ? getDefaultNamespace() : boost::optional<std::string>()));
+ serializers_.push_back(boost::make_shared<IQSerializer>(payloadSerializers, setExplictNSonTopLevelElements ? getDefaultNamespace() : boost::optional<std::string>()));
+ serializers_.push_back(boost::make_shared<MessageSerializer>(payloadSerializers, setExplictNSonTopLevelElements ? getDefaultNamespace() : boost::optional<std::string>()));
serializers_.push_back(boost::make_shared<CompressRequestSerializer>());
serializers_.push_back(boost::make_shared<CompressFailureSerializer>());
serializers_.push_back(boost::make_shared<AuthRequestSerializer>());
diff --git a/Swiften/Serializer/XMPPSerializer.h b/Swiften/Serializer/XMPPSerializer.h
index cbcdccb..d1aa386 100644
--- a/Swiften/Serializer/XMPPSerializer.h
+++ b/Swiften/Serializer/XMPPSerializer.h
@@ -22,7 +22,7 @@ namespace Swift {
class SWIFTEN_API XMPPSerializer {
public:
- XMPPSerializer(PayloadSerializerCollection*, StreamType type);
+ XMPPSerializer(PayloadSerializerCollection*, StreamType type, bool setExplictNSonTopLevelElements);
std::string serializeHeader(const ProtocolHeader&) const;
SafeByteArray serializeElement(boost::shared_ptr<ToplevelElement> stanza) const;