Fri Sep 29 11:12:58 2006

Asterisk developer's documentation


app_transfer.c File Reference

Transfer a caller. More...

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

Include dependency graph for app_transfer.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 transfer_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 const char * app = "Transfer"
static const char * descrip
 LOCAL_USER_DECL
 STANDARD_LOCAL_USER
static const char * synopsis = "Transfer caller to remote extension"
static const char * tdesc = "Transfer"


Detailed Description

Transfer a caller.

Requires transfer support from channel driver

Definition in file app_transfer.c.


Function Documentation

char* description ( void   ) 

Provides a description of the module.

Returns:
a short description of your module

Definition at line 165 of file app_transfer.c.

00166 {
00167    return (char *) tdesc;
00168 }

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 179 of file app_transfer.c.

References ASTERISK_GPL_KEY.

00180 {
00181    return ASTERISK_GPL_KEY;
00182 }

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 160 of file app_transfer.c.

References ast_register_application(), and transfer_exec().

00161 {
00162    return ast_register_application(app, transfer_exec, synopsis, descrip);
00163 }

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

Definition at line 71 of file app_transfer.c.

References AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_goto_if_exists(), ast_log(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_transfer(), localuser::chan, ast_channel::context, LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_ERROR, LOG_WARNING, option_priority_jumping, parse(), pbx_builtin_setvar_helper(), ast_channel::tech, ast_channel_tech::transfer, and ast_channel::type.

Referenced by load_module().

00072 {
00073    int res;
00074    int len;
00075    struct localuser *u;
00076    char *slash;
00077    char *tech = NULL;
00078    char *dest = NULL;
00079    char *status;
00080    char *parse;
00081    int priority_jump = 0;
00082    AST_DECLARE_APP_ARGS(args,
00083       AST_APP_ARG(dest);
00084       AST_APP_ARG(options);
00085    );
00086 
00087    LOCAL_USER_ADD(u);
00088 
00089    if (ast_strlen_zero((char *)data)) {
00090       ast_log(LOG_WARNING, "Transfer requires an argument ([Tech/]destination[|options])\n");
00091       LOCAL_USER_REMOVE(u);
00092       pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "FAILURE");
00093       return 0;
00094    } else {
00095       parse = ast_strdupa(data);
00096       if (!parse) {
00097          ast_log(LOG_ERROR, "Out of memory!\n");
00098          LOCAL_USER_REMOVE(u);
00099          return -1;
00100       }
00101    }
00102 
00103    AST_STANDARD_APP_ARGS(args, parse);
00104 
00105    if (args.options) {
00106       if (strchr(args.options, 'j'))
00107          priority_jump = 1;
00108    }
00109 
00110    dest = args.dest;
00111 
00112    if ((slash = strchr(dest, '/')) && (len = (slash - dest))) {
00113       tech = dest;
00114       dest = slash + 1;
00115       /* Allow execution only if the Tech/destination agrees with the type of the channel */
00116       if (strncasecmp(chan->type, tech, len)) {
00117          pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "FAILURE");
00118          LOCAL_USER_REMOVE(u);
00119          return 0;
00120       }
00121    }
00122 
00123    /* Check if the channel supports transfer before we try it */
00124    if (!chan->tech->transfer) {
00125       pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "UNSUPPORTED");
00126       LOCAL_USER_REMOVE(u);
00127       return 0;
00128    }
00129 
00130    res = ast_transfer(chan, dest);
00131 
00132    if (res < 0) {
00133       status = "FAILURE";
00134       if (priority_jump || option_priority_jumping)
00135          ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
00136       res = 0;
00137    } else {
00138       status = "SUCCESS";
00139       res = 0;
00140    }
00141 
00142    pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", status);
00143 
00144    LOCAL_USER_REMOVE(u);
00145 
00146    return res;
00147 }

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 149 of file app_transfer.c.

References ast_unregister_application(), and STANDARD_HANGUP_LOCALUSERS.

00150 {
00151    int res;
00152 
00153    res = ast_unregister_application(app);
00154 
00155    STANDARD_HANGUP_LOCALUSERS;
00156 
00157    return res; 
00158 }

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 170 of file app_transfer.c.

References STANDARD_USECOUNT.

00171 {
00172    int res;
00173 
00174    STANDARD_USECOUNT(res);
00175 
00176    return res;
00177 }


Variable Documentation

const char* app = "Transfer" [static]

Definition at line 52 of file app_transfer.c.

const char* descrip [static]

Definition at line 56 of file app_transfer.c.

LOCAL_USER_DECL

Definition at line 48 of file app_transfer.c.

STANDARD_LOCAL_USER

Definition at line 46 of file app_transfer.c.

const char* synopsis = "Transfer caller to remote extension" [static]

Definition at line 54 of file app_transfer.c.

const char* tdesc = "Transfer" [static]

Definition at line 50 of file app_transfer.c.


Generated on Fri Sep 29 11:12:59 2006 for Asterisk - the Open Source PBX by  doxygen 1.4.7