summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-12-09 21:45:53 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-12-09 21:45:53 (GMT)
commit53e476d1c202119ddc87102208103675e47f9e43 (patch)
tree8d882982020fe515d8abc941c9c9ee2112e8cb1b
parent9bcba37ce570e0ca839cf3489fd9e34b3b5d44c8 (diff)
downloadswift-53e476d1c202119ddc87102208103675e47f9e43.zip
swift-53e476d1c202119ddc87102208103675e47f9e43.tar.bz2
Handle stream errors in client session.
-rw-r--r--Swift/Controllers/MainController.cpp1
-rw-r--r--Swiften/Client/ClientError.h1
-rw-r--r--Swiften/Client/ClientSession.cpp4
-rw-r--r--Swiften/Client/ClientSession.h1
-rw-r--r--Swiften/Client/CoreClient.cpp3
-rw-r--r--Swiften/Client/UnitTest/ClientSessionTest.cpp18
6 files changed, 28 insertions, 0 deletions
diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp
index 878ed9b..018948b 100644
--- a/Swift/Controllers/MainController.cpp
+++ b/Swift/Controllers/MainController.cpp
@@ -423,6 +423,7 @@ void MainController::handleDisconnected(const boost::optional<ClientError>& erro
case ClientError::UnexpectedElementError: message = "Unexpected response"; break;
case ClientError::ResourceBindError: message = "Error binding resource"; break;
case ClientError::SessionStartError: message = "Error starting session"; break;
+ case ClientError::StreamError: message = "Stream error"; break;
case ClientError::TLSError: message = "Encryption error"; break;
case ClientError::ClientCertificateLoadError: message = "Error loading certificate (Invalid password?)"; break;
case ClientError::ClientCertificateError: message = "Certificate not authorized"; break;
diff --git a/Swiften/Client/ClientError.h b/Swiften/Client/ClientError.h
index 7ba0322..baf1b0a 100644
--- a/Swiften/Client/ClientError.h
+++ b/Swiften/Client/ClientError.h
@@ -23,6 +23,7 @@ namespace Swift {
UnexpectedElementError,
ResourceBindError,
SessionStartError,
+ StreamError,
TLSError,
ClientCertificateLoadError,
ClientCertificateError,
diff --git a/Swiften/Client/ClientSession.cpp b/Swiften/Client/ClientSession.cpp
index 13816d3..a7f39b6 100644
--- a/Swiften/Client/ClientSession.cpp
+++ b/Swiften/Client/ClientSession.cpp
@@ -13,6 +13,7 @@
#include "Swiften/Elements/ProtocolHeader.h"
#include "Swiften/Elements/StreamFeatures.h"
+#include "Swiften/Elements/StreamError.h"
#include "Swiften/Elements/StartTLSRequest.h"
#include "Swiften/Elements/StartTLSFailure.h"
#include "Swiften/Elements/TLSProceed.h"
@@ -151,6 +152,9 @@ void ClientSession::handleElement(boost::shared_ptr<Element> element) {
std::cerr << "Warning: Ignoring ack" << std::endl;
}
}
+ else if (StreamError::ref streamError = boost::dynamic_pointer_cast<StreamError>(element)) {
+ finishSession(Error::StreamError);
+ }
else if (getState() == Initialized) {
boost::shared_ptr<Stanza> stanza = boost::dynamic_pointer_cast<Stanza>(element);
if (stanza) {
diff --git a/Swiften/Client/ClientSession.h b/Swiften/Client/ClientSession.h
index 20573a0..170491f 100644
--- a/Swiften/Client/ClientSession.h
+++ b/Swiften/Client/ClientSession.h
@@ -51,6 +51,7 @@ namespace Swift {
SessionStartError,
TLSClientCertificateError,
TLSError,
+ StreamError,
} type;
Error(Type type) : type(type) {}
};
diff --git a/Swiften/Client/CoreClient.cpp b/Swiften/Client/CoreClient.cpp
index c4e5225..ed9302d 100644
--- a/Swiften/Client/CoreClient.cpp
+++ b/Swiften/Client/CoreClient.cpp
@@ -152,6 +152,9 @@ void CoreClient::handleSessionFinished(boost::shared_ptr<Error> error) {
case ClientSession::Error::TLSClientCertificateError:
clientError = ClientError(ClientError::ClientCertificateError);
break;
+ case ClientSession::Error::StreamError:
+ clientError = ClientError(ClientError::StreamError);
+ break;
}
}
else if (boost::shared_ptr<SessionStream::Error> actualError = boost::dynamic_pointer_cast<SessionStream::Error>(error)) {
diff --git a/Swiften/Client/UnitTest/ClientSessionTest.cpp b/Swiften/Client/UnitTest/ClientSessionTest.cpp
index 74f3376..dbed9aa 100644
--- a/Swiften/Client/UnitTest/ClientSessionTest.cpp
+++ b/Swiften/Client/UnitTest/ClientSessionTest.cpp
@@ -9,11 +9,13 @@
#include <deque>
#include <boost/bind.hpp>
#include <boost/optional.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
#include "Swiften/Session/SessionStream.h"
#include "Swiften/Client/ClientSession.h"
#include "Swiften/Elements/StartTLSRequest.h"
#include "Swiften/Elements/StreamFeatures.h"
+#include "Swiften/Elements/StreamError.h"
#include "Swiften/Elements/TLSProceed.h"
#include "Swiften/Elements/StartTLSFailure.h"
#include "Swiften/Elements/AuthRequest.h"
@@ -32,6 +34,7 @@ using namespace Swift;
class ClientSessionTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(ClientSessionTest);
CPPUNIT_TEST(testStart_Error);
+ CPPUNIT_TEST(testStart_StreamError);
CPPUNIT_TEST(testStartTLS);
CPPUNIT_TEST(testStartTLS_ServerError);
CPPUNIT_TEST(testStartTLS_ConnectError);
@@ -77,6 +80,17 @@ class ClientSessionTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT(sessionFinishedError);
}
+ void testStart_StreamError() {
+ boost::shared_ptr<ClientSession> session(createSession());
+ session->start();
+ server->sendStreamStart();
+ server->sendStreamError();
+
+ CPPUNIT_ASSERT_EQUAL(ClientSession::Finished, session->getState());
+ CPPUNIT_ASSERT(sessionFinishedReceived);
+ CPPUNIT_ASSERT(sessionFinishedError);
+ }
+
void testStartTLS() {
boost::shared_ptr<ClientSession> session(createSession());
session->setCertificateTrustChecker(blindCertificateTrustChecker);
@@ -351,6 +365,10 @@ class ClientSessionTest : public CppUnit::TestFixture {
onElementReceived(streamFeatures);
}
+ void sendStreamError() {
+ onElementReceived(boost::make_shared<StreamError>());
+ }
+
void sendTLSProceed() {
onElementReceived(boost::shared_ptr<TLSProceed>(new TLSProceed()));
}