Skip to content
Snippets Groups Projects
Commit e329a07e authored by Hugo Lefeuvre's avatar Hugo Lefeuvre Committed by Andreas Traczyk
Browse files

Forbid sending messages/calling banned contacts


Also: In order to avoid crashes in the future, we check the contact
index variable before using it in conversationmodel.

Change-Id: I038c7049781a9bce951f09ed4a0f1d3100e6df3c
Reviewed-by: default avatarAndreas Traczyk <andreas.traczyk@savoirfairelinux.com>
parent 3d6c7672
Branches
No related tags found
No related merge requests found
......@@ -39,6 +39,7 @@ struct Info
std::string registeredName;
bool isTrusted = false;
bool isPresent = false;
bool isBanned = false;
};
} // namespace contact
......
......@@ -137,8 +137,9 @@ BannedContactModel::columnCount( const QModelIndex& parent ) const
void
BannedContactModel::add(ContactMethod* cm)
{
if (d_ptr->m_lBanned.contains(cm))
if (isBanned(cm))
return;
beginInsertRows(QModelIndex(),d_ptr->m_lBanned.size(),d_ptr->m_lBanned.size());
d_ptr->m_lBanned << cm;
endInsertRows();
......@@ -151,6 +152,7 @@ BannedContactModel::add(ContactMethod* cm)
void
BannedContactModel::remove(ContactMethod* cm)
{
// Do not remove contact if contact isn't banned
auto rowIndex = d_ptr->m_lBanned.indexOf(cm);
if (rowIndex < 0)
return;
......@@ -166,3 +168,13 @@ BannedContactModel::remove(ContactMethod* cm)
ConfigurationManager::instance().addContact(cm->account()->id(), cm->uri());
}
/**
* this function returns whether passed ContactMethod is in the banned list or not.
* @param cm, the ContactMethod whose presence in the banned list should be checked.
*/
bool
BannedContactModel::isBanned(ContactMethod* cm)
{
return d_ptr->m_lBanned.contains(cm);
}
......@@ -45,6 +45,7 @@ public:
// Helper
void add(ContactMethod* cm);
void remove(ContactMethod* cm);
bool isBanned(ContactMethod* cm);
private:
virtual ~BannedContactModel();
......
......@@ -37,6 +37,7 @@
#include "contactmethod.h"
#include "namedirectory.h"
#include "phonedirectorymodel.h"
#include "bannedcontactmodel.h"
#include "private/vcardutils.h"
#include "authority/daemon.h"
......@@ -470,6 +471,7 @@ ContactModelPimpl::fillsWithRINGContacts() {
contact::Info contactInfo;
contactInfo.profileInfo = profileInfo;
contactInfo.registeredName = cm->registeredName().toStdString();
contactInfo.isBanned = account->bannedContactModel()->isBanned(cm);
{
std::lock_guard<std::mutex> lk(contactsMtx_);
......@@ -546,6 +548,13 @@ ContactModelPimpl::addToContacts(ContactMethod* cm, const profile::Type& type)
auto contactInfo = database::buildContactFromProfileId(db, contactId);
contactInfo.registeredName = cm->registeredName().toStdString();
auto* account = AccountModel::instance().getById(linked.owner.id.c_str());
if (not account) {
qDebug() << "ContactModel::addToContacts(), nullptr";
return;
}
contactInfo.isBanned = account->bannedContactModel()->isBanned(cm);
contactInfo.isPresent = cm->isPresent();
contactInfo.profileInfo.type = type; // Because PENDING should not be stored in the database
auto iter = contacts.find(contactInfo.profileInfo.uri);
......
......@@ -503,6 +503,12 @@ ConversationModelPimpl::placeCall(const std::string& uid, bool isAudioOnly)
if (url.empty())
return; // Incorrect item
// Don't call banned contact
if (contactInfo.isBanned) {
qDebug() << "ContactModel::placeCall: denied, contact is banned";
return;
}
sendContactRequest(participant);
if (linked.owner.profileInfo.type != profile::Type::SIP) {
......@@ -510,8 +516,13 @@ ConversationModelPimpl::placeCall(const std::string& uid, bool isAudioOnly)
}
// If call is with temporary contact, conversation has been removed and must be updated
int contactIndex;
if (isTemporary && (contactIndex = indexOfContact(convId)) < 0) {
qDebug() << "Can't place call: Other participant is not a contact";
return;
}
auto& newConv = isTemporary ? conversations.at(indexOfContact(convId)) : conversation;
auto& newConv = isTemporary ? conversations.at(contactIndex) : conversation;
convId = newConv.uid;
newConv.callId = linked.owner.callModel->createCall(url, isAudioOnly);
......@@ -556,6 +567,12 @@ ConversationModel::sendMessage(const std::string& uid, const std::string& body)
auto status = interaction::Status::SENDING;
for (const auto& participant: conversation.participants) {
auto contactInfo = owner.contactModel->getContact(participant);
if (contactInfo.isBanned) {
qDebug() << "ContactModel::sendMessage: denied, contact is banned";
return;
}
pimpl_->sendContactRequest(participant);
QStringList callLists = CallManager::instance().getCallList(); // no auto
......@@ -576,8 +593,13 @@ ConversationModel::sendMessage(const std::string& uid, const std::string& body)
// If first interaction with temporary contact, we have to update the conversations info
// at this stage
int contactIndex;
if (isTemporary && (contactIndex = pimpl_->indexOfContact(convId)) < 0) {
qDebug() << "Can't send message: Other participant is not a contact";
return;
}
auto& newConv = isTemporary ? pimpl_->conversations.at(pimpl_->indexOfContact(convId)) : conversation;
auto& newConv = isTemporary ? pimpl_->conversations.at(contactIndex) : conversation;
convId = newConv.uid;
// Add interaction to database
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment