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"
|
2003-02-21 06:00:08 +00:00
|
|
|
|
|
|
|
static char *synopsis = "Soft Hangup Application";
|
|
|
|
|
2005-01-12 15:55:52 +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";
|
|
|
|
|
|
|
|
|
|
|
|
static int softhangup_exec(struct ast_channel *chan, void *data)
|
|
|
|
{
|
2006-08-21 02:11:39 +00:00
|
|
|
struct ast_module_user *u;
|
2003-02-21 06:00:08 +00:00
|
|
|
struct ast_channel *c=NULL;
|
2005-01-12 15:55:52 +00:00
|
|
|
char *options, *cut, *cdata, *match;
|
|
|
|
char name[AST_CHANNEL_NAME] = "";
|
|
|
|
int all = 0;
|
2005-10-19 18:19:02 +00:00
|
|
|
|
2005-10-26 19:48:14 +00:00
|
|
|
if (ast_strlen_zero(data)) {
|
2003-02-21 06:00:08 +00:00
|
|
|
ast_log(LOG_WARNING, "SoftHangup requires an argument (Technology/resource)\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2005-01-12 15:55:52 +00:00
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
u = ast_module_user_add(chan);
|
2005-10-19 18:19:02 +00:00
|
|
|
|
2005-01-12 15:55:52 +00:00
|
|
|
cdata = ast_strdupa(data);
|
|
|
|
match = strsep(&cdata, "|");
|
|
|
|
options = strsep(&cdata, "|");
|
|
|
|
all = options && strchr(options,'a');
|
2004-05-20 16:30:10 +00:00
|
|
|
c = ast_channel_walk_locked(NULL);
|
2003-02-21 06:00:08 +00:00
|
|
|
while (c) {
|
2005-01-12 15:55:52 +00:00
|
|
|
strncpy(name, c->name, sizeof(name)-1);
|
|
|
|
ast_mutex_unlock(&c->lock);
|
2005-06-06 02:29:18 +00:00
|
|
|
/* XXX watch out, i think it is wrong to access c-> after unlocking! */
|
2005-01-12 15:55:52 +00:00
|
|
|
if (all) {
|
|
|
|
/* CAPI is set up like CAPI[foo/bar]/clcnt */
|
2006-02-01 23:05:28 +00:00
|
|
|
if (!strcmp(c->tech->type, "CAPI"))
|
2005-01-12 15:55:52 +00:00
|
|
|
cut = strrchr(name,'/');
|
|
|
|
/* Basically everything else is Foo/Bar-Z */
|
|
|
|
else
|
|
|
|
cut = strchr(name,'-');
|
|
|
|
/* Get rid of what we've cut */
|
|
|
|
if (cut)
|
|
|
|
*cut = 0;
|
|
|
|
}
|
|
|
|
if (!strcasecmp(name, match)) {
|
|
|
|
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);
|
2005-01-12 15:55:52 +00:00
|
|
|
if(!all)
|
|
|
|
break;
|
2003-02-21 06:00:08 +00:00
|
|
|
}
|
2004-05-20 16:30:10 +00:00
|
|
|
c = ast_channel_walk_locked(c);
|
2003-02-21 06:00:08 +00:00
|
|
|
}
|
2005-10-19 18:19:02 +00:00
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
ast_module_user_remove(u);
|
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
|
|
|
{
|
2005-10-18 22:52:21 +00:00
|
|
|
int res;
|
|
|
|
|
|
|
|
res = ast_unregister_application(app);
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
ast_module_user_hangup_all();
|
2005-10-18 22:52:21 +00:00
|
|
|
|
|
|
|
return res;
|
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");
|