]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-11838 [mod_kazoo] handle intercept
authorLuis Azedo <luis@2600hz.com>
Fri, 10 May 2019 17:41:23 +0000 (18:41 +0100)
committerLuis Azedo <luis@2600hz.com>
Fri, 10 May 2019 17:41:23 +0000 (18:41 +0100)
src/mod/event_handlers/mod_kazoo/kazoo.conf.xml
src/mod/event_handlers/mod_kazoo/kazoo_tweaks.c

index 5464407c7a92eeb610d8f4deb30c2a7ef0f2bf82..a86942068193cb58eb7a43d242b0ed0e2f06df76 100644 (file)
@@ -17,7 +17,7 @@
                <param name="receive-msg-preallocate" value="8192" />
                <param name="node-worker-threads" value="5" />
                <param name="receive-timeout" value="1" />
-               <param name="event-stream-framing" value="2" />
+               <param name="event-stream-framing" value="4" />
 
        </settings>
 
             </field>
         </definition>
 
+        <definition name="originated-legs">
+            <filters>
+                <filter name="variable_originated_legs" type="include" compare="exists" />
+            </filters>
+            <field name="Other-Legs" type="static" serialize-as="object">
+                <fields verbose="false">
+                    <field name="variable_originated_legs" as="Callee" />
+                    <field name="variable_originate_causes" as="Causes" />
+                </fields>
+            </field>            
+        </definition>
+
         <definition name="transfer-history">
             <filters>
                 <filter name="variable_transfer_history" type="include" compare="exists" />
@@ -54,7 +66,7 @@
             <field name="Call-Interaction-Is-Root" type="static" value="true" serialize-as="boolean">
                    <filters>
                    <filter name="variable_Call-Interaction-ID" type="include" compare="field" value="variable_Original-Call-Interaction-ID" />
-                      <field name="${first-of(Event-Subclass|Event-Name|#none)}" type="include" compare="list" value="CHANNEL_DESTROY|KZ_CDR"/>
+                      <filter name="${first-of(Event-Subclass|Event-Name|#none)}" type="include" compare="list" value="CHANNEL_DESTROY|KZ_CDR"/>
                    </filters>
             </field>
         </definition>
         </definition>
 
         <definition name="Privacy">
-                    <field name="Caller-Privacy-Hide-Number" as="Hide-Number" serialize-as="boolean" />
-                    <field name="Caller-Privacy-Hide-Name" as="Hide-Name" serialize-as="boolean" />
-                    <field name="Caller-Screen-Bit" as="Screen-Bit" serialize-as="boolean" />
+            <field name="Privacy" type="static" serialize-as="object">
+                <fields verbose="false">
+                           <field name="Caller-Privacy-Hide-Number" as="Hide-Number" serialize-as="boolean" />
+                           <field name="Caller-Privacy-Hide-Name" as="Hide-Name" serialize-as="boolean" />
+                           <field name="Caller-Screen-Bit" as="Screen-Bit" serialize-as="boolean" />
+                </fields>
+            </field>
         </definition>
 
         <definition name="Custom-Channel-Vars">
                         </fields>
                     </field>
 
+                    <field name="Caller-Privacy-Hide-Number" as="Privacy-Hide-Number" serialize-as="boolean" />
+                    <field name="Caller-Privacy-Hide-Name" as="Privacy-Hide-Name" serialize-as="boolean" />
+
                 </fields>
             </field>
         </definition>
 
         <definition name="application">
             <field name="Application-Name" type="first-of"
-                value="kazoo_application_name|Application-UUID-Name|Application|Event-Subclass" />
+                value="Application-UUID-Name|kazoo_application_name|Application|Event-Subclass" />
             <field name="Application-Response" type="first-of"
                 value="kazoo_application_response|Application-Response" />
         </definition>
 
         <definition name="raw-application">
             <field name="Raw-Application-Name" type="first-of"
-                value="Application|kazoo_application_name|Event-Subclass" />
+                value="kazoo_application_name|Application|Event-Subclass" />
             <field name="Application-Data" as="Raw-Application-Data" />
         </definition>
 
             <field name="user-agent" type="reference" />
             <field name="Custom-Channel-Vars" type="reference" />
             <field name="Custom-Application-Vars" type="reference" />
-            <field name="Control" type="reference" />           
+            <field name="Control" type="reference" />
+            <field name="debug-call" type="reference" />
         </definition>
 
         <definition name="fetch-info">
             <field name="freeswitch-url" type="reference" />
             <field name="Control" type="reference" />
             <field name="Privacy" type="reference" />
+            <field name="debug-call" type="reference" />
             
         </definition>
 
                 <field name="Event-Name" type="static" value="route_req" />
                 <field name="Hunt-Context" as="Fetch-Key-Value" />
         </definition>
-        <definition name="metaflow_dialplan">
-                <field name="metaflow" type="group">
-                    <filters>
-                        <filter name="Hunt-Context" type="include" compare="value"
-                            value="metaflow" />
-                    </filters>
-                    <fields verbose="false">
-                        <field name="Hunt-Context" as="Context" />
-                        <field name="Resource-Type" type="static" value="metaflow" />
-                        <!--
-                        <field name="variable_Call-Control-Queue" as="Metaflow-Control-Queue" />
-                        <field name="variable_Call-Control-PID" as="Metaflow-Control-PID" />
-                        -->
-                        <field name="variable_Metaflow-Control-Queue" as="Metaflow-Control-Queue" />
-                        <field name="variable_Metaflow-Control-PID" as="Metaflow-Control-PID" />
-                        <field name="Custom-Routing-Headers" type="static"
-                            serialize-as="object">
-                            <fields verbose="false">
-                                <field name="Metaflow-Request-Type" type="static" value="in-call" />
-                                <field name="Other-Leg-Unique-ID" as="Other-Leg-Call-ID" />
-                                <field name="Hunt-Destination-Number" as="Metaflow-Request" />
-                            </fields>
-                        </field>
-                    </fields>
-
-                </field>        
-        </definition>
 
     </definitions>
 
                                                <field name="variable_Media-Recordings" as="Media-Recordings" />
                                                <field name="debug-call" type="reference" />
                         <field name="transfer-history" type="reference" />
+                        <field name="originated-legs" type="reference" />
                                                
                                        </fields>
                                        <filters>
 
                                </event>
 
+                <event name="CHANNEL_PROGRESS">
+                    <fields verbose="false">
+                        <field name="call_event" type="reference" />
+                        <field name="from-to" type="reference" />
+                        <field name="debug-call" type="reference" />
+                    </fields>
+                </event>
+
                                <event name="CHANNEL_PROGRESS_MEDIA">
                                        <fields verbose="false">
                                                <field name="call_event" type="reference" />
                                </event>
 
                                <event name="kazoo::masquerade">
+                               <!-- 
                                        <filters>
                                                <filter type="exclude" name="kazoo_event_name" compare="value"
                                                        value="CHANNEL_EXECUTE_COMPLETE" />
                                        </filters>
+                           -->
                                        <fields verbose="false">
                                                <field name="call_event" type="reference" />
+                                               <field name="application-uuid" type="reference" />
                                                <field name="Application-Response" type="first-of"
-                                                       value="variable_originate_disposition|#FAIL" />
+                                                       value="variable_endpoint_disposition|variable_originate_disposition|#FAIL" />
                                                <field name="Disposition" type="first-of"
                                                        value="variable_originate_disposition|variable_endpoint_disposition" />
+                        <field name="Bridge-Hangup-Cause" type="first-of" value="variable_bridge_hangup_cause|variable_last_bridge_hangup_cause" />
+                        <field name="variable_endpoint_disposition" as="Endpoint-Disposition" />
+                        <field name="variable_transfer_disposition" as="Transfer-Disposition" />
                                        </fields>
                                </event>
 
                         <filter name="Application" value="ring_ready" />
                         <filter name="Application" value="log" />
                         <filter name="Application" value="execute_extension" />
+                        <filter name="Application" value="bridge" />
                                        </filters>
 
                                        <fields verbose="false">
                                                <field name="Disposition" type="first-of"
                                                        value="variable_originate_disposition|variable_endpoint_disposition" />
                                                <field name="Bridge-Hangup-Cause" type="first-of" value="variable_bridge_hangup_cause|variable_last_bridge_hangup_cause" />
+                        <field name="variable_endpoint_disposition" as="Endpoint-Disposition" />
+                        <field name="variable_transfer_disposition" as="Transfer-Disposition" />
+                                               
                                                <field name="debug-call" type="reference" />
                                        </fields>
 
                                                <field name="call_event" type="reference" />
                                                <field name="Custom-Channel-Vars" type="reference" />
                                                <field name="Custom-Application-Vars" type="reference" />
+                                               <field name="debug-call" type="reference" />
                                        </fields>
                                </event>
 
 
             <fields verbose="false">
                 <field name="voice_dialplan" type="reference" />
-                <field name="metaflow_dialplan" type="reference" />
                 <field name="debug-call" type="reference" />
             </fields>
 
index 19aa19980d9c9f59100e8534514d8c1583b84ce1..67f4d37a9904a8f059a26e376a7b3444869d9d3d 100644 (file)
@@ -31,6 +31,7 @@
 #include "mod_kazoo.h"
 
 #define INTERACTION_VARIABLE "Call-Interaction-ID"
+#define BRIDGE_INTERCEPT_VARIABLE "Bridge-Intercepted"
 
 static char *TWEAK_NAMES[] = {
        "interaction-id",
@@ -66,6 +67,9 @@ static switch_status_t kz_tweaks_signal_bridge_on_hangup(switch_core_session_t *
 
        const char *peer_uuid = switch_channel_get_variable(channel, "Bridge-B-Unique-ID");
 
+       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "tweak signal bridge on hangup: %s , %s\n", switch_core_session_get_uuid(session), peer_uuid);
+
+
        if (switch_event_create(&my_event, SWITCH_EVENT_CHANNEL_UNBRIDGE) == SWITCH_STATUS_SUCCESS) {
                switch_event_add_header_string(my_event, SWITCH_STACK_BOTTOM, "Bridge-A-Unique-ID", switch_core_session_get_uuid(session));
                switch_event_add_header_string(my_event, SWITCH_STACK_BOTTOM, "Bridge-B-Unique-ID", peer_uuid);
@@ -100,6 +104,9 @@ static void kz_tweaks_handle_bridge_variables(switch_event_t *event)
 
        if (!kz_test_tweak(KZ_TWEAK_BRIDGE_VARIABLES)) return;
 
+       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "tweak bridge event handler: variables : %s , %s\n", a_leg, b_leg);
+
+
        if (a_leg && (a_session = switch_core_session_force_locate(a_leg)) != NULL) {
                switch_channel_t *a_channel = switch_core_session_get_channel(a_session);
                if(switch_channel_get_variable_dup(a_channel, bridge_variables[0], SWITCH_FALSE, -1) == NULL) {
@@ -130,91 +137,56 @@ static void kz_tweaks_handle_bridge_variables(switch_event_t *event)
 
 }
 
-static void kz_tweaks_handle_bridge_replaces_aleg(switch_event_t *event)
+static void kz_tweaks_handle_bridge_intercepted(switch_event_t *event)
 {
        switch_event_t *my_event;
+       switch_core_session_t *a_session = NULL;
+       switch_core_session_t *b_session = NULL;
 
-       const char *replaced_call_id =  switch_event_get_header(event, "variable_sip_replaces_call_id");
-       const char *a_leg_call_id =     switch_event_get_header(event, "variable_sip_replaces_a-leg");
-       const char *peer_uuid = switch_event_get_header(event, "Unique-ID");
-       int processed = 0;
+       const char *uuid = switch_event_get_header(event, "Unique-ID");
+       const char *a_leg = switch_event_get_header(event, "Bridge-A-Unique-ID");
+       const char *b_leg = switch_event_get_header(event, "Bridge-B-Unique-ID");
+       const char *bridge_intercepted = NULL;
 
        if (!kz_test_tweak(KZ_TWEAK_BRIDGE_REPLACES_ALEG)) return;
 
+       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "tweak bridge event handler: intercepted : %s , %s, %s\n", uuid, a_leg, b_leg);
 
-       if(a_leg_call_id && replaced_call_id) {
-               const char *call_id = switch_event_get_header(event, "Bridge-B-Unique-ID");
-               switch_core_session_t *session = NULL;
-               if ((session = switch_core_session_locate(peer_uuid)) != NULL) {
-                       switch_channel_t *channel = switch_core_session_get_channel(session);
-                       processed = switch_true(switch_channel_get_variable_dup(channel, "Bridge-Event-Processed", SWITCH_FALSE, -1));
-                       switch_channel_set_variable(channel, "Bridge-Event-Processed", "true");
-                       switch_core_session_rwunlock(session);
-               }
-
-               if(processed) {
-                       if(call_id) {
-                               if((session = switch_core_session_locate(call_id)) != NULL) {
-                                       switch_channel_t *channel = switch_core_session_get_channel(session);
-                                       switch_channel_set_variable(channel, "Bridge-Event-Processed", "true");
-                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "creating channel_bridge event A - %s , B - %s\n", switch_core_session_get_uuid(session), peer_uuid);
-                                       if (switch_event_create(&my_event, SWITCH_EVENT_CHANNEL_BRIDGE) == SWITCH_STATUS_SUCCESS) {
-                                               switch_event_add_header_string(my_event, SWITCH_STACK_BOTTOM, "Bridge-A-Unique-ID", switch_core_session_get_uuid(session));
-                                               switch_event_add_header_string(my_event, SWITCH_STACK_BOTTOM, "Bridge-B-Unique-ID", peer_uuid);
-                                               switch_channel_event_set_data(channel, my_event);
-                                               switch_event_fire(&my_event);
-                                       }
-                                       switch_channel_set_variable(channel, "Bridge-B-Unique-ID", peer_uuid);
-                                       switch_channel_add_state_handler(channel, &kz_tweaks_signal_bridge_state_handlers);
-                                       switch_core_session_rwunlock(session);
-                               } else {
-                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "invalid session : %s\n", call_id);
-                                       DUMP_EVENT(event);
-                               }
-                       }
-               }
-
-       }
-
-}
 
-static void kz_tweaks_handle_bridge_replaces_call_id(switch_event_t *event)
-{
-       switch_event_t *my_event;
+       if ((a_session = switch_core_session_locate(a_leg)) != NULL) {
+               switch_channel_t *a_channel = switch_core_session_get_channel(a_session);
+               bridge_intercepted = switch_channel_get_variable_dup(a_channel, BRIDGE_INTERCEPT_VARIABLE, SWITCH_TRUE, -1);
+               switch_channel_set_variable(a_channel, BRIDGE_INTERCEPT_VARIABLE, NULL);
+               if (bridge_intercepted && switch_true(bridge_intercepted)) {
+                       switch_channel_set_variable(a_channel, "Bridge-B-Unique-ID", b_leg);
+                       switch_channel_add_state_handler(a_channel, &kz_tweaks_signal_bridge_state_handlers);
 
-       const char *replaced_call_id =  switch_event_get_header(event, "variable_sip_replaces_call_id");
-       const char *a_leg_call_id =     switch_event_get_header(event, "variable_sip_replaces_a-leg");
-       const char *peer_uuid = switch_event_get_header(event, "Unique-ID");
-
-       if (!kz_test_tweak(KZ_TWEAK_BRIDGE_REPLACES_CALL_ID)) return;
-
-       if(a_leg_call_id && replaced_call_id) {
-               switch_core_session_t *call_session = NULL;
-               const char *call_id = switch_event_get_header(event, "Bridge-B-Unique-ID");
-               if (call_id && (call_session = switch_core_session_force_locate(call_id)) != NULL) {
-                       switch_channel_t *call_channel = switch_core_session_get_channel(call_session);
-                       if (switch_event_create(&my_event, SWITCH_EVENT_CHANNEL_BRIDGE) == SWITCH_STATUS_SUCCESS) {
-                               switch_event_add_header_string(my_event, SWITCH_STACK_BOTTOM, "Bridge-A-Unique-ID", switch_core_session_get_uuid(call_session));
-                               switch_event_add_header_string(my_event, SWITCH_STACK_BOTTOM, "Bridge-B-Unique-ID", peer_uuid);
-                               switch_channel_event_set_data(call_channel, my_event);
-                               switch_event_fire(&my_event);
+                       if ((b_session = switch_core_session_locate(b_leg)) != NULL) {
+                               switch_channel_t *b_channel = switch_core_session_get_channel(b_session);
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "creating channel_bridge event A - %s , B - %s\n", switch_core_session_get_uuid(b_session), uuid);
+                               if (switch_event_create(&my_event, SWITCH_EVENT_CHANNEL_BRIDGE) == SWITCH_STATUS_SUCCESS) {
+                                       switch_event_add_header_string(my_event, SWITCH_STACK_BOTTOM, "Bridge-A-Unique-ID", switch_core_session_get_uuid(b_session));
+                                       switch_event_add_header_string(my_event, SWITCH_STACK_BOTTOM, "Bridge-B-Unique-ID", uuid);
+                                       switch_channel_event_set_data(b_channel, my_event);
+                                       switch_event_fire(&my_event);
+                               }
+                               switch_core_session_rwunlock(b_session);
                        }
-                       switch_channel_set_variable(call_channel, "Bridge-B-Unique-ID", peer_uuid);
-                       switch_channel_add_state_handler(call_channel, &kz_tweaks_signal_bridge_state_handlers);
-                       switch_core_session_rwunlock(call_session);
-               } else {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "NOT FOUND : %s\n", call_id);
                }
+               switch_core_session_rwunlock(a_session);
        }
-
+       switch_safe_strdup(bridge_intercepted);
 }
 
 static void kz_tweaks_channel_bridge_event_handler(switch_event_t *event)
 {
+       const char *uuid = switch_event_get_header(event, "Unique-ID");
+
        if (!kz_test_tweak(KZ_TWEAK_BRIDGE)) return;
 
-       kz_tweaks_handle_bridge_replaces_call_id(event);
-       kz_tweaks_handle_bridge_replaces_aleg(event);
+       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "tweak bridge event handler: %s\n", uuid);
+
+       kz_tweaks_handle_bridge_intercepted(event);
        kz_tweaks_handle_bridge_variables(event);
 }
 
@@ -232,12 +204,21 @@ static void kz_tweaks_channel_replaced_event_handler(switch_event_t *event)
 
 static void kz_tweaks_channel_intercepted_event_handler(switch_event_t *event)
 {
+       switch_core_session_t *uuid_session = NULL;
        const char *uuid = switch_event_get_header(event, "Unique-ID");
        const char *peer_uuid = switch_event_get_header(event, "intercepted_by");
 
        if (!kz_test_tweak(KZ_TWEAK_TRANSFERS)) return;
 
-       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "INTERCEPTED : %s => %s\n", uuid, peer_uuid);
+       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "tweak intercepted handler : %s was intercepted by %s\n", uuid, peer_uuid);
+
+       if ((uuid_session = switch_core_session_force_locate(peer_uuid)) != NULL) {
+               switch_channel_t *uuid_channel = switch_core_session_get_channel(uuid_session);
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "marking %s for channel_bridge handling\n", peer_uuid);
+               switch_channel_set_variable(uuid_channel, BRIDGE_INTERCEPT_VARIABLE, "true");
+               switch_core_session_rwunlock(uuid_session);
+       }
+
 }
 
 static void kz_tweaks_channel_transferor_event_handler(switch_event_t *event)