<p>Joshua Colp <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/9311">View Change</a></p><div style="white-space:pre-wrap">Approvals:
George Joseph: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, approved
Jenkins2: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">AMI SendText action: Fix to use correct thread to send the text.<br><br>The AMI action was directly sending the text to the channel driver.<br>However, this makes two threads attempt to handle media and runs afowl of<br>CHECK_BLOCKING.<br><br>* Queue a read action to make the channel's media handling thread actually<br>send the text message. This changes the AMI actions success/fail response<br>to just mean the text was queued to be sent not that the text actually got<br>sent. The channel driver may not even support sending text messages.<br><br>ASTERISK-27943<br><br>Change-Id: I9dce343d8fa634ba5a416a1326d8a6340f98c379<br>---<br>M include/asterisk/frame.h<br>M main/channel.c<br>M main/manager.c<br>3 files changed, 30 insertions(+), 5 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/asterisk/frame.h b/include/asterisk/frame.h</span><br><span>index 542407e..b618d19 100644</span><br><span>--- a/include/asterisk/frame.h</span><br><span>+++ b/include/asterisk/frame.h</span><br><span>@@ -337,6 +337,7 @@</span><br><span> </span><br><span> enum ast_frame_read_action {</span><br><span> AST_FRAME_READ_ACTION_CONNECTED_LINE_MACRO,</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_FRAME_READ_ACTION_SEND_TEXT,</span><br><span> };</span><br><span> </span><br><span> struct ast_control_read_action_payload {</span><br><span>diff --git a/main/channel.c b/main/channel.c</span><br><span>index dcb284b..c0e3cb4 100644</span><br><span>--- a/main/channel.c</span><br><span>+++ b/main/channel.c</span><br><span>@@ -3773,6 +3773,11 @@</span><br><span> ast_party_connected_line_free(&connected);</span><br><span> ast_channel_lock(chan);</span><br><span> break;</span><br><span style="color: hsl(120, 100%, 40%);">+ case AST_FRAME_READ_ACTION_SEND_TEXT:</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unlock(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sendtext(chan, (const char *) read_action_payload->payload);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_lock(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span> }</span><br><span> ast_frfree(f);</span><br><span> f = &ast_null_frame;</span><br><span>diff --git a/main/manager.c b/main/manager.c</span><br><span>index ec50cb8..ab42432 100644</span><br><span>--- a/main/manager.c</span><br><span>+++ b/main/manager.c</span><br><span>@@ -4745,10 +4745,13 @@</span><br><span> </span><br><span> static int action_sendtext(struct mansession *s, const struct message *m)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_channel *c = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_channel *c;</span><br><span> const char *name = astman_get_header(m, "Channel");</span><br><span> const char *textmsg = astman_get_header(m, "Message");</span><br><span style="color: hsl(0, 100%, 40%);">- int res = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_control_read_action_payload *frame_payload;</span><br><span style="color: hsl(120, 100%, 40%);">+ int payload_size;</span><br><span style="color: hsl(120, 100%, 40%);">+ int frame_size;</span><br><span style="color: hsl(120, 100%, 40%);">+ int res;</span><br><span> </span><br><span> if (ast_strlen_zero(name)) {</span><br><span> astman_send_error(s, m, "No channel specified");</span><br><span>@@ -4760,13 +4763,29 @@</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (!(c = ast_channel_get_by_name(name))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ c = ast_channel_get_by_name(name);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!c) {</span><br><span> astman_send_error(s, m, "No such channel");</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- res = ast_sendtext(c, textmsg);</span><br><span style="color: hsl(0, 100%, 40%);">- c = ast_channel_unref(c);</span><br><span style="color: hsl(120, 100%, 40%);">+ payload_size = strlen(textmsg) + 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ frame_size = payload_size + sizeof(*frame_payload);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ frame_payload = ast_malloc(frame_size);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!frame_payload) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unref(c);</span><br><span style="color: hsl(120, 100%, 40%);">+ astman_send_error(s, m, "Failure");</span><br><span style="color: hsl(120, 100%, 40%);">+ return 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%);">+ frame_payload->action = AST_FRAME_READ_ACTION_SEND_TEXT;</span><br><span style="color: hsl(120, 100%, 40%);">+ frame_payload->payload_size = payload_size;</span><br><span style="color: hsl(120, 100%, 40%);">+ memcpy(frame_payload->payload, textmsg, payload_size);</span><br><span style="color: hsl(120, 100%, 40%);">+ res = ast_queue_control_data(c, AST_CONTROL_READ_ACTION, frame_payload, frame_size);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(frame_payload);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unref(c);</span><br><span> </span><br><span> if (res >= 0) {</span><br><span> astman_send_ack(s, m, "Success");</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/9311">change 9311</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/9311"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I9dce343d8fa634ba5a416a1326d8a6340f98c379 </div>
<div style="display:none"> Gerrit-Change-Number: 9311 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Richard Mudgett <rmudgett@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>