app_zapateller.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 Playback the special information tone to get rid of telemarketers
  21. *
  22. * \author Mark Spencer <markster@digium.com>
  23. *
  24. * \ingroup applications
  25. */
  26. /*** MODULEINFO
  27. <support_level>extended</support_level>
  28. ***/
  29. #include "asterisk.h"
  30. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  31. #include "asterisk/lock.h"
  32. #include "asterisk/file.h"
  33. #include "asterisk/channel.h"
  34. #include "asterisk/pbx.h"
  35. #include "asterisk/module.h"
  36. #include "asterisk/translate.h"
  37. #include "asterisk/app.h"
  38. /*** DOCUMENTATION
  39. <application name="Zapateller" language="en_US">
  40. <synopsis>
  41. Block telemarketers with SIT.
  42. </synopsis>
  43. <syntax>
  44. <parameter name="options" required="true">
  45. <para>Comma delimited list of options.</para>
  46. <optionlist>
  47. <option name="answer">
  48. <para>Causes the line to be answered before playing the tone.</para>
  49. </option>
  50. <option name="nocallerid">
  51. <para>Causes Zapateller to only play the tone if there is no
  52. callerid information available.</para>
  53. </option>
  54. </optionlist>
  55. </parameter>
  56. </syntax>
  57. <description>
  58. <para>Generates special information tone to block telemarketers from calling you.</para>
  59. <para>This application will set the following channel variable upon completion:</para>
  60. <variablelist>
  61. <variable name="ZAPATELLERSTATUS">
  62. <para>This will contain the last action accomplished by the
  63. Zapateller application. Possible values include:</para>
  64. <value name="NOTHING" />
  65. <value name="ANSWERED" />
  66. <value name="ZAPPED" />
  67. </variable>
  68. </variablelist>
  69. </description>
  70. </application>
  71. ***/
  72. static char *app = "Zapateller";
  73. static int zapateller_exec(struct ast_channel *chan, const char *data)
  74. {
  75. int res = 0;
  76. int i, answer = 0, nocallerid = 0;
  77. char *parse = ast_strdupa((char *)data);
  78. AST_DECLARE_APP_ARGS(args,
  79. AST_APP_ARG(options)[2];
  80. );
  81. AST_STANDARD_APP_ARGS(args, parse);
  82. for (i = 0; i < args.argc; i++) {
  83. if (!strcasecmp(args.options[i], "answer"))
  84. answer = 1;
  85. else if (!strcasecmp(args.options[i], "nocallerid"))
  86. nocallerid = 1;
  87. }
  88. pbx_builtin_setvar_helper(chan, "ZAPATELLERSTATUS", "NOTHING");
  89. ast_stopstream(chan);
  90. if (ast_channel_state(chan) != AST_STATE_UP) {
  91. if (answer) {
  92. res = ast_answer(chan);
  93. pbx_builtin_setvar_helper(chan, "ZAPATELLERSTATUS", "ANSWERED");
  94. }
  95. if (!res)
  96. res = ast_safe_sleep(chan, 500);
  97. }
  98. if (nocallerid /* Zap caller if no caller id. */
  99. && ast_channel_caller(chan)->id.number.valid
  100. && !ast_strlen_zero(ast_channel_caller(chan)->id.number.str)) {
  101. /* We have caller id. */
  102. return res;
  103. }
  104. if (!res)
  105. res = ast_tonepair(chan, 950, 0, 330, 0);
  106. if (!res)
  107. res = ast_tonepair(chan, 1400, 0, 330, 0);
  108. if (!res)
  109. res = ast_tonepair(chan, 1800, 0, 330, 0);
  110. if (!res)
  111. res = ast_tonepair(chan, 0, 0, 1000, 0);
  112. pbx_builtin_setvar_helper(chan, "ZAPATELLERSTATUS", "ZAPPED");
  113. return res;
  114. }
  115. static int unload_module(void)
  116. {
  117. return ast_unregister_application(app);
  118. }
  119. static int load_module(void)
  120. {
  121. return ((ast_register_application_xml(app, zapateller_exec)) ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_SUCCESS);
  122. }
  123. AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Block Telemarketers with Special Information Tone");