Merged revisions 121078 via svnmerge from
[asterisk-bristuff.git] / funcs / func_blacklist.c
blob2a2fa78c798355b07afe53fa2843ed39f875a59d
1 /*
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.
19 /*! \file
21 * \brief Function to lookup the callerid number, and see if it is blacklisted
23 * \author Mark Spencer <markster@digium.com>
25 * \ingroup functions
29 #include "asterisk.h"
31 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
33 #include "asterisk/pbx.h"
34 #include "asterisk/module.h"
35 #include "asterisk/channel.h"
36 #include "asterisk/astdb.h"
38 static int blacklist_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
40 char blacklist[1];
41 int bl = 0;
43 if (chan->cid.cid_num) {
44 if (!ast_db_get("blacklist", chan->cid.cid_num, blacklist, sizeof (blacklist)))
45 bl = 1;
47 if (chan->cid.cid_name) {
48 if (!ast_db_get("blacklist", chan->cid.cid_name, blacklist, sizeof (blacklist)))
49 bl = 1;
52 snprintf(buf, len, "%d", bl);
53 return 0;
56 static struct ast_custom_function blacklist_function = {
57 .name = "BLACKLIST",
58 .synopsis = "Check if the callerid is on the blacklist",
59 .desc = "Uses astdb to check if the Caller*ID is in family 'blacklist'. Returns 1 or 0.\n",
60 .syntax = "BLACKLIST()",
61 .read = blacklist_read,
64 static int unload_module(void)
66 return ast_custom_function_unregister(&blacklist_function);
69 static int load_module(void)
71 return ast_custom_function_register(&blacklist_function);
74 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Look up Caller*ID name/number from blacklist database");