/* * Copyright (c) 2010-2017 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once #include #include #include #include #include #include #include #include #include namespace Swift { class CryptoProvider; class SWIFTEN_API ComponentSession : public std::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 std::shared_ptr create(const JID& jid, const std::string& secret, std::shared_ptr stream, CryptoProvider* crypto) { return std::shared_ptr(new ComponentSession(jid, secret, stream, crypto)); } State getState() const { return state; } void start(); void finish(); void sendStanza(std::shared_ptr); public: boost::signals2::signal onInitialized; boost::signals2::signal)> onFinished; boost::signals2::signal)> onStanzaReceived; private: ComponentSession(const JID& jid, const std::string& secret, std::shared_ptr, CryptoProvider*); void finishSession(Error::Type error); void finishSession(std::shared_ptr error); void sendStreamHeader(); void handleElement(std::shared_ptr); void handleStreamStart(const ProtocolHeader&); void handleStreamClosed(std::shared_ptr); bool checkState(State); private: JID jid; std::string secret; std::shared_ptr stream; CryptoProvider* crypto; std::shared_ptr error; State state; }; }