Sat Aug 6 00:39:20 2011

Asterisk developer's documentation


app_lookupblacklist.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 App to lookup the callerid number, and see if it is blacklisted
00022  *
00023  * \author Mark Spencer <markster@digium.com>
00024  *
00025  * \ingroup applications
00026  * 
00027  */
00028 
00029 #include "asterisk.h"
00030 
00031 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 56922 $")
00032 
00033 #include <stdlib.h>
00034 #include <stdio.h>
00035 #include <string.h>
00036 
00037 #include "asterisk/lock.h"
00038 #include "asterisk/file.h"
00039 #include "asterisk/logger.h"
00040 #include "asterisk/options.h"
00041 #include "asterisk/channel.h"
00042 #include "asterisk/pbx.h"
00043 #include "asterisk/module.h"
00044 #include "asterisk/translate.h"
00045 #include "asterisk/image.h"
00046 #include "asterisk/callerid.h"
00047 #include "asterisk/astdb.h"
00048 #include "asterisk/options.h"
00049 
00050 static char *app = "LookupBlacklist";
00051 
00052 static char *synopsis = "Look up Caller*ID name/number from blacklist database";
00053 
00054 static char *descrip =
00055   "  LookupBlacklist(options): Looks up the Caller*ID number on the active\n"
00056   "channel in the Asterisk database (family 'blacklist').  \n"
00057   "The option string may contain the following character:\n"
00058   "   'j' -- jump to n+101 priority if the number/name is found in the blacklist\n"
00059   "This application sets the following channel variable upon completion:\n"
00060   "   LOOKUPBLSTATUS    The status of the Blacklist lookup as a text string, one of\n"
00061   "      FOUND | NOTFOUND\n"
00062   "Example: exten => 1234,1,LookupBlacklist()\n\n"
00063   "This application is deprecated and may be removed from a future release.\n"
00064   "Please use the dialplan function BLACKLIST() instead.\n";
00065 
00066 
00067 static int blacklist_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
00068 {
00069    char blacklist[1];
00070    int bl = 0;
00071 
00072    if (chan->cid.cid_num) {
00073       if (!ast_db_get("blacklist", chan->cid.cid_num, blacklist, sizeof (blacklist)))
00074          bl = 1;
00075    }
00076    if (chan->cid.cid_name) {
00077       if (!ast_db_get("blacklist", chan->cid.cid_name, blacklist, sizeof (blacklist)))
00078          bl = 1;
00079    }
00080 
00081    snprintf(buf, len, "%d", bl);
00082    return 0;
00083 }
00084 
00085 static struct ast_custom_function blacklist_function = {
00086    .name = "BLACKLIST",
00087    .synopsis = "Check if the callerid is on the blacklist",
00088    .desc = "Uses astdb to check if the Caller*ID is in family 'blacklist'.  Returns 1 or 0.\n",
00089    .syntax = "BLACKLIST()",
00090    .read = blacklist_read,
00091 };
00092 
00093 static int
00094 lookupblacklist_exec (struct ast_channel *chan, void *data)
00095 {
00096    char blacklist[1];
00097    struct ast_module_user *u;
00098    int bl = 0;
00099    int priority_jump = 0;
00100    static int dep_warning = 0;
00101 
00102    u = ast_module_user_add(chan);
00103 
00104    if (!dep_warning) {
00105       dep_warning = 1;
00106       ast_log(LOG_WARNING, "LookupBlacklist is deprecated.  Please use ${BLACKLIST()} instead.\n");
00107    }
00108 
00109    if (!ast_strlen_zero(data)) {
00110       if (strchr(data, 'j'))
00111          priority_jump = 1;
00112    }
00113 
00114    if (chan->cid.cid_num) {
00115       if (!ast_db_get("blacklist", chan->cid.cid_num, blacklist, sizeof (blacklist))) {
00116          if (option_verbose > 2)
00117             ast_log(LOG_NOTICE, "Blacklisted number %s found\n",chan->cid.cid_num);
00118          bl = 1;
00119       }
00120    }
00121    if (chan->cid.cid_name) {
00122       if (!ast_db_get("blacklist", chan->cid.cid_name, blacklist, sizeof (blacklist))) {
00123          if (option_verbose > 2)
00124             ast_log (LOG_NOTICE,"Blacklisted name \"%s\" found\n",chan->cid.cid_name);
00125          bl = 1;
00126       }
00127    }
00128 
00129    if (bl) {
00130       if (priority_jump || ast_opt_priority_jumping) 
00131          ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
00132       pbx_builtin_setvar_helper(chan, "LOOKUPBLSTATUS", "FOUND");
00133    } else
00134       pbx_builtin_setvar_helper(chan, "LOOKUPBLSTATUS", "NOTFOUND"); 
00135 
00136    ast_module_user_remove(u);
00137 
00138    return 0;
00139 }
00140 
00141 static int unload_module(void)
00142 {
00143    int res;
00144 
00145    res = ast_unregister_application(app);
00146    res |= ast_custom_function_unregister(&blacklist_function);
00147 
00148    ast_module_user_hangup_all();
00149 
00150    return res; 
00151 }
00152 
00153 static int load_module(void)
00154 {
00155    int res = ast_custom_function_register(&blacklist_function);
00156    res |= ast_register_application (app, lookupblacklist_exec, synopsis,descrip);
00157    return res;
00158 }
00159 
00160 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Look up Caller*ID name/number from blacklist database");

Generated on Sat Aug 6 00:39:20 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7