Debian Codegraph @

funcs/func_blacklist.c

raw symbols SCIP
1 /*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 1999 - 2005, Digium, Inc.
5 *
6 * Mark Spencer <[email protected]>
7 *
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.
13 *
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.
17 */
18
19 /*! \file
20 *
21 * \brief Function to lookup the callerid number, and see if it is blacklisted
22 *
23 * \author Mark Spencer <[email protected]>
24 *
25 * \ingroup functions
26 *
27 */
28
29 /*** MODULEINFO
30 <support_level>core</support_level>
31 ***/
32
33 #include "asterisk.h"
34
35 #include "asterisk/pbx.h"
36 #include "asterisk/module.h"
37 #include "asterisk/channel.h"
38 #include "asterisk/astdb.h"
39
40 /*** DOCUMENTATION
41 <function name="BLACKLIST" language="en_US">
42 <since>
43 <version>1.6.0</version>
44 </since>
45 <synopsis>
46 Check if the callerid is on the blacklist.
47 </synopsis>
48 <syntax />
49 <description>
50 <para>Uses astdb to check if the Caller*ID is in family <literal>blacklist</literal>.
51 Returns <literal>1</literal> or <literal>0</literal>.</para>
52 </description>
53 <see-also>
54 <ref type="function">DB</ref>
55 </see-also>
56 </function>
57
58 ***/
59
60 static int blacklist_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
61 {
62 char blacklist[1];
63 int bl = 0;
64
65 if (!chan) {
66 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
67 return -1;
68 }
69
70 if (ast_channel_caller(chan)->id.number.valid && ast_channel_caller(chan)->id.number.str) {
71 if (!ast_db_get("blacklist", ast_channel_caller(chan)->id.number.str, blacklist, sizeof (blacklist)))
72 bl = 1;
73 }
74 if (ast_channel_caller(chan)->id.name.valid && ast_channel_caller(chan)->id.name.str) {
75 if (!ast_db_get("blacklist", ast_channel_caller(chan)->id.name.str, blacklist, sizeof (blacklist)))
76 bl = 1;
77 }
78
79 snprintf(buf, len, "%d", bl);
80 return 0;
81 }
82
83 static int blacklist_read2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **str, ssize_t len)
84 {
85 /* 2 bytes is a single integer, plus terminating null */
86 if (ast_str_size(*str) - ast_str_strlen(*str) < 2) {
87 if (len > ast_str_size(*str) || len == 0) {
88 ast_str_make_space(str, len ? len : ast_str_strlen(*str) + 2);
89 }
90 }
91 if (ast_str_size(*str) - ast_str_strlen(*str) >= 2) {
92 int res = blacklist_read(chan, cmd, data, ast_str_buffer(*str) + ast_str_strlen(*str), 2);
93 ast_str_update(*str);
94 return res;
95 }
96 return -1;
97 }
98
99 static struct ast_custom_function blacklist_function = {
100 .name = "BLACKLIST",
101 .read = blacklist_read,
102 .read2 = blacklist_read2,
103 };
104
105 static int unload_module(void)
106 {
107 return ast_custom_function_unregister(&blacklist_function);
108 }
109
110 static int load_module(void)
111 {
112 return ast_custom_function_register(&blacklist_function);
113 }
114
115 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Look up Caller*ID name/number from blacklist database");