app_zapateller.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Asterisk -- A telephony toolkit for Linux.
  3. *
  4. * Playback the special information tone to get rid of telemarketers
  5. *
  6. * Copyright (C) 1999, Mark Spencer
  7. *
  8. * Mark Spencer <markster@linux-support.net>
  9. *
  10. * This program is free software, distributed under the terms of
  11. * the GNU General Public License
  12. */
  13. #include <asterisk/lock.h>
  14. #include <asterisk/file.h>
  15. #include <asterisk/logger.h>
  16. #include <asterisk/channel.h>
  17. #include <asterisk/pbx.h>
  18. #include <asterisk/module.h>
  19. #include <asterisk/translate.h>
  20. #include <string.h>
  21. #include <stdlib.h>
  22. static char *tdesc = "Block Telemarketers with Special Information Tone";
  23. static char *app = "Zapateller";
  24. static char *synopsis = "Block telemarketers with SIT";
  25. static char *descrip =
  26. " Zapateller(options): Generates special information tone to block\n"
  27. "telemarketers from calling you. Returns 0 normally or -1 on hangup.\n"
  28. "Options is a pipe-delimited list of options. The following options\n"
  29. "are available: 'answer' causes the line to be answered before playing\n"
  30. "the tone, 'nocallerid' causes Zapateller to only play the tone if there\n"
  31. "is no callerid information available. Options should be separated by |\n"
  32. "characters\n";
  33. STANDARD_LOCAL_USER;
  34. LOCAL_USER_DECL;
  35. static int zapateller_exec(struct ast_channel *chan, void *data)
  36. {
  37. int res = 0;
  38. struct localuser *u;
  39. int answer = 0, nocallerid = 0;
  40. char *c;
  41. char *stringp=NULL;
  42. LOCAL_USER_ADD(u);
  43. stringp=data;
  44. c = strsep(&stringp, "|");
  45. while(c && strlen(c)) {
  46. if (!strcasecmp(c, "answer"))
  47. answer = 1;
  48. else if (!strcasecmp(c, "nocallerid"))
  49. nocallerid = 1;
  50. c = strsep(&stringp, "|");
  51. }
  52. ast_stopstream(chan);
  53. if (chan->_state != AST_STATE_UP) {
  54. if (answer)
  55. res = ast_answer(chan);
  56. if (!res) {
  57. res = ast_safe_sleep(chan, 500);
  58. }
  59. }
  60. if (chan->callerid && nocallerid) {
  61. LOCAL_USER_REMOVE(u);
  62. return res;
  63. }
  64. if (!res)
  65. res = ast_tonepair(chan, 950, 0, 330, 0);
  66. if (!res)
  67. res = ast_tonepair(chan, 1400, 0, 330, 0);
  68. if (!res)
  69. res = ast_tonepair(chan, 1800, 0, 330, 0);
  70. if (!res)
  71. res = ast_tonepair(chan, 0, 0, 1000, 0);
  72. LOCAL_USER_REMOVE(u);
  73. return res;
  74. }
  75. int unload_module(void)
  76. {
  77. STANDARD_HANGUP_LOCALUSERS;
  78. return ast_unregister_application(app);
  79. }
  80. int load_module(void)
  81. {
  82. return ast_register_application(app, zapateller_exec, synopsis, descrip);
  83. }
  84. char *description(void)
  85. {
  86. return tdesc;
  87. }
  88. int usecount(void)
  89. {
  90. int res;
  91. STANDARD_USECOUNT(res);
  92. return res;
  93. }
  94. char *key()
  95. {
  96. return ASTERISK_GPL_KEY;
  97. }