Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Swiften/Client/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <Swiften/Disco/EntityCapsManager.h>
#include <Swiften/FileTransfer/FileTransferManagerImpl.h>
#include <Swiften/Jingle/JingleSessionManager.h>
#include <Swiften/MIX/MIXRegistry.h>
#include <Swiften/MUC/MUCManager.h>
#include <Swiften/MUC/MUCRegistry.h>
#include <Swiften/Network/NetworkFactories.h>
Expand Down Expand Up @@ -58,6 +59,8 @@ Client::Client(const JID& jid, const SafeString& password, NetworkFactories* net
directedPresenceSender = new DirectedPresenceSender(stanzaChannelPresenceSender);
discoManager = new ClientDiscoManager(getIQRouter(), directedPresenceSender, networkFactories->getCryptoProvider());

mixRegistry = new MIXRegistry(getJID(), getIQRouter(), getRoster());

mucRegistry = new MUCRegistry();
mucManager = new MUCManager(getStanzaChannel(), getIQRouter(), directedPresenceSender, mucRegistry);

Expand Down Expand Up @@ -118,6 +121,8 @@ Client::~Client() {
delete avatarManager;
delete vcardManager;

delete mixRegistry;

delete mucManager;
delete mucRegistry;

Expand Down Expand Up @@ -148,13 +153,13 @@ void Client::handleConnected() {
discoManager->handleConnected();
}

void Client::requestRoster() {
void Client::requestRoster(bool includeMIX) {
// FIXME: We should set this once when the session is finished, but there
// is currently no callback for this
if (getSession()) {
rosterController->setUseVersioning(getSession()->getRosterVersioningSupported());
}
rosterController->requestRoster();
rosterController->requestRoster(includeMIX);
}

Presence::ref Client::getLastPresence(const JID& jid) const {
Expand Down
8 changes: 7 additions & 1 deletion Swiften/Client/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace Swift {
class FileTransferManager;
class FileTransferManager;
class JingleSessionManager;
class MIXRegistry;
class MUCManager;
class MUCRegistry;
class MemoryStorages;
Expand Down Expand Up @@ -93,7 +94,7 @@ namespace Swift {
*
* \see getRoster()
*/
void requestRoster();
void requestRoster(bool includeMIX = false);

/**
* Returns the last received presence for the given (full) JID.
Expand All @@ -111,6 +112,10 @@ namespace Swift {

PresenceSender* getPresenceSender() const;

MIXRegistry* getMIXRegistry() const {
return mixRegistry;
}

MUCManager* getMUCManager() const {
return mucManager;
}
Expand Down Expand Up @@ -191,6 +196,7 @@ namespace Swift {
PresenceOracle* presenceOracle;
DirectedPresenceSender* directedPresenceSender;
StanzaChannelPresenceSender* stanzaChannelPresenceSender;
MIXRegistry* mixRegistry;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initialise with nullptr or better, keep as unique_ptr.

MUCRegistry* mucRegistry;
VCardManager* vcardManager;
AvatarManager* avatarManager;
Expand Down
1 change: 1 addition & 0 deletions Swiften/Elements/DiscoInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const std::string DiscoInfo::MessageDeliveryReceiptsFeature = std::string("urn:x
const std::string DiscoInfo::WhiteboardFeature = std::string("http://swift.im/whiteboard");
const std::string DiscoInfo::BlockingCommandFeature = std::string("urn:xmpp:blocking");
const std::string DiscoInfo::MessageCarbonsFeature = std::string("urn:xmpp:carbons:2");
const std::string DiscoInfo::MIXFeature = std::string("urn:xmpp:mix:0");

bool DiscoInfo::Identity::operator<(const Identity& other) const {
if (category_ == other.category_) {
Expand Down
1 change: 1 addition & 0 deletions Swiften/Elements/DiscoInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace Swift {
static const std::string WhiteboardFeature;
static const std::string BlockingCommandFeature;
static const std::string MessageCarbonsFeature;
static const std::string MIXFeature;

class Identity {
public:
Expand Down
8 changes: 6 additions & 2 deletions Swiften/Elements/RosterItemPayload.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ namespace Swift {
public:
enum Subscription { None, To, From, Both, Remove };

RosterItemPayload() : subscription_(None), ask_(false) {}
RosterItemPayload(const JID& jid, const std::string& name, Subscription subscription, const std::vector<std::string>& groups = std::vector<std::string>()) : jid_(jid), name_(name), subscription_(subscription), groups_(groups), ask_(false) { }
RosterItemPayload() : subscription_(None), ask_(false), isMIXChannel_(false) {}
RosterItemPayload(const JID& jid, const std::string& name, Subscription subscription, const std::vector<std::string>& groups = std::vector<std::string>()) : jid_(jid), name_(name), subscription_(subscription), groups_(groups), ask_(false) , isMIXChannel_(false) { }

void setJID(const JID& jid) { jid_ = jid; }
const JID& getJID() const { return jid_; }
Expand All @@ -41,12 +41,16 @@ namespace Swift {
unknownContent_ += c;
}

void setMIXChannel(bool isMIXChannel) { isMIXChannel_ = isMIXChannel; }
bool isMIXChannel() const { return isMIXChannel_; }

private:
JID jid_;
std::string name_;
Subscription subscription_;
std::vector<std::string> groups_;
bool ask_;
std::string unknownContent_;
bool isMIXChannel_;
};
}
11 changes: 10 additions & 1 deletion Swiften/Elements/RosterPayload.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Swift {
typedef std::vector<RosterItemPayload> RosterItemPayloads;

public:
RosterPayload() {}
RosterPayload(bool hasAnnotate = false) : hasAnnotate_(hasAnnotate) {}

boost::optional<RosterItemPayload> getItem(const JID& jid) const;

Expand All @@ -42,7 +42,16 @@ namespace Swift {
version_ = version;
}

bool hasMIXAnnotationSupport() const {
return hasAnnotate_;
}

void setSupportsMIXAnnotations(bool hasAnnotate) {
hasAnnotate_ = hasAnnotate;
}

private:
bool hasAnnotate_;
RosterItemPayloads items_;
boost::optional<std::string> version_;
};
Expand Down
19 changes: 0 additions & 19 deletions Swiften/MIX/MIX.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
#include <Swiften/Base/API.h>
#include <Swiften/JID/JID.h>
#include <Swiften/Elements/Form.h>
#include <Swiften/Elements/MIXJoin.h>
#include <Swiften/Elements/MIXLeave.h>
#include <Swiften/Elements/MIXUpdateSubscription.h>
#include <Swiften/Elements/MIXUserPreference.h>
#include <Swiften/Elements/ErrorPayload.h>
Expand All @@ -29,26 +27,11 @@ namespace Swift {
public:
virtual ~MIX();

/**
* Join a MIX channel and subscribe to nodes.
*/
virtual void joinChannel(const std::unordered_set<std::string>& nodes) = 0;

/**
* Join Channel with a set of preferences.
*/
virtual void joinChannelWithPreferences(const std::unordered_set<std::string>& nodes, Form::ref form) = 0;

/**
* Update subscription of nodes.
*/
virtual void updateSubscription(const std::unordered_set<std::string>& nodes) = 0;

/**
* Leave a MIX channel and unsubcribe nodes.
*/
virtual void leaveChannel() = 0;

/**
* Request a configuration form for updating preferences.
*/
Expand All @@ -60,8 +43,6 @@ namespace Swift {
virtual void updatePreferences(Form::ref form) = 0;

public:
boost::signals2::signal<void (MIXJoin::ref /* joinResponse */, ErrorPayload::ref /* joinError */)> onJoinResponse;
boost::signals2::signal<void (MIXLeave::ref /* leaveResponse */, ErrorPayload::ref /* leaveError */)> onLeaveResponse;
boost::signals2::signal<void (MIXUpdateSubscription::ref /* updateResponse */, ErrorPayload::ref /* updateError */)> onSubscriptionUpdateResponse;
boost::signals2::signal<void (Form::ref /* preferencesForm */, ErrorPayload::ref /* failedConfiguration */)> onPreferencesFormResponse;
boost::signals2::signal<void (MIXUserPreference::ref /* userPreferenceResponse */, ErrorPayload::ref /* failedUpdate */)> onPreferencesUpdateResponse;
Expand Down
34 changes: 0 additions & 34 deletions Swiften/MIX/MIXImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,6 @@ MIXImpl::~MIXImpl() {

}

void MIXImpl::joinChannel(const std::unordered_set<std::string>& nodes) {
joinChannelWithPreferences(nodes, nullptr);
}

void MIXImpl::joinChannelWithPreferences(const std::unordered_set<std::string>& nodes, Form::ref form) {
auto joinPayload = std::make_shared<MIXJoin>();
joinPayload->setChannel(channelJID_);
for (auto node : nodes) {
joinPayload->addSubscription(node);
}
if (form) {
joinPayload->setForm(form);
}
auto request = std::make_shared<GenericRequest<MIXJoin>>(IQ::Set, getJID(), joinPayload, iqRouter_);
request->onResponse.connect(boost::bind(&MIXImpl::handleJoinResponse, this, _1, _2));
request->send();
}

void MIXImpl::handleJoinResponse(MIXJoin::ref payload, ErrorPayload::ref error) {
onJoinResponse(payload, error);
}

void MIXImpl::updateSubscription(const std::unordered_set<std::string>& nodes) {
auto updateSubscriptionPayload = std::make_shared<MIXUpdateSubscription>();
updateSubscriptionPayload->setSubscriptions(nodes);
Expand All @@ -55,18 +33,6 @@ void MIXImpl::handleUpdateSubscriptionResponse(MIXUpdateSubscription::ref payloa
onSubscriptionUpdateResponse(payload, error);
}

void MIXImpl::leaveChannel() {
auto leavePayload = std::make_shared<MIXLeave>();
leavePayload->setChannel(channelJID_);
auto request = std::make_shared<GenericRequest<MIXLeave>>(IQ::Set, getJID(), leavePayload, iqRouter_);
request->onResponse.connect(boost::bind(&MIXImpl::handleLeaveResponse, this, _1, _2));
request->send();
}

void MIXImpl::handleLeaveResponse(MIXLeave::ref payload, ErrorPayload::ref error) {
onLeaveResponse(payload, error);
}

void MIXImpl::requestPreferencesForm() {
auto prefPayload = std::make_shared<MIXUserPreference>();
auto request = std::make_shared<GenericRequest<MIXUserPreference>>(IQ::Get, channelJID_, prefPayload, iqRouter_);
Expand Down
8 changes: 0 additions & 8 deletions Swiften/MIX/MIXImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,13 @@ namespace Swift {
return channelJID_;
}

virtual void joinChannel(const std::unordered_set<std::string>& nodes) override;

virtual void joinChannelWithPreferences(const std::unordered_set<std::string>& nodes, Form::ref form) override;

virtual void updateSubscription(const std::unordered_set<std::string>& nodes) override;

virtual void leaveChannel() override;

virtual void requestPreferencesForm() override;

virtual void updatePreferences(Form::ref form) override;

private:
void handleJoinResponse(MIXJoin::ref, ErrorPayload::ref);
void handleLeaveResponse(MIXLeave::ref, ErrorPayload::ref);
void handleUpdateSubscriptionResponse(MIXUpdateSubscription::ref, ErrorPayload::ref);
void handlePreferencesFormReceived(MIXUserPreference::ref, ErrorPayload::ref);
void handlePreferencesResultReceived(MIXUserPreference::ref /*payload*/, ErrorPayload::ref error);
Expand Down
85 changes: 85 additions & 0 deletions Swiften/MIX/MIXRegistry.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright (c) 2017 Tarun Gupta
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/

#include <Swiften/MIX/MIXRegistry.h>
#include <Swiften/Base/Log.h>

namespace Swift {

MIXRegistry::MIXRegistry(const JID& ownJID, IQRouter* iqRouter, XMPPRoster* xmppRoster) : ownJID_(ownJID), iqRouter_(iqRouter), xmppRoster_(xmppRoster) {
xmppRoster_->onJIDAdded.connect(boost::bind(&MIXRegistry::handleJIDAdded, this, _1));
xmppRoster_->onJIDRemoved.connect(boost::bind(&MIXRegistry::handleJIDRemoved, this, _1));
}

MIXRegistry::~MIXRegistry() {

}

void MIXRegistry::joinChannel(const JID& channelJID, const std::unordered_set<std::string>& nodes) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably check if a channel with channelJID is already on the roster and log a warning instead of issuing a join.

auto i = entries_.find(channelJID);
if (i != entries_.end()) {
SWIFT_LOG(warning) << "Channel already joined: " << channelJID << std::endl;
return;
}
auto joinPayload = std::make_shared<MIXJoin>();
joinPayload->setChannel(channelJID);
for (auto node : nodes) {
joinPayload->addSubscription(node);
}
auto request = std::make_shared<GenericRequest<MIXJoin>>(IQ::Set, ownJID_.toBare(), joinPayload, iqRouter_);
request->onResponse.connect(boost::bind(&MIXRegistry::handleJoinResponse, this, _1, _2));
request->send();
}

void MIXRegistry::handleJoinResponse(MIXJoin::ref /*payload*/, ErrorPayload::ref error) {
if (error) {
onChannelJoinFailed(error);
}
}

void MIXRegistry::leaveChannel(const JID& channelJID) {
auto leavePayload = std::make_shared<MIXLeave>();
leavePayload->setChannel(channelJID);
auto request = std::make_shared<GenericRequest<MIXLeave>>(IQ::Set, ownJID_.toBare(), leavePayload, iqRouter_);
request->send();
}

void MIXRegistry::handleJIDAdded(const JID& jid) {
if (xmppRoster_->isMIXChannel(jid)) {
auto i = entries_.find(jid);
if (i == entries_.end()) {
entries_.insert(std::make_pair(jid, std::make_shared<MIXImpl>(ownJID_, jid, iqRouter_)));
}
onChannelJoined(jid);
}
}

void MIXRegistry::handleJIDRemoved(const JID& jid) {
auto i = entries_.find(jid);
if (i != entries_.end()) {
entries_.erase(jid);
onChannelLeft(jid);
}
}

std::unordered_set<MIXImpl::ref> MIXRegistry::getChannels() {
std::unordered_set<MIXImpl::ref> results;
for (const auto& entry : entries_) {
results.insert(entry.second);
}
return results;
}

MIX::ref MIXRegistry::getMIXInstance(const JID& channelJID) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method should return a MIXImpl instance for the channel JID, if and only if it is joined, so it is in the roster.

auto i = entries_.find(channelJID);
if (i != entries_.end()) {
return i->second;
} else {
return nullptr;
}
}

}
Loading