]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-9698 fire custom sofia::bye_response event when response to BYE is received and...
authorChris Rienzo <chris.rienzo@citrix.com>
Fri, 4 Nov 2016 13:02:09 +0000 (09:02 -0400)
committerChris Rienzo <chris.rienzo@citrix.com>
Fri, 4 Nov 2016 16:00:39 +0000 (12:00 -0400)
src/mod/endpoints/mod_sofia/mod_sofia.c
src/mod/endpoints/mod_sofia/mod_sofia.h
src/mod/endpoints/mod_sofia/sofia.c
src/mod/endpoints/mod_sofia/sofia_glue.c

index be03dd2d43bccc84fb3c0c7327fdd472153aa506..63c92cc852beafdc2454d6ca4cb2549e48be9ce3 100644 (file)
@@ -620,7 +620,9 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session)
        sofia_clear_flag(tech_pvt, TFLAG_IO);
 
        if (tech_pvt->sofia_private) {
-               *tech_pvt->sofia_private->uuid = '\0';
+               /* set to NULL so that switch_core_session_locate no longer succeeds, but don't lose the UUID in uuid_str so we
+                * can fire events with session UUID */
+               tech_pvt->sofia_private->uuid = NULL;
        }
 
        switch_mutex_unlock(tech_pvt->sofia_mutex);
@@ -5896,6 +5898,11 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load)
                switch_goto_status(SWITCH_STATUS_TERM, err);
        }
 
+       if (switch_event_reserve_subclass(MY_EVENT_BYE_RESPONSE) != SWITCH_STATUS_SUCCESS) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't register subclass %s!\n", MY_EVENT_BYE_RESPONSE);
+               switch_goto_status(SWITCH_STATUS_TERM, err);
+       }
+
        switch_find_local_ip(mod_sofia_globals.guess_ip, sizeof(mod_sofia_globals.guess_ip), &mod_sofia_globals.guess_mask, AF_INET);
        in.s_addr = mod_sofia_globals.guess_mask;
        switch_set_string(mod_sofia_globals.guess_mask_str, inet_ntoa(in));
index 966717bef7ccbe99de13ddb8280cf371e75967cf..ba4f9a653401c9c43eaa48934f6d30b06cc35b52 100644 (file)
@@ -104,6 +104,8 @@ typedef struct private_object private_object_t;
 #define MY_EVENT_REPLACED "sofia::replaced"
 #define MY_EVENT_INTERCEPTED "sofia::intercepted"
 
+#define MY_EVENT_BYE_RESPONSE "sofia::bye_response"
+
 #define MULTICAST_EVENT "multicast::event"
 #define SOFIA_REPLACES_HEADER "_sofia_replaces_"
 #define SOFIA_CHAT_PROTO "sip"
@@ -169,7 +171,8 @@ typedef struct sofia_dispatch_event_s {
 } sofia_dispatch_event_t;
 
 struct sofia_private {
-       char uuid[SWITCH_UUID_FORMATTED_LENGTH + 1];
+       char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
+       char *uuid;
        char gateway_name[256];
        char auth_gateway_name[256];
        char *call_id;
@@ -297,6 +300,7 @@ typedef enum {
        PFLAG_PROXY_HOLD,
        PFLAG_PROXY_INFO,
        PFLAG_PROXY_MESSAGE,
+       PFLAG_FIRE_BYE_RESPONSE_EVENTS,
 
        /* No new flags below this line */
        PFLAG_MAX
index a0e0fae2c88e7be3deda42ccbf66c589651aab45..76208038a94068acc95f632487a7d87392616c7f 100644 (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;
index 3b356c0ed871bb69d5ca147b78d5d7a7d473fb7b..6b523ac993fd0ed7c2fb92c9830f1e9a778ec58d 100644 (file)
@@ -1181,7 +1181,8 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session)
                }
 
                tech_pvt->sofia_private = sofia_private;
-               switch_copy_string(tech_pvt->sofia_private->uuid, switch_core_session_get_uuid(session), sizeof(tech_pvt->sofia_private->uuid));
+               switch_copy_string(tech_pvt->sofia_private->uuid_str, switch_core_session_get_uuid(session), sizeof(tech_pvt->sofia_private->uuid_str));
+               tech_pvt->sofia_private->uuid = tech_pvt->sofia_private->uuid_str;
                nua_handle_bind(tech_pvt->nh, tech_pvt->sofia_private);
        }