Asterisk - The Open Source Telephony Project GIT-master-f36a736
func_blacklist.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 1999 - 2005, Digium, Inc.
5 *
6 * Mark Spencer <markster@digium.com>
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 <markster@digium.com>
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 <synopsis>
43 Check if the callerid is on the blacklist.
44 </synopsis>
45 <syntax />
46 <description>
47 <para>Uses astdb to check if the Caller*ID is in family <literal>blacklist</literal>.
48 Returns <literal>1</literal> or <literal>0</literal>.</para>
49 </description>
50 <see-also>
51 <ref type="function">DB</ref>
52 </see-also>
53 </function>
54
55***/
56
57static int blacklist_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
58{
59 char blacklist[1];
60 int bl = 0;
61
62 if (!chan) {
63 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
64 return -1;
65 }
66
67 if (ast_channel_caller(chan)->id.number.valid && ast_channel_caller(chan)->id.number.str) {
68 if (!ast_db_get("blacklist", ast_channel_caller(chan)->id.number.str, blacklist, sizeof (blacklist)))
69 bl = 1;
70 }
71 if (ast_channel_caller(chan)->id.name.valid && ast_channel_caller(chan)->id.name.str) {
72 if (!ast_db_get("blacklist", ast_channel_caller(chan)->id.name.str, blacklist, sizeof (blacklist)))
73 bl = 1;
74 }
75
76 snprintf(buf, len, "%d", bl);
77 return 0;
78}
79
80static int blacklist_read2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **str, ssize_t len)
81{
82 /* 2 bytes is a single integer, plus terminating null */
83 if (ast_str_size(*str) - ast_str_strlen(*str) < 2) {
84 if (len > ast_str_size(*str) || len == 0) {
86 }
87 }
88 if (ast_str_size(*str) - ast_str_strlen(*str) >= 2) {
89 int res = blacklist_read(chan, cmd, data, ast_str_buffer(*str) + ast_str_strlen(*str), 2);
91 return res;
92 }
93 return -1;
94}
95
97 .name = "BLACKLIST",
98 .read = blacklist_read,
99 .read2 = blacklist_read2,
100};
101
102static int unload_module(void)
103{
105}
106
107static int load_module(void)
108{
110}
111
112AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Look up Caller*ID name/number from blacklist database");
const char * str
Definition: app_jack.c:147
Persistent data storage (akin to *doze registry)
int ast_db_get(const char *family, const char *key, char *value, int valuelen)
Get key value specified by family/key.
Definition: main/db.c:427
Asterisk main include file. File version handling, generic pbx functions.
#define ast_log
Definition: astobj2.c:42
General Asterisk PBX channel definitions.
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static const char name[]
Definition: format_mp3.c:68
static struct ast_custom_function blacklist_function
static int blacklist_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
static int load_module(void)
static int unload_module(void)
static int blacklist_read2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **str, ssize_t len)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define LOG_WARNING
Asterisk module definitions.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:581
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
Core PBX routines and definitions.
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1558
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:761
#define ast_str_make_space(buf, new_len)
Definition: strings.h:828
void ast_str_update(struct ast_str *buf)
Update the length of the buffer, after using ast_str merely as a buffer.
Definition: strings.h:703
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:730
size_t ast_str_size(const struct ast_str *buf)
Returns the current maximum length (without reallocation) of the current buffer.
Definition: strings.h:742
Main Channel structure associated with a channel.
Data structure associated with a custom dialplan function.
Definition: pbx.h:118
const char * name
Definition: pbx.h:119
Support for dynamic strings.
Definition: strings.h:623
Number structure.
Definition: app_followme.c:154