#pragma once #include #include #include "Swiften/Session/Session.h" #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 ClientSession : public Session { public: enum State { Initial, WaitingForStreamStart, Negotiating, Compressing, Encrypting, WaitingForCredentials, Authenticating, BindingResource, StartingSession, SessionStarted, Error, Finished }; ClientSession( const JID& jid, boost::shared_ptr, TLSLayerFactory*, PayloadParserFactoryCollection*, PayloadSerializerCollection*); State getState() const { return state_; } boost::optional getError() const { return error_; } void sendCredentials(const String& password); void setCertificate(const PKCS12Certificate& certificate); private: void sendStreamHeader(); void sendSessionStart(); virtual void handleSessionStarted(); virtual void handleSessionFinished(const boost::optional& error); virtual void handleElement(boost::shared_ptr); virtual void handleStreamStart(const ProtocolHeader&); void handleTLSConnected(); void handleTLSError(); void setError(SessionError); bool checkState(State); public: boost::signal onNeedCredentials; private: TLSLayerFactory* tlsLayerFactory_; State state_; boost::optional error_; boost::shared_ptr tlsLayer_; boost::shared_ptr whitespacePingLayer_; bool needSessionStart_; PKCS12Certificate certificate_; }; }