app_senddtmf.c 2.5 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. * \ingroup applications
  23. */
  24. #include <stdlib.h>
  25. #include <stdio.h>
  26. #include <string.h>
  27. #include "asterisk.h"
  28. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  29. #include "asterisk/lock.h"
  30. #include "asterisk/file.h"
  31. #include "asterisk/logger.h"
  32. #include "asterisk/channel.h"
  33. #include "asterisk/pbx.h"
  34. #include "asterisk/module.h"
  35. #include "asterisk/translate.h"
  36. #include "asterisk/options.h"
  37. #include "asterisk/utils.h"
  38. #include "asterisk/app.h"
  39. static char *tdesc = "Send DTMF digits Application";
  40. static char *app = "SendDTMF";
  41. static char *synopsis = "Sends arbitrary DTMF digits";
  42. static char *descrip =
  43. " SendDTMF(digits[|timeout_ms]): Sends DTMF digits on a channel. \n"
  44. " Accepted digits: 0-9, *#abcd\n"
  45. " The application will either pass the assigned digits or terminate if it\n"
  46. " encounters an error.\n";
  47. STANDARD_LOCAL_USER;
  48. LOCAL_USER_DECL;
  49. static int senddtmf_exec(struct ast_channel *chan, void *data)
  50. {
  51. int res = 0;
  52. struct localuser *u;
  53. char *digits = NULL, *to = NULL;
  54. int timeout = 250;
  55. if (ast_strlen_zero(data)) {
  56. ast_log(LOG_WARNING, "SendDTMF requires an argument (digits or *#aAbBcCdD)\n");
  57. return 0;
  58. }
  59. LOCAL_USER_ADD(u);
  60. digits = ast_strdupa(data);
  61. if (!digits) {
  62. ast_log(LOG_ERROR, "Out of Memory!\n");
  63. LOCAL_USER_REMOVE(u);
  64. return -1;
  65. }
  66. if ((to = strchr(digits,'|'))) {
  67. *to = '\0';
  68. to++;
  69. timeout = atoi(to);
  70. }
  71. if(timeout <= 0)
  72. timeout = 250;
  73. res = ast_dtmf_stream(chan,NULL,digits,timeout);
  74. LOCAL_USER_REMOVE(u);
  75. return res;
  76. }
  77. int unload_module(void)
  78. {
  79. int res;
  80. res = ast_unregister_application(app);
  81. STANDARD_HANGUP_LOCALUSERS;
  82. return res;
  83. }
  84. int load_module(void)
  85. {
  86. return ast_register_application(app, senddtmf_exec, synopsis, descrip);
  87. }
  88. char *description(void)
  89. {
  90. return tdesc;
  91. }
  92. int usecount(void)
  93. {
  94. int res;
  95. STANDARD_USECOUNT(res);
  96. return res;
  97. }
  98. char *key()
  99. {
  100. return ASTERISK_GPL_KEY;
  101. }