Thu Oct 1 13:08:37 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: 46200 $")
00031 
00032 #include <stdlib.h>
00033 #include <stdio.h>
00034 #include <string.h>
00035 #include <unistd.h>
00036 #include <sys/types.h>
00037 
00038 #include "asterisk/file.h"
00039 #include "asterisk/logger.h"
00040 #include "asterisk/channel.h"
00041 #include "asterisk/pbx.h"
00042 #include "asterisk/module.h"
00043 #include "asterisk/lock.h"
00044 
00045 static char *synopsis = "Soft Hangup Application";
00046 
00047 static char *desc = "  SoftHangup(Technology/resource|options)\n"
00048 "Hangs up the requested channel.  If there are no channels to hangup,\n"
00049 "the application will report it.\n"
00050 "- 'options' may contain the following letter:\n"
00051 "     'a' : hang up all channels on a specified device instead of a single resource\n";
00052 
00053 static char *app = "SoftHangup";
00054 
00055 
00056 static int softhangup_exec(struct ast_channel *chan, void *data)
00057 {
00058    struct ast_module_user *u;
00059    struct ast_channel *c=NULL;
00060    char *options, *cut, *cdata, *match;
00061    char name[AST_CHANNEL_NAME] = "";
00062    int all = 0;
00063    
00064    if (ast_strlen_zero(data)) {
00065                 ast_log(LOG_WARNING, "SoftHangup requires an argument (Technology/resource)\n");
00066       return 0;
00067    }
00068    
00069    u = ast_module_user_add(chan);
00070 
00071    cdata = ast_strdupa(data);
00072    match = strsep(&cdata, "|");
00073    options = strsep(&cdata, "|");
00074    all = options && strchr(options,'a');
00075    c = ast_channel_walk_locked(NULL);
00076    while (c) {
00077       ast_copy_string(name, c->name, sizeof(name));
00078       ast_mutex_unlock(&c->lock);
00079       /* XXX watch out, i think it is wrong to access c-> after unlocking! */
00080       if (all) {
00081          /* CAPI is set up like CAPI[foo/bar]/clcnt */ 
00082          if (!strcmp(c->tech->type, "CAPI")) 
00083             cut = strrchr(name,'/');
00084          /* Basically everything else is Foo/Bar-Z */
00085          else
00086             cut = strchr(name,'-');
00087          /* Get rid of what we've cut */
00088          if (cut)
00089             *cut = 0;
00090       }
00091       if (!strcasecmp(name, match)) {
00092          ast_log(LOG_WARNING, "Soft hanging %s up.\n",c->name);
00093          ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT);
00094          if(!all)
00095             break;
00096       }
00097       c = ast_channel_walk_locked(c);
00098    }
00099    
00100    ast_module_user_remove(u);
00101 
00102    return 0;
00103 }
00104 
00105 static int unload_module(void)
00106 {
00107    int res;
00108 
00109    res = ast_unregister_application(app);
00110 
00111    ast_module_user_hangup_all();
00112 
00113    return res; 
00114 }
00115 
00116 static int load_module(void)
00117 {
00118    return ast_register_application(app, softhangup_exec, synopsis, desc);
00119 }
00120 
00121 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Hangs up the requested channel");

Generated on Thu Oct 1 13:08:37 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7