<p>Richard Mudgett has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/9310">View Change</a></p><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;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/10/9310/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/include/asterisk/frame.h b/include/asterisk/frame.h<br>index 542407e..b618d19 100644<br>--- a/include/asterisk/frame.h<br>+++ b/include/asterisk/frame.h<br>@@ -337,6 +337,7 @@<br> <br> enum ast_frame_read_action {<br>     AST_FRAME_READ_ACTION_CONNECTED_LINE_MACRO,<br>+  AST_FRAME_READ_ACTION_SEND_TEXT,<br> };<br> <br> struct ast_control_read_action_payload {<br>diff --git a/main/channel.c b/main/channel.c<br>index 141a8a5..140d8e9 100644<br>--- a/main/channel.c<br>+++ b/main/channel.c<br>@@ -3795,6 +3795,11 @@<br>                                  ast_party_connected_line_free(&connected);<br>                                        ast_channel_lock(chan);<br>                                       break;<br>+                               case AST_FRAME_READ_ACTION_SEND_TEXT:<br>+                                        ast_channel_unlock(chan);<br>+                                    ast_sendtext(chan, (const char *) read_action_payload->payload);<br>+                                  ast_channel_lock(chan);<br>+                                      break;<br>                                }<br>                             ast_frfree(f);<br>                                f = &ast_null_frame;<br>diff --git a/main/manager.c b/main/manager.c<br>index 34cb5b9..909e4ba 100644<br>--- a/main/manager.c<br>+++ b/main/manager.c<br>@@ -4736,10 +4736,13 @@<br> <br> static int action_sendtext(struct mansession *s, const struct message *m)<br> {<br>-        struct ast_channel *c = NULL;<br>+        struct ast_channel *c;<br>        const char *name = astman_get_header(m, "Channel");<br>         const char *textmsg = astman_get_header(m, "Message");<br>-     int res = 0;<br>+ struct ast_control_read_action_payload *frame_payload;<br>+       int payload_size;<br>+    int frame_size;<br>+      int res;<br> <br>   if (ast_strlen_zero(name)) {<br>          astman_send_error(s, m, "No channel specified");<br>@@ -4751,13 +4754,29 @@<br>           return 0;<br>     }<br> <br>- if (!(c = ast_channel_get_by_name(name))) {<br>+  c = ast_channel_get_by_name(name);<br>+   if (!c) {<br>             astman_send_error(s, m, "No such channel");<br>                 return 0;<br>     }<br> <br>- res = ast_sendtext(c, textmsg);<br>-      c = ast_channel_unref(c);<br>+    payload_size = strlen(textmsg) + 1;<br>+  frame_size = payload_size + sizeof(*frame_payload);<br>+<br>+       frame_payload = ast_malloc(frame_size);<br>+      if (!frame_payload) {<br>+                ast_channel_unref(c);<br>+                astman_send_error(s, m, "Failure");<br>+                return 0;<br>+    }<br>+<br>+ frame_payload->action = AST_FRAME_READ_ACTION_SEND_TEXT;<br>+  frame_payload->payload_size = payload_size;<br>+       memcpy(frame_payload->payload, textmsg, payload_size);<br>+    res = ast_queue_control_data(c, AST_CONTROL_READ_ACTION, frame_payload, frame_size);<br>+<br>+      ast_free(frame_payload);<br>+     ast_channel_unref(c);<br> <br>      if (res >= 0) {<br>            astman_send_ack(s, m, "Success");<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/9310">change 9310</a>. To unsubscribe, 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/9310"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 15 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I9dce343d8fa634ba5a416a1326d8a6340f98c379 </div>
<div style="display:none"> Gerrit-Change-Number: 9310 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Richard Mudgett <rmudgett@digium.com> </div>