[asterisk-commits] tilghman: branch 1.4 r189537 - /branches/1.4/funcs/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Apr 20 17:02:22 CDT 2009


Author: tilghman
Date: Mon Apr 20 17:02:16 2009
New Revision: 189537

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=189537
Log:
Add a workaround for func_odbc/ARRAY() for problems that occur with certain special characters.
In certain cases, due to the way Set() works in 1.4, values may not get set
properly.  This is a workaround for 1.4 only that corrects for these issues,
without making func_odbc more difficult to use properly.
(closes issue #14614)
 Reported by: wdoekes
 Patches: 
       20090309__bug14614__2.diff.txt uploaded by tilghman (license 14)
       double_set_unescape_workaround_for_func_odbc.osso-and-tilghman-1.diff uploaded by wdoekes (license 717)
 Tested by: wdoekes, tilghman

Modified:
    branches/1.4/funcs/func_odbc.c
    branches/1.4/funcs/func_strings.c

Modified: branches/1.4/funcs/func_odbc.c
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/funcs/func_odbc.c?view=diff&rev=189537&r1=189536&r2=189537
==============================================================================
--- branches/1.4/funcs/func_odbc.c (original)
+++ branches/1.4/funcs/func_odbc.c Mon Apr 20 17:02:16 2009
@@ -227,6 +227,9 @@
 	SQLSMALLINT colcount=0;
 	SQLLEN indicator;
 
+	/* Reset, in case of an error */
+	pbx_builtin_setvar_helper(chan, "~ODBCVALUES~", "");
+
 	AST_LIST_LOCK(&queries);
 	AST_LIST_TRAVERSE(&queries, query, list) {
 		if (!strcmp(query->acf->name, cmd)) {
@@ -345,9 +348,9 @@
 			return -1;
 		}
 
-		/* Copy data, encoding '\' and ',' for the argument parser */
+		/* Copy data, encoding '\', ',', '"', and '|' for the argument parser */
 		for (i = 0; i < sizeof(coldata); i++) {
-			if (escapecommas && (coldata[i] == '\\' || coldata[i] == ',')) {
+			if (escapecommas && strchr("\\,|\"", coldata[i])) {
 				buf[buflen++] = '\\';
 			}
 			buf[buflen++] = coldata[i];
@@ -368,6 +371,10 @@
 	SQLCloseCursor(stmt);
 	SQLFreeHandle(SQL_HANDLE_STMT, stmt);
 	ast_odbc_release_obj(obj);
+
+	/* Pass an unadulterated string to ARRAY, if needed.  This is only needed
+	 * in 1.4, because of the misfeature in Set. */
+	pbx_builtin_setvar_helper(chan, "~ODBCVALUES~", buf);
 	if (chan)
 		ast_autoservice_stop(chan);
 	if (bogus_chan)

Modified: branches/1.4/funcs/func_strings.c
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/funcs/func_strings.c?view=diff&rev=189537&r1=189536&r2=189537
==============================================================================
--- branches/1.4/funcs/func_strings.c (original)
+++ branches/1.4/funcs/func_strings.c Mon Apr 20 17:02:16 2009
@@ -162,6 +162,23 @@
 	.read = regex,
 };
 
+static int strecmp(const char *pre, const char *post)
+{
+	int res;
+	for (; *pre && *post; pre++, post++) {
+		if (*pre == '"') {
+			post--;
+			continue;
+		} else if (*pre == '\\') {
+			pre++;
+		}
+		if ((res = strncmp(pre, post, 1))) {
+			return res;
+		}
+	}
+	return strncmp(pre, post, 1);
+}
+
 static int array(struct ast_channel *chan, char *cmd, char *var,
 		 const char *value)
 {
@@ -173,6 +190,15 @@
 	);
 	char *value2;
 	int i;
+
+	if (chan) {
+		const char *value3;
+		ast_mutex_lock(&chan->lock);
+		if ((value3 = pbx_builtin_getvar_helper(chan, "~ODBCVALUES~")) && strecmp(value3, value) == 0) {
+			value = ast_strdupa(value3);
+		}
+		ast_mutex_unlock(&chan->lock);
+	}
 
 	value2 = ast_strdupa(value);
 	if (!var || !value2)




More information about the asterisk-commits mailing list