diff --git a/apps/app_blind_transfer.c b/apps/app_blind_transfer.c new file mode 100644 index 0000000000..1c3fbb27cb --- /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 + * + * 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 + * + * \ingroup applications + */ + +/*** MODULEINFO + extended + ***/ + +#include "asterisk.h" + +#include "asterisk/pbx.h" +#include "asterisk/module.h" +#include "asterisk/app.h" +#include "asterisk/channel.h" +#include "asterisk/bridge.h" + +/*** DOCUMENTATION + + + Blind transfer channel(s) to the extension and context provided + + + + Specify extension. + + + Optionally specify a context. + By default, Asterisk will use the caller channel context. + + + + Redirect all channels currently bridged to the caller channel to the + specified destination. + The result of the application will be reported in the BLINDTRANSFERSTATUS + channel variable: + + + + Transfer succeeded. + + + Transfer failed. + + + Transfer invalid. + + + Transfer not permitted. + + + + + + ***/ + +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 0000000000..dc86df0031 --- /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 6901b709f4..be07fda30f 100644 --- a/menuselect/example_menuselect-tree +++ b/menuselect/example_menuselect-tree @@ -10,6 +10,8 @@ + + diff --git a/menuselect/test/menuselect-tree b/menuselect/test/menuselect-tree index 40c08b69f1..ac69e90f14 100644 --- a/menuselect/test/menuselect-tree +++ b/menuselect/test/menuselect-tree @@ -11,6 +11,8 @@ + +