aboutsummaryrefslogtreecommitdiffstats
path: root/funcs
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2006-05-22 03:40:31 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2006-05-22 03:40:31 +0000
commit96ba011628ffb363beb3fa7f92e134c5bfdf5562 (patch)
tree0386b4d7b8eb2a495647a36d26265f2b60205395 /funcs
parente332760b294a648af33baf3d957527bf9593b379 (diff)
Escaping commas within fields isn't always desireable.
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@29364 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'funcs')
-rw-r--r--funcs/func_odbc.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/funcs/func_odbc.c b/funcs/func_odbc.c
index 4f17e02e2..1dfc778e1 100644
--- a/funcs/func_odbc.c
+++ b/funcs/func_odbc.c
@@ -53,11 +53,16 @@ static char *tdesc = "ODBC lookups";
static char *config = "func_odbc.conf";
+enum {
+ OPT_ESCAPECOMMAS = (1 << 0),
+} odbc_option_flags;
+
struct acf_odbc_query {
AST_LIST_ENTRY(acf_odbc_query) list;
char dsn[30];
char sql_read[2048];
char sql_write[2048];
+ unsigned int flags;
struct ast_custom_function *acf;
};
@@ -230,7 +235,7 @@ static int acf_odbc_read(struct ast_channel *chan, char *cmd, char *s, char *buf
struct odbc_obj *obj;
struct acf_odbc_query *query;
char sql[2048] = "", varname[15];
- int res, x, buflen = 0;
+ int res, x, buflen = 0, escapecommas;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(field)[100];
);
@@ -282,6 +287,9 @@ static int acf_odbc_read(struct ast_channel *chan, char *cmd, char *s, char *buf
pbx_builtin_setvar_helper(chan, varname, NULL);
}
+ /* Save this flag, so we can release the lock */
+ escapecommas = ast_test_flag(query, OPT_ESCAPECOMMAS);
+
AST_LIST_UNLOCK(&queries);
res = SQLAllocHandle (SQL_HANDLE_STMT, obj->con, &stmt);
@@ -345,7 +353,7 @@ static int acf_odbc_read(struct ast_channel *chan, char *cmd, char *s, char *buf
/* Copy data, encoding '\' and ',' for the argument parser */
for (i = 0; i < sizeof(coldata); i++) {
- if (coldata[i] == '\\' || coldata[i] == ',') {
+ if (escapecommas && (coldata[i] == '\\' || coldata[i] == ',')) {
buf[buflen++] = '\\';
}
buf[buflen++] = coldata[i];
@@ -420,6 +428,13 @@ static int init_acf_query(struct ast_config *cfg, char *catg, struct acf_odbc_qu
ast_copy_string((*query)->sql_write, tmp, sizeof((*query)->sql_write));
}
+ /* Allow escaping of embedded commas in fields to be turned off */
+ ast_set_flag((*query), OPT_ESCAPECOMMAS);
+ if ((tmp = ast_variable_retrieve(cfg, catg, "escapecommas"))) {
+ if (ast_false(tmp))
+ ast_clear_flag((*query), OPT_ESCAPECOMMAS);
+ }
+
(*query)->acf = ast_calloc(1, sizeof(struct ast_custom_function));
if (! (*query)->acf) {
free(*query);