From 65b2ec699026c2e0b6586c19b344ff6ad64616fd Mon Sep 17 00:00:00 2001
From: Anthony Minessale <anthony.minessale@gmail.com>
Date: Thu, 18 Oct 2007 21:36:57 +0000
Subject: [PATCH] change var parser to ${func(arg)}

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5979 d0543943-73ff-0310-b7d9-9358b9ac24b2
---
 src/switch_channel.c | 36 ++++++++++++++++--------------------
 1 file changed, 16 insertions(+), 20 deletions(-)

diff --git a/src/switch_channel.c b/src/switch_channel.c
index 290d0de2d6..d44f3f54da 100644
--- a/src/switch_channel.c
+++ b/src/switch_channel.c
@@ -1301,9 +1301,10 @@ SWITCH_DECLARE(char *) switch_channel_expand_variables(switch_channel_t *channel
 
 			if (*p == '$' && !nv) {
 				if (*(p+1)) {
-					vtype = 1;
-					if (*(p + 1) != '{') {
-						vtype = 2;
+					if (*(p+1) == '{') {
+						vtype = 1;
+					} else {
+						nv = 1;
 					}
 				} else {
 					nv = 1;
@@ -1331,31 +1332,26 @@ SWITCH_DECLARE(char *) switch_channel_expand_variables(switch_channel_t *channel
 				e = s;
 				vname = s;
 				while (*e) {
-					if (!br && *e == ' ') {
-						*e++ = '\0';
-						sp++;
-						break;
-					}
 					if (br == 1 && *e == '}') {
 						br = 0;
 						*e++ = '\0';
 						break;
 					}
-					if (vtype == 2) {
-						if (*e == '(') {
-							*e++ = '\0';
-							vval = e;
-							br = 2;
-						}
-						if (br == 2 && *e == ')') {
-							*e++ = '\0';
-							br = 0;
-							break;
-						}
-					}
 					e++;
 				}
 				p = e;
+				
+				if ((vval = strchr(vname, '('))) {
+					e = vval - 1;
+					*vval++ = '\0';
+					while(*e == ' ') {
+						*e-- = '\0';
+					}
+					if ((e = strchr(vval, ')'))) {
+						*e = '\0';
+					}
+					vtype = 2;
+				}
 
 				if (vtype == 1) {
 					sub_val = switch_channel_get_variable(channel, vname);