2011-03-18 13:47:50 +01:00
|
|
|
/**
|
|
|
|
* XMPP - libpurple transport
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009, Jan Kaluza <hanzz@soc.pidgin.im>
|
|
|
|
*
|
|
|
|
* 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 <string>
|
|
|
|
#include <algorithm>
|
2013-01-23 11:29:43 +01:00
|
|
|
#include "Swiften/Elements/VCard.h"
|
2015-11-16 10:49:10 +01:00
|
|
|
#include "Swiften/Elements/Presence.h"
|
2011-03-18 13:47:50 +01:00
|
|
|
|
2011-03-20 23:04:20 +01:00
|
|
|
namespace Transport {
|
|
|
|
|
|
|
|
class RosterManager;
|
2016-01-22 15:17:51 +01:00
|
|
|
class User;
|
2011-03-18 13:47:50 +01:00
|
|
|
|
2011-03-21 09:57:48 +01:00
|
|
|
typedef enum { BUDDY_NO_FLAG = 0,
|
|
|
|
BUDDY_JID_ESCAPING = 2,
|
2011-08-23 08:02:41 +02:00
|
|
|
BUDDY_IGNORE = 4,
|
|
|
|
BUDDY_BLOCKED = 8,
|
2011-03-21 09:57:48 +01:00
|
|
|
} BuddyFlag;
|
|
|
|
|
|
|
|
/// Represents one legacy network Buddy.
|
2011-04-03 11:39:06 +02:00
|
|
|
class Buddy {
|
2011-03-18 13:47:50 +01:00
|
|
|
public:
|
2012-03-08 20:04:56 +01:00
|
|
|
typedef enum { Ask,
|
|
|
|
Both,
|
|
|
|
} Subscription;
|
2011-03-21 09:57:48 +01:00
|
|
|
/// Constructor.
|
2011-06-06 10:48:27 +02:00
|
|
|
|
|
|
|
/// \param rosterManager RosterManager associated with this buddy.
|
|
|
|
/// \param id ID which identifies the buddy in database or -1 if it's new buddy which is
|
|
|
|
/// not in database yet.
|
2012-08-09 11:21:01 +02:00
|
|
|
Buddy(RosterManager *rosterManager, long id = -1, BuddyFlag flags = BUDDY_NO_FLAG);
|
2011-03-21 09:57:48 +01:00
|
|
|
|
|
|
|
/// Destructor
|
2011-04-03 11:39:06 +02:00
|
|
|
virtual ~Buddy();
|
2011-03-18 13:47:50 +01:00
|
|
|
|
2011-06-06 10:48:27 +02:00
|
|
|
/// Sets unique ID used to identify this buddy by StorageBackend.
|
|
|
|
|
|
|
|
/// This is set
|
2011-03-21 09:57:48 +01:00
|
|
|
/// by RosterStorage class once the buddy is stored into database or when the
|
|
|
|
/// buddy is loaded from database.
|
|
|
|
/// You should not need to set this ID manually.
|
|
|
|
/// \param id ID
|
|
|
|
void setID(long id);
|
|
|
|
|
|
|
|
/// Returns unique ID used to identify this buddy by StorageBackend.
|
2011-06-06 10:48:27 +02:00
|
|
|
|
|
|
|
/// \return ID which identifies the buddy in database or -1 if it's new buddy which is
|
|
|
|
/// not in database yet.
|
2011-03-21 09:57:48 +01:00
|
|
|
long getID();
|
|
|
|
|
|
|
|
/// Returns full JID of this buddy.
|
2011-06-06 10:48:27 +02:00
|
|
|
|
2011-03-21 09:57:48 +01:00
|
|
|
/// \param hostname hostname used as domain in returned JID
|
|
|
|
/// \return full JID of this buddy
|
2011-03-30 21:23:39 +02:00
|
|
|
const Swift::JID &getJID();
|
2011-03-18 13:47:50 +01:00
|
|
|
|
2011-03-21 09:57:48 +01:00
|
|
|
/// Generates whole Presennce stanza with current status/show for this buddy.
|
2011-06-06 10:48:27 +02:00
|
|
|
|
2011-03-21 09:57:48 +01:00
|
|
|
/// Presence stanza does not containt "to" attribute, it has to be added manually.
|
|
|
|
/// \param features features used in returned stanza
|
|
|
|
/// \param only_new if True, this function returns Presence stanza only if it's different
|
|
|
|
/// than the previously generated one.
|
|
|
|
/// \return Presence stanza or NULL.
|
2013-02-22 09:45:31 +01:00
|
|
|
std::vector<Swift::Presence::ref> &generatePresenceStanzas(int features, bool only_new = false);
|
2011-03-18 13:47:50 +01:00
|
|
|
|
2011-07-27 10:33:34 +02:00
|
|
|
void setBlocked(bool block) {
|
2011-08-23 08:02:41 +02:00
|
|
|
if (block)
|
|
|
|
m_flags = (BuddyFlag) (m_flags | BUDDY_BLOCKED);
|
|
|
|
else
|
|
|
|
m_flags = (BuddyFlag) (m_flags & ~BUDDY_BLOCKED);
|
2011-07-27 10:33:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isBlocked() {
|
2011-09-07 14:03:27 +02:00
|
|
|
return (m_flags & BUDDY_BLOCKED) != 0;
|
2011-07-27 10:33:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-21 09:57:48 +01:00
|
|
|
/// Sets current subscription.
|
2011-06-06 10:48:27 +02:00
|
|
|
|
2011-03-21 09:57:48 +01:00
|
|
|
/// \param subscription "to", "from", "both", "ask"
|
2012-03-08 20:04:56 +01:00
|
|
|
void setSubscription(Subscription subscription);
|
2011-03-21 09:57:48 +01:00
|
|
|
|
|
|
|
/// Returns current subscription
|
2011-06-06 10:48:27 +02:00
|
|
|
|
2011-03-21 09:57:48 +01:00
|
|
|
/// \return subscription "to", "from", "both", "ask"
|
2012-03-08 20:04:56 +01:00
|
|
|
Subscription getSubscription();
|
2011-03-18 13:47:50 +01:00
|
|
|
|
2011-03-21 09:57:48 +01:00
|
|
|
/// Sets this buddy's flags.
|
2011-06-06 10:48:27 +02:00
|
|
|
|
2011-03-21 09:57:48 +01:00
|
|
|
/// \param flags flags
|
|
|
|
void setFlags(BuddyFlag flags);
|
2011-03-18 13:47:50 +01:00
|
|
|
|
2011-03-21 09:57:48 +01:00
|
|
|
/// Returns this buddy's flags.
|
2011-06-06 10:48:27 +02:00
|
|
|
|
2011-03-21 09:57:48 +01:00
|
|
|
/// \param flags flags
|
|
|
|
BuddyFlag getFlags();
|
2011-03-18 13:47:50 +01:00
|
|
|
|
2011-06-06 10:48:27 +02:00
|
|
|
/// Returns RosterManager associated with this buddy.
|
|
|
|
|
|
|
|
/// \return RosterManager associated with this buddy.
|
2011-03-20 23:04:20 +01:00
|
|
|
RosterManager *getRosterManager() { return m_rosterManager; }
|
|
|
|
|
2011-03-21 09:57:48 +01:00
|
|
|
/// Returns legacy network username which does not contain unsafe characters,
|
|
|
|
/// so it can be used in JIDs.
|
|
|
|
std::string getSafeName();
|
|
|
|
|
2013-01-12 10:09:35 +01:00
|
|
|
void sendPresence();
|
2011-03-30 21:23:39 +02:00
|
|
|
|
2013-02-22 09:45:31 +01:00
|
|
|
void handleRawPresence(Swift::Presence::ref);
|
|
|
|
|
2011-06-06 10:48:27 +02:00
|
|
|
/// Handles VCard from legacy network and forwards it to XMPP user.
|
2011-04-11 14:03:15 +02:00
|
|
|
|
2011-06-06 10:48:27 +02:00
|
|
|
/// \param id ID used in IQ-result.
|
|
|
|
/// \param vcard VCard which will be sent.
|
|
|
|
void handleVCardReceived(const std::string &id, Swift::VCard::ref vcard);
|
|
|
|
|
|
|
|
/// Returns legacy network username of this buddy. (for example UIN for ICQ, JID for Jabber, ...).
|
2011-04-11 14:03:15 +02:00
|
|
|
|
2011-03-21 09:57:48 +01:00
|
|
|
/// \return legacy network username
|
2011-03-18 13:47:50 +01:00
|
|
|
virtual std::string getName() = 0;
|
|
|
|
|
2011-03-21 09:57:48 +01:00
|
|
|
/// Returns alias (nickname) of this buddy.
|
2011-06-06 10:48:27 +02:00
|
|
|
|
2011-03-21 09:57:48 +01:00
|
|
|
/// \return alias (nickname)
|
2011-03-18 13:47:50 +01:00
|
|
|
virtual std::string getAlias() = 0;
|
|
|
|
|
2011-03-21 09:57:48 +01:00
|
|
|
/// Returns list of groups this buddy is in.
|
2011-06-06 10:48:27 +02:00
|
|
|
|
2011-03-21 09:57:48 +01:00
|
|
|
/// \return groups
|
2011-03-18 13:47:50 +01:00
|
|
|
virtual std::vector<std::string> getGroups() = 0;
|
|
|
|
|
2011-03-21 09:57:48 +01:00
|
|
|
/// Returns current legacy network status and statuMessage of this buddy.
|
2011-06-06 10:48:27 +02:00
|
|
|
|
2011-03-21 09:57:48 +01:00
|
|
|
/// \param status current status/show is stored here
|
|
|
|
/// \param statusMessage current status message is stored here
|
|
|
|
/// \return true if status was stored successfully
|
2011-03-18 13:47:50 +01:00
|
|
|
virtual bool getStatus(Swift::StatusShow &status, std::string &statusMessage) = 0;
|
|
|
|
|
2011-06-06 10:48:27 +02:00
|
|
|
/// Returns SHA-1 hash of buddy icon (avatar) or empty string if there is no avatar for this buddy.
|
|
|
|
|
2011-03-21 09:57:48 +01:00
|
|
|
/// \return avatar hash or empty string.
|
2011-03-18 13:47:50 +01:00
|
|
|
virtual std::string getIconHash() = 0;
|
|
|
|
|
2013-02-22 09:45:31 +01:00
|
|
|
virtual bool isAvailable() = 0;
|
|
|
|
|
2011-06-06 10:48:27 +02:00
|
|
|
/// Returns legacy name of buddy from JID.
|
|
|
|
|
|
|
|
/// \param jid Jabber ID.
|
|
|
|
/// \return legacy name of buddy from JID.
|
2016-01-22 15:17:51 +01:00
|
|
|
static std::string JIDToLegacyName(const Swift::JID &jid, User *user = NULL);
|
|
|
|
static Buddy *JIDToBuddy(const Swift::JID &jid, User *user);
|
2012-08-09 14:57:57 +02:00
|
|
|
static BuddyFlag buddyFlagsFromJID(const Swift::JID &jid);
|
2011-04-06 14:32:03 +02:00
|
|
|
|
2012-08-02 07:47:18 +02:00
|
|
|
protected:
|
2011-03-24 11:42:31 +01:00
|
|
|
void generateJID();
|
2012-08-07 17:41:13 +02:00
|
|
|
Swift::JID m_jid;
|
2013-02-22 09:45:31 +01:00
|
|
|
std::vector<Swift::Presence::ref> m_presences;
|
2011-03-24 11:42:31 +01:00
|
|
|
|
2012-08-02 07:47:18 +02:00
|
|
|
private:
|
2011-03-18 13:47:50 +01:00
|
|
|
long m_id;
|
2011-03-21 09:57:48 +01:00
|
|
|
BuddyFlag m_flags;
|
2011-03-20 23:04:20 +01:00
|
|
|
RosterManager *m_rosterManager;
|
2012-03-08 20:04:56 +01:00
|
|
|
Subscription m_subscription;
|
2011-03-18 13:47:50 +01:00
|
|
|
};
|
2011-03-20 23:04:20 +01:00
|
|
|
|
|
|
|
}
|