summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-11-06 20:26:48 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-11-06 20:26:48 (GMT)
commitb6003bea740e8898127ec135e230eed421924370 (patch)
tree16c5b26aa1983011b0546da50f5faca9fc738db5 /Swiften/Session/BasicSessionStream.cpp
parent3fbab3b40dfc31da46924f13984415b18087a8d4 (diff)
downloadswift-b6003bea740e8898127ec135e230eed421924370.zip
swift-b6003bea740e8898127ec135e230eed421924370.tar.bz2
Added SessionStream.
Diffstat (limited to 'Swiften/Session/BasicSessionStream.cpp')
-rw-r--r--Swiften/Session/BasicSessionStream.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/Swiften/Session/BasicSessionStream.cpp b/Swiften/Session/BasicSessionStream.cpp
new file mode 100644
index 0000000..46d4e16
--- /dev/null
+++ b/Swiften/Session/BasicSessionStream.cpp
@@ -0,0 +1,72 @@
+// TODO: whitespacePingLayer_->setInactive();
+
+#include "Swiften/Session/BasicSessionStream.h"
+
+#include <boost/bind.hpp>
+
+#include "Swiften/StreamStack/XMPPLayer.h"
+#include "Swiften/StreamStack/StreamStack.h"
+#include "Swiften/StreamStack/ConnectionLayer.h"
+#include "Swiften/StreamStack/WhitespacePingLayer.h"
+#include "Swiften/StreamStack/TLSLayer.h"
+#include "Swiften/StreamStack/TLSLayerFactory.h"
+
+namespace Swift {
+
+BasicSessionStream::BasicSessionStream(boost::shared_ptr<Connection> connection, PayloadParserFactoryCollection* payloadParserFactories, PayloadSerializerCollection* payloadSerializers, TLSLayerFactory* tlsLayerFactory) : tlsLayerFactory(tlsLayerFactory) {
+ xmppLayer = boost::shared_ptr<XMPPLayer>(
+ new XMPPLayer(payloadParserFactories, payloadSerializers));
+ xmppLayer->onStreamStart.connect(boost::ref(onStreamStartReceived));
+ xmppLayer->onElement.connect(boost::ref(onElementReceived));
+ xmppLayer->onError.connect(boost::bind(
+ &BasicSessionStream::handleXMPPError, this));
+
+ connectionLayer = boost::shared_ptr<ConnectionLayer>(
+ new ConnectionLayer(connection));
+
+ streamStack = new StreamStack(xmppLayer, connectionLayer);
+}
+
+BasicSessionStream::~BasicSessionStream() {
+ delete streamStack;
+}
+
+void BasicSessionStream::writeHeader(const ProtocolHeader& header) {
+ xmppLayer->writeHeader(header);
+}
+
+void BasicSessionStream::writeElement(boost::shared_ptr<Element> element) {
+ xmppLayer->writeElement(element);
+}
+
+bool BasicSessionStream::supportsTLSEncryption() {
+ return tlsLayerFactory && tlsLayerFactory->canCreate();
+}
+
+void BasicSessionStream::addTLSEncryption() {
+ tlsLayer = tlsLayerFactory->createTLSLayer();
+ streamStack->addLayer(tlsLayer);
+ // TODO: Add tls layer certificate if needed
+ tlsLayer->onError.connect(boost::bind(&BasicSessionStream::handleTLSError, this));
+ tlsLayer->connect();
+}
+
+void BasicSessionStream::addWhitespacePing() {
+ whitespacePingLayer = boost::shared_ptr<WhitespacePingLayer>(new WhitespacePingLayer());
+ streamStack->addLayer(whitespacePingLayer);
+ whitespacePingLayer->setActive();
+}
+
+void BasicSessionStream::resetXMPPParser() {
+ xmppLayer->resetParser();
+}
+
+void BasicSessionStream::handleXMPPError() {
+ // TODO
+}
+
+void BasicSessionStream::handleTLSError() {
+ // TODO
+}
+
+};