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
30 ASTERISK_FILE_VERSION(__FILE__
, "$Revision$")
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
] = "";
64 if (ast_strlen_zero(data
)) {
65 ast_log(LOG_WARNING
, "SoftHangup requires an argument (Technology/resource)\n");
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
);
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! */
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 */
86 cut
= strchr(name
,'-');
87 /* Get rid of what we've cut */
91 if (!strcasecmp(name
, match
)) {
92 ast_log(LOG_WARNING
, "Soft hanging %s up.\n",c
->name
);
93 ast_softhangup(c
, AST_SOFTHANGUP_EXPLICIT
);
97 c
= ast_channel_walk_locked(c
);
100 ast_module_user_remove(u
);
105 static int unload_module(void)
109 res
= ast_unregister_application(app
);
111 ast_module_user_hangup_all();
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");