app_transfer.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. #include "asterisk.h"
  29. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  30. #include "asterisk/pbx.h"
  31. #include "asterisk/module.h"
  32. #include "asterisk/app.h"
  33. #include "asterisk/channel.h"
  34. static const char *app = "Transfer";
  35. static const char *synopsis = "Transfer caller to remote extension";
  36. static const char *descrip =
  37. " Transfer([Tech/]dest): Requests the remote caller be transferred\n"
  38. "to a given destination. If TECH (SIP, IAX2, LOCAL etc) is used, only\n"
  39. "an incoming call with the same channel technology will be transfered.\n"
  40. "Note that for SIP, if you transfer before call is setup, a 302 redirect\n"
  41. "SIP message will be returned to the caller.\n"
  42. "\nThe result of the application will be reported in the TRANSFERSTATUS\n"
  43. "channel variable:\n"
  44. " SUCCESS Transfer succeeded\n"
  45. " FAILURE Transfer failed\n"
  46. " UNSUPPORTED Transfer unsupported by channel driver\n";
  47. static int transfer_exec(struct ast_channel *chan, void *data)
  48. {
  49. int res;
  50. int len;
  51. char *slash;
  52. char *tech = NULL;
  53. char *dest = NULL;
  54. char *status;
  55. char *parse;
  56. AST_DECLARE_APP_ARGS(args,
  57. AST_APP_ARG(dest);
  58. );
  59. if (ast_strlen_zero((char *)data)) {
  60. ast_log(LOG_WARNING, "Transfer requires an argument ([Tech/]destination)\n");
  61. pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "FAILURE");
  62. return 0;
  63. } else
  64. parse = ast_strdupa(data);
  65. AST_STANDARD_APP_ARGS(args, parse);
  66. dest = args.dest;
  67. if ((slash = strchr(dest, '/')) && (len = (slash - dest))) {
  68. tech = dest;
  69. dest = slash + 1;
  70. /* Allow execution only if the Tech/destination agrees with the type of the channel */
  71. if (strncasecmp(chan->tech->type, tech, len)) {
  72. pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "FAILURE");
  73. return 0;
  74. }
  75. }
  76. /* Check if the channel supports transfer before we try it */
  77. if (!chan->tech->transfer) {
  78. pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "UNSUPPORTED");
  79. return 0;
  80. }
  81. res = ast_transfer(chan, dest);
  82. if (res < 0) {
  83. status = "FAILURE";
  84. res = 0;
  85. } else {
  86. status = "SUCCESS";
  87. res = 0;
  88. }
  89. pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", status);
  90. return res;
  91. }
  92. static int unload_module(void)
  93. {
  94. return ast_unregister_application(app);
  95. }
  96. static int load_module(void)
  97. {
  98. return ast_register_application(app, transfer_exec, synopsis, descrip);
  99. }
  100. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Transfers a caller to another extension");