Optionally display the value of several variables within the Status command.
[asterisk-bristuff.git] / apps / app_softhangup.c
blob7af8525604cbc9a343c7cd2c909785480ba36e89
1 /*
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.
19 /*! \file
21 * \brief SoftHangup application
23 * \author Mark Spencer <markster@digium.com>
25 * \ingroup applications
28 #include "asterisk.h"
30 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
32 #include "asterisk/file.h"
33 #include "asterisk/channel.h"
34 #include "asterisk/pbx.h"
35 #include "asterisk/module.h"
36 #include "asterisk/lock.h"
37 #include "asterisk/app.h"
39 static char *synopsis = "Soft Hangup Application";
41 static char *desc = " SoftHangup(Technology/resource[,options]):\n"
42 "Hangs up the requested channel. If there are no channels to hangup,\n"
43 "the application will report it.\n"
44 " Options:\n"
45 " 'a' - hang up all channels on a specified device instead of a single resource\n";
47 static char *app = "SoftHangup";
49 enum {
50 OPTION_ALL = (1 << 0),
53 AST_APP_OPTIONS(app_opts,{
54 AST_APP_OPTION('a', OPTION_ALL),
55 });
57 static int softhangup_exec(struct ast_channel *chan, void *data)
59 struct ast_channel *c = NULL;
60 char *cut, *opts[0];
61 char name[AST_CHANNEL_NAME] = "", *parse;
62 struct ast_flags flags;
63 int lenmatch;
64 AST_DECLARE_APP_ARGS(args,
65 AST_APP_ARG(channel);
66 AST_APP_ARG(options);
69 if (ast_strlen_zero(data)) {
70 ast_log(LOG_WARNING, "SoftHangup requires an argument (Technology/resource)\n");
71 return 0;
74 parse = ast_strdupa(data);
75 AST_STANDARD_APP_ARGS(args, parse);
77 if (args.argc == 2)
78 ast_app_parse_options(app_opts, &flags, opts, args.options);
79 lenmatch = strlen(args.channel);
81 for (c = ast_walk_channel_by_name_prefix_locked(NULL, args.channel, lenmatch);
83 c = ast_walk_channel_by_name_prefix_locked(c, args.channel, lenmatch)) {
84 ast_copy_string(name, c->name, sizeof(name));
85 if (ast_test_flag(&flags, OPTION_ALL)) {
86 /* CAPI is set up like CAPI[foo/bar]/clcnt */
87 if (!strcmp(c->tech->type, "CAPI"))
88 cut = strrchr(name, '/');
89 /* Basically everything else is Foo/Bar-Z */
90 else
91 cut = strchr(name, '-');
92 /* Get rid of what we've cut */
93 if (cut)
94 *cut = 0;
96 if (!strcasecmp(name, args.channel)) {
97 ast_log(LOG_WARNING, "Soft hanging %s up.\n", c->name);
98 ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT);
99 if (!ast_test_flag(&flags, OPTION_ALL)) {
100 ast_channel_unlock(c);
101 break;
104 ast_channel_unlock(c);
107 return 0;
110 static int unload_module(void)
112 return ast_unregister_application(app);
115 static int load_module(void)
117 return ast_register_application(app, softhangup_exec, synopsis, desc);
120 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Hangs up the requested channel");