| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
#include "asterisk.h" |
| 34 |
|
| 35 |
#include "asterisk/pbx.h" |
| 36 |
#include "asterisk/module.h" |
| 37 |
#include "asterisk/channel.h" |
| 38 |
#include "asterisk/astdb.h" |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
static int blacklist_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
| 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 |
} |
| 82 |
|
| 83 |
static int blacklist_read2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **str, ssize_t len) |
| 84 |
{ |
| 85 |
|
| 86 |
if (ast_str_size(*str) - ast_str_strlen(*str) < 2) { |
| 87 |
if (len > ast_str_size(*str) || len == 0) { |
| 88 |
ast_str_make_space(str, len ? len : ast_str_strlen(*str) + 2); |
| 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); |
| 93 |
ast_str_update(*str); |
| 94 |
return res; |
| 95 |
} |
| 96 |
return -1; |
| 97 |
} |
| 98 |
|
| 99 |
static struct ast_custom_function blacklist_function = { |
| 100 |
.name = "BLACKLIST", |
| 101 |
.read = blacklist_read, |
| 102 |
.read2 = blacklist_read2, |
| 103 |
}; |
| 104 |
|
| 105 |
static int unload_module(void) |
| 106 |
{ |
| 107 |
return ast_custom_function_unregister(&blacklist_function); |
| 108 |
} |
| 109 |
|
| 110 |
static int load_module(void) |
| 111 |
{ |
| 112 |
return ast_custom_function_register(&blacklist_function); |
| 113 |
} |
| 114 |
|
| 115 |
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Look up Caller*ID name/number from blacklist database"); |