Sat Mar 10 01:54:17 2012

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 /*** MODULEINFO
00030    <support_level>core</support_level>
00031  ***/
00032 
00033 #include "asterisk.h"
00034 
00035 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328209 $")
00036 
00037 #include "asterisk/pbx.h"
00038 #include "asterisk/module.h"
00039 #include "asterisk/channel.h"
00040 #include "asterisk/astdb.h"
00041 
00042 /*** DOCUMENTATION
00043    <function name="BLACKLIST" language="en_US">
00044       <synopsis>
00045          Check if the callerid is on the blacklist.
00046       </synopsis>
00047       <syntax />
00048       <description>
00049          <para>Uses astdb to check if the Caller*ID is in family <literal>blacklist</literal>.
00050          Returns <literal>1</literal> or <literal>0</literal>.</para>
00051       </description>
00052       <see-also>
00053          <ref type="function">DB</ref>
00054       </see-also>
00055    </function>
00056 
00057 ***/
00058 
00059 static int blacklist_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
00060 {
00061    char blacklist[1];
00062    int bl = 0;
00063 
00064    if (chan->caller.id.number.valid && chan->caller.id.number.str) {
00065       if (!ast_db_get("blacklist", chan->caller.id.number.str, blacklist, sizeof (blacklist)))
00066          bl = 1;
00067    }
00068    if (chan->caller.id.name.valid && chan->caller.id.name.str) {
00069       if (!ast_db_get("blacklist", chan->caller.id.name.str, blacklist, sizeof (blacklist)))
00070          bl = 1;
00071    }
00072 
00073    snprintf(buf, len, "%d", bl);
00074    return 0;
00075 }
00076 
00077 static int blacklist_read2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **str, ssize_t len)
00078 {
00079    /* 2 bytes is a single integer, plus terminating null */
00080    if (ast_str_size(*str) - ast_str_strlen(*str) < 2) {
00081       if (len > ast_str_size(*str) || len == 0) {
00082          ast_str_make_space(str, len ? len : ast_str_strlen(*str) + 2);
00083       }
00084    }
00085    if (ast_str_size(*str) - ast_str_strlen(*str) >= 2) {
00086       int res = blacklist_read(chan, cmd, data, ast_str_buffer(*str) + ast_str_strlen(*str), 2);
00087       ast_str_update(*str);
00088       return res;
00089    }
00090    return -1;
00091 }
00092 
00093 static struct ast_custom_function blacklist_function = {
00094    .name = "BLACKLIST",
00095    .read = blacklist_read,
00096    .read2 = blacklist_read2,
00097 };
00098 
00099 static int unload_module(void)
00100 {
00101    return ast_custom_function_unregister(&blacklist_function);
00102 }
00103 
00104 static int load_module(void)
00105 {
00106    return ast_custom_function_register(&blacklist_function);
00107 }
00108 
00109 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Look up Caller*ID name/number from blacklist database");

Generated on Sat Mar 10 01:54:17 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7