app_senddtmf.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 App to send DTMF digits
  21. *
  22. * \author Mark Spencer <markster@digium.com>
  23. *
  24. * \ingroup applications
  25. */
  26. #include "asterisk.h"
  27. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  28. #include "asterisk/pbx.h"
  29. #include "asterisk/module.h"
  30. #include "asterisk/app.h"
  31. #include "asterisk/manager.h"
  32. #include "asterisk/channel.h"
  33. static char *app = "SendDTMF";
  34. static char *synopsis = "Sends arbitrary DTMF digits";
  35. static char *descrip =
  36. " SendDTMF(digits[,[timeout_ms][,duration_ms]]): Sends DTMF digits on a channel. \n"
  37. " Accepted digits: 0-9, *#abcd, (default .25s pause between digits)\n"
  38. " The application will either pass the assigned digits or terminate if it\n"
  39. " encounters an error.\n"
  40. " Optional Params: \n"
  41. " timeout_ms: pause between digits.\n"
  42. " duration_ms: duration of each digit.\n";
  43. static int senddtmf_exec(struct ast_channel *chan, void *vdata)
  44. {
  45. int res = 0;
  46. char *data;
  47. int timeout = 0, duration = 0;
  48. AST_DECLARE_APP_ARGS(args,
  49. AST_APP_ARG(digits);
  50. AST_APP_ARG(timeout);
  51. AST_APP_ARG(duration);
  52. );
  53. if (ast_strlen_zero(vdata)) {
  54. ast_log(LOG_WARNING, "SendDTMF requires an argument (digits or *#aAbBcCdD)\n");
  55. return 0;
  56. }
  57. data = ast_strdupa(vdata);
  58. AST_STANDARD_APP_ARGS(args, data);
  59. if (!ast_strlen_zero(args.timeout))
  60. timeout = atoi(args.timeout);
  61. if (!ast_strlen_zero(args.duration))
  62. duration = atoi(args.duration);
  63. res = ast_dtmf_stream(chan, NULL, args.digits, timeout <= 0 ? 250 : timeout, duration);
  64. return res;
  65. }
  66. static char mandescr_playdtmf[] =
  67. "Description: Plays a dtmf digit on the specified channel.\n"
  68. "Variables: (all are required)\n"
  69. " Channel: Channel name to send digit to\n"
  70. " Digit: The dtmf digit to play\n";
  71. static int manager_play_dtmf(struct mansession *s, const struct message *m)
  72. {
  73. const char *channel = astman_get_header(m, "Channel");
  74. const char *digit = astman_get_header(m, "Digit");
  75. struct ast_channel *chan = ast_get_channel_by_name_locked(channel);
  76. if (!chan) {
  77. astman_send_error(s, m, "Channel not specified");
  78. return 0;
  79. }
  80. if (ast_strlen_zero(digit)) {
  81. astman_send_error(s, m, "No digit specified");
  82. ast_channel_unlock(chan);
  83. return 0;
  84. }
  85. ast_senddigit(chan, *digit, 0);
  86. ast_channel_unlock(chan);
  87. astman_send_ack(s, m, "DTMF successfully queued");
  88. return 0;
  89. }
  90. static int unload_module(void)
  91. {
  92. int res;
  93. res = ast_unregister_application(app);
  94. res |= ast_manager_unregister("PlayDTMF");
  95. return res;
  96. }
  97. static int load_module(void)
  98. {
  99. int res;
  100. res = ast_manager_register2( "PlayDTMF", EVENT_FLAG_CALL, manager_play_dtmf, "Play DTMF signal on a specific channel.", mandescr_playdtmf );
  101. res |= ast_register_application(app, senddtmf_exec, synopsis, descrip);
  102. return res;
  103. }
  104. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send DTMF digits Application");