<p>George Joseph has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/9024">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">app_sendtext:  Enhance SendText to support Enhanced Messaging<br><br>SendText now accepts new channel variables that can be used<br>to override the To and From display names and set the Content-Type<br>of a message.  Since you can now set Content-Type, other text/*<br>content types are now valid.<br><br>Change-Id: I648b4574478119f95de09d9f08e9595831b02830<br>---<br>M CHANGES<br>M apps/app_sendtext.c<br>2 files changed, 170 insertions(+), 29 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/24/9024/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/CHANGES b/CHANGES<br>index 040224b..95d3303 100644<br>--- a/CHANGES<br>+++ b/CHANGES<br>@@ -25,6 +25,22 @@<br> --- Functionality changes from Asterisk 13.20.0 to Asterisk 13.21.0 ----------<br> ------------------------------------------------------------------------------<br> <br>+Core<br>+------------------<br>+ * Core bridging and, more specifically, bridge_softmix have been enhanced to<br>+   relay received frames of type TEXT or TEXT_DATA to all participants in a<br>+   softmix bridge.  res_pjsip_messaging and chan_pjsip have been enhanced to<br>+   take advantage of this so when res_pjsip_messaging receives an in-dialog<br>+   MESSAGE message from a user in a conference call, it's relayed to all<br>+   other participants in the call.<br>+<br>+app_sendtext<br>+------------------<br>+    Support Enhanced Messaging.  SendText now accepts new channel variables<br>+    that can be used to override the To and From display names and set the<br>+    Content-Type of a message.  Since you can now set Content-Type, other<br>+    text/* content types are now valid.<br>+<br> Build System<br> ------------------<br>  * RADIUS backends for CEL and CDR can now also be built using the radcli<br>diff --git a/apps/app_sendtext.c b/apps/app_sendtext.c<br>index 3c1b4f5..d1cd120 100644<br>--- a/apps/app_sendtext.c<br>+++ b/apps/app_sendtext.c<br>@@ -40,19 +40,60 @@<br> #include "asterisk/pbx.h"<br> #include "asterisk/module.h"<br> #include "asterisk/app.h"<br>+#include "asterisk/message.h"<br> <br> /*** DOCUMENTATION<br>     <application name="SendText" language="en_US"><br>              <synopsis><br>-                     Send a Text Message.<br>+                 Send a Text Message on a channel.<br>             </synopsis><br>             <syntax><br>-                       <parameter name="text" required="true" /><br>+                  <parameter name="text" required="false" /><br>          </syntax><br>               <description><br>-                  <para>Sends <replaceable>text</replaceable> to current channel (callee).</para><br>-                      <para>Result of transmission will be stored in the <variable>SENDTEXTSTATUS</variable></para><br>+                        <para>Sends <replaceable>text</replaceable> to the current channel.</para><br>+                   <note><para><literal>current channel</literal> could be the caller or callee depending<br>+                       on the context in which this application is called.</para></note><br>+                        <para><br>+                 </para><br>+                        <para>The following variables can be set:</para><br>                  <variablelist><br>+                         <variable name="SENDTEXT_FROM_DISPLAYNAME"><br>+                                  <para>If set and this channel supports enhanced messaging, this value will be<br>+                                  used as the <literal>From</literal> display name.</para><br>+                           </variable><br>+                            <variable name="SENDTEXT_TO_DISPLAYNAME"><br>+                                    <para>If set and this channel supports enhanced messaging, this value will be<br>+                                  used as the <literal>To</literal> display name.</para><br>+                             </variable><br>+                            <variable name="SENDTEXT_CONTENT_TYPE"><br>+                                      <para>If set and this channel supports enhanced messaging, this value will be<br>+                                  used as the message <literal>Content-Type</literal>.  It <emphasis>MUST</emphasis><br>+                                   be a <literal>text/&#42;</literal> content type.  If not specified, the<br>+                                      default of <literal>text/plain</literal> will be used.</para><br>+                              </variable><br>+                            <variable name="SENDTEXT_BODY"><br>+                                      <para>If set this value will be used as the message body and any text supplied<br>+                                 as a function parameter will be ignored.<br>+                                     </para><br>+                                </variable><br>+                    </variablelist><br>+                        <para><br>+                 </para><br>+                        <para>Result of transmission will be stored in the following variables:</para><br>+                   <variablelist><br>+                         <variable name="SENDTEXTTYPE"><br>+                                       <value name="NONE"><br>+                                          No message sent.<br>+                                     </value><br>+                                       <value name="BASIC"><br>+                                         Message body sent without attributes because the channel driver<br>+                                              doesn't support enhanced messaging.<br>+                                      </value><br>+                                       <value name="ENHANCED"><br>+                                              The message was sent using enhanced messaging.<br>+                                       </value><br>+                               </variable><br>                             <variable name="SENDTEXTSTATUS"><br>                                      <value name="SUCCESS"><br>                                                Transmission succeeded.<br>@@ -65,7 +106,34 @@<br>                                  </value><br>                                </variable><br>                     </variablelist><br>-                        <note><para>At this moment, text is supposed to be 7 bit ASCII in most channels.</para></note><br>+                       <para><br>+                 </para><br>+                        <note><para>The text encoding and transmission method is completely at the<br>+                       discretion of the channel driver.  chan_pjsip will use in-dialog SIP MESSAGE<br>+                 messages always.  chan_sip will use T.140 via RTP if a text media type was<br>+                   negotiated and in-dialog SIP MESSAGE messages otherwise.</para></note><br>+                   <para><br>+                 </para><br>+                        <para>Examples:<br>+                        </para><br>+                        <example title="Send a simple message"><br>+                       same => n,SendText(Your Text Here)<br>+                       </example><br>+                     <para>If the channel driver supports enhanced messaging (currently only chan_pjsip),<br>+                   you can set additional variables:</para><br>+                       <example title="Alter the From display name"><br>+                         same => n,Set(SENDTEXT_FROM_DISPLAYNAME=Really From Bob)<br>+                  same => n,SendText(Your Text Here)<br>+                       </example><br>+                     <example title="Send a JSON String"><br>+                  same => n,Set(SENDTEXT_CONTENT_TYPE=text/json)<br>+                    same => n,SendText({"foo":a, "bar":23})<br>+                      </example><br>+                     <example title="Send a JSON String (alternate)"><br>+                      same => n,Set(SENDTEXT_CONTENT_TYPE=text/json)<br>+                    same => n,Set(SENDTEXT_BODY={"foo":a, "bar":23})<br>+                      same => n,SendText()<br>+                     </example><br>              </description><br>          <see-also><br>                      <ref type="application">SendImage</ref><br>@@ -78,36 +146,93 @@<br> <br> static int sendtext_exec(struct ast_channel *chan, const char *data)<br> {<br>-    char *status = "UNSUPPORTED";<br>+      char *status;<br>+        char *msg_type;<br>       struct ast_str *str;<br>-<br>-      /* NOT ast_strlen_zero, because some protocols (e.g. SIP) MUST be able to<br>-     * send a zero-length message. */<br>-    if (!data) {<br>-         ast_log(LOG_WARNING, "SendText requires an argument (text)\n");<br>-            return -1;<br>-   }<br>-<br>- if (!(str = ast_str_alloca(strlen(data) + 1))) {<br>-             return -1;<br>-   }<br>-<br>- ast_str_get_encoded_str(&str, -1, data);<br>+ const char *from;<br>+    const char *to;<br>+      const char *content_type;<br>+    const char *body;<br>+    int rc = 0;<br> <br>        ast_channel_lock(chan);<br>-      if (!ast_channel_tech(chan)->send_text) {<br>-         ast_channel_unlock(chan);<br>-            /* Does not support transport */<br>-             pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);<br>-         return 0;<br>+    from = pbx_builtin_getvar_helper(chan, "SENDTEXT_FROM_DISPLAYNAME");<br>+       to = pbx_builtin_getvar_helper(chan, "SENDTEXT_TO_DISPLAYNAME");<br>+   content_type = pbx_builtin_getvar_helper(chan, "SENDTEXT_CONTENT_TYPE");<br>+   body = S_OR(pbx_builtin_getvar_helper(chan, "SENDTEXT_BODY"), data);<br>+       body = S_OR(body, "");<br>+<br>+  if (!(str = ast_str_alloca(strlen(body) + 1))) {<br>+             rc = -1;<br>+             goto cleanup;<br>         }<br>-    status = "FAILURE";<br>-        if (!ast_sendtext(chan, ast_str_buffer(str))) {<br>-              status = "SUCCESS";<br>+        ast_str_get_encoded_str(&str, -1, body);<br>+ body = ast_str_buffer(str);<br>+<br>+       msg_type = "NONE";<br>+ status = "UNSUPPORTED";<br>+    if (ast_channel_tech(chan)->send_text_data) {<br>+             struct ast_msg_data *msg;<br>+            struct ast_msg_data_attribute attrs[] =<br>+              {<br>+                    {<br>+                            .type = AST_MSG_DATA_ATTR_FROM,<br>+                              .value = (char *)S_OR(from, ""),<br>+                   },<br>+                   {<br>+                            .type = AST_MSG_DATA_ATTR_TO,<br>+                                .value = (char *)S_OR(to, ""),<br>+                     },<br>+                   {<br>+                            .type = AST_MSG_DATA_ATTR_CONTENT_TYPE,<br>+                              .value = (char *)S_OR(content_type, ""),<br>+                   },<br>+                   {<br>+                            .type = AST_MSG_DATA_ATTR_BODY,<br>+                              .value = (char *)S_OR(body, ""),<br>+                   },<br>+           };<br>+<br>+                if (!ast_strlen_zero(content_type) && !ast_begins_with(content_type, "text/")) {<br>+                   ast_log(LOG_ERROR, "SENDTEXT_CONTENT_TYPE must begin with 'text/'\n");<br>+                     rc = -1;<br>+                     goto cleanup;<br>+                }<br>+            msg_type = "ENHANCED";<br>+             msg = ast_msg_data_alloc(AST_MSG_DATA_SOURCE_TYPE_IN_DIALOG, attrs, ARRAY_LEN(attrs));<br>+               if (msg) {<br>+                   if (ast_sendtext_data(chan, msg) == 0) {<br>+                             status = "SUCCESS";<br>+                        } else {<br>+                             status = "FAILURE";<br>+                        }<br>+<br>+                 ast_free(msg);<br>+               } else {<br>+                     rc = -1;<br>+                     goto cleanup;<br>+                }<br>+<br>+ } else if (ast_channel_tech(chan)->send_text) {<br>+           msg_type = "BASIC";<br>+                if (ast_sendtext(chan, body) == 0) {<br>+                 status = "SUCCESS";<br>+                } else {<br>+                     status = "FAILURE";<br>+                }<br>     }<br>-    ast_channel_unlock(chan);<br>+<br>+ pbx_builtin_setvar_helper(chan, "SENDTEXTTYPE", msg_type);<br>  pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);<br>- return 0;<br>+<br>+cleanup:<br>+      pbx_builtin_setvar_helper(chan, "SENDTEXT_FROM_DISPLAYNAME", NULL);<br>+        pbx_builtin_setvar_helper(chan, "SENDTEXT_TO_DISPLAYNAME", NULL);<br>+  pbx_builtin_setvar_helper(chan, "SENDTEXT_CONTENT_TYPE", NULL);<br>+    pbx_builtin_setvar_helper(chan, "SENDTEXT_BODY", NULL);<br>+    ast_channel_unlock(chan);<br>+<br>+ return rc;<br> }<br> <br> static int unload_module(void)<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/9024">change 9024</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/9024"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13.21 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I648b4574478119f95de09d9f08e9595831b02830 </div>
<div style="display:none"> Gerrit-Change-Number: 9024 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>