| 
									
										
										
										
											2003-02-21 06:00:08 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * Asterisk -- An open source telephony toolkit. | 
					
						
							| 
									
										
										
										
											2003-02-21 06:00:08 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * Copyright (C) 1999 - 2005, Digium, Inc. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Mark Spencer <markster@digium.com> | 
					
						
							| 
									
										
										
										
											2003-02-21 06:00:08 +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-02-21 06:00:08 +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 SoftHangup application | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2003-02-21 06:00:08 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-07 18:54:56 +00:00
										 |  |  | #include "asterisk.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ASTERISK_FILE_VERSION(__FILE__, "$Revision$") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-06 22:39:32 +00:00
										 |  |  | #include <stdlib.h>
 | 
					
						
							| 
									
										
										
										
											2005-11-08 04:48:00 +00:00
										 |  |  | #include <stdio.h>
 | 
					
						
							| 
									
										
										
										
											2005-06-06 22:39:32 +00:00
										 |  |  | #include <string.h>
 | 
					
						
							| 
									
										
										
										
											2005-11-08 04:48:00 +00:00
										 |  |  | #include <unistd.h>
 | 
					
						
							|  |  |  | #include <sys/types.h>
 | 
					
						
							| 
									
										
										
										
											2005-06-06 22:39:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-21 06:02:45 +00:00
										 |  |  | #include "asterisk/file.h"
 | 
					
						
							|  |  |  | #include "asterisk/logger.h"
 | 
					
						
							|  |  |  | #include "asterisk/channel.h"
 | 
					
						
							|  |  |  | #include "asterisk/pbx.h"
 | 
					
						
							|  |  |  | #include "asterisk/module.h"
 | 
					
						
							|  |  |  | #include "asterisk/lock.h"
 | 
					
						
							| 
									
										
										
										
											2007-07-23 19:51:41 +00:00
										 |  |  | #include "asterisk/app.h"
 | 
					
						
							| 
									
										
										
										
											2003-02-21 06:00:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static char *synopsis = "Soft Hangup Application"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-23 19:51:41 +00:00
										 |  |  | static char *desc = "SoftHangup(Technology/resource[,options])\n" | 
					
						
							| 
									
										
										
										
											2005-11-07 22:01:22 +00:00
										 |  |  | "Hangs up the requested channel.  If there are no channels to hangup,\n" | 
					
						
							|  |  |  | "the application will report it.\n" | 
					
						
							| 
									
										
										
										
											2005-01-12 15:55:52 +00:00
										 |  |  | "- 'options' may contain the following letter:\n" | 
					
						
							|  |  |  | "     'a' : hang up all channels on a specified device instead of a single resource\n"; | 
					
						
							| 
									
										
										
										
											2003-02-21 06:00:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static char *app = "SoftHangup"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-23 19:51:41 +00:00
										 |  |  | enum { | 
					
						
							|  |  |  | 	OPTION_ALL = (1 << 0), | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AST_APP_OPTIONS(app_opts,{ | 
					
						
							|  |  |  | 	AST_APP_OPTION('a', OPTION_ALL), | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2003-02-21 06:00:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static int softhangup_exec(struct ast_channel *chan, void *data) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2007-07-23 19:51:41 +00:00
										 |  |  | 	struct ast_channel *c = NULL; | 
					
						
							|  |  |  | 	char *cut, *opts[0]; | 
					
						
							|  |  |  | 	char name[AST_CHANNEL_NAME] = "", *parse; | 
					
						
							|  |  |  | 	struct ast_flags flags; | 
					
						
							|  |  |  | 	int lenmatch; | 
					
						
							|  |  |  | 	AST_DECLARE_APP_ARGS(args, | 
					
						
							|  |  |  | 		AST_APP_ARG(channel); | 
					
						
							|  |  |  | 		AST_APP_ARG(options); | 
					
						
							|  |  |  | 	); | 
					
						
							| 
									
										
										
										
											2005-10-19 18:19:02 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-10-26 19:48:14 +00:00
										 |  |  | 	if (ast_strlen_zero(data)) { | 
					
						
							| 
									
										
										
										
											2007-07-23 19:51:41 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "SoftHangup requires an argument (Technology/resource)\n"); | 
					
						
							| 
									
										
										
										
											2003-02-21 06:00:08 +00:00
										 |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-07-23 19:51:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	parse = ast_strdupa(data); | 
					
						
							|  |  |  | 	AST_STANDARD_APP_ARGS(args, parse); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (args.argc == 2) | 
					
						
							|  |  |  | 		ast_app_parse_options(app_opts, &flags, opts, args.options); | 
					
						
							|  |  |  | 	lenmatch = strlen(args.channel); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (c = ast_walk_channel_by_name_prefix_locked(NULL, args.channel, lenmatch); | 
					
						
							|  |  |  | 		 c; | 
					
						
							|  |  |  | 		 c = ast_walk_channel_by_name_prefix_locked(c, args.channel, lenmatch)) { | 
					
						
							| 
									
										
										
										
											2006-10-25 14:44:50 +00:00
										 |  |  | 		ast_copy_string(name, c->name, sizeof(name)); | 
					
						
							| 
									
										
										
										
											2007-07-23 19:51:41 +00:00
										 |  |  | 		if (ast_test_flag(&flags, OPTION_ALL)) { | 
					
						
							| 
									
										
										
										
											2005-01-12 15:55:52 +00:00
										 |  |  | 			/* CAPI is set up like CAPI[foo/bar]/clcnt */  | 
					
						
							| 
									
										
										
										
											2006-02-01 23:05:28 +00:00
										 |  |  | 			if (!strcmp(c->tech->type, "CAPI"))  | 
					
						
							| 
									
										
										
										
											2007-07-23 19:51:41 +00:00
										 |  |  | 				cut = strrchr(name, '/'); | 
					
						
							| 
									
										
										
										
											2005-01-12 15:55:52 +00:00
										 |  |  | 			/* Basically everything else is Foo/Bar-Z */ | 
					
						
							|  |  |  | 			else | 
					
						
							| 
									
										
										
										
											2007-07-23 19:51:41 +00:00
										 |  |  | 				cut = strchr(name, '-'); | 
					
						
							| 
									
										
										
										
											2005-01-12 15:55:52 +00:00
										 |  |  | 			/* Get rid of what we've cut */ | 
					
						
							|  |  |  | 			if (cut) | 
					
						
							|  |  |  | 				*cut = 0; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2007-07-23 19:51:41 +00:00
										 |  |  | 		if (!strcasecmp(name, args.channel)) { | 
					
						
							|  |  |  | 			ast_log(LOG_WARNING, "Soft hanging %s up.\n", c->name); | 
					
						
							| 
									
										
										
										
											2003-02-21 06:00:08 +00:00
										 |  |  | 			ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT); | 
					
						
							| 
									
										
										
										
											2007-07-23 19:51:41 +00:00
										 |  |  | 			if (!ast_test_flag(&flags, OPTION_ALL)) { | 
					
						
							|  |  |  | 				ast_mutex_unlock(&c->lock); | 
					
						
							| 
									
										
										
										
											2005-01-12 15:55:52 +00:00
										 |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2007-07-23 19:51:41 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2003-02-21 06:00:08 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2007-07-23 19:51:41 +00:00
										 |  |  | 		ast_mutex_unlock(&c->lock); | 
					
						
							| 
									
										
										
										
											2003-02-21 06:00:08 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int unload_module(void) | 
					
						
							| 
									
										
										
										
											2003-02-21 06:00:08 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-07-16 13:35:20 +00:00
										 |  |  | 	return ast_unregister_application(app); | 
					
						
							| 
									
										
										
										
											2003-02-21 06:00:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int load_module(void) | 
					
						
							| 
									
										
										
										
											2003-02-21 06:00:08 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	return ast_register_application(app, softhangup_exec, synopsis, desc); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Hangs up the requested channel"); |