2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
21 * \brief SoftHangup application
23 * \author Mark Spencer <markster@digium.com>
25 * \ingroup applications
29 <support_level>core</support_level>
34 #include "asterisk/file.h"
35 #include "asterisk/channel.h"
36 #include "asterisk/pbx.h"
37 #include "asterisk/module.h"
38 #include "asterisk/lock.h"
39 #include "asterisk/app.h"
42 <application name="SoftHangup" language="en_US">
44 Hangs up the requested channel.
47 <parameter name="Technology/Resource" required="true" />
48 <parameter name="options">
51 <para>Hang up all channels on a specified device instead of a single resource</para>
57 <para>Hangs up the requested channel. If there are no channels to
58 hangup, the application will report it.</para>
64 static char *app = "SoftHangup";
67 OPTION_ALL = (1 << 0),
70 AST_APP_OPTIONS(app_opts,{
71 AST_APP_OPTION('a', OPTION_ALL),
74 static int softhangup_exec(struct ast_channel *chan, const char *data)
76 struct ast_channel *c = NULL;
78 char name[AST_CHANNEL_NAME] = "", *parse;
79 struct ast_flags flags = {0};
81 AST_DECLARE_APP_ARGS(args,
85 struct ast_channel_iterator *iter;
87 if (ast_strlen_zero(data)) {
88 ast_log(LOG_WARNING, "SoftHangup requires an argument (Technology/resource)\n");
92 parse = ast_strdupa(data);
93 AST_STANDARD_APP_ARGS(args, parse);
96 ast_app_parse_options(app_opts, &flags, opts, args.options);
97 lenmatch = strlen(args.channel);
99 if (!(iter = ast_channel_iterator_by_name_new(args.channel, lenmatch))) {
103 while ((c = ast_channel_iterator_next(iter))) {
105 ast_copy_string(name, ast_channel_name(c), sizeof(name));
106 if (ast_test_flag(&flags, OPTION_ALL)) {
107 /* CAPI is set up like CAPI[foo/bar]/clcnt */
108 if (!strcmp(ast_channel_tech(c)->type, "CAPI")) {
109 cut = strrchr(name, '/');
110 /* Basically everything else is Foo/Bar-Z */
112 /* use strrchr() because Foo/Bar-Z could actually be Foo/B-a-r-Z */
113 cut = strrchr(name,'-');
115 /* Get rid of what we've cut */
119 if (!strcasecmp(name, args.channel)) {
120 ast_log(LOG_WARNING, "Soft hanging %s up.\n", ast_channel_name(c));
121 ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT);
122 if (!ast_test_flag(&flags, OPTION_ALL)) {
123 ast_channel_unlock(c);
124 c = ast_channel_unref(c);
128 ast_channel_unlock(c);
129 c = ast_channel_unref(c);
132 ast_channel_iterator_destroy(iter);
137 static int unload_module(void)
139 return ast_unregister_application(app);
142 static int load_module(void)
144 return ast_register_application_xml(app, softhangup_exec);
147 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Hangs up the requested channel");