| 
									
										
										
										
											2006-09-21 19:35:29 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Asterisk -- An open source telephony toolkit. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (C) 1999 - 2005, Digium, Inc. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Mark Spencer <markster@digium.com> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * See http://www.asterisk.org for more information about
 | 
					
						
							|  |  |  |  * the Asterisk project. Please do not directly contact | 
					
						
							|  |  |  |  * any of the maintainers of this project for assistance; | 
					
						
							|  |  |  |  * the project provides a web site, mailing lists and IRC | 
					
						
							|  |  |  |  * channels for your use. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software, distributed under the terms of | 
					
						
							|  |  |  |  * the GNU General Public License Version 2. See the LICENSE file | 
					
						
							|  |  |  |  * at the top of the source tree. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*! \file
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \brief Function to lookup the callerid number, and see if it is blacklisted | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \author Mark Spencer <markster@digium.com> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \ingroup functions | 
					
						
							| 
									
										
										
										
											2017-12-22 09:23:22 -05:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2006-09-21 19:35:29 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-14 20:28:54 +00:00
										 |  |  | /*** MODULEINFO
 | 
					
						
							|  |  |  | 	<support_level>core</support_level> | 
					
						
							|  |  |  |  ***/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-09-21 19:35:29 +00:00
										 |  |  | #include "asterisk.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "asterisk/pbx.h"
 | 
					
						
							|  |  |  | #include "asterisk/module.h"
 | 
					
						
							| 
									
										
										
										
											2007-11-22 02:30:58 +00:00
										 |  |  | #include "asterisk/channel.h"
 | 
					
						
							| 
									
										
										
										
											2006-09-21 19:35:29 +00:00
										 |  |  | #include "asterisk/astdb.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-01 21:10:07 +00:00
										 |  |  | /*** DOCUMENTATION
 | 
					
						
							|  |  |  | 	<function name="BLACKLIST" language="en_US"> | 
					
						
							| 
									
										
										
										
											2025-01-23 16:35:58 -05:00
										 |  |  | 		<since> | 
					
						
							|  |  |  | 			<version>1.6.0</version> | 
					
						
							|  |  |  | 		</since> | 
					
						
							| 
									
										
										
										
											2008-11-01 21:10:07 +00:00
										 |  |  | 		<synopsis> | 
					
						
							|  |  |  | 			Check if the callerid is on the blacklist. | 
					
						
							|  |  |  | 		</synopsis> | 
					
						
							|  |  |  | 		<syntax /> | 
					
						
							|  |  |  | 		<description> | 
					
						
							|  |  |  | 			<para>Uses astdb to check if the Caller*ID is in family <literal>blacklist</literal>. | 
					
						
							|  |  |  | 			Returns <literal>1</literal> or <literal>0</literal>.</para> | 
					
						
							|  |  |  | 		</description> | 
					
						
							| 
									
										
										
										
											2008-11-05 12:13:57 +00:00
										 |  |  | 		<see-also> | 
					
						
							|  |  |  | 			<ref type="function">DB</ref> | 
					
						
							|  |  |  | 		</see-also> | 
					
						
							| 
									
										
										
										
											2008-11-01 21:10:07 +00:00
										 |  |  | 	</function> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ***/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-01-07 19:00:36 +00:00
										 |  |  | static int blacklist_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) | 
					
						
							| 
									
										
										
										
											2006-09-21 19:35:29 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	char blacklist[1]; | 
					
						
							|  |  |  | 	int bl = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-27 19:21:44 +00:00
										 |  |  | 	if (!chan) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-29 16:52:47 +00:00
										 |  |  | 	if (ast_channel_caller(chan)->id.number.valid && ast_channel_caller(chan)->id.number.str) { | 
					
						
							|  |  |  | 		if (!ast_db_get("blacklist", ast_channel_caller(chan)->id.number.str, blacklist, sizeof (blacklist))) | 
					
						
							| 
									
										
										
										
											2006-09-21 19:35:29 +00:00
										 |  |  | 			bl = 1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-29 16:52:47 +00:00
										 |  |  | 	if (ast_channel_caller(chan)->id.name.valid && ast_channel_caller(chan)->id.name.str) { | 
					
						
							|  |  |  | 		if (!ast_db_get("blacklist", ast_channel_caller(chan)->id.name.str, blacklist, sizeof (blacklist))) | 
					
						
							| 
									
										
										
										
											2006-09-21 19:35:29 +00:00
										 |  |  | 			bl = 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	snprintf(buf, len, "%d", bl); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-29 18:53:01 +00:00
										 |  |  | static int blacklist_read2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **str, ssize_t len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* 2 bytes is a single integer, plus terminating null */ | 
					
						
							|  |  |  | 	if (ast_str_size(*str) - ast_str_strlen(*str) < 2) { | 
					
						
							|  |  |  | 		if (len > ast_str_size(*str) || len == 0) { | 
					
						
							|  |  |  | 			ast_str_make_space(str, len ? len : ast_str_strlen(*str) + 2); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (ast_str_size(*str) - ast_str_strlen(*str) >= 2) { | 
					
						
							|  |  |  | 		int res = blacklist_read(chan, cmd, data, ast_str_buffer(*str) + ast_str_strlen(*str), 2); | 
					
						
							|  |  |  | 		ast_str_update(*str); | 
					
						
							|  |  |  | 		return res; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-09-21 19:35:29 +00:00
										 |  |  | static struct ast_custom_function blacklist_function = { | 
					
						
							|  |  |  | 	.name = "BLACKLIST", | 
					
						
							|  |  |  | 	.read = blacklist_read, | 
					
						
							| 
									
										
										
										
											2009-04-29 18:53:01 +00:00
										 |  |  | 	.read2 = blacklist_read2, | 
					
						
							| 
									
										
										
										
											2006-09-21 19:35:29 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int unload_module(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2007-07-16 13:35:20 +00:00
										 |  |  | 	return ast_custom_function_unregister(&blacklist_function); | 
					
						
							| 
									
										
										
										
											2006-09-21 19:35:29 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int load_module(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return ast_custom_function_register(&blacklist_function); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Look up Caller*ID name/number from blacklist database"); |