[Asterisk-code-review] message.c: Support 'To' header override with AMI's MessageSend. (asterisk[18])

Friendly Automation asteriskteam at digium.com
Wed Sep 22 10:16:17 CDT 2021


Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/16498 )

Change subject: message.c: Support 'To' header override with AMI's MessageSend.
......................................................................

message.c: Support 'To' header override with AMI's MessageSend.

The MessageSend AMI action has been updated to allow the Destination
and the To addresses to be provided separately. This brings the
MessageSend manager command in line with the capabilities of the
MessageSend dialplan application.

ASTERISK-29663 #close

Change-Id: I8513168d3e189a9fed88aaab6f5547ccb50d332c
---
A doc/CHANGES-staging/manager_message_send.txt
M main/message.c
2 files changed, 39 insertions(+), 6 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Friendly Automation: Approved for Submit



diff --git a/doc/CHANGES-staging/manager_message_send.txt b/doc/CHANGES-staging/manager_message_send.txt
new file mode 100644
index 0000000..ab5b58a
--- /dev/null
+++ b/doc/CHANGES-staging/manager_message_send.txt
@@ -0,0 +1,6 @@
+Subject: MessageSend
+
+The MessageSend AMI action has been updated to allow the Destination
+and the To addresses to be provided separately. This brings the
+MessageSend manager command in line with the capabilities of the
+MessageSend dialplan application.
diff --git a/main/message.c b/main/message.c
index 75450e9..8ca3987 100644
--- a/main/message.c
+++ b/main/message.c
@@ -190,8 +190,22 @@
 		</synopsis>
 		<syntax>
 			<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
-			<parameter name="To" required="true">
-				<para>The URI the message is to be sent to.</para>
+			<parameter name="Destination" required="false">
+				<para>A To URI for the message. If Destination is provided, the To
+				parameter can also be supplied and may alter the message based on
+				the specified message technology.</para>
+				<para>For backwards compatibility, if Destination is not provided,
+				the To parameter must be provided and will be used as the message
+				destination.</para>
+				<xi:include xpointer="xpointer(/docs/info[@name='MessageDestinationInfo'])" />
+			</parameter>
+			<parameter name="To" required="false">
+				<para>A To URI for the message if needed for the
+				message technology being used to send this message. This can be a
+				SIP(S) URI, such as <literal>Alice <sip:alice at atlanta.com></literal>,
+				or a string in the format <literal>alice at atlanta.com</literal>.</para>
+				<para>This parameter is required if the Destination parameter is not
+				provided.</para>
 				<xi:include xpointer="xpointer(/docs/info[@name='MessageToInfo'])" />
 			</parameter>
 			<parameter name="From">
@@ -1305,10 +1319,12 @@
 
 static int action_messagesend(struct mansession *s, const struct message *m)
 {
-	const char *to = ast_strdupa(astman_get_header(m, "To"));
+	const char *destination = astman_get_header(m, "Destination");
+	const char *to = astman_get_header(m, "To");
 	const char *from = astman_get_header(m, "From");
 	const char *body = astman_get_header(m, "Body");
 	const char *base64body = astman_get_header(m, "Base64Body");
+	const char *to_override = NULL;
 	char base64decoded[1301] = { 0, };
 	char *tech_name = NULL;
 	struct ast_variable *vars = NULL;
@@ -1317,9 +1333,16 @@
 	struct ast_msg *msg;
 	int res = -1;
 
-	if (ast_strlen_zero(to)) {
-		astman_send_error(s, m, "No 'To' address specified.");
-		return 0;
+	if (!ast_strlen_zero(destination)) {
+		if (!ast_strlen_zero(to)) {
+			to_override = to;
+		}
+		to = destination;
+	} else {
+		if (ast_strlen_zero(to)) {
+			astman_send_error(s, m, "No 'To' address specified.");
+			return 0;
+		}
 	}
 
 	if (!ast_strlen_zero(base64body)) {
@@ -1351,6 +1374,10 @@
 
 	ast_msg_set_body(msg, "%s", body);
 
+	if (to_override) {
+		ast_string_field_set(msg, to, to_override);
+	}
+
 	res = msg_tech->msg_send(msg, S_OR(to, ""), S_OR(from, ""));
 
 	ast_rwlock_unlock(&msg_techs_lock);

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/16498
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 18
Gerrit-Change-Id: I8513168d3e189a9fed88aaab6f5547ccb50d332c
Gerrit-Change-Number: 16498
Gerrit-PatchSet: 2
Gerrit-Owner: Sean Bright <sean at seanbright.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210922/e264c7f2/attachment.html>


More information about the asterisk-code-review mailing list