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 /*** MODULEINFO
00029    <support_level>core</support_level>
00030  ***/
00031 
00032 #include "asterisk.h"
00033 
00034 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 356042 $")
00035 
00036 #include "asterisk/file.h"
00037 #include "asterisk/channel.h"
00038 #include "asterisk/pbx.h"
00039 #include "asterisk/module.h"
00040 #include "asterisk/lock.h"
00041 #include "asterisk/app.h"
00042 
00043 /*** DOCUMENTATION
00044    <application name="SoftHangup" language="en_US">
00045       <synopsis>
00046          Hangs up the requested channel.
00047       </synopsis>
00048       <syntax>
00049          <parameter name="Technology/Resource" required="true" />
00050          <parameter name="options">
00051             <optionlist>
00052                <option name="a">
00053                   <para>Hang up all channels on a specified device instead of a single resource</para>
00054                </option>
00055             </optionlist>
00056          </parameter>
00057       </syntax>   
00058       <description>
00059          <para>Hangs up the requested channel.  If there are no channels to 
00060          hangup, the application will report it.</para>
00061       </description>
00062    </application>
00063 
00064  ***/
00065 
00066 static char *app = "SoftHangup";
00067 
00068 enum {
00069    OPTION_ALL = (1 << 0),
00070 };
00071 
00072 AST_APP_OPTIONS(app_opts,{
00073    AST_APP_OPTION('a', OPTION_ALL),
00074 });
00075 
00076 static int softhangup_exec(struct ast_channel *chan, const char *data)
00077 {
00078    struct ast_channel *c = NULL;
00079    char *cut, *opts[0];
00080    char name[AST_CHANNEL_NAME] = "", *parse;
00081    struct ast_flags flags = {0};
00082    int lenmatch;
00083    AST_DECLARE_APP_ARGS(args,
00084       AST_APP_ARG(channel);
00085       AST_APP_ARG(options);
00086    );
00087    struct ast_channel_iterator *iter;
00088    
00089    if (ast_strlen_zero(data)) {
00090       ast_log(LOG_WARNING, "SoftHangup requires an argument (Technology/resource)\n");
00091       return 0;
00092    }
00093 
00094    parse = ast_strdupa(data);
00095    AST_STANDARD_APP_ARGS(args, parse);
00096 
00097    if (args.argc == 2)
00098       ast_app_parse_options(app_opts, &flags, opts, args.options);
00099    lenmatch = strlen(args.channel);
00100 
00101    if (!(iter = ast_channel_iterator_by_name_new(args.channel, lenmatch))) {
00102       return -1;
00103    }
00104 
00105    while ((c = ast_channel_iterator_next(iter))) {
00106       ast_channel_lock(c);
00107       ast_copy_string(name, ast_channel_name(c), sizeof(name));
00108       if (ast_test_flag(&flags, OPTION_ALL)) {
00109          /* CAPI is set up like CAPI[foo/bar]/clcnt */ 
00110          if (!strcmp(ast_channel_tech(c)->type, "CAPI")) {
00111             cut = strrchr(name, '/');
00112          /* Basically everything else is Foo/Bar-Z */
00113          } else {
00114             /* use strrchr() because Foo/Bar-Z could actually be Foo/B-a-r-Z */
00115             cut = strrchr(name,'-');
00116          }
00117          /* Get rid of what we've cut */
00118          if (cut)
00119             *cut = 0;
00120       }
00121       if (!strcasecmp(name, args.channel)) {
00122          ast_log(LOG_WARNING, "Soft hanging %s up.\n", ast_channel_name(c));
00123          ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT);
00124          if (!ast_test_flag(&flags, OPTION_ALL)) {
00125             ast_channel_unlock(c);
00126             c = ast_channel_unref(c);
00127             break;
00128          }
00129       }
00130       ast_channel_unlock(c);
00131       c = ast_channel_unref(c);
00132    }
00133 
00134    ast_channel_iterator_destroy(iter);
00135 
00136    return 0;
00137 }
00138 
00139 static int unload_module(void)
00140 {
00141    return ast_unregister_application(app);
00142 }
00143 
00144 static int load_module(void)
00145 {
00146    return ast_register_application_xml(app, softhangup_exec);
00147 }
00148 
00149 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Hangs up the requested channel");

Generated on Thu Apr 16 06:27:12 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6