summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-07-13 07:17:57 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-07-13 07:18:39 (GMT)
commit6ca206b0d0645e50a8a2c59ebd134f9c0f164b9b (patch)
tree1c4d785f79941b07e7c7d7473fe98d09229b5fa6 /Swiften/Parser
parent72858ab262a16aa8db209c2898ab0d3c951a9829 (diff)
downloadswift-6ca206b0d0645e50a8a2c59ebd134f9c0f164b9b.zip
swift-6ca206b0d0645e50a8a2c59ebd134f9c0f164b9b.tar.bz2
Server stream header support.
Diffstat (limited to 'Swiften/Parser')
-rw-r--r--Swiften/Parser/UnitTest/XMPPParserTest.cpp23
-rw-r--r--Swiften/Parser/XMPPParser.cpp2
-rw-r--r--Swiften/Parser/XMPPParserClient.h2
3 files changed, 23 insertions, 4 deletions
diff --git a/Swiften/Parser/UnitTest/XMPPParserTest.cpp b/Swiften/Parser/UnitTest/XMPPParserTest.cpp
index 787828c..a8b805e 100644
--- a/Swiften/Parser/UnitTest/XMPPParserTest.cpp
+++ b/Swiften/Parser/UnitTest/XMPPParserTest.cpp
@@ -19,6 +19,7 @@ class XMPPParserTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(XMPPParserTest);
CPPUNIT_TEST(testParse_SimpleSession);
+ CPPUNIT_TEST(testParse_SimpleClientFromServerSession);
CPPUNIT_TEST(testParse_Presence);
CPPUNIT_TEST(testParse_IQ);
CPPUNIT_TEST(testParse_Message);
@@ -43,12 +44,26 @@ 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(Client::ElementEvent, client_.events[1].type);
CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[2].type);
CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[3].type);
CPPUNIT_ASSERT_EQUAL(Client::StreamEnd, client_.events[4].type);
}
+ void testParse_SimpleClientFromServerSession() {
+ XMPPParser testling(&client_, &factories_);
+
+ CPPUNIT_ASSERT(testling.parse("<?xml version='1.0'?>"));
+ CPPUNIT_ASSERT(testling.parse("<stream:stream from='example.com' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='aeab'>"));
+
+ 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);
+ }
+
+
void testParse_Presence() {
XMPPParser testling(&client_, &factories_);
@@ -137,17 +152,21 @@ 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) : type(type) {}
Type type;
+ String from;
+ String to;
+ String id;
boost::shared_ptr<Element> element;
};
Client() {}
- void handleStreamStart() {
- events.push_back(Event(StreamStart));
+ void handleStreamStart(const String& from, const String& to, const String& id) {
+ events.push_back(Event(StreamStart, from, to, id));
}
void handleElement(boost::shared_ptr<Element> element) {
diff --git a/Swiften/Parser/XMPPParser.cpp b/Swiften/Parser/XMPPParser.cpp
index 59cfce7..0f04cca 100644
--- a/Swiften/Parser/XMPPParser.cpp
+++ b/Swiften/Parser/XMPPParser.cpp
@@ -54,7 +54,7 @@ bool XMPPParser::parse(const String& data) {
void XMPPParser::handleStartElement(const String& element, const String& ns, const AttributeMap& attributes) {
if (!inStream()) {
if (element == "stream" && ns == "http://etherx.jabber.org/streams") {
- client_->handleStreamStart(attributes.getAttribute("to"));
+ client_->handleStreamStart(attributes.getAttribute("from"), attributes.getAttribute("to"), attributes.getAttribute("id"));
}
else {
parseErrorOccurred_ = true;
diff --git a/Swiften/Parser/XMPPParserClient.h b/Swiften/Parser/XMPPParserClient.h
index d19c7d0..fb81df8 100644
--- a/Swiften/Parser/XMPPParserClient.h
+++ b/Swiften/Parser/XMPPParserClient.h
@@ -12,7 +12,7 @@ namespace Swift {
public:
virtual ~XMPPParserClient();
- virtual void handleStreamStart(const String& header) = 0;
+ virtual void handleStreamStart(const String& from, const String& to, const String& id) = 0;
virtual void handleElement(boost::shared_ptr<Element>) = 0;
virtual void handleStreamEnd() = 0;
};