Files @ 0b87eda80694
Branch filter:

Location: libtransport.git/include/transport/transport.h - annotation

HanzZ
Skype: move sqlite3 db stuff into skypedb.cpp
e678a46286f4
e678a46286f4
e678a46286f4
e678a46286f4
e678a46286f4
e678a46286f4
e678a46286f4
e678a46286f4
e678a46286f4
e678a46286f4
e678a46286f4
e678a46286f4
e678a46286f4
e678a46286f4
e678a46286f4
e678a46286f4
e678a46286f4
e678a46286f4
e678a46286f4
e678a46286f4
e678a46286f4
e678a46286f4
e678a46286f4
79cc6dc63de8
e678a46286f4
e678a46286f4
e678a46286f4
e678a46286f4
e678a46286f4
e678a46286f4
79cc6dc63de8
a9fbe73b8025
02b2f22f3e96
cc64a76c8be5
cc64a76c8be5
f9d40b961a35
c5edfd19b1aa
e678a46286f4
c8006a0ebab6
f035510e4798
2b834d16abc8
e678a46286f4
e678a46286f4
c5edfd19b1aa
c8006a0ebab6
1e8eb7076f17
e678a46286f4
271a7134db1a
271a7134db1a
d39705842a2a
d39705842a2a
d39705842a2a
d39705842a2a
d39705842a2a
c5edfd19b1aa
e678a46286f4
271a7134db1a
d39705842a2a
d39705842a2a
d39705842a2a
271a7134db1a
271a7134db1a
271a7134db1a
271a7134db1a
d39705842a2a
cc64a76c8be5
d39705842a2a
cc64a76c8be5
dd11e43325de
271a7134db1a
271a7134db1a
c5edfd19b1aa
e678a46286f4
d39705842a2a
d39705842a2a
d39705842a2a
d39705842a2a
79cc6dc63de8
2ae880ff94b5
d39705842a2a
d39705842a2a
d39705842a2a
18a72df6850b
18a72df6850b
2ae880ff94b5
d39705842a2a
2ae880ff94b5
d39705842a2a
f035510e4798
2ae880ff94b5
d39705842a2a
d39705842a2a
d39705842a2a
79cc6dc63de8
d39705842a2a
cc64a76c8be5
cc64a76c8be5
cc64a76c8be5
cc64a76c8be5
28ca4ba95e42
cc64a76c8be5
cc64a76c8be5
28ca4ba95e42
99aff9256622
271a7134db1a
d39705842a2a
271a7134db1a
c5edfd19b1aa
c5edfd19b1aa
d39705842a2a
d39705842a2a
d39705842a2a
dd11e43325de
5f017bd15dc7
d39705842a2a
d39705842a2a
d39705842a2a
c8006a0ebab6
c8006a0ebab6
599469670eec
d39705842a2a
599469670eec
599469670eec
599469670eec
599469670eec
99aff9256622
599469670eec
599469670eec
d39705842a2a
599469670eec
599469670eec
599469670eec
599469670eec
d39705842a2a
599469670eec
599469670eec
599469670eec
9c294ea31925
9c294ea31925
d39705842a2a
d39705842a2a
d39705842a2a
cc64a76c8be5
cc64a76c8be5
cc64a76c8be5
c5edfd19b1aa
99aff9256622
cc64a76c8be5
cc64a76c8be5
cc64a76c8be5
cc64a76c8be5
e23f8e3c7f9d
e23f8e3c7f9d
e678a46286f4
e678a46286f4
e678a46286f4
2b834d16abc8
c5edfd19b1aa
877d783276c0
877d783276c0
99aff9256622
e23f8e3c7f9d
5f017bd15dc7
e678a46286f4
dd11e43325de
e678a46286f4
79cc6dc63de8
e678a46286f4
e678a46286f4
e678a46286f4
e678a46286f4
f035510e4798
79cc6dc63de8
79cc6dc63de8
941bba0427fe
c7f2b6298073
c5edfd19b1aa
e678a46286f4
bf4183c181eb
c5edfd19b1aa
e678a46286f4
c8006a0ebab6
828ae9d2cb88
c5edfd19b1aa
c5edfd19b1aa
c5edfd19b1aa
bc585576a9ab
e678a46286f4
e678a46286f4
/**
 * libtransport -- C++ library for easy XMPP Transports development
 *
 * Copyright (C) 2011, Jan Kaluza <hanzz.k@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 */

#pragma once

#include <vector>
#include "Swiften/Server/Server.h"
#include "Swiften/Disco/GetDiscoInfoRequest.h"
#include "Swiften/Disco/EntityCapsManager.h"
#include "Swiften/Disco/CapsManager.h"
#include "Swiften/Disco/CapsMemoryStorage.h"
#include "Swiften/Network/BoostTimerFactory.h"
#include "Swiften/Network/BoostIOServiceThread.h"
#include "Swiften/Server/UserRegistry.h"
#include "Swiften/Base/SafeByteArray.h"
#include "Swiften/Jingle/JingleSessionManager.h"
#include "Swiften/Component/ComponentError.h"
#include "Swiften/Component/Component.h"

#include <boost/bind.hpp>
#include "transport/config.h"
#include "transport/factory.h"
#include "transport/presenceoracle.h"
#include <Swiften/Network/BoostConnectionServer.h>

namespace Transport {
	class StorageBackend;
	class Factory;
	class UserRegistry;

	/// Represents one transport instance.

	/// It's used to connect the Jabber server and provides transaction layer
	/// between Jabber server and other classes.
	///
	/// In server mode it represents Jabber server to which users can connect and use
	/// it as transport.
	class Component {
		public:
			/// Creates new Component instance.

			/// \param loop Main event loop.
			/// \param config Cofiguration; this class uses following Config values:
			/// 	- service.jid
			/// 	- service.password
			/// 	- service.server
			/// 	- service.port
			/// 	- service.server_mode
			/// \param factories Swift::NetworkFactories.
			/// \param factory Transport Abstract factory used to create basic transport structures.
			/// \param userRegistery UserRegistry class instance. It's needed only when running transport in server-mode.
			Component(Swift::EventLoop *loop, Swift::NetworkFactories *factories, Config *config, Factory *factory, Transport::UserRegistry *userRegistry = NULL);

			/// Component destructor.
			~Component();

			/// Returns Swift::StanzaChannel associated with this Transport::Component.

			/// It can be used to send presences and other stanzas.
			/// \return Swift::StanzaChannel associated with this Transport::Component.
			Swift::StanzaChannel *getStanzaChannel();

			/// Returns Swift::IQRouter associated with this Component.

			/// \return Swift::IQRouter associated with this Component.
			Swift::IQRouter *getIQRouter() { return m_iqRouter; }

			/// Returns Swift::PresenceOracle associated with this Transport::Component.

			/// You can use it to check current resource connected for particular user.
			/// \return Swift::PresenceOracle associated with this Transport::Component.
			PresenceOracle *getPresenceOracle();

			/// Returns True if the component is in server mode.

			/// \return True if the component is in server mode.
			bool inServerMode() { return m_server != NULL; }

			/// Starts the Component.
			
			/// In server-mode, it starts listening on particular port for new client connections.
			/// In gateway-mode, it connects the XMPP server.
			void start();

			/// Stops the component.
			void stop();

			/// Returns Jabber ID of this transport.

			/// \return Jabber ID of this transport
			Swift::JID &getJID() { return m_jid; }

			/// Returns Swift::NetworkFactories which can be used to create new connections.

			/// \return Swift::NetworkFactories which can be used to create new connections.
			Swift::NetworkFactories *getNetworkFactories() { return m_factories; }

			/// Returns Transport Factory used to create basic Transport components.

			/// \return Transport Factory used to create basic Transport components.
			Factory *getFactory() { return m_factory; }

			/// This signal is emitted when server disconnects the transport because of some error.

			/// \param error disconnection error
			boost::signal<void (const Swift::ComponentError &error)> onConnectionError;

			/// This signal is emitted when transport successfully connects the server.
			boost::signal<void ()> onConnected;

			/// This signal is emitted when XML stanza is sent to server.

			/// \param xml xml stanza
			boost::signal<void (const std::string &xml)> onXMLOut;

			/// This signal is emitted when XML stanza is received from server.

			/// \param xml xml stanza
			boost::signal<void (const std::string &xml)> onXMLIn;

			Config *getConfig() { return m_config; }

			/// This signal is emitted when presence from XMPP user is received.

			/// It's emitted only for presences addressed to transport itself
			/// (for example to="j2j.domain.tld") and for presences comming to
			/// MUC (for example to="#chat%irc.freenode.org@irc.domain.tld")
			/// \param presence Presence.
			boost::signal<void (Swift::Presence::ref presence)> onUserPresenceReceived;

			/// Component class asks the XMPP clients automatically for their capabilities.
			/// This signal is emitted when capabilities have been received or changed.
			/// \param jid JID of the client for which we received capabilities
			/// \param info disco#info with response.
			boost::signal<void (const Swift::JID& jid, boost::shared_ptr<Swift::DiscoInfo> info)> onUserDiscoInfoReceived;

		private:
			void handleConnected();
			void handleConnectionError(const Swift::ComponentError &error);
			void handleServerStopped(boost::optional<Swift::BoostConnectionServer::Error> e);
			void handlePresence(Swift::Presence::ref presence);
			void handleDataRead(const Swift::SafeByteArray &data);
			void handleDataWritten(const Swift::SafeByteArray &data);

			void handleDiscoInfoResponse(boost::shared_ptr<Swift::DiscoInfo> info, Swift::ErrorPayload::ref error, const Swift::JID& jid);
			void handleCapsChanged(const Swift::JID& jid);

			Swift::NetworkFactories *m_factories;
			Swift::Component *m_component;
			Swift::Server *m_server;
			Swift::Timer::ref m_reconnectTimer;
			Swift::EntityCapsManager *m_entityCapsManager;
			Swift::CapsManager *m_capsManager;
			Swift::CapsMemoryStorage *m_capsMemoryStorage;
			PresenceOracle *m_presenceOracle;
			Swift::StanzaChannel *m_stanzaChannel;
			Swift::IQRouter *m_iqRouter;
			
			Transport::UserRegistry *m_userRegistry;
			StorageBackend *m_storageBackend;
			int m_reconnectCount;
			Config* m_config;
			std::string m_protocol;
			Swift::JID m_jid;
			Factory *m_factory;
			Swift::EventLoop *m_loop;

		friend class User;
		friend class UserRegistration;
		friend class NetworkPluginServer;
	};
}