func_blacklist.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "asterisk.h"
00034
00035 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 411313 $")
00036
00037 #include "asterisk/pbx.h"
00038 #include "asterisk/module.h"
00039 #include "asterisk/channel.h"
00040 #include "asterisk/astdb.h"
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 static int blacklist_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
00060 {
00061 char blacklist[1];
00062 int bl = 0;
00063
00064 if (!chan) {
00065 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
00066 return -1;
00067 }
00068
00069 if (chan->caller.id.number.valid && chan->caller.id.number.str) {
00070 if (!ast_db_get("blacklist", chan->caller.id.number.str, blacklist, sizeof (blacklist)))
00071 bl = 1;
00072 }
00073 if (chan->caller.id.name.valid && chan->caller.id.name.str) {
00074 if (!ast_db_get("blacklist", chan->caller.id.name.str, blacklist, sizeof (blacklist)))
00075 bl = 1;
00076 }
00077
00078 snprintf(buf, len, "%d", bl);
00079 return 0;
00080 }
00081
00082 static int blacklist_read2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **str, ssize_t len)
00083 {
00084
00085 if (ast_str_size(*str) - ast_str_strlen(*str) < 2) {
00086 if (len > ast_str_size(*str) || len == 0) {
00087 ast_str_make_space(str, len ? len : ast_str_strlen(*str) + 2);
00088 }
00089 }
00090 if (ast_str_size(*str) - ast_str_strlen(*str) >= 2) {
00091 int res = blacklist_read(chan, cmd, data, ast_str_buffer(*str) + ast_str_strlen(*str), 2);
00092 ast_str_update(*str);
00093 return res;
00094 }
00095 return -1;
00096 }
00097
00098 static struct ast_custom_function blacklist_function = {
00099 .name = "BLACKLIST",
00100 .read = blacklist_read,
00101 .read2 = blacklist_read2,
00102 };
00103
00104 static int unload_module(void)
00105 {
00106 return ast_custom_function_unregister(&blacklist_function);
00107 }
00108
00109 static int load_module(void)
00110 {
00111 return ast_custom_function_register(&blacklist_function);
00112 }
00113
00114 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Look up Caller*ID name/number from blacklist database");