spectrum2/include/transport/User.h

188 lines
5.8 KiB
C
Raw Permalink Normal View History

/**
* 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 <boost/signal.hpp>
#include <time.h>
#include "transport/StorageBackend.h"
2011-09-30 10:00:44 +02:00
#include <Swiften/FileTransfer/OutgoingFileTransfer.h>
2011-11-28 17:34:45 +01:00
#include "Swiften/Elements/SpectrumErrorPayload.h"
#include "Swiften/JID/JID.h"
#include "Swiften/Elements/Presence.h"
#include "Swiften/Elements/Message.h"
#include "Swiften/Elements/DiscoInfo.h"
#include "Swiften/Network/Timer.h"
#include "Swiften/Network/Connection.h"
#include "Swiften/SwiftenCompat.h"
namespace Transport {
class Component;
2011-03-20 23:04:20 +01:00
class RosterManager;
class ConversationManager;
class UserManager;
2011-12-08 17:55:23 +01:00
class PresenceOracle;
2011-03-17 20:31:00 +01:00
/// Represents online XMPP user.
class User {
public:
2011-03-17 20:31:00 +01:00
/// Creates new User class.
/// \param jid XMPP JID associated with this user
/// \param userInfo UserInfo struct with informations needed to connect
/// this user to legacy network
/// \param component Component associated with this user
User(const Swift::JID &jid, UserInfo &userInfo, Component * component, UserManager *userManager);
2011-03-17 20:31:00 +01:00
/// Destroyes User.
virtual ~User();
2011-03-17 20:31:00 +01:00
/// Returns JID of XMPP user who is currently connected using this User class.
/// \return full JID
const Swift::JID &getJID();
2011-07-13 14:58:58 +02:00
/// Returns full JID which supports particular feature or invalid JID.
/// \param feature disco#info feature.
/// \return full JID which supports particular feature or invalid JID.
2012-12-26 09:59:09 +01:00
std::vector<Swift::JID> getJIDWithFeature(const std::string &feature);
2011-07-13 14:58:58 +02:00
// Swift::DiscoInfo::ref getCaps(const Swift::JID &jid) const;
2011-09-28 10:58:48 +02:00
2011-03-17 20:31:00 +01:00
/// Returns UserInfo struct with informations needed to connect the legacy network.
/// \return UserInfo struct
UserInfo &getUserInfo() { return m_userInfo; }
2011-03-20 23:04:20 +01:00
RosterManager *getRosterManager() { return m_rosterManager; }
ConversationManager *getConversationManager() { return m_conversationManager; }
2011-03-24 11:42:31 +01:00
Component *getComponent() { return m_component; }
UserManager *getUserManager() { return m_userManager; }
virtual void disconnectUser(const std::string &error, Swift::SpectrumErrorPayload::Error e) = 0;
virtual void clearRoomList() {}
virtual void addRoomToRoomList(const std::string &handle, const std::string &name) {}
virtual void requestVCard() {}
2011-03-18 09:44:23 +01:00
void setData(void *data) { m_data = data; }
void *getData() { return m_data; }
2011-03-17 20:31:00 +01:00
/// Handles presence from XMPP JID associated with this user.
/// \param presence Swift::Presence.
void handlePresence(Swift::Presence::ref presence, bool forceJoin = false);
2011-03-17 20:31:00 +01:00
2011-04-06 14:05:52 +02:00
void handleSubscription(Swift::Presence::ref presence);
void handleDiscoInfo(const Swift::JID& jid, SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::DiscoInfo> info);
2011-08-03 13:08:48 +02:00
time_t &getLastActivity() {
return m_lastActivity;
}
void updateLastActivity() {
m_lastActivity = time(NULL);
}
2011-03-17 20:31:00 +01:00
/// Returns language.
/// \return language
const char *getLang() { return "en"; }
2011-11-28 17:34:45 +01:00
void handleDisconnected(const std::string &error, Swift::SpectrumErrorPayload::Error e = Swift::SpectrumErrorPayload::CONNECTION_ERROR_OTHER_ERROR);
bool isReadyToConnect() {
return m_readyForConnect;
}
void setConnected(bool connected);
void sendCurrentPresence();
2011-08-03 13:08:48 +02:00
void setIgnoreDisconnect(bool ignoreDisconnect);
bool isConnected() {
return m_connected;
}
int getResourceCount() {
return m_resources;
}
void addUserSetting(const std::string &key, const std::string &value) {
m_settings[key] = value;
}
const std::string &getUserSetting(const std::string &key) {
return m_settings[key];
}
void setCacheMessages(bool cacheMessages);
bool shouldCacheMessages() {
return m_cacheMessages;
}
void setReconnectLimit(int limit) {
m_reconnectLimit = limit;
}
void setStorageBackend(StorageBackend *storageBackend) {
m_storageBackend = storageBackend;
}
void leaveRoom(const std::string &room);
2011-03-18 09:44:23 +01:00
boost::signal<void ()> onReadyToConnect;
2011-06-12 12:27:57 +02:00
boost::signal<void (Swift::Presence::ref presence)> onPresenceChanged;
boost::signal<void (Swift::Presence::ref presence)> onRawPresenceReceived;
2011-11-24 19:37:38 +01:00
boost::signal<void (const Swift::JID &who, const std::string &room, const std::string &nickname, const std::string &password)> onRoomJoined;
2011-05-15 15:18:31 +02:00
boost::signal<void (const std::string &room)> onRoomLeft;
boost::signal<void ()> onDisconnected;
2011-03-18 09:44:23 +01:00
private:
2011-03-18 09:44:23 +01:00
void onConnectingTimeout();
Swift::JID m_jid;
2011-03-20 23:04:20 +01:00
Component *m_component;
RosterManager *m_rosterManager;
UserManager *m_userManager;
ConversationManager *m_conversationManager;
2011-12-08 17:55:23 +01:00
PresenceOracle *m_presenceOracle;
2011-03-17 20:31:00 +01:00
UserInfo m_userInfo;
2011-03-18 09:44:23 +01:00
void *m_data;
bool m_connected;
bool m_readyForConnect;
2011-08-03 13:08:48 +02:00
bool m_ignoreDisconnect;
2011-03-18 09:44:23 +01:00
Swift::Timer::ref m_reconnectTimer;
SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Connection> connection;
2011-08-03 13:08:48 +02:00
time_t m_lastActivity;
std::map<Swift::JID, Swift::DiscoInfo::ref> m_legacyCaps;
std::vector<SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::OutgoingFileTransfer> > m_filetransfers;
int m_resources;
int m_reconnectCounter;
std::list<Swift::Presence::ref> m_joinedRooms;
std::map<std::string, std::string> m_settings;
bool m_cacheMessages;
int m_reconnectLimit;
StorageBackend *m_storageBackend;
};
}