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:
Naveen Albert
2021-11-15 21:08:11 +00:00
committed by Friendly Automation
parent 6a6967bf0c
commit 23a4a12420
3 changed files with 57 additions and 1 deletions

View File

@@ -8602,6 +8602,27 @@ void *ast_get_extension_app_data(struct ast_exten *e)
return e ? e->data : NULL;
}
int ast_get_extension_data(char *buf, int bufsize, struct ast_channel *c,
const char *context, const char *exten, int priority)
{
struct ast_exten *e;
struct pbx_find_info q = { .stacklen = 0 }; /* the rest is set in pbx_find_context */
ast_rdlock_contexts();
e = pbx_find_extension(c, NULL, &q, context, exten, priority, NULL, "", E_MATCH);
if (e) {
if (buf) {
const char *tmp = ast_get_extension_app_data(e);
if (tmp) {
ast_copy_string(buf, tmp, bufsize);
}
}
ast_unlock_contexts();
return 0;
}
ast_unlock_contexts();
return -1;
}
/*
* Walking functions ...
*/