From 6c694241c5712dff20210411e9c8f72918ccfb96 Mon Sep 17 00:00:00 2001 From: Sean Bright Date: Tue, 21 Sep 2021 10:58:09 -0400 Subject: [PATCH] message.c: Support To header override with AMI's MessageSend ASTERISK-29663 #close Change-Id: I8513168d3e189a9fed88aaab6f5547ccb50d332c --- main/message.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/main/message.c b/main/message.c index 75450e913d..00e66dbc9f 100644 --- a/main/message.c +++ b/main/message.c @@ -1305,10 +1305,12 @@ exit_cleanup: 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,11 +1319,20 @@ static int action_messagesend(struct mansession *s, const struct message *m) 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; + } } + to = ast_strdupa(to); + if (!ast_strlen_zero(base64body)) { ast_base64decode((unsigned char *) base64decoded, base64body, sizeof(base64decoded) - 1); body = base64decoded; @@ -1351,6 +1362,10 @@ static int action_messagesend(struct mansession *s, const struct message *m) ast_msg_set_body(msg, "%s", body); + if (!ast_strlen_zero(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); -- 2.25.1