app_channelredirect.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. /*** MODULEINFO
  25. <support_level>core</support_level>
  26. ***/
  27. #include "asterisk.h"
  28. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  29. #include "asterisk/file.h"
  30. #include "asterisk/channel.h"
  31. #include "asterisk/pbx.h"
  32. #include "asterisk/module.h"
  33. #include "asterisk/lock.h"
  34. #include "asterisk/app.h"
  35. #include "asterisk/features.h"
  36. /*** DOCUMENTATION
  37. <application name="ChannelRedirect" language="en_US">
  38. <synopsis>
  39. Redirects given channel to a dialplan target
  40. </synopsis>
  41. <syntax>
  42. <parameter name="channel" required="true" />
  43. <parameter name="context" required="false" />
  44. <parameter name="extension" required="false" />
  45. <parameter name="priority" required="true" />
  46. </syntax>
  47. <description>
  48. <para>Sends the specified channel to the specified extension priority</para>
  49. <para>This application sets the following channel variables upon completion</para>
  50. <variablelist>
  51. <variable name="CHANNELREDIRECT_STATUS">
  52. <value name="NOCHANNEL" />
  53. <value name="SUCCESS" />
  54. <para>Are set to the result of the redirection</para>
  55. </variable>
  56. </variablelist>
  57. </description>
  58. </application>
  59. ***/
  60. static const char app[] = "ChannelRedirect";
  61. static int asyncgoto_exec(struct ast_channel *chan, const char *data)
  62. {
  63. int res = -1;
  64. char *info;
  65. struct ast_channel *chan2 = NULL;
  66. AST_DECLARE_APP_ARGS(args,
  67. AST_APP_ARG(channel);
  68. AST_APP_ARG(label);
  69. );
  70. if (ast_strlen_zero(data)) {
  71. ast_log(LOG_WARNING, "%s requires an argument (channel,[[context,]exten,]priority)\n", app);
  72. return -1;
  73. }
  74. info = ast_strdupa(data);
  75. AST_STANDARD_APP_ARGS(args, info);
  76. if (ast_strlen_zero(args.channel) || ast_strlen_zero(args.label)) {
  77. ast_log(LOG_WARNING, "%s requires an argument (channel,[[context,]exten,]priority)\n", app);
  78. return -1;
  79. }
  80. if (!(chan2 = ast_channel_get_by_name(args.channel))) {
  81. ast_log(LOG_WARNING, "No such channel: %s\n", args.channel);
  82. pbx_builtin_setvar_helper(chan, "CHANNELREDIRECT_STATUS", "NOCHANNEL");
  83. return 0;
  84. }
  85. res = ast_async_parseable_goto(chan2, args.label);
  86. chan2 = ast_channel_unref(chan2);
  87. pbx_builtin_setvar_helper(chan, "CHANNELREDIRECT_STATUS", "SUCCESS");
  88. return res;
  89. }
  90. static int unload_module(void)
  91. {
  92. return ast_unregister_application(app);
  93. }
  94. static int load_module(void)
  95. {
  96. return ast_register_application_xml(app, asyncgoto_exec) ?
  97. AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
  98. }
  99. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Redirects a given channel to a dialplan target");