Thu Apr 28 2011 17:15:22

Asterisk developer's documentation


func_blacklist.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  *
00021  * \brief Function to lookup the callerid number, and see if it is blacklisted
00022  *
00023  * \author Mark Spencer <markster@digium.com>
00024  *
00025  * \ingroup functions
00026  * 
00027  */
00028 
00029 #include "asterisk.h"
00030 
00031 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 154542 $")
00032 
00033 #include "asterisk/pbx.h"
00034 #include "asterisk/module.h"
00035 #include "asterisk/channel.h"
00036 #include "asterisk/astdb.h"
00037 
00038 /*** DOCUMENTATION
00039    <function name="BLACKLIST" language="en_US">
00040       <synopsis>
00041          Check if the callerid is on the blacklist.
00042       </synopsis>
00043       <syntax />
00044       <description>
00045          <para>Uses astdb to check if the Caller*ID is in family <literal>blacklist</literal>.
00046          Returns <literal>1</literal> or <literal>0</literal>.</para>
00047       </description>
00048       <see-also>
00049          <ref type="function">DB</ref>
00050       </see-also>
00051    </function>
00052 
00053 ***/
00054 
00055 static int blacklist_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
00056 {
00057    char blacklist[1];
00058    int bl = 0;
00059 
00060    if (chan->cid.cid_num) {
00061       if (!ast_db_get("blacklist", chan->cid.cid_num, blacklist, sizeof (blacklist)))
00062          bl = 1;
00063    }
00064    if (chan->cid.cid_name) {
00065       if (!ast_db_get("blacklist", chan->cid.cid_name, blacklist, sizeof (blacklist)))
00066          bl = 1;
00067    }
00068 
00069    snprintf(buf, len, "%d", bl);
00070    return 0;
00071 }
00072 
00073 static struct ast_custom_function blacklist_function = {
00074    .name = "BLACKLIST",
00075    .read = blacklist_read,
00076 };
00077 
00078 static int unload_module(void)
00079 {
00080    return ast_custom_function_unregister(&blacklist_function);
00081 }
00082 
00083 static int load_module(void)
00084 {
00085    return ast_custom_function_register(&blacklist_function);
00086 }
00087 
00088 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Look up Caller*ID name/number from blacklist database");