put presence-data in events

This commit is contained in:
Anthony Minessale 2012-05-10 12:15:25 -05:00
parent 921de9446f
commit e54ab070f4
5 changed files with 92 additions and 10 deletions

View 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

View 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"))) {

View 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 };

View 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:

View 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);
}