From fc796a3d47d9338c399a5ec99f8c6fc482d52cfb Mon Sep 17 00:00:00 2001
From: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
Date: Mon, 29 May 2017 16:23:14 -0400
Subject: [PATCH] conference: prevent a call to be added twice

Fix Manager::addParticipant() to always accept (return true)
to add a call already in given conference (no-op).
Without this patch, doing so causes a daemon crash.

Change-Id: I7b03a1349e7cac148ba3991b8e0bc2a9f1521c85
Reviewed-by: Olivier Soldano <olivier.soldano@savoirfairelinux.com>
---
 src/manager.cpp | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/manager.cpp b/src/manager.cpp
index d66067e794..b3edbad11e 100644
--- a/src/manager.cpp
+++ b/src/manager.cpp
@@ -1307,8 +1307,6 @@ bool
 Manager::addParticipant(const std::string& callId,
                         const std::string& conferenceId)
 {
-    RING_DBG("Add participant %s to %s", callId.c_str(), conferenceId.c_str());
-
     auto iter = pimpl_->conferenceMap_.find(conferenceId);
     if (iter == pimpl_->conferenceMap_.end() or iter->second == nullptr) {
         RING_ERR("Conference id is not valid");
@@ -1321,6 +1319,14 @@ Manager::addParticipant(const std::string& callId,
         return false;
     }
 
+    // No-op if the call is already a conference participant
+    if (call->getConfId() == conferenceId) {
+        RING_WARN("Call %s already participant of conf %s", callId.c_str(), conferenceId.c_str());
+        return true;
+    }
+
+    RING_DBG("Add participant %s to %s", callId.c_str(), conferenceId.c_str());
+
     // store the current call id (it will change in offHoldCall or in answerCall)
     auto current_call_id = getCurrentCallId();
 
-- 
GitLab