From 20bc2fde18e23586031bd0ff8714a3578a7d03f1 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 7 Dec 2006 00:36:00 +0000 Subject: [PATCH] come down from the acid trip from the last commit git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3561 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/switch_channel.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/switch_channel.c b/src/switch_channel.c index b8b98d4e1f..628bcd998c 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -1107,6 +1107,16 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_answer(switch_channel_t * } +#define resize(l) {\ +char *dp;\ +olen += (len + l + block);\ +cpos = c - data;\ +if ((dp = realloc(data, olen))) {\ + data = dp;\ + c = data + cpos;\ + memset(c, 0, olen - cpos);\ + }} \ + SWITCH_DECLARE(char *) switch_channel_expand_variables(switch_channel_t *channel, char *in) { char *p, *c; @@ -1129,15 +1139,17 @@ SWITCH_DECLARE(char *) switch_channel_expand_variables(switch_channel_t *channel if (*p == '$') { vtype = 1; + if (*(p+1) != '{') { + vtype = 2; + } } - if (*(p+1) != '{') { - vtype = 2; - } - + if (vtype) { char *s = p, *e, *vname, *vval = NULL; size_t nlen; + s++; + if (vtype == 1 && *s == '{') { br = 1; s++; @@ -1195,24 +1207,23 @@ SWITCH_DECLARE(char *) switch_channel_expand_variables(switch_channel_t *channel } if ((nlen = sub_val ? strlen(sub_val) : 0)) { if (len + nlen >= olen) { - char *dp; - olen += (len + nlen + block); - cpos = c - data; - if ((dp = realloc(data, olen))) { - data = dp; - c = data + cpos; - memset(c, 0, olen - cpos); - } + resize(nlen); } len += nlen; strcat(c, sub_val); c += nlen; - } switch_safe_free(func_val); + sub_val = NULL; + vname = NULL; + vtype = 0; } + if (len + 1 >= olen) { + resize(1); + } + if (sp) { *c++ = ' '; sp = 0;