/* * Copyright (c) 2010-2014 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once #include #include #include #include #include #include #include #include #include #include namespace Swift { class ComponentAuthenticator; class CryptoProvider; class SWIFTEN_API ComponentSession : public boost::enable_shared_from_this { public: enum State { Initial, WaitingForStreamStart, Authenticating, Initialized, Finishing, Finished }; struct Error : public Swift::Error { enum Type { AuthenticationFailedError, UnexpectedElementError } type; Error(Type type) : type(type) {} }; ~ComponentSession(); static boost::shared_ptr create(const JID& jid, const std::string& secret, boost::shared_ptr stream, CryptoProvider* crypto) { return boost::shared_ptr(new ComponentSession(jid, secret, stream, crypto)); } State getState() const { return state; } void start(); void finish(); void sendStanza(boost::shared_ptr); public: boost::signal onInitialized; boost::signal)> onFinished; boost::signal)> onStanzaReceived; private: ComponentSession(const JID& jid, const std::string& secret, boost::shared_ptr, CryptoProvider*); void finishSession(Error::Type error); void finishSession(boost::shared_ptr error); void sendStreamHeader(); void handleElement(boost::shared_ptr); void handleStreamStart(const ProtocolHeader&); void handleStreamClosed(boost::shared_ptr); bool checkState(State); private: JID jid; std::string secret; boost::shared_ptr stream; CryptoProvider* crypto; boost::shared_ptr error; State state; }; }