<p>Sean Bright has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/16496">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">message.c: Support To header override with AMI's MessageSend<br><br>ASTERISK-29663 #close<br><br>Change-Id: I8513168d3e189a9fed88aaab6f5547ccb50d332c<br>---<br>M main/message.c<br>1 file changed, 33 insertions(+), 6 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/96/16496/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/message.c b/main/message.c</span><br><span>index 75450e9..8ca3987 100644</span><br><span>--- a/main/message.c</span><br><span>+++ b/main/message.c</span><br><span>@@ -190,8 +190,22 @@</span><br><span> </synopsis></span><br><span> <syntax></span><br><span> <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" /></span><br><span style="color: hsl(0, 100%, 40%);">- <parameter name="To" required="true"></span><br><span style="color: hsl(0, 100%, 40%);">- <para>The URI the message is to be sent to.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ <parameter name="Destination" required="false"></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>A To URI for the message. If Destination is provided, the To</span><br><span style="color: hsl(120, 100%, 40%);">+ parameter can also be supplied and may alter the message based on</span><br><span style="color: hsl(120, 100%, 40%);">+ the specified message technology.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>For backwards compatibility, if Destination is not provided,</span><br><span style="color: hsl(120, 100%, 40%);">+ the To parameter must be provided and will be used as the message</span><br><span style="color: hsl(120, 100%, 40%);">+ destination.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ <xi:include xpointer="xpointer(/docs/info[@name='MessageDestinationInfo'])" /></span><br><span style="color: hsl(120, 100%, 40%);">+ </parameter></span><br><span style="color: hsl(120, 100%, 40%);">+ <parameter name="To" required="false"></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>A To URI for the message if needed for the</span><br><span style="color: hsl(120, 100%, 40%);">+ message technology being used to send this message. This can be a</span><br><span style="color: hsl(120, 100%, 40%);">+ SIP(S) URI, such as <literal>Alice <sip:alice@atlanta.com></literal>,</span><br><span style="color: hsl(120, 100%, 40%);">+ or a string in the format <literal>alice@atlanta.com</literal>.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>This parameter is required if the Destination parameter is not</span><br><span style="color: hsl(120, 100%, 40%);">+ provided.</para></span><br><span> <xi:include xpointer="xpointer(/docs/info[@name='MessageToInfo'])" /></span><br><span> </parameter></span><br><span> <parameter name="From"></span><br><span>@@ -1305,10 +1319,12 @@</span><br><span> </span><br><span> static int action_messagesend(struct mansession *s, const struct message *m)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- const char *to = ast_strdupa(astman_get_header(m, "To"));</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *destination = astman_get_header(m, "Destination");</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *to = astman_get_header(m, "To");</span><br><span> const char *from = astman_get_header(m, "From");</span><br><span> const char *body = astman_get_header(m, "Body");</span><br><span> const char *base64body = astman_get_header(m, "Base64Body");</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *to_override = NULL;</span><br><span> char base64decoded[1301] = { 0, };</span><br><span> char *tech_name = NULL;</span><br><span> struct ast_variable *vars = NULL;</span><br><span>@@ -1317,9 +1333,16 @@</span><br><span> struct ast_msg *msg;</span><br><span> int res = -1;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (ast_strlen_zero(to)) {</span><br><span style="color: hsl(0, 100%, 40%);">- astman_send_error(s, m, "No 'To' address specified.");</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_strlen_zero(destination)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_strlen_zero(to)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ to_override = to;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ to = destination;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_strlen_zero(to)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ astman_send_error(s, m, "No 'To' address specified.");</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span> </span><br><span> if (!ast_strlen_zero(base64body)) {</span><br><span>@@ -1351,6 +1374,10 @@</span><br><span> </span><br><span> ast_msg_set_body(msg, "%s", body);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ if (to_override) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_string_field_set(msg, to, to_override);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> res = msg_tech->msg_send(msg, S_OR(to, ""), S_OR(from, ""));</span><br><span> </span><br><span> ast_rwlock_unlock(&msg_techs_lock);</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/16496">change 16496</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/+/16496"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: I8513168d3e189a9fed88aaab6f5547ccb50d332c </div>
<div style="display:none"> Gerrit-Change-Number: 16496 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean@seanbright.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>