Wed Oct 28 11:51:04 2009

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: 89521 $")
00032 
00033 #include "asterisk/pbx.h"
00034 #include "asterisk/module.h"
00035 #include "asterisk/channel.h"
00036 #include "asterisk/astdb.h"
00037 
00038 static int blacklist_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
00039 {
00040    char blacklist[1];
00041    int bl = 0;
00042 
00043    if (chan->cid.cid_num) {
00044       if (!ast_db_get("blacklist", chan->cid.cid_num, blacklist, sizeof (blacklist)))
00045          bl = 1;
00046    }
00047    if (chan->cid.cid_name) {
00048       if (!ast_db_get("blacklist", chan->cid.cid_name, blacklist, sizeof (blacklist)))
00049          bl = 1;
00050    }
00051 
00052    snprintf(buf, len, "%d", bl);
00053    return 0;
00054 }
00055 
00056 static struct ast_custom_function blacklist_function = {
00057    .name = "BLACKLIST",
00058    .synopsis = "Check if the callerid is on the blacklist",
00059    .desc = "Uses astdb to check if the Caller*ID is in family 'blacklist'.  Returns 1 or 0.\n",
00060    .syntax = "BLACKLIST()",
00061    .read = blacklist_read,
00062 };
00063 
00064 static int unload_module(void)
00065 {
00066    return ast_custom_function_unregister(&blacklist_function);
00067 }
00068 
00069 static int load_module(void)
00070 {
00071    return ast_custom_function_register(&blacklist_function);
00072 }
00073 
00074 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Look up Caller*ID name/number from blacklist database");

Generated on Wed Oct 28 11:51:04 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6