<p>Kevin Harwell has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/14517">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">manager - Add Content-Type parameter to the SendText action<br><br>This patch allows a user of AMI to now specify the type of message<br>content contained within by setting the 'Content-Type' parameter.<br><br>Note, the AMI version has been bumped for this change.<br><br>ASTERISK-28945 #close<br><br>Change-Id: Ibb5315702532c6b954e1498beddc8855fabdf4bb<br>---<br>A doc/CHANGES-staging/ami_sendtext_content_type.txt<br>M include/asterisk/manager.h<br>M include/asterisk/message.h<br>M main/channel.c<br>M main/manager.c<br>M main/message.c<br>6 files changed, 69 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/17/14517/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/doc/CHANGES-staging/ami_sendtext_content_type.txt b/doc/CHANGES-staging/ami_sendtext_content_type.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..45037ff</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/ami_sendtext_content_type.txt</span><br><span>@@ -0,0 +1,4 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: AMI</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+You can now specify an optional 'Content-Type' as an argument for the Asterisk</span><br><span style="color: hsl(120, 100%, 40%);">+SendText manager action.</span><br><span>diff --git a/include/asterisk/manager.h b/include/asterisk/manager.h</span><br><span>index 9968ec8..85c26c1 100644</span><br><span>--- a/include/asterisk/manager.h</span><br><span>+++ b/include/asterisk/manager.h</span><br><span>@@ -54,7 +54,7 @@</span><br><span> - \ref manager.c Main manager code file</span><br><span> */</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-#define AMI_VERSION "2.10.5"</span><br><span style="color: hsl(120, 100%, 40%);">+#define AMI_VERSION "2.10.6"</span><br><span> #define DEFAULT_MANAGER_PORT 5038 /* Default port for Asterisk management via TCP */</span><br><span> #define DEFAULT_MANAGER_TLS_PORT 5039 /* Default port for Asterisk management via TCP */</span><br><span> </span><br><span>diff --git a/include/asterisk/message.h b/include/asterisk/message.h</span><br><span>index f5b7a75..94b5e91 100644</span><br><span>--- a/include/asterisk/message.h</span><br><span>+++ b/include/asterisk/message.h</span><br><span>@@ -480,6 +480,24 @@</span><br><span> struct ast_msg_data_attribute attributes[], size_t count);</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Allocates an ast_msg_data structure.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 13.35.0</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 16.12.0</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 17.6.0</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param source The source type of the message</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param to Where the message is sent to</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param from Where the message is sent from</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param content_type Content type of the body</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param body The message body</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \return Pointer to msg structure or NULL on allocation failure.</span><br><span style="color: hsl(120, 100%, 40%);">+ * Caller must call ast_free when done.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+struct ast_msg_data *ast_msg_data_alloc2(enum ast_msg_data_source_type source_type,</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *to, const char *from, const char *content_type, const char *body);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span> * \brief Clone an ast_msg_data structure</span><br><span> * \since 13.22.0</span><br><span> * \since 15.5.0</span><br><span>diff --git a/main/channel.c b/main/channel.c</span><br><span>index 9f68a9a..688e370 100644</span><br><span>--- a/main/channel.c</span><br><span>+++ b/main/channel.c</span><br><span>@@ -4115,7 +4115,7 @@</span><br><span> break;</span><br><span> case AST_FRAME_READ_ACTION_SEND_TEXT:</span><br><span> ast_channel_unlock(chan);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_sendtext(chan, (const char *) read_action_payload->payload);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sendtext_data(chan, (struct ast_msg_data *)read_action_payload->payload);</span><br><span> ast_channel_lock(chan);</span><br><span> break;</span><br><span> }</span><br><span>diff --git a/main/manager.c b/main/manager.c</span><br><span>index c79d4f1..72527c8 100644</span><br><span>--- a/main/manager.c</span><br><span>+++ b/main/manager.c</span><br><span>@@ -102,6 +102,7 @@</span><br><span> #include "asterisk/format_cache.h"</span><br><span> #include "asterisk/translate.h"</span><br><span> #include "asterisk/taskprocessor.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/message.h"</span><br><span> </span><br><span> /*** DOCUMENTATION</span><br><span> <manager name="Ping" language="en_US"></span><br><span>@@ -877,6 +878,9 @@</span><br><span> <parameter name="Message" required="true"></span><br><span> <para>Message to send.</para></span><br><span> </parameter></span><br><span style="color: hsl(120, 100%, 40%);">+ <parameter name="Content-Type" required="false" default="text"></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>The type of content in the message</para></span><br><span style="color: hsl(120, 100%, 40%);">+ </parameter></span><br><span> </syntax></span><br><span> <description></span><br><span> <para>Sends A Text Message to a channel while in a call.</para></span><br><span>@@ -4814,7 +4818,9 @@</span><br><span> 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(120, 100%, 40%);">+ const char *content_type = astman_get_header(m, "Content-Type");</span><br><span> struct ast_control_read_action_payload *frame_payload;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_msg_data *msg;</span><br><span> int payload_size;</span><br><span> int frame_size;</span><br><span> int res;</span><br><span>@@ -4835,22 +4841,32 @@</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- payload_size = strlen(textmsg) + 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ msg = ast_msg_data_alloc2(AST_MSG_DATA_SOURCE_TYPE_UNKNOWN,</span><br><span style="color: hsl(120, 100%, 40%);">+ NULL, NULL, content_type, textmsg);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!msg) {</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, "Unable to allocate message");</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%);">+ payload_size = ast_msg_data_get_length(msg);</span><br><span> frame_size = payload_size + sizeof(*frame_payload);</span><br><span> </span><br><span> frame_payload = ast_malloc(frame_size);</span><br><span> if (!frame_payload) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(msg);</span><br><span> ast_channel_unref(c);</span><br><span style="color: hsl(0, 100%, 40%);">- astman_send_error(s, m, "Failure");</span><br><span style="color: hsl(120, 100%, 40%);">+ astman_send_error(s, m, "Unable to allocate message's frame payload");</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span> frame_payload->action = AST_FRAME_READ_ACTION_SEND_TEXT;</span><br><span> frame_payload->payload_size = payload_size;</span><br><span style="color: hsl(0, 100%, 40%);">- memcpy(frame_payload->payload, textmsg, payload_size);</span><br><span style="color: hsl(120, 100%, 40%);">+ memcpy(frame_payload->payload, msg, payload_size);</span><br><span> res = ast_queue_control_data(c, AST_CONTROL_READ_ACTION, frame_payload, frame_size);</span><br><span> </span><br><span> ast_free(frame_payload);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(msg);</span><br><span> ast_channel_unref(c);</span><br><span> </span><br><span> if (res >= 0) {</span><br><span>diff --git a/main/message.c b/main/message.c</span><br><span>index b3d739e..1eea006 100644</span><br><span>--- a/main/message.c</span><br><span>+++ b/main/message.c</span><br><span>@@ -1427,6 +1427,32 @@</span><br><span> return msg;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+struct ast_msg_data *ast_msg_data_alloc2(enum ast_msg_data_source_type source_type,</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *to, const char *from, const char *content_type, const char *body)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_msg_data_attribute attrs[] =</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%);">+ .type = AST_MSG_DATA_ATTR_TO,</span><br><span style="color: hsl(120, 100%, 40%);">+ .value = (char *)S_OR(to, ""),</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%);">+ .type = AST_MSG_DATA_ATTR_FROM,</span><br><span style="color: hsl(120, 100%, 40%);">+ .value = (char *)S_OR(from, ""),</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%);">+ .type = AST_MSG_DATA_ATTR_CONTENT_TYPE,</span><br><span style="color: hsl(120, 100%, 40%);">+ .value = (char *)S_OR(content_type, ""),</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%);">+ .type = AST_MSG_DATA_ATTR_BODY,</span><br><span style="color: hsl(120, 100%, 40%);">+ .value = (char *)S_OR(body, ""),</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%);">+ return ast_msg_data_alloc(source_type, attrs, ARRAY_LEN(attrs));</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> struct ast_msg_data *ast_msg_data_dup(struct ast_msg_data *msg)</span><br><span> {</span><br><span> struct ast_msg_data *dest;</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/14517">change 14517</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/+/14517"/><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: Ibb5315702532c6b954e1498beddc8855fabdf4bb </div>
<div style="display:none"> Gerrit-Change-Number: 14517 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>