From 7abff700d413ba3153c76b50bc31b256eb0c50db Mon Sep 17 00:00:00 2001 From: tilghman Date: Tue, 3 Jun 2008 22:42:03 +0000 Subject: Merged revisions 120226 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r120226 | tilghman | 2008-06-03 17:41:04 -0500 (Tue, 03 Jun 2008) | 8 lines Due to incorrect use of the AST_LIST_INSERT_HEAD() macro the loopback switch cannot perform any translation on the extension number before searching for it in the target context. (closes issue #12473) Reported by: chappell Patches: pbx_loopback.c.diff uploaded by chappell (license 8) ........ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@120227 f38db490-d61c-443f-a65b-d21fe96a405b --- pbx/pbx_loopback.c | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) (limited to 'pbx/pbx_loopback.c') diff --git a/pbx/pbx_loopback.c b/pbx/pbx_loopback.c index e6f4ed904..e9001deef 100644 --- a/pbx/pbx_loopback.c +++ b/pbx/pbx_loopback.c @@ -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; } -- cgit v1.2.3