summaryrefslogtreecommitdiff
path: root/apps/app_macro.c
diff options
context:
space:
mode:
authorTilghman Lesher <tilghman@meg.abyt.es>2009-04-29 18:53:01 +0000
committerTilghman Lesher <tilghman@meg.abyt.es>2009-04-29 18:53:01 +0000
commita866a7590085a1f635ca92459c3917e5cded257a (patch)
tree972bdf8f96c18f1b9667469307af69385f4a75f3 /apps/app_macro.c
parent0ea83eab4811c8519e4e04bf4c59b1744cf1efc9 (diff)
Merge str_substitution branch.
This branch adds additional methods to dialplan functions, whereby the result buffers are now dynamic buffers, which can be expanded to the size of any result. No longer are variable substitutions limited to 4095 bytes of data. In addition, the common case of needing buffers much smaller than that will enable substitution to only take up the amount of memory actually needed. The existing variable substitution routines are still available, but users of those API calls should transition to using the dynamic-buffer APIs. Reviewboard: http://reviewboard.digium.com/r/174/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@191140 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'apps/app_macro.c')
-rw-r--r--apps/app_macro.c35
1 files changed, 24 insertions, 11 deletions
diff --git a/apps/app_macro.c b/apps/app_macro.c
index dfbd3b12c..458a93b37 100644
--- a/apps/app_macro.c
+++ b/apps/app_macro.c
@@ -231,13 +231,14 @@ static int _macro_exec(struct ast_channel *chan, void *data, int exclusive)
int offset, depth = 0, maxdepth = 7;
int setmacrocontext=0;
int autoloopflag, inhangup = 0;
+ struct ast_str *tmp_subst = NULL;
char *save_macro_exten;
char *save_macro_context;
char *save_macro_priority;
char *save_macro_offset;
struct ast_datastore *macro_store = ast_channel_datastore_find(chan, &macro_ds_info, NULL);
-
+
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "Macro() requires arguments. See \"core show application macro\" for help.\n");
return -1;
@@ -281,7 +282,6 @@ static int _macro_exec(struct ast_channel *chan, void *data, int exclusive)
return 0;
}
snprintf(depthc, sizeof(depthc), "%d", depth + 1);
- pbx_builtin_setvar_helper(chan, "MACRO_DEPTH", depthc);
tmp = ast_strdupa(data);
rest = tmp;
@@ -311,7 +311,11 @@ static int _macro_exec(struct ast_channel *chan, void *data, int exclusive)
}
ast_autoservice_stop(chan);
}
-
+
+ if (!(tmp_subst = ast_str_create(16))) {
+ return -1;
+ }
+
/* Save old info */
oldpriority = chan->priority;
ast_copy_string(oldexten, chan->exten, sizeof(oldexten));
@@ -337,6 +341,8 @@ static int _macro_exec(struct ast_channel *chan, void *data, int exclusive)
save_macro_offset = ast_strdup(pbx_builtin_getvar_helper(chan, "MACRO_OFFSET"));
pbx_builtin_setvar_helper(chan, "MACRO_OFFSET", NULL);
+ pbx_builtin_setvar_helper(chan, "MACRO_DEPTH", depthc);
+
/* Setup environment for new run */
chan->exten[0] = 's';
chan->exten[1] = '\0';
@@ -415,8 +421,9 @@ static int _macro_exec(struct ast_channel *chan, void *data, int exclusive)
gosub_level++;
ast_debug(1, "Incrementing gosub_level\n");
} else if (!strcasecmp(runningapp, "GOSUBIF")) {
- char tmp2[1024], *cond, *app_arg, *app2 = tmp2;
- pbx_substitute_variables_helper(chan, runningdata, tmp2, sizeof(tmp2) - 1);
+ char *cond, *app_arg, *app2;
+ ast_str_substitute_variables(&tmp_subst, 0, chan, runningdata);
+ app2 = ast_str_buffer(tmp_subst);
cond = strsep(&app2, "?");
app_arg = strsep(&app2, ":");
if (pbx_checkcondition(cond)) {
@@ -438,19 +445,24 @@ static int _macro_exec(struct ast_channel *chan, void *data, int exclusive)
ast_debug(1, "Decrementing gosub_level\n");
} else if (!strncasecmp(runningapp, "EXEC", 4)) {
/* Must evaluate args to find actual app */
- char tmp2[1024], *tmp3 = NULL;
- pbx_substitute_variables_helper(chan, runningdata, tmp2, sizeof(tmp2) - 1);
+ char *tmp2, *tmp3 = NULL;
+ ast_str_substitute_variables(&tmp_subst, 0, chan, runningdata);
+ tmp2 = ast_str_buffer(tmp_subst);
if (!strcasecmp(runningapp, "EXECIF")) {
tmp3 = strchr(tmp2, '|');
- if (tmp3)
+ if (tmp3) {
*tmp3++ = '\0';
- if (!pbx_checkcondition(tmp2))
+ }
+ if (!pbx_checkcondition(tmp2)) {
tmp3 = NULL;
- } else
+ }
+ } else {
tmp3 = tmp2;
+ }
- if (tmp3)
+ if (tmp3) {
ast_debug(1, "Last app: %s\n", tmp3);
+ }
if (tmp3 && !strncasecmp(tmp3, "GOSUB", 5)) {
gosub_level++;
@@ -547,6 +559,7 @@ static int _macro_exec(struct ast_channel *chan, void *data, int exclusive)
}
}
ast_channel_unlock(chan);
+ ast_free(tmp_subst);
return res;
}