diff options
Diffstat (limited to 'Swiften/Parser/PayloadParsers')
8 files changed, 216 insertions, 0 deletions
diff --git a/Swiften/Parser/PayloadParsers/DeliveryReceiptParser.cpp b/Swiften/Parser/PayloadParsers/DeliveryReceiptParser.cpp new file mode 100644 index 0000000..347200d --- /dev/null +++ b/Swiften/Parser/PayloadParsers/DeliveryReceiptParser.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2011 Tobias Markmann + * Licensed under the BSD license. + * See http://www.opensource.org/licenses/bsd-license.php for more information. + */ + +#include <Swiften/Parser/PayloadParsers/DeliveryReceiptParser.h> + +#include <boost/optional.hpp> + +namespace Swift { + +DeliveryReceiptParser::DeliveryReceiptParser() : level_(0) { +} + +void DeliveryReceiptParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributeMap) { + if (level_ == 0) { + if (element == "received") { + if (attributeMap.getAttributeValue("id").is_initialized()) { + getPayloadInternal()->setReceivedID(attributeMap.getAttributeValue("id").get()); + } + } + } + ++level_; +} + +void DeliveryReceiptParser::handleEndElement(const std::string&, const std::string&) { + --level_; +} + +void DeliveryReceiptParser::handleCharacterData(const std::string&) { + +} + +} diff --git a/Swiften/Parser/PayloadParsers/DeliveryReceiptParser.h b/Swiften/Parser/PayloadParsers/DeliveryReceiptParser.h new file mode 100644 index 0000000..90a0921 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/DeliveryReceiptParser.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2011 Tobias Markmann + * Licensed under the BSD license. + * See http://www.opensource.org/licenses/bsd-license.php for more information. + */ + +#pragma once + +#include <Swiften/Elements/DeliveryReceipt.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class DeliveryReceiptParser : public GenericPayloadParser<DeliveryReceipt> { + public: + DeliveryReceiptParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributeMap); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); + + private: + int level_; + }; +} diff --git a/Swiften/Parser/PayloadParsers/DeliveryReceiptParserFactory.h b/Swiften/Parser/PayloadParsers/DeliveryReceiptParserFactory.h new file mode 100644 index 0000000..259e04a --- /dev/null +++ b/Swiften/Parser/PayloadParsers/DeliveryReceiptParserFactory.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2011 Tobias Markmann + * Licensed under the BSD license. + * See http://www.opensource.org/licenses/bsd-license.php for more information. + */ + +#pragma once + +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/DeliveryReceiptParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + + class DeliveryReceiptParserFactory : public PayloadParserFactory { + public: + DeliveryReceiptParserFactory() { + } + + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { + return ns == "urn:xmpp:receipts" && element == "received"; + } + + virtual PayloadParser* createPayloadParser() { + return new DeliveryReceiptParser(); + } + + }; +} diff --git a/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.cpp b/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.cpp new file mode 100644 index 0000000..f10cbc9 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2011 Tobias Markmann + * Licensed under the BSD license. + * See http://www.opensource.org/licenses/bsd-license.php for more information. + */ + +#include <Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.h> + +#include <boost/optional.hpp> + +#include <Swiften/Base/Log.h> + +namespace Swift { + +DeliveryReceiptRequestParser::DeliveryReceiptRequestParser() { +} + +void DeliveryReceiptRequestParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { + +} + +void DeliveryReceiptRequestParser::handleEndElement(const std::string&, const std::string&) { + +} + +void DeliveryReceiptRequestParser::handleCharacterData(const std::string&) { + +} + +} diff --git a/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.h b/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.h new file mode 100644 index 0000000..55f7997 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2011 Tobias Markmann + * Licensed under the BSD license. + * See http://www.opensource.org/licenses/bsd-license.php for more information. + */ + +#pragma once + +#include <Swiften/Elements/DeliveryReceiptRequest.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class DeliveryReceiptRequestParser : public GenericPayloadParser<DeliveryReceiptRequest> { + public: + DeliveryReceiptRequestParser(); + + virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&); + virtual void handleEndElement(const std::string&, const std::string&); + virtual void handleCharacterData(const std::string& data); + }; +} diff --git a/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParserFactory.h b/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParserFactory.h new file mode 100644 index 0000000..9bd98c2 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParserFactory.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2011 Tobias Markmann + * Licensed under the BSD license. + * See http://www.opensource.org/licenses/bsd-license.php for more information. + */ + +#pragma once + +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + + class DeliveryReceiptRequestParserFactory : public PayloadParserFactory { + public: + DeliveryReceiptRequestParserFactory() { + } + + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { + return ns == "urn:xmpp:receipts" && element == "request"; + } + + virtual PayloadParser* createPayloadParser() { + return new DeliveryReceiptRequestParser(); + } + + }; +} diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp index 04e9fa6..01addf5 100644 --- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp +++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp @@ -64,6 +64,8 @@ #include <Swiften/Parser/PayloadParsers/S5BProxyRequestParser.h> #include <Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.h> #include <Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h> +#include <Swiften/Parser/PayloadParsers/DeliveryReceiptParserFactory.h> +#include <Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParserFactory.h> using namespace boost; @@ -121,6 +123,8 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() { factories_.push_back(boost::make_shared<GenericPayloadParserFactory<JingleFileTransferReceivedParser> >("received", "urn:xmpp:jingle:apps:file-transfer:3")); factories_.push_back(boost::make_shared<GenericPayloadParserFactory<JingleFileTransferHashParser> >("checksum")); factories_.push_back(boost::make_shared<GenericPayloadParserFactory<S5BProxyRequestParser> >("query", "http://jabber.org/protocol/bytestreams")); + factories_.push_back(boost::make_shared<DeliveryReceiptParserFactory>()); + factories_.push_back(boost::make_shared<DeliveryReceiptRequestParserFactory>()); foreach(shared_ptr<PayloadParserFactory> factory, factories_) { addFactory(factory.get()); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/DeliveryReceiptParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/DeliveryReceiptParserTest.cpp new file mode 100644 index 0000000..919c342 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/DeliveryReceiptParserTest.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2011 Tobias Markmann + * Licensed under the BSD license. + * See http://www.opensource.org/licenses/bsd-license.php for more information. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include <Swiften/Elements/Message.h> +#include <Swiften/Parser/PayloadParsers/DeliveryReceiptParser.h> +#include <Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> + +using namespace Swift; + +class DeliveryReceiptParserTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(DeliveryReceiptParserTest); + CPPUNIT_TEST(testParseXEP0184Example3); + CPPUNIT_TEST(testParseXEP0184Example4); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParseXEP0184Example3() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse("<request xmlns='urn:xmpp:receipts'/>")); + + DeliveryReceiptRequest::ref request = boost::dynamic_pointer_cast<DeliveryReceiptRequest>(parser.getPayload()); + + CPPUNIT_ASSERT(request); + } + + void testParseXEP0184Example4() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse("<received xmlns='urn:xmpp:receipts' id='richard2-4.1.247'/>")); + + DeliveryReceipt::ref receipt = boost::dynamic_pointer_cast<DeliveryReceipt>(parser.getPayload()); + + CPPUNIT_ASSERT_EQUAL(std::string("richard2-4.1.247"), receipt->getReceivedID()); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(DeliveryReceiptParserTest); + |