<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/14381">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Friendly Automation: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">app_queue: track masquerades in app_queue to avoid leaked stasis subscriptions<br><br>Add a new "masquarade" channel event, and use it in app_queue to track unique id's.<br><br>Testcase is submitted as https://gerrit.asterisk.org/c/testsuite/+/14210<br><br>ASTERISK-28829 #close<br>ASTERISK-25844 #close<br><br>Change-Id: Ifc5f9f9fd70903f3c6e49738d3bc632b085d2df6<br>---<br>M apps/app_queue.c<br>M include/asterisk/stasis_channels.h<br>M main/channel.c<br>M main/stasis_channels.c<br>4 files changed, 45 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/apps/app_queue.c b/apps/app_queue.c</span><br><span>index a9630c9..3a572ef 100644</span><br><span>--- a/apps/app_queue.c</span><br><span>+++ b/apps/app_queue.c</span><br><span>@@ -6233,6 +6233,33 @@</span><br><span> remove_stasis_subscriptions(queue_data);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static void handle_masquerade(void *userdata, struct stasis_subscription *sub,</span><br><span style="color: hsl(120, 100%, 40%);">+ struct stasis_message *msg)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct queue_stasis_data *queue_data = userdata;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_channel_blob *channel_blob = stasis_message_data(msg);</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *new_channel_id;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ new_channel_id = ast_json_string_get(ast_json_object_get(channel_blob->blob, "newchanneluniqueid"));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_lock(queue_data);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (queue_data->dying) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_unlock(queue_data);</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%);">+ if (!strcmp(channel_blob->snapshot->uniqueid, queue_data->caller_uniqueid)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_debug(1, "Replacing caller channel %s with %s due to masquerade\n", queue_data->caller_uniqueid, new_channel_id);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_string_field_set(queue_data, caller_uniqueid, new_channel_id);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (!strcmp(channel_blob->snapshot->uniqueid, queue_data->member_uniqueid)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_debug(1, "Replacing member channel %s with %s due to masquerade\n", queue_data->member_uniqueid, new_channel_id);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_string_field_set(queue_data, member_uniqueid, new_channel_id);</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%);">+ ao2_unlock(queue_data);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*!</span><br><span> * \internal</span><br><span> * \brief Callback for all stasis channel events</span><br><span>@@ -6306,6 +6333,8 @@</span><br><span> handle_local_optimization_end, queue_data);</span><br><span> stasis_message_router_add(queue_data->channel_router, ast_channel_hangup_request_type(),</span><br><span> handle_hangup, queue_data);</span><br><span style="color: hsl(120, 100%, 40%);">+ stasis_message_router_add(queue_data->channel_router, ast_channel_masquerade_type(),</span><br><span style="color: hsl(120, 100%, 40%);">+ handle_masquerade, queue_data);</span><br><span> stasis_message_router_set_default(queue_data->channel_router,</span><br><span> queue_channel_cb, queue_data);</span><br><span> </span><br><span>diff --git a/include/asterisk/stasis_channels.h b/include/asterisk/stasis_channels.h</span><br><span>index fec451f..3942c56 100644</span><br><span>--- a/include/asterisk/stasis_channels.h</span><br><span>+++ b/include/asterisk/stasis_channels.h</span><br><span>@@ -392,6 +392,14 @@</span><br><span> struct stasis_message_type *ast_channel_hangup_request_type(void);</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 16</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Message type for when a channel is being masqueraded</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval A stasis message type</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+struct stasis_message_type *ast_channel_masquerade_type(void);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span> * \since 12</span><br><span> * \brief Message type for when DTMF begins on a channel.</span><br><span> *</span><br><span>diff --git a/main/channel.c b/main/channel.c</span><br><span>index 4b1b2ea..9f68a9a 100644</span><br><span>--- a/main/channel.c</span><br><span>+++ b/main/channel.c</span><br><span>@@ -10940,6 +10940,7 @@</span><br><span> </span><br><span> int ast_channel_move(struct ast_channel *dest, struct ast_channel *source)</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+ RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);</span><br><span> SCOPED_MUTEX(lock, &channel_move_lock);</span><br><span> </span><br><span> if (dest == source) {</span><br><span>@@ -10964,6 +10965,10 @@</span><br><span> ast_channel_masq_set(dest, source);</span><br><span> ast_channel_masqr_set(source, dest);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ blob = ast_json_pack("{s: s}",</span><br><span style="color: hsl(120, 100%, 40%);">+ "newchanneluniqueid", ast_channel_uniqueid(dest));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_publish_blob(source, ast_channel_masquerade_type(), blob);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> ast_channel_unlock(dest);</span><br><span> ast_channel_unlock(source);</span><br><span> </span><br><span>diff --git a/main/stasis_channels.c b/main/stasis_channels.c</span><br><span>index 58d52bf..7cd4295 100644</span><br><span>--- a/main/stasis_channels.c</span><br><span>+++ b/main/stasis_channels.c</span><br><span>@@ -1290,6 +1290,7 @@</span><br><span> STASIS_MESSAGE_TYPE_DEFN(ast_channel_hangup_request_type,</span><br><span> .to_json = hangup_request_to_json,</span><br><span> );</span><br><span style="color: hsl(120, 100%, 40%);">+STASIS_MESSAGE_TYPE_DEFN(ast_channel_masquerade_type);</span><br><span> STASIS_MESSAGE_TYPE_DEFN(ast_channel_dtmf_begin_type);</span><br><span> STASIS_MESSAGE_TYPE_DEFN(ast_channel_dtmf_end_type,</span><br><span> .to_json = dtmf_end_to_json,</span><br><span>@@ -1338,6 +1339,7 @@</span><br><span> STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_dial_type);</span><br><span> STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_varset_type);</span><br><span> STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_hangup_request_type);</span><br><span style="color: hsl(120, 100%, 40%);">+ STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_masquerade_type);</span><br><span> STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_dtmf_begin_type);</span><br><span> STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_dtmf_end_type);</span><br><span> STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_hold_type);</span><br><span>@@ -1388,6 +1390,7 @@</span><br><span> res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_dial_type);</span><br><span> res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_varset_type);</span><br><span> res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_hangup_request_type);</span><br><span style="color: hsl(120, 100%, 40%);">+ res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_masquerade_type);</span><br><span> res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_dtmf_begin_type);</span><br><span> res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_dtmf_end_type);</span><br><span> res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_hold_type);</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/14381">change 14381</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/+/14381"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-Change-Id: Ifc5f9f9fd70903f3c6e49738d3bc632b085d2df6 </div>
<div style="display:none"> Gerrit-Change-Number: 14381 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Reviewer: Nathan Bruning <nathan@iperity.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>