summaryrefslogtreecommitdiff
path: root/funcs
diff options
context:
space:
mode:
authorTilghman Lesher <tilghman@meg.abyt.es>2005-12-27 02:02:23 +0000
committerTilghman Lesher <tilghman@meg.abyt.es>2005-12-27 02:02:23 +0000
commitdd161bec3b0fc208ba3dbfc59cc182cadaa0c3fc (patch)
tree78695566ff2240d3c05e57ce0387b21898da632d /funcs
parent63ed37defd389f67f1406f6defb4f8ffd653402a (diff)
Add SQL_ESC to allow single ticks to be escaped
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7642 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'funcs')
-rw-r--r--funcs/func_odbc.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/funcs/func_odbc.c b/funcs/func_odbc.c
index 770ac8092..496933ef0 100644
--- a/funcs/func_odbc.c
+++ b/funcs/func_odbc.c
@@ -351,6 +351,35 @@ acf_out:
return buf;
}
+static char *acf_escape(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
+{
+ char *in, *out = buf;
+ for (in = data; *in && out - buf < len; in++) {
+ if (*in == '\'') {
+ *out = '\'';
+ out++;
+ }
+ *out = *in;
+ out++;
+ }
+ *out = '\0';
+ return buf;
+}
+
+struct ast_custom_function escape_function = {
+ .name = "SQL_ESC",
+ .synopsis = "Escapes single ticks for use in SQL statements",
+ .syntax = "SQL_ESC(<string>)",
+ .desc =
+"Used in SQL templates to escape data which may contain single ticks (') which\n"
+"are otherwise used to delimit data. For example:\n"
+"SELECT foo FROM bar WHERE baz='${SQL_ESC(${ARG1})}'\n",
+ .read = acf_escape,
+ .write = NULL,
+};
+
+
+
static int init_acf_query(struct ast_config *cfg, char *catg, struct acf_odbc_query **query)
{
char *tmp;
@@ -477,6 +506,7 @@ static int odbc_load_module(void)
}
ast_config_destroy(cfg);
+ ast_custom_function_register(&escape_function);
out:
ast_mutex_unlock(&query_lock);
return res;
@@ -507,6 +537,8 @@ static int odbc_unload_module(void)
free(lastquery);
queries = NULL;
+ ast_custom_function_unregister(&escape_function);
+
ast_mutex_unlock(&query_lock);
return 0;
}