From db2413b4462f17862c42fb4665f201a06a4d1b2c Mon Sep 17 00:00:00 2001 From: George Joseph Date: Mon, 4 Jun 2018 08:50:51 -0600 Subject: [PATCH] app_sendtext: Allow content types other than text/plain There was no real reason to limit the conteny type to text/plain other than that's what it was limited to before. Now any text/* content type will be allowed for channel drivers that don't support enhanced messaging and any type will be allowed for channel drivers that do support enhanced messaging. Change-Id: I94a90cfee98b4bc8e22aa5c0b6afb7b862f979d9 --- apps/app_sendtext.c | 18 +++++++++++------- main/channel.c | 4 ++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/apps/app_sendtext.c b/apps/app_sendtext.c index d1cd1208af..6d0c7d31da 100644 --- a/apps/app_sendtext.c +++ b/apps/app_sendtext.c @@ -68,9 +68,13 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") If set and this channel supports enhanced messaging, this value will be - used as the message Content-Type. It MUST - be a text/* content type. If not specified, the + used as the message Content-Type. If not specified, the default of text/plain will be used. + Warning: Messages of types other than + text/* cannot be sent via channel drivers that do not + support Enhanced Messaging. An attempt to do so will be ignored and will result + in the SENDTEXTSTATUS variable being set to + UNSUPPORTED. If set this value will be used as the message body and any text supplied @@ -193,11 +197,6 @@ static int sendtext_exec(struct ast_channel *chan, const char *data) }, }; - if (!ast_strlen_zero(content_type) && !ast_begins_with(content_type, "text/")) { - ast_log(LOG_ERROR, "SENDTEXT_CONTENT_TYPE must begin with 'text/'\n"); - rc = -1; - goto cleanup; - } msg_type = "ENHANCED"; msg = ast_msg_data_alloc(AST_MSG_DATA_SOURCE_TYPE_IN_DIALOG, attrs, ARRAY_LEN(attrs)); if (msg) { @@ -214,6 +213,11 @@ static int sendtext_exec(struct ast_channel *chan, const char *data) } } else if (ast_channel_tech(chan)->send_text) { + if (!ast_strlen_zero(content_type) && !ast_begins_with(content_type, "text/")) { + rc = -1; + goto cleanup; + } + msg_type = "BASIC"; if (ast_sendtext(chan, body) == 0) { status = "SUCCESS"; diff --git a/main/channel.c b/main/channel.c index 8de7ad28a0..a5cc4e7e9f 100644 --- a/main/channel.c +++ b/main/channel.c @@ -4890,7 +4890,7 @@ int ast_sendtext_data(struct ast_channel *chan, struct ast_msg_data *msg) CHECK_BLOCKING(chan); if (ast_channel_tech(chan)->write_text - && (ast_strlen_zero(content_type) || strcasecmp(content_type, "text/plain") == 0) + && (ast_strlen_zero(content_type) || ast_begins_with(content_type, "text/")) && (ast_format_cap_has_type(ast_channel_nativeformats(chan), AST_MEDIA_TYPE_TEXT))) { struct ast_frame f; size_t body_len = strlen(body) + 1; @@ -4918,7 +4918,7 @@ int ast_sendtext_data(struct ast_channel *chan, struct ast_msg_data *msg) ast_channel_name(chan), body); res = ast_channel_tech(chan)->send_text_data(chan, msg); } else if (ast_channel_tech(chan)->send_text - && (ast_strlen_zero(content_type) || strcasecmp(content_type, "text/plain") == 0)) { + && (ast_strlen_zero(content_type) || ast_begins_with(content_type, "text/"))) { /* Send the body of an enhanced message to a channel driver that supports only a char str */ ast_debug(1, "Sending TEXT to %s: %s\n", ast_channel_name(chan), body); res = ast_channel_tech(chan)->send_text(chan, body); -- 2.47.2