Sun Aug 6 15:02:24 2006

Asterisk developer's documentation


Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

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  * \ingroup applications
00024  * 
00025  */
00026 
00027 #include <stdlib.h>
00028 #include <stdio.h>
00029 #include <string.h>
00030 
00031 #include "asterisk.h"
00032 
00033 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 7221 $")
00034 
00035 #include "asterisk/lock.h"
00036 #include "asterisk/file.h"
00037 #include "asterisk/logger.h"
00038 #include "asterisk/options.h"
00039 #include "asterisk/channel.h"
00040 #include "asterisk/pbx.h"
00041 #include "asterisk/module.h"
00042 #include "asterisk/translate.h"
00043 #include "asterisk/image.h"
00044 #include "asterisk/callerid.h"
00045 #include "asterisk/astdb.h"
00046 #include "asterisk/options.h"
00047 
00048 static char *tdesc = "Look up Caller*ID name/number from blacklist database";
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";
00063 
00064 STANDARD_LOCAL_USER;
00065 
00066 LOCAL_USER_DECL;
00067 
00068 static int
00069 lookupblacklist_exec (struct ast_channel *chan, void *data)
00070 {
00071    char blacklist[1];
00072    struct localuser *u;
00073    int bl = 0;
00074    int priority_jump = 0;
00075 
00076    LOCAL_USER_ADD(u);
00077 
00078    if (!ast_strlen_zero(data)) {
00079       if (strchr(data, 'j'))
00080          priority_jump = 1;
00081    }
00082 
00083    if (chan->cid.cid_num) {
00084       if (!ast_db_get("blacklist", chan->cid.cid_num, blacklist, sizeof (blacklist))) {
00085          if (option_verbose > 2)
00086             ast_log(LOG_NOTICE, "Blacklisted number %s found\n",chan->cid.cid_num);
00087          bl = 1;
00088       }
00089    }
00090    if (chan->cid.cid_name) {
00091       if (!ast_db_get("blacklist", chan->cid.cid_name, blacklist, sizeof (blacklist))) {
00092          if (option_verbose > 2)
00093             ast_log (LOG_NOTICE,"Blacklisted name \"%s\" found\n",chan->cid.cid_name);
00094          bl = 1;
00095       }
00096    }
00097 
00098    if (bl) {
00099       if (priority_jump || option_priority_jumping) 
00100          ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
00101       pbx_builtin_setvar_helper(chan, "LOOKUPBLSTATUS", "FOUND");
00102    } else
00103       pbx_builtin_setvar_helper(chan, "LOOKUPBLSTATUS", "NOTFOUND"); 
00104 
00105    LOCAL_USER_REMOVE(u);
00106 
00107    return 0;
00108 }
00109 
00110 int unload_module (void)
00111 {
00112    int res;
00113 
00114    res = ast_unregister_application(app);
00115 
00116    STANDARD_HANGUP_LOCALUSERS;
00117 
00118    return res; 
00119 }
00120 
00121 int load_module (void)
00122 {
00123    return ast_register_application (app, lookupblacklist_exec, synopsis,descrip);
00124 }
00125 
00126 char *description (void)
00127 {
00128    return tdesc;
00129 }
00130 
00131 int usecount (void)
00132 {
00133    int res;
00134    STANDARD_USECOUNT (res);
00135    return res;
00136 }
00137 
00138 char *key ()
00139 {
00140    return ASTERISK_GPL_KEY;
00141 }

Generated on Sun Aug 6 15:02:24 2006 for Asterisk - the Open Source PBX by  doxygen 1.4.2