From 0477cb67f5a454367f4b5208bdee6d849d64495c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 17 Sep 2010 14:11:57 -0500 Subject: [PATCH] add sofia profile gwlist up|down to list up or downed profiles for feeding into mod distributor to exclude dead gateways --- src/mod/endpoints/mod_sofia/mod_sofia.c | 18 ++++++++++++++++++ src/mod/endpoints/mod_sofia/mod_sofia.h | 1 + src/mod/endpoints/mod_sofia/sofia_glue.c | 22 ++++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 5039fefe50..1e8876e638 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -3166,6 +3166,21 @@ static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t goto done; } + + if (!strcasecmp(argv[1], "gwlist")) { + int up = 1; + + if (argc > 2) { + if (!strcasecmp(argv[2], "down")) { + up = 0; + } + } + + sofia_glue_gateway_list(profile, stream, up); + goto done; + } + + stream->write_function(stream, "-ERR Unknown command!\n"); done: @@ -4637,6 +4652,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load) switch_console_set_complete("add sofia profile ::sofia::list_profiles siptrace on"); switch_console_set_complete("add sofia profile ::sofia::list_profiles siptrace off"); + switch_console_set_complete("add sofia profile ::sofia::list_profiles gwlist up"); + switch_console_set_complete("add sofia profile ::sofia::list_profiles gwlist down"); + switch_console_set_complete("add sofia status profile ::sofia::list_profiles"); switch_console_set_complete("add sofia status profile ::sofia::list_profiles reg"); switch_console_set_complete("add sofia status gateway ::sofia::list_gateways"); diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 96acbcd9ed..5a6995806a 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -942,6 +942,7 @@ switch_status_t sofia_glue_tech_set_video_codec(private_object_t *tech_pvt, int const char *sofia_glue_strip_proto(const char *uri); switch_status_t reconfig_sofia(sofia_profile_t *profile); void sofia_glue_del_gateway(sofia_gateway_t *gp); +void sofia_glue_gateway_list(sofia_profile_t *profile, switch_stream_handle_t *stream, int up); void sofia_glue_del_every_gateway(sofia_profile_t *profile); void sofia_reg_send_reboot(sofia_profile_t *profile, const char *user, const char *host, const char *contact, const char *user_agent, const char *network_ip); diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index d17981c9d0..498230789a 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -4267,6 +4267,28 @@ void sofia_glue_del_every_gateway(sofia_profile_t *profile) } +void sofia_glue_gateway_list(sofia_profile_t *profile, switch_stream_handle_t *stream, int up) +{ + sofia_gateway_t *gp = NULL; + char *r = (char *) stream->data; + + switch_mutex_lock(mod_sofia_globals.hash_mutex); + for (gp = profile->gateways; gp; gp = gp->next) { + int reged = (gp->state == REG_STATE_REGED); + + if (up ? reged : !reged) { + stream->write_function(stream, "%s ", gp->name); + } + } + + if (r) { + end_of(r) = '\0'; + } + + switch_mutex_unlock(mod_sofia_globals.hash_mutex); +} + + void sofia_glue_del_gateway(sofia_gateway_t *gp) { if (!gp->deleted) {