From 76b648036a3f77492f90566c2480759a671f19fc Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 10 Oct 2008 15:36:02 +0000 Subject: [PATCH] (MODENDP-112) custom sofia::gateway_state event git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9932 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/mod/endpoints/mod_sofia/mod_sofia.c | 8 +++++++- src/mod/endpoints/mod_sofia/mod_sofia.h | 2 ++ src/mod/endpoints/mod_sofia/sofia_reg.c | 24 ++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index d766743c32..1153562c5a 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -1193,7 +1193,8 @@ static switch_status_t sofia_receive_event(switch_core_session_t *session, switc typedef switch_status_t (*sofia_command_t) (char **argv, int argc, switch_stream_handle_t *stream); -static const char *sofia_state_names[] = { "UNREGED", +static const char *sofia_state_names[] = { + "UNREGED", "TRYING", "REGISTER", "REGED", @@ -1204,6 +1205,11 @@ static const char *sofia_state_names[] = { "UNREGED", NULL }; +const char * sofia_state_string(int state) +{ + return sofia_state_names[state]; +} + struct cb_helper { sofia_profile_t *profile; switch_stream_handle_t *stream; diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 9f53371a7c..726b3ecf0b 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -72,6 +72,7 @@ typedef struct private_object private_object_t; #define MY_EVENT_REGISTER "sofia::register" #define MY_EVENT_UNREGISTER "sofia::unregister" #define MY_EVENT_EXPIRE "sofia::expire" +#define MY_EVENT_GATEWAY_STATE "sofia::gateway_state" #define MULTICAST_EVENT "multicast::event" #define SOFIA_REPLACES_HEADER "_sofia_replaces_" @@ -699,3 +700,4 @@ void sofia_glue_del_gateway(sofia_gateway_t *gp); void sofia_reg_send_reboot(sofia_profile_t *profile, const char *user, const char *host, const char *contact, const char *user_agent); void sofia_glue_restart_all_profiles(void); void sofia_glue_toggle_hold(private_object_t *tech_pvt, int sendonly); +const char * sofia_state_string(int state); diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index c6787bc876..c0fa655446 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -56,6 +56,15 @@ static void sofia_reg_kill_reg(sofia_gateway_t *gateway_ptr, int unreg) } +static void sofia_reg_fire_custom_gateway_state_event(sofia_gateway_t *gateway) { + switch_event_t *s_event; + if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, MY_EVENT_GATEWAY_STATE) == SWITCH_STATUS_SUCCESS) { + switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "Gateway", "%s", gateway->name); + switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "State", "%s", sofia_state_string(gateway->state)); + switch_event_fire(&s_event); + } +} + void sofia_reg_unregister(sofia_profile_t *profile) { sofia_gateway_t *gateway_ptr; @@ -197,6 +206,9 @@ void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now) } break; } + if (ostate != gateway_ptr->state) { + sofia_reg_fire_custom_gateway_state_event(gateway_ptr); + } } } @@ -1021,6 +1033,7 @@ void sofia_reg_handle_sip_r_register(int status, tagi_t tags[]) { if (sofia_private && sofia_private->gateway) { + reg_state_t ostate = sofia_private->gateway->state; switch (status) { case 200: if (sip && sip->sip_contact) { @@ -1056,6 +1069,9 @@ void sofia_reg_handle_sip_r_register(int status, switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Registration Failed with status %d\n", status); break; } + if (ostate != sofia_private->gateway->state) { + sofia_reg_fire_custom_gateway_state_event(sofia_private->gateway); + } } } @@ -1480,12 +1496,16 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co } if ((gateway_ptr = sofia_reg_find_gateway(name))) { + reg_state_t ostate = gateway_ptr->state; gateway_ptr->retry = 0; if (exptime) { gateway_ptr->state = REG_STATE_UNREGED; } else { gateway_ptr->state = REG_STATE_UNREGISTER; } + if (ostate != gateway_ptr->state) { + sofia_reg_fire_custom_gateway_state_event(gateway_ptr); + } sofia_reg_release_gateway(gateway_ptr); } @@ -1502,12 +1522,16 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co for (x = 0; x < argc; x++) { if ((gateway_ptr = sofia_reg_find_gateway((char *) argv[x]))) { + reg_state_t ostate = gateway_ptr->state; gateway_ptr->retry = 0; if (exptime) { gateway_ptr->state = REG_STATE_UNREGED; } else { gateway_ptr->state = REG_STATE_UNREGISTER; } + if (ostate != gateway_ptr->state) { + sofia_reg_fire_custom_gateway_state_event(gateway_ptr); + } sofia_reg_release_gateway(gateway_ptr); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Gateway '%s' not found.\n", argv[x]);