app_transfer.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999 - 2005, Digium, Inc.
  5. *
  6. * Mark Spencer <markster@digium.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 Transfer a caller
  21. *
  22. * \author Mark Spencer <markster@digium.com>
  23. *
  24. * Requires transfer support from channel driver
  25. *
  26. * \ingroup applications
  27. */
  28. /*** MODULEINFO
  29. <support_level>core</support_level>
  30. ***/
  31. #include "asterisk.h"
  32. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  33. #include "asterisk/pbx.h"
  34. #include "asterisk/module.h"
  35. #include "asterisk/app.h"
  36. #include "asterisk/channel.h"
  37. /*** DOCUMENTATION
  38. <application name="Transfer" language="en_US">
  39. <synopsis>
  40. Transfer caller to remote extension.
  41. </synopsis>
  42. <syntax>
  43. <parameter name="dest" required="true" argsep="">
  44. <argument name="Tech/" />
  45. <argument name="destination" required="true" />
  46. </parameter>
  47. </syntax>
  48. <description>
  49. <para>Requests the remote caller be transferred
  50. to a given destination. If TECH (SIP, IAX2, etc) is used, only
  51. an incoming call with the same channel technology will be transferred.
  52. Note that for SIP, if you transfer before call is setup, a 302 redirect
  53. SIP message will be returned to the caller.</para>
  54. <para>The result of the application will be reported in the <variable>TRANSFERSTATUS</variable>
  55. channel variable:</para>
  56. <variablelist>
  57. <variable name="TRANSFERSTATUS">
  58. <value name="SUCCESS">
  59. Transfer succeeded.
  60. </value>
  61. <value name="FAILURE">
  62. Transfer failed.
  63. </value>
  64. <value name="UNSUPPORTED">
  65. Transfer unsupported by channel driver.
  66. </value>
  67. </variable>
  68. </variablelist>
  69. </description>
  70. </application>
  71. ***/
  72. static const char * const app = "Transfer";
  73. static int transfer_exec(struct ast_channel *chan, const char *data)
  74. {
  75. int res;
  76. int len;
  77. char *slash;
  78. char *tech = NULL;
  79. char *dest = NULL;
  80. char *status;
  81. char *parse;
  82. AST_DECLARE_APP_ARGS(args,
  83. AST_APP_ARG(dest);
  84. );
  85. if (ast_strlen_zero((char *)data)) {
  86. ast_log(LOG_WARNING, "Transfer requires an argument ([Tech/]destination)\n");
  87. pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "FAILURE");
  88. return 0;
  89. } else
  90. parse = ast_strdupa(data);
  91. AST_STANDARD_APP_ARGS(args, parse);
  92. dest = args.dest;
  93. if ((slash = strchr(dest, '/')) && (len = (slash - dest))) {
  94. tech = dest;
  95. dest = slash + 1;
  96. /* Allow execution only if the Tech/destination agrees with the type of the channel */
  97. if (strncasecmp(ast_channel_tech(chan)->type, tech, len)) {
  98. pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "FAILURE");
  99. return 0;
  100. }
  101. }
  102. /* Check if the channel supports transfer before we try it */
  103. if (!ast_channel_tech(chan)->transfer) {
  104. pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "UNSUPPORTED");
  105. return 0;
  106. }
  107. res = ast_transfer(chan, dest);
  108. if (res < 0) {
  109. status = "FAILURE";
  110. res = 0;
  111. } else {
  112. status = "SUCCESS";
  113. res = 0;
  114. }
  115. pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", status);
  116. return res;
  117. }
  118. static int unload_module(void)
  119. {
  120. return ast_unregister_application(app);
  121. }
  122. static int load_module(void)
  123. {
  124. return ast_register_application_xml(app, transfer_exec);
  125. }
  126. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Transfers a caller to another extension");