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 /Swiften/Parser | |
parent | 7f1bcf974efac0ed87b6f8f639e1fdc16a89eb09 (diff) | |
download | swift-contrib-30bbee78103b3dc125eba0f81c25e5399032d6ef.zip swift-contrib-30bbee78103b3dc125eba0f81c25e5399032d6ef.tar.bz2 |
Added elements, parsers & serializers for XEP-0198 Stanza Acking.
Diffstat (limited to 'Swiften/Parser')
-rw-r--r-- | Swiften/Parser/EnableSessionManagementParser.h | 17 | ||||
-rw-r--r-- | Swiften/Parser/SConscript | 1 | ||||
-rw-r--r-- | Swiften/Parser/SessionManagementEnabledParser.h | 17 | ||||
-rw-r--r-- | Swiften/Parser/SessionManagementFailedParser.h | 17 | ||||
-rw-r--r-- | Swiften/Parser/StanzaAckParser.cpp | 33 | ||||
-rw-r--r-- | Swiften/Parser/StanzaAckParser.h | 23 | ||||
-rw-r--r-- | Swiften/Parser/StanzaAckRequestParser.h | 17 | ||||
-rw-r--r-- | Swiften/Parser/XMPPParser.cpp | 20 |
8 files changed, 145 insertions, 0 deletions
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(); } |