/* * Copyright (c) 2010 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include #include #include #include #include #include #include #include #include #include namespace Swift { class ComponentAuthenticator; 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) { return boost::shared_ptr(new ComponentSession(jid, secret, stream)); } 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); 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; boost::shared_ptr error; State state; }; }