From d88d2c1b3ca852f927527e6789f2cb1e84d7a3ed Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 27 Jun 2008 15:07:28 +0000 Subject: [PATCH] add url encode/decode api calls git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8855 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- .../applications/mod_commands/mod_commands.c | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index 2a26636581..628a44cf93 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -178,6 +178,45 @@ static switch_status_t _find_user(const char *cmd, switch_core_session_t *sessio return SWITCH_STATUS_SUCCESS; } +SWITCH_STANDARD_API(url_decode_function) +{ + char *reply = ""; + char *data = NULL; + + if (!switch_strlen_zero(cmd)) { + data = strdup(cmd); + switch_url_decode(data); + reply = data; + } + + stream->write_function(stream, "%s", reply); + + switch_safe_free(data); + return SWITCH_STATUS_SUCCESS; + +} + +SWITCH_STANDARD_API(url_encode_function) +{ + char *reply = ""; + char *data = NULL; + int len = 0 ; + + if (!switch_strlen_zero(cmd)) { + len = (strlen(cmd) * 3) + 1; + switch_zmalloc(data, len); + switch_url_encode(cmd, data, len); + reply = data; + } + + stream->write_function(stream, "%s", reply); + + switch_safe_free(data); + return SWITCH_STATUS_SUCCESS; + +} + + SWITCH_STANDARD_API(user_exists_function) { return _find_user(cmd, session, stream, SWITCH_TRUE); @@ -2390,6 +2429,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load) SWITCH_ADD_API(commands_api_interface, "user_exists", "find a user", user_exists_function, " "); SWITCH_ADD_API(commands_api_interface, "xml_locate", "find some xml", xml_locate_function, "[root |
]"); SWITCH_ADD_API(commands_api_interface, "user_data", "find user data", user_data_function, "@ [var|param] "); + SWITCH_ADD_API(commands_api_interface, "url_encode", "url encode a string", url_encode_function, ""); + SWITCH_ADD_API(commands_api_interface, "url_decode", "url decode a string", url_decode_function, ""); /* indicate that the module should continue to be loaded */ return SWITCH_STATUS_NOUNLOAD;