Sun Aug 6 15:02:26 2006

Asterisk developer's documentation


Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

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  * \ingroup applications
00024  */
00025 
00026 #include <stdlib.h>
00027 #include <stdio.h>
00028 #include <string.h>
00029 #include <unistd.h>
00030 #include <sys/types.h>
00031 
00032 #include "asterisk.h"
00033 
00034 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 7221 $")
00035 
00036 #include "asterisk/file.h"
00037 #include "asterisk/logger.h"
00038 #include "asterisk/channel.h"
00039 #include "asterisk/pbx.h"
00040 #include "asterisk/module.h"
00041 #include "asterisk/lock.h"
00042 
00043 static char *synopsis = "Soft Hangup Application";
00044 
00045 static char *tdesc = "Hangs up the requested channel";
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 STANDARD_LOCAL_USER;
00056 
00057 LOCAL_USER_DECL;
00058 
00059 static int softhangup_exec(struct ast_channel *chan, void *data)
00060 {
00061    struct localuser *u;
00062    struct ast_channel *c=NULL;
00063    char *options, *cut, *cdata, *match;
00064    char name[AST_CHANNEL_NAME] = "";
00065    int all = 0;
00066    
00067    if (ast_strlen_zero(data)) {
00068                 ast_log(LOG_WARNING, "SoftHangup requires an argument (Technology/resource)\n");
00069       return 0;
00070    }
00071    
00072    LOCAL_USER_ADD(u);
00073 
00074    cdata = ast_strdupa(data);
00075    match = strsep(&cdata, "|");
00076    options = strsep(&cdata, "|");
00077    all = options && strchr(options,'a');
00078    c = ast_channel_walk_locked(NULL);
00079    while (c) {
00080       strncpy(name, c->name, sizeof(name)-1);
00081       ast_mutex_unlock(&c->lock);
00082       /* XXX watch out, i think it is wrong to access c-> after unlocking! */
00083       if (all) {
00084          /* CAPI is set up like CAPI[foo/bar]/clcnt */ 
00085          if (!strcmp(c->type,"CAPI")) 
00086             cut = strrchr(name,'/');
00087          /* Basically everything else is Foo/Bar-Z */
00088          else
00089             cut = strchr(name,'-');
00090          /* Get rid of what we've cut */
00091          if (cut)
00092             *cut = 0;
00093       }
00094       if (!strcasecmp(name, match)) {
00095          ast_log(LOG_WARNING, "Soft hanging %s up.\n",c->name);
00096          ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT);
00097          if(!all)
00098             break;
00099       }
00100       c = ast_channel_walk_locked(c);
00101    }
00102    
00103    LOCAL_USER_REMOVE(u);
00104 
00105    return 0;
00106 }
00107 
00108 int unload_module(void)
00109 {
00110    int res;
00111 
00112    res = ast_unregister_application(app);
00113 
00114    STANDARD_HANGUP_LOCALUSERS;
00115 
00116    return res; 
00117 }
00118 
00119 int load_module(void)
00120 {
00121    return ast_register_application(app, softhangup_exec, synopsis, desc);
00122 }
00123 
00124 char *description(void)
00125 {
00126    return tdesc;
00127 }
00128 
00129 int usecount(void)
00130 {
00131    int res;
00132    STANDARD_USECOUNT(res);
00133    return res;
00134 }
00135 
00136 char *key()
00137 {
00138    return ASTERISK_GPL_KEY;
00139 }

Generated on Sun Aug 6 15:02:26 2006 for Asterisk - the Open Source PBX by  doxygen 1.4.2