Wed Oct 28 15:49:11 2009

Asterisk developer's documentation


pbx_loopback.c File Reference

Loopback PBX Module. More...

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include "asterisk.h"
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/config.h"
#include "asterisk/options.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/frame.h"
#include "asterisk/cli.h"
#include "asterisk/lock.h"
#include "asterisk/md5.h"
#include "asterisk/linkedlists.h"
#include "asterisk/chanvars.h"
#include "asterisk/sched.h"
#include "asterisk/io.h"
#include "asterisk/utils.h"
#include "asterisk/crypto.h"
#include "asterisk/astdb.h"

Include dependency graph for pbx_loopback.c:

Go to the source code of this file.

Defines

#define LOOPBACK_COMMON

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 loopback_canmatch (struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
static int loopback_exec (struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, int newstack, const char *data)
static int loopback_exists (struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
static char * loopback_helper (char *buf, int buflen, const char *exten, const char *context, int priority, const char *data)
static int loopback_matchmore (struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
static void loopback_subst (char **newexten, char **newcontext, int *priority, char **newpattern, char *buf)
int unload_module (void)
 Cleanup all module structures, sockets, etc.
int usecount (void)
 Provides a usecount.

Variables

static struct ast_switch loopback_switch
static char * tdesc = "Loopback Switch"


Detailed Description

Loopback PBX Module.

Definition in file pbx_loopback.c.


Define Documentation

#define LOOPBACK_COMMON


Function Documentation

char* description ( void   ) 

Provides a description of the module.

Returns:
a short description of your module

Definition at line 181 of file pbx_loopback.c.

00182 {
00183    return tdesc;
00184 }

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 191 of file pbx_loopback.c.

References ASTERISK_GPL_KEY.

00192 {
00193    return ASTERISK_GPL_KEY;
00194 }

int load_module ( void   ) 

Initialize the module.

This function is called at module load time. Put all code in here that needs to set up your module's hardware, software, registrations, etc.

Returns:
This function should return 0 on success and non-zero on failure. If the module is not loaded successfully, Asterisk will call its unload_module() function.
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.
TE STUFF END

Definition at line 202 of file pbx_loopback.c.

References ast_register_switch().

00203 {
00204    ast_register_switch(&loopback_switch);
00205    return 0;
00206 }

static int loopback_canmatch ( struct ast_channel chan,
const char *  context,
const char *  exten,
int  priority,
const char *  callerid,
const char *  data 
) [static]

Definition at line 141 of file pbx_loopback.c.

References ast_canmatch_extension(), ast_extension_match(), and LOOPBACK_COMMON.

00142 {
00143    LOOPBACK_COMMON;
00144    res = ast_canmatch_extension(chan, newcontext, newexten, newpriority, callerid);
00145    if (newpattern && !ast_extension_match(newpattern, exten))
00146       res = 0;
00147    return res;
00148 }

static int loopback_exec ( struct ast_channel chan,
const char *  context,
const char *  exten,
int  priority,
const char *  callerid,
int  newstack,
const char *  data 
) [static]

Definition at line 150 of file pbx_loopback.c.

References ast_exec_extension(), ast_extension_match(), ast_spawn_extension(), and LOOPBACK_COMMON.

00151 {
00152    LOOPBACK_COMMON;
00153    if (newstack)
00154       res = ast_spawn_extension(chan, newcontext, newexten, newpriority, callerid);
00155    else
00156       res = ast_exec_extension(chan, newcontext, newexten, newpriority, callerid);
00157    if (newpattern && !ast_extension_match(newpattern, exten))
00158       res = -1;
00159    return res;
00160 }

static int loopback_exists ( struct ast_channel chan,
const char *  context,
const char *  exten,
int  priority,
const char *  callerid,
const char *  data 
) [static]

Definition at line 132 of file pbx_loopback.c.

References ast_exists_extension(), ast_extension_match(), and LOOPBACK_COMMON.

00133 {
00134    LOOPBACK_COMMON;
00135    res = ast_exists_extension(chan, newcontext, newexten, newpriority, callerid);
00136    if (newpattern && !ast_extension_match(newpattern, exten))
00137       res = 0;
00138    return res;
00139 }

static char* loopback_helper ( char *  buf,
int  buflen,
const char *  exten,
const char *  context,
int  priority,
const char *  data 
) [static]

Definition at line 84 of file pbx_loopback.c.

References AST_LIST_EMPTY, AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_INSERT_HEAD, AST_LIST_REMOVE_HEAD, ast_var_assign(), ast_var_delete(), and pbx_substitute_variables_varshead().

00085 {
00086    struct ast_var_t *newvariable;
00087    struct varshead headp;
00088    char tmp[80];
00089 
00090    snprintf(tmp, sizeof(tmp), "%d", priority);
00091    memset(buf, 0, buflen);
00092    AST_LIST_HEAD_INIT_NOLOCK(&headp);
00093    newvariable = ast_var_assign("EXTEN", exten);
00094    AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
00095    newvariable = ast_var_assign("CONTEXT", context);
00096    AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
00097    newvariable = ast_var_assign("PRIORITY", tmp);
00098    AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
00099    pbx_substitute_variables_varshead(&headp, data, buf, buflen);
00100    /* Substitute variables */
00101    while (!AST_LIST_EMPTY(&headp)) {           /* List Deletion. */
00102       newvariable = AST_LIST_REMOVE_HEAD(&headp, entries);
00103       ast_var_delete(newvariable);
00104    }
00105    return buf;
00106 }

static int loopback_matchmore ( struct ast_channel chan,
const char *  context,
const char *  exten,
int  priority,
const char *  callerid,
const char *  data 
) [static]

Definition at line 162 of file pbx_loopback.c.

References ast_extension_match(), ast_matchmore_extension(), and LOOPBACK_COMMON.

00163 {
00164    LOOPBACK_COMMON;
00165    res = ast_matchmore_extension(chan, newcontext, newexten, newpriority, callerid);
00166    if (newpattern && !ast_extension_match(newpattern, exten))
00167       res = 0;
00168    return res;
00169 }

static void loopback_subst ( char **  newexten,
char **  newcontext,
int *  priority,
char **  newpattern,
char *  buf 
) [static]

Definition at line 108 of file pbx_loopback.c.

References ast_strlen_zero().

00109 {
00110    char *con;
00111    char *pri;
00112    *newpattern = strchr(buf, '/');
00113    if (*newpattern) {
00114       *(*newpattern) = '\0';
00115       (*newpattern)++;
00116    }
00117    con = strchr(buf, '@');
00118    if (con) {
00119       *con = '\0';
00120       con++;
00121       pri = strchr(con, ':');
00122    } else
00123       pri = strchr(buf, ':');
00124    if (!ast_strlen_zero(buf))
00125       *newexten = buf;
00126    if (!ast_strlen_zero(con))
00127       *newcontext = con;
00128    if (!ast_strlen_zero(pri))
00129       sscanf(pri, "%30d", priority);
00130 }

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.
Standard module functions ...

Definition at line 196 of file pbx_loopback.c.

References ast_unregister_switch().

00197 {
00198    ast_unregister_switch(&loopback_switch);
00199    return 0;
00200 }

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 186 of file pbx_loopback.c.

00187 {
00188    return 1;
00189 }


Variable Documentation

struct ast_switch loopback_switch [static]

Definition at line 171 of file pbx_loopback.c.

char* tdesc = "Loopback Switch" [static]

Definition at line 55 of file pbx_loopback.c.


Generated on Wed Oct 28 15:49:11 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6