Wed Apr 6 11:29:45 2011

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: 276347 $")
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->caller.id.number.valid && chan->caller.id.number.str) {
00061       if (!ast_db_get("blacklist", chan->caller.id.number.str, blacklist, sizeof (blacklist)))
00062          bl = 1;
00063    }
00064    if (chan->caller.id.name.valid && chan->caller.id.name.str) {
00065       if (!ast_db_get("blacklist", chan->caller.id.name.str, blacklist, sizeof (blacklist)))
00066          bl = 1;
00067    }
00068 
00069    snprintf(buf, len, "%d", bl);
00070    return 0;
00071 }
00072 
00073 static int blacklist_read2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **str, ssize_t len)
00074 {
00075    /* 2 bytes is a single integer, plus terminating null */
00076    if (ast_str_size(*str) - ast_str_strlen(*str) < 2) {
00077       if (len > ast_str_size(*str) || len == 0) {
00078          ast_str_make_space(str, len ? len : ast_str_strlen(*str) + 2);
00079       }
00080    }
00081    if (ast_str_size(*str) - ast_str_strlen(*str) >= 2) {
00082       int res = blacklist_read(chan, cmd, data, ast_str_buffer(*str) + ast_str_strlen(*str), 2);
00083       ast_str_update(*str);
00084       return res;
00085    }
00086    return -1;
00087 }
00088 
00089 static struct ast_custom_function blacklist_function = {
00090    .name = "BLACKLIST",
00091    .read = blacklist_read,
00092    .read2 = blacklist_read2,
00093 };
00094 
00095 static int unload_module(void)
00096 {
00097    return ast_custom_function_unregister(&blacklist_function);
00098 }
00099 
00100 static int load_module(void)
00101 {
00102    return ast_custom_function_register(&blacklist_function);
00103 }
00104 
00105 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Look up Caller*ID name/number from blacklist database");

Generated on Wed Apr 6 11:29:45 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7