Files
@ 9c294ea31925
Branch filter:
Location: libtransport.git/include/transport/transport.h
9c294ea31925
7.3 KiB
text/plain
AdminInterface class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | /**
* 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/Swiften.h"
#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/Presence/PresenceOracle.h"
#include "Swiften/Network/BoostTimerFactory.h"
#include "Swiften/Network/BoostIOServiceThread.h"
#include "Swiften/Server/UserRegistry.h"
#include "Swiften/Base/SafeByteArray.h"
#include <boost/bind.hpp>
#include "transport/config.h"
#include "transport/factory.h"
#define tr(lang,STRING) (STRING)
#define _(STRING) (STRING)
namespace Transport {
// typedef enum { CLIENT_FEATURE_ROSTERX = 2,
// CLIENT_FEATURE_XHTML_IM = 4,
// CLIENT_FEATURE_FILETRANSFER = 8,
// CLIENT_FEATURE_CHATSTATES = 16
// } SpectrumImportantFeatures;
//
class StorageBackend;
class DiscoInfoResponder;
class DiscoItemsResponder;
class Factory;
/// 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 factory Transport Abstract factory used to create basic transport structures.
Component(Swift::EventLoop *loop, Config *config, Factory *factory);
/// 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.
Swift::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; }
/// Returns user password from internal UserRegistry.
/// In server mode, the password user used for login can be obtained by
/// this method.
/// \param barejid User's bare JID.
/// \return User's password.
const std::string &getUserRegistryPassword(const std::string &barejid);
/// Connects the Jabber server.
void start();
void stop();
/// Sets disco#info features which are sent as answer to disco#info IQ-get.
/// This sets features of transport contact (For example "j2j.domain.tld").
/// \param features list of features as sent in disco#info response
void setTransportFeatures(std::list<std::string> &features);
/// Sets disco#info features which are sent as answer to disco#info IQ-get.
/// This sets features of legacy network buddies (For example "me\40gmail.com@j2j.domain.tld").
/// \param features list of features as sent in disco#info response
void setBuddyFeatures(std::list<std::string> &features);
/// 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::BoostNetworkFactories *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").
/// \param presence presence data
boost::signal<void (Swift::Presence::ref presence)> onUserPresenceReceived;
// boost::signal<void (boost::shared_ptr<Swift::DiscoInfo> info, Swift::ErrorPayload::ref error, const Swift::JID& jid)> onDiscoInfoResponse;
private:
void handleConnected();
void handleConnectionError(const Swift::ComponentError &error);
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::BoostNetworkFactories *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;
Swift::PresenceOracle *m_presenceOracle;
Swift::StanzaChannel *m_stanzaChannel;
Swift::IQRouter *m_iqRouter;
Swift::UserRegistry *m_userRegistry;
StorageBackend *m_storageBackend;
DiscoInfoResponder *m_discoInfoResponder;
DiscoItemsResponder *m_discoItemsResponder;
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;
};
}
|