Tue Aug 20 16:35:04 2013

Asterisk developer's documentation


func_blacklist.c File Reference

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

#include "asterisk.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/astdb.h"

Go to the source code of this file.

Functions

 AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Look up Caller*ID name/number from blacklist database")
static int blacklist_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
static int blacklist_read2 (struct ast_channel *chan, const char *cmd, char *data, struct ast_str **str, ssize_t len)
static int load_module (void)
static int unload_module (void)

Variables

static struct ast_custom_function blacklist_function

Detailed Description

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

Author:
Mark Spencer <markster@digium.com>

Definition in file func_blacklist.c.


Function Documentation

AST_MODULE_INFO_STANDARD ( ASTERISK_GPL_KEY  ,
"Look up Caller*ID name/number from blacklist database"   
)
static int blacklist_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
) [static]

Definition at line 59 of file func_blacklist.c.

References ast_db_get(), ast_channel::caller, ast_party_caller::id, ast_party_id::name, ast_party_id::number, ast_party_name::str, ast_party_number::str, ast_party_name::valid, and ast_party_number::valid.

Referenced by blacklist_read2().

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 }

static int blacklist_read2 ( struct ast_channel chan,
const char *  cmd,
char *  data,
struct ast_str **  str,
ssize_t  len 
) [static]

Definition at line 77 of file func_blacklist.c.

References ast_str_buffer(), ast_str_make_space(), ast_str_size(), ast_str_strlen(), ast_str_update(), and blacklist_read().

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 }

static int load_module ( void   )  [static]

Definition at line 104 of file func_blacklist.c.

References ast_custom_function_register.

00105 {
00106    return ast_custom_function_register(&blacklist_function);
00107 }

static int unload_module ( void   )  [static]

Definition at line 99 of file func_blacklist.c.

References ast_custom_function_unregister().

00100 {
00101    return ast_custom_function_unregister(&blacklist_function);
00102 }


Variable Documentation

Initial value:
 {
   .name = "BLACKLIST",
   .read = blacklist_read,
   .read2 = blacklist_read2,
}

Definition at line 93 of file func_blacklist.c.


Generated on 20 Aug 2013 for Asterisk - The Open Source Telephony Project by  doxygen 1.6.1