summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-07-12 17:57:48 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-07-12 18:49:51 (GMT)
commit72858ab262a16aa8db209c2898ab0d3c951a9829 (patch)
tree411ccedbf9bdd746ccb1f124e74fe91111d63a56 /Swiften
parenteb1338be843c53aa02fac0d38455aada3f89db0b (diff)
downloadswift-72858ab262a16aa8db209c2898ab0d3c951a9829.zip
swift-72858ab262a16aa8db209c2898ab0d3c951a9829.tar.bz2
Added ServerFromClientSession.
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Parser/XMPPParser.cpp2
-rw-r--r--Swiften/Parser/XMPPParserClient.h7
-rw-r--r--Swiften/Server/Makefile.inc1
-rw-r--r--Swiften/Server/ServerFromClientSession.cpp47
-rw-r--r--Swiften/Server/ServerFromClientSession.h41
-rw-r--r--Swiften/StreamStack/IncomingConnectionLayer.h22
-rw-r--r--Swiften/StreamStack/XMPPLayer.cpp4
-rw-r--r--Swiften/StreamStack/XMPPLayer.h4
8 files changed, 120 insertions, 8 deletions
diff --git a/Swiften/Parser/XMPPParser.cpp b/Swiften/Parser/XMPPParser.cpp
index e05cbca..59cfce7 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();
+ client_->handleStreamStart(attributes.getAttribute("to"));
}
else {
parseErrorOccurred_ = true;
diff --git a/Swiften/Parser/XMPPParserClient.h b/Swiften/Parser/XMPPParserClient.h
index abecc71..d19c7d0 100644
--- a/Swiften/Parser/XMPPParserClient.h
+++ b/Swiften/Parser/XMPPParserClient.h
@@ -6,12 +6,13 @@
#include "Swiften/Elements/Element.h"
namespace Swift {
- class XMPPParserClient
- {
+ class String;
+
+ class XMPPParserClient {
public:
virtual ~XMPPParserClient();
- virtual void handleStreamStart() = 0;
+ virtual void handleStreamStart(const String& header) = 0;
virtual void handleElement(boost::shared_ptr<Element>) = 0;
virtual void handleStreamEnd() = 0;
};
diff --git a/Swiften/Server/Makefile.inc b/Swiften/Server/Makefile.inc
index 54f09ce..1ab98d7 100644
--- a/Swiften/Server/Makefile.inc
+++ b/Swiften/Server/Makefile.inc
@@ -1,5 +1,6 @@
SWIFTEN_SOURCES += \
Swiften/Server/ServerSession.cpp \
+ Swiften/Server/ServerFromClientSession.cpp \
Swiften/Server/ServerStanzaRouter.cpp \
Swiften/Server/IncomingConnection.cpp
diff --git a/Swiften/Server/ServerFromClientSession.cpp b/Swiften/Server/ServerFromClientSession.cpp
new file mode 100644
index 0000000..e85021e
--- /dev/null
+++ b/Swiften/Server/ServerFromClientSession.cpp
@@ -0,0 +1,47 @@
+#include "Swiften/Server/ServerFromClientSession.h"
+
+#include <boost/bind.hpp>
+
+#include "Swiften/Network/IncomingConnection.h"
+#include "Swiften/StreamStack/StreamStack.h"
+#include "Swiften/StreamStack/IncomingConnectionLayer.h"
+#include "Swiften/StreamStack/XMPPLayer.h"
+
+namespace Swift {
+
+ServerFromClientSession::ServerFromClientSession(
+ boost::shared_ptr<IncomingConnection> connection,
+ PayloadParserFactoryCollection* payloadParserFactories,
+ PayloadSerializerCollection* payloadSerializers) :
+ connection_(connection),
+ payloadParserFactories_(payloadParserFactories),
+ payloadSerializers_(payloadSerializers) {
+ xmppLayer_ = new XMPPLayer(payloadParserFactories_, payloadSerializers_);
+ xmppLayer_->onStreamStart.connect(
+ boost::bind(&ServerFromClientSession::handleStreamStart, this, _1));
+ xmppLayer_->onElement.connect(
+ boost::bind(&ServerFromClientSession::handleElement, this, _1));
+ //xmppLayer_->onError.connect(
+ // boost::bind(&ServerFromClientSession::setError, this, XMLError));
+ xmppLayer_->onDataRead.connect(
+ boost::bind(boost::ref(onDataRead), _1));
+ xmppLayer_->onWriteData.connect(
+ boost::bind(boost::ref(onDataWritten), _1));
+ connectionLayer_ = new IncomingConnectionLayer(connection_.get());
+ streamStack_ = new StreamStack(xmppLayer_, connectionLayer_);
+}
+
+ServerFromClientSession::~ServerFromClientSession() {
+ delete streamStack_;
+ delete connectionLayer_;
+ delete xmppLayer_;
+}
+
+void ServerFromClientSession::handleElement(boost::shared_ptr<Element>) {
+}
+
+void ServerFromClientSession::handleStreamStart(const String& domain) {
+ xmppLayer_->writeHeader(domain);
+}
+
+}
diff --git a/Swiften/Server/ServerFromClientSession.h b/Swiften/Server/ServerFromClientSession.h
new file mode 100644
index 0000000..cedfcdb
--- /dev/null
+++ b/Swiften/Server/ServerFromClientSession.h
@@ -0,0 +1,41 @@
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+#include <boost/signal.hpp>
+
+namespace Swift {
+ class Element;
+ class PayloadParserFactoryCollection;
+ class PayloadSerializerCollection;
+ class StreamStack;
+ class XMPPLayer;
+ class IncomingConnectionLayer;
+ class IncomingConnection;
+ class ByteArray;
+ class String;
+
+ class ServerFromClientSession {
+ public:
+ ServerFromClientSession(
+ boost::shared_ptr<IncomingConnection> connection,
+ PayloadParserFactoryCollection* payloadParserFactories,
+ PayloadSerializerCollection* payloadSerializers);
+ ~ServerFromClientSession();
+
+ boost::signal<void()> onSessionFinished;
+ boost::signal<void (const ByteArray&)> onDataWritten;
+ boost::signal<void (const ByteArray&)> onDataRead;
+
+ private:
+ void handleElement(boost::shared_ptr<Element>);
+ void handleStreamStart(const String& domain);
+
+ private:
+ boost::shared_ptr<IncomingConnection> connection_;
+ PayloadParserFactoryCollection* payloadParserFactories_;
+ PayloadSerializerCollection* payloadSerializers_;
+ IncomingConnectionLayer* connectionLayer_;
+ StreamStack* streamStack_;
+ XMPPLayer* xmppLayer_;
+ };
+}
diff --git a/Swiften/StreamStack/IncomingConnectionLayer.h b/Swiften/StreamStack/IncomingConnectionLayer.h
new file mode 100644
index 0000000..c1a9eab
--- /dev/null
+++ b/Swiften/StreamStack/IncomingConnectionLayer.h
@@ -0,0 +1,22 @@
+#pragma once
+
+#include <boost/signal.hpp>
+
+#include "Swiften/StreamStack/LowLayer.h"
+#include "Swiften/Network/IncomingConnection.h"
+
+namespace Swift {
+ class IncomingConnectionLayer : public LowLayer {
+ public:
+ IncomingConnectionLayer(IncomingConnection* connection) : connection_(connection) {
+ connection_->onDataRead.connect(onDataRead);
+ }
+
+ void writeData(const ByteArray& data) {
+ connection_->write(data);
+ }
+
+ private:
+ IncomingConnection* connection_;
+ };
+}
diff --git a/Swiften/StreamStack/XMPPLayer.cpp b/Swiften/StreamStack/XMPPLayer.cpp
index 7afa762..464d4b0 100644
--- a/Swiften/StreamStack/XMPPLayer.cpp
+++ b/Swiften/StreamStack/XMPPLayer.cpp
@@ -56,8 +56,8 @@ void XMPPLayer::doResetParser() {
resetParserAfterParse_ = false;
}
-void XMPPLayer::handleStreamStart() {
- onStreamStart();
+void XMPPLayer::handleStreamStart(const String& domain) {
+ onStreamStart(domain);
}
void XMPPLayer::handleElement(boost::shared_ptr<Element> stanza) {
diff --git a/Swiften/StreamStack/XMPPLayer.h b/Swiften/StreamStack/XMPPLayer.h
index 07b5b1c..e064d94 100644
--- a/Swiften/StreamStack/XMPPLayer.h
+++ b/Swiften/StreamStack/XMPPLayer.h
@@ -31,14 +31,14 @@ namespace Swift {
void resetParser();
public:
- boost::signal<void ()> onStreamStart;
+ boost::signal<void (const String& domain)> onStreamStart;
boost::signal<void (boost::shared_ptr<Element>)> onElement;
boost::signal<void (const ByteArray&)> onWriteData;
boost::signal<void (const ByteArray&)> onDataRead;
boost::signal<void ()> onError;
private:
- void handleStreamStart();
+ void handleStreamStart(const String&);
void handleElement(boost::shared_ptr<Element>);
void handleStreamEnd();