mod_sofia: fire an event for gateway ping
This commit is contained in:
parent
194e57268a
commit
3c5c5905ad
|
@ -332,7 +332,9 @@ typedef enum {
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SOFIA_GATEWAY_DOWN,
|
SOFIA_GATEWAY_DOWN,
|
||||||
SOFIA_GATEWAY_UP
|
SOFIA_GATEWAY_UP,
|
||||||
|
|
||||||
|
SOFIA_GATEWAY_INVALID
|
||||||
} sofia_gateway_status_t;
|
} sofia_gateway_status_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
@ -981,3 +983,7 @@ void sofia_glue_tech_track(sofia_profile_t *profile, switch_core_session_t *sess
|
||||||
int sofia_glue_recover(switch_bool_t flush);
|
int sofia_glue_recover(switch_bool_t flush);
|
||||||
void sofia_profile_destroy(sofia_profile_t *profile);
|
void sofia_profile_destroy(sofia_profile_t *profile);
|
||||||
switch_status_t sip_dig_function(_In_opt_z_ const char *cmd, _In_opt_ switch_core_session_t *session, _In_ switch_stream_handle_t *stream);
|
switch_status_t sip_dig_function(_In_opt_z_ const char *cmd, _In_opt_ switch_core_session_t *session, _In_ switch_stream_handle_t *stream);
|
||||||
|
const char *sofia_gateway_status_name(sofia_gateway_status_t status);
|
||||||
|
void sofia_reg_fire_custom_gateway_state_event(sofia_gateway_t *gateway, int status, const char *phrase);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3589,13 +3589,23 @@ switch_status_t config_sofia(int reload, char *profile_name)
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *sofia_gateway_status_name(sofia_gateway_status_t status)
|
||||||
|
{
|
||||||
|
static const char *status_names[] = { "DOWN", "UP", NULL };
|
||||||
|
|
||||||
|
if (status < SOFIA_GATEWAY_INVALID) {
|
||||||
|
return status_names[status];
|
||||||
|
} else {
|
||||||
|
return "INVALID";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void sofia_handle_sip_r_options(switch_core_session_t *session, int status,
|
static void sofia_handle_sip_r_options(switch_core_session_t *session, int status,
|
||||||
char const *phrase,
|
char const *phrase,
|
||||||
nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
|
nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
|
||||||
tagi_t tags[])
|
tagi_t tags[])
|
||||||
{
|
{
|
||||||
sofia_gateway_t *gateway = NULL;
|
sofia_gateway_t *gateway = NULL;
|
||||||
static const char *status_names[] = { "DOWN", "UP", NULL };
|
|
||||||
|
|
||||||
if (sofia_private && !zstr(sofia_private->gateway_name)) {
|
if (sofia_private && !zstr(sofia_private->gateway_name)) {
|
||||||
gateway = sofia_reg_find_gateway(sofia_private->gateway_name);
|
gateway = sofia_reg_find_gateway(sofia_private->gateway_name);
|
||||||
|
@ -3611,12 +3621,14 @@ static void sofia_handle_sip_r_options(switch_core_session_t *session, int statu
|
||||||
if (gateway->ping_count < gateway->ping_max) {
|
if (gateway->ping_count < gateway->ping_max) {
|
||||||
gateway->ping_count++;
|
gateway->ping_count++;
|
||||||
|
|
||||||
if (gateway->ping_count >= 0)
|
if (gateway->ping_count >= 0 && gateway->status != SOFIA_GATEWAY_UP) {
|
||||||
gateway->status = SOFIA_GATEWAY_UP;
|
gateway->status = SOFIA_GATEWAY_UP;
|
||||||
|
sofia_reg_fire_custom_gateway_state_event(gateway, status, phrase);
|
||||||
|
}
|
||||||
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
|
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
|
||||||
"Ping succeeded %s with code %d - count %d/%d/%d, state %s\n",
|
"Ping succeeded %s with code %d - count %d/%d/%d, state %s\n",
|
||||||
gateway->name, status, gateway->ping_min, gateway->ping_count, gateway->ping_max, status_names[gateway->status]);
|
gateway->name, status, gateway->ping_min, gateway->ping_count, gateway->ping_max, sofia_gateway_status_name(gateway->status));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (gateway->state == REG_STATE_REGED) {
|
if (gateway->state == REG_STATE_REGED) {
|
||||||
|
@ -3627,13 +3639,15 @@ static void sofia_handle_sip_r_options(switch_core_session_t *session, int statu
|
||||||
if (gateway->ping_count > gateway->ping_min) {
|
if (gateway->ping_count > gateway->ping_min) {
|
||||||
gateway->ping_count--;
|
gateway->ping_count--;
|
||||||
|
|
||||||
if (gateway->ping_count <= 0)
|
if (gateway->ping_count <= 0 && gateway->status != SOFIA_GATEWAY_DOWN) {
|
||||||
gateway->status = SOFIA_GATEWAY_DOWN;
|
gateway->status = SOFIA_GATEWAY_DOWN;
|
||||||
|
sofia_reg_fire_custom_gateway_state_event(gateway, status, phrase);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
|
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
|
||||||
"Ping failed %s with code %d - count %d/%d/%d, state %s\n",
|
"Ping failed %s with code %d - count %d/%d/%d, state %s\n",
|
||||||
gateway->name, status, gateway->ping_min, gateway->ping_count, gateway->ping_max, status_names[gateway->status]);
|
gateway->name, status, gateway->ping_min, gateway->ping_count, gateway->ping_max, sofia_gateway_status_name(gateway->status));
|
||||||
}
|
}
|
||||||
|
|
||||||
gateway->ping = switch_epoch_time_now(NULL) + gateway->ping_freq;
|
gateway->ping = switch_epoch_time_now(NULL) + gateway->ping_freq;
|
||||||
|
|
|
@ -90,12 +90,13 @@ static void sofia_reg_kill_reg(sofia_gateway_t *gateway_ptr)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sofia_reg_fire_custom_gateway_state_event(sofia_gateway_t *gateway, int status, const char *phrase)
|
void sofia_reg_fire_custom_gateway_state_event(sofia_gateway_t *gateway, int status, const char *phrase)
|
||||||
{
|
{
|
||||||
switch_event_t *s_event;
|
switch_event_t *s_event;
|
||||||
if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, MY_EVENT_GATEWAY_STATE) == SWITCH_STATUS_SUCCESS) {
|
if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, MY_EVENT_GATEWAY_STATE) == SWITCH_STATUS_SUCCESS) {
|
||||||
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "Gateway", gateway->name);
|
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "Gateway", gateway->name);
|
||||||
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "State", sofia_state_string(gateway->state));
|
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "State", sofia_state_string(gateway->state));
|
||||||
|
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "Ping-Status", sofia_gateway_status_name(gateway->status));
|
||||||
if (!zstr(phrase)) {
|
if (!zstr(phrase)) {
|
||||||
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "Phrase", phrase);
|
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "Phrase", phrase);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue