<p>George Joseph has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/11455">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">app_confbridge: Attended transfer event fixup<br><br>When a channel already in a conference bridge is attended transfered<br>to another extension, or when an exysting call is attended<br>transferred into a conference bridge, we now generate ConfbridgeJoin<br>and ConfbridgeLeave events for the entering and departing channels.<br><br>Change-Id: Id7709cfbceb26fbcb828b2d0d2a6b2fbeaf028e1<br>---<br>M apps/app_confbridge.c<br>M apps/confbridge/confbridge_manager.c<br>M apps/confbridge/include/confbridge.h<br>M main/cdr.c<br>4 files changed, 154 insertions(+), 2 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/55/11455/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/apps/app_confbridge.c b/apps/app_confbridge.c</span><br><span>index df93215..888a25f 100644</span><br><span>--- a/apps/app_confbridge.c</span><br><span>+++ b/apps/app_confbridge.c</span><br><span>@@ -1459,6 +1459,122 @@</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+void confbridge_handle_atxfer(struct ast_attended_transfer_message *msg)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_channel_snapshot *old_snapshot;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_channel_snapshot *new_snapshot;</span><br><span style="color: hsl(120, 100%, 40%);">+ char *confbr_name = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ char *comma;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct confbridge_conference *conference = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct confbridge_user *user = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct confbridge_user temp_user = { 0, };</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_channel *new_chan = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_channel *old_chan = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct user_profile u_profile;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (msg->to_transferee.channel_snapshot</span><br><span style="color: hsl(120, 100%, 40%);">+ && strcmp(msg->to_transferee.channel_snapshot->appl, "ConfBridge") == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* We're transferring a bridge to an extension */</span><br><span style="color: hsl(120, 100%, 40%);">+ old_snapshot = msg->to_transferee.channel_snapshot;</span><br><span style="color: hsl(120, 100%, 40%);">+ new_snapshot = msg->target;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (msg->to_transfer_target.channel_snapshot</span><br><span style="color: hsl(120, 100%, 40%);">+ && strcmp(msg->to_transfer_target.channel_snapshot->appl, "ConfBridge") == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* We're transferring a call to a bridge */</span><br><span style="color: hsl(120, 100%, 40%);">+ old_snapshot = msg->to_transfer_target.channel_snapshot;</span><br><span style="color: hsl(120, 100%, 40%);">+ new_snapshot = msg->transferee;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Could not determine proper channels\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /*</span><br><span style="color: hsl(120, 100%, 40%);">+ * old_snapshot->data should have the original parameters passed to</span><br><span style="color: hsl(120, 100%, 40%);">+ * the ConfBridge app:</span><br><span style="color: hsl(120, 100%, 40%);">+ * conference[,bridge_profile[,user_profile[,menu]]]</span><br><span style="color: hsl(120, 100%, 40%);">+ * We'll use "conference" to look up the bridge.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * We _could_ use old_snapshot->bridgeid to get the bridge but</span><br><span style="color: hsl(120, 100%, 40%);">+ * that would involve locking the conference_bridges container</span><br><span style="color: hsl(120, 100%, 40%);">+ * and iterating over it looking for a matching bridge.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_strlen_zero(old_snapshot->data)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Channel '%s' didn't have app data set\n", old_snapshot->name);</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ confbr_name = ast_strdupa(old_snapshot->data);</span><br><span style="color: hsl(120, 100%, 40%);">+ comma = strchr(confbr_name, ',');</span><br><span style="color: hsl(120, 100%, 40%);">+ if (comma) {</span><br><span style="color: hsl(120, 100%, 40%);">+ *comma = '\0';</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_debug(1, "Confbr: %s Leaving: %s Joining: %s\n", confbr_name, old_snapshot->name, new_snapshot->name);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ conference = ao2_find(conference_bridges, confbr_name, OBJ_SEARCH_KEY);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!conference) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Conference bridge '%s' not found\n", confbr_name);</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_lock(conference);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_LIST_TRAVERSE(&conference->active_list, user, list) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (strcasecmp(ast_channel_name(user->chan), old_snapshot->name) == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ old_chan = user->chan;</span><br><span style="color: hsl(120, 100%, 40%);">+ u_profile = user->u_profile;</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!old_chan && conference->waitingusers) {</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_LIST_TRAVERSE(&conference->waiting_list, user, list) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (strcasecmp(ast_channel_name(user->chan), old_snapshot->name) == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ old_chan = user->chan;</span><br><span style="color: hsl(120, 100%, 40%);">+ u_profile = user->u_profile;</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!old_chan) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Channel '%s' left before it could be replaced in bridge '%s'\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ old_snapshot->name, confbr_name);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_unlock(conference);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(conference, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_ref(old_chan);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ new_chan = ast_channel_get_by_name(new_snapshot->name);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!new_chan) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Channel '%s' left before it could be joined to bridge '%s'\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ new_snapshot->name, confbr_name);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_cleanup(old_chan);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_unlock(conference);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(conference, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_debug(1, "Old chan: %p %s New chan: %p %s\n", old_chan, ast_channel_name(old_chan),</span><br><span style="color: hsl(120, 100%, 40%);">+ new_chan, ast_channel_name(new_chan));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /*</span><br><span style="color: hsl(120, 100%, 40%);">+ * We're going to use the existing user profile to create the messages.</span><br><span style="color: hsl(120, 100%, 40%);">+ * It and the channel are the only things in the user structure that</span><br><span style="color: hsl(120, 100%, 40%);">+ * are used by the send event functions.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ temp_user.u_profile = u_profile;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ temp_user.chan = old_chan;</span><br><span style="color: hsl(120, 100%, 40%);">+ send_leave_event(&temp_user, conference);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_cleanup(old_chan);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ temp_user.chan = new_chan;</span><br><span style="color: hsl(120, 100%, 40%);">+ send_join_event(&temp_user, conference);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_cleanup(new_chan);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_unlock(conference);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(conference, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*!</span><br><span> * \brief Join a conference bridge</span><br><span> *</span><br><span>diff --git a/apps/confbridge/confbridge_manager.c b/apps/confbridge/confbridge_manager.c</span><br><span>index 9ac0d55..c6ae0af 100644</span><br><span>--- a/apps/confbridge/confbridge_manager.c</span><br><span>+++ b/apps/confbridge/confbridge_manager.c</span><br><span>@@ -325,6 +325,26 @@</span><br><span> ast_free(extra_text);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static void confbridge_atxfer_cb(void *data, struct stasis_subscription *sub,</span><br><span style="color: hsl(120, 100%, 40%);">+ struct stasis_message *message)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_attended_transfer_message *msg = stasis_message_data(message);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (msg->result != AST_BRIDGE_TRANSFER_SUCCESS) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /*</span><br><span style="color: hsl(120, 100%, 40%);">+ * This callback will get called for ALL attended transfers</span><br><span style="color: hsl(120, 100%, 40%);">+ * so we need to make sure this transfer belongs to</span><br><span style="color: hsl(120, 100%, 40%);">+ * a conference bridge before trying to handle it.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (msg->dest_type == AST_ATTENDED_TRANSFER_DEST_APP</span><br><span style="color: hsl(120, 100%, 40%);">+ && strcmp(msg->dest.app, "ConfBridge") == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ confbridge_handle_atxfer(msg);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static void confbridge_start_record_cb(void *data, struct stasis_subscription *sub,</span><br><span> struct stasis_message *message)</span><br><span> {</span><br><span>@@ -452,6 +472,13 @@</span><br><span> return -1;</span><br><span> }</span><br><span> if (stasis_message_router_add(bridge_state_router,</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_attended_transfer_type(),</span><br><span style="color: hsl(120, 100%, 40%);">+ confbridge_atxfer_cb,</span><br><span style="color: hsl(120, 100%, 40%);">+ NULL)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ manager_confbridge_shutdown();</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (stasis_message_router_add(bridge_state_router,</span><br><span> confbridge_leave_type(),</span><br><span> confbridge_leave_cb,</span><br><span> NULL)) {</span><br><span>diff --git a/apps/confbridge/include/confbridge.h b/apps/confbridge/include/confbridge.h</span><br><span>index e59400c..9bedfc0 100644</span><br><span>--- a/apps/confbridge/include/confbridge.h</span><br><span>+++ b/apps/confbridge/include/confbridge.h</span><br><span>@@ -28,6 +28,7 @@</span><br><span> #include "asterisk/channel.h"</span><br><span> #include "asterisk/bridge.h"</span><br><span> #include "asterisk/bridge_features.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/stasis_bridges.h"</span><br><span> #include "conf_state.h"</span><br><span> </span><br><span> /* Maximum length of a conference bridge name */</span><br><span>@@ -650,4 +651,14 @@</span><br><span> * \retval -1 on error.</span><br><span> */</span><br><span> int conf_announce_channel_push(struct ast_channel *ast);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Create join/leave events for attended transfers</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 13.28.0</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param msg The attended transfer stasis message</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+void confbridge_handle_atxfer(struct ast_attended_transfer_message *msg);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> #endif</span><br><span>diff --git a/main/cdr.c b/main/cdr.c</span><br><span>index 496fb36..644ebdd 100644</span><br><span>--- a/main/cdr.c</span><br><span>+++ b/main/cdr.c</span><br><span>@@ -1593,14 +1593,12 @@</span><br><span> static int base_process_bridge_leave(struct cdr_object *cdr, struct ast_bridge_snapshot *bridge, struct ast_channel_snapshot *channel)</span><br><span> {</span><br><span> /* In general, most things shouldn't get a bridge leave */</span><br><span style="color: hsl(0, 100%, 40%);">- ast_assert(0);</span><br><span> return 1;</span><br><span> }</span><br><span> </span><br><span> static int base_process_dial_end(struct cdr_object *cdr, struct ast_channel_snapshot *caller, struct ast_channel_snapshot *peer, const char *dial_status)</span><br><span> {</span><br><span> /* In general, most things shouldn't get a dial end. */</span><br><span style="color: hsl(0, 100%, 40%);">- ast_assert(0);</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/11455">change 11455</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/11455"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: certified/13.21 </div>
<div style="display:none"> Gerrit-Change-Id: Id7709cfbceb26fbcb828b2d0d2a6b2fbeaf028e1 </div>
<div style="display:none"> Gerrit-Change-Number: 11455 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>