| 
									
										
										
										
											2003-01-17 03:46:33 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * Asterisk -- An open source telephony toolkit. | 
					
						
							| 
									
										
										
										
											2003-01-17 03:46:33 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * Copyright (C) 1999 - 2005, Digium, Inc. | 
					
						
							| 
									
										
										
										
											2003-01-17 03:46:33 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-07-10 22:56:21 +00:00
										 |  |  |  * Mark Spencer <markster@digium.com> | 
					
						
							| 
									
										
										
										
											2003-01-17 03:46:33 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * 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. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2003-01-17 03:46:33 +00:00
										 |  |  |  * This program is free software, distributed under the terms of | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * the GNU General Public License Version 2. See the LICENSE file | 
					
						
							|  |  |  |  * at the top of the source tree. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-24 20:12:06 +00:00
										 |  |  | /*! \file
 | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-10-24 20:12:06 +00:00
										 |  |  |  * \brief Privacy Routines | 
					
						
							| 
									
										
										
										
											2005-12-30 21:18:06 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-03-22 19:51:16 +00:00
										 |  |  |  * \author Mark Spencer <markster@digium.com> | 
					
						
							| 
									
										
										
										
											2003-01-17 03:46:33 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-15 16:20:16 +00:00
										 |  |  | /*** MODULEINFO
 | 
					
						
							|  |  |  | 	<support_level>core</support_level> | 
					
						
							|  |  |  |  ***/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-07 18:54:56 +00:00
										 |  |  | #include "asterisk.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-17 03:46:33 +00:00
										 |  |  | #include <sys/time.h>
 | 
					
						
							|  |  |  | #include <signal.h>
 | 
					
						
							|  |  |  | #include <dirent.h>
 | 
					
						
							| 
									
										
										
										
											2005-04-21 06:02:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "asterisk/channel.h"
 | 
					
						
							|  |  |  | #include "asterisk/file.h"
 | 
					
						
							|  |  |  | #include "asterisk/app.h"
 | 
					
						
							|  |  |  | #include "asterisk/dsp.h"
 | 
					
						
							|  |  |  | #include "asterisk/astdb.h"
 | 
					
						
							|  |  |  | #include "asterisk/callerid.h"
 | 
					
						
							|  |  |  | #include "asterisk/privacy.h"
 | 
					
						
							|  |  |  | #include "asterisk/utils.h"
 | 
					
						
							|  |  |  | #include "asterisk/lock.h"
 | 
					
						
							| 
									
										
										
										
											2003-01-17 03:46:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | int ast_privacy_check(char *dest, char *cid) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	char tmp[256] = ""; | 
					
						
							|  |  |  | 	char *trimcid = ""; | 
					
						
							|  |  |  | 	char *n, *l; | 
					
						
							|  |  |  | 	int res; | 
					
						
							|  |  |  | 	char key[256], result[256]; | 
					
						
							|  |  |  | 	if (cid) | 
					
						
							| 
									
										
										
										
											2005-07-10 22:56:21 +00:00
										 |  |  | 		ast_copy_string(tmp, cid, sizeof(tmp)); | 
					
						
							| 
									
										
										
										
											2003-01-17 03:46:33 +00:00
										 |  |  | 	ast_callerid_parse(tmp, &n, &l); | 
					
						
							|  |  |  | 	if (l) { | 
					
						
							|  |  |  | 		ast_shrink_phone_number(l); | 
					
						
							|  |  |  | 		trimcid = l; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	snprintf(key, sizeof(key), "%s/%s", dest, trimcid); | 
					
						
							|  |  |  | 	res = ast_db_get("privacy", key, result, sizeof(result)); | 
					
						
							|  |  |  | 	if (!res) { | 
					
						
							|  |  |  | 		if (!strcasecmp(result, "allow")) | 
					
						
							|  |  |  | 			return AST_PRIVACY_ALLOW; | 
					
						
							|  |  |  | 		if (!strcasecmp(result, "deny")) | 
					
						
							|  |  |  | 			return AST_PRIVACY_DENY; | 
					
						
							|  |  |  | 		if (!strcasecmp(result, "kill")) | 
					
						
							|  |  |  | 			return AST_PRIVACY_KILL; | 
					
						
							|  |  |  | 		if (!strcasecmp(result, "torture")) | 
					
						
							|  |  |  | 			return AST_PRIVACY_TORTURE; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return AST_PRIVACY_UNKNOWN; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int ast_privacy_reset(char *dest) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (!dest) | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	return ast_db_deltree("privacy", dest); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int ast_privacy_set(char *dest, char *cid, int status) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	char tmp[256] = ""; | 
					
						
							|  |  |  | 	char *trimcid = ""; | 
					
						
							|  |  |  | 	char *n, *l; | 
					
						
							|  |  |  | 	int res; | 
					
						
							|  |  |  | 	char key[256]; | 
					
						
							|  |  |  | 	if (cid) | 
					
						
							| 
									
										
										
										
											2005-07-10 22:56:21 +00:00
										 |  |  | 		ast_copy_string(tmp, cid, sizeof(tmp)); | 
					
						
							| 
									
										
										
										
											2003-01-17 03:46:33 +00:00
										 |  |  | 	ast_callerid_parse(tmp, &n, &l); | 
					
						
							|  |  |  | 	if (l) { | 
					
						
							|  |  |  | 		ast_shrink_phone_number(l); | 
					
						
							|  |  |  | 		trimcid = l; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2004-05-28 19:20:29 +00:00
										 |  |  | 	if (ast_strlen_zero(trimcid)) { | 
					
						
							| 
									
										
										
										
											2003-01-17 03:46:33 +00:00
										 |  |  | 		/* Don't store anything for empty Caller*ID */ | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	snprintf(key, sizeof(key), "%s/%s", dest, trimcid); | 
					
						
							| 
									
										
										
										
											2012-03-22 19:51:16 +00:00
										 |  |  | 	if (status == AST_PRIVACY_UNKNOWN) | 
					
						
							| 
									
										
										
										
											2003-01-17 03:46:33 +00:00
										 |  |  | 		res = ast_db_del("privacy", key); | 
					
						
							|  |  |  | 	else if (status == AST_PRIVACY_ALLOW) | 
					
						
							|  |  |  | 		res = ast_db_put("privacy", key, "allow"); | 
					
						
							|  |  |  | 	else if (status == AST_PRIVACY_DENY) | 
					
						
							|  |  |  | 		res = ast_db_put("privacy", key, "deny"); | 
					
						
							|  |  |  | 	else if (status == AST_PRIVACY_KILL) | 
					
						
							|  |  |  | 		res = ast_db_put("privacy", key, "kill"); | 
					
						
							|  |  |  | 	else if (status == AST_PRIVACY_TORTURE) | 
					
						
							|  |  |  | 		res = ast_db_put("privacy", key, "torture"); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		res = -1; | 
					
						
							|  |  |  | 	return res; | 
					
						
							|  |  |  | } |