From 40f1d8141ec42de40ab3658a458af6d2b6d7bdc8 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 14 Dec 2007 17:13:20 +0000 Subject: [PATCH] add user_exists git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6791 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- .../applications/mod_commands/mod_commands.c | 54 ++++++++++++------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index e88185bd18..e0126a4fbc 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -83,8 +83,8 @@ SWITCH_STANDARD_API(user_data_function) err = "can't find user"; goto end; } - - + + end: if (xml) { @@ -119,7 +119,8 @@ SWITCH_STANDARD_API(user_data_function) } -SWITCH_STANDARD_API(find_user_function) + +static switch_status_t _find_user(const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream, switch_bool_t tf) { switch_xml_t x_domain = NULL, x_user = NULL, xml = NULL; int argc; @@ -171,22 +172,26 @@ SWITCH_STANDARD_API(find_user_function) end: - if (err) { - if (host) { - stream->write_function(stream, "%s\n", err); - } else { - stream->write_function(stream, "-Error %s\n", err); - } - } - - if (xml && x_user) { - xmlstr = switch_xml_toxml(x_user, SWITCH_FALSE); - switch_assert(xmlstr); - - stream->write_function(stream, "%s", xmlstr); - free(xmlstr); + if (session || tf) { + stream->write_function(stream, err ? "false" : "true"); switch_xml_free(xml); - + } else { + if (err) { + if (host) { + stream->write_function(stream, "%s\n", err); + } else { + stream->write_function(stream, "-Error %s\n", err); + } + } + + if (xml && x_user) { + xmlstr = switch_xml_toxml(x_user, SWITCH_FALSE); + switch_assert(xmlstr); + + stream->write_function(stream, "%s", xmlstr); + free(xmlstr); + switch_xml_free(xml); + } } free(mydata); @@ -194,6 +199,18 @@ SWITCH_STANDARD_API(find_user_function) } +SWITCH_STANDARD_API(user_exists_function) +{ + return _find_user(cmd, session, stream, SWITCH_TRUE); +} + +SWITCH_STANDARD_API(find_user_function) +{ + return _find_user(cmd, session, stream, SWITCH_FALSE); +} + + + SWITCH_STANDARD_API(xml_locate_function) { @@ -2062,6 +2079,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load) SWITCH_ADD_API(commands_api_interface, "regex", "Eval a regex", regex_function, "|[|]"); SWITCH_ADD_API(commands_api_interface, "uuid_chat", "Send a chat message", uuid_chat, UUID_CHAT_SYNTAX); SWITCH_ADD_API(commands_api_interface, "find_user_xml", "find a user", find_user_function, " @"); + 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] ");