diff options
author | Tobias Markmann <tm@ayena.de> | 2014-10-13 11:47:14 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2014-10-13 14:09:45 (GMT) |
commit | da894fc2d49f179e93fee660b235aa960f23d673 (patch) | |
tree | 808f0cb0aae8a0784059594037bd04358c125a05 | |
parent | 3f9c73993358b3636e3244f3e29cb4ee916e7b02 (diff) | |
download | swift-contrib-da894fc2d49f179e93fee660b235aa960f23d673.zip swift-contrib-da894fc2d49f179e93fee660b235aa960f23d673.tar.bz2 |
Correctly set 'jabber:client' namespace on message/presence/IQ stanzas for BOSH connections.
Test-Information:
Tested with Swift and interoperability against Psi. Swift debug log now correctly
shows the namespace being set. Previously Psi did not display the body of messages
due to them being in the worng namespace. Now as they are in the correct namespace
messages are displayed correctly by Psi.
Change-Id: I547e335100abebfcf170cf7f41b86fd2dbb01692
-rw-r--r-- | Swiften/Serializer/GenericStanzaSerializer.h | 2 | ||||
-rw-r--r-- | Swiften/Serializer/IQSerializer.h | 9 | ||||
-rw-r--r-- | Swiften/Serializer/MessageSerializer.cpp | 6 | ||||
-rw-r--r-- | Swiften/Serializer/MessageSerializer.h | 6 | ||||
-rw-r--r-- | Swiften/Serializer/PresenceSerializer.cpp | 9 | ||||
-rw-r--r-- | Swiften/Serializer/PresenceSerializer.h | 7 | ||||
-rw-r--r-- | Swiften/Serializer/StanzaSerializer.cpp | 11 | ||||
-rw-r--r-- | Swiften/Serializer/StanzaSerializer.h | 5 | ||||
-rw-r--r-- | Swiften/Serializer/UnitTest/XMPPSerializerTest.cpp | 4 | ||||
-rw-r--r-- | Swiften/Serializer/XMPPSerializer.cpp | 8 | ||||
-rw-r--r-- | Swiften/Serializer/XMPPSerializer.h | 2 | ||||
-rw-r--r-- | Swiften/Session/BOSHSessionStream.cpp | 2 | ||||
-rw-r--r-- | Swiften/StreamStack/XMPPLayer.cpp | 6 | ||||
-rw-r--r-- | Swiften/StreamStack/XMPPLayer.h | 4 |
14 files changed, 51 insertions, 30 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; diff --git a/Swiften/Session/BOSHSessionStream.cpp b/Swiften/Session/BOSHSessionStream.cpp index 8cdbdb0..63e35b8 100644 --- a/Swiften/Session/BOSHSessionStream.cpp +++ b/Swiften/Session/BOSHSessionStream.cpp @@ -56,7 +56,7 @@ BOSHSessionStream::BOSHSessionStream( connectionPool->onBOSHDataRead.connect(boost::bind(&BOSHSessionStream::handlePoolBOSHDataRead, this, _1)); connectionPool->onBOSHDataWritten.connect(boost::bind(&BOSHSessionStream::handlePoolBOSHDataWritten, this, _1)); - xmppLayer = new XMPPLayer(payloadParserFactories, payloadSerializers, xmlParserFactory, ClientStreamType); + xmppLayer = new XMPPLayer(payloadParserFactories, payloadSerializers, xmlParserFactory, ClientStreamType, true); xmppLayer->onStreamStart.connect(boost::bind(&BOSHSessionStream::handleStreamStartReceived, this, _1)); xmppLayer->onElement.connect(boost::bind(&BOSHSessionStream::handleElementReceived, this, _1)); xmppLayer->onError.connect(boost::bind(&BOSHSessionStream::handleXMPPError, this)); diff --git a/Swiften/StreamStack/XMPPLayer.cpp b/Swiften/StreamStack/XMPPLayer.cpp index 59418a2..1f06b06 100644 --- a/Swiften/StreamStack/XMPPLayer.cpp +++ b/Swiften/StreamStack/XMPPLayer.cpp @@ -15,14 +15,16 @@ XMPPLayer::XMPPLayer( PayloadParserFactoryCollection* payloadParserFactories, PayloadSerializerCollection* payloadSerializers, XMLParserFactory* xmlParserFactory, - StreamType streamType) : + StreamType streamType, + bool setExplictNSonTopLevelElements) : payloadParserFactories_(payloadParserFactories), payloadSerializers_(payloadSerializers), xmlParserFactory_(xmlParserFactory), + setExplictNSonTopLevelElements_(setExplictNSonTopLevelElements), resetParserAfterParse_(false), inParser_(false) { xmppParser_ = new XMPPParser(this, payloadParserFactories_, xmlParserFactory); - xmppSerializer_ = new XMPPSerializer(payloadSerializers_, streamType); + xmppSerializer_ = new XMPPSerializer(payloadSerializers_, streamType, setExplictNSonTopLevelElements); } XMPPLayer::~XMPPLayer() { diff --git a/Swiften/StreamStack/XMPPLayer.h b/Swiften/StreamStack/XMPPLayer.h index bb0e498..13266e4 100644 --- a/Swiften/StreamStack/XMPPLayer.h +++ b/Swiften/StreamStack/XMPPLayer.h @@ -33,7 +33,8 @@ namespace Swift { PayloadParserFactoryCollection* payloadParserFactories, PayloadSerializerCollection* payloadSerializers, XMLParserFactory* xmlParserFactory, - StreamType streamType); + StreamType streamType, + bool setExplictNSonTopLevelElements = false); ~XMPPLayer(); void writeHeader(const ProtocolHeader& header); @@ -67,6 +68,7 @@ namespace Swift { PayloadSerializerCollection* payloadSerializers_; XMLParserFactory* xmlParserFactory_; XMPPSerializer* xmppSerializer_; + bool setExplictNSonTopLevelElements_; bool resetParserAfterParse_; bool inParser_; }; |