From 5f8cabc232b3e2ebcfca18dcd96848c32dd06681 Mon Sep 17 00:00:00 2001
From: Naveen Albert <mail@interlinked.x10host.com>
Date: Thu, 20 May 2021 10:51:32 -0400
Subject: [PATCH] app_confbridge: New option to prevent answer supervision

A new user option, answer_channel, adds the capability to
prevent answering the channel if it hasn't already been
answered yet.

ASTERISK-29440

Change-Id: I26642729d0345f178c7b8045506605c8402de54b
---
 apps/app_confbridge.c                         |  9 +++++----
 apps/confbridge/conf_config_parser.c          | 13 ++++++++++---
 apps/confbridge/include/confbridge.h          |  1 +
 configs/samples/confbridge.conf.sample        |  2 ++
 doc/CHANGES-staging/app_confbridge_answer.txt |  6 ++++++
 5 files changed, 24 insertions(+), 7 deletions(-)
 create mode 100644 doc/CHANGES-staging/app_confbridge_answer.txt

diff --git a/apps/app_confbridge.c b/apps/app_confbridge.c
index 8ad188a5d8..8b88c5257c 100644
--- a/apps/app_confbridge.c
+++ b/apps/app_confbridge.c
@@ -2535,10 +2535,6 @@ static int confbridge_exec(struct ast_channel *chan, const char *data)
 		AST_APP_ARG(menu_profile_name);
 	);
 
-	if (ast_channel_state(chan) != AST_STATE_UP) {
-		ast_answer(chan);
-	}
-
 	if (ast_bridge_features_init(&user.features)) {
 		pbx_builtin_setvar_helper(chan, "CONFBRIDGE_RESULT", "FAILED");
 		res = -1;
@@ -2588,6 +2584,11 @@ static int confbridge_exec(struct ast_channel *chan, const char *data)
 		goto confbridge_cleanup;
 	}
 
+	/* If channel hasn't been answered already, answer it, unless we're explicitly not supposed to */
+	if ((ast_channel_state(chan) != AST_STATE_UP) && (ast_test_flag(&user.u_profile, USER_OPT_ANSWER_CHANNEL))) {
+		ast_answer(chan);
+	}
+
 	quiet = ast_test_flag(&user.u_profile, USER_OPT_QUIET);
 
 	/* ask for a PIN immediately after finding user profile.  This has to be
diff --git a/apps/confbridge/conf_config_parser.c b/apps/confbridge/conf_config_parser.c
index 656acc650f..e5e253bc94 100644
--- a/apps/confbridge/conf_config_parser.c
+++ b/apps/confbridge/conf_config_parser.c
@@ -247,6 +247,9 @@
 					participants in the conference bridge. If disabled then no text
 					messages are sent to the user.</para></description>
 				</configOption>
+				<configOption name="answer_channel" default="yes">
+					<synopsis>Sets if a user's channel should be answered if currently unanswered.</synopsis>
+				</configOption>
 			</configObject>
 			<configObject name="bridge_profile">
 				<synopsis>A named profile to apply to specific bridges.</synopsis>
@@ -1609,9 +1612,12 @@ static char *handle_cli_confbridge_show_user_profile(struct ast_cli_entry *e, in
 	ast_cli(a->fd,"Announce User Count all: %s\n",
 		u_profile.flags & USER_OPT_ANNOUNCEUSERCOUNTALL ?
 		"enabled" : "disabled");
-        ast_cli(a->fd,"Text Messaging:          %s\n",
-                u_profile.flags & USER_OPT_TEXT_MESSAGING ?
-                "enabled" : "disabled");
+	ast_cli(a->fd,"Text Messaging:          %s\n",
+			u_profile.flags & USER_OPT_TEXT_MESSAGING ?
+			"enabled" : "disabled");
+	ast_cli(a->fd,"Answer Channel:          %s\n",
+			u_profile.flags & USER_OPT_ANSWER_CHANNEL ?
+			"true" : "false");
 	ast_cli(a->fd, "\n");
 
 	return CLI_SUCCESS;
@@ -2410,6 +2416,7 @@ int conf_load_config(void)
 	aco_option_register(&cfg_info, "jitterbuffer", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_JITTERBUFFER);
 	aco_option_register(&cfg_info, "timeout", ACO_EXACT, user_types, "0", OPT_UINT_T, 0, FLDSET(struct user_profile, timeout));
 	aco_option_register(&cfg_info, "text_messaging", ACO_EXACT, user_types, "yes", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_TEXT_MESSAGING);
+	aco_option_register(&cfg_info, "answer_channel", ACO_EXACT, user_types, "yes", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_ANSWER_CHANNEL);
 
 	/* This option should only be used with the CONFBRIDGE dialplan function */
 	aco_option_register_custom(&cfg_info, "template", ACO_EXACT, user_types, NULL, user_template_handler, 0);
diff --git a/apps/confbridge/include/confbridge.h b/apps/confbridge/include/confbridge.h
index f413359357..5ae49b7d6a 100644
--- a/apps/confbridge/include/confbridge.h
+++ b/apps/confbridge/include/confbridge.h
@@ -69,6 +69,7 @@ enum user_profile_flags {
 	USER_OPT_SEND_EVENTS = (1 << 17), /*!< Send text message events to users */
 	USER_OPT_ECHO_EVENTS = (1 << 18), /*!< Send events only to the admin(s) */
 	USER_OPT_TEXT_MESSAGING = (1 << 19), /*!< Send text messages to the user */
+	USER_OPT_ANSWER_CHANNEL = (1 << 20), /*!< Sets if the channel should be answered if currently unanswered */
 };
 
 enum bridge_profile_flags {
diff --git a/configs/samples/confbridge.conf.sample b/configs/samples/confbridge.conf.sample
index 7749c93ef7..eecbb65d64 100644
--- a/configs/samples/confbridge.conf.sample
+++ b/configs/samples/confbridge.conf.sample
@@ -165,6 +165,8 @@ type=user
 ;text_messaging=yes ; When set to yes text messages will be sent to this user. Text messages
                     ; may occur as a result of events or can be received from other participants.
                     ; When set to no text messages will not be sent to this user.
+;answer_channel=yes   ; Sets if the channel should be answered if it hasn't been already.
+                          ; On by default.
 
 ; --- ConfBridge Bridge Profile Options ---
 [default_bridge]
diff --git a/doc/CHANGES-staging/app_confbridge_answer.txt b/doc/CHANGES-staging/app_confbridge_answer.txt
new file mode 100644
index 0000000000..b975f48f4e
--- /dev/null
+++ b/doc/CHANGES-staging/app_confbridge_answer.txt
@@ -0,0 +1,6 @@
+Subject: app_confbridge answer supervision control
+
+app_confbridge now provides a user option to prevent
+answer supervision if the channel hasn't been
+answered yet. To use it, set a user profile's
+answer_channel option to no.
-- 
GitLab