Tue Nov 4 13:20:25 2008

Asterisk developer's documentation


app_softhangup.c File Reference

SoftHangup application. More...

#include "asterisk.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/lock.h"

Go to the source code of this file.

Functions

 AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Hangs up the requested channel")
static int load_module (void)
static int softhangup_exec (struct ast_channel *chan, void *data)
static int unload_module (void)

Variables

static char * app = "SoftHangup"
static char * desc
static char * synopsis = "Soft Hangup Application"


Detailed Description

SoftHangup application.

Author:
Mark Spencer <markster@digium.com>

Definition in file app_softhangup.c.


Function Documentation

AST_MODULE_INFO_STANDARD ( ASTERISK_GPL_KEY  ,
"Hangs up the requested channel"   
)

static int load_module ( void   )  [static]

Definition at line 116 of file app_softhangup.c.

References ast_register_application(), and softhangup_exec().

00117 {
00118    return ast_register_application(app, softhangup_exec, synopsis, desc);
00119 }

static int softhangup_exec ( struct ast_channel chan,
void *  data 
) [static]

Definition at line 56 of file app_softhangup.c.

References AST_CHANNEL_NAME, ast_channel_walk_locked(), ast_log(), ast_module_user_add, ast_module_user_remove, ast_mutex_unlock(), ast_softhangup(), AST_SOFTHANGUP_EXPLICIT, ast_strdupa, ast_strlen_zero(), ast_channel::lock, LOG_WARNING, match(), name, strsep(), ast_channel::tech, and ast_channel_tech::type.

Referenced by load_module().

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 }

static int unload_module ( void   )  [static]

Definition at line 105 of file app_softhangup.c.

References ast_module_user_hangup_all, and ast_unregister_application().

00106 {
00107    int res;
00108 
00109    res = ast_unregister_application(app);
00110 
00111    ast_module_user_hangup_all();
00112 
00113    return res; 
00114 }


Variable Documentation

char* app = "SoftHangup" [static]

Definition at line 53 of file app_softhangup.c.

char* desc [static]

Initial value:

 "  SoftHangup(Technology/resource|options)\n"
"Hangs up the requested channel.  If there are no channels to hangup,\n"
"the application will report it.\n"
"- 'options' may contain the following letter:\n"
"     'a' : hang up all channels on a specified device instead of a single resource\n"

Definition at line 47 of file app_softhangup.c.

char* synopsis = "Soft Hangup Application" [static]

Definition at line 45 of file app_softhangup.c.


Generated on Tue Nov 4 13:20:25 2008 for Asterisk - the Open Source PBX by  doxygen 1.4.7