app_channelredirect.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2006, Sergey Basmanov
  5. *
  6. * See http://www.asterisk.org for more information about
  7. * the Asterisk project. Please do not directly contact
  8. * any of the maintainers of this project for assistance;
  9. * the project provides a web site, mailing lists and IRC
  10. * channels for your use.
  11. *
  12. * This program is free software, distributed under the terms of
  13. * the GNU General Public License Version 2. See the LICENSE file
  14. * at the top of the source tree.
  15. */
  16. /*! \file
  17. *
  18. * \brief ChannelRedirect application
  19. *
  20. * \author Sergey Basmanov <sergey_basmanov@mail.ru>
  21. *
  22. * \ingroup applications
  23. */
  24. #include "asterisk.h"
  25. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  26. #include "asterisk/file.h"
  27. #include "asterisk/channel.h"
  28. #include "asterisk/pbx.h"
  29. #include "asterisk/module.h"
  30. #include "asterisk/lock.h"
  31. #include "asterisk/app.h"
  32. #include "asterisk/features.h"
  33. static char *app = "ChannelRedirect";
  34. static char *synopsis = "Redirects given channel to a dialplan target.";
  35. static char *descrip =
  36. "ChannelRedirect(channel,[[context,]extension,]priority)\n"
  37. " Sends the specified channel to the specified extension priority\n"
  38. "This application sets the following channel variables upon completion:\n"
  39. " CHANNELREDIRECT_STATUS - Are set to the result of the redirection\n"
  40. " either NOCHANNEL or SUCCESS\n";
  41. static int asyncgoto_exec(struct ast_channel *chan, void *data)
  42. {
  43. int res = -1;
  44. char *info;
  45. struct ast_channel *chan2 = NULL;
  46. AST_DECLARE_APP_ARGS(args,
  47. AST_APP_ARG(channel);
  48. AST_APP_ARG(label);
  49. );
  50. if (ast_strlen_zero(data)) {
  51. ast_log(LOG_WARNING, "%s requires an argument (channel,[[context,]exten,]priority)\n", app);
  52. return -1;
  53. }
  54. info = ast_strdupa(data);
  55. AST_STANDARD_APP_ARGS(args, info);
  56. if (ast_strlen_zero(args.channel) || ast_strlen_zero(args.label)) {
  57. ast_log(LOG_WARNING, "%s requires an argument (channel,[[context,]exten,]priority)\n", app);
  58. return -1;
  59. }
  60. chan2 = ast_get_channel_by_name_locked(args.channel);
  61. if (!chan2) {
  62. ast_log(LOG_WARNING, "No such channel: %s\n", args.channel);
  63. pbx_builtin_setvar_helper(chan, "CHANNELREDIRECT_STATUS", "NOCHANNEL");
  64. return 0;
  65. }
  66. if (chan2->pbx) {
  67. ast_set_flag(chan2, AST_FLAG_BRIDGE_HANGUP_DONT); /* don't let the after-bridge code run the h-exten */
  68. }
  69. res = ast_async_parseable_goto(chan2, args.label);
  70. pbx_builtin_setvar_helper(chan, "CHANNELREDIRECT_STATUS", "SUCCESS");
  71. ast_channel_unlock(chan2);
  72. return res;
  73. }
  74. static int unload_module(void)
  75. {
  76. return ast_unregister_application(app);
  77. }
  78. static int load_module(void)
  79. {
  80. return ast_register_application(app, asyncgoto_exec, synopsis, descrip);
  81. }
  82. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Redirects a given channel to a dialplan target");