2011-02-13 18:51:43 +01:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
|
2016-09-12 18:20:58 +02:00
|
|
|
#include <boost/signal.hpp>
|
2011-02-13 18:51:43 +01:00
|
|
|
#include <time.h>
|
2015-11-18 14:05:57 +01:00
|
|
|
#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"
|
2015-11-18 14:05:57 +01:00
|
|
|
#include "Swiften/JID/JID.h"
|
|
|
|
#include "Swiften/Elements/Presence.h"
|
|
|
|
#include "Swiften/Elements/Message.h"
|
|
|
|
#include "Swiften/Elements/DiscoInfo.h"
|
2013-01-23 11:29:43 +01:00
|
|
|
#include "Swiften/Network/Timer.h"
|
|
|
|
#include "Swiften/Network/Connection.h"
|
2016-09-12 18:20:58 +02:00
|
|
|
#include "Swiften/SwiftenCompat.h"
|
2011-02-13 18:51:43 +01:00
|
|
|
|
|
|
|
namespace Transport {
|
|
|
|
|
|
|
|
class Component;
|
2011-03-20 23:04:20 +01:00
|
|
|
class RosterManager;
|
2011-04-01 23:54:29 +02:00
|
|
|
class ConversationManager;
|
2011-04-03 21:15:14 +02:00
|
|
|
class UserManager;
|
2011-12-08 17:55:23 +01:00
|
|
|
class PresenceOracle;
|
2011-02-13 18:51:43 +01:00
|
|
|
|
2011-03-17 20:31:00 +01:00
|
|
|
/// Represents online XMPP user.
|
2015-11-16 10:49:10 +01:00
|
|
|
class User {
|
2011-02-13 18:51:43 +01:00
|
|
|
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
|
2011-04-03 21:15:14 +02:00
|
|
|
User(const Swift::JID &jid, UserInfo &userInfo, Component * component, UserManager *userManager);
|
2011-03-17 20:31:00 +01:00
|
|
|
|
|
|
|
/// Destroyes User.
|
2011-02-13 18:51:43 +01:00
|
|
|
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
|
2011-02-13 18:51:43 +01:00
|
|
|
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
|
|
|
|
2015-11-16 10:49:10 +01: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; }
|
|
|
|
|
2011-04-01 23:54:29 +02:00
|
|
|
ConversationManager *getConversationManager() { return m_conversationManager; }
|
|
|
|
|
2011-03-24 11:42:31 +01:00
|
|
|
Component *getComponent() { return m_component; }
|
|
|
|
|
2012-10-18 09:04:20 +02:00
|
|
|
UserManager *getUserManager() { return m_userManager; }
|
2015-11-16 10:49:10 +01:00
|
|
|
|
|
|
|
virtual void disconnectUser(const std::string &error, Swift::SpectrumErrorPayload::Error e) = 0;
|
2016-02-07 20:53:35 +01:00
|
|
|
virtual void clearRoomList() {}
|
|
|
|
virtual void addRoomToRoomList(const std::string &handle, const std::string &name) {}
|
2016-02-04 06:55:14 +01:00
|
|
|
virtual void requestVCard() {}
|
2012-10-18 09:04:20 +02:00
|
|
|
|
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.
|
2012-10-24 10:53:26 +02:00
|
|
|
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);
|
|
|
|
|
2016-09-12 18:20:58 +02:00
|
|
|
void handleDiscoInfo(const Swift::JID& jid, SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::DiscoInfo> info);
|
2011-09-19 14:22:01 +02:00
|
|
|
|
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
|
2011-02-13 18:51:43 +01:00
|
|
|
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);
|
2011-04-03 21:15:14 +02:00
|
|
|
|
2011-07-17 23:05:54 +02:00
|
|
|
bool isReadyToConnect() {
|
|
|
|
return m_readyForConnect;
|
|
|
|
}
|
|
|
|
|
2011-09-11 18:26:18 +02:00
|
|
|
void setConnected(bool connected);
|
|
|
|
|
|
|
|
void sendCurrentPresence();
|
2011-07-17 23:05:54 +02:00
|
|
|
|
2011-08-03 13:08:48 +02:00
|
|
|
void setIgnoreDisconnect(bool ignoreDisconnect);
|
|
|
|
|
2011-07-17 23:05:54 +02:00
|
|
|
bool isConnected() {
|
|
|
|
return m_connected;
|
|
|
|
}
|
|
|
|
|
2012-09-22 18:09:25 +02:00
|
|
|
int getResourceCount() {
|
|
|
|
return m_resources;
|
|
|
|
}
|
|
|
|
|
2012-12-18 10:59:52 +01:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2012-12-21 09:26:34 +01:00
|
|
|
void setCacheMessages(bool cacheMessages);
|
|
|
|
|
|
|
|
bool shouldCacheMessages() {
|
|
|
|
return m_cacheMessages;
|
|
|
|
}
|
|
|
|
|
2015-12-21 13:41:30 +01:00
|
|
|
void setReconnectLimit(int limit) {
|
|
|
|
m_reconnectLimit = limit;
|
|
|
|
}
|
|
|
|
|
2016-02-04 06:55:14 +01:00
|
|
|
void setStorageBackend(StorageBackend *storageBackend) {
|
|
|
|
m_storageBackend = storageBackend;
|
|
|
|
}
|
|
|
|
|
2016-01-20 07:36:05 +01:00
|
|
|
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;
|
2013-02-09 11:09:38 +01:00
|
|
|
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;
|
2011-04-03 21:15:14 +02:00
|
|
|
boost::signal<void ()> onDisconnected;
|
2011-03-18 09:44:23 +01:00
|
|
|
|
2011-02-13 18:51:43 +01:00
|
|
|
private:
|
2011-03-18 09:44:23 +01:00
|
|
|
void onConnectingTimeout();
|
|
|
|
|
2011-02-13 18:51:43 +01:00
|
|
|
Swift::JID m_jid;
|
2011-03-20 23:04:20 +01:00
|
|
|
Component *m_component;
|
|
|
|
RosterManager *m_rosterManager;
|
2011-04-03 21:15:14 +02:00
|
|
|
UserManager *m_userManager;
|
2011-04-01 23:54:29 +02:00
|
|
|
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;
|
2016-09-12 18:20:58 +02:00
|
|
|
SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Connection> connection;
|
2011-08-03 13:08:48 +02:00
|
|
|
time_t m_lastActivity;
|
2011-09-19 14:22:01 +02:00
|
|
|
std::map<Swift::JID, Swift::DiscoInfo::ref> m_legacyCaps;
|
2016-09-12 18:20:58 +02:00
|
|
|
std::vector<SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::OutgoingFileTransfer> > m_filetransfers;
|
2011-11-11 10:00:11 +01:00
|
|
|
int m_resources;
|
2011-12-07 18:41:16 +01:00
|
|
|
int m_reconnectCounter;
|
2012-10-24 10:53:26 +02:00
|
|
|
std::list<Swift::Presence::ref> m_joinedRooms;
|
2012-12-18 10:59:52 +01:00
|
|
|
std::map<std::string, std::string> m_settings;
|
2012-12-21 09:26:34 +01:00
|
|
|
bool m_cacheMessages;
|
2015-12-21 13:41:30 +01:00
|
|
|
int m_reconnectLimit;
|
2016-02-04 06:55:14 +01:00
|
|
|
StorageBackend *m_storageBackend;
|
2011-02-13 18:51:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|