From ebf3632e085e81fa3fdbda1e7e4685c4868fbb39 Mon Sep 17 00:00:00 2001
From: Gregory Nietsky <gregory@distrotech.co.za>
Date: Mon, 3 Oct 2011 09:49:38 +0000
Subject: [PATCH] Merged revisions 338950 via svnmerge from
 https://origsvn.digium.com/svn/asterisk/branches/10

........
  r338950 | irroot | 2011-10-03 11:37:59 +0200 (Mon, 03 Oct 2011) | 14 lines

  Fixup a race condition in res_fax.c where FAXOPT(gateway)=no will
  turn off the gateway but the framehook is not destroyed.

  this problem happens when a gateway is attempted in the dialplan and
  the device is not available i may want to do fax to mail in the server
  it will not be allowed.

  instead of checking only AST_FAX_TECH_GATEWAY also check gateway_id

  Reverts 338904

  Fix some white space.
........


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

diff --git a/res/res_fax.c b/res/res_fax.c
index 49812167c9..5f2b693f53 100644
--- a/res/res_fax.c
+++ b/res/res_fax.c
@@ -1650,7 +1650,7 @@ static int receivefax_exec(struct ast_channel *chan, const char *data)
 	ast_string_field_set(details, error, "INIT_ERROR");
 	set_channel_variables(chan, details);
 
-	if (details->caps & AST_FAX_TECH_GATEWAY) {
+	if ((details->caps & AST_FAX_TECH_GATEWAY) && (details->gateway_id > 0)) {
 		ast_string_field_set(details, resultstr, "can't receive a fax on a channel with a T.38 gateway");
 		set_channel_variables(chan, details);
 		ast_log(LOG_ERROR, "executing ReceiveFAX on a channel with a T.38 Gateway is not supported\n");
@@ -2120,7 +2120,7 @@ static int sendfax_exec(struct ast_channel *chan, const char *data)
 	ast_string_field_set(details, error, "INIT_ERROR");
 	set_channel_variables(chan, details);
 
-	if (details->caps & AST_FAX_TECH_GATEWAY) {
+	if ((details->caps & AST_FAX_TECH_GATEWAY) && (details->gateway_id > 0)) {
 		ast_string_field_set(details, resultstr, "can't send a fax on a channel with a T.38 gateway");
 		set_channel_variables(chan, details);
 		ast_log(LOG_ERROR, "executing SendFAX on a channel with a T.38 Gateway is not supported\n");
@@ -2843,8 +2843,6 @@ static struct ast_frame *fax_gateway_framehook(struct ast_channel *chan, struct
 			}
 		}
 
-		details->caps &= ~AST_FAX_TECH_GATEWAY;
-
 		ao2_ref(details, -1);
 		return NULL;
 	}
@@ -3673,7 +3671,7 @@ static int load_module(void)
 	}
 
 	ast_cli_register_multiple(fax_cli, ARRAY_LEN(fax_cli));
-	res = ast_custom_function_register(&acf_faxopt);	
+	res = ast_custom_function_register(&acf_faxopt);
 	fax_logger_level = ast_logger_register_level("FAX");
 
 	return res;
-- 
GitLab