Index: pbx/pbx_realtime.c =================================================================== --- pbx/pbx_realtime.c (revision 335652) +++ pbx/pbx_realtime.c (working copy) @@ -68,6 +68,9 @@ AST_APP_OPTION('p', OPTION_PATTERNS_DISABLED), }); +AST_THREADSTORAGE(appdata_buf); +AST_THREADSTORAGE(tmp3_buf); + struct cache_entry { struct timeval when; struct ast_variable *var; @@ -344,19 +347,23 @@ if (!ast_strlen_zero(app)) { struct ast_app *a = pbx_findapp(app); if (a) { - char appdata[512]; + struct ast_str *appdata = ast_str_thread_get(&appdata_buf, 16); char tmp1[80]; char tmp2[80]; - char tmp3[EXT_DATA_SIZE]; + struct ast_str *tmp3 = ast_str_thread_get(&tmp3_buf, 16); - appdata[0] = 0; /* just in case the substitute var func isn't called */ - if(!ast_strlen_zero(tmp)) - pbx_substitute_variables_helper(chan, tmp, appdata, sizeof(appdata) - 1); + if (!appdata) { + return -1; + } + ast_str_reset(appdata); /* just in case the substitute var func isn't called */ + if (!ast_strlen_zero(tmp)) { + ast_str_substitute_variables(&appdata, 0, chan, tmp); + } ast_verb(3, "Executing [%s@%s:%d] %s(\"%s\", \"%s\")\n", chan->exten, chan->context, chan->priority, term_color(tmp1, app, COLOR_BRCYAN, 0, sizeof(tmp1)), term_color(tmp2, chan->name, COLOR_BRMAGENTA, 0, sizeof(tmp2)), - term_color(tmp3, S_OR(appdata, ""), COLOR_BRMAGENTA, 0, sizeof(tmp3))); + ast_str_term_color(&tmp3, 0, ast_str_buffer(appdata), COLOR_BRMAGENTA, 0)); manager_event(EVENT_FLAG_DIALPLAN, "Newexten", "Channel: %s\r\n" "Context: %s\r\n" @@ -365,9 +372,9 @@ "Application: %s\r\n" "AppData: %s\r\n" "Uniqueid: %s\r\n", - chan->name, chan->context, chan->exten, chan->priority, app, !ast_strlen_zero(appdata) ? appdata : "(NULL)", chan->uniqueid); - - res = pbx_exec(chan, a, appdata); + chan->name, chan->context, chan->exten, chan->priority, app, ast_str_buffer(appdata), chan->uniqueid); + + res = pbx_exec(chan, a, ast_str_buffer(appdata)); } else ast_log(LOG_NOTICE, "No such application '%s' for extension '%s' in context '%s'\n", app, exten, context); } else { Index: include/asterisk/term.h =================================================================== --- include/asterisk/term.h (revision 335652) +++ include/asterisk/term.h (working copy) @@ -66,6 +66,30 @@ * plus a null char */ #define AST_TERM_MAX_ESCAPE_CHARS 23 +/*! + * \brief Colorize a string + * + * \param out Output buffer + * \param maxlen Argument passed through to the ast_str interface + * \param in Input string + * \param fgcolor Color constant for the foreground color + * \param bgcolor Color constant for the background color + * + * \return A pointer to the output string + */ +char *ast_str_term_color(struct ast_str **out, int maxlen, const char *in, int fgcolor, int bgcolor); + +/*! + * \brief Colorize a string + * + * \param outbuf Output buffer + * \param inbuf Input string + * \param fgcolor Color constant for the foreground color + * \param bgcolor Color constant for the background color + * \param maxout Size of the output buffer + * + * \return A pointer to the output string + */ char *term_color(char *outbuf, const char *inbuf, int fgcolor, int bgcolor, int maxout); /*! Index: main/term.c =================================================================== --- main/term.c (revision 335652) +++ main/term.c (working copy) @@ -36,6 +36,7 @@ #include "asterisk/term.h" #include "asterisk/lock.h" #include "asterisk/utils.h" +#include "asterisk/strings.h" static int vt100compat; @@ -177,6 +178,36 @@ return 0; } +char *ast_str_term_color(struct ast_str **out, int maxlen, const char *in, int fgcolor, int bgcolor) +{ + int attr = 0; + + if (!vt100compat || !fgcolor) { + ast_str_set(out, maxlen, "%s", in); + return ast_str_buffer(*out); + } + + if (fgcolor & 128) { + attr = ast_opt_light_background ? 0 : ATTR_BRIGHT; + fgcolor &= ~128; + } + + if (bgcolor) { + bgcolor &= ~128; + } + + if (ast_opt_light_background) { + fgcolor = opposite(fgcolor); + } + + if (ast_opt_force_black_background) { + ast_str_set(out, maxlen, "%c[%d;%d;%dm%s%c[%d;%dm", ESC, attr, fgcolor, bgcolor + 10, in, ESC, COLOR_WHITE, COLOR_BLACK + 10); + } else { + ast_str_set(out, maxlen, "%c[%d;%dm%s%c[0m", ESC, attr, fgcolor, in, ESC); + } + return ast_str_buffer(*out); +} + char *term_color(char *outbuf, const char *inbuf, int fgcolor, int bgcolor, int maxout) { int attr = 0;