Fri Jun 19 12:09:29 2009

Asterisk developer's documentation


app_softhangup.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  *
00021  * \brief SoftHangup application
00022  *
00023  * \author Mark Spencer <markster@digium.com>
00024  * 
00025  * \ingroup applications
00026  */
00027 
00028 #include "asterisk.h"
00029 
00030 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 89424 $")
00031 
00032 #include "asterisk/file.h"
00033 #include "asterisk/channel.h"
00034 #include "asterisk/pbx.h"
00035 #include "asterisk/module.h"
00036 #include "asterisk/lock.h"
00037 #include "asterisk/app.h"
00038 
00039 static char *synopsis = "Soft Hangup Application";
00040 
00041 static char *desc = "  SoftHangup(Technology/resource[,options]):\n"
00042 "Hangs up the requested channel.  If there are no channels to hangup,\n"
00043 "the application will report it.\n"
00044 "  Options:\n"
00045 "     'a'  - hang up all channels on a specified device instead of a single resource\n";
00046 
00047 static char *app = "SoftHangup";
00048 
00049 enum {
00050    OPTION_ALL = (1 << 0),
00051 };
00052 
00053 AST_APP_OPTIONS(app_opts,{
00054    AST_APP_OPTION('a', OPTION_ALL),
00055 });
00056 
00057 static int softhangup_exec(struct ast_channel *chan, void *data)
00058 {
00059    struct ast_channel *c = NULL;
00060    char *cut, *opts[0];
00061    char name[AST_CHANNEL_NAME] = "", *parse;
00062    struct ast_flags flags;
00063    int lenmatch;
00064    AST_DECLARE_APP_ARGS(args,
00065       AST_APP_ARG(channel);
00066       AST_APP_ARG(options);
00067    );
00068    
00069    if (ast_strlen_zero(data)) {
00070       ast_log(LOG_WARNING, "SoftHangup requires an argument (Technology/resource)\n");
00071       return 0;
00072    }
00073 
00074    parse = ast_strdupa(data);
00075    AST_STANDARD_APP_ARGS(args, parse);
00076 
00077    if (args.argc == 2)
00078       ast_app_parse_options(app_opts, &flags, opts, args.options);
00079    lenmatch = strlen(args.channel);
00080 
00081    for (c = ast_walk_channel_by_name_prefix_locked(NULL, args.channel, lenmatch);
00082        c;
00083        c = ast_walk_channel_by_name_prefix_locked(c, args.channel, lenmatch)) {
00084       ast_copy_string(name, c->name, sizeof(name));
00085       if (ast_test_flag(&flags, OPTION_ALL)) {
00086          /* CAPI is set up like CAPI[foo/bar]/clcnt */ 
00087          if (!strcmp(c->tech->type, "CAPI")) 
00088             cut = strrchr(name, '/');
00089          /* Basically everything else is Foo/Bar-Z */
00090          else
00091             cut = strchr(name, '-');
00092          /* Get rid of what we've cut */
00093          if (cut)
00094             *cut = 0;
00095       }
00096       if (!strcasecmp(name, args.channel)) {
00097          ast_log(LOG_WARNING, "Soft hanging %s up.\n", c->name);
00098          ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT);
00099          if (!ast_test_flag(&flags, OPTION_ALL)) {
00100             ast_channel_unlock(c);
00101             break;
00102          }
00103       }
00104       ast_channel_unlock(c);
00105    }
00106 
00107    return 0;
00108 }
00109 
00110 static int unload_module(void)
00111 {
00112    return ast_unregister_application(app);
00113 }
00114 
00115 static int load_module(void)
00116 {
00117    return ast_register_application(app, softhangup_exec, synopsis, desc);
00118 }
00119 
00120 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Hangs up the requested channel");

Generated on Fri Jun 19 12:09:29 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7