[asterisk-commits] trunk r29364 - in /trunk: configs/func_odbc.conf.sample funcs/func_odbc.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sun May 21 20:40:32 MST 2006


Author: tilghman
Date: Sun May 21 22:40:31 2006
New Revision: 29364

URL: http://svn.digium.com/view/asterisk?rev=29364&view=rev
Log:
Escaping commas within fields isn't always desireable.

Modified:
    trunk/configs/func_odbc.conf.sample
    trunk/funcs/func_odbc.c

Modified: trunk/configs/func_odbc.conf.sample
URL: http://svn.digium.com/view/asterisk/trunk/configs/func_odbc.conf.sample?rev=29364&r1=29363&r2=29364&view=diff
==============================================================================
--- trunk/configs/func_odbc.conf.sample (original)
+++ trunk/configs/func_odbc.conf.sample Sun May 21 22:40:31 2006
@@ -35,4 +35,7 @@
 read=SELECT location FROM presence WHERE id='${SQL_ESC(${ARG1})}'
 write=UPDATE presence SET location='${SQL_ESC(${VAL1})}' WHERE id='${SQL_ESC(${ARG1})}'
 ;prefix=OFFICE		; Changes this function from ODBC_PRESENCE to OFFICE_PRESENCE
+;escapecommas=no	; Normally, commas within a field are escaped such that each
+			; field may be separated into individual variables with ARRAY.
+			; This option turns that behavior off [default=yes].
 

Modified: trunk/funcs/func_odbc.c
URL: http://svn.digium.com/view/asterisk/trunk/funcs/func_odbc.c?rev=29364&r1=29363&r2=29364&view=diff
==============================================================================
--- trunk/funcs/func_odbc.c (original)
+++ trunk/funcs/func_odbc.c Sun May 21 22:40:31 2006
@@ -53,11 +53,16 @@
 
 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 @@
 	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 @@
 		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 @@
 
 		/* 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];
@@ -418,6 +426,13 @@
 
 	if ((tmp = ast_variable_retrieve(cfg, catg, "write"))) {
 		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));



More information about the asterisk-commits mailing list