Asterisk - The Open Source Telephony Project GIT-master-8924258
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
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 <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
60static 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
83static 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) {
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);
94 return res;
95 }
96 return -1;
97}
98
100 .name = "BLACKLIST",
101 .read = blacklist_read,
102 .read2 = blacklist_read2,
103};
104
105static int unload_module(void)
106{
108}
109
110static int load_module(void)
111{
113}
114
115AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Look up Caller*ID name/number from blacklist database");
const char * str
Definition: app_jack.c:150
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: db.c:421
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:1559
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:157