[Asterisk-code-review] app_blind_transfer: new application BlindTransfer (...asterisk[16])

George Joseph asteriskteam at digium.com
Wed Jun 12 10:43:17 CDT 2019


George Joseph has submitted this change and it was merged. ( https://gerrit.asterisk.org/c/asterisk/+/11381 )

Change subject: app_blind_transfer: new application BlindTransfer
......................................................................

app_blind_transfer: new application BlindTransfer

BlindTransfer redirects all channels currently bridged to the
caller channel to the specified destination.

This application can be useful with Custom Dynamic Features.
For example to make blind transfer to a predefined number.

features.conf
;;;
[applicationmap]
my_blindxfer => *6,self,GoSub,"my_blindxfer,s,1",default
;;;

extensions.conf
;;;
[globals]
DYNAMIC_FEATURES=my_blindxfer

[my_blindxfer]
exten => s,1,BlindTransfer(1234567890,default)
   same => n,Return()
;;;

This application also can be used to completly redefine Blind transfer
feature using dialplan. For example:

features.conf
;;;
[featuremap]
blindxfer =>

[applicationmap]
custom_blindxfer => ##,self,GoSub,"custom_blindxfer,s,1",default
;;;

extensions.conf
;;;
[globals]
DYNAMIC_FEATURES=custom_blindxfer

[custom_blindxfer]
exten => s,1,
   same => n,Playback(pbx-transfer)
   same => n,Read(dest,dial,10,i,3,3)
   same => n,BlindTransfer(${dest},default)
   same => n,Return()
;;;

Change-Id: I9d55e7f69ccfd4472dec00d62771d6de8803215a
---
A apps/app_blind_transfer.c
A doc/CHANGES-staging/app_blind_transfer.txt
M menuselect/example_menuselect-tree
M menuselect/test/menuselect-tree
4 files changed, 145 insertions(+), 0 deletions(-)

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



diff --git a/apps/app_blind_transfer.c b/apps/app_blind_transfer.c
new file mode 100644
index 0000000..1c3fbb2
--- /dev/null
+++ b/apps/app_blind_transfer.c
@@ -0,0 +1,137 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2019, Alexei Gradinari
+ *
+ * Alexei Gradinari <alex2grad at gmail.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief Blind transfer by caller channel
+ *
+ * \author Alexei Gradinari <alex2grad at gmail.com>
+ *
+ * \ingroup applications
+ */
+
+/*** MODULEINFO
+	<support_level>extended</support_level>
+ ***/
+
+#include "asterisk.h"
+
+#include "asterisk/pbx.h"
+#include "asterisk/module.h"
+#include "asterisk/app.h"
+#include "asterisk/channel.h"
+#include "asterisk/bridge.h"
+
+/*** DOCUMENTATION
+	<application name="BlindTransfer" language="en_US">
+		<synopsis>
+			Blind transfer channel(s) to the extension and context provided
+		</synopsis>
+		<syntax>
+			<parameter name="exten" required="true">
+				<para>Specify extension.</para>
+			</parameter>
+			<parameter name="context">
+				<para>Optionally specify a context.
+				By default, Asterisk will use the caller channel context.</para>
+			</parameter>
+		</syntax>
+		<description>
+			<para>Redirect all channels currently bridged to the caller channel to the
+			specified destination.</para>
+			<para>The result of the application will be reported in the <variable>BLINDTRANSFERSTATUS</variable>
+			channel variable:</para>
+			<variablelist>
+				<variable name="BLINDTRANSFERSTATUS">
+					<value name="SUCCESS">
+						Transfer succeeded.
+					</value>
+					<value name="FAILURE">
+						Transfer failed.
+					</value>
+					<value name="INVALID">
+						Transfer invalid.
+					</value>
+					<value name="NOTPERMITTED">
+						Transfer not permitted.
+					</value>
+				</variable>
+			</variablelist>
+		</description>
+	</application>
+ ***/
+
+static const char * const app = "BlindTransfer";
+
+static int blind_transfer_exec(struct ast_channel *chan, const char *data)
+{
+	char *exten = NULL;
+	char *context = NULL;
+	char *parse;
+	AST_DECLARE_APP_ARGS(args,
+		AST_APP_ARG(exten);
+		AST_APP_ARG(context);
+	);
+
+	if (ast_strlen_zero((char *)data)) {
+		ast_log(LOG_WARNING, "%s requires an argument (exten)\n", app);
+		pbx_builtin_setvar_helper(chan, "BLINDTRANSFERSTATUS", "FAILURE");
+		return 0;
+	}
+
+	parse = ast_strdupa(data);
+	AST_STANDARD_APP_ARGS(args, parse);
+
+	exten = args.exten;
+	if (ast_strlen_zero(args.context)) {
+		context = (char *)ast_channel_context(chan);
+	} else {
+		context = args.context;
+	}
+
+	switch (ast_bridge_transfer_blind(1, chan, exten, context, NULL, NULL)) {
+		case AST_BRIDGE_TRANSFER_NOT_PERMITTED:
+			pbx_builtin_setvar_helper(chan, "BLINDTRANSFERSTATUS", "NOTPERMITTED");
+			break;
+		case AST_BRIDGE_TRANSFER_INVALID:
+			pbx_builtin_setvar_helper(chan, "BLINDTRANSFERSTATUS", "INVALID");
+			break;
+		case AST_BRIDGE_TRANSFER_FAIL:
+			pbx_builtin_setvar_helper(chan, "BLINDTRANSFERSTATUS", "FAILURE");
+			break;
+		case AST_BRIDGE_TRANSFER_SUCCESS:
+			pbx_builtin_setvar_helper(chan, "BLINDTRANSFERSTATUS", "SUCCESS");
+			break;
+		default:
+			pbx_builtin_setvar_helper(chan, "BLINDTRANSFERSTATUS", "FAILURE");
+        }
+
+	return 0;
+}
+
+static int unload_module(void)
+{
+	return ast_unregister_application(app);
+}
+
+static int load_module(void)
+{
+	return ast_register_application_xml(app, blind_transfer_exec);
+}
+
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Blind transfer channel to the given destination");
diff --git a/doc/CHANGES-staging/app_blind_transfer.txt b/doc/CHANGES-staging/app_blind_transfer.txt
new file mode 100644
index 0000000..dc86df0
--- /dev/null
+++ b/doc/CHANGES-staging/app_blind_transfer.txt
@@ -0,0 +1,4 @@
+Subject: BlindTransfer
+
+A new application, this will redirect all channels currently
+bridged to the caller channel to the specified destination.
diff --git a/menuselect/example_menuselect-tree b/menuselect/example_menuselect-tree
index 6901b70..be07fda 100644
--- a/menuselect/example_menuselect-tree
+++ b/menuselect/example_menuselect-tree
@@ -10,6 +10,8 @@
 		</member>
 		<member name="app_authenticate" displayname="Authentication Application" remove_on_change="apps/app_authenticate.o apps/app_authenticate.so">
 		</member>
+		<member name="app_blind_transfer" displayname="Blind transfer by caller channel" remove_on_change="apps/app_blind_transfer.o apps/app_blind_transfer.so">
+		</member>
 		<member name="app_cdr" displayname="Tell Asterisk to not maintain a CDR for the current call" remove_on_change="apps/app_cdr.o apps/app_cdr.so">
 		</member>
 		<member name="app_chanisavail" displayname="Check channel availability" remove_on_change="apps/app_chanisavail.o apps/app_chanisavail.so">
diff --git a/menuselect/test/menuselect-tree b/menuselect/test/menuselect-tree
index 40c08b6..ac69e90 100644
--- a/menuselect/test/menuselect-tree
+++ b/menuselect/test/menuselect-tree
@@ -11,6 +11,8 @@
 </member>
 <member name="app_authenticate" displayname="Authentication Application" remove_on_change="apps/app_authenticate.o apps/app_authenticate.so">
 </member>
+<member name="app_blind_transfer" displayname="Blind transfer by caller channel" remove_on_change="apps/app_blind_transfer.o apps/app_blind_transfer.so">
+</member>
 <member name="app_cdr" displayname="Tell Asterisk to not maintain a CDR for the current call" remove_on_change="apps/app_cdr.o apps/app_cdr.so">
 </member>
 <member name="app_chanisavail" displayname="Check channel availability" remove_on_change="apps/app_chanisavail.o apps/app_chanisavail.so">

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/11381
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: I9d55e7f69ccfd4472dec00d62771d6de8803215a
Gerrit-Change-Number: 11381
Gerrit-PatchSet: 7
Gerrit-Owner: Alexei Gradinari <alex2grad at gmail.com>
Gerrit-Reviewer: Alexei Gradinari <alex2grad at gmail.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190612/c4c3a93d/attachment-0001.html>


More information about the asterisk-code-review mailing list