Wed Oct 28 15:48:07 2009

Asterisk developer's documentation

app_lookupblacklist.c File Reference

App to lookup the callerid number, and see if it is blacklisted. More...

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "asterisk.h"
#include "asterisk/lock.h"
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/options.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/translate.h"
#include "asterisk/image.h"
#include "asterisk/callerid.h"
#include "asterisk/astdb.h"

Include dependency graph for app_lookupblacklist.c:

Go to the source code of this file.


char * description (void)
 Provides a description of the module.
char * key ()
 Returns the ASTERISK_GPL_KEY.
int load_module (void)
 Initialize the module.
static int lookupblacklist_exec (struct ast_channel *chan, void *data)
int unload_module (void)
 Cleanup all module structures, sockets, etc.
int usecount (void)
 Provides a usecount.


static char * app = "LookupBlacklist"
static char * descrip
static char * synopsis = "Look up Caller*ID name/number from blacklist database"
static char * tdesc = "Look up Caller*ID name/number from blacklist database"

Detailed Description

App to lookup the callerid number, and see if it is blacklisted.

Definition in file app_lookupblacklist.c.

Function Documentation

char* description ( void   ) 

Provides a description of the module.

a short description of your module

Definition at line 126 of file app_lookupblacklist.c.

00127 {
00128    return tdesc;
00129 }

char* key ( void   ) 


This returns the ASTERISK_GPL_KEY, signifiying that you agree to the terms of the GPL stated in the ASTERISK_GPL_KEY. Your module will not load if it does not return the EXACT message:

 char *key(void) {
         return ASTERISK_GPL_KEY;


Definition at line 138 of file app_lookupblacklist.c.


00139 {
00140    return ASTERISK_GPL_KEY;
00141 }

int load_module ( void   ) 

Initialize the module.

This function is called at module load time. Put all code in here that needs to set up your module's hardware, software, registrations, etc.

This function should return 0 on success and non-zero on failure. If the module is not loaded successfully, Asterisk will call its unload_module() function.
Initialize the Agents module. This function is being called by Asterisk when loading the module. Among other thing it registers applications, cli commands and reads the cofiguration file.

int Always 0.

Definition at line 121 of file app_lookupblacklist.c.

References ast_register_application(), and lookupblacklist_exec().

static int lookupblacklist_exec ( struct ast_channel chan,
void *  data 
) [static]

Definition at line 69 of file app_lookupblacklist.c.

References ast_db_get(), ast_goto_if_exists(), ast_log(), ast_strlen_zero(), ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, ast_channel::context, ast_channel::exten, LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_NOTICE, option_priority_jumping, option_verbose, pbx_builtin_setvar_helper(), and ast_channel::priority.

Referenced by load_module().

00070 {
00071    char blacklist[1];
00072    struct localuser *u;
00073    int bl = 0;
00074    int priority_jump = 0;
00076    LOCAL_USER_ADD(u);
00078    if (!ast_strlen_zero(data)) {
00079       if (strchr(data, 'j'))
00080          priority_jump = 1;
00081    }
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    }
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"); 
00105    LOCAL_USER_REMOVE(u);
00107    return 0;
00108 }

int unload_module ( void   ) 

Cleanup all module structures, sockets, etc.

This is called at exit. Any registrations and memory allocations need to be unregistered and free'd here. Nothing else will do these for you (until exit).

Zero on success, or non-zero on error.

Definition at line 110 of file app_lookupblacklist.c.

References ast_unregister_application(), and STANDARD_HANGUP_LOCALUSERS.

00111 {
00112    int res;
00114    res = ast_unregister_application(app);
00118    return res; 
00119 }

int usecount ( void   ) 

Provides a usecount.

This function will be called by various parts of asterisk. Basically, all it has to do is to return a usecount when called. You will need to maintain your usecount within the module somewhere. The usecount should be how many channels provided by this module are in use.

The module's usecount.

Definition at line 131 of file app_lookupblacklist.c.


00132 {
00133    int res;
00134    STANDARD_USECOUNT (res);
00135    return res;
00136 }

Variable Documentation

char* app = "LookupBlacklist" [static]

Definition at line 50 of file app_lookupblacklist.c.

char* descrip [static]

Definition at line 54 of file app_lookupblacklist.c.

Definition at line 66 of file app_lookupblacklist.c.

Definition at line 64 of file app_lookupblacklist.c.

char* synopsis = "Look up Caller*ID name/number from blacklist database" [static]

Definition at line 52 of file app_lookupblacklist.c.

char* tdesc = "Look up Caller*ID name/number from blacklist database" [static]

Definition at line 48 of file app_lookupblacklist.c.

Generated on Wed Oct 28 15:48:07 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6