diff options
author | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2009-04-20 22:02:16 +0000 |
---|---|---|
committer | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2009-04-20 22:02:16 +0000 |
commit | a3720841ae07657c947fc2fea90586bcdb89e9d2 (patch) | |
tree | 7a73eb6b58cf3cb7f11033f68b8f51c70c5d9057 /funcs | |
parent | 01e18e19a0305206315360dee517c6eb09f58c8b (diff) |
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
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@189537 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'funcs')
-rw-r--r-- | funcs/func_odbc.c | 11 | ||||
-rw-r--r-- | funcs/func_strings.c | 26 |
2 files changed, 35 insertions, 2 deletions
diff --git a/funcs/func_odbc.c b/funcs/func_odbc.c index 49007d792..5052d1c17 100644 --- a/funcs/func_odbc.c +++ b/funcs/func_odbc.c @@ -227,6 +227,9 @@ static int acf_odbc_read(struct ast_channel *chan, char *cmd, char *s, char *buf 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 @@ static int acf_odbc_read(struct ast_channel *chan, char *cmd, char *s, char *buf 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 @@ static int acf_odbc_read(struct ast_channel *chan, char *cmd, char *s, char *buf 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) diff --git a/funcs/func_strings.c b/funcs/func_strings.c index 8b0d562ba..05161d04c 100644 --- a/funcs/func_strings.c +++ b/funcs/func_strings.c @@ -162,6 +162,23 @@ static struct ast_custom_function regex_function = { .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) { @@ -174,6 +191,15 @@ static int array(struct ast_channel *chan, char *cmd, char *var, 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) return -1; |