From 6dd5e59b058a7d10994374fdfee2948d59b99a34 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 16 Dec 2011 13:41:15 -0600 Subject: [PATCH] add sofia global standby on that makes sofia not do anything but refuse to work until sofia global standby off or sofia recover is issued --- src/mod/endpoints/mod_sofia/mod_sofia.c | 20 ++++++++++++++++-- src/mod/endpoints/mod_sofia/mod_sofia.h | 4 +++- src/mod/endpoints/mod_sofia/sofia.c | 27 +++++++++++++++++++++++- src/mod/endpoints/mod_sofia/sofia_glue.c | 26 +++++++++++++++++++++++ 4 files changed, 73 insertions(+), 4 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index c058efb9cf..1dfe82a62d 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -4139,6 +4139,7 @@ SWITCH_STANDARD_API(sofia_function) int ston = -1; int cton = -1; int wdon = -1; + int stbyon = -1; if (argc > 1) { if (!strcasecmp(argv[1], "debug")) { @@ -4174,6 +4175,12 @@ SWITCH_STANDARD_API(sofia_function) } } + if (!strcasecmp(argv[1], "standby")) { + if (argc > 2) { + stbyon = switch_true(argv[2]); + } + } + if (!strcasecmp(argv[1], "capture")) { if (argc > 2) { cton = switch_true(argv[2]); @@ -4191,11 +4198,14 @@ SWITCH_STANDARD_API(sofia_function) sofia_glue_global_siptrace(ston); stream->write_function(stream, "+OK Global siptrace %s", ston ? "on" : "off"); } else if (cton != -1) { - sofia_glue_global_capture(cton); - stream->write_function(stream, "+OK Global capture %s", cton ? "on" : "off"); + sofia_glue_global_capture(cton); + stream->write_function(stream, "+OK Global capture %s", cton ? "on" : "off"); } else if (wdon != -1) { sofia_glue_global_watchdog(wdon); stream->write_function(stream, "+OK Global watchdog %s", wdon ? "on" : "off"); + } else if (stbyon != -1) { + sofia_glue_global_standby(stbyon); + stream->write_function(stream, "+OK Global standby %s", stbyon ? "on" : "off"); } else { stream->write_function(stream, "-ERR Usage: siptrace |capture |watchdog |debug destination_number)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Invalid Empty Destination\n"); goto error; @@ -5406,6 +5421,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load) switch_console_set_complete("add sofia tracelevel ::[console:alert:crit:err:warning:notice:info:debug"); switch_console_set_complete("add sofia global siptrace ::[on:off"); + switch_console_set_complete("add sofia global standby ::[on:off"); switch_console_set_complete("add sofia global capture ::[on:off"); switch_console_set_complete("add sofia global watchdog ::[on:off"); diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 8ab6e91e7a..7d92a320df 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -219,7 +219,7 @@ typedef enum { PFLAG_UUID_AS_CALLID, PFLAG_SCROOGE, PFLAG_MANAGE_SHARED_APPEARANCE, - PFLAG_MANAGE_SHARED_APPEARANCE_SYLANTRO_DELETED_USE_ME, + PFLAG_STANDBY, PFLAG_DISABLE_SRV, PFLAG_DISABLE_SRV503, PFLAG_DISABLE_NAPTR, @@ -843,6 +843,8 @@ switch_mutex_unlock(obj->flag_mutex); /* Function Prototypes */ /*************************************************************************************************************************************************************/ +void sofia_glue_global_standby(switch_bool_t on); + switch_status_t sofia_glue_activate_rtp(private_object_t *tech_pvt, switch_rtp_flag_t myflags); void sofia_glue_deactivate_rtp(private_object_t *tech_pvt); diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 777cf0970b..ff722d385b 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -857,7 +857,6 @@ static void our_sofia_event_callback(nua_event_t event, int locked = 0; int check_destroy = 1; - if (sofia_private && sofia_private->is_call && sofia_private->de) { sofia_dispatch_event_t *qde = sofia_private->de; sofia_private->de = NULL; @@ -1302,6 +1301,14 @@ void sofia_event_callback(nua_event_t event, sofia_dispatch_event_t *de; + if (sofia_test_pflag(profile, PFLAG_STANDBY)) { + if (event < nua_r_set_params || event > nua_r_authenticate) { + nua_respond(nh, 503, "System Paused", TAG_END()); + } + return; + } + + switch_mutex_lock(profile->flag_mutex); profile->queued_events++; switch_mutex_unlock(profile->flag_mutex); @@ -1586,6 +1593,12 @@ void *SWITCH_THREAD_FUNC sofia_profile_worker_thread_run(switch_thread_t *thread /* While we're running, or there is a pending sql statment that we haven't appended to sqlbuf yet, because of a lack of buffer space */ while ((mod_sofia_globals.running == 1 && sofia_test_pflag(profile, PFLAG_RUNNING)) || sql) { + + if (sofia_test_pflag(profile, PFLAG_STANDBY)) { + switch_yield(1000000); + continue; + } + if (sofia_test_pflag(profile, PFLAG_SQL_IN_TRANS)) { /* Do we have enough statements or is the timeout expired */ while (sql || (sofia_test_pflag(profile, PFLAG_RUNNING) && mod_sofia_globals.running == 1 && @@ -2965,6 +2978,12 @@ switch_status_t reconfig_sofia(sofia_profile_t *profile) } else { sofia_clear_pflag(profile, PFLAG_PRESENCE_MAP); } + } else if (!strcasecmp(var, "profile-standby")) { + if (switch_true(val)) { + sofia_set_pflag(profile, PFLAG_STANDBY); + } else { + sofia_clear_pflag(profile, PFLAG_STANDBY); + } } else if (!strcasecmp(var, "liberal-dtmf")) { if (switch_true(val)) { sofia_set_pflag(profile, PFLAG_LIBERAL_DTMF); @@ -3695,6 +3714,12 @@ switch_status_t config_sofia(int reload, char *profile_name) } else { sofia_clear_pflag(profile, PFLAG_PRESENCE_MAP); } + } else if (!strcasecmp(var, "profile-standby")) { + if (switch_true(val)) { + sofia_set_pflag(profile, PFLAG_STANDBY); + } else { + sofia_clear_pflag(profile, PFLAG_STANDBY); + } } else if (!strcasecmp(var, "liberal-dtmf")) { if (switch_true(val)) { sofia_set_pflag(profile, PFLAG_LIBERAL_DTMF); diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index 191dd5083a..8ea0322657 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -5312,6 +5312,30 @@ void sofia_glue_global_siptrace(switch_bool_t on) } +void sofia_glue_global_standby(switch_bool_t on) +{ + switch_hash_index_t *hi; + const void *var; + void *val; + sofia_profile_t *pptr; + + switch_mutex_lock(mod_sofia_globals.hash_mutex); + if (mod_sofia_globals.profile_hash) { + for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) { + switch_hash_this(hi, &var, NULL, &val); + if ((pptr = (sofia_profile_t *) val)) { + if (on) { + sofia_set_pflag_locked(pptr, PFLAG_STANDBY); + } else { + sofia_clear_pflag_locked(pptr, PFLAG_STANDBY); + } + } + } + } + switch_mutex_unlock(mod_sofia_globals.hash_mutex); + +} + void sofia_glue_global_capture(switch_bool_t on) { switch_hash_index_t *hi; @@ -5674,6 +5698,8 @@ int sofia_glue_recover(switch_bool_t flush) h.profile = profile; h.total = 0; + sofia_clear_pflag_locked(profile, PFLAG_STANDBY); + if (flush) { sql = switch_mprintf("delete from sip_recovery where profile_name='%q'", profile->name); sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);