2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
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.
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.
21 * \brief App to lookup the callerid number, and see if it is blacklisted
23 * \author Mark Spencer <markster@digium.com>
25 * \ingroup applications
31 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
37 #include "asterisk/lock.h"
38 #include "asterisk/file.h"
39 #include "asterisk/logger.h"
40 #include "asterisk/options.h"
41 #include "asterisk/channel.h"
42 #include "asterisk/pbx.h"
43 #include "asterisk/module.h"
44 #include "asterisk/translate.h"
45 #include "asterisk/image.h"
46 #include "asterisk/callerid.h"
47 #include "asterisk/astdb.h"
48 #include "asterisk/options.h"
50 static char *app = "LookupBlacklist";
52 static char *synopsis = "Look up Caller*ID name/number from blacklist database";
54 static char *descrip =
55 " LookupBlacklist(options): Looks up the Caller*ID number on the active\n"
56 "channel in the Asterisk database (family 'blacklist'). \n"
57 "The option string may contain the following character:\n"
58 " 'j' -- jump to n+101 priority if the number/name is found in the blacklist\n"
59 "This application sets the following channel variable upon completion:\n"
60 " LOOKUPBLSTATUS The status of the Blacklist lookup as a text string, one of\n"
62 "Example: exten => 1234,1,LookupBlacklist()\n";
65 static int blacklist_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
70 if (chan->cid.cid_num) {
71 if (!ast_db_get("blacklist", chan->cid.cid_num, blacklist, sizeof (blacklist)))
74 if (chan->cid.cid_name) {
75 if (!ast_db_get("blacklist", chan->cid.cid_name, blacklist, sizeof (blacklist)))
79 snprintf(buf, len, "%d", bl);
83 static struct ast_custom_function blacklist_function = {
85 .synopsis = "Check if the callerid is on the blacklist",
86 .desc = "Uses astdb to check if the Caller*ID is in family 'blacklist'. Returns 1 or 0.\n",
87 .syntax = "BLACKLIST()",
88 .read = blacklist_read,
92 lookupblacklist_exec (struct ast_channel *chan, void *data)
95 struct ast_module_user *u;
97 int priority_jump = 0;
98 static int dep_warning = 0;
100 u = ast_module_user_add(chan);
104 ast_log(LOG_WARNING, "LookupBlacklist is deprecated. Please use ${BLACKLIST()} instead.\n");
107 if (!ast_strlen_zero(data)) {
108 if (strchr(data, 'j'))
112 if (chan->cid.cid_num) {
113 if (!ast_db_get("blacklist", chan->cid.cid_num, blacklist, sizeof (blacklist))) {
114 if (option_verbose > 2)
115 ast_log(LOG_NOTICE, "Blacklisted number %s found\n",chan->cid.cid_num);
119 if (chan->cid.cid_name) {
120 if (!ast_db_get("blacklist", chan->cid.cid_name, blacklist, sizeof (blacklist))) {
121 if (option_verbose > 2)
122 ast_log (LOG_NOTICE,"Blacklisted name \"%s\" found\n",chan->cid.cid_name);
128 if (priority_jump || ast_opt_priority_jumping)
129 ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
130 pbx_builtin_setvar_helper(chan, "LOOKUPBLSTATUS", "FOUND");
132 pbx_builtin_setvar_helper(chan, "LOOKUPBLSTATUS", "NOTFOUND");
134 ast_module_user_remove(u);
139 static int unload_module(void)
143 res = ast_unregister_application(app);
144 res |= ast_custom_function_unregister(&blacklist_function);
146 ast_module_user_hangup_all();
151 static int load_module(void)
153 int res = ast_custom_function_register(&blacklist_function);
154 res |= ast_register_application (app, lookupblacklist_exec, synopsis,descrip);
158 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Look up Caller*ID name/number from blacklist database");