diff options
author | Remko Tronçon <git@el-tramo.be> | 2010-10-15 19:42:01 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2010-10-15 19:42:01 (GMT) |
commit | 9173ea9c7d9e35a6b0fd87ee51a07f4e96b53fd6 (patch) | |
tree | 399911d37b7b7378be12a368717cd7c7142523ef /Swiften/Component/ComponentSession.h | |
parent | 062658db9f46ef749eeec09c162e5afaf1524ab6 (diff) | |
download | swift-contrib-9173ea9c7d9e35a6b0fd87ee51a07f4e96b53fd6.zip swift-contrib-9173ea9c7d9e35a6b0fd87ee51a07f4e96b53fd6.tar.bz2 |
Added ComponentSession.
Diffstat (limited to 'Swiften/Component/ComponentSession.h')
-rw-r--r-- | Swiften/Component/ComponentSession.h | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/Swiften/Component/ComponentSession.h b/Swiften/Component/ComponentSession.h new file mode 100644 index 0000000..cbfa227 --- /dev/null +++ b/Swiften/Component/ComponentSession.h @@ -0,0 +1,81 @@ +/* + * 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 <boost/shared_ptr.hpp> +#include <boost/enable_shared_from_this.hpp> + +#include "Swiften/JID/JID.h" +#include "Swiften/Base/boost_bsignals.h" +#include "Swiften/Base/Error.h" +#include "Swiften/Base/String.h" +#include "Swiften/Elements/Element.h" +#include "Swiften/Elements/Stanza.h" +#include "Swiften/Session/SessionStream.h" + +namespace Swift { + class ComponentAuthenticator; + + class ComponentSession : public boost::enable_shared_from_this<ComponentSession> { + public: + enum State { + Initial, + WaitingForStreamStart, + Authenticating, + Initialized, + Finished + }; + + struct Error : public Swift::Error { + enum Type { + AuthenticationFailedError, + UnexpectedElementError, + } type; + Error(Type type) : type(type) {} + }; + + ~ComponentSession(); + + static boost::shared_ptr<ComponentSession> create(const JID& jid, const String& secret, boost::shared_ptr<SessionStream> stream) { + return boost::shared_ptr<ComponentSession>(new ComponentSession(jid, secret, stream)); + } + + State getState() const { + return state; + } + + void start(); + void finish(); + + void sendStanza(boost::shared_ptr<Stanza>); + + public: + boost::signal<void ()> onInitialized; + boost::signal<void (boost::shared_ptr<Swift::Error>)> onFinished; + boost::signal<void (boost::shared_ptr<Stanza>)> onStanzaReceived; + + private: + ComponentSession(const JID& jid, const String& secret, boost::shared_ptr<SessionStream>); + + void finishSession(Error::Type error); + void finishSession(boost::shared_ptr<Swift::Error> error); + + void sendStreamHeader(); + + void handleElement(boost::shared_ptr<Element>); + void handleStreamStart(const ProtocolHeader&); + void handleStreamError(boost::shared_ptr<Swift::Error>); + + bool checkState(State); + + private: + JID jid; + String secret; + boost::shared_ptr<SessionStream> stream; + State state; + }; +} |