summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Session')
-rw-r--r--Swiften/Session/BasicSessionStream.cpp20
-rw-r--r--Swiften/Session/BasicSessionStream.h2
-rw-r--r--Swiften/Session/SessionStream.h13
3 files changed, 28 insertions, 7 deletions
diff --git a/Swiften/Session/BasicSessionStream.cpp b/Swiften/Session/BasicSessionStream.cpp
index 115dc7c..8b14367 100644
--- a/Swiften/Session/BasicSessionStream.cpp
+++ b/Swiften/Session/BasicSessionStream.cpp
@@ -1,5 +1,3 @@
-// TODO: Send out better errors
-
#include "Swiften/Session/BasicSessionStream.h"
#include <boost/bind.hpp>
@@ -23,6 +21,8 @@ void BasicSessionStream::initialize() {
xmppLayer->onElement.connect(boost::bind(&BasicSessionStream::handleElementReceived, shared_from_this(), _1));
xmppLayer->onError.connect(boost::bind(
&BasicSessionStream::handleXMPPError, shared_from_this()));
+ xmppLayer->onDataRead.connect(boost::bind(&BasicSessionStream::handleDataRead, shared_from_this(), _1));
+ xmppLayer->onWriteData.connect(boost::bind(&BasicSessionStream::handleDataWritten, shared_from_this(), _1));
connection->onDisconnected.connect(boost::bind(&BasicSessionStream::handleConnectionError, shared_from_this(), _1));
connectionLayer = boost::shared_ptr<ConnectionLayer>(
@@ -64,7 +64,7 @@ void BasicSessionStream::addTLSEncryption() {
assert(available);
tlsLayer = tlsLayerFactory->createTLSLayer();
if (hasTLSCertificate() && !tlsLayer->setClientCertificate(getTLSCertificate())) {
- onError(boost::shared_ptr<Error>(new Error()));
+ onError(boost::shared_ptr<Error>(new Error(Error::InvalidTLSCertificateError)));
}
else {
streamStack->addLayer(tlsLayer);
@@ -101,7 +101,7 @@ void BasicSessionStream::handleElementReceived(boost::shared_ptr<Element> elemen
void BasicSessionStream::handleXMPPError() {
available = false;
- onError(boost::shared_ptr<Error>(new Error()));
+ onError(boost::shared_ptr<Error>(new Error(Error::ParseError)));
}
void BasicSessionStream::handleTLSConnected() {
@@ -110,12 +110,20 @@ void BasicSessionStream::handleTLSConnected() {
void BasicSessionStream::handleTLSError() {
available = false;
- onError(boost::shared_ptr<Error>(new Error()));
+ onError(boost::shared_ptr<Error>(new Error(Error::TLSError)));
}
void BasicSessionStream::handleConnectionError(const boost::optional<Connection::Error>&) {
available = false;
- onError(boost::shared_ptr<Error>(new Error()));
+ onError(boost::shared_ptr<Error>(new Error(Error::ConnectionError)));
+}
+
+void BasicSessionStream::handleDataRead(const ByteArray& data) {
+ onDataRead(String(data.getData(), data.getSize()));
+}
+
+void BasicSessionStream::handleDataWritten(const ByteArray& data) {
+ onDataWritten(String(data.getData(), data.getSize()));
}
};
diff --git a/Swiften/Session/BasicSessionStream.h b/Swiften/Session/BasicSessionStream.h
index 5fe0b4c..0cb50eb 100644
--- a/Swiften/Session/BasicSessionStream.h
+++ b/Swiften/Session/BasicSessionStream.h
@@ -50,6 +50,8 @@ namespace Swift {
void handleTLSError();
void handleStreamStartReceived(const ProtocolHeader&);
void handleElementReceived(boost::shared_ptr<Element>);
+ void handleDataRead(const ByteArray& data);
+ void handleDataWritten(const ByteArray& data);
private:
bool available;
diff --git a/Swiften/Session/SessionStream.h b/Swiften/Session/SessionStream.h
index b2444f5..6bba237 100644
--- a/Swiften/Session/SessionStream.h
+++ b/Swiften/Session/SessionStream.h
@@ -13,7 +13,16 @@ namespace Swift {
public:
class Error : public Swift::Error {
public:
- Error() {}
+ enum Type {
+ ParseError,
+ TLSError,
+ InvalidTLSCertificateError,
+ ConnectionError
+ };
+
+ Error(Type type) : type(type) {}
+
+ Type type;
};
virtual ~SessionStream();
@@ -43,6 +52,8 @@ namespace Swift {
boost::signal<void (boost::shared_ptr<Element>)> onElementReceived;
boost::signal<void (boost::shared_ptr<Error>)> onError;
boost::signal<void ()> onTLSEncrypted;
+ boost::signal<void (const String&)> onDataRead;
+ boost::signal<void (const String&)> onDataWritten;
protected:
const PKCS12Certificate& getTLSCertificate() const {