From 2a7500021edd5bb9d68c69f3409c14dcca6ffdcf Mon Sep 17 00:00:00 2001
From: "Kevin P. Fleming" <kpfleming@digium.com>
Date: Wed, 26 Jan 2011 22:39:07 +0000
Subject: [PATCH] Add ability to disable T.38 usage for specific
 SendFAX/ReceiveFAX sessions.

Sometimes during troubleshooting it can be useful to disable T.38 usage in order
to narrow down a problem. This patch adds an 'n' option to SendFAX and ReceiveFAX
so that can be done without having to disable T.38 usage entirely for the peer
that Asterisk is communicating with.

(inspired by trying to assist Bryant Zimmerman on asterisk-users)



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@304342 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 res/res_fax.c | 54 ++++++++++++++++++++++++++++++++-------------------
 1 file changed, 34 insertions(+), 20 deletions(-)

diff --git a/res/res_fax.c b/res/res_fax.c
index 5d666085f4..c926d95dbb 100644
--- a/res/res_fax.c
+++ b/res/res_fax.c
@@ -74,6 +74,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 					<option name="f">
 						<para>Allow audio fallback FAX transfer on T.38 capable channels.</para>
 					</option>
+					<option name="n">
+						<para>Disable usage of T.38 on otherwise T.38 capable channels.</para>
+					</option>
 					<option name="s">
 						<para>Send progress Manager events (overrides statusevents setting in res_fax.conf).</para>
 					</option>
@@ -107,6 +110,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 					<option name="f">
 						<para>Allow audio fallback FAX transfer on T.38 capable channels.</para>
 					</option>
+					<option name="n">
+						<para>Disable usage of T.38 on otherwise T.38 capable channels.</para>
+					</option>
 					<option name="s">
 						<para>Send progress Manager events (overrides statusevents setting in res_fax.conf).</para>
 					</option>
@@ -267,6 +273,7 @@ enum {
 	OPT_STATUS      = (1 << 3),
 	OPT_ALLOWAUDIO  = (1 << 5),
 	OPT_REQUEST_T38 = (1 << 6),
+	OPT_DISABLE_T38 = (1 << 7),
 };
 
 AST_APP_OPTIONS(fax_exec_options, BEGIN_OPTIONS
@@ -274,6 +281,7 @@ AST_APP_OPTIONS(fax_exec_options, BEGIN_OPTIONS
 	AST_APP_OPTION('c', OPT_CALLERMODE),
 	AST_APP_OPTION('d', OPT_DEBUG),
 	AST_APP_OPTION('f', OPT_ALLOWAUDIO),
+	AST_APP_OPTION('n', OPT_DISABLE_T38),
 	AST_APP_OPTION('s', OPT_STATUS),
 	AST_APP_OPTION('z', OPT_REQUEST_T38),
 END_OPTIONS);
@@ -1619,7 +1627,8 @@ static int receivefax_exec(struct ast_channel *chan, const char *data)
 	}
 
 	if ((ast_channel_get_t38_state(chan) == T38_STATE_UNAVAILABLE) ||
-	    ast_test_flag(&opts, OPT_ALLOWAUDIO)) {
+	    ast_test_flag(&opts, OPT_ALLOWAUDIO) ||
+	    ast_test_flag(&opts, OPT_DISABLE_T38)) {
 		details->option.allow_audio = AST_FAX_OPTFLAG_TRUE;
 	}
 
@@ -1644,17 +1653,19 @@ static int receivefax_exec(struct ast_channel *chan, const char *data)
 		}
 	}
 
-	if (set_fax_t38_caps(chan, details)) {
-		ast_string_field_set(details, error, "T38_NEG_ERROR");
-		ast_string_field_set(details, resultstr, "error negotiating T.38");
-		set_channel_variables(chan, details);
-		fax_session_release(s, token);
-		ao2_ref(s, -1);
-		ao2_ref(details, -1);
-		return -1;
+	if (!ast_test_flag(&opts, OPT_DISABLE_T38)) {
+		if (set_fax_t38_caps(chan, details)) {
+			ast_string_field_set(details, error, "T38_NEG_ERROR");
+			ast_string_field_set(details, resultstr, "error negotiating T.38");
+			set_channel_variables(chan, details);
+			fax_session_release(s, token);
+			ao2_ref(s, -1);
+			ao2_ref(details, -1);
+			return -1;
+		}
 	}
 
-	if (details->caps & AST_FAX_TECH_T38) {
+	if (!ast_test_flag(&opts, OPT_DISABLE_T38) && (details->caps & AST_FAX_TECH_T38)) {
 		if (receivefax_t38_init(chan, details)) {
 			ast_string_field_set(details, error, "T38_NEG_ERROR");
 			ast_string_field_set(details, resultstr, "error negotiating T.38");
@@ -2094,7 +2105,8 @@ static int sendfax_exec(struct ast_channel *chan, const char *data)
 	}
 
 	if ((ast_channel_get_t38_state(chan) == T38_STATE_UNAVAILABLE) ||
-	    ast_test_flag(&opts, OPT_ALLOWAUDIO)) {
+	    ast_test_flag(&opts, OPT_ALLOWAUDIO) ||
+	    ast_test_flag(&opts, OPT_DISABLE_T38)) {
 		details->option.allow_audio = AST_FAX_OPTFLAG_TRUE;
 	}
 
@@ -2123,17 +2135,19 @@ static int sendfax_exec(struct ast_channel *chan, const char *data)
 		}
 	}
 
-	if (set_fax_t38_caps(chan, details)) {
-		ast_string_field_set(details, error, "T38_NEG_ERROR");
-		ast_string_field_set(details, resultstr, "error negotiating T.38");
-		set_channel_variables(chan, details);
-		fax_session_release(s, token);
-		ao2_ref(s, -1);
-		ao2_ref(details, -1);
-		return -1;
+	if (!ast_test_flag(&opts, OPT_DISABLE_T38)) {
+		if (set_fax_t38_caps(chan, details)) {
+			ast_string_field_set(details, error, "T38_NEG_ERROR");
+			ast_string_field_set(details, resultstr, "error negotiating T.38");
+			set_channel_variables(chan, details);
+			fax_session_release(s, token);
+			ao2_ref(s, -1);
+			ao2_ref(details, -1);
+			return -1;
+		}
 	}
 
-	if (details->caps & AST_FAX_TECH_T38) {
+	if (!ast_test_flag(&opts, OPT_DISABLE_T38) && (details->caps & AST_FAX_TECH_T38)) {
 		if (sendfax_t38_init(chan, details)) {
 			ast_string_field_set(details, error, "T38_NEG_ERROR");
 			ast_string_field_set(details, resultstr, "error negotiating T.38");
-- 
GitLab