mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-06 04:30:28 +00:00
pbx: Add variable substitution API for extensions
Currently, variable substitution involving dialplan extensions is quite clunky since it entails obtaining the current dialplan location, backing it up, storing the desired variables for substitution on the channel, performing substitution, then restoring the original location. In addition to being clunky, things could also go wrong if an async goto were to occur and change the dialplan location during a substitution. Fundamentally, there's no reason it needs to be done this way, so new API is added to allow for directly passing in the dialplan location for the purposes of variable substitution so we don't need to mess with the channel information anymore. Existing API is not changed. ASTERISK-29745 #close Change-Id: I23273bf27fa0efb64a606eebf9aa8e2f41a065e4
This commit is contained in:
committed by
George Joseph
parent
2b2b708d43
commit
cc1418ef47
@@ -624,6 +624,11 @@ void ast_str_substitute_variables_varshead(struct ast_str **buf, ssize_t maxlen,
|
||||
}
|
||||
|
||||
void pbx_substitute_variables_helper_full(struct ast_channel *c, struct varshead *headp, const char *cp1, char *cp2, int count, size_t *used)
|
||||
{
|
||||
pbx_substitute_variables_helper_full_location(c, headp, cp1, cp2, count, used, NULL, NULL, 0);
|
||||
}
|
||||
|
||||
void pbx_substitute_variables_helper_full_location(struct ast_channel *c, struct varshead *headp, const char *cp1, char *cp2, int count, size_t *used, char *context, char *exten, int pri)
|
||||
{
|
||||
/* Substitutes variables into cp2, based on string cp1, cp2 NO LONGER NEEDS TO BE ZEROED OUT!!!! */
|
||||
const char *whereweare;
|
||||
@@ -759,7 +764,16 @@ void pbx_substitute_variables_helper_full(struct ast_channel *c, struct varshead
|
||||
ast_debug(2, "Function %s result is '%s'\n", vars, cp4 ? cp4 : "(null)");
|
||||
} else {
|
||||
/* Retrieve variable value */
|
||||
pbx_retrieve_variable(c, vars, &cp4, workspace, VAR_BUF_SIZE, headp);
|
||||
/* For dialplan location, if we were told what to substitute explicitly, use that instead */
|
||||
if (exten && !strcmp(vars, "EXTEN")) {
|
||||
ast_copy_string(workspace, exten, VAR_BUF_SIZE);
|
||||
} else if (context && !strcmp(vars, "CONTEXT")) {
|
||||
ast_copy_string(workspace, context, VAR_BUF_SIZE);
|
||||
} else if (pri && !strcmp(vars, "PRIORITY")) {
|
||||
snprintf(workspace, VAR_BUF_SIZE, "%d", pri);
|
||||
} else {
|
||||
pbx_retrieve_variable(c, vars, &cp4, workspace, VAR_BUF_SIZE, headp);
|
||||
}
|
||||
}
|
||||
if (cp4) {
|
||||
cp4 = substring(cp4, offset, offset2, workspace, VAR_BUF_SIZE);
|
||||
|
Reference in New Issue
Block a user