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 Function to lookup the callerid number, and see if it is blacklisted
23 * \author Mark Spencer <markster@digium.com>
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 int blacklist_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
55 if (chan->cid.cid_num) {
56 if (!ast_db_get("blacklist", chan->cid.cid_num, blacklist, sizeof (blacklist)))
59 if (chan->cid.cid_name) {
60 if (!ast_db_get("blacklist", chan->cid.cid_name, blacklist, sizeof (blacklist)))
64 snprintf(buf, len, "%d", bl);
68 static struct ast_custom_function blacklist_function = {
70 .synopsis = "Check if the callerid is on the blacklist",
71 .desc = "Uses astdb to check if the Caller*ID is in family 'blacklist'. Returns 1 or 0.\n",
72 .syntax = "BLACKLIST()",
73 .read = blacklist_read,
76 static int unload_module(void)
78 int res = ast_custom_function_unregister(&blacklist_function);
79 ast_module_user_hangup_all();
83 static int load_module(void)
85 return ast_custom_function_register(&blacklist_function);
88 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Look up Caller*ID name/number from blacklist database");