diff options
author | Remko Tronçon <git@el-tramo.be> | 2010-10-15 16:15:57 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2010-10-15 16:15:57 (GMT) |
commit | 062658db9f46ef749eeec09c162e5afaf1524ab6 (patch) | |
tree | 12ea883e39c7d938310ea715c71127bc1801319c /Swiften/Parser | |
parent | f52aa93c3d6d5976b072d31f3d3336beb1596ece (diff) | |
download | swift-062658db9f46ef749eeec09c162e5afaf1524ab6.zip swift-062658db9f46ef749eeec09c162e5afaf1524ab6.tar.bz2 |
Added Component parser, serializer, element, and connector.
Diffstat (limited to 'Swiften/Parser')
-rw-r--r-- | Swiften/Parser/ComponentHandshakeParser.cpp | 30 | ||||
-rw-r--r-- | Swiften/Parser/ComponentHandshakeParser.h | 26 | ||||
-rw-r--r-- | Swiften/Parser/SConscript | 1 | ||||
-rw-r--r-- | Swiften/Parser/UnitTest/XMPPParserTest.cpp | 19 | ||||
-rw-r--r-- | Swiften/Parser/XMPPParser.cpp | 4 |
5 files changed, 68 insertions, 12 deletions
diff --git a/Swiften/Parser/ComponentHandshakeParser.cpp b/Swiften/Parser/ComponentHandshakeParser.cpp new file mode 100644 index 0000000..e88adb3 --- /dev/null +++ b/Swiften/Parser/ComponentHandshakeParser.cpp @@ -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. + */ + +#include "Swiften/Parser/ComponentHandshakeParser.h" +#include "Swiften/StringCodecs/Base64.h" + +namespace Swift { + +ComponentHandshakeParser::ComponentHandshakeParser() : GenericElementParser<ComponentHandshake>(), depth(0) { +} + +void ComponentHandshakeParser::handleStartElement(const String&, const String&, const AttributeMap&) { + ++depth; +} + +void ComponentHandshakeParser::handleEndElement(const String&, const String&) { + --depth; + if (depth == 0) { + getElementGeneric()->setData(text); + } +} + +void ComponentHandshakeParser::handleCharacterData(const String& text) { + this->text += text; +} + +} diff --git a/Swiften/Parser/ComponentHandshakeParser.h b/Swiften/Parser/ComponentHandshakeParser.h new file mode 100644 index 0000000..de5b8e1 --- /dev/null +++ b/Swiften/Parser/ComponentHandshakeParser.h @@ -0,0 +1,26 @@ +/* + * 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/ComponentHandshake.h" +#include "Swiften/Base/String.h" + +namespace Swift { + class ComponentHandshakeParser : public GenericElementParser<ComponentHandshake> { + public: + ComponentHandshakeParser(); + + virtual void handleStartElement(const String&, const String& ns, const AttributeMap&); + virtual void handleEndElement(const String&, const String& ns); + virtual void handleCharacterData(const String&); + + private: + int depth; + String text; + }; +} diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript index 9cd6b31..0256cbf 100644 --- a/Swiften/Parser/SConscript +++ b/Swiften/Parser/SConscript @@ -16,6 +16,7 @@ sources = [ "MessageParser.cpp", "PayloadParser.cpp", "StanzaAckParser.cpp", + "ComponentHandshakeParser.cpp", "PayloadParserFactory.cpp", "PayloadParserFactoryCollection.cpp", "PayloadParsers/BodyParser.cpp", diff --git a/Swiften/Parser/UnitTest/XMPPParserTest.cpp b/Swiften/Parser/UnitTest/XMPPParserTest.cpp index cd42b90..90a4b03 100644 --- a/Swiften/Parser/UnitTest/XMPPParserTest.cpp +++ b/Swiften/Parser/UnitTest/XMPPParserTest.cpp @@ -22,8 +22,7 @@ using namespace Swift; -class XMPPParserTest : public CppUnit::TestFixture -{ +class XMPPParserTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(XMPPParserTest); CPPUNIT_TEST(testParse_SimpleSession); CPPUNIT_TEST(testParse_SimpleClientFromServerSession); @@ -37,8 +36,6 @@ class XMPPParserTest : public CppUnit::TestFixture CPPUNIT_TEST_SUITE_END(); public: - XMPPParserTest() {} - void testParse_SimpleSession() { XMPPParser testling(&client_, &factories_); @@ -51,7 +48,7 @@ class XMPPParserTest : public CppUnit::TestFixture CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(client_.events.size())); CPPUNIT_ASSERT_EQUAL(Client::StreamStart, client_.events[0].type); - CPPUNIT_ASSERT_EQUAL(String("example.com"), client_.events[0].to); + CPPUNIT_ASSERT_EQUAL(String("example.com"), client_.events[0].header->getTo()); CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[1].type); CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[2].type); CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[3].type); @@ -66,8 +63,8 @@ class XMPPParserTest : public CppUnit::TestFixture CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(client_.events.size())); CPPUNIT_ASSERT_EQUAL(Client::StreamStart, client_.events[0].type); - CPPUNIT_ASSERT_EQUAL(String("example.com"), client_.events[0].from); - CPPUNIT_ASSERT_EQUAL(String("aeab"), client_.events[0].id); + CPPUNIT_ASSERT_EQUAL(String("example.com"), client_.events[0].header->getFrom()); + CPPUNIT_ASSERT_EQUAL(String("aeab"), client_.events[0].header->getID()); } @@ -159,21 +156,19 @@ class XMPPParserTest : public CppUnit::TestFixture struct Event { Event(Type type, boost::shared_ptr<Element> element) : type(type), element(element) {} - Event(Type type, const String& from, const String& to, const String& id) : type(type), from(from), to(to), id(id) {} + Event(Type type, const ProtocolHeader& header) : type(type), header(header) {} Event(Type type) : type(type) {} Type type; - String from; - String to; - String id; + boost::optional<ProtocolHeader> header; boost::shared_ptr<Element> element; }; Client() {} void handleStreamStart(const ProtocolHeader& header) { - events.push_back(Event(StreamStart, header.getFrom(), header.getTo(), header.getID())); + events.push_back(Event(StreamStart, header)); } void handleElement(boost::shared_ptr<Element> element) { diff --git a/Swiften/Parser/XMPPParser.cpp b/Swiften/Parser/XMPPParser.cpp index 795bee6..93797b3 100644 --- a/Swiften/Parser/XMPPParser.cpp +++ b/Swiften/Parser/XMPPParser.cpp @@ -37,6 +37,7 @@ #include "Swiften/Parser/CompressedParser.h" #include "Swiften/Parser/UnknownElementParser.h" #include "Swiften/Parser/TLSProceedParser.h" +#include "Swiften/Parser/ComponentHandshakeParser.h" // TODO: Whenever an error occurs in the handlers, stop the parser by returing // a bool value, and stopping the XML parser @@ -177,6 +178,9 @@ ElementParser* XMPPParser::createElementParser(const String& element, const Stri else if (element == "r" && ns == "urn:xmpp:sm:2") { return new StanzaAckRequestParser(); } + else if (element == "handshake") { + return new ComponentHandshakeParser(); + } return new UnknownElementParser(); } |