summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-06-01 08:48:42 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-06-01 09:24:28 (GMT)
commit2812bddd81f8a1b804c7460f4e14cd0aa393d129 (patch)
treed46294f35150c4f0f43deaf2d31fceaf945ae715 /Swiften/Client/Session.h
downloadswift-2812bddd81f8a1b804c7460f4e14cd0aa393d129.zip
swift-2812bddd81f8a1b804c7460f4e14cd0aa393d129.tar.bz2
Import.
Diffstat (limited to 'Swiften/Client/Session.h')
-rw-r--r--Swiften/Client/Session.h126
1 files changed, 126 insertions, 0 deletions
diff --git a/Swiften/Client/Session.h b/Swiften/Client/Session.h
new file mode 100644
index 0000000..c49d877
--- /dev/null
+++ b/Swiften/Client/Session.h
@@ -0,0 +1,126 @@
+#ifndef SWIFTEN_Session_H
+#define SWIFTEN_Session_H
+
+#include <boost/signal.hpp>
+#include <boost/shared_ptr.hpp>
+
+#include "Swiften/Base/String.h"
+#include "Swiften/JID/JID.h"
+#include "Swiften/Elements/Element.h"
+#include "Swiften/Network/Connection.h"
+#include "Swiften/TLS/PKCS12Certificate.h"
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadSerializerCollection;
+ class ConnectionFactory;
+ class Connection;
+ class StreamStack;
+ class XMPPLayer;
+ class ConnectionLayer;
+ class TLSLayerFactory;
+ class TLSLayer;
+ class WhitespacePingLayer;
+
+ class Session {
+ public:
+ enum State {
+ Initial,
+ Connecting,
+ WaitingForStreamStart,
+ Negotiating,
+ Compressing,
+ Encrypting,
+ WaitingForCredentials,
+ Authenticating,
+ BindingResource,
+ StartingSession,
+ SessionStarted,
+ Error
+ };
+ enum SessionError {
+ NoError,
+ DomainNameResolveError,
+ ConnectionError,
+ ConnectionReadError,
+ XMLError,
+ AuthenticationFailedError,
+ NoSupportedAuthMechanismsError,
+ UnexpectedElementError,
+ ResourceBindError,
+ SessionStartError,
+ TLSError,
+ ClientCertificateLoadError,
+ ClientCertificateError
+ };
+
+ Session(const JID& jid, ConnectionFactory*, TLSLayerFactory*, PayloadParserFactoryCollection*, PayloadSerializerCollection*);
+ ~Session();
+
+ State getState() const {
+ return state_;
+ }
+
+ SessionError getError() const {
+ return error_;
+ }
+
+ const JID& getJID() const {
+ 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 handleConnected();
+ void handleConnectionError(Connection::Error);
+ void handleElement(boost::shared_ptr<Element>);
+ void handleStreamStart();
+ void handleTLSConnected();
+ void handleTLSError();
+
+ void setError(SessionError);
+ 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_;
+ ConnectionFactory* connectionFactory_;
+ TLSLayerFactory* tlsLayerFactory_;
+ PayloadParserFactoryCollection* payloadParserFactories_;
+ PayloadSerializerCollection* payloadSerializers_;
+ State state_;
+ SessionError error_;
+ Connection* connection_;
+ XMPPLayer* xmppLayer_;
+ TLSLayer* tlsLayer_;
+ ConnectionLayer* connectionLayer_;
+ WhitespacePingLayer* whitespacePingLayer_;
+ StreamStack* streamStack_;
+ bool needSessionStart_;
+ PKCS12Certificate certificate_;
+ };
+
+}
+
+#endif