From 9943975660143fd377c66daa2eff9e00f24997da Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 25 Mar 2008 22:06:48 +0000 Subject: [PATCH] add optional call_id arg to sofia profile foo flush_inbound_reg [] git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7965 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/mod/endpoints/mod_sofia/mod_sofia.c | 14 ++++++++++---- src/mod/endpoints/mod_sofia/mod_sofia.h | 1 + src/mod/endpoints/mod_sofia/sofia_reg.c | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index c3038a7beb..14639f1026 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -1325,10 +1325,16 @@ static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t stream->write_function(stream, "Invalid Profile [%s]", switch_str_nil(profile_name)); return SWITCH_STATUS_SUCCESS; } - + if (!strcasecmp(argv[1], "flush_inbound_reg")) { - sofia_reg_check_expire(profile, 0); - stream->write_function(stream, "+OK\n"); + if (argc > 2) { + sofia_reg_expire_call_id(profile, argv[2]); + stream->write_function(stream, "+OK flushing all registrations matching specified call_id\n"); + } else { + sofia_reg_check_expire(profile, 0); + stream->write_function(stream, "+OK flushing all registrations\n"); + } + goto done; } @@ -1542,7 +1548,7 @@ SWITCH_STANDARD_API(sofia_function) const char *usage_string = "USAGE:\n" "--------------------------------------------------------------------------------\n" "sofia help\n" - "sofia profile [start|stop|restart|flush_inbound_reg|[register|unregister] [|all]] [reloadxml]\n" + "sofia profile [start|stop|restart|flush_inbound_reg []|[register|unregister] [|all]] [reloadxml]\n" "sofia status [[profile | gateway] ]\n" "sofia loglevel [0-9]\n" "--------------------------------------------------------------------------------\n"; diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 9e20028c7e..e053181974 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -602,3 +602,4 @@ switch_status_t sofia_glue_build_crypto(private_object_t *tech_pvt, int index, s void sofia_glue_tech_patch_sdp(private_object_t *tech_pvt); switch_status_t sofia_glue_tech_proxy_remote_addr(private_object_t *tech_pvt); void sofia_presence_event_thread_start(void); +void sofia_reg_expire_call_id(sofia_profile_t *profile, const char *call_id); diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index c030a7aed4..e164526a34 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -206,6 +206,24 @@ int sofia_reg_del_callback(void *pArg, int argc, char **argv, char **columnNames return 0; } +void sofia_reg_expire_call_id(sofia_profile_t *profile, const char *call_id) +{ + char sql[1024]; + char *psql = sql; + + switch_snprintf(sql, sizeof(sql), "select *,'%s' from sip_registrations where call_id='%s'", profile->name, call_id); + switch_mutex_lock(profile->ireg_mutex); + sofia_glue_execute_sql_callback(profile, + SWITCH_TRUE, + NULL, + sql, + sofia_reg_del_callback, + NULL); + switch_mutex_unlock(profile->ireg_mutex); + + switch_snprintf(sql, sizeof(sql), "delete from sip_registrations where call_id='%s'", call_id); + sofia_glue_execute_sql(profile, &psql, SWITCH_FALSE); +} void sofia_reg_check_expire(sofia_profile_t *profile, time_t now) {