diff options
author | Remko Tronçon <git@el-tramo.be> | 2010-08-28 21:45:20 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2010-08-28 21:54:37 (GMT) |
commit | 30bbee78103b3dc125eba0f81c25e5399032d6ef (patch) | |
tree | 8aba7a0099eb6fff7c8b73a113b8a8b561d15706 | |
parent | 7f1bcf974efac0ed87b6f8f639e1fdc16a89eb09 (diff) | |
download | swift-contrib-30bbee78103b3dc125eba0f81c25e5399032d6ef.zip swift-contrib-30bbee78103b3dc125eba0f81c25e5399032d6ef.tar.bz2 |
Added elements, parsers & serializers for XEP-0198 Stanza Acking.
19 files changed, 383 insertions, 0 deletions
diff --git a/Swiften/Elements/EnableSessionManagement.h b/Swiften/Elements/EnableSessionManagement.h new file mode 100644 index 0000000..f89ac2e --- /dev/null +++ b/Swiften/Elements/EnableSessionManagement.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include "Swiften/Elements/Element.h" +#include "Swiften/Base/Shared.h" + +namespace Swift { + class EnableSessionManagement : public Element, public Shared<EnableSessionManagement> { + public: + EnableSessionManagement() {} + }; +} diff --git a/Swiften/Elements/SessionManagementEnabled.h b/Swiften/Elements/SessionManagementEnabled.h new file mode 100644 index 0000000..1645ca4 --- /dev/null +++ b/Swiften/Elements/SessionManagementEnabled.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include "Swiften/Elements/Element.h" +#include "Swiften/Base/Shared.h" + +namespace Swift { + class SessionManagementEnabled : public Element, public Shared<SessionManagementEnabled> { + public: + SessionManagementEnabled() {} + }; +} diff --git a/Swiften/Elements/SessionManagementFailed.h b/Swiften/Elements/SessionManagementFailed.h new file mode 100644 index 0000000..e71f2a6 --- /dev/null +++ b/Swiften/Elements/SessionManagementFailed.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include "Swiften/Elements/Element.h" +#include "Swiften/Base/Shared.h" + +namespace Swift { + class SessionManagementFailed : public Element, public Shared<SessionManagementFailed> { + public: + SessionManagementFailed() {} + }; +} diff --git a/Swiften/Elements/StanzaAck.h b/Swiften/Elements/StanzaAck.h new file mode 100644 index 0000000..a1a39f8 --- /dev/null +++ b/Swiften/Elements/StanzaAck.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include "Swiften/Elements/Element.h" +#include "Swiften/Base/Shared.h" + +namespace Swift { + class StanzaAck : public Element, public Shared<StanzaAck> { + public: + StanzaAck() : handledStanzasCount(-1) {} + + int getHandledStanzasCount() const { + return handledStanzasCount; + } + + void setHandledStanzasCount(int i) { + handledStanzasCount = i; + } + + bool isValid() const { + return handledStanzasCount != -1; + } + + private: + int handledStanzasCount; + }; +} diff --git a/Swiften/Elements/StanzaAckRequest.h b/Swiften/Elements/StanzaAckRequest.h new file mode 100644 index 0000000..ab4f354 --- /dev/null +++ b/Swiften/Elements/StanzaAckRequest.h @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include "Swiften/Elements/Element.h" +#include "Swiften/Base/Shared.h" + +namespace Swift { + class StanzaAckRequest : public Element, public Shared<StanzaAckRequest> { + }; +} diff --git a/Swiften/Parser/EnableSessionManagementParser.h b/Swiften/Parser/EnableSessionManagementParser.h new file mode 100644 index 0000000..8a878fd --- /dev/null +++ b/Swiften/Parser/EnableSessionManagementParser.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include "Swiften/Parser/GenericElementParser.h" +#include "Swiften/Elements/EnableSessionManagement.h" + +namespace Swift { + class EnableSessionManagementParser : public GenericElementParser<EnableSessionManagement> { + public: + EnableSessionManagementParser() : GenericElementParser<EnableSessionManagement>() {} + }; +} diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript index 4efd343..4ab70a4 100644 --- a/Swiften/Parser/SConscript +++ b/Swiften/Parser/SConscript @@ -15,6 +15,7 @@ sources = [ "IQParser.cpp", "MessageParser.cpp", "PayloadParser.cpp", + "StanzaAckParser.cpp", "PayloadParserFactory.cpp", "PayloadParserFactoryCollection.cpp", "PayloadParsers/BodyParser.cpp", diff --git a/Swiften/Parser/SessionManagementEnabledParser.h b/Swiften/Parser/SessionManagementEnabledParser.h new file mode 100644 index 0000000..968ea3e --- /dev/null +++ b/Swiften/Parser/SessionManagementEnabledParser.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include "Swiften/Parser/GenericElementParser.h" +#include "Swiften/Elements/SessionManagementEnabled.h" + +namespace Swift { + class SessionManagementEnabledParser : public GenericElementParser<SessionManagementEnabled> { + public: + SessionManagementEnabledParser() : GenericElementParser<SessionManagementEnabled>() {} + }; +} diff --git a/Swiften/Parser/SessionManagementFailedParser.h b/Swiften/Parser/SessionManagementFailedParser.h new file mode 100644 index 0000000..945cade --- /dev/null +++ b/Swiften/Parser/SessionManagementFailedParser.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include "Swiften/Parser/GenericElementParser.h" +#include "Swiften/Elements/SessionManagementFailed.h" + +namespace Swift { + class SessionManagementFailedParser : public GenericElementParser<SessionManagementFailed> { + public: + SessionManagementFailedParser() : GenericElementParser<SessionManagementFailed>() {} + }; +} diff --git a/Swiften/Parser/StanzaAckParser.cpp b/Swiften/Parser/StanzaAckParser.cpp new file mode 100644 index 0000000..62e912b --- /dev/null +++ b/Swiften/Parser/StanzaAckParser.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "Swiften/Parser/StanzaAckParser.h" + +#include <boost/lexical_cast.hpp> + +namespace Swift { + +StanzaAckParser::StanzaAckParser() : GenericElementParser<StanzaAck>(), depth(0) { +} + +void StanzaAckParser::handleStartElement(const String&, const String&, const AttributeMap& attributes) { + if (depth == 0) { + String handledStanzasString = attributes.getAttribute("h"); + try { + getElementGeneric()->setHandledStanzasCount(boost::lexical_cast<int>(handledStanzasString.getUTF8String())); + } + catch (const boost::bad_lexical_cast &) { + getElementGeneric()->setHandledStanzasCount(-1); + } + } + ++depth; +} + +void StanzaAckParser::handleEndElement(const String&, const String&) { + --depth; +} + +} diff --git a/Swiften/Parser/StanzaAckParser.h b/Swiften/Parser/StanzaAckParser.h new file mode 100644 index 0000000..fa9644f --- /dev/null +++ b/Swiften/Parser/StanzaAckParser.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include "Swiften/Parser/GenericElementParser.h" +#include "Swiften/Elements/StanzaAck.h" + +namespace Swift { + class StanzaAckParser : public GenericElementParser<StanzaAck> { + public: + StanzaAckParser(); + + virtual void handleStartElement(const String&, const String& ns, const AttributeMap&); + virtual void handleEndElement(const String&, const String& ns); + + private: + int depth; + }; +} diff --git a/Swiften/Parser/StanzaAckRequestParser.h b/Swiften/Parser/StanzaAckRequestParser.h new file mode 100644 index 0000000..82290c6 --- /dev/null +++ b/Swiften/Parser/StanzaAckRequestParser.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include "Swiften/Parser/GenericElementParser.h" +#include "Swiften/Elements/StanzaAckRequest.h" + +namespace Swift { + class StanzaAckRequestParser : public GenericElementParser<StanzaAckRequest> { + public: + StanzaAckRequestParser() : GenericElementParser<StanzaAckRequest>() {} + }; +} diff --git a/Swiften/Parser/XMPPParser.cpp b/Swiften/Parser/XMPPParser.cpp index 827eda4..9b8a604 100644 --- a/Swiften/Parser/XMPPParser.cpp +++ b/Swiften/Parser/XMPPParser.cpp @@ -25,6 +25,11 @@ #include "Swiften/Parser/AuthFailureParser.h" #include "Swiften/Parser/AuthChallengeParser.h" #include "Swiften/Parser/AuthResponseParser.h" +#include "Swiften/Parser/EnableSessionManagementParser.h" +#include "Swiften/Parser/SessionManagementEnabledParser.h" +#include "Swiften/Parser/SessionManagementFailedParser.h" +#include "Swiften/Parser/StanzaAckParser.h" +#include "Swiften/Parser/StanzaAckRequestParser.h" #include "Swiften/Parser/StartTLSParser.h" #include "Swiften/Parser/StartTLSFailureParser.h" #include "Swiften/Parser/CompressParser.h" @@ -159,6 +164,21 @@ ElementParser* XMPPParser::createElementParser(const String& element, const Stri else if (element == "proceed") { return new TLSProceedParser(); } + else if (element == "enable" && ns == "urn:xmpp:sm:2") { + return new EnableSessionManagementParser(); + } + else if (element == "enabled" && ns == "urn:xmpp:sm:2") { + return new SessionManagementEnabledParser(); + } + else if (element == "failed" && ns == "urn:xmpp:sm:2") { + return new SessionManagementFailedParser(); + } + else if (element == "a" && ns == "urn:xmpp:sm:2") { + return new StanzaAckParser(); + } + else if (element == "r" && ns == "urn:xmpp:sm:2") { + return new StanzaAckRequestParser(); + } return new UnknownElementParser(); } diff --git a/Swiften/Serializer/EnableSessionManagementSerializer.h b/Swiften/Serializer/EnableSessionManagementSerializer.h new file mode 100644 index 0000000..0820cdf --- /dev/null +++ b/Swiften/Serializer/EnableSessionManagementSerializer.h @@ -0,0 +1,25 @@ +/* + * 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/shared_ptr.hpp> + +#include "Swiften/Elements/EnableSessionManagement.h" +#include "Swiften/Serializer/GenericElementSerializer.h" +#include "Swiften/Serializer/XML/XMLElement.h" + +namespace Swift { + class EnableSessionManagementSerializer : public GenericElementSerializer<EnableSessionManagement> { + public: + EnableSessionManagementSerializer() : GenericElementSerializer<EnableSessionManagement>() { + } + + virtual String serialize(boost::shared_ptr<Element>) const { + return XMLElement("enable", "urn:xmpp:sm:2").serialize(); + } + }; +} diff --git a/Swiften/Serializer/SessionManagementEnabledSerializer.h b/Swiften/Serializer/SessionManagementEnabledSerializer.h new file mode 100644 index 0000000..4c492b7 --- /dev/null +++ b/Swiften/Serializer/SessionManagementEnabledSerializer.h @@ -0,0 +1,25 @@ +/* + * 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/shared_ptr.hpp> + +#include "Swiften/Elements/SessionManagementEnabled.h" +#include "Swiften/Serializer/GenericElementSerializer.h" +#include "Swiften/Serializer/XML/XMLElement.h" + +namespace Swift { + class SessionManagementEnabledSerializer : public GenericElementSerializer<SessionManagementEnabled> { + public: + SessionManagementEnabledSerializer() : GenericElementSerializer<SessionManagementEnabled>() { + } + + virtual String serialize(boost::shared_ptr<Element>) const { + return XMLElement("enabled", "urn:xmpp:sm:2").serialize(); + } + }; +} diff --git a/Swiften/Serializer/SessionManagementFailedSerializer.h b/Swiften/Serializer/SessionManagementFailedSerializer.h new file mode 100644 index 0000000..ecc0cb8 --- /dev/null +++ b/Swiften/Serializer/SessionManagementFailedSerializer.h @@ -0,0 +1,25 @@ +/* + * 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/shared_ptr.hpp> + +#include "Swiften/Elements/SessionManagementFailed.h" +#include "Swiften/Serializer/GenericElementSerializer.h" +#include "Swiften/Serializer/XML/XMLElement.h" + +namespace Swift { + class SessionManagementFailedSerializer : public GenericElementSerializer<SessionManagementFailed> { + public: + SessionManagementFailedSerializer() : GenericElementSerializer<SessionManagementFailed>() { + } + + virtual String serialize(boost::shared_ptr<Element>) const { + return XMLElement("failed", "urn:xmpp:sm:2").serialize(); + } + }; +} diff --git a/Swiften/Serializer/StanzaAckRequestSerializer.h b/Swiften/Serializer/StanzaAckRequestSerializer.h new file mode 100644 index 0000000..26d015d --- /dev/null +++ b/Swiften/Serializer/StanzaAckRequestSerializer.h @@ -0,0 +1,25 @@ +/* + * 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/shared_ptr.hpp> + +#include "Swiften/Elements/StanzaAckRequest.h" +#include "Swiften/Serializer/GenericElementSerializer.h" +#include "Swiften/Serializer/XML/XMLElement.h" + +namespace Swift { + class StanzaAckRequestSerializer : public GenericElementSerializer<StanzaAckRequest> { + public: + StanzaAckRequestSerializer() : GenericElementSerializer<StanzaAckRequest>() { + } + + virtual String serialize(boost::shared_ptr<Element>) const { + return XMLElement("r", "urn:xmpp:sm:2").serialize(); + } + }; +} diff --git a/Swiften/Serializer/StanzaAckSerializer.h b/Swiften/Serializer/StanzaAckSerializer.h new file mode 100644 index 0000000..eb957b9 --- /dev/null +++ b/Swiften/Serializer/StanzaAckSerializer.h @@ -0,0 +1,30 @@ +/* + * 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/shared_ptr.hpp> +#include <boost/lexical_cast.hpp> + +#include "Swiften/Elements/StanzaAck.h" +#include "Swiften/Serializer/GenericElementSerializer.h" +#include "Swiften/Serializer/XML/XMLElement.h" + +namespace Swift { + class StanzaAckSerializer : public GenericElementSerializer<StanzaAck> { + public: + StanzaAckSerializer() : GenericElementSerializer<StanzaAck>() { + } + + virtual String serialize(boost::shared_ptr<Element> element) const { + StanzaAck::ref stanzaAck = StanzaAck::cast(element); + assert(stanzaAck->isValid()); + XMLElement result("a", "urn:xmpp:sm:2"); + result.setAttribute("h", String(boost::lexical_cast<std::string>(stanzaAck->getHandledStanzasCount()))); + return result.serialize(); + } + }; +} diff --git a/Swiften/Serializer/XMPPSerializer.cpp b/Swiften/Serializer/XMPPSerializer.cpp index c55600d..b619cae 100644 --- a/Swiften/Serializer/XMPPSerializer.cpp +++ b/Swiften/Serializer/XMPPSerializer.cpp @@ -19,6 +19,11 @@ #include "Swiften/Serializer/AuthSuccessSerializer.h" #include "Swiften/Serializer/AuthChallengeSerializer.h" #include "Swiften/Serializer/AuthResponseSerializer.h" +#include "Swiften/Serializer/EnableSessionManagementSerializer.h" +#include "Swiften/Serializer/SessionManagementEnabledSerializer.h" +#include "Swiften/Serializer/SessionManagementFailedSerializer.h" +#include "Swiften/Serializer/StanzaAckSerializer.h" +#include "Swiften/Serializer/StanzaAckRequestSerializer.h" #include "Swiften/Serializer/StartTLSRequestSerializer.h" #include "Swiften/Serializer/StartTLSFailureSerializer.h" #include "Swiften/Serializer/TLSProceedSerializer.h" @@ -43,6 +48,11 @@ XMPPSerializer::XMPPSerializer(PayloadSerializerCollection* payloadSerializers) serializers_.push_back(boost::shared_ptr<ElementSerializer>(new StartTLSFailureSerializer())); serializers_.push_back(boost::shared_ptr<ElementSerializer>(new TLSProceedSerializer())); serializers_.push_back(boost::shared_ptr<ElementSerializer>(new StreamFeaturesSerializer())); + serializers_.push_back(boost::shared_ptr<ElementSerializer>(new EnableSessionManagementSerializer())); + serializers_.push_back(boost::shared_ptr<ElementSerializer>(new SessionManagementEnabledSerializer())); + serializers_.push_back(boost::shared_ptr<ElementSerializer>(new SessionManagementFailedSerializer())); + serializers_.push_back(boost::shared_ptr<ElementSerializer>(new StanzaAckSerializer())); + serializers_.push_back(boost::shared_ptr<ElementSerializer>(new StanzaAckRequestSerializer())); } String XMPPSerializer::serializeHeader(const ProtocolHeader& header) const { |