FS-9698 fire custom sofia::bye_response event when response to BYE is received and fire-bye-response-events profile param is true

This commit is contained in:
Chris Rienzo committed 2016-11-04 12:00:39 -04:00
1 parent 2c111bbdb5
commit 3ff491274d
4 files changed
+52 -8

No files matched your search

+37 -5
View File
@@ -864,6 +864,30 @@ void sofia_handle_sip_i_notify(switch_core_session_t *session, int status,
}
/*
* This will fire an event containing X-headers from the BYE response
*/
void sofia_handle_sip_r_bye(switch_core_session_t *session, int status,
char const *phrase,
nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
sofia_dispatch_event_t *de, tagi_t tags[])
{
if (profile && sofia_test_pflag(profile, PFLAG_FIRE_BYE_RESPONSE_EVENTS) && sip && sip->sip_call_id && !zstr(sip->sip_call_id->i_id) && sofia_private && !zstr_buf(sofia_private->uuid_str)) {
switch_event_t *bye_response_event = NULL;
sip_unknown_t *un;
if (switch_event_create_subclass(&bye_response_event, SWITCH_EVENT_CUSTOM, MY_EVENT_BYE_RESPONSE) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(bye_response_event, SWITCH_STACK_BOTTOM, "call-id", "%s", sip->sip_call_id->i_id);
switch_event_add_header(bye_response_event, SWITCH_STACK_BOTTOM, "Unique-ID", "%s", sofia_private->uuid_str);
for (un = sip->sip_unknown; un; un = un->un_next) {
if (!zstr(un->un_value)) {
switch_event_add_header(bye_response_event, SWITCH_STACK_BOTTOM, un->un_name, "%s", un->un_value);
}
}
switch_event_fire(&bye_response_event);
}
}
}
void sofia_handle_sip_i_bye(switch_core_session_t *session, int status,
char const *phrase,
nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
@@ -1415,7 +1439,6 @@ static void our_sofia_event_callback(nua_event_t event,
if (sofia_private && sofia_private != &mod_sofia_globals.destroy_private && sofia_private != &mod_sofia_globals.keep_private) {
if (!zstr(sofia_private->gateway_name)) {
if (!(gateway = sofia_reg_find_gateway(sofia_private->gateway_name))) {
return;
@@ -1549,7 +1572,6 @@ static void our_sofia_event_callback(nua_event_t event,
case nua_i_fork:
case nua_r_info:
break;
case nua_r_bye:
case nua_r_unregister:
case nua_r_unsubscribe:
case nua_i_terminated:
@@ -1674,6 +1696,9 @@ static void our_sofia_event_callback(nua_event_t event,
case nua_i_bye:
sofia_handle_sip_i_bye(session, status, phrase, nua, profile, nh, sofia_private, sip, de, tags);
break;
case nua_r_bye:
sofia_handle_sip_r_bye(session, status, phrase, nua, profile, nh, sofia_private, sip, de, tags);
break;
case nua_r_notify:
if (session) {
sofia_handle_sip_r_notify(session, status, phrase, nua, profile, nh, sofia_private, sip, de, tags);
@@ -2417,7 +2442,8 @@ void sofia_event_callback(nua_event_t event,
if (uuid) {
if ((session = switch_core_session_locate(uuid))) {
tech_pvt = switch_core_session_get_private(session);
switch_copy_string(sofia_private->uuid, switch_core_session_get_uuid(session), sizeof(sofia_private->uuid));
switch_copy_string(sofia_private->uuid_str, switch_core_session_get_uuid(session), sizeof(sofia_private->uuid_str));
sofia_private->uuid = sofia_private->uuid_str;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Re-attaching to session %s\n", sofia_private->uuid);
de->init_session = session;
sofia_clear_flag(tech_pvt, TFLAG_BYE);
@@ -2511,7 +2537,8 @@ void sofia_event_callback(nua_event_t event,
goto end;
}
switch_copy_string(sofia_private->uuid, switch_core_session_get_uuid(session), sizeof(sofia_private->uuid));
switch_copy_string(sofia_private->uuid_str, switch_core_session_get_uuid(session), sizeof(sofia_private->uuid_str));
sofia_private->uuid = sofia_private->uuid_str;
de->init_session = session;
switch_core_session_queue_signal_data(session, de);
@@ -4627,6 +4654,12 @@ switch_status_t config_sofia(sofia_config_t reload, char *profile_name)
} else {
sofia_clear_pflag(profile, PFLAG_ENABLE_CHAT);
}
} else if (!strcasecmp(var, "fire-bye-response-events")) {
if (switch_true(val)) {
sofia_set_pflag(profile, PFLAG_FIRE_BYE_RESPONSE_EVENTS);
} else {
sofia_clear_pflag(profile, PFLAG_FIRE_BYE_RESPONSE_EVENTS);
}
} else if (!strcasecmp(var, "fire-message-events")) {
if (switch_true(val)) {
sofia_set_pflag(profile, PFLAG_FIRE_MESSAGE_EVENTS);
@@ -8135,7 +8168,6 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status,
ss_state = nua_callstate_terminated;
}
if (ss_state == nua_callstate_terminated) {
if (tech_pvt->sofia_private) {
tech_pvt->sofia_private = NULL;