app_attended_transfer.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 Attended 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. #include "asterisk/features_config.h"
  36. /*** DOCUMENTATION
  37. <application name="AttendedTransfer" language="en_US">
  38. <synopsis>
  39. Attended transfer to the extension provided and TRANSFER_CONTEXT
  40. </synopsis>
  41. <syntax>
  42. <parameter name="exten" required="true">
  43. <para>Specify extension.</para>
  44. </parameter>
  45. </syntax>
  46. <description>
  47. <para>Queue up attended transfer to the specified extension in the <literal>TRANSFER_CONTEXT</literal>.</para>
  48. <para>Note that the attended transfer only work when two channels have answered and are bridged together.</para>
  49. <para>Make sure to set Attended Transfer DTMF feature <literal>atxfer</literal>
  50. and attended transfer is permitted.</para>
  51. <para>The result of the application will be reported in the <variable>ATTENDEDTRANSFERSTATUS</variable>
  52. channel variable:</para>
  53. <variablelist>
  54. <variable name="ATTENDEDTRANSFERSTATUS">
  55. <value name="SUCCESS">
  56. Transfer successfully queued.
  57. </value>
  58. <value name="FAILURE">
  59. Transfer failed.
  60. </value>
  61. <value name="NOTPERMITTED">
  62. Transfer not permitted.
  63. </value>
  64. </variable>
  65. </variablelist>
  66. </description>
  67. </application>
  68. ***/
  69. static const char * const app = "AttendedTransfer";
  70. static int attended_transfer_exec(struct ast_channel *chan, const char *data)
  71. {
  72. char *exten = NULL;
  73. const char *context = NULL;
  74. char *parse;
  75. AST_DECLARE_APP_ARGS(args,
  76. AST_APP_ARG(exten);
  77. );
  78. char feature_code[AST_FEATURE_MAX_LEN];
  79. const char *digit;
  80. struct ast_frame f = { .frametype = AST_FRAME_DTMF };
  81. if (ast_strlen_zero((char *)data)) {
  82. ast_log(LOG_WARNING, "%s requires an argument (exten)\n", app);
  83. pbx_builtin_setvar_helper(chan, "ATTENDEDTRANSFERSTATUS", "FAILURE");
  84. return 0;
  85. }
  86. context = pbx_builtin_getvar_helper(chan, "TRANSFER_CONTEXT");
  87. if (ast_strlen_zero(context)) {
  88. pbx_builtin_setvar_helper(chan, "ATTENDEDTRANSFERSTATUS", "NOTPERMITTED");
  89. return 0;
  90. }
  91. ast_channel_lock(chan);
  92. if (ast_get_builtin_feature(chan, "atxfer", feature_code, sizeof(feature_code)) ||
  93. ast_strlen_zero(feature_code)) {
  94. pbx_builtin_setvar_helper(chan, "ATTENDEDTRANSFERSTATUS", "NOTPERMITTED");
  95. ast_channel_unlock(chan);
  96. return 0;
  97. }
  98. ast_channel_unlock(chan);
  99. parse = ast_strdupa(data);
  100. AST_STANDARD_APP_ARGS(args, parse);
  101. exten = args.exten;
  102. for (digit = feature_code; *digit; ++digit) {
  103. f.subclass.integer = *digit;
  104. ast_queue_frame(chan, &f);
  105. }
  106. for (digit = exten; *digit; ++digit) {
  107. f.subclass.integer = *digit;
  108. ast_queue_frame(chan, &f);
  109. }
  110. f.subclass.integer = '#';
  111. ast_queue_frame(chan, &f);
  112. pbx_builtin_setvar_helper(chan, "ATTENDEDTRANSFERSTATUS", "SUCCESS");
  113. return 0;
  114. }
  115. static int unload_module(void)
  116. {
  117. return ast_unregister_application(app);
  118. }
  119. static int load_module(void)
  120. {
  121. return ast_register_application_xml(app, attended_transfer_exec);
  122. }
  123. AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Attended transfer to the given extension");