Revision
16462
Author
rupa
Date
2010-01-22 11:55:39 -0600 (Fri, 22 Jan 2010)

Log Message

MODAPP-354 - add sql_escape

Modified Paths

Diff

Modified: freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c (16461 => 16462)


--- freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c	2010-01-22 17:47:08 UTC (rev 16461)
+++ freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c	2010-01-22 17:55:39 UTC (rev 16462)
@@ -4040,6 +4040,18 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
+#define SQL_ESCAPE_SYNTAX "<string>"
+SWITCH_STANDARD_API(sql_escape)
+{
+	if (zstr(cmd)) {
+		stream->write_function(stream, "-USAGE: %s\n", SQL_ESCAPE_SYNTAX);
+	} else {
+		stream->write_function(stream, "%q", cmd);
+	}
+
+	return SWITCH_STATUS_SUCCESS;
+}
+
 SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_commands_shutdown)
 {
 	int x;
@@ -4116,6 +4128,7 @@
 	SWITCH_ADD_API(commands_api_interface, "sched_hangup", "Schedule a running call to hangup", sched_hangup_function, SCHED_HANGUP_SYNTAX);
 	SWITCH_ADD_API(commands_api_interface, "sched_transfer", "Schedule a transfer for a running call", sched_transfer_function, SCHED_TRANSFER_SYNTAX);
 	SWITCH_ADD_API(commands_api_interface, "show", "Show", show_function, SHOW_SYNTAX);
+	SWITCH_ADD_API(commands_api_interface, "sql_escape", "Escape a string to prevent sql injection", sql_escape, SQL_ESCAPE_SYNTAX);
 	SWITCH_ADD_API(commands_api_interface, "status", "status", status_function, "");
 	SWITCH_ADD_API(commands_api_interface, "strftime_tz", "strftime_tz", strftime_tz_api_function, "<Timezone_name> [format string]");
 	SWITCH_ADD_API(commands_api_interface, "stun", "stun", stun_function, "<stun_server>[:port]");
@@ -4219,6 +4232,7 @@
 	switch_console_set_complete("add show say");
 	switch_console_set_complete("add show timer");
 	switch_console_set_complete("add shutdown");
+	switch_console_set_complete("add sql_escape");
 	switch_console_set_complete("add uuid_audio ::console::list_uuid start read mute");
 	switch_console_set_complete("add uuid_audio ::console::list_uuid start read level");
 	switch_console_set_complete("add uuid_audio ::console::list_uuid start write mute");