]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
put presence-data in events
authorAnthony Minessale <anthm@freeswitch.org>
Thu, 10 May 2012 17:15:25 +0000 (12:15 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Thu, 10 May 2012 17:15:30 +0000 (12:15 -0500)
src/include/switch_event.h
src/switch_channel.c
src/switch_core_sqldb.c
src/switch_event.c
src/switch_ivr_bridge.c

index dd5991bf07829ec2a5795f5e7cfc530d58c0fb82..5909c0e0c07b7ff84b197ae1e7443af6227324b1 100644 (file)
@@ -402,6 +402,8 @@ SWITCH_DECLARE(void) switch_event_deliver(switch_event_t **event);
 
 SWITCH_DECLARE(char *) switch_event_build_param_string(switch_event_t *event, const char *prefix, switch_hash_t *vars_map);
 SWITCH_DECLARE(int) switch_event_check_permission_list(switch_event_t *list, const char *name);
+SWITCH_DECLARE(void) switch_event_add_presence_data_cols(switch_channel_t *channel, switch_event_t *event, const char *prefix);
+
 ///\}
 
 SWITCH_END_EXTERN_C
index 3c4262b0a9a817fabdb5d489b938a9faeb53a595..20734d04f406b7cca40ea1d69753dcad15eea227 100644 (file)
@@ -1160,6 +1160,38 @@ SWITCH_DECLARE(uint32_t) switch_channel_del_variable_prefix(switch_channel_t *ch
        return r;
 }
 
+
+SWITCH_DECLARE(void) switch_channel_set_presence_data_vals(switch_channel_t *channel, const char *presence_data_cols)
+{
+       if (!zstr(presence_data_cols)) {
+               char *cols[128] = { 0 };
+               char header_name[128] = "";
+               int col_count = 0, i = 0;
+               char *data_copy = NULL;
+
+               if (zstr(presence_data_cols)) {
+                       presence_data_cols = switch_channel_get_variable_dup(channel, "presence_data_cols", SWITCH_FALSE, -1);
+                       if (zstr(presence_data_cols)) {
+                               return;
+                       }
+               }
+
+               data_copy = strdup(presence_data_cols);
+       
+               col_count = switch_split(data_copy, ':', cols);
+       
+               for (i = 0; i < col_count; i++) {
+                       const char *val = NULL;
+                       switch_snprintf(header_name, sizeof(header_name), "PD-%s", cols[i]);
+                       val = switch_channel_get_variable(channel, cols[i]);
+                       switch_channel_set_profile_var(channel, header_name, val);
+               }
+               
+               switch_safe_free(data_copy);
+       }
+}
+
+
 SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_var_check(switch_channel_t *channel,
                                                                                                                                          const char *varname, const char *value, switch_bool_t var_check)
 {
@@ -2192,6 +2224,7 @@ SWITCH_DECLARE(void) switch_channel_event_set_basic_data(switch_channel_t *chann
 
        if ((v = switch_channel_get_variable(channel, "presence_data_cols"))) {
                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Presence-Data-Cols", v);
+               switch_event_add_presence_data_cols(channel, event, "PD-");
        }
 
        if ((v = switch_channel_get_variable(channel, "call_uuid"))) {
index d6c64758aa0ca6ec9e13ec34105938b0e9ed457c..5c59d96962f8da559233ac188e59eab00ebb60f3 100644 (file)
@@ -1171,7 +1171,7 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread,
 
 static char *parse_presence_data_cols(switch_event_t *event)
 {
-       char *cols[25] = { 0 };
+       char *cols[128] = { 0 };
        int col_count = 0;
        char *data_copy;
        switch_stream_handle_t stream = { 0 };
index bce57b79ee140f71c7ca22172528cbcde1c0b223..fa864526c812fead0dac3b8a1a2188e8729e36be 100644 (file)
@@ -2399,7 +2399,34 @@ SWITCH_DECLARE(int) switch_event_check_permission_list(switch_event_t *list, con
        return r;       
 }
 
+SWITCH_DECLARE(void) switch_event_add_presence_data_cols(switch_channel_t *channel, switch_event_t *event, const char *prefix)
+{
+       const char *data;
+
+       if (!prefix) prefix = "";
+       
+       if ((data = switch_channel_get_variable(channel, "presence_data_cols"))) {
+               char *cols[128] = { 0 };
+               char header_name[128] = "";
+               int col_count = 0, i = 0;
+               char *data_copy = NULL;
 
+               data_copy = strdup(data);
+       
+               col_count = switch_split(data_copy, ':', cols);
+       
+               for (i = 0; i < col_count; i++) {
+                       const char *val = NULL;
+                       switch_snprintf(header_name, sizeof(header_name), "%s%s", prefix, cols[i]);
+                       
+                       val = switch_channel_get_variable(channel, cols[i]);
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header_name, val);
+               }
+               
+               switch_safe_free(data_copy);
+       }
+
+}
 
 
 /* For Emacs:
index 6a2cee0405df2ec7fb58949eb7ccc645fae4fb48..3d9758f62bb9cb4eb068566a92c531b9a981e801 100644 (file)
@@ -968,9 +968,16 @@ static switch_status_t signal_bridge_on_hibernate(switch_core_session_t *session
 
        if (switch_channel_test_flag(channel, CF_BRIDGE_ORIGINATOR)) {
                if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_BRIDGE) == SWITCH_STATUS_SUCCESS) {
+                       switch_core_session_t *other_session;
+
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Bridge-A-Unique-ID", switch_core_session_get_uuid(session));
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Bridge-B-Unique-ID", msg.string_arg);
                        switch_channel_event_set_data(channel, event);
+                       if ((other_session = switch_core_session_locate(msg.string_arg))) {
+                               switch_channel_t *other_channel = switch_core_session_get_channel(other_session);
+                               switch_event_add_presence_data_cols(other_channel, event, "Bridge-B-PD-");
+                               switch_core_session_rwunlock(other_session);
+                       }
                        switch_event_fire(&event);
                }
        }
@@ -1052,16 +1059,27 @@ static switch_status_t signal_bridge_on_hangup(switch_core_session_t *session)
                        }
                }
                
-               switch_core_session_rwunlock(other_session);
-       }
+               if (switch_channel_test_flag(channel, CF_BRIDGE_ORIGINATOR)) {
+                       switch_channel_clear_flag_recursive(channel, CF_BRIDGE_ORIGINATOR);
+                       if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_UNBRIDGE) == SWITCH_STATUS_SUCCESS) {
+                               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Bridge-A-Unique-ID", switch_core_session_get_uuid(session));
+                               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Bridge-B-Unique-ID", uuid);
+                               switch_event_add_presence_data_cols(other_channel, event, "Bridge-B-PD-");
+                               switch_channel_event_set_data(channel, event);
+                               switch_event_fire(&event);
+                       }
+               }
 
-       if (switch_channel_test_flag(channel, CF_BRIDGE_ORIGINATOR)) {
-               switch_channel_clear_flag_recursive(channel, CF_BRIDGE_ORIGINATOR);
-               if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_UNBRIDGE) == SWITCH_STATUS_SUCCESS) {
-                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Bridge-A-Unique-ID", switch_core_session_get_uuid(session));
-                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Bridge-B-Unique-ID", uuid);
-                       switch_channel_event_set_data(channel, event);
-                       switch_event_fire(&event);
+               switch_core_session_rwunlock(other_session);
+       } else {
+               if (switch_channel_test_flag(channel, CF_BRIDGE_ORIGINATOR)) {
+                       switch_channel_clear_flag_recursive(channel, CF_BRIDGE_ORIGINATOR);
+                       if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_UNBRIDGE) == SWITCH_STATUS_SUCCESS) {
+                               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Bridge-A-Unique-ID", switch_core_session_get_uuid(session));
+                               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Bridge-B-Unique-ID", uuid);
+                               switch_channel_event_set_data(channel, event);
+                               switch_event_fire(&event);
+                       }
                }
        }
 
@@ -1242,6 +1260,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Bridge-A-Unique-ID", switch_core_session_get_uuid(session));
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Bridge-B-Unique-ID", switch_core_session_get_uuid(peer_session));
                        switch_channel_event_set_data(caller_channel, event);
+                       switch_event_add_presence_data_cols(peer_channel, event, "Bridge-B-PD-");
                        switch_event_fire(&event);
                        br = 1;
                }
@@ -1425,6 +1444,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses
                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Bridge-A-Unique-ID", switch_core_session_get_uuid(session));
                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Bridge-B-Unique-ID", switch_core_session_get_uuid(peer_session));
                switch_channel_event_set_data(caller_channel, event);
+               switch_event_add_presence_data_cols(peer_channel, event, "Bridge-B-PD-");
                switch_event_fire(&event);
        }