@ -45,17 +45,26 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
# include "asterisk/astdb.h"
/* Loopback switch substitutes ${EXTEN}, ${CONTEXT}, and ${PRIORITY} into
the data passed to it to try to get a string of the form :
/* Loopback switch creates a 'tunnel' to another context. When extension
lookups pass through the ' tunnel ' , Asterisk expressions can be used
to modify the target extension , context , and priority in any way desired .
If there is a match at the far end , execution jumps through the ' tunnel '
to the matched context , extension , and priority .
Global variables as well as $ { CONTEXT } , $ { EXTEN } , and $ { PRIORITY } are
available for substitution . After substitution Loopback expects to get
a string of the form :
[ exten ] @ context [ : priority ] [ / extramatch ]
Where exten , context , and priority are another extension , context , and priority
to lookup and " extramatch " is an extra match restriction the * original * number
must fit if specified . The " extramatch " begins with _ like an exten pattern
if it is specified . Note that the search context MUST be a different context
from the current context or the search will not succeed in an effort to reduce
the likelihood of loops ( they ' re still possible if you try hard , so be careful ! )
to lookup and " extramatch " is a dialplan extension pattern which the * original *
number must match . If exten or priority are empty , the original values are
used .
Note that the search context MUST be a different context from the current
context or the search will not succeed . This is intended to reduce the
likelihood of loops ( they ' re still possible if you try hard , so be careful ! )
*/
@ -66,13 +75,12 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
char * newexten = ( char * ) exten , * newcontext = ( char * ) context ; \
int newpriority = priority ; \
char * newpattern = NULL ; \
loopback_ helper ( buf , sizeof ( buf ) , exten , context , priority , data ) ; \
loopback_ subst ( & newexten , & newcontext , & newpriority , & newpattern , buf ) ; \
loopback_ subst ( buf , sizeof ( buf ) , exten , context , priority , data ) ; \
loopback_ parse ( & newexten , & newcontext , & newpriority , & newpattern , buf ) ; \
ast_log ( LOG_DEBUG , " Parsed into %s @ %s priority %d \n " , newexten , newcontext , newpriority ) ; \
if ( ! strcasecmp ( newcontext , context ) ) return - 1
static char * loopback_helper ( char * buf , int buflen , const char * exten , const char * context , int priority , const char * data )
static char * loopback_subst ( char * buf , int buflen , const char * exten , const char * context , int priority , const char * data )
{
struct ast_var_t * newvariable ;
struct varshead headp ;
@ -80,9 +88,12 @@ static char *loopback_helper(char *buf, int buflen, const char *exten, const cha
snprintf ( tmp , sizeof ( tmp ) , " %d " , priority ) ;
AST_LIST_HEAD_INIT_NOLOCK ( & headp ) ;
AST_LIST_INSERT_HEAD ( & headp , ast_var_assign ( " EXTEN " , exten ) , entries ) ;
AST_LIST_INSERT_HEAD ( & headp , ast_var_assign ( " CONTEXT " , context ) , entries ) ;
AST_LIST_INSERT_HEAD ( & headp , ast_var_assign ( " PRIORITY " , tmp ) , entries ) ;
newvariable = ast_var_assign ( " EXTEN " , exten ) ;
AST_LIST_INSERT_HEAD ( & headp , newvariable , entries ) ;
newvariable = ast_var_assign ( " CONTEXT " , context ) ;
AST_LIST_INSERT_HEAD ( & headp , newvariable , entries ) ;
newvariable = ast_var_assign ( " PRIORITY " , tmp ) ;
AST_LIST_INSERT_HEAD ( & headp , newvariable , entries ) ;
/* Substitute variables */
pbx_substitute_variables_varshead ( & headp , data , buf , buflen ) ;
/* free the list */
@ -91,7 +102,7 @@ static char *loopback_helper(char *buf, int buflen, const char *exten, const cha
return buf ;
}
static void loopback_ subst ( char * * newexten , char * * newcontext , int * priority , char * * newpattern , char * buf )
static void loopback_ parse ( char * * newexten , char * * newcontext , int * priority , char * * newpattern , char * buf )
{
char * con ;
char * pri ;
@ -135,9 +146,6 @@ static int loopback_exec(struct ast_channel *chan, const char *context, const ch
int found ;
LOOPBACK_COMMON ;
res = ast_spawn_extension ( chan , newcontext , newexten , newpriority , callerid , & found , 0 ) ;
/* XXX hmmm... res is overridden ? */
if ( newpattern & & ! ast_extension_match ( newpattern , exten ) )
res = - 1 ;
return res ;
}