app_blind_transfer.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2019, Alexei Gradinari
  5. *
  6. * Alexei Gradinari <alex2grad@gmail.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*! \file
  19. *
  20. * \brief Blind transfer by caller channel
  21. *
  22. * \author Alexei Gradinari <alex2grad@gmail.com>
  23. *
  24. * \ingroup applications
  25. */
  26. /*** MODULEINFO
  27. <support_level>extended</support_level>
  28. ***/
  29. #include "asterisk.h"
  30. #include "asterisk/pbx.h"
  31. #include "asterisk/module.h"
  32. #include "asterisk/app.h"
  33. #include "asterisk/channel.h"
  34. #include "asterisk/bridge.h"
  35. /*** DOCUMENTATION
  36. <application name="BlindTransfer" language="en_US">
  37. <synopsis>
  38. Blind transfer channel(s) to the extension and context provided
  39. </synopsis>
  40. <syntax>
  41. <parameter name="exten" required="true">
  42. <para>Specify extension.</para>
  43. </parameter>
  44. <parameter name="context">
  45. <para>Optionally specify a context.
  46. By default, Asterisk will use the caller channel context.</para>
  47. </parameter>
  48. </syntax>
  49. <description>
  50. <para>Redirect all channels currently bridged to the caller channel to the
  51. specified destination.</para>
  52. <para>The result of the application will be reported in the <variable>BLINDTRANSFERSTATUS</variable>
  53. channel variable:</para>
  54. <variablelist>
  55. <variable name="BLINDTRANSFERSTATUS">
  56. <value name="SUCCESS">
  57. Transfer succeeded.
  58. </value>
  59. <value name="FAILURE">
  60. Transfer failed.
  61. </value>
  62. <value name="INVALID">
  63. Transfer invalid.
  64. </value>
  65. <value name="NOTPERMITTED">
  66. Transfer not permitted.
  67. </value>
  68. </variable>
  69. </variablelist>
  70. </description>
  71. </application>
  72. ***/
  73. static const char * const app = "BlindTransfer";
  74. static int blind_transfer_exec(struct ast_channel *chan, const char *data)
  75. {
  76. char *exten = NULL;
  77. char *context = NULL;
  78. char *parse;
  79. AST_DECLARE_APP_ARGS(args,
  80. AST_APP_ARG(exten);
  81. AST_APP_ARG(context);
  82. );
  83. if (ast_strlen_zero((char *)data)) {
  84. ast_log(LOG_WARNING, "%s requires an argument (exten)\n", app);
  85. pbx_builtin_setvar_helper(chan, "BLINDTRANSFERSTATUS", "FAILURE");
  86. return 0;
  87. }
  88. parse = ast_strdupa(data);
  89. AST_STANDARD_APP_ARGS(args, parse);
  90. exten = args.exten;
  91. if (ast_strlen_zero(args.context)) {
  92. context = (char *)ast_channel_context(chan);
  93. } else {
  94. context = args.context;
  95. }
  96. switch (ast_bridge_transfer_blind(1, chan, exten, context, NULL, NULL)) {
  97. case AST_BRIDGE_TRANSFER_NOT_PERMITTED:
  98. pbx_builtin_setvar_helper(chan, "BLINDTRANSFERSTATUS", "NOTPERMITTED");
  99. break;
  100. case AST_BRIDGE_TRANSFER_INVALID:
  101. pbx_builtin_setvar_helper(chan, "BLINDTRANSFERSTATUS", "INVALID");
  102. break;
  103. case AST_BRIDGE_TRANSFER_FAIL:
  104. pbx_builtin_setvar_helper(chan, "BLINDTRANSFERSTATUS", "FAILURE");
  105. break;
  106. case AST_BRIDGE_TRANSFER_SUCCESS:
  107. pbx_builtin_setvar_helper(chan, "BLINDTRANSFERSTATUS", "SUCCESS");
  108. break;
  109. default:
  110. pbx_builtin_setvar_helper(chan, "BLINDTRANSFERSTATUS", "FAILURE");
  111. }
  112. return 0;
  113. }
  114. static int unload_module(void)
  115. {
  116. return ast_unregister_application(app);
  117. }
  118. static int load_module(void)
  119. {
  120. return ast_register_application_xml(app, blind_transfer_exec);
  121. }
  122. AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Blind transfer channel to the given destination");