| 
									
										
										
										
											2002-06-20 16:46:34 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * Asterisk -- An open source telephony toolkit. | 
					
						
							| 
									
										
										
										
											2002-06-20 16:46:34 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-01-21 07:06:25 +00:00
										 |  |  |  * Copyright (C) 1999 - 2005, Digium, Inc. | 
					
						
							| 
									
										
										
										
											2002-06-20 16:46:34 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2004-10-02 00:58:31 +00:00
										 |  |  |  * Mark Spencer <markster@digium.com> | 
					
						
							| 
									
										
										
										
											2002-06-20 16:46:34 +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. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2002-06-20 16:46:34 +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 Playback the special information tone to get rid of telemarketers | 
					
						
							| 
									
										
										
										
											2005-12-30 21:18:06 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * \author Mark Spencer <markster@digium.com> | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  *  | 
					
						
							| 
									
										
										
										
											2005-11-06 15:09:47 +00:00
										 |  |  |  * \ingroup applications | 
					
						
							| 
									
										
										
										
											2002-06-20 16:46:34 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  |   | 
					
						
							| 
									
										
										
										
											2005-06-06 22:39:32 +00:00
										 |  |  | #include "asterisk.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ASTERISK_FILE_VERSION(__FILE__, "$Revision$") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-07 18:54:56 +00:00
										 |  |  | #include <stdlib.h>
 | 
					
						
							|  |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-21 06:02:45 +00:00
										 |  |  | #include "asterisk/lock.h"
 | 
					
						
							|  |  |  | #include "asterisk/file.h"
 | 
					
						
							|  |  |  | #include "asterisk/logger.h"
 | 
					
						
							|  |  |  | #include "asterisk/channel.h"
 | 
					
						
							|  |  |  | #include "asterisk/pbx.h"
 | 
					
						
							|  |  |  | #include "asterisk/module.h"
 | 
					
						
							|  |  |  | #include "asterisk/translate.h"
 | 
					
						
							| 
									
										
										
										
											2002-06-20 16:46:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static char *app = "Zapateller"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char *synopsis = "Block telemarketers with SIT"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char *descrip =  | 
					
						
							| 
									
										
										
										
											2003-03-31 03:19:34 +00:00
										 |  |  | "  Zapateller(options):  Generates special information tone to block\n" | 
					
						
							| 
									
										
										
										
											2005-11-07 22:01:22 +00:00
										 |  |  | "telemarketers from calling you.  Options is a pipe-delimited list of\n"  | 
					
						
							|  |  |  | "options.  The following options are available:\n" | 
					
						
							|  |  |  | "'answer' causes the line to be answered before playing the tone,\n"  | 
					
						
							|  |  |  | "'nocallerid' causes Zapateller to only play the tone if there\n" | 
					
						
							| 
									
										
										
										
											2003-03-31 03:19:34 +00:00
										 |  |  | "is no callerid information available.  Options should be separated by |\n" | 
					
						
							|  |  |  | "characters\n"; | 
					
						
							| 
									
										
										
										
											2002-06-20 16:46:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int zapateller_exec(struct ast_channel *chan, void *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int res = 0; | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | 	struct ast_module_user *u; | 
					
						
							| 
									
										
										
										
											2002-12-02 02:44:16 +00:00
										 |  |  | 	int answer = 0, nocallerid = 0; | 
					
						
							|  |  |  | 	char *c; | 
					
						
							|  |  |  | 	char *stringp=NULL; | 
					
						
							| 
									
										
										
										
											2002-06-20 16:46:34 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | 	u = ast_module_user_add(chan); | 
					
						
							| 
									
										
										
										
											2002-12-02 02:44:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	stringp=data; | 
					
						
							|  |  |  |         c = strsep(&stringp, "|"); | 
					
						
							| 
									
										
										
										
											2005-10-26 19:48:14 +00:00
										 |  |  |         while(!ast_strlen_zero(c)) { | 
					
						
							| 
									
										
										
										
											2002-12-02 02:44:16 +00:00
										 |  |  | 		if (!strcasecmp(c, "answer")) | 
					
						
							|  |  |  | 			answer = 1; | 
					
						
							|  |  |  | 		else if (!strcasecmp(c, "nocallerid")) | 
					
						
							|  |  |  | 			nocallerid = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 c = strsep(&stringp, "|"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-20 16:46:34 +00:00
										 |  |  | 	ast_stopstream(chan); | 
					
						
							| 
									
										
										
										
											2002-07-12 09:03:50 +00:00
										 |  |  | 	if (chan->_state != AST_STATE_UP) { | 
					
						
							| 
									
										
										
										
											2002-12-02 02:44:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (answer)  | 
					
						
							| 
									
										
										
										
											2002-06-20 16:46:34 +00:00
										 |  |  | 			res = ast_answer(chan); | 
					
						
							|  |  |  | 		if (!res) { | 
					
						
							|  |  |  | 			res = ast_safe_sleep(chan, 500); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2004-10-02 00:58:31 +00:00
										 |  |  | 	if (chan->cid.cid_num && nocallerid) { | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | 		ast_module_user_remove(u); | 
					
						
							| 
									
										
										
										
											2002-12-02 02:44:16 +00:00
										 |  |  | 		return res; | 
					
						
							|  |  |  | 	}  | 
					
						
							| 
									
										
										
										
											2002-06-20 16:46:34 +00:00
										 |  |  | 	if (!res)  | 
					
						
							|  |  |  | 		res = ast_tonepair(chan, 950, 0, 330, 0); | 
					
						
							|  |  |  | 	if (!res)  | 
					
						
							|  |  |  | 		res = ast_tonepair(chan, 1400, 0, 330, 0); | 
					
						
							|  |  |  | 	if (!res)  | 
					
						
							|  |  |  | 		res = ast_tonepair(chan, 1800, 0, 330, 0); | 
					
						
							| 
									
										
										
										
											2002-12-02 02:44:16 +00:00
										 |  |  | 	if (!res)  | 
					
						
							|  |  |  | 		res = ast_tonepair(chan, 0, 0, 1000, 0); | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | 	ast_module_user_remove(u); | 
					
						
							| 
									
										
										
										
											2002-06-20 16:46:34 +00:00
										 |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int unload_module(void) | 
					
						
							| 
									
										
										
										
											2002-06-20 16:46:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-10-18 22:52:21 +00:00
										 |  |  | 	int res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	res = ast_unregister_application(app); | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | 	ast_module_user_hangup_all(); | 
					
						
							| 
									
										
										
										
											2005-10-18 22:52:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return res;	 | 
					
						
							| 
									
										
										
										
											2002-06-20 16:46:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int load_module(void) | 
					
						
							| 
									
										
										
										
											2002-06-20 16:46:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	return ast_register_application(app, zapateller_exec, synopsis, descrip); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Block Telemarketers with Special Information Tone"); |