From 9aa8df3dd9e8395efbbd182fc78c735cae4fec09 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Fri, 21 Aug 2009 14:48:42 +0000 Subject: [PATCH] MODENDP-232 git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@14585 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/mod/endpoints/mod_sofia/mod_sofia.c | 66 +++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index b4e5078ecb..d328df5fe1 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -1717,7 +1717,7 @@ static switch_status_t cmd_status(char **argv, int argc, switch_stream_handle_t char *sql = NULL; if ((argv[1]) && (profile = sofia_glue_find_profile(argv[1]))) { - if (!argv[2] || strcasecmp(argv[2], "reg")) { + if (!argv[2] || (strcasecmp(argv[2], "reg") && strcasecmp(argv[2], "user"))) { stream->write_function(stream, "%s\n", line); stream->write_function(stream, "Name \t%s\n", switch_str_nil(argv[1])); stream->write_function(stream, "Domain Name \t%s\n", profile->domain_name ? profile->domain_name : "N/A"); @@ -1792,6 +1792,36 @@ static switch_status_t cmd_status(char **argv, int argc, switch_stream_handle_t profile->name, argv[3]); } } + if (!sql && argv[2] && !strcasecmp(argv[2], "user") && argv[3]) { + char *dup = strdup(argv[3]); + char *host = NULL, *user = NULL; + char *sqlextra = NULL; + + switch_assert(dup); + + if ((host = strchr(dup, '@'))) { + *host++ = '\0'; + user = dup; + } else { + host = dup; + } + + if (switch_strlen_zero(user) ) { + sqlextra = switch_mprintf("(sip_host='%q')", host); + } else if (switch_strlen_zero(host)) { + sqlextra = switch_mprintf("(sip_user='%q')", user); + } else { + sqlextra = switch_mprintf("(sip_user='%q' and sip_host='%q')", user, host); + } + + sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status," + "rpid,expires,user_agent,server_user,server_host,profile_name,hostname," + "network_ip,network_port,sip_username,sip_realm" + " from sip_registrations where profile_name='%q' and %s", + profile->name, sqlextra); + switch_safe_free(dup); + switch_safe_free(sqlextra); + } if (!sql) { sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status," @@ -1917,7 +1947,7 @@ static switch_status_t cmd_xml_status(char **argv, int argc, switch_stream_handl if ((argv[1]) && (profile = sofia_glue_find_profile(argv[1]))) { stream->write_function(stream, "%s\n", header); stream->write_function(stream, "\n"); - if (!argv[2] || strcasecmp(argv[2], "reg")) { + if (!argv[2] || (strcasecmp(argv[2], "reg") && strcasecmp(argv[2], "user"))) { stream->write_function(stream, " \n"); stream->write_function(stream, " %s\n", switch_str_nil(argv[1])); stream->write_function(stream, " %s\n", profile->domain_name ? profile->domain_name : "N/A"); @@ -1984,6 +2014,36 @@ static switch_status_t cmd_xml_status(char **argv, int argc, switch_stream_handl profile->name, argv[3]); } } + if (!sql && argv[2] && !strcasecmp(argv[2], "user") && argv[3]) { + char *dup = strdup(argv[3]); + char *host = NULL, *user = NULL; + char *sqlextra = NULL; + + switch_assert(dup); + + if ((host = strchr(dup, '@'))) { + *host++ = '\0'; + user = dup; + } else { + host = dup; + } + + if (switch_strlen_zero(user)) { + sqlextra = switch_mprintf("(sip_host='%q')", host); + } else if (switch_strlen_zero(host)) { + sqlextra = switch_mprintf("(sip_user='%q')", user); + } else { + sqlextra = switch_mprintf("(sip_user='%q' and sip_host='%q')", user, host); + } + + sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status," + "rpid,expires,user_agent,server_user,server_host,profile_name,hostname," + "network_ip,network_port,sip_username,sip_realm" + " from sip_registrations where profile_name='%q' and %s", + profile->name, sqlextra); + switch_safe_free(dup); + switch_safe_free(sqlextra); + } if (!sql) { sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status," @@ -2475,7 +2535,7 @@ SWITCH_STANDARD_API(sofia_function) "--------------------------------------------------------------------------------\n" "sofia help\n" "sofia profile [[start|stop|restart|rescan] [reloadxml]|flush_inbound_reg [] [reboot]|[register|unregister] [|all]|killgw |[stun-auto-disable|stun-enabled] [true|false]]|siptrace [on|off]\n" - "sofia status profile [ reg ] | [ pres ]\n" + "sofia status profile [ reg ] | [ pres ] | [ user ]\n" "sofia status gateway \n" "sofia loglevel [0-9]\n" "--------------------------------------------------------------------------------\n";