Asterisk - The Open Source Telephony Project GIT-master-a63eec2
Loading...
Searching...
No Matches
Functions | Variables
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"
Include dependency graph for func_blacklist.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
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_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Look up Caller*ID name/number from blacklist database" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_custom_function blacklist_function
 

Detailed Description

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

Author
Mark Spencer marks.nosp@m.ter@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

Definition in file func_blacklist.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 115 of file func_blacklist.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 115 of file func_blacklist.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 115 of file func_blacklist.c.

◆ blacklist_read()

static int blacklist_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)
static

Definition at line 60 of file func_blacklist.c.

61{
62 char blacklist[1];
63 int bl = 0;
64
65 if (!chan) {
66 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
67 return -1;
68 }
69
70 if (ast_channel_caller(chan)->id.number.valid && ast_channel_caller(chan)->id.number.str) {
71 if (!ast_db_get("blacklist", ast_channel_caller(chan)->id.number.str, blacklist, sizeof (blacklist)))
72 bl = 1;
73 }
74 if (ast_channel_caller(chan)->id.name.valid && ast_channel_caller(chan)->id.name.str) {
75 if (!ast_db_get("blacklist", ast_channel_caller(chan)->id.name.str, blacklist, sizeof (blacklist)))
76 bl = 1;
77 }
78
79 snprintf(buf, len, "%d", bl);
80 return 0;
81}
int ast_db_get(const char *family, const char *key, char *value, int valuelen)
Get key value specified by family/key.
Definition db.c:421
#define ast_log
Definition astobj2.c:42
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
char buf[BUFSIZE]
Definition eagi_proxy.c:66
static const char name[]
Definition format_mp3.c:68
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define LOG_WARNING
Number structure.

References ast_channel_caller(), ast_db_get(), ast_log, buf, len(), LOG_WARNING, and name.

Referenced by blacklist_read2().

◆ blacklist_read2()

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

Definition at line 83 of file func_blacklist.c.

84{
85 /* 2 bytes is a single integer, plus terminating null */
86 if (ast_str_size(*str) - ast_str_strlen(*str) < 2) {
87 if (len > ast_str_size(*str) || len == 0) {
89 }
90 }
91 if (ast_str_size(*str) - ast_str_strlen(*str) >= 2) {
92 int res = blacklist_read(chan, cmd, data, ast_str_buffer(*str) + ast_str_strlen(*str), 2);
94 return res;
95 }
96 return -1;
97}
const char * str
Definition app_jack.c:150
static int blacklist_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
size_t attribute_pure ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition strings.h:730
#define ast_str_make_space(buf, new_len)
Definition strings.h:828
void ast_str_update(struct ast_str *buf)
Update the length of the buffer, after using ast_str merely as a buffer.
Definition strings.h:703
char *attribute_pure ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition strings.h:761
size_t attribute_pure ast_str_size(const struct ast_str *buf)
Returns the current maximum length (without reallocation) of the current buffer.
Definition strings.h:742

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

◆ load_module()

static int load_module ( void  )
static

Definition at line 110 of file func_blacklist.c.

111{
113}
static struct ast_custom_function blacklist_function
#define ast_custom_function_register(acf)
Register a custom function.
Definition pbx.h:1562

References ast_custom_function_register, and blacklist_function.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 105 of file func_blacklist.c.

106{
108}
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.

References ast_custom_function_unregister(), and blacklist_function.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Look up Caller*ID name/number from blacklist database" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 115 of file func_blacklist.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 115 of file func_blacklist.c.

◆ blacklist_function

struct ast_custom_function blacklist_function
static
Initial value:
= {
.name = "BLACKLIST",
.read = blacklist_read,
.read2 = blacklist_read2,
}
static int blacklist_read2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **str, ssize_t len)

Definition at line 99 of file func_blacklist.c.

99 {
100 .name = "BLACKLIST",
101 .read = blacklist_read,
102 .read2 = blacklist_read2,
103};

Referenced by load_module(), and unload_module().