Wed Jan 8 2020 09:50:12

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

static void __reg_module (void)
 
static void __unreg_module (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 = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
 
static 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

static void __reg_module ( void  )
static

Definition at line 114 of file func_blacklist.c.

static void __unreg_module ( void  )
static

Definition at line 114 of file func_blacklist.c.

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_log(), ast_channel::caller, ast_party_caller::id, LOG_WARNING, 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().

60 {
61  char blacklist[1];
62  int bl = 0;
63 
64  if (!chan) {
65  ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
66  return -1;
67  }
68 
69  if (chan->caller.id.number.valid && chan->caller.id.number.str) {
70  if (!ast_db_get("blacklist", chan->caller.id.number.str, blacklist, sizeof (blacklist)))
71  bl = 1;
72  }
73  if (chan->caller.id.name.valid && chan->caller.id.name.str) {
74  if (!ast_db_get("blacklist", chan->caller.id.name.str, blacklist, sizeof (blacklist)))
75  bl = 1;
76  }
77 
78  snprintf(buf, len, "%d", bl);
79  return 0;
80 }
char * str
Subscriber phone number (Malloced)
Definition: channel.h:241
struct ast_party_caller caller
Channel Caller ID information.
Definition: channel.h:804
int ast_db_get(const char *family, const char *key, char *out, int outlen)
Get key value specified by family/key.
Definition: db.c:348
struct ast_party_name name
Subscriber name.
Definition: channel.h:290
#define LOG_WARNING
Definition: logger.h:144
char * str
Subscriber name (Malloced)
Definition: channel.h:214
struct ast_party_id id
Caller party ID.
Definition: channel.h:370
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
unsigned char valid
TRUE if the name information is valid/present.
Definition: channel.h:229
unsigned char valid
TRUE if the number information is valid/present.
Definition: channel.h:247
struct ast_party_number number
Subscriber phone number.
Definition: channel.h:292
static int blacklist_read2 ( struct ast_channel chan,
const char *  cmd,
char *  data,
struct ast_str **  str,
ssize_t  len 
)
static

Definition at line 82 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().

83 {
84  /* 2 bytes is a single integer, plus terminating null */
85  if (ast_str_size(*str) - ast_str_strlen(*str) < 2) {
86  if (len > ast_str_size(*str) || len == 0) {
87  ast_str_make_space(str, len ? len : ast_str_strlen(*str) + 2);
88  }
89  }
90  if (ast_str_size(*str) - ast_str_strlen(*str) >= 2) {
91  int res = blacklist_read(chan, cmd, data, ast_str_buffer(*str) + ast_str_strlen(*str), 2);
92  ast_str_update(*str);
93  return res;
94  }
95  return -1;
96 }
size_t ast_str_size(const struct ast_str *buf)
Returns the current maximum length (without reallocation) of the current buffer.
Definition: strings.h:482
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:497
static int blacklist_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
int ast_str_make_space(struct ast_str **buf, size_t new_len)
Definition: strings.h:588
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:471
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:446
static int load_module ( void  )
static

Definition at line 109 of file func_blacklist.c.

References ast_custom_function_register.

110 {
112 }
static struct ast_custom_function blacklist_function
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1164
static int unload_module ( void  )
static

Definition at line 104 of file func_blacklist.c.

References ast_custom_function_unregister().

105 {
107 }
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
Definition: pbx.c:3814
static struct ast_custom_function blacklist_function

Variable Documentation

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 = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
static

Definition at line 114 of file func_blacklist.c.

Definition at line 114 of file func_blacklist.c.

struct ast_custom_function blacklist_function
static
Initial value:
= {
.name = "BLACKLIST",
.read = blacklist_read,
.read2 = blacklist_read2,
}
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)

Definition at line 98 of file func_blacklist.c.