Fix a few things I missed to ensure zt_chan_conf structure is not modified in mkintf
[asterisk-bristuff.git] / apps / app_lookupblacklist.c
blob88ed52d861b8954e1e9ebe54ed2c464913dd214d
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 App to lookup the callerid number, and see if it is blacklisted
23 * \author Mark Spencer <markster@digium.com>
25 * \ingroup applications
29 #include "asterisk.h"
31 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <string.h>
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"
61 " FOUND | NOTFOUND\n"
62 "Example: exten => 1234,1,LookupBlacklist()\n\n"
63 "This application is deprecated and may be removed from a future release.\n"
64 "Please use the dialplan function BLACKLIST() instead.\n";
67 static int blacklist_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
69 char blacklist[1];
70 int bl = 0;
72 if (chan->cid.cid_num) {
73 if (!ast_db_get("blacklist", chan->cid.cid_num, blacklist, sizeof (blacklist)))
74 bl = 1;
76 if (chan->cid.cid_name) {
77 if (!ast_db_get("blacklist", chan->cid.cid_name, blacklist, sizeof (blacklist)))
78 bl = 1;
81 snprintf(buf, len, "%d", bl);
82 return 0;
85 static struct ast_custom_function blacklist_function = {
86 .name = "BLACKLIST",
87 .synopsis = "Check if the callerid is on the blacklist",
88 .desc = "Uses astdb to check if the Caller*ID is in family 'blacklist'. Returns 1 or 0.\n",
89 .syntax = "BLACKLIST()",
90 .read = blacklist_read,
93 static int
94 lookupblacklist_exec (struct ast_channel *chan, void *data)
96 char blacklist[1];
97 struct ast_module_user *u;
98 int bl = 0;
99 int priority_jump = 0;
100 static int dep_warning = 0;
102 u = ast_module_user_add(chan);
104 if (!dep_warning) {
105 dep_warning = 1;
106 ast_log(LOG_WARNING, "LookupBlacklist is deprecated. Please use ${BLACKLIST()} instead.\n");
109 if (!ast_strlen_zero(data)) {
110 if (strchr(data, 'j'))
111 priority_jump = 1;
114 if (chan->cid.cid_num) {
115 if (!ast_db_get("blacklist", chan->cid.cid_num, blacklist, sizeof (blacklist))) {
116 if (option_verbose > 2)
117 ast_log(LOG_NOTICE, "Blacklisted number %s found\n",chan->cid.cid_num);
118 bl = 1;
121 if (chan->cid.cid_name) {
122 if (!ast_db_get("blacklist", chan->cid.cid_name, blacklist, sizeof (blacklist))) {
123 if (option_verbose > 2)
124 ast_log (LOG_NOTICE,"Blacklisted name \"%s\" found\n",chan->cid.cid_name);
125 bl = 1;
129 if (bl) {
130 if (priority_jump || ast_opt_priority_jumping)
131 ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
132 pbx_builtin_setvar_helper(chan, "LOOKUPBLSTATUS", "FOUND");
133 } else
134 pbx_builtin_setvar_helper(chan, "LOOKUPBLSTATUS", "NOTFOUND");
136 ast_module_user_remove(u);
138 return 0;
141 static int unload_module(void)
143 int res;
145 res = ast_unregister_application(app);
146 res |= ast_custom_function_unregister(&blacklist_function);
148 ast_module_user_hangup_all();
150 return res;
153 static int load_module(void)
155 int res = ast_custom_function_register(&blacklist_function);
156 res |= ast_register_application (app, lookupblacklist_exec, synopsis,descrip);
157 return res;
160 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Look up Caller*ID name/number from blacklist database");