app_lookupblacklist.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Asterisk -- A telephony toolkit for Linux.
  3. *
  4. * App to lookup the callerid number, and see if it is blacklisted
  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/options.h>
  17. #include <asterisk/channel.h>
  18. #include <asterisk/pbx.h>
  19. #include <asterisk/module.h>
  20. #include <asterisk/translate.h>
  21. #include <asterisk/image.h>
  22. #include <asterisk/callerid.h>
  23. #include <asterisk/astdb.h>
  24. #include <string.h>
  25. #include <stdlib.h>
  26. static char *tdesc = "Look up Caller*ID name/number from blacklist database";
  27. static char *app = "LookupBlacklist";
  28. static char *synopsis = "Look up Caller*ID name/number from blacklist database";
  29. static char *descrip =
  30. " LookupBlacklist: Looks up the Caller*ID number on the active\n"
  31. "channel in the Asterisk database (family 'blacklist'). If the\n"
  32. "number is found, and if there exists a priority n + 101,\n"
  33. "where 'n' is the priority of the current instance, then the\n"
  34. "channel will be setup to continue at that priority level.\n"
  35. "Otherwise, it returns 0. Does nothing if no Caller*ID was received on the\n"
  36. "channel.\n"
  37. "Example: database put blacklist <name/number> 1\n";
  38. STANDARD_LOCAL_USER;
  39. LOCAL_USER_DECL;
  40. static int
  41. lookupblacklist_exec (struct ast_channel *chan, void *data)
  42. {
  43. char old_cid[144] = "", *num, *name;
  44. char blacklist[1];
  45. char shrunknum[64] = "";
  46. struct localuser *u;
  47. int bl = 0;
  48. LOCAL_USER_ADD (u);
  49. if (chan->callerid)
  50. {
  51. strncpy (old_cid, chan->callerid, sizeof (old_cid) - 1);
  52. ast_callerid_parse (old_cid, &name, &num);
  53. if (num)
  54. strncpy (shrunknum, num, sizeof (shrunknum) - 1);
  55. else
  56. num = shrunknum;
  57. ast_shrink_phone_number (shrunknum);
  58. if (!ast_db_get ("blacklist", shrunknum, blacklist, sizeof (blacklist)))
  59. {
  60. if (option_verbose > 2)
  61. ast_log(LOG_NOTICE, "Blacklisted number %s found\n",shrunknum);
  62. bl = 1;
  63. }
  64. else if (!ast_db_get ("blacklist", name, blacklist, sizeof (blacklist)))
  65. {
  66. if (option_verbose > 2)
  67. ast_log (LOG_NOTICE,"Blacklisted name \"%s\" found\n",name);
  68. bl = 1;
  69. }
  70. }
  71. if (bl && ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->callerid))
  72. chan->priority+=100;
  73. LOCAL_USER_REMOVE (u);
  74. return 0;
  75. }
  76. int unload_module (void)
  77. {
  78. STANDARD_HANGUP_LOCALUSERS;
  79. return ast_unregister_application (app);
  80. }
  81. int load_module (void)
  82. {
  83. return ast_register_application (app, lookupblacklist_exec, synopsis,descrip);
  84. }
  85. char *description (void)
  86. {
  87. return tdesc;
  88. }
  89. int usecount (void)
  90. {
  91. int res;
  92. STANDARD_USECOUNT (res);
  93. return res;
  94. }
  95. char *key ()
  96. {
  97. return ASTERISK_GPL_KEY;
  98. }