Fix a few things I missed to ensure zt_chan_conf structure is not modified in mkintf
[asterisk-bristuff.git] / apps / app_softhangup.c
blob018edc07d7066fbfa1d62d28d5cc6f284b8cef1e
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 <stdlib.h>
33 #include <stdio.h>
34 #include <string.h>
35 #include <unistd.h>
36 #include <sys/types.h>
38 #include "asterisk/file.h"
39 #include "asterisk/logger.h"
40 #include "asterisk/channel.h"
41 #include "asterisk/pbx.h"
42 #include "asterisk/module.h"
43 #include "asterisk/lock.h"
45 static char *synopsis = "Soft Hangup Application";
47 static char *desc = " SoftHangup(Technology/resource|options)\n"
48 "Hangs up the requested channel. If there are no channels to hangup,\n"
49 "the application will report it.\n"
50 "- 'options' may contain the following letter:\n"
51 " 'a' : hang up all channels on a specified device instead of a single resource\n";
53 static char *app = "SoftHangup";
56 static int softhangup_exec(struct ast_channel *chan, void *data)
58 struct ast_module_user *u;
59 struct ast_channel *c=NULL;
60 char *options, *cut, *cdata, *match;
61 char name[AST_CHANNEL_NAME] = "";
62 int all = 0;
64 if (ast_strlen_zero(data)) {
65 ast_log(LOG_WARNING, "SoftHangup requires an argument (Technology/resource)\n");
66 return 0;
69 u = ast_module_user_add(chan);
71 cdata = ast_strdupa(data);
72 match = strsep(&cdata, "|");
73 options = strsep(&cdata, "|");
74 all = options && strchr(options,'a');
75 c = ast_channel_walk_locked(NULL);
76 while (c) {
77 ast_copy_string(name, c->name, sizeof(name));
78 ast_mutex_unlock(&c->lock);
79 /* XXX watch out, i think it is wrong to access c-> after unlocking! */
80 if (all) {
81 /* CAPI is set up like CAPI[foo/bar]/clcnt */
82 if (!strcmp(c->tech->type, "CAPI"))
83 cut = strrchr(name,'/');
84 /* Basically everything else is Foo/Bar-Z */
85 else
86 cut = strchr(name,'-');
87 /* Get rid of what we've cut */
88 if (cut)
89 *cut = 0;
91 if (!strcasecmp(name, match)) {
92 ast_log(LOG_WARNING, "Soft hanging %s up.\n",c->name);
93 ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT);
94 if(!all)
95 break;
97 c = ast_channel_walk_locked(c);
100 ast_module_user_remove(u);
102 return 0;
105 static int unload_module(void)
107 int res;
109 res = ast_unregister_application(app);
111 ast_module_user_hangup_all();
113 return res;
116 static int load_module(void)
118 return ast_register_application(app, softhangup_exec, synopsis, desc);
121 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Hangs up the requested channel");