Thu May 24 14:21:34 2007

Asterisk developer's documentation


app_softhangup.c File Reference

SoftHangup application. More...

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include "asterisk.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"

Include dependency graph for app_softhangup.c:

Go to the source code of this file.

Functions

char * description (void)
 Provides a description of the module.
char * key ()
 Returns the ASTERISK_GPL_KEY.
int load_module (void)
 Initialize the module.
static int softhangup_exec (struct ast_channel *chan, void *data)
int unload_module (void)
 Cleanup all module structures, sockets, etc.
int usecount (void)
 Provides a usecount.

Variables

static char * app = "SoftHangup"
static char * desc
 LOCAL_USER_DECL
 STANDARD_LOCAL_USER
static char * synopsis = "Soft Hangup Application"
static char * tdesc = "Hangs up the requested channel"


Detailed Description

SoftHangup application.

Definition in file app_softhangup.c.


Function Documentation

char* description ( void   ) 

Provides a description of the module.

Returns:
a short description of your module

Definition at line 124 of file app_softhangup.c.

00125 {
00126    return tdesc;
00127 }

char* key ( void   ) 

Returns the ASTERISK_GPL_KEY.

This returns the ASTERISK_GPL_KEY, signifiying that you agree to the terms of the GPL stated in the ASTERISK_GPL_KEY. Your module will not load if it does not return the EXACT message:

 char *key(void) {
         return ASTERISK_GPL_KEY;
 }

Returns:
ASTERISK_GPL_KEY

Definition at line 136 of file app_softhangup.c.

References ASTERISK_GPL_KEY.

00137 {
00138    return ASTERISK_GPL_KEY;
00139 }

int load_module ( void   ) 

Initialize the module.

Initialize the Agents module. This function is being called by Asterisk when loading the module. Among other thing it registers applications, cli commands and reads the cofiguration file.

Returns:
int Always 0.

Definition at line 119 of file app_softhangup.c.

References ast_register_application(), and softhangup_exec().

00120 {
00121    return ast_register_application(app, softhangup_exec, synopsis, desc);
00122 }

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

Definition at line 59 of file app_softhangup.c.

References AST_CHANNEL_NAME, ast_channel_walk_locked(), ast_log(), ast_mutex_unlock(), ast_softhangup(), AST_SOFTHANGUP_EXPLICIT, ast_strdupa, ast_strlen_zero(), LOCAL_USER_ADD, LOCAL_USER_REMOVE, ast_channel::lock, LOG_WARNING, match(), ast_channel::name, name, strsep(), and ast_channel::type.

Referenced by load_module().

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 }

int unload_module ( void   ) 

Cleanup all module structures, sockets, etc.

This is called at exit. Any registrations and memory allocations need to be unregistered and free'd here. Nothing else will do these for you (until exit).

Returns:
Zero on success, or non-zero on error.

Definition at line 108 of file app_softhangup.c.

References ast_unregister_application(), and STANDARD_HANGUP_LOCALUSERS.

00109 {
00110    int res;
00111 
00112    res = ast_unregister_application(app);
00113 
00114    STANDARD_HANGUP_LOCALUSERS;
00115 
00116    return res; 
00117 }

int usecount ( void   ) 

Provides a usecount.

This function will be called by various parts of asterisk. Basically, all it has to do is to return a usecount when called. You will need to maintain your usecount within the module somewhere. The usecount should be how many channels provided by this module are in use.

Returns:
The module's usecount.

Definition at line 129 of file app_softhangup.c.

References STANDARD_USECOUNT.

00130 {
00131    int res;
00132    STANDARD_USECOUNT(res);
00133    return res;
00134 }


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.

LOCAL_USER_DECL

Definition at line 57 of file app_softhangup.c.

STANDARD_LOCAL_USER

Definition at line 55 of file app_softhangup.c.

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

Definition at line 43 of file app_softhangup.c.

char* tdesc = "Hangs up the requested channel" [static]

Definition at line 45 of file app_softhangup.c.


Generated on Thu May 24 14:21:35 2007 for Asterisk - the Open Source PBX by  doxygen 1.4.7