[Asterisk-code-review] app sendtext: Allow content types other than text/plain (asterisk[15])

Joshua Colp asteriskteam at digium.com
Tue Jun 5 04:29:48 CDT 2018


Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/9080 )

Change subject: app_sendtext:  Allow content types other than text/plain
......................................................................

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
---
M apps/app_sendtext.c
M main/channel.c
2 files changed, 13 insertions(+), 9 deletions(-)

Approvals:
  Benjamin Keith Ford: Looks good to me, but someone else must approve
  Matthew Fredrickson: Looks good to me, approved
  Joshua Colp: Approved for Submit



diff --git a/apps/app_sendtext.c b/apps/app_sendtext.c
index 1cefb6c..45ae073 100644
--- a/apps/app_sendtext.c
+++ b/apps/app_sendtext.c
@@ -66,9 +66,13 @@
 				</variable>
 				<variable name="SENDTEXT_CONTENT_TYPE">
 					<para>If set and this channel supports enhanced messaging, this value will be
-					used as the message <literal>Content-Type</literal>.  It <emphasis>MUST</emphasis>
-					be a <literal>text/*</literal> content type.  If not specified, the
+					used as the message <literal>Content-Type</literal>.  If not specified, the
 					default of <literal>text/plain</literal> will be used.</para>
+					<para><emphasis>Warning:</emphasis> Messages of types other than
+					<literal>text/*</literal> 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 <literal>SENDTEXTSTATUS</literal> variable being set to
+					<literal>UNSUPPORTED</literal>.</para>
 				</variable>
 				<variable name="SENDTEXT_BODY">
 					<para>If set this value will be used as the message body and any text supplied
@@ -191,11 +195,6 @@
 			},
 		};
 
-		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) {
@@ -212,6 +211,11 @@
 		}
 
 	} 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 4475d24..92ec444 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -4693,7 +4693,7 @@
 
 	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;
@@ -4721,7 +4721,7 @@
 			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);

-- 
To view, visit https://gerrit.asterisk.org/9080
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: merged
Gerrit-Change-Id: I94a90cfee98b4bc8e22aa5c0b6afb7b862f979d9
Gerrit-Change-Number: 9080
Gerrit-PatchSet: 2
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Matthew Fredrickson <creslin at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180605/f1424c9e/attachment.html>


More information about the asterisk-code-review mailing list