summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-07-19 13:21:38 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-07-19 13:27:00 (GMT)
commita6fcd9e7aa12c5e00c61ff809e81fba14babd70c (patch)
treef65419f4f9a78a1db574f8fa792e745f7fbdf76c /Swiften/Client/ClientSession.h
parent9ccf1973ec3e23e4ba061b774c3f3e3bde4f1040 (diff)
downloadswift-a6fcd9e7aa12c5e00c61ff809e81fba14babd70c.zip
swift-a6fcd9e7aa12c5e00c61ff809e81fba14babd70c.tar.bz2
Factor out common session stuff into Session class.
Diffstat (limited to 'Swiften/Client/ClientSession.h')
-rw-r--r--Swiften/Client/ClientSession.h54
1 files changed, 11 insertions, 43 deletions
diff --git a/Swiften/Client/ClientSession.h b/Swiften/Client/ClientSession.h
index 50dae24..22e4a88 100644
--- a/Swiften/Client/ClientSession.h
+++ b/Swiften/Client/ClientSession.h
@@ -3,6 +3,7 @@
#include <boost/signal.hpp>
#include <boost/shared_ptr.hpp>
+#include "Swiften/Session/Session.h"
#include "Swiften/Base/String.h"
#include "Swiften/JID/JID.h"
#include "Swiften/Elements/Element.h"
@@ -21,7 +22,7 @@ namespace Swift {
class TLSLayer;
class WhitespacePingLayer;
- class ClientSession {
+ class ClientSession : public Session {
public:
enum State {
Initial,
@@ -34,21 +35,8 @@ namespace Swift {
BindingResource,
StartingSession,
SessionStarted,
- Error
- };
- enum SessionError {
- NoError,
- ConnectionReadError,
- ConnectionWriteError,
- XMLError,
- AuthenticationFailedError,
- NoSupportedAuthMechanismsError,
- UnexpectedElementError,
- ResourceBindError,
- SessionStartError,
- TLSError,
- ClientCertificateLoadError,
- ClientCertificateError
+ Error,
+ Finished
};
ClientSession(
@@ -57,13 +45,12 @@ namespace Swift {
TLSLayerFactory*,
PayloadParserFactoryCollection*,
PayloadSerializerCollection*);
- ~ClientSession();
State getState() const {
return state_;
}
- SessionError getError() const {
+ boost::optional<SessionError> getError() const {
return error_;
}
@@ -71,26 +58,18 @@ namespace Swift {
return jid_;
}
- void start();
- void stop();
-
void sendCredentials(const String& password);
- void sendElement(boost::shared_ptr<Element>);
void setCertificate(const PKCS12Certificate& certificate);
- protected:
- StreamStack* getStreamStack() const {
- return streamStack_;
- }
-
private:
- void initializeStreamStack();
void sendStreamHeader();
void sendSessionStart();
- void handleDisconnected(const boost::optional<Connection::Error>&);
- void handleElement(boost::shared_ptr<Element>);
- void handleStreamStart();
+ virtual void handleSessionStarted();
+ virtual void handleSessionFinished(const boost::optional<SessionError>& error);
+ virtual void handleElement(boost::shared_ptr<Element>);
+ virtual void handleStreamStart(const ProtocolHeader&);
+
void handleTLSConnected();
void handleTLSError();
@@ -98,26 +77,15 @@ namespace Swift {
bool checkState(State);
public:
- boost::signal<void ()> onSessionStarted;
- boost::signal<void (SessionError)> onError;
boost::signal<void ()> onNeedCredentials;
- boost::signal<void (boost::shared_ptr<Element>) > onElementReceived;
- boost::signal<void (const ByteArray&)> onDataWritten;
- boost::signal<void (const ByteArray&)> onDataRead;
private:
JID jid_;
TLSLayerFactory* tlsLayerFactory_;
- PayloadParserFactoryCollection* payloadParserFactories_;
- PayloadSerializerCollection* payloadSerializers_;
State state_;
- SessionError error_;
- boost::shared_ptr<Connection> connection_;
- boost::shared_ptr<XMPPLayer> xmppLayer_;
+ boost::optional<SessionError> error_;
boost::shared_ptr<TLSLayer> tlsLayer_;
- boost::shared_ptr<ConnectionLayer> connectionLayer_;
boost::shared_ptr<WhitespacePingLayer> whitespacePingLayer_;
- StreamStack* streamStack_;
bool needSessionStart_;
PKCS12Certificate certificate_;
};